Drupal version: 7.14
Insert module: 7.x-1.1

When the "Insert" button is clicked, with a style different to thumbnail or original (medium for example), a "Clean URL" is pasted in the HTML editor:
http://www.mydomain.com/sites/default/files/styles/medium/public/image.png

If the image has not already been created, it will give a broken image. The "Clean URL" should NOT be used:
http://www.mydomain.com/?q=sites/default/files/styles/medium/public/image.png

The parameter "?q=" force Drupal to create the image if it doesn't exists.

CommentFileSizeAuthor
#4 insert_no_clean_urls.patch1.89 KBquicksketch
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gaellafond’s picture

PATCH

image.inc
Line: 50
ACTUAL CODE

function template_preprocess_image_insert_image(&$vars) {
  $vars['file'] = file_load($vars['item']['fid']);

  // We call this function merely to trigger access to the
  // image_style_generate() callback. We actually use image_style_path() to
  // build the final location of the file.
  $url = image_style_url($vars['style_name'], $vars['file']->uri);

  $vars['uri'] = image_style_path($vars['style_name'], $vars['file']->uri);
  $vars['url'] = insert_create_url($vars['uri']);
  $vars['class'] = !empty($vars['widget']['settings']['insert_class']) ? $vars['widget']['settings']['insert_class'] : '';
}

Calling "image_style_url" create the URL, not the physical image. The BUG can be fixed by using the returned URL instead of crafting one using the homemade function "insert_create_url".

PATCHED CODE

function template_preprocess_image_insert_image(&$vars) {
  $vars['file'] = file_load($vars['item']['fid']);
  $vars['uri'] = image_style_path($vars['style_name'], $vars['file']->uri);
  $vars['url'] = image_style_url($vars['style_name'], $vars['file']->uri);
  $vars['class'] = !empty($vars['widget']['settings']['insert_class']) ? $vars['widget']['settings']['insert_class'] : '';
}
quicksketch’s picture

Priority: Critical » Normal

So summary: Insert uses the wrong path when using not-Clean URLs.

I think we need to keep using insert_create_url() to make it so that the $absolute option is still obeyed, but you're right that we need to check if the file exists or not before trying to use a non-clean URL.

quicksketch’s picture

Title: Images are not created - Wrong URL is called » Inserted path is incorrect when clean URLs disabled and image does not exist
quicksketch’s picture

Status: Active » Fixed
FileSize
1.89 KB

I've committed this patch modeled on image_style_url() that should fix this problem.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Clarification about the difference between the 2 URLs