function domain_source_lookup in Domain Access 6.2
Same name and namespace in other branches
- 7.3 domain_source/domain_source.module \domain_source_lookup()
- 7.2 domain_source/domain_source.module \domain_source_lookup()
Find the proper source domain for a node.
Parameters
$nid: The node id.
$domains: An optional array of domain ids, which is present when this function is called from hook_nodeapi().
$domain_site: Optional flag indicating that the node is assigned to all domains.
$reset: Force a reset of the static data lookup.
Return value
The active source domain to use; an array returned by domain_lookup().
4 calls to domain_source_lookup()
- domain_source_domain_source_alter in domain_source/
domain_source.module - Implement hook_domain_source_node_alter().
- domain_source_nodeapi in domain_source/
domain_source.module - Implement hook_nodeapi()
- domain_source_validate in domain_source/
domain_source.module - Form validation step
- hook_domain_source_alter in ./
API.php - Allows modules to specify the target link for a node.
File
- domain_source/
domain_source.module, line 243 - Creates a source domain for linking to content from other domains.
Code
function domain_source_lookup($nid, $domains = array(), $domain_site = FALSE, $reset = FALSE) {
global $_domain;
static $lookups;
// Static cache.
if (!$reset && isset($lookups[$nid])) {
return $lookups[$nid];
}
$source = db_result(db_query("SELECT domain_id FROM {domain_source} WHERE nid = %d", $nid));
// Default source for nodes with no setting.
if ($source === FALSE) {
$source = variable_get('domain_default_source', 0);
}
// Global setting for 'do not change domain.'
if ($source == -1) {
$source = $_domain['domain_id'];
}
else {
if ($source == DOMAIN_SOURCE_USE_ACTIVE) {
$source = $_domain['domain_id'];
}
}
// When called from url_rewrite_outbound(), we have no data.
if (empty($domains)) {
$lookup = domain_get_node_domains($nid);
$domain_site = $lookup['domain_site'];
$domains = $lookup['domain_id'];
}
// domain_get_node_domains() returns the default (0) domain as -1, so we
// must transform it here before running a check.
$source = $source == 0 ? -1 : $source;
// If no valid source is found, take the first match from the $domains array.
if (empty($domain_site) && !empty($domains) && !in_array($source, $domains)) {
$source = current($domains);
}
// Convert the source id from -1 to 0 and run the lookup.
$domain_id = $source == -1 ? 0 : $source;
$lookups[$nid] = domain_lookup($domain_id);
return $lookups[$nid];
}