function path_redirect_goto in Path redirect 6
Same name and namespace in other branches
- 5 path_redirect.module \path_redirect_goto()
1 call to path_redirect_goto()
- path_redirect_init in ./
path_redirect.module - Implements hook_init().
1 string reference to 'path_redirect_goto'
- path_redirect_validate_source_field in ./
path_redirect.admin.inc - Validate a redirect's source path (from) field.
File
- ./
path_redirect.module, line 105
Code
function path_redirect_goto($redirect = NULL) {
if (!isset($redirect)) {
$path = path_redirect_get_path();
$language = $GLOBALS['language']->language;
$query = path_redirect_get_query();
$redirect = path_redirect_load_by_source($path, $language, $query);
}
elseif (is_numeric($redirect)) {
$redirect = path_redirect_load($redirect);
}
if ($redirect) {
// Create the absolute redirection URL.
$redirect['redirect_url'] = url($redirect['redirect'], array(
'query' => $redirect['query'],
'fragment' => $redirect['fragment'],
'absolute' => TRUE,
));
// Update the last used timestamp so that unused redirects can be purged.
db_query("UPDATE {path_redirect} SET last_used = %d WHERE rid = %d", time(), $redirect['rid']);
if (url($redirect['redirect']) == url($_GET['q'])) {
// Prevent infinite loop redirection.
watchdog('path_redirect', 'Redirect to <code>%redirect</code> is causing an infinite loop; redirect cancelled.', array(
'%redirect' => $redirect['redirect_url'],
), WATCHDOG_WARNING, l(t('Edit'), 'admin/build/path-redirect/edit/' . $redirect['rid']));
}
elseif (variable_get('path_redirect_allow_bypass', 0) && isset($_GET['redirect']) && $_GET['redirect'] === 'no') {
// If the user has requested not to be redirected, show a message.
drupal_set_message(t('This page has been moved to <a href="@redirect">@redirect</a>.', array(
'@redirect' => $redirect['redirect_url'],
)));
}
elseif (variable_get('path_redirect_redirect_warning', 0)) {
// Show a message and automatically redirect after 10 seconds.
drupal_set_message(t('This page has been moved to <a href="@redirect">@redirect</a>. You will be automatically redirected in 10 seconds.', array(
'@redirect' => $redirect['redirect_url'],
)), 'error');
drupal_set_html_head('<meta http-equiv="refresh" content="10;url=' . $redirect['redirect_url'] . '" />');
}
else {
// Perform the redirect.
unset($_REQUEST['destination']);
drupal_goto($redirect['redirect_url'], NULL, NULL, $redirect['type']);
}
}
// If this is being executed as a menu item, return a not found flag.
return MENU_NOT_FOUND;
}