function domain_invalid_domain_requested in Domain Access 7.2
Same name and namespace in other branches
- 6.2 domain.module \domain_invalid_domain_requested()
- 7.3 domain.module \domain_invalid_domain_requested()
Redirect a request to an invalid domain.
We were sent here from domain_init() because the user cannot view the requested domain.
Take the user to the best valid match, which is usually the primary domain. In the case of nodes, try to find another match.
Return value
No return. This function issues a drupal_goto();
1 call to domain_invalid_domain_requested()
- domain_init in ./
domain.module - Implements hook_init().
File
- ./
domain.module, line 2432 - Core module functions for the Domain Access suite.
Code
function domain_invalid_domain_requested() {
global $_domain, $user;
// Some users are allowed to view inactive domains.
if (user_access('access inactive domains')) {
return;
}
// Check to see if this is a node page. These are redirected to a visible page, if possible.
$node = menu_get_object();
if (empty($node->nid)) {
$item = menu_get_item();
$path = $item['href'];
if (drupal_is_front_page($item['href'])) {
$path = '';
}
$default = domain_default();
// Log the access attempt.
watchdog('domain', 'Invalid domain requested by %user on %domain; redirected to %default.', array(
'%user' => isset($user->name) ? $user->name : variable_get('anonymous', t('Anonymous')),
'%domain' => $_domain['sitename'],
'%default' => $default['sitename'],
), WATCHDOG_WARNING);
drupal_goto($default['path'] . drupal_get_path_alias($path));
}
// Try to find the proper redirect for a node.
$path = "node/{$node->nid}";
$domain = domain_get_node_match($node->nid);
if ($domain['valid']) {
$redirect = $domain;
}
elseif (!empty($node->domains)) {
foreach ($node->domains as $domain_id) {
if ($domain_id == -1) {
$domain_id = 0;
}
$domain = domain_lookup($domain_id);
if ($domain['valid']) {
$redirect = $domain;
break;
}
}
}
// If we found no node matches, just go to the home page.
$extra = ' ' . t('node page.');
if (empty($redirect)) {
$redirect = domain_default();
$path = '';
$extra = '.';
}
// Log the access attempt.
watchdog('domain', 'Invalid domain requested by %user on %domain, redirected to %redirect', array(
'%user' => isset($user->name) ? $user->name : variable_get('anonymous', t('Anonymous')),
'%domain' => $_domain['sitename'],
'%redirect' => $redirect['sitename'] . $extra,
), WATCHDOG_WARNING);
drupal_goto($redirect['path'] . drupal_get_path_alias($path));
}