--- path_redirect.install 2007-12-24 12:48:49.000000000 -0600 +++ path_redirect.install 2008-01-20 19:10:33.000000000 -0600 @@ -80,6 +80,15 @@ function path_redirect_update_3() { return $ret; } +/** + * Clear the menu cache since paths have changed. + */ +function path_redirect_update_4() { + cache_clear_all(NULL, 'cache_menu'); + drupal_set_message(t('Menu paths for the Path Redirect module have been updated.')); + return array(); +} + function path_redirect_uninstall() { db_query('DROP TABLE {path_redirect}'); switch ($GLOBALS['db_type']) { --- path_redirect.module 2008-01-19 13:51:06.000000000 -0600 +++ path_redirect.module 2008-01-20 18:48:31.000000000 -0600 @@ -7,14 +7,13 @@ if (module_exists('workflow_ng')) { /** * Implementation of hook_help - * */ function path_redirect_help($section) { switch ($section) { - case 'admin/build/path_redirect': + case 'admin/build/path-redirect': return 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): + 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.
"); } } @@ -24,7 +23,6 @@ function path_redirect_help($section) { * * 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 @@ -55,39 +53,44 @@ function path_redirect_menu($may_cache) $items = array(); if ($may_cache) { $items[] = array( - 'path' => 'admin/build/path_redirect', + 'path' => 'admin/build/path-redirect', 'title' => t('URL redirects'), 'access' => $access, 'callback' => 'path_redirect_admin', 'description' => t('Redirect users from one URL to another.'), ); $items[] = array( - 'path' => 'admin/build/path_redirect/list', + 'path' => 'admin/build/path-redirect/list', 'title' => t('List'), 'access' => $access, 'weight' => -3, 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items[] = array( - 'path' => 'admin/build/path_redirect/new', + 'path' => 'admin/build/path-redirect/add', 'title' => t('Add redirect'), 'access' => $access, + 'callback' => 'drupal_get_form', + 'callback arguments' => array('path_redirect_edit'), 'weight' => 2, 'type' => MENU_LOCAL_TASK, ); - } - else { - if (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'path_redirect' && arg(3) == 'edit') { - $items[] = array( - 'path' => 'admin/build/path_redirect/edit', - 'title' => t('Edit'), - 'access' => $access, - 'callback' => 'path_redirect_admin', - 'type' => MENU_LOCAL_TASK, - 'weight' => 9, - ); - } - + $items[] = array( + 'path' => 'admin/build/path-redirect/edit', + 'title' => t('Edit'), + 'access' => $access, + 'callback' => 'drupal_get_form', + 'callback arguments' => array('path_redirect_edit'), + 'type' => MENU_CALLBACK, + ); + $items[] = array( + 'path' => 'admin/build/path-redirect/delete', + 'title' => t('Delete'), + 'access' => $access, + 'callback' => 'drupal_get_form', + 'callback arguments' => array('path_redirect_delete_confirm'), + 'type' => MENU_CALLBACK, + ); } return $items; } @@ -100,38 +103,9 @@ function path_redirect_perm() { } /** - * Callback for administration pages - * - * @param $rid - * redirect id - * @param $op - * operation: delete - * @return - * themed output for page + * Render a list of redirects for the main admin page. */ -function path_redirect_admin($rid = FALSE, $op = FALSE) { - if ($rid) { - $breadcrumbs = array(l(t('Home'), '/'), l(t('Administer'), 'admin'), l(t('URL redirects'), 'admin/build/path_redirect')); - if ($rid == 'new') { - drupal_set_breadcrumb($breadcrumbs); - return drupal_get_form('path_redirect_edit'); - } - else { - $rid = db_escape_string($rid); - $redirect = path_redirect_load($rid); - if ($redirect && $op != 'delete') { - drupal_set_breadcrumb($breadcrumbs); - return drupal_get_form('path_redirect_edit', $redirect); - } - elseif ($redirect && $op == 'delete') { - return drupal_get_form('path_redirect_delete_confirm', $redirect); - } - else { - drupal_not_found(); - } - } - } - +function path_redirect_admin($rid = FALSE) { $header = array( array('data' => t('From'), 'field' => 'path', 'sort' => 'asc'), array('data' => t('To'), 'field' => 'redirect'), @@ -141,7 +115,7 @@ function path_redirect_admin($rid = FALS $result = pager_query('SELECT rid, path, redirect, query, fragment, type FROM {path_redirect}'. tablesort_sql($header), 50); $count = db_num_rows($result); - $types = path_redirect_error_list(); + $types = path_redirect_status_codes(); while ($r = db_fetch_object($result)) { $path = $r->path; $redirect = $r->redirect; @@ -152,8 +126,8 @@ function path_redirect_admin($rid = FALS check_url($redirect . $query . $fragment), $types[$r->type]['title'], array('data' => l(t('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')), + array('data' => l(t('edit'), 'admin/build/path-redirect/edit/'. $r->rid)), + array('data' => l(t('delete'), 'admin/build/path-redirect/delete/'. $r->rid)), ); } @@ -162,21 +136,40 @@ function path_redirect_admin($rid = FALS } $output = theme('table', $header, $rows, array('class' => 'path-redirects')); - $output .= ''. l(t('Add new redirect'), 'admin/build/path_redirect/new') .'
'; + $output .= ''. l(t('Add new redirect'), 'admin/build/path-redirect/add') .'
'; $output .= theme('pager'); return $output; } -function path_redirect_edit($edit = array('path' => '', 'redirect' => '', 'query' => '', 'fragment' => '', 'type' => '301', 'rid' => NULL)) { +/** + * Callback for add and edit pages. + * + * @return + * A form for drupal_get_form. + */ +function path_redirect_edit($rid = FALSE) { + if ($rid) { + $redirect = path_redirect_load($rid); + $output = path_redirect_edit_form($redirect); + } + else { + $output = path_redirect_edit_form(); + } + return $output; +} + +function path_redirect_edit_form($edit = array('path' => '', 'redirect' => '', 'query' => '', 'fragment' => '', 'type' => '301', 'rid' => NULL)) { $default_type = 301; $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.'), + '#size' => 50, '#maxlength' => 255, '#default_value' => $edit['path'], + '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q='), ); $form['redirect'] = array( @@ -227,7 +220,7 @@ function path_redirect_edit($edit = arra '#collapsed' => ($edit['type'] == $default_type), ); - foreach (path_redirect_error_list() as $key => $info) { + foreach (path_redirect_status_codes() as $key => $info) { $form['type'][]['type'] = array( '#type' => 'radio', '#title' => $info['title'], @@ -264,7 +257,7 @@ function path_redirect_edit_validate($fo // The "from" path should not conflict with another redirect $result = path_redirect_load(NULL, preg_replace('/[?#].*/', '', $form_values['path'])); if ($result && (!$form_values['rid'] || ($form_values['rid'] !== $result['rid']))) { - $path_error .= ' '. t('The from path you entered is already redirected. You can edit this redirect instead.', array('@edit-page' => url('admin/build/path_redirect/edit/'. $result['rid']))); + $path_error .= ' '. t('The from path you entered is already redirected. You can edit this redirect instead.', array('@edit-page' => url('admin/build/path-redirect/edit/'. $result['rid']))); } // Check that the "from" path is valid and contains no # or ? if (strstr($form_values['path'], '#')) { @@ -304,7 +297,7 @@ function path_redirect_edit_validate($fo function path_redirect_edit_submit($form_id, &$form_values) { path_redirect_save($form_values); drupal_set_message(t('Redirect has been saved.')); - drupal_goto('admin/build/path_redirect'); + drupal_goto('admin/build/path-redirect'); } function path_redirect_save($edit) { @@ -369,19 +362,19 @@ function path_redirect_delete($from = NU return $result; } -function path_redirect_delete_confirm($redirect) { +function path_redirect_delete_confirm($rid) { $form['rid'] = array( '#type' => 'value', - '#value' => check_plain($redirect['rid']), + '#value' => check_plain($rid), ); - $redirect = path_redirect_load($redirect['rid']); - return confirm_form($form, t('Are you sure you want to delete the redirect from %path to %redirect?', array('%path' => $redirect['path'], '%redirect' => $redirect['redirect'])), 'admin/build/path_redirect', NULL, t('Delete it!'), t('Cancel')); + $redirect = path_redirect_load($rid); + return confirm_form($form, t('Are you sure you want to delete the redirect from %path to %redirect?', array('%path' => $redirect['path'], '%redirect' => $redirect['redirect'])), 'admin/build/path-redirect', NULL, t('Delete it!'), t('Cancel')); } function path_redirect_delete_confirm_submit($form_id, $form_values) { path_redirect_delete(NULL, NULL, $form_values['rid']); drupal_set_message(t('Redirect item has been deleted.')); - drupal_goto('admin/build/path_redirect'); + drupal_goto('admin/build/path-redirect'); } /** @@ -419,11 +412,11 @@ function path_redirect_goto($path = '', } /** - * Return an array of 300-range error codes + * Return an array of 300-range status codes * placed here for clarity */ -function path_redirect_error_list() { - $errors = array( +function path_redirect_status_codes() { + $codes = array( 300 => array('title' => t('300 Multiple Choices'), 'description' => t('The request is ambiguous and needs clarification as to which resource was requested.')), 301 => array('title' => t('301 Moved Permanently'), 'description' => t('Moved Permanently. The resource has permanently moved elsewhere, the response indicates where it has gone to. Recommended.')), 302 => array('title' => t('302 Found'), 'description' => t('The resource has temporarily moved elsewhere, the response indicates where it is at present. This is Drupal\'s default redirect type.')), @@ -433,5 +426,5 @@ function path_redirect_error_list() { 307 => array('title' => t('307 Temporary Redirect'), 'description' => t('The resource has temporarily moved elsewhere, the response indicates where it is at present. Client should still use this URL.')), ); - return $errors; + return $codes; }