| Project: | Inline |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Issue Summary
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?
Comments
#1
Please supply a proper patch. See http://drupal.org/patch for further information.
#2
here you go
#3
Please read http://drupal.org/coding-standards
#4
Hi! 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.
#5
Gosh, didn't know the whole issue title would change, changing back. :)