diff options
author | Dries Buytaert <dries@buytaert.net> | 2011-02-04 19:43:25 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2011-02-04 19:43:25 +0000 |
commit | 371b1d0ff1db32050128fb0ab38adead0758859c (patch) | |
tree | 99dbac3a87a14861f9b4f5f4287912e8dfb362be /modules | |
parent | 0a7220483d2818d0cdb1da56cc6445e94bb4f37c (diff) | |
download | brdo-371b1d0ff1db32050128fb0ab38adead0758859c.tar.gz brdo-371b1d0ff1db32050128fb0ab38adead0758859c.tar.bz2 |
- Patch #1025124 by catch, jbrown: remove cruft from theme_image_style() and image_style_url(). Should be faster too.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/image/image.module | 31 | ||||
-rw-r--r-- | modules/image/image.test | 21 |
2 files changed, 32 insertions, 20 deletions
diff --git a/modules/image/image.module b/modules/image/image.module index bb2953142..0e4f55911 100644 --- a/modules/image/image.module +++ b/modules/image/image.module @@ -805,16 +805,18 @@ function image_style_flush($style) { * @see image_style_deliver() */ function image_style_url($style_name, $path) { - $scheme = file_uri_scheme($path); - if ($scheme === 'private') { - $target = file_uri_target($path); - $url = url('system/files/styles/' . $style_name . '/' . $scheme . '/' . $target, array('absolute' => TRUE)); + $uri = image_style_path($style_name, $path); + + // If not using clean URLs, the image derivative callback is only available + // with the query string. If the file does not exist, use url() to ensure + // that it is included. Once the file exists it's fine to fall back to the + // actual file path, this avoids bootstrapping PHP once the files are built. + if (!variable_get('clean_url') && file_uri_scheme($uri) == 'public' && !file_exists($uri)) { + $directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath(); + return url($directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE)); } - else { - $destination = image_style_path($style_name, $path); - $url = url(file_stream_wrapper_get_instance_by_scheme($scheme)->getDirectoryPath() . '/' . file_uri_target($destination), array('absolute' => TRUE)); - } - return $url; + + return file_create_url($uri); } /** @@ -1092,16 +1094,7 @@ function image_effect_apply($image, $effect) { * @ingroup themeable */ function theme_image_style($variables) { - $style_name = $variables['style_name']; - $path = $variables['path']; - - // The derivative image is not created until it has been requested so the file - // may not yet exist, in this case we just fallback to the URL. - $style_path = image_style_path($style_name, $path); - if (!file_exists($style_path)) { - $style_path = image_style_url($style_name, $path); - } - $variables['path'] = $style_path; + $variables['path'] = image_style_url($variables['style_name'], $variables['path']); return theme('image', $variables); } diff --git a/modules/image/image.test b/modules/image/image.test index 94e51ab6c..224548c81 100644 --- a/modules/image/image.test +++ b/modules/image/image.test @@ -155,12 +155,27 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase { } /** + * Test image_style_url() with the "public://" scheme and unclean URLs. + */ + function testImageStylUrlAndPathPublicUnclean() { + $this->_testImageStyleUrlAndPath('public', FALSE); + } + + /** + * Test image_style_url() with the "private://" schema and unclean URLs. + */ + function testImageStyleUrlAndPathPrivateUnclean() { + $this->_testImageStyleUrlAndPath('private', FALSE); + } + + /** * Test image_style_url(). */ - function _testImageStyleUrlAndPath($scheme) { + function _testImageStyleUrlAndPath($scheme, $clean_url = TRUE) { // Make the default scheme neither "public" nor "private" to verify the // functions work for other than the default scheme. variable_set('file_default_scheme', 'temporary'); + variable_set('clean_url', $clean_url); // Create the directories for the styles. $directory = $scheme . '://styles/' . $this->style_name; @@ -182,6 +197,10 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase { $this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.')); $generate_url = image_style_url($this->style_name, $original_uri); + if (!$clean_url) { + $this->assertTrue(strpos($generate_url, '?q=') !== FALSE, 'When using non-clean URLS, the system path contains the query string.'); + } + // Fetch the URL that generates the file. $this->drupalGet($generate_url); $this->assertResponse(200, t('Image was generated at the URL.')); |