When attempting to insert html on a system with a private filesystem an absolute system path is inserted as the image source. The attached patch changes img_assist_load_properties to recieve the URL of the image instead. Not sure if it breaks anything else, but it works on my site. Previously only filtered input worked.

CommentFileSizeAuthor
inserthtml_private_files.patch1.07 KBdopry

Comments

serval-1’s picture

How does this behave when you change the image by uploading an image with another filename?
It would be nice to see /image/[nid]/view/[preview|thumb|original] as the returning URL. This will keep the images working when you change the filename.
I don't know the return value of the function "file_create_url", so probably this issue is already solved by using that function.

Robrecht Jacques’s picture

This bug is similar to the one I've discovered for filter: http://drupal.org/node/25922.

I'm not sure if this is the right solution, I'll look at it tomorrow. The idea is correct though: add a "file_create_url()" somewhere, but I'm not 100% convinced your patch adds it at the right place.

dopry’s picture

I'm not sure that is is the right spot. Basically it comes down to, it needs a url not a filesystem path in the html. If you or someone more familiar with img_assist could double check or suggest a better solution I can implement it. I'm rather naieve when it comes to drupal's file handling.... although I'm slowly learning it.

serval-1’s picture

I think it is an undocumented feature of the image module, but here is the code from image.module:

/**
 * Fetches an image file, allows "shorthand" image urls such of the form:
 * image/view/$nid/$label
 * (e.g. image/view/25/thumbnail or image/view/14)
 */
function image_fetch($nid = 0, $size = 'preview') {
  if ($nid) {
    $node = node_load(array('nid' => $nid));
    if ($node->images[$size]) {
      $file = $node->images[$size];
      $headers = image_file_download($file);
      file_transfer($file, $headers);
    }
  }
}

So you can use image/view/$nid/$label as a URL to the image.
I have tried it in my img_assist.module and it is working like a charm. Sorry I can't post the patch as I am using the old 4.6 version, but here is the code:

In the function img_assist_load_properties($id = null):

  //$id_field   .= form_hidden('filepath', $img->filepath);
  $id_field   .= form_hidden('filepath', url("image/view/$img->nid/"));
  $id_field   .= form_hidden('nodePath', url("node/$img->nid"));
  $id_field   .= form_hidden('origWidth', $img->width);
  $id_field   .= form_hidden('origHeight', $img->height);
  //$id_field   .= form_hidden('thumbpath', $img->thumbpath);
  $id_field   .= form_hidden('thumbpath', url("image/view/$img->nid/thumbnail"));

The original lines are commented out. I think there are some other places where you have to replace $img->filepath with url("image/view/$img->nid/$label"), but this is a good start.

benshell’s picture

Status: Active » Closed (fixed)

I'm closing this issue since it's been inactive for over six months. I'm the new maintainer of img_assist, but I can only support img_assist for Drupal 4.7+. The new version of img_assist on Drupal 4.7 beta seems to work fine with a private filesystem.