| 1 |
<?php |
<?php |
| 2 |
// $Id: path_redirect.module,v 1.3.2.7.2.58 2009/11/04 06:00:11 davereid Exp $ |
// $Id: path_redirect.module,v 1.3.2.7.2.59 2009/11/04 06:29:09 davereid Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 212 |
} |
} |
| 213 |
|
|
| 214 |
/** |
/** |
| 215 |
|
* Validate a redirection. |
| 216 |
|
*/ |
| 217 |
|
function path_redirect_validate_redirect($redirect, $form_parents = '') { |
| 218 |
|
if (strpos($redirect['path'], '#') !== FALSE) { |
| 219 |
|
// Check that the "from" path is valid and contains no # fragment |
| 220 |
|
form_set_error($form_parents . 'path', t('The <strong>from</strong> path cannot use a fragment anchor.')); |
| 221 |
|
} |
| 222 |
|
|
| 223 |
|
//if (!valid_url($form_state['values']['path'])) { |
| 224 |
|
// //Make sure "from" has the form of a local Drupal path |
| 225 |
|
// form_set_error('path', t('The redirect <strong>from</strong> path does not appear valid. This must be a local Drupal path.')); |
| 226 |
|
//} |
| 227 |
|
|
| 228 |
|
if ($existing = path_redirect_load_by_path($redirect['path'], $redirect['language'])) { |
| 229 |
|
if ($redirect['rid'] != $existing['rid']) { |
| 230 |
|
// The "from" path should not conflict with another redirect |
| 231 |
|
form_set_error($form_parents . 'path', t('The <strong>from</strong> path %source is already being redirected. Do you want to <a href="@edit-page">edit the existing redirect</a>?', array('%source' => $redirect['path'], '@edit-page' => url('admin/build/path-redirect/edit/'. $existing['rid'])))); |
| 232 |
|
} |
| 233 |
|
} |
| 234 |
|
|
| 235 |
|
if ($pid = db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $redirect['path']))) { |
| 236 |
|
// A redirect's 'from' cannot match any values from url_alias, it will cause an infinite loop. |
| 237 |
|
form_set_error($form_parents . 'path', t('You cannot add an existing alias as a redirect as it will not work. You must <a href="@alias-delete">delete the alias</a> first.', array('@alias-delete' => url('admin/build/path/delete/' . $pid, array('query' => drupal_get_destination()))))); |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
if (menu_get_item($redirect['path'])) { |
| 241 |
|
form_set_error($form_parents . 'path', t('You cannot create a redirect from a currently valid path.')); |
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
if (!valid_url($redirect['redirect']) && !valid_url($redirect['redirect'], TRUE) && $redirect['redirect'] != '<front>') { |
| 245 |
|
form_set_error($form_parents . 'redirect', t('The redirect <strong>to</strong> path does not appear valid.')); |
| 246 |
|
} |
| 247 |
|
|
| 248 |
|
// check that there there are no redirect loops |
| 249 |
|
if (url($redirect['path']) == url($redirect['redirect'])) { |
| 250 |
|
form_set_error($form_parents . 'redirect', t('You are attempting to redirect the page to itself. This will result in an infinite loop.')); |
| 251 |
|
} |
| 252 |
|
} |
| 253 |
|
|
| 254 |
|
/** |
| 255 |
* Save an URL redirect to the database. |
* Save an URL redirect to the database. |
| 256 |
*/ |
*/ |
| 257 |
function path_redirect_save($redirect) { |
function path_redirect_save($redirect) { |