Index: includes/insert.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/insert/includes/insert.inc,v retrieving revision 1.1 diff -u -r1.1 insert.inc --- includes/insert.inc 21 Oct 2009 06:23:43 -0000 1.1 +++ includes/insert.inc 8 Jan 2010 18:55:47 -0000 @@ -42,7 +42,7 @@ * Preprocess variables for the insert-image.tpl.php file. */ function template_preprocess_insert_image(&$vars) { - $vars['url'] = file_create_url($vars['item']['filepath']); + $vars['url'] = insert_create_url($vars['item']['filepath']); $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'] : ''; @@ -53,7 +53,7 @@ * Preprocess variables for the insert-link.tpl.php file. */ function template_preprocess_insert_link(&$vars) { - $vars['url'] = file_create_url($vars['item']['filepath']); + $vars['url'] = insert_create_url($vars['item']['filepath']); $vars['class'] = !empty($vars['widget']['insert_class']) ? $vars['widget']['insert_class'] : ''; $vars['name'] = $vars['item']['filename']; } Index: includes/imagecache.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/insert/includes/imagecache.inc,v retrieving revision 1.1 diff -u -r1.1 imagecache.inc --- includes/imagecache.inc 21 Oct 2009 06:23:43 -0000 1.1 +++ includes/imagecache.inc 8 Jan 2010 18:55:47 -0000 @@ -32,7 +32,7 @@ * Theme the content that will be inserted for ImageCache presets. */ function template_preprocess_imagecache_insert_image(&$vars) { - $vars['filepath'] = $vars['item']['filepath']; - $vars['url'] = imagecache_create_url($vars['preset_name'], $vars['item']['filepath']); + $vars['filepath'] = imagecache_create_path($vars['preset_name'], $vars['item']['filepath']); + $vars['url'] = insert_create_url($vars['filepath']); $vars['class'] = !empty($vars['widget']['insert_class']) ? $vars['widget']['insert_class'] : ''; } Index: insert.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/insert/insert.module,v retrieving revision 1.1 diff -u -r1.1 insert.module --- insert.module 21 Oct 2009 06:23:43 -0000 1.1 +++ insert.module 8 Jan 2010 18:55:47 -0000 @@ -308,6 +308,34 @@ } /** + * Utility function to create a URL for Insert. + * + * This is modeled after file_create_url(), but with the modification that it + * will consistently use absolute or relative URLs, depending on the Insert + * setting. + */ +function insert_create_url($path) { + // Strip file_directory_path from $path. We only include relative paths in urls. + if (strpos($path, file_directory_path() .'/') === 0) { + $path = trim(substr($path, strlen(file_directory_path())), '\\/'); + } + + // This variable has no configuration location. It may be set by placing + // $conf['insert_absolute_paths'] = FALSE; + // in the site settings.php file, or by manually running variable_set(). + // For reasons why this might not do what you want and why there's no UI + // see http://drupal.org/node/640352. + $absolute = variable_get('insert_absolute_paths', TRUE); + + switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) { + case FILE_DOWNLOADS_PUBLIC: + return ($absolute ? $GLOBALS['base_url'] . '/' : $GLOBALS['base_path']) . file_directory_path() . '/' . str_replace('\\', '/', $path); + case FILE_DOWNLOADS_PRIVATE: + return url('system/files/' . $path, array('absolute' => $absolute)); + } +} + +/** * Preprocess variables for the insert-widget.tpl.php file. */ function template_preprocess_insert_widget(&$vars) {