Active
Project:
Image Resize Filter
Version:
6.x-1.9
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
19 May 2011 at 12:35 UTC
Updated:
1 Aug 2012 at 18:04 UTC
It isnt major, but cdn support would be appreciated.
The combination of filefield, insert, image resize and cdn causes the following.
When a image is uploaded the cdn code kicks in. This alters the url that is insert into the editor. Which causes image resize to think the image is on a remote server. Even though the file is also available locally. I've adjusted the code a little bit to check for the CDN module and check for the cdn domains.
As im absolutely shit with patches ill just provide you the php code. Maybe somebody else can create a patch out of this.
image_resize_filter.module, function image_resize_filter_get_images, around line 303
//CDN check and implementation
$hosts = false;
$domains = array();
$domains[] = preg_quote($_SERVER['HTTP_HOST'], '/');
if(module_exists('cdn')) {
$cdn_domains = cdn_get_domains();
foreach ($cdn_domains as $cdn_domain) {
$cdn_domain = str_replace(array('http://','https://'), '', $cdn_domain);
$domains[] = preg_quote($cdn_domain, '/');
}
}
foreach ($domains as $domain) {
if(preg_match('/http[s]?:\/\/' . $domain . '/', $src)) {
$hosts = true;
}
}
// Determine if this is a local or remote file.
$location = 'unknown';
if (strpos($src, '/') === 0) {
$location = 'local';
}
elseif ($hosts) {
$location = 'local';
}
elseif (strpos($src, 'http') === 0) {
$location = 'remote';
}
// If not resizing images in this location, continue on to the next image.
if (!in_array($location, $settings['image_locations'])) {
continue;
}
// Convert the URL to a local path.
$local_path = NULL;
if ($location == 'local') {
// Remove the http:// and base path.
foreach ($domains as $domain) {
if(preg_match('/http[s]?:\/\/' . $domain . '/', $src)) {
$local_path = preg_replace('/(http[s]?:\/\/' . $domain . ')?' . preg_quote(base_path(), '/') . '/', '', $src, 1);
}
}
// Build a list of acceptable language prefixes.
$lang_codes = '';
if (in_array(variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE), array(LANGUAGE_NEGOTIATION_PATH, LANGUAGE_NEGOTIATION_PATH_DEFAULT))) {
$languages = language_list();
$lang_codes = array();
foreach ($languages as $key => $language) {
if ($language->prefix) {
$lang_codes[$key] = preg_quote($language->prefix, '!');
}
}
$lang_codes = $lang_codes ? '((' . implode('|', $lang_codes) . ')/)?' : '';
}
// Convert to a file system path if using private files.
if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE && preg_match('!^(\?q\=)?' . $lang_codes . 'system/files/!', $local_path)) {
$local_path = file_directory_path() . '/' . preg_replace('!^(\?q\=)?' . $lang_codes . 'system/files/!', '', $local_path);
}
$local_path = rawurldecode($local_path);
}
Comments
Comment #1
wim leersI think instead of having this kind of work-around, it makes much more sense to ensure that all file URLs in node bodies are not CDN'd (i.e. not file_url_alter()'d). They should only be altered upon viewing.