function cdn_advanced_get_servers in CDN 6.2
Same name and namespace in other branches
- 7.2 cdn.advanced.inc \cdn_advanced_get_servers()
Gets the servers on which a file is available when advanced mode is enabled.
Parameters
$path: The path to get the servers for.
1 call to cdn_advanced_get_servers()
- cdn_file_url_alter in ./
cdn.module - Implementation of hook_file_url_alter().
File
- ./
cdn.advanced.inc, line 18 - Logic for advanced mode ("File Conveyor mode" in the UI).
Code
function cdn_advanced_get_servers($path) {
static $absolute_path_prefix;
if (!isset($absolute_path_prefix)) {
$absolute_path_prefix = realpath('.');
}
$db = _cdn_advanced_get_db_connection();
// In case no connection to the database could be made, pretend the file was
// not found in the synced files database.
if (!$db) {
return array();
}
// Get the real path to the file.
// TRICKY: we used to do this here:
// $input_file = realpath('./' . $path);
// But this fails when a file has been deleted by File Conveyor. This new
// approach only works when no symbolic links are used.
$input_file = $absolute_path_prefix . '/' . $path;
// Retrieve the URLs of the file on the CDN.
$sql = "SELECT url, server\n FROM synced_files\n WHERE input_file = :input_file";
$stmt = $db
->prepare($sql);
$stmt
->bindParam(':input_file', $input_file, PDO::PARAM_STR);
$stmt
->execute();
$servers = $stmt
->fetchAll(PDO::FETCH_ASSOC);
return $servers;
}