Support PDF attachments

xurizaemon - September 29, 2009 - 02:23
Project:Taxonomy Image
Version:6.x-1.6
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

We have a use case for PDF attachments to terms (and I'm not aware of a module which allows attaching non-image content to terms in a similar fashion).

The only change I had to make to get this module functioning appropriately was:

1. Use taxonomy_image_get_url() to build the reference in my term (views) template.
2. Disable the exit in taxonomy_image_get_object()

<?php
 
// Get more properties if we had an image.
 
if (!empty($image[$tid]->path)) {
   
$image[$tid]->tid = $tid;
   
$img = getimagesize($image[$tid]->url);
   
// Make sure it worked.
   
if (!$img) {
//      return NULL;
   
}
   
// ... and away ye go

?>

A couple of things I noticed in looking at this:

1. Taxonomy Image doesn't validate uploads anyway. You can upload a .doc file if you want. Not sure if you could upload malicious content this way; though some would argue .pdf and .doc are malicious anyway.

2. The uploaded file will be referenced using an image tag on the term edit screen, even if it's not an image. You end up with <img src="http://full/path/to/my.pdf" /> on screen. If this is a PDF, Webkit browsers will actually render it as an inline image.

3. This following code actually generates an HTTP request for the image file, which might cause things to fail if anonymous users are not permitted to view the image or if URLs are disabled in PHP's file_get_contents(). I didn't test this, just spotted that it's using the full URL rather than the local path.:

<?php
    $img
= getimagesize($image[$tid]->url);
 
?>

I can break those last three items into separate issues if you want?

 
 

Drupal is a registered trademark of Dries Buytaert.