' . t('About') . ''; $output .= '
' . t('The Login Destination module allows you to customize the destination that the user is redirected to after logging in, registering to the site, using a one-time login link or logging out. The destination can be an internal page or an external URL. You may specify certain conditions like pages or user roles and make the destination depend upon them. You may also use a PHP snippets to provide custom conditions and destinations. Note that PHP Filter module has to be enabled and you have to be granted the "Use PHP for settings" permissions to be able to enter PHP code.') . '
'; return $output; case 'admin/config/people/login-destination': return '' . t('Login destination rules are evaluated each time a user logs in, registers to the site, uses a one-time login link or logs out. Each rule consists of the destination, path conditions and user roles conditions. First matching rule gets executed.') . '
'; } } /** * Implements hook_menu(). */ function login_destination_menu() { $items['admin/config/people/login-destination'] = array( 'title' => 'Login destinations', 'description' => 'Customize the destination that the user is redirected to after login.', 'page callback' => 'login_destination_overview', 'access arguments' => array('administer users'), 'file' => 'login_destination.admin.inc', 'weight' => 10, ); $items['admin/config/people/login-destination/add'] = array( 'title' => 'Add login destination rule', 'page callback' => 'drupal_get_form', 'page arguments' => array('login_destination_edit_form'), 'access arguments' => array('administer users'), 'type' => MENU_LOCAL_ACTION, 'weight' => 1, 'file' => 'login_destination.admin.inc', ); $items['admin/config/people/login-destination/edit/%login_destination'] = array( 'title' => 'Edit login destination rule', 'page callback' => 'drupal_get_form', 'page arguments' => array('login_destination_edit_form', 5), 'access arguments' => array('administer users'), 'file' => 'login_destination.admin.inc', ); $items['admin/config/people/login-destination/delete/%login_destination'] = array( 'title' => 'Delete login destination rule', 'page callback' => 'drupal_get_form', 'page arguments' => array('login_destination_delete_form', 5), 'access arguments' => array('administer users'), 'file' => 'login_destination.admin.inc', ); $items['admin/config/people/login-destination/list'] = array( 'title' => 'List', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items['admin/config/people/login-destination/settings'] = array( 'title' => 'Settings', 'description' => 'Change Login Destination settings.', 'page callback' => 'drupal_get_form', 'page arguments' => array('login_destination_settings'), 'access arguments' => array('administer users'), 'type' => MENU_LOCAL_TASK, 'file' => 'login_destination.admin.inc', 'weight' => 10, ); return $items; } /** * Load a login destination. */ function login_destination_load($id) { $result = db_select('login_destination', 'l') ->fields('l') ->condition('id', $id) ->execute() ->fetchAssoc(); $result['triggers'] = unserialize($result['triggers']); if (empty($result['triggers'])) { $result['triggers'] = array(); } $result['roles'] = unserialize($result['roles']); if (empty($result['roles'])) { $result['roles'] = array(); } return $result; } /** * Implements hook_theme */ function login_destination_theme() { return array( 'login_destination_destination' => array( 'variables' => array('destination' => NULL), 'file' => 'login_destination.admin.inc', ), 'login_destination_pages' => array( 'variables' => array('pages' => NULL, 'pages_type' => 0), 'file' => 'login_destination.admin.inc', ), 'login_destination_triggers' => array( 'variables' => array('items' => NULL), 'file' => 'login_destination.admin.inc', ), 'login_destination_roles' => array( 'variables' => array('items' => NULL), 'file' => 'login_destination.admin.inc', ), ); } /** * Implements hook_form_alter */ function login_destination_form_alter(&$form, &$form_state, $form_id) { // We redirect by using the drupal_goto_alter hook. If we simply // call drupal_goto() it may break compability with other modules. If we set // the $_GET['destination'] variable we will loose the possibility to redirect // to an external URL. // Please note the the system_goto_action() calls drupal_goto() // More on this issue http://drupal.org/node/732542. // If we add the $form_state['redirect'] here it will be overriden by the // user_login_submit(). So we add a submit handler instead and will set the // redirect later. Our submit handler will be executed after the execution // of user_login_submit(). This is because form_submit() functions are // appended to form before hook_form_alter() is executed. // We will execute also after LoginToboggan's function as it replaces the // original submit function from user module. switch ($form_id) { case 'user_register_form': // user register page case 'user_login': // user login page $form['#validate'][] = 'login_destination_validate'; break; } switch ($form_id) { case 'user_profile_form': // one-time login, password reset if (isset($_GET['pass-reset-token'])) { // Redirect only from user_pass_reset // You have to explicitally turn on the option to always redirect from // the profile page. This is for constistency. $form['#submit'][] = 'login_destination_submit'; break; } } } /** * Helper submit function. */ function login_destination_validate($form, &$form_state) { // LoginToboggan's unified page is rendered dynamically. Fix it. switch ($form['#form_id']) { case 'user_register_form': if (drupal_match_path($_GET['q'], 'user')) { $_GET['q'] = 'user/register'; } break; case 'user_login': if (drupal_match_path($_GET['q'], 'user/register')) { $_GET['q'] = 'user'; } break; } // Fix the current page in case of 403 page. if ($form['#form_id'] == 'user_login') { if(drupal_get_http_header('Status') == '403 Forbidden') { $_GET['current'] = $_GET['destination']; } } } /** * Helper submit function. */ function login_destination_submit($form, &$form_state) { login_destination_perform_redirect('login'); } /** * Implements hook_menu_link_alter */ function login_destination_menu_link_alter(&$item) { // Flag a link to be altered by hook_translated_menu_link_alter(). // This is called only on menu rebuild, so we have to add this information // manually to the database on install. Clearing caches also helps. $paths = array('user/logout', 'user/login', 'user'); if (in_array($item['link_path'], $paths)) { $item['options']['alter'] = TRUE; } } /** * Implements hook_translated_menu_link_alter */ function login_destination_translated_menu_link_alter(&$item, $map) { global $user; $paths = array('user/login', 'user'); // Append the current path to URL. if ($item['link_path'] == 'user/logout' || (in_array($item['link_path'], $paths) && user_is_anonymous())) { $item['localized_options']['query'] = array('current' => $_GET['q']); } } /** * Implements hook_page_alter */ function login_destination_page_alter(&$page) { // Substitute toolbar's pre_render function to change links. if (isset($page['page_top']['toolbar']['#pre_render'])) { $page['page_top']['toolbar']['#pre_render'][0] = 'login_destination_toolbar_pre_render'; } } /** * Helper function to change toolbar's links. */ function login_destination_toolbar_pre_render($toolbar) { $toolbar = toolbar_pre_render($toolbar); // Add current param to be able to evaluate previous page. $toolbar['toolbar_user']['#links']['logout']['query'] = array('current' => $_GET['q']); return $toolbar; } /** * Implements hook_user_login */ function login_destination_user_login(&$edit, $account) { if (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset' || variable_get('login_destination_immediate_redirect', FALSE)) { login_destination_perform_redirect('login'); } } /** * Implements hook_user_insert */ function login_destination_user_insert(&$edit, $account, $category) { global $user; if (!$user->uid) { // If the user is already logged in, it means probably that they create a // user account and not the user registers themselves. login_destination_perform_redirect('login'); } } /** * Implements hook_user_logout */ function login_destination_user_logout($account) { login_destination_perform_redirect('logout', _login_destination_get_current('logout')); } /** * Implements hook_drupal_goto_alter */ function login_destination_drupal_goto_alter(&$path, &$options, &$http_response_code) { // Note that this functionality cannot be backported do 6.x as Drupal 6 does // not call drupal_alter for drupal_goto. // This actually may be used also by templates. if (isset($GLOBALS['destination'])) { $destination = $GLOBALS['destination']; // alter drupal_goto if (is_array($destination)) { $path = $destination[0]; $options = array(); if (count($destination) > 1) { $options = $destination[1]; } } else { $path = $destination; } } } /** * Pass destination to drupal_goto. */ function login_destination_prepare_goto($destination) { // Check if $_GET['destination'] should overwrite us if (!isset($_GET['destination']) || !variable_get('login_destination_preserve_destination', FALSE)) { $GLOBALS['destination'] = $destination; } } /** * Evaluate rules and perform redirect. * This function is intended to be used by external modules. * @param