'r4032login_redirect', 'access callback' => 'r4032login_access_callback', 'type' => MENU_CALLBACK, ); return $items; } /** * Without an access callback on the menu item for r4032login_redirect, * the redirect will be 403 and just have the default access denied page anyway. */ function r4032login_access_callback() { return TRUE; } /** * Implements hook_form_FORM_ID_alter(). */ function r4032login_form_system_site_information_settings_alter(&$form, &$form_state, $form_id) { $form['error_page']['r4032login_display_denied_message'] = array( '#type' => 'checkbox', '#weight' => -1, '#title' => t('Display access denied message on login page'), '#default_value' => variable_get('r4032login_display_denied_message', TRUE), ); return system_settings_form($form); } /** * Implements hook_theme(). */ function r4032login_theme() { return array( 'r4032login_denied' => array( 'variables' => array(), ), ); } /** * MENU_CALLBACK for /4032login * * Redirect anonymous users from 403 Access Denied pages to the /user/login page * with a message explaining that they must login to view the requested page * and a query string parameter appended to the url to return after login. */ function r4032login_redirect() { global $user, $language; if (user_is_anonymous()) { if (variable_get('r4032login_display_denied_message', TRUE)) { drupal_set_message(t('Access denied.'), 'error'); } $path = _r4032login_remove_language($_GET['destination']); // using drupal_goto() with destination set causes a recursive redirect loop header('Location: ' . url('user/login', array('query' => array('destination' => $path), 'absolute' => TRUE)), TRUE, 302); exit; } else { return drupal_set_page_content(theme('r4032login_denied')); } } /** * Special handling for sites that use localization. * * @see http://drupal.org/node/339120 */ function _r4032login_remove_language($destination) { $prefix = arg(0, $destination); $languages = language_list(); while (list(, $lang) = each($languages)) { if (strcasecmp($prefix, $lang->language) == 0) { return substr($destination, strlen($prefix) + 1); // remove prefix and slash } } return $destination; } /** * Display themed Access denied page. */ function theme_r4032login_denied() { drupal_set_title(t('Access denied')); return '
' . t('You are not authorized to access this page.') . '
'; }