Index: path_redirect.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/path_redirect/Attic/path_redirect.admin.inc,v retrieving revision 1.1.2.21 diff -u -p -r1.1.2.21 path_redirect.admin.inc --- path_redirect.admin.inc 27 Jan 2009 19:30:56 -0000 1.1.2.21 +++ path_redirect.admin.inc 27 Feb 2009 22:00:04 -0000 @@ -82,7 +82,14 @@ function path_redirect_edit_form(&$form_ '#default_value' => $edit['path'], '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), ); - + + $form['wildcard'] = array( + '#type' => 'checkbox', + '#title' => t('Wildcard'), + '#description' => t('Allow all URLs with the path defined above as a base to be redirected. For example, if you set the path as "foo", paths such as "foo/bar/baz" or "foo/baz" will be redirected.'), + '#default_value' => $edit['wildcard'], + ); + $form['redirect'] = array( '#type' => 'item', '#prefix' => '
', Index: path_redirect.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/path_redirect/path_redirect.install,v retrieving revision 1.2.2.6.2.11 diff -u -p -r1.2.2.6.2.11 path_redirect.install --- path_redirect.install 27 Jan 2009 19:14:12 -0000 1.2.2.6.2.11 +++ path_redirect.install 27 Feb 2009 22:00:04 -0000 @@ -68,6 +68,12 @@ function path_redirect_schema() { 'not null' => TRUE, 'description' => 'The HTTP status code to use for the redirect.', ), + 'wildcard' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => FALSE, + 'description' => 'Does this redirect support wildcards.', + ), ), 'primary key' => array('rid'), 'unique keys' => array('path' => array('path')), Index: path_redirect.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/path_redirect/path_redirect.module,v retrieving revision 1.3.2.7.2.20 diff -u -p -r1.3.2.7.2.20 path_redirect.module --- path_redirect.module 27 Jan 2009 19:17:00 -0000 1.3.2.7.2.20 +++ path_redirect.module 27 Feb 2009 22:00:04 -0000 @@ -31,14 +31,42 @@ function path_redirect_init() { // Remove trailing slash from path. $path = preg_replace('/\/\?|\/$/', '', $path); - - $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))); + + $r = db_fetch_object(db_query("SELECT rid, redirect, query, fragment, type, wildcard FROM {path_redirect} WHERE path = '%s' OR path = '%s'", $path, utf8_encode($path))); + if (!$r) { $path = preg_replace('/\?.*/', '', $path); - $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))); + $r = db_fetch_object(db_query("SELECT rid, redirect, query, fragment, type, wildcard FROM {path_redirect} WHERE path = '%s' OR path = '%s'", $path, utf8_encode($path))); } - + + if (!$r) { + // wildcard matching + $wildcard = FALSE; + $args = explode('/', $path); + + foreach ($args as $arg) { + // remove recursively the last argument to fin a match + array_pop($args); + $q = implode('/', $args) ; + + $r = db_fetch_object(db_query("SELECT rid, redirect, query, fragment, type, wildcard FROM {path_redirect} WHERE path = '%s' OR path = '%s'", $q, utf8_encode($q))); + + if($r->wildcard == 1) { + // we have a query that matches our URL and has a wildcard + $wildcard = TRUE; + break; + } + } + } + if ($r) { + if ($wildcard) { + // rebuilds the redirect URL + $redirect_prefix = implode('/', $args); + $redirect_suffix = explode($redirect_prefix, $path); + $r->redirect .= $redirect_suffix[1]; + } + $redirect = url($r->redirect, array('query' => $r->query, 'fragment' => $r->fragment, 'absolute' => TRUE)); if (url($r->redirect) == url($path)) { // Prevent infinite loop redirection. @@ -138,10 +166,10 @@ function path_redirect_save($edit) { ); if (!empty($edit['rid'])) { - $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']); + $return = db_query("UPDATE {path_redirect} SET path = '%s', redirect = '%s', query = '%s', fragment = '%s', type = %d, wildcard = %d WHERE rid = %d", $edit['path'], $edit['redirect'], $edit['query'], $edit['fragment'], $edit['type'], $edit['rid'], $edit['wildcard']); } else { - $return = db_query("INSERT INTO {path_redirect} (path, redirect, query, fragment, type) VALUES ('%s', '%s', '%s', '%s', '%s')", $edit['path'], $edit['redirect'], $edit['query'], $edit['fragment'], $edit['type']); + $return = db_query("INSERT INTO {path_redirect} (path, redirect, query, fragment, type, wildcard) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $edit['path'], $edit['redirect'], $edit['query'], $edit['fragment'], $edit['type'], $edit['wildcard']); } return $return; } @@ -151,10 +179,10 @@ function path_redirect_save($edit) { */ function path_redirect_load($rid = NULL, $from = NULL) { if (!empty($rid)) { - $result = db_fetch_array(db_query("SELECT rid, path, redirect, query, fragment, type FROM {path_redirect} WHERE rid = %d", $rid)); + $result = db_fetch_array(db_query("SELECT rid, path, redirect, query, fragment, type, wildcard FROM {path_redirect} WHERE rid = %d", $rid)); } elseif (!empty($from)) { - $result = db_fetch_array(db_query("SELECT rid, path, redirect, query, fragment, type FROM {path_redirect} WHERE path = '%s'", $from)); + $result = db_fetch_array(db_query("SELECT rid, path, redirect, query, fragment, type, wildcard FROM {path_redirect} WHERE path = '%s'", $from)); } return $result; }