Download & Extend

Javascript display of image Ads does not work when site is in a subdirectory in a multisite enviroment.

Project:Advertisement
Version:6.x-2.2
Component:ad_image module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work

Issue Summary

Due to symbolic links and other underlying structures in my sites directory, showing ads with Javascript failed in my multisite enviroment.
I found that the preg_replace function used the return from drupal_get_path('module', 'ad') to filter out the extra bits added to the return of file_create_url when called from javascript.

I changed the regex pattern to accomodate the difference in the return values so that it now works in a multisite enviroment where sites are placed in subdirectories. I suspect that the same problem would maybe appear in subdomain installations.

The altered ad_image_display function looks like this:

<?php
/**
* Function used to display the selected ad.
*/
function ad_image_display_ad($ad) {
 
$image = db_fetch_object(db_query('SELECT a.fid, a.url, a.tooltip, a.width, a.height, f.filepath FROM {ad_image} a INNER JOIN {files} f ON a.fid = f.fid WHERE a.aid = %d AND f.nid = %d', $ad->aid, $ad->aid));
 
// Strip module path from image path if serving images from adserve.php.
 
$path_to_ad_module_pieces = explode("/", drupal_get_path('module' , 'ad'));
 
$base_modules_directory = array_shift($path_to_ad_module_pieces);
 
$ad_module_directory_name = array_pop($path_to_ad_module_pieces);
 
$pattern = '/\/'. $base_modules_directory . '\/.*\/' . $ad_module_directory_name . '/';
 
$image_path = preg_replace($pattern, '', file_create_url($image->filepath));
  return (
"<div class=\"image-advertisement\" id=\"ad-$ad->aid\"><a href=\"$ad->redirect/@HOSTID___\" title=\"". htmlentities($image->tooltip, ENT_QUOTES) .'"'. ad_link_attributes() ."><img src=\"$image_path\" width=\"$image->width\" height=\"$image->height\" /></a></div>");
}
?>
AttachmentSize
regex_fix.patch1.47 KB

Comments

#1

I suspect that the same problem would maybe appear in subdomain installations.

And I believe that the problem is solved with my patch.

#2

Any plans on incorporating this patch?

I just got reminded of the bug after updating the ad module.

I have not had any problems with this patch.

-Vidar

#3

Thanks for this patch. We've had infuriatingly intermittent problems with image ads in our multi-site setup. I hesitate to speak too soon but this patch seems to have fixed it. I'd rate this as quite a high-priority bug as it means image ads either don't work at all or work only intermittently in multi-site setups. So this patch gets my vote.

Thanks again,

Dave

#4

Status:needs review» postponed (maintainer needs more info)

I've installed the ad module on a multi-site install, and have not run into any problems displaying ads in each installation without this patch. Please provide more details on how to duplicate this issue.

#5

Some things I tried in trying to duplicate this bug report:

  • Created a multi-site install, accessing the ad module through sites/all, and my subdomains via sites/test1.com and sites/test2.com
  • Moved the ad module to sites/default, then added it to sites/test1.com/modules with a symbolic link
  • Made sites/test1.com a symbolic link
  • Made sites/ a symbolic link

None of these installations broke the ad_image module. I'm out of ideas.

#6

I have not tried using subdomains. (site1.example.com)
I broke ad-module when I had sites I accessed through subdirectories. I.e: www.example.com/site1, www.example.com/site2

the symlink setup was like this:
example.com/site1 -> example.com/drupal5
example.com/drupal5/sites/example.com.site1 -> example.com/drupal5/sites/site1
(repeat for more sites)

Ad module was placed in each sites modules directory

#7

Status:postponed (maintainer needs more info)» fixed

Some time ago issues with symbolic links and ad module position were addressed. I believe this is now fixed. Please re-open if you can still duplicate, and provide a complete explanation of your directory setup.

#8

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

#9

Status:closed (fixed)» needs work

Hello all,

I have this bug on a multisite installation. The page source shows that it is trying to call up the following URL:
http://example.com/sites/example.com/modules/ad/serve.php?q=1&t=33
Of course this is an invalid URL, it should be just http://example.com/modules/ad/serve.php?q=1&t=33
I tried installing the ad module both it ~/www/sites/all/modules and also ~/www/sites/example.com/modules, and it makes no difference.
I'm using Drupal 6.19 / ad 6.x-2.2 on Apache / CentOS

Thanks for any help you can offer with this!

#10

Version:5.x-1.4-1» 6.x-2.2

Similar problem operating from a subdomain/subdirectory

I was considering this module so I wanted to test it in a sandbox. This was not a multi site but a full drupal install in a subdir with a subdomain i.e.

sandbox.mysite.com

So the sandbox is in a directory from my main drupal install. i.e. home/www = main site and home/www/sandbox = is running a different version of drupal (6.19) with minimal modules.

I played with ad module and couldn't get it working properly. It was exhibiting results similar to other issues in this queue like only showing ads in RAW mode, not counting impressions, etc.

I couldn't get any debug output either. Viewing source would show a javascript line calling a url. Accessing that url directly results in page not found. That url seemed to be formed correctly i.e. http://sandbox.mysite.com/sites/all/modules/ad/serve.php?etc...

I was about to give up on it for a while when I thought I'd give it a quick test on my main site. It worked!

So installing on mysite.com worked with no problem. Was up and running in about a minute. But in a subdir accessed by a subdomain I failed to get it working.

I will do further testing on the main site, hoping to deploy this on client sites if it proves stable. Thought this might shed some light for others experiencing those other issues (no ads except in raw, etc). If they're in a subdirectory that may be the problem. If there's anything you can suggest or would like me to try to help figure out the problem, let me know.

Thanks!

#11

Hmmm, so what do we do if we need to use a subdirectory?

#12

Hi All.

I'm having this problem in an Aegir multi-site setup. I tried to the function Vidar Løvbrekke added above, but that doesn't appear to help me either as all I'm getting output to the screen... e.g.:

<img src="/" width="" height="">

By default the code is being outputted like this:

<img src="http://sitename.net/sites/sitename.net/modules/ad/sites/sitename.net/files/Bob_Dylan_AD2.png" alt="Win a Bob Dylan Signature Series Harmonica" title="Win a Bob Dylan Signature Series Harmonica" width="220" height="401">

I tried upgrading to '6.x-2.x-dev' to see if this would help, but it doesn't appear to have done.

Please help!

#13

Hi, are there any hacks or workarounds? I still have to use RAW, which means that impressions are not tracked.

#14

I tried the patch, and just kept getting the following message:

Hunk #1 FAILED at 15.
1 out of 1 hunk FAILED

So I tried pasting in the altered function manually, but that had no effect on the problem at all as far as I could determine.