Currently, when img_assist enters the 'img src', it does so with the absolute url: "http://mysite.com/system/files/img.jpg" This is a problem if the site is ever moved, since the 'http://mysite.com' is now embedded in the node itself. I don't recall that this was a part of the drupal 4 version.

If you remove the 'http://mysite.com' from the string, the image still appears: "/system/files/img.jpg". Is it possible to have the relative URL be the default? Or, can someone point out the function so I can override it in the template.php?
Thanks,
Maria

Comments

zoo33’s picture

Status: Active » Closed (works as designed)

The relevant code (if using filter tags) looks like this:

<?php
  return theme('image_display', $node, $label, file_create_url($node->images[$label]), $attributes);
?>

file_create_url() returns an absolute url. This is exactly the same thing as image.module does, and core modules such as user.module also output their images with absolute urls. However, the absolute urls can be rebuilt if the base url changes. Not sure if you just need to empty the cache of if you have to resave nodes though...

Or you can hack your own version of theme_image_display() and strip the base url.

So I guess this is by design. Please correct me and re-open the issue if I'm wrong.

mariagwyn’s picture

So, just to be clear: If i have to move my site, say from a dev/test location to a production location, the url for the image will change, without me having to do any crazy find/replace in my DB? If this is the case, then I am okay with it. But it looks to me as if the actual HTML inserted into a node is the absolute URL. Drupal will recognize this and change it? If it will really do this, then I am okay with it as is. Has anyone moved sites without a problem? Maybe drupal really is more powerful than I thought; I just assumed that once code was in the content of a node, drupal can't change it.

TobiasH’s picture

If i have to move my site, say from a dev/test location to a production location, the url for the image will change, without me having to do any crazy find/replace in my DB? If this is the case, then I am okay with it.

You are right! Drupal recognizes your site-location. In the past I had some bad behavior with img_assist while moving a site if I don't change the "Default url " in admin/settings/img_assist (drupal 4.7) to the new base url.

mariagwyn’s picture

Tobias: I thought the default URL in the admin/settings/img_assist was for the href that the inserted image referred to, not the source of the image. Is this not the case?

Zoo33: The following concerns me a little -

Not sure if you just need to empty the cache of if you have to resave nodes though...

.
If I move my site to a new URL (development to production), and I have to resave every node, that could be a problem. I guess I am still confused: does drupal read text embedded in a node (as img_assist is once inserted) and change the url? I have not easy way of testing this since the image files genuinely exist at both the development and production locations, so it could be pulling from either files folder.

TobiasH’s picture

mariagwyn: I'm sure about not reaserving every node. I've done the change of site-location a few times.

I thought the default URL in the admin/settings/img_assist was for the href that the inserted image referred to, not the source of the image. Is this not the case?

Yes, this is the case. After moving your site all fotos have the right path (to new_base/file folder). But I often used the option "refer to image" in my sites. You must change the "Default url" option. Then all images link (href) to the right image nodes.

zoo33’s picture

@mariagwyn: I wrote that since I wasn't 100% sure how the filter is applied to node content. I think you should be fine with just clearing the Drupal cache after such a move. I suggest you test this so you can know for sure.

mariagwyn’s picture

I forgot that I started this thread, and started another (http://drupal.org/node/109380). It does not appear that upon moving the site that the img_assist urls update. So, ideally, the url would be 'system/files/image.img' without the 'http://...'. The url is embedded in the node into which the image is placed, so there is no way that drupal would know to change the html within the node. Any way to fix this? I see the output in the function, but I can't change it. I have this in my phptemplate (changing some of the classes of the output):

 function phptemplate_img_assist_inline($node, $size, $attributes) {

  if ($attributes['title'] && $attributes['desc']) {
    $caption = '<span class="caption">' . $attributes['title'] . ': </span>' . '<span class="inset-caption">' . $attributes['desc'] . '</span>';
  } elseif ($attributes['title']) {
    $caption = '<span class="caption">' . $attributes['title'] . '</span>';
  } elseif ($attributes['desc']) {
  	$caption = '<span class="inset-caption">' . $attributes['desc'] . '</span>';
  }
  $node->title = strip_tags($caption); // change the node title because img_assist_display() uses the node title for alt and title
  $img_tag = img_assist_display($node, $size);

  if ( $attributes['align'] == "center" ) {
    $output = "<span class=\"inline {$attributes['align']}\" style=\"width: {$attributes['width']}px;\">";
  } else {
    $output  = "<span class=\"inline {$attributes['align']}\">";
  }
  $link = explode(',', $attributes['link']);

  if ($link[0] == 'node') {
    $output .= l($img_tag, "node/" . $node->nid, array(), NULL, NULL, FALSE, TRUE);

  } elseif ($link[0] == 'popup') {
    $popup_size = variable_get('img_assist_popup_label', 'preview');
    $info = image_get_info(file_create_path($node->images[$popup_size]));
    $width = $info['width'];
    $height = $info['height'];
    $output .= l($img_tag, '', array('onclick'=>"launch_popup($node->nid, $width, $height); return false;", 'target'=>'_blank'), NULL, NULL, FALSE, TRUE);

  } elseif ($link[0] == 'url') {
    $output .= l($img_tag, $attributes['url'], array(), NULL, NULL, FALSE, TRUE);
  } else {
    $output .= $img_tag;
  }

  if ($caption) {
    $info = image_get_info(file_create_path($node->images[$size['label']]));
    $width = $info['width'] - 2; // reduce the caption width slightly so the variable width of the text doesn't ever exceed the image width
    $output .= "<span class=\"img-assist-box\" style=\"width: {$width}px;\">$caption</span>";
  }
  $output .= "</span>";
  return $output;
}

Any ideas on how to change the 'url'? Thanks, Maria