You are here

function domain_path_paths in Domain Path 6

Return an array of all paths.

We cache this for performance.

Parameters

$key: The type of data to return. Currently, 'nid' returns an array keyed by node id. 'alias' returns an array keyed by path alias.

$nid: A specific node id to return alias matches.

$reset: Boolean value to reset the static variable.

Return value

An array of matches.

4 calls to domain_path_paths()
domain_path_domainpath in ./domain_path.module
Implements hook_domainpath().
domain_path_form_alter in ./domain_path.module
Implements hook_form_alter().
domain_path_nodeapi in ./domain_path.module
Implements hook_nodeapi().
domain_path_url_inbound_alter in ./domain_path.module
Implements hook_url_inbound_alter().

File

./domain_path.module, line 102
Path alias handling for multiple domains.

Code

function domain_path_paths($key = 'nid', $nid = NULL, $reset = FALSE) {
  static $paths;

  // Cache routine. Only run this once.
  if (!isset($paths) || $reset) {

    // Try to get the data from cache.
    $cache = cache_get('domain_path');
    if (isset($cache->data)) {
      $paths = $cache->data;
    }

    // No cache, run the database query.
    if (!isset($paths)) {
      $paths = array(
        'nid' => array(),
        'alias' => array(),
      );

      // TODO: better handling for different entities.
      // TODO: Language support!
      $result = db_query("SELECT domain_id, source, alias, language, entity_type, entity_id FROM {domain_path} WHERE entity_type = 'node'");
      while ($path = db_fetch_object($result)) {
        $paths['nid'][$path->entity_id][$path->domain_id] = $path->alias;
        $paths['alias'][$path->alias][$path->domain_id] = $path->source;
      }

      // Cache for performance.
      // TODO: test.
      cache_set('domain_path', $paths);

      // Return data for a single node?
    }
  }

  // If returning results for a single node, pass back only matches.
  if (!is_null($nid)) {
    if (!isset($paths[$key][$nid])) {
      $paths[$key][$nid] = array();
    }
    return $paths[$key][$nid];
  }

  // Return requested data.
  return $paths[$key];
}