diff --git a/imagecache.module b/imagecache.module index 743e90c..8bb3c2c 100644 --- a/imagecache.module +++ b/imagecache.module @@ -315,19 +315,22 @@ function imagecache_action_definition($action) { } /** - * Return a URL that points to the location of a derivative of the - * original image transformed with the given preset. + * Return a URL that points to the location of a derivative of the original + * image transformed with the given preset. * * Special care is taken to make this work with the possible combinations of * Clean URLs and public/private downloads. For example, when Clean URLs are not * available an URL with query should be returned, like - * http://example.com/?q=files/imagecache/foo.jpg, so that imagecache is able + * http://example.com/?q=files/imagecache/foo.jpg, so that ImageCache is able * intercept the request for this file. * - * This code is very similar to the Drupal core function file_create_url(), but + * This code began similarly to Drupal core's function file_create_url(), but * handles the case of Clean URLs and public downloads differently however. + * It also implements hook_file_url_alter() which was added to Drupal 7 and + * backported to PressFlow 6.x. * * @param $presetname + * String specifying an ImageCache preset name. * @param $filepath * String specifying the path to the image file. * @param $bypass_browser_cache @@ -338,16 +341,30 @@ function imagecache_action_definition($action) { * A Boolean indicating that the URL should be absolute. Defaults to TRUE. */ function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = FALSE, $absolute = TRUE) { - $path = _imagecache_strip_file_directory($filepath); - - $args = array('absolute' => $absolute, 'query' => empty($bypass_browser_cache) ? NULL : time()); - switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) { - case FILE_DOWNLOADS_PUBLIC: - $base = $absolute ? $GLOBALS['base_url'] .'/' : ''; - return url($base . file_directory_path() ."/imagecache/$presetname/$path", $args); - case FILE_DOWNLOADS_PRIVATE: - return url("system/files/imagecache/$presetname/$path", $args); + $args = array('query' => empty($bypass_browser_cache) ? NULL : time()); + $file_directory = file_directory_path(); + + // Determine the path of the derivative inside the files directory. + $derivative_path = 'imagecache/'. $presetname .'/'. _imagecache_strip_file_directory($filepath); + + // Then construct a full path and see if anyone wants to alter it. + $altered_path = $old_path = $file_directory .'/'. $derivative_path; + drupal_alter('file_url', $altered_path); + + // If any module has altered the path, then return the alteration... + if ($altered_path != $old_path) { + // ...but use url() so our $bypass_browser_cache parameter is honored. + return url($altered_path, $args); } + + // It was unchanged so use the download method's prefix. + $prefix = array( + FILE_DOWNLOADS_PUBLIC => $file_directory, + FILE_DOWNLOADS_PRIVATE => 'system/files', + ); + $path = $prefix[variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)] .'/'. $derivative_path; + + return url($path, $args + array('absolute' => $absolute)); } /**