Commit 371b1d0f authored by Dries's avatar Dries

- Patch #1025124 by catch, jbrown: remove cruft from theme_image_style() and...

- Patch #1025124 by catch, jbrown: remove cruft from theme_image_style() and image_style_url(). Should be faster too.
parent 0a722048
......@@ -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);
}
......
......@@ -154,13 +154,28 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase {
$this->_testImageStyleUrlAndPath('private');
}
/**
* 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.'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment