function customerror_check_redirect in Customerror 7
Same name and namespace in other branches
- 5 customerror.module \customerror_check_redirect()
- 6 customerror.module \customerror_check_redirect()
Check list of redirects.
1 call to customerror_check_redirect()
- customerror_page in ./
customerror.module - Returns the content to display on the the 403 or 404 error page.
File
- ./
customerror.module, line 313 - Enables custom 404 (not found) and 403 (access denied) pages in Drupal.
Code
function customerror_check_redirect() {
if (isset($_GET['destination'])) {
$destination = $_GET['destination'];
}
if (empty($destination)) {
return;
}
$redirects = trim(variable_get('customerror_redirect', ''));
if (empty($redirects)) {
return;
}
$redirect_list = explode("\n", $redirects);
foreach ($redirect_list as $item) {
$pair = explode(' ', $item);
$src = trim($pair[0]);
if (isset($pair[1])) {
$dst = trim($pair[1]);
}
else {
$dst = NULL;
}
if (empty($src) || empty($dst)) {
$item = trim($item);
// Replace sp with nbsp.
$item = str_replace(' ', ' ', $item);
drupal_set_message(t('Malformet redirect <code>"@item"</code> in custom error 404 redirect list.', array(
'@item' => $item,
)), 'error');
}
else {
$src = str_replace("/", "\\/", $src);
// In case there are spaces in the URL, we escape them.
$orig_dst = str_replace(" ", "%20", $destination);
if (preg_match('/' . $src . '/', $orig_dst)) {
$_GET['destination'] = $dst;
drupal_goto($dst);
}
}
}
}