function swftools_get_url_and_path in SWF Tools 6.3
Determines the url for a file, and expands its filepath if necessary.
This function is necessary because SWF Tools allows flexibility in how the site interprets filenames. If just a filename is provided then this might point to a file on the local system, or it might point to an external location if the remote media path is set. However, for things like auto-detection of sizes to work when the filename is local it must be expanded to include the file path.
If $file is a full and valid absolute url then the function returns $file on both keys.
If $file is full and valid url on the local system then the function returns $file on both keys.
If $file is a path to a local file (sites/default/files/xxx) then src_path will return this, and src will return a full relative url.
If $file is just a filename and remote media is active then src and src_path will both be set to the url for the external location.
If $file is just a filename and remote media is not active then src_path will return the path to the local system (so xxx becomes sites/default/files/xxx) and src will return the full relative url.
Parameters
string $file: A string containing a url or a path to a file.
Return value
array An array with two keys
- src: The url to the file (relative if on the local system)
- src_path: The path to the file, expanded if necessary
9 calls to swftools_get_url_and_path()
- hook_swftools_preprocess_PLAYER in docs/
swftools.php - Does the final preparation prior to rendering the specified player.
- swf in ./
swftools.module - Processes a file, or an array of files, and returns the relevant mark-up to render a Flash based player.
- swftools_flowplayer3_swftools_preprocess_flowplayer3 in flowplayer3/
swftools_flowplayer3.module - Implementation of hook_swftools_preprocess_[player]().
- swftools_flowplayer_swftools_playlist_flowplayer in flowplayer/
swftools_flowplayer.module - swftools_flowplayer_swftools_preprocess_flowplayer in flowplayer/
swftools_flowplayer.module - Implementation of hook_swftools_preprocess_[player]().
File
- ./
swftools.module, line 1520 - The primary component of SWF Tools that enables comprehensive media handling.
Code
function swftools_get_url_and_path($file) {
// src will contain a full, or relative, url that is used to render the file
// src_path will contain a partial path (without webroot), or the original file path
$ret = array(
'fileurl' => '',
'filepath' => $file,
);
// If already a valid absolute url simply return it
if (valid_url($file, TRUE)) {
$ret['fileurl'] = $file;
return $ret;
}
// If a valid url, and starts with /, then assume to be a local path relative to web root
// No security check is needed as the result of this is only output to the webpage
// We strip base_path from the file to create filepath that is valid for image_get_info later.
// FileField will create paths with spaces in - need to reverse that when testing for valid_url
$temp = str_replace(' ', '%20', $file);
// if (valid_url($file) && strpos($file, '/') === 0) {
if (valid_url($temp) && strpos($file, '/') === 0) {
return array(
'fileurl' => $file,
'filepath' => str_replace(base_path(), '', $file),
);
}
// If defintely in the local file system return a relative url to the file
if ($file == file_create_path($file)) {
// If media checking is active check to see if it actually exists
if (variable_get('swftools_check_media', TRUE)) {
// If the file doesn't exist, set an error message and return FALSE to indicate failure
if (!file_exists($file)) {
drupal_set_message(t('SWF Tools could not find %file.', array(
'%file' => $file,
)), 'error');
return FALSE;
}
}
// If we got here then return a relative url to the file
$ret['fileurl'] = swftools_create_url($file);
return $ret;
}
// Retrieve the media url setting
$media_url = trim(variable_get('swftools_media_url', ''));
// If a remote path is set build the appropriate url to the file
if ($media_url) {
$ret['fileurl'] = $media_url . '/' . $path;
return $ret;
}
// If we got here then expand to a local file path and call again
return swftools_get_url_and_path(file_create_path($file));
}