[SOLVED] Compatibility with the ad module

rconstantine - October 18, 2007 - 02:32
Project:Pdfview
Version:5.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:active
Description

You need to modify the tcpdf.php file. Find the public function Image declaration and just after it, add:

if (preg_match('/([^?]*\?(.*?))/', $file)){//nf hack to get ad module to not crap out the pdfs
        $file = "sites/all/modules/pdfview/tcpdf/images/_blank.png";
      }

You might have to resave the _blank.png as non-interlaced as it will possibly throw an error about how there's no support for interlaced files. Why TCPDF comes with an image it doesn't support is beyond me.

The regex obviously looks to see if there is a string followed by a '?', followed by anything. I'm assuming this will be a query, not a valid file. I tried to execute the php file that is called to fill the src="" with the real image path, but didn't figure it out. This is a hard-coded work around. Would have rather figured the other way out because it could have been a patch for pdfview.

Executing the php file that the ad module stuffs into the image src="" attribute does a document.write, so there's no usable output to simply grab and replace the old src="" with.

Does that make sense? If not, you probably aren't using the ad module.

#1

rconstantine - October 18, 2007 - 03:14

It would seem I didn't quite test that enough. I was getting intermittent problems. Primarily, text overlapping other text, or regular text turning into hyperlinks for the ad.

So don't do the above change. Instead, in the pdfview.module file, add this line:

$string = preg_replace('/(<div class="advertisement")(.*?)(><\/div><\/div>)/', '', $string);

just before the return statement in the pdfview_check_images function. This will pull out the ad altogether. Maybe a better solution for a pdf download anyway.

 
 

Drupal is a registered trademark of Dries Buytaert.