diff -ruN path_redirect.orig/path_redirect.admin.inc path_redirect/path_redirect.admin.inc --- path_redirect.orig/path_redirect.admin.inc 2008-03-08 03:10:02.000000000 +0100 +++ path_redirect/path_redirect.admin.inc 2008-10-01 11:39:47.000000000 +0200 @@ -2,6 +2,11 @@ // $Id: path_redirect.admin.inc,v 1.1.2.16 2008/03/08 02:10:02 horsepunchkid Exp $ /** + * @file + * Administrative page callbacks for the path_redirect module. + */ + +/** * Render a list of redirects for the main admin page. */ function path_redirect_admin($rid = FALSE) { @@ -117,7 +122,7 @@ $form['type'] = array( '#type' => 'fieldset', '#title' => t('Redirect Type'), - '#collapsible' => true, + '#collapsible' => TRUE, '#collapsed' => ($edit['type'] == PATH_REDIRECT_DEFAULT_TYPE), ); diff -ruN path_redirect.orig/path_redirect.install path_redirect/path_redirect.install --- path_redirect.orig/path_redirect.install 2008-04-14 05:29:32.000000000 +0200 +++ path_redirect/path_redirect.install 2008-10-01 11:38:43.000000000 +0200 @@ -2,6 +2,12 @@ // $Id: path_redirect.install,v 1.2.2.6.2.7 2008/04/14 03:29:32 horsepunchkid Exp $ /** + * @file + * Handles installation and updates for the path_redirect module. + * + */ + +/** * Implementation of hook_install(). */ function path_redirect_install() { @@ -95,7 +101,7 @@ update_sql("UPDATE {path_redirect} SET type = '304' WHERE type = 'HTTP/1.0 304 Not Modified'"); update_sql("UPDATE {path_redirect} SET type = '305' WHERE type = 'HTTP/1.0 305 Use Proxy'"); update_sql("UPDATE {path_redirect} SET type = '307' WHERE type = 'HTTP/1.0 307 Temporary Redirect'"); - // Now that we've got integers in the column, we change the column type - MySQL will convert values + // Now that we've got integers in the column, we change the column type - MySQL will convert values $ret = array(); db_change_field($ret, 'path_redirect', 'type', 'type', array( diff -ruN path_redirect.orig/path_redirect.module path_redirect/path_redirect.module --- path_redirect.orig/path_redirect.module 2008-03-08 02:10:17.000000000 +0100 +++ path_redirect/path_redirect.module 2008-10-01 11:42:57.000000000 +0200 @@ -1,11 +1,17 @@ '. 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.') .'

'; case 'admin/build/path-redirect/'. $arg[2]: case 'admin/build/path-redirect/edit/'. $arg[3]: - return '

'. t("The from path must be an internal Drupal path in the form of 'node/123', 'admin/logs', or 'taxonomy/term/123'. The to path can be either an internal Drupal path as above or a complete external URL such as http://www.example.com/. Furthermore, the to 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.") .'

'; + return '

'. t("The from path must be an internal Drupal path in the form of 'node/123', 'admin/reports', or 'taxonomy/term/123'. The to path can be either an internal Drupal path as above or a complete external URL such as http://www.example.com/. Furthermore, the to 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.") .'

'; } } /** - * Implementation of hook_init + * Implementation of hook_init(). * * Early checking of URL requested. * If a match is found, user is redirected using drupal_goto() */ function path_redirect_init() { // see if this page has a redirect path - $path = substr(request_uri(), strlen($GLOBALS['base_path'])); + $path = drupal_substr(request_uri(), drupal_strlen($GLOBALS['base_path'])); if (preg_match('/^\?q=/', $path)) { $path = preg_replace(array('/^\?q=/', '/&/'), array('', '?'), $path, 1); } @@ -59,7 +65,7 @@ } /** - * Implementation of hook_menu + * Implementation of hook_menu(). */ function path_redirect_menu() { $items['admin/build/path-redirect'] = array( @@ -105,7 +111,7 @@ ); $items['admin/settings/path-redirect'] = array( 'title' => 'URL redirects', - 'description' => t('Configure behavior for URL redirects'), + 'description' => 'Configure behavior for URL redirects', 'page callback' => 'drupal_get_form', 'page arguments' => array('path_redirect_settings'), 'access arguments' => array('administer redirects'), @@ -115,13 +121,34 @@ } /** - * Implementation of hook_perm + * Implementation of hook_perm(). */ function path_redirect_perm() { return array('administer redirects'); } function path_redirect_save($edit) { + + /** + * Start: Infinite redirection loop prevention + */ + //here we try to prevent writing records that redirect from path alias back to the raw url such as dst to src + //because globalredirect module redirects from src back to dst and that causes infinite loop + //since globalredirect does not have database tables through which this problem could be fixed, we try to fix it in here + $looping = FALSE; //whether this path redirect will cause infinite loop + $query = "SELECT * FROM {url_alias} u WHERE src = '%s' AND dst = '%s'"; + $result = db_query($query, $edit['redirect'], $edit['path']); + while ($infiloop = db_fetch_object($result)) { + $looping = TRUE; + continue ; //found what we were looking for. lets exit + } + if ($looping) { + return ; //prevent writing record that potentialy could cause an infinite redirecting loop + } + /** + * Finish: Infinite redirection loop prevention + */ + if (empty($edit['type'])) { $edit['type'] = PATH_REDIRECT_DEFAULT_TYPE; } @@ -190,6 +217,21 @@ } /** + * Implementing hook_cron() + * + */ +function path_redirect_cron() { + //perform periodic cleanup of paths that have potential to cause infinite redirection loop + //it is possible that with path_redirect_save changes, this could go into a hook_update_n + //because new looping records would not be written so a clean up should not have to be done more than once + $query = "SELECT rid FROM {url_alias} u INNER JOIN {path_redirect} p ON u.src = p.redirect AND p.path = u.dst"; + $result = db_query($query); + while ( $row = db_fetch_object($result)) { + path_redirect_delete(NULL, NULL, $row->rid); + } +} + +/** * This is a copy of drupal_goto() redesigned for use during the bootstrap */ function path_redirect_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302) {