The Image Caption Filter module looks for an exact match on the class="..." string for each img tag, which means that images with multiple classes (such as the extra class created by ImageCache when combined with Insert module) won't get captions.

In other words, class="imagecache_thumb image-right" SHOULD get a caption because it contains "image-right", but currently it does not.

The expected behavior would be for the module split the classes up and check each one.

Comments

bradweikel’s picture

The fix for this is pretty basic:

1) change Line 71 to this:
$class = explode(" ", $matches[1]);

2) the conditional at Line 83 needs to be modified to check the entire array for matches, probably using count(array_intersect(class, array("image-right"...)))

3) the return value inside that conditional will need to be tweaked a bit so that the correct classes are preserved

I'd get us started on a patch, but I'm traveling and don't have a suitable dev environment, so hopefully somebody else can put together a patch.

vood002’s picture

The fix isn't quite this simple...although these two small changes will leave it in a partially-working state

Change line 71 to
$class = explode(" ", $matches[1]);

Change line 83 to
if ( array_intersect( $class, array('image-left', 'image-right', 'standalone-image')) && ($title)){

Then, the class is passed on to the

element with:
"<div class=\"" . $class . "\" style=\"width: " . $width . "px\">"

so this comes up as 'Array', and the line:

$imgText = preg_replace ('/class=\"(.+?)\"/i', '', $imgText);

will remove all classes from the image, where we'd like to only remove the class that causes captioning.

I'm going to work on this as soon as i can...should be pretty easy to roll a patch that makes this module very usable...unfortunately I have a lot on my plate ahead of it.

The only other problem I can see is that this module grabs the width of the image-containing div from the image width tag...which really isn't a tag that anyone should be using. This should be updated to use imagesx() if GD is detected....unless there's something I'm overlooking.

bradweikel’s picture

In my defense, that's precisely what I meant by "the return value... will need to be tweaked... so that the correct classes are preserved"

:)

You should file the width problem in another issue, so any patches in this queue don't get cluttered or delayed by multiple issues.

fletchgqc’s picture

You are right that this is a limitation. A patch would be welcomed but I'm about to submit some major code changes to this module so please just wait until they're in.

Regarding using the width attribute of the image tag, that is totally valid and not deprecated (won't explain here but you can research it). However new code which I'm about to submit will also allow width from inline style.

fletchgqc’s picture

brian_c’s picture

Please note that the patch in #5 does NOT fix the multiple classes issue that is the subject of this thread (it's a little confusing that you've linked to it from here)

NPC’s picture

Subscribing. The patch to the patch in #5 fixed it (THANK YOU!), but I want to know when it will be done properly (or checked in to the main branch).