You are here

function l10n_update_server in Localization update 7

Same name and namespace in other branches
  1. 6 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.

3 calls to l10n_update_server()
l10n_update_build_projects in ./l10n_update.project.inc
Rebuild project list
theme_l10n_update_single_project_status in ./l10n_update.admin.inc
Format a single project translation state.
theme_l10n_update_single_project_wrapper in ./l10n_update.admin.inc
Format project translation state with states per language.

File

./l10n_update.module, line 316
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 {
      module_load_include('parser.inc', 'l10n_update');
      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];
}