13
10
return '<p>'. t('Here you can set up URL redirecting for this site. Any existing or non-existing path within this site can redirect to any internal or external URL.') .'</p>';
14
11
case 'admin/build/path-redirect/'. $arg[2]:
15
12
case 'admin/build/path-redirect/edit/'. $arg[3]:
16
return '<p>'. t("The <strong>from</strong> path must be an internal Drupal path in the form of 'node/123', 'admin/logs', or 'taxonomy/term/123'. The <strong>to</strong> path can be either an internal Drupal path as above or a complete external URL such as http://www.example.com/. Furthermore, the <strong>to</strong> path may contain query arguments (such as 'page=2') and fragment anchors, to make it possible to redirect to 'admin/user?page=1#help'. Most redirects will not contain queries or anchors.") .'</p>';
13
return '<p>'. t("The <strong>from</strong> path must be an internal Drupal path in the form of 'node/123', 'admin/reports', or 'taxonomy/term/123'. The <strong>to</strong> path can be either an internal Drupal path as above or a complete external URL such as http://www.example.com/. Furthermore, the <strong>to</strong> path may contain query arguments (such as 'page=2') and fragment anchors, to make it possible to redirect to 'admin/user?page=1#help'. Most redirects will not contain queries or anchors.") .'</p>';
21
* Implementation of hook_init
18
* Implementation of hook_init().
23
20
* Early checking of URL requested.
24
21
* If a match is found, user is redirected using drupal_goto()
23
* @todo Massive revision needed. Split into sub-functions if necessary.
26
25
function path_redirect_init() {
27
26
// see if this page has a redirect path
28
$path = substr(request_uri(), strlen($GLOBALS['base_path']));
27
$path = substr(request_uri(), strlen(base_path()));
29
28
if (preg_match('/^\?q=/', $path)) {
30
29
$path = preg_replace(array('/^\?q=/', '/&/'), array('', '?'), $path, 1);
32
// Remove trailing slash from path.
33
$path = preg_replace('/\/\?|\/$/', '', $path);
32
35
$r = db_fetch_object(db_query("SELECT rid, redirect, query, fragment, type FROM {path_redirect} WHERE path = '%s' OR path = '%s'", $path, utf8_encode($path)));
34
37
$path = preg_replace('/\?.*/', '', $path);
35
38
$r = db_fetch_object(db_query("SELECT rid, redirect, query, fragment, type FROM {path_redirect} WHERE path = '%s' OR path = '%s'", $path, utf8_encode($path)));
38
// only redirect if allow_bypass is off or bypass is not requested
39
if ($r && !(variable_get('path_redirect_allow_bypass', 0) && !empty($_GET['redirect']) && $_GET['redirect'] == 'no') && url($r->redirect) != url($path)) {
40
if (variable_get('path_redirect_redirect_warning', 0)) {
41
drupal_set_message(t('This page has been moved. You may want to update your bookmarks.'));
43
if (function_exists('drupal_goto')) {
44
// if there's a result found, do the redirect
45
unset($_REQUEST['destination']);
46
drupal_goto($r->redirect, ($r->query ? $r->query: NULL), ($r->fragment ? $r->fragment : NULL), $r->type);
42
$redirect = url($r->redirect, array('query' => $r->query, 'fragment' => $r->fragment, 'absolute' => TRUE));
43
if (url($r->redirect) == url($path)) {
44
// Prevent infinite loop redirection.
45
watchdog('path_redirect', 'Redirect to <code>%redirect</code> is causing an infinite loop; redirect cancelled.', array('%redirect' => $r->redirect), WATCHDOG_WARNING, l(t('edit'), 'admin/build/path-redirect/edit/'. $r->rid));
47
elseif (variable_get('path_redirect_allow_bypass', 0) && isset($_GET['redirect']) && $_GET['redirect'] === 'no') {
48
// If the user has requested not to be redirected, show a message.
49
drupal_set_message(t('This page has been redirected to <a href="@redirect">@redirect</a>.', array('@redirect' => $redirect)));
51
elseif (variable_get('path_redirect_redirect_warning', 0)) {
52
drupal_set_message(t('This page has been moved to <a href="@redirect">@redirect</a> and will redirect in 5 seconds. You may want to update your bookmarks.', array('@redirect' => $redirect)), 'error');
53
drupal_set_html_head("<meta http-equiv=\"refresh\" content=\"5;url=$redirect\" />");
49
// page caching is turned on so drupal_goto() (common.inc) hasn't been loaded
50
path_redirect_goto($r->redirect, ($r->query ? $r->query: NULL), ($r->fragment ? $r->fragment : NULL), $r->type);
56
// @todo Clean the redirection code up. Do we need to duplicate code?
57
if (function_exists('drupal_goto')) {
58
// if there's a result found, do the redirect
59
unset($_REQUEST['destination']);
60
drupal_goto($r->redirect, $r->query, $r->fragment, $r->type);
63
// page caching is turned on so drupal_goto() (common.inc) hasn't been loaded
64
path_redirect_goto($r->redirect, $r->query, $r->fragment, $r->type);
53
else if ($r && url($r->redirect) == url($path)) {
54
watchdog('path_redirect', 'Redirect to <code>%redirect</code> is causing an infinite loop; redirect cancelled.', array('%redirect' => $r->redirect), WATCHDOG_WARNING, l(t('edit'), 'admin/build/path-redirect/edit/'. $r->rid));
56
else if ($r && variable_get('path_redirect_allow_bypass', 0) && !empty($_GET['redirect']) && $_GET['redirect'] === 'no') {
57
drupal_set_message(t('This page is redirected to:') .' <code>'. l($r->redirect, $r->redirect, array('query' => ($r->query ? $r->query: NULL), 'fragment' => ($r->fragment ? $r->fragment : NULL))) .'</code>');
62
* Implementation of hook_menu
71
* Implementation of hook_menu().
64
73
function path_redirect_menu() {
65
74
$items['admin/build/path-redirect'] = array(
118
* Implementation of hook_perm
127
* Implementation of hook_perm().
120
129
function path_redirect_perm() {
121
130
return array('administer redirects');
124
133
function path_redirect_save($edit) {
125
if (empty($edit['type'])) {
126
$edit['type'] = PATH_REDIRECT_DEFAULT_TYPE;
128
if (empty($edit['query'])) {
131
if (empty($edit['fragment'])) {
132
$edit['fragment'] = '';
135
'type' => variable_get('path_redirect_default_status', 301),
135
140
if (!empty($edit['rid'])) {
136
141
$return = db_query("UPDATE {path_redirect} SET path = '%s', redirect = '%s', query = '%s', fragment = '%s', type = %d WHERE rid = %d", $edit['path'], $edit['redirect'], $edit['query'], $edit['fragment'], $edit['type'], $edit['rid']);