You are here

function l10n_update_server in Localization update 6

Same name and namespace in other branches
  1. 7 l10n_update.module \l10n_update_server()

Get server information, that can come from different sources.

  • From server list provided by modules. They can provide full server information or just the url
  • From server_url in a project, we'll fetch latest data from the server itself

Parameters

string $name: Server name e.g. localize.drupal.org

string $url: Server url

boolean $refresh: TRUE = refresh the server data.

Return value

array Array of server data.

2 calls to l10n_update_server()
l10n_update_build_projects in ./l10n_update.project.inc
Rebuild project list
theme_l10n_update_project_status in ./l10n_update.admin.inc
Format project update status.

File

./l10n_update.module, line 332
Download translations from remote localization server.

Code

function l10n_update_server($name = NULL, $url = NULL, $refresh = FALSE) {
  static $info, $server_list;

  // Retrieve server list from modules
  if (!isset($server_list) || $refresh) {
    $server_list = module_invoke_all('l10n_servers');
  }

  // We need at least the server url to fetch all the information
  if (!$url && $name && isset($server_list[$name])) {
    $url = $server_list[$name]['server_url'];
  }

  // If we still don't have an url, cannot find this server, return false
  if (!$url) {
    return FALSE;
  }

  // Cache server information based on the url, refresh if asked
  $cid = 'l10n_update_server:' . $url;
  if ($refresh) {
    unset($info);
    cache_clear_all($cid, 'cache_l10n_update');
  }
  if (!isset($info[$url])) {
    if ($cache = cache_get($cid, 'cache_l10n_update')) {
      $info[$url] = $cache->data;
    }
    else {
      require_once 'l10n_update.parser.inc';
      if ($name && !empty($server_list[$name])) {

        // The name is in our list, it can be full data or just an url
        $server = $server_list[$name];
      }
      else {

        // This may be a new server provided by a module / package
        $server = array(
          'name' => $name,
          'server_url' => $url,
        );

        // If searching by name, store the name => url mapping
        if ($name) {
          $server_list[$name] = $server;
        }
      }

      // Now fetch server meta information form the server itself
      if ($server = l10n_update_get_server($server)) {
        cache_set($cid, $server, 'cache_l10n_update');
        $info[$url] = $server;
      }
      else {

        // If no server information, this will be FALSE. We won't search a server twice
        $info[$url] = FALSE;
      }
    }
  }
  return $info[$url];
}