Attached is a patch that adds imagecache support to inline.module's output. If Imagecache is installed, you can set a custom preset for scaling/cropping/etc of inlined images in both teaser and full node views. If greybox module is installed, it's also possible to make all inline images automatically link to a popup grey_box version of the full image.

if neither module is installed, the behavior is unchanged. yay.

Comments

sun’s picture

Title: Inline: add imagecache and greybox support » Add imagecache and greybox support
Status: Needs review » Needs work
  $preset_var = $teaser ? 'inline_teaser_preset' : 'inline_full_preset';

  if (module_exists('imagecache') && variable_get($preset_var, 'default') != 'default') {

$preset_var doesn't seem to be 'default' in any case.

-      list($width, $height) = getimagesize($file->filepath);
+      list($width, $height) = getimagesize(file_create_url($file->filepath));

seems to deal with another filepath issue. AFAIK, there are no open issues about inlined image filepaths currently. Can you explain this change?

Please do not include the module name in issues. I know, the recent posts listing doesn't display the project name for issues, but regarding project issue queues, these prefixes are not welcome.

It's almost needless to say that I like this patch very much... ;)

eaton’s picture

Status: Needs work » Needs review
StatusFileSize
new4.17 KB

Good catches -- thanks. I'm not sure how the file_create_path() change snuck in there -- I think it was accidental. The 'default' handling is unnecessary as well -- I just set it up such that the preset name is empty if no preset has been specified, and it works fine without any special casing. The re-rolled patch is attached...

eaton’s picture

StatusFileSize
new3.77 KB

After some careful examination, I've come to the conclusion that greybox integration *isn't* actually a good idea. It's really intended for popping up iframes of other web sites, not individual images. This version of the patch preserves imagecache integration, but adds an 'inline-image-link' to all HREFs generated for image linking. That means that a generic script like ThickBox can be used and attached to that class easily.

sun’s picture

function theme_inline_img($file, $teaser) {
  $preset_var = $teaser ? 'inline_teaser_preset' : 'inline_full_preset';

  if (module_exists('imagecache') && variable_get($preset_var, '')) {

We should replace $teaser with $field in the arguments of theme_inline_img() to make the code more understandable and to remove duplicate conditionals from function calls. $teaser seems then to be replaceable by $field == 'teaser'.

Please also avoid changes to other code lines:

-  $title = ( $file->title ? $file->title : $file->filename );
+  $title = ($file->title ? $file->title : $file->filename );

and avoid double spaces

+    $presets =  _imagecache_get_presets();
...
+      '#options' =>  $options,

and adhere to Drupal coding guidelines:

+    $image = theme('imagecache',
+      variable_get($preset_var, 'default'),
+      $file->filepath,
+      $title,
+      $title,
+      array('class' => 'inline'));
// should be
+    $image = theme('imagecache', variable_get($preset_var, 'default'), $file->filepath, $title, $title, array('class' => 'inline'));

and

+      array('class' => 'inline', 'style' => 'width: '.$file->width.'px; height:'.$file->height.'px;'),
// should be
+      array('class' => 'inline', 'style' => 'width: '. $file->width .'px; height:'. $file->height .'px;'),

You might install Coder module to automate such tests.

Did you already test that Inline works the same way it did without this patch?

sun’s picture

Title: Add imagecache and greybox support » Add imagecache support
Assigned: Unassigned » sun
Status: Needs review » Fixed

I've reworked your code and committed this feature to HEAD and DRUPAL-5.
Thanks for your help!

Anonymous’s picture

Status: Fixed » Closed (fixed)