function domain_prefix_domainpath in Domain Access 6.2
Implement hook_domainpath().
1 string reference to 'domain_prefix_domainpath'
- domain_prefix_domain_bootstrap_full in domain_prefix/
domain_prefix.module - Implementats hook_domain_bootstrap_full().
File
- domain_prefix/
domain_prefix.path.inc, line 13 - Implement hook_domainpath(). This is a resource-intensive function, so we only include it if an alias of the {url_alias} table is present.
Code
function domain_prefix_domainpath($domain_id, &$path, $path_language = NULL) {
global $language, $_domain;
// $map[$domain_id] keys are Drupal paths and the values are the corresponding aliases
static $map = array(), $count = array(), $status = array(), $tablename = array();
// If the alias is for the current domain, do nothing.
if ($domain_id == $_domain['domain_id']) {
$path = drupal_get_path_alias($path, $path_language);
return;
}
// Get a string for mapping the language lookup.
$language_map = !empty($path_language) ? $path_language : $language->language;
// The default domain does not use a prefix.
if ($domain_id == 0 && !isset($status[0])) {
$status[0] = db_table_exists('url_alias');
$tablename[0] = 'url_alias';
}
// Check to see if table prefixing has been done for the {url_alias} table.
if (!isset($status[$domain_id])) {
$prefix = domain_prefix_string($domain_id);
$status[$domain_id] = domain_prefix_table_exists($prefix, 'url_alias');
$tablename[$domain_id] = $prefix . 'url_alias';
}
if (!$status[$domain_id]) {
return;
}
// Use $count[$domain_id] to avoid looking up paths in subsequent calls if there are no aliases
if (!isset($count[$domain_id])) {
$count[$domain_id] = db_result(db_query('SELECT 1 FROM {%s}', $tablename[$domain_id]));
}
if ($count[$domain_id]) {
if (!isset($map[$domain_id][$language_map][$path])) {
$alias = db_result(db_query("SELECT dst FROM {%s} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC, pid DESC", $tablename[$domain_id], $path, $path_language));
$map[$domain_id][$language_map][$path] = $alias ? $alias : $path;
}
$path = $map[$domain_id][$language_map][$path];
}
}