function url_redirect_page_build in Url Redirect 7
Implements hook_page_build().
File
- ./
url_redirect.module, line 85 - Adds URL Redirect and UI to set paths to redirect.
Code
function url_redirect_page_build(&$page) {
global $user;
$current_alias = drupal_get_path_alias();
// Check URL path in url_redirect table.
if (drupal_is_front_page()) {
$path = check_plain('<front>');
$path_check = url_redirect_path_check($path);
}
else {
$path = check_plain($_GET['q']);
$path_check = url_redirect_path_check($path);
}
// Get wildcards list.
$wildcard_list = url_redirect_get_wildcards();
// check for path matcher.
foreach ($wildcard_list as $delta => $list) {
$redirect = $list['redirect_path'];
if (drupal_match_path($current_alias, $list['path'])) {
// Do the redirect.
$path_check = url_redirect_path_check($list['path']);
break;
}
}
if ($path_check) {
$check_for = $path_check['check_for'];
$message = $path_check['message'];
if ($message == t('Yes')) {
drupal_set_message(t("You have been redirected to '@link_path'.", array(
'@link_path' => $path_check['redirect_path'],
)));
}
// Check for Role.
if ($check_for == t('Role')) {
$role_check = (array) json_decode($path_check['roles']);
$role_check_array = array_keys($role_check);
$user_role_check_array = array_keys($user->roles);
$checked_result = array_intersect($role_check_array, $user_role_check_array);
if ($checked_result) {
drupal_goto($path_check['redirect_path']);
}
}
elseif ($check_for == t('User')) {
$user_check = (array) json_decode($path_check['users']);
$user_check_array = array_keys($user_check);
$uid = array(
$user->uid,
);
$checked_user_result = array_intersect($user_check_array, $uid);
if ($checked_user_result) {
drupal_goto($path_check['redirect_path']);
}
}
}
}