--- path_redirect.module 2008-01-19 13:51:06.000000000 -0600
+++ path_redirect.module 2008-01-20 20:12:30.000000000 -0600
@@ -28,14 +28,45 @@ function path_redirect_help($section) {
*/
function path_redirect_init() {
// see if this page has a redirect path
+ // first we build an array of possible path entries for the current path
$query = '';
if (isset($_SERVER['QUERY_STRING'])) {
$query = preg_replace('/^q=([^&]*).*$/', '\1', $_SERVER['QUERY_STRING']);
}
- $r = db_fetch_object(db_query("SELECT redirect, query, fragment, type FROM {path_redirect} WHERE path = '%s' OR path = '%s'", $query, utf8_encode($query)));
+ $paths[] = $query;
+ $utf = utf8_encode($query); // the utf8 version
+ if ($utf != $query) {
+ $paths[] = $utf;
+ }
+ // then we stick '<*>' in each position and add those to the possibilities
+ $args = explode('/', $query);
+ foreach($args as $key => $val) {
+ $temp = $args;
+ $temp[$key] = '<*>';
+ $temp_path = implode('/', $temp);
+ if (!in_array($temp_path, $paths)) {
+ $paths[] = implode('/', $temp);
+ }
+ }
+ // sanitize everything
+ foreach ($paths as $key => $val) {
+ $paths[$key] = db_escape_string($val);
+ }
+ $r = db_fetch_object(db_query("SELECT path, redirect, query, fragment, type FROM {path_redirect} WHERE path IN ('". implode("','", $paths) ."') LIMIT 1"));
if ($r) {
+ if (strpos($r->path, '<*>') !== FALSE) {
+ //find the position of the wildcard
+ $rargs = explode('/', $r->path);
+ foreach ($rargs as $key => $val) {
+ if (strpos($val, '<*>') !== FALSE) {
+ $r->redirect = str_replace('<*>', $args[$key], $r->redirect);
+ $r->query = str_replace('<*>', $args[$key], $r->query);
+ $r->fragment = str_replace('<*>', $args[$key], $r->fragment);
+ break;
+ }
+ }
+ }
if (function_exists('drupal_goto')) {
- // if there's a result found, do the redirect
unset($_REQUEST['destination']);
drupal_goto($r->redirect, ($r->query ? $r->query: NULL), ($r->fragment ? $r->fragment : NULL), $r->type);
}
@@ -151,7 +182,7 @@ function path_redirect_admin($rid = FALS
$path,
check_url($redirect . $query . $fragment),
$types[$r->type]['title'],
- array('data' => l(t('test'), $r->path, array())),
+ array('data' => l(t('test'), preg_replace('/<\*>/', 'test', $r->path), array())),
array('data' => l(t('edit'), 'admin/build/path_redirect/edit/'. $r->rid)),
array('data' => l(t('delete'), 'admin/build/path_redirect/edit/'. $r->rid .'/delete')),
);
@@ -174,7 +205,10 @@ function path_redirect_edit($edit = arra
$form['path'] = array(
'#type' => 'textfield',
'#title' => t('From'),
- '#description' => t('Enter a Drupal path or path alias to redirect. Query strings ?foo=bar and fragment anchors #baz are not allowed.'),
+ '#description' => t('Enter a Drupal path or path alias to redirect. Query strings ?foo=bar and fragment anchors #baz are not allowed.
+ A single wildcard of <*> can be used as a distinct
+ path segment (separated by /).
+ Example: photos/<*>/large'),
'#maxlength' => 255,
'#default_value' => $edit['path'],
);
@@ -184,7 +218,14 @@ function path_redirect_edit($edit = arra
'#prefix' => '
<*> in any of these fields to have
+ the value of the wildcard appear in the redirected path.',
+ array('%front' => '