function file_aliases_preprocess_image in File Aliases 7
Implements hook_preprocess_image().
Parameters
$variables:
File
- ./
file_aliases.module, line 60 - Contains core functions for the File Aliases module.
Code
function file_aliases_preprocess_image(&$variables) {
if (isset($variables['style_name'])) {
$regex = ".*?files\\/styles\\/{$variables['style_name']}\\/(.*?)\\/(.*)";
if (defined('IMAGE_DERIVATIVE_TOKEN')) {
$regex .= '\\?(' . IMAGE_DERIVATIVE_TOKEN . '=\\S{8})';
}
if (preg_match("/{$regex}/", $variables['path'], $matches)) {
$fid = db_select('file_managed', 'f')
->fields('f', array(
'fid',
))
->condition('uri', "{$matches[1]}://{$matches[2]}")
->execute()
->fetchField();
if ($fid) {
$source = "file_aliases/{$fid}";
if (($alias = drupal_get_path_alias($source)) != $source) {
$variables['path'] = file_create_url($alias) . "?{$variables['style_name']}";
if (defined('IMAGE_DERIVATIVE_TOKEN')) {
$variables['path'] .= "&{$matches[3]}";
}
}
}
}
}
}