- Patch #1025124 by catch, jbrown: remove cruft from theme_image_style() and image_style_url(). Should be faster too.
parent
0a7220483d
commit
371b1d0ff1
|
@ -805,16 +805,18 @@ function image_style_flush($style) {
|
||||||
* @see image_style_deliver()
|
* @see image_style_deliver()
|
||||||
*/
|
*/
|
||||||
function image_style_url($style_name, $path) {
|
function image_style_url($style_name, $path) {
|
||||||
$scheme = file_uri_scheme($path);
|
$uri = image_style_path($style_name, $path);
|
||||||
if ($scheme === 'private') {
|
|
||||||
$target = file_uri_target($path);
|
// If not using clean URLs, the image derivative callback is only available
|
||||||
$url = url('system/files/styles/' . $style_name . '/' . $scheme . '/' . $target, array('absolute' => TRUE));
|
// 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);
|
return file_create_url($uri);
|
||||||
$url = url(file_stream_wrapper_get_instance_by_scheme($scheme)->getDirectoryPath() . '/' . file_uri_target($destination), array('absolute' => TRUE));
|
|
||||||
}
|
|
||||||
return $url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1092,16 +1094,7 @@ function image_effect_apply($image, $effect) {
|
||||||
* @ingroup themeable
|
* @ingroup themeable
|
||||||
*/
|
*/
|
||||||
function theme_image_style($variables) {
|
function theme_image_style($variables) {
|
||||||
$style_name = $variables['style_name'];
|
$variables['path'] = image_style_url($variables['style_name'], $variables['path']);
|
||||||
$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;
|
|
||||||
return theme('image', $variables);
|
return theme('image', $variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,13 +154,28 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase {
|
||||||
$this->_testImageStyleUrlAndPath('private');
|
$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().
|
* Test image_style_url().
|
||||||
*/
|
*/
|
||||||
function _testImageStyleUrlAndPath($scheme) {
|
function _testImageStyleUrlAndPath($scheme, $clean_url = TRUE) {
|
||||||
// Make the default scheme neither "public" nor "private" to verify the
|
// Make the default scheme neither "public" nor "private" to verify the
|
||||||
// functions work for other than the default scheme.
|
// functions work for other than the default scheme.
|
||||||
variable_set('file_default_scheme', 'temporary');
|
variable_set('file_default_scheme', 'temporary');
|
||||||
|
variable_set('clean_url', $clean_url);
|
||||||
|
|
||||||
// Create the directories for the styles.
|
// Create the directories for the styles.
|
||||||
$directory = $scheme . '://styles/' . $this->style_name;
|
$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.'));
|
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
|
||||||
$generate_url = image_style_url($this->style_name, $original_uri);
|
$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.
|
// Fetch the URL that generates the file.
|
||||||
$this->drupalGet($generate_url);
|
$this->drupalGet($generate_url);
|
||||||
$this->assertResponse(200, t('Image was generated at the URL.'));
|
$this->assertResponse(200, t('Image was generated at the URL.'));
|
||||||
|
|
Loading…
Reference in New Issue