I noticed the theme_inline_img is missing a way to add cutsom attributes (i.e. "class=" or "align=") to the image. After testing the code below, please consider adding it to the module so users can add classes to the inline images to improve CSS layout flexibility. Thanks!
I overrode the theme_inline_img code that contained:
if (module_exists('imagecache') && variable_get($inline_preset, '') != '') {
$image = theme('imagecache',
variable_get($inline_preset, ''),
$file->filepath,
$title,
$title,
array('class' => 'inline')
);
}
else {
$image = theme('image',
$file->filepath,
$title,
$title,
array('class' => 'inline')
);
}
with this in my phptemplate_inline_img function:
$titleArr = explode('|',$file->title);
$file->title = trim(array_shift($titleArr),"\x22\x27");
foreach($titleArr as $title) {
if (strpos($title,"=")>0) {
$pos = strpos($title,"=");
$attrkey = trim(substr($title,0,$pos));
$attrvalue = trim(substr($title,$pos+1));
} else {
$attrkey = "class";
$attrvalue = $title;
}
if ($file->attributes[$attrkey]) $file->attributes[$attrkey] .= ' ';
$file->attributes[$attrkey] = trim($attrvalue,"\x22\x27"); //trims quotes
}
// adds inline class
if ($imgAttributes = $file->attributes) $imgAttributes['class'] .= ' inline';
else $imgAttributes['class'] = 'inline';
if (module_exists('imagecache') && variable_get($inline_preset, '') != '') {
$image = theme('imagecache',
variable_get($inline_preset, ''),
$file->filepath,
$title,
$title,
$imgAttributes
);
}
else {
$image = theme('image',
$file->filepath,
$title,
$title,
$imgAttributes
);
}
node that a pipe key (|) seperates the new attributes from the title, and an attribute without an "=" within it is assumed to be a "class"
In other words: [inline:filename.jpg=file title|left] is the same as [inline:filename.jpg=file title|class=left]
Also, I trim the values for "", so this works too. [inline:filename.jpg="file title"|class="left"]
Any comments?
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | inline.classes.patch | 2.28 KB | gnucifer |
| #2 | inline-352584-1176167.patch | 1.85 KB | jefftrnr |
Comments
Comment #1
sunPlease supply a proper patch. See http://drupal.org/patch for further information.
Comment #2
jefftrnr commentedhere you go
Comment #3
sunPlease read http://drupal.org/coding-standards
Comment #4
gnucifer commentedHi! I made almost the exact same changes myself, but instead of
[inline:filename.jpg=file title|class=left]
I used the syntax:
[inline:filename.jpg=file title,left]
(multiple classes separated by space are fine too)
Submitting my (relatively small) changes as a patch in case anyone is interested.
Comment #5
gnucifer commentedGosh, didn't know the whole issue title would change, changing back. :)