Would the maintainers be able to give some guidance with how I could code the 2.x branch to support inline images? When I made this module: http://drupal.org/sandbox/ShaunDychko/1905886 for CKEditor, I had to make it against the 7.x-1.x since the 2.x branch doesn't yet support inline images. My understanding is that the 1.x branch does a regex search, by way of hook_entity_view and a #post-render function, for img tags in a textarea, looking for an src attribute that matches an image style with the resp_img default suffix. Could something similar be done in the 2.x branch? Can you make a rough outline of the best way to proceed?

Or maybe this effort should go into the http://drupal.org/project/picture module?

Comments

shaundychko’s picture

Title: Mentoring to support inline images in 2.x branch » Mentoring to support inline images in 2.x branch or move to picture module?
attiks’s picture

I would prefer to add this to picture, so closing this in favor of #1910296: How to add support for inline images? and moving discussion to #1885766: WYSIWYG support

gateone’s picture

Erm - the picture module is a nice idea but sadly not all image related modules are yet able to use it. Like the imagefield_crop that won't accept the "picture" display formatter.

In fact, the solution was easier than you might think. The problem with inline images is quite simple, it has to do with the fact that resp_img.module takes the original image path that will still contain the new ?itok=xxxxxxxx token - it does not get rid of that token but adds it's own token on top of that - resulting in image paths that look like this:

path/to/file.jpg%3Fitok%3Dxxxxxxxx?itokitok=xxxxxxxx

This will of course produce a file not found when the web server tries to find a file called file.jpg%3Fitok%3Dxxxxxxxx instead of file.jpg

Now my quick fix for this - and sorry, I am really not the best in writing quality code so this might be done much better:

In resp_img.module (version 7.x-2.x-dev) I looked for this part:

// Use path or uri untill D7 uses one in all places.
  if (!isset($variables['path']) || empty($variables['path'])) {
    $variables['path'] = ($variables['uri']);
  }
  if (!isset($variables['uri']) || empty($variables['uri'])) {
    $variables['uri'] = ($variables['path']);
  }
  $images = array();
  $output = array();

and added a regular expression search to get rid of the offending old token - like so:

// Use path or uri untill D7 uses one in all places.
  if (!isset($variables['path']) || empty($variables['path'])) {
    $variables['uri'] = preg_replace('#(\?itok=)[A-Za-z0-9_]{8}#', '', $variables['uri']);
    $variables['path'] = ($variables['uri']);
  }
  if (!isset($variables['uri']) || empty($variables['uri'])) {
    $variables['path'] = preg_replace('#(\?itok=)[A-Za-z0-9_]{8}#', '', $variables['path']);
    $variables['uri'] = ($variables['path']);
  }
  $images = array();
  $output = array();

As I said, I am not the best in coding, and there might be much more elegant ways to unset the old image security token before the new one gets added.

This solution is working nicely, any cleanups or better suggestions highly welcome, but I guess this will help getting rid of the problem.

attiks’s picture

Can you provide a patch so we can test this?

Regarding "Like the imagefield_crop that won't accept the "picture" display formatter.", what is needed to make this work with picture?

attiks’s picture

attiks’s picture

Issue summary: View changes
Status: Active » Fixed

Old issue, I think you better update to the picture module

Status: Fixed » Closed (fixed)

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