You are here

function cdn_advanced_get_url in CDN 6

Gets the URL for a file when the basic mode is enabled.

Parameters

$path: The path to get the URL for.

1 call to cdn_advanced_get_url()
custom_file_url_rewrite in ./cdn.module

File

./cdn.module, line 366
Implementation of the core hooks, defines, public and private functions.

Code

function cdn_advanced_get_url($path) {
  $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(
      FALSE,
      FALSE,
    );
  }

  // Get the real path to the file (resolves symbolic links).
  $input_file = realpath('./' . $path);

  // Retrieve the URLs of the file on the CDN.
  $sql = "SELECT url, server FROM synced_files 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);

  // The file is not available from any server.
  if (count($servers) == 0) {
    $url = FALSE;
    $server = FALSE;
  }
  else {
    if (count($servers) > 1 && function_exists('cdn_advanced_pick_server')) {
      $picked_server = cdn_advanced_pick_server($servers);
      $url = $picked_server['url'];
      $server = $picked_server['server'];
    }
    else {
      $url = $servers[0]['url'];
      $server = $servers[0]['server'];
    }
  }
  return array(
    $url,
    $server,
  );
}