Hello, I'm using the insert module and am quite happy with it on my test site. I hope to create a site locally and upload it to the web. I've noticed when viewing the source in FCK that the image links created by insert are the full path of the site ie: "http://localhost/test/system/files/imagecache/story_image/images/some_im...". This obviously isn't going to be most convenient for migration purposes. I've tried looking through settings to see what I should change but no luck so far. Any help?

I hope I've gone about posting this request the proper way. Feel free to point me to some documentation I've missed and I'll study more myself. Thank you.

Comments

Title:Linking relevant to pathLinking with relative paths

The module developer has mentioned elsewhere that he has decided to use absolute paths to ensure that links don't break in rss feeds, etc...

To solve problems like the one you mention, he suggests to use the module pathologic. Using pathologic would enable you to have the image links updated when migrating from your local site to your remote one.

Just configure the pathologic filter to consider both remote and local links to be "local". See the pathologic handbook pages.

Status:Active» Fixed

The module developer has mentioned elsewhere that he has decided to use absolute paths to ensure that links don't break in rss feeds, etc...

To solve problems like the one you mention, he suggests to use the module pathologic. Using pathologic would enable you to have the image links updated when migrating from your local site to your remote one.

Just configure the pathologic filter to consider both remote and local links to be "local". See the pathologic handbook pages.

A themer asked me about this problem and I've decided to simply strip the HTTP_HOST out of the Fileurl. He can put the preprocess function for each module he wants to use in his template.php.

This avoids inserting absolute paths from the beginning - but makes it impossible to insert them as well. You should think about this before putting it into the template.php

/**
* Theme the content that will be inserted for ImageCache presets.
*/
function phptemplate_preprocess_imagecache_insert_image(&$vars) {
  $tmp = imagecache_create_url($vars['preset_name'], $vars['item']['filepath']);
  $uri = 'http://'. $_SERVER['HTTP_HOST'];
  $vars['url'] = str_replace($uri, '', $tmp);
  $vars['filepath'] = $vars['item']['filepath'];
  $vars['class'] = !empty($vars['widget']['insert_class']) ? $vars['widget']['insert_class'] : '';
}
/**
* Preprocess variables for the insert-image.tpl.php file.
*/
function phptemplate_preprocess_insert_image(&$vars) {
  $tmp = file_create_url($vars['item']['filepath']);
  $uri = 'http://'. $_SERVER['HTTP_HOST'];
  $vars['url'] = str_replace($uri, '', $tmp);
  $vars['class'] = !empty($vars['widget']['insert_class']) ? $vars['widget']['insert_class'] : '';
  $image_info = @image_get_info($vars['item']['filepath']);
  $vars['width'] = isset($image_info['width']) ? $image_info['width'] : '';
  $vars['height'] = isset($image_info['height']) ? $image_info['height'] : '';
}
/**
* Preprocess variables for the insert-link.tpl.php file.
*/
function phptemplate_preprocess_insert_link(&$vars) {
  $tmp = file_create_url($vars['item']['filepath']);
  $uri = 'http://'. $_SERVER['HTTP_HOST'];
  $vars['url'] = str_replace($uri, '', $tmp);
  $vars['class'] = !empty($vars['widget']['insert_class']) ? $vars['widget']['insert_class'] : '';
  $vars['name'] = $vars['item']['filename'];
}

It's a little problem for me too.

Why don't make it an option in Insert module settings ?
Administrater could decide for relative or absolute path.

Category:support» feature
Status:Fixed» Active

Well, let's open this as a feature request then. While I understand the reasoning of the module developer for using absolute paths, I don't agree with it. The Pathologic workaround could also be applied to the rss feeds instead. An additional problem I encountered when using the proposed pathologic workaround, is that while the paths to images are corrected in node view, they obviously aren't in node/*/edit view.

In the meantime, I will look at the template.php workaround. Thanks anschinsan!

Status:Active» Closed (duplicate)

Status:Closed (duplicate)» Needs review
StatusFileSize
new1.1 KB

wrote a patch to add the system settings in the UI.

Status:Needs review» Closed (won't fix)

I won't be adding a settings page for this option.

StatusFileSize
new1.28 KB

If you're wanting this feature in the 7.x branch and are stuck, I've attached a quick and dirty patch that will allow this for public:// stream wrappers. Remember to add this line to your settings.php:

<?php
$conf
['insert_absolute_paths'] = FALSE;
?>

subscribe

Version:6.x-1.x-dev» 7.x-1.x-dev

#9 appears to work for me. I am then also using Pathologic module with "/" also set to be considered local, so if I were to move my site to a subdirectory the src attribute would be reflected.

#9 works only if Drupal installation is in the root of the URL. It doesn't work if it is in sub-directory of web-root (e.g. site-url/drupal).

Also if pathauto is enabled, and the aliases start with content/*, so the URL becomes site-url/drupal/content/*. So, insert is adding drupal/content extra instead of directly starting from sites/default/files.

Then #9 probably needs to prepend

<?php
base_path
();
?>
on the url.

Status:Closed (won't fix)» Needs review
StatusFileSize
new1.29 KB

Adding to #9, if a site is in sub-directory (as per #12), just checked the checked the return value $url['path'] by strstr function.
Attaching a patch which might work.

Status:Needs review» Fixed
StatusFileSize
new750 bytes

Thanks guys, I don't know why I didn't think of an approach like this before. I've revised the code from these patches into a shorter version that should work with/without private files, on other non-standard schemes, and with/without clean URLs. The solution is so simple I can't believe I didn't think of it. Thanks all for your help on this one. Committed this patch to 7.x-1.x branch.

Status:Fixed» Closed (fixed)

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