function stage_file_proxy_process_file_uri in Stage File Proxy 7
Checks to see if a file should be downloaded from the origin site.
Parameters
string $uri: A fully-qualified file URI.
Return value
string|bool A string containing the new location to the file if it was downloaded, or FALSE if the file could not be processed with stage_file_proxy.
4 calls to stage_file_proxy_process_file_uri()
- drush_stage_file_proxy_dl in ./
stage_file_proxy.drush.inc - Download all managed files from the origin.
- stage_file_proxy_file_url_alter in ./
stage_file_proxy.module - Implements hook_file_url_alter().
- stage_file_proxy_init in ./
stage_file_proxy.module - Implements hook_init().
- stage_file_proxy_preprocess_picture in ./
stage_file_proxy.module - Implements hook_preprocess_HOOK() for theme_picture().
File
- ./
stage_file_proxy.module, line 411 - Stage File Proxy Module.
Code
function stage_file_proxy_process_file_uri($uri) {
// Prevent this function from being accidentally interpreted as a theme
// process hook (in which case the first parameter would be an array).
if (!is_string($uri)) {
return FALSE;
}
// There are cases when this is called for non-files, e.g. when someone does a
// file_create_url() for a dir, and stage_file_proxy_file_url_alter calls us.
// Anyway, whatever is there - maybe a symlink or some other odd ork - will
// break our logic anyway. So checking for file_exists() here.
if (file_uri_scheme($uri) === 'public' && !file_exists($uri)) {
$excluded_paths = array();
drupal_alter('stage_file_proxy_excluded_paths', $excluded_paths, $uri);
foreach ($excluded_paths as $excluded_path) {
if (strpos($uri, $excluded_path) !== FALSE) {
return FALSE;
}
}
// Path relative to file directory. Used for hotlinking.
$relative_path = file_uri_target($uri);
if ($proxy_url = stage_file_proxy_get_file_remote_url($relative_path)) {
// Is this imagecache? Request the root file and let imagecache resize.
// We check this first so locally added files have precedence.
$original_path = _stage_file_proxy_image_style_path_original($relative_path, TRUE);
if ($original_path) {
if (file_exists($original_path)) {
// image_style_deliver() can generate the derivative since the
// source file exists.
return FALSE;
}
if (variable_get('stage_file_proxy_use_imagecache_root', TRUE)) {
// Config says: Fetch the original.
// Attempt to download the source of the requested derivative image.
stage_file_proxy_fetch_file(file_uri_target($original_path));
// Do not change the file's URL since we want to still direct the
// user to the image style derivative, instead of the source image.
return FALSE;
}
}
// Check if hotlinking is enabled.
if (variable_get('stage_file_proxy_hotlink', FALSE)) {
return $proxy_url;
}
// It's an image original, no hotlinking, so just fetch.
if ($local = stage_file_proxy_fetch_file($relative_path)) {
// If the file was downloaded successfully, then set the path to the
// now local version of the file. This result is different since it
// will not include the public:// scheme prefix.
return $local;
}
}
}
return FALSE;
}