You are here

function domain_get_content_urls in Domain Access 7.3

Get all possible published URLs pointing to a node.

Parameters

$node: A node object.

Return value

array An array of absolute URLs keyed by domain_id, with the canonical id as the first element of the array.

File

./domain.module, line 1901
Core module functions for the Domain Access suite.

Code

function domain_get_content_urls($node) {
  $urls = array();

  // If not set, return normal absolute url.
  if (empty($node->domains)) {
    $options['absolute'] = TRUE;
    $urls[] = url('node/' . $node->id, $options);
  }
  $weight = -100;
  foreach ($node->domains as $domain_id) {
    $domain = domain_load($domain_id);
    if (!$domain['valid']) {
      continue;
    }

    // Calculate the proper path to the node.
    $path = drupal_get_path_alias('node/' . $node->nid, $node->language);
    $options['language'] = $node->language;
    domain_path($domain_id, $path, $options, $path);
    $url = $domain['path'] . $path;

    // Order domains by weight.
    if ($domain['weight'] > $weight) {
      $new[$domain_id] = $url;
      $urls = $new + $urls;
    }
    else {
      $urls[$domain_id] = $url;
    }
    $weight = $domain['weight'];
  }

  // Determine the canonical URL and make it the first item.
  // This only comes into play if domain source is used.
  // Else we assume the first item in the array is canonical.
  if (isset($node->domain_source) && isset($urls[$node->domain_source])) {
    $canonical[$node->domain_source] = $urls[$node->domain_source];
    unset($urls[$node->domain_source]);
    $urls = $canonical + $urls;
  }
  return $urls;
}