'Login Destination', 'description' => 'Control where users are redirected to, once they login.', 'page callback' => 'drupal_get_form', 'page arguments' => array('login_destination_admin_settings'), 'access arguments' => array(LOGIN_DEST_PERM_ADMIN), 'type' => MENU_NORMAL_ITEM ); return $items; } function login_destination_admin_settings() { $form = array(); # on which pages we redirect $form['condition'] = array( '#type' => 'fieldset', '#title' => t('Redirection condition'), '#description' => t('When should redirection happen?') ); $form['condition']['ld_condition_type'] = array( '#type' => 'radios', '#default_value' => variable_get('ld_condition_type', 'always'), '#options' => array( LOGIN_COND_ALWAYS => t('Always'), LOGIN_COND_PAGES => t('List of paths'), LOGIN_COND_SNIPPET => t('PHP snippet (experts only)') ) ); $form['condition']['ld_condition_snippet'] = array( '#type' => 'textarea', '#default_value' => variable_get('ld_condition_snippet', ''), '#title' => t('Redirect condition: IMPORTANT! If using a WYSWYG editor - ensure that you use its plain text mode! There is a link below the text box.'), '#rows' => 4, '#description' => t('Always: Redirection happens always. Redirect condition field is ignored.'). '
' . t('List of paths mode: Enter a list of paths, one path per one line. Redirection will happen only when logging from specified pages. Example paths are %ex1 or %ex2.', array('%ex1' => 'contact', '%ex2' => 'user/login')). '
'. t('PHP snippet mode: Enter PHP code to find should redirection happen or not (NO %php tags!). It should return a boolean value.', array('%php' => '')) ); # to where we redirect $form['destination'] = array( '#type' => 'fieldset', '#title' => t('Destination URL settings'), '#description' => t('To where exactly should the user be redirected upon login.') ); $form['destination']['ld_destination'] = array( '#type' => 'checkbox', '#default_value' => variable_get('ld_destination', TRUE), '#title' => t('Preserve destination'), '#description' => t("If checked, 'destination=' parameter specified in the URL will be used to perform redirection. Otherwise, redirection will be always performed according to the settings below."), ); $form['destination']['ld_url_type'] = array( '#type' => 'radios', '#default_value' => variable_get('ld_url_type', LOGIN_DEST_STATIC), '#options' => array( LOGIN_DEST_STATIC => t('Static URL'), LOGIN_DEST_SNIPPET => t('PHP snippet (experts only)') ) ); $form['destination']['ld_url_destination'] = array( '#type' => 'textarea', '#default_value' => variable_get('ld_url_destination', 'user'), '#title' => t('URL: (IMPORTANT! If using a WYSWYG editor - ensure that you use its plain text mode! There is a link below the text box. )'), '#rows' => 4, '#description' => t('Static URL mode: Enter a static path. Example paths are %ex1 or %ex2.', array('%ex1' => 'node/add', '%ex2' => 'workspace')). '
'. t("PHP snippet mode: Enter PHP code to evaluate path (NO %php tags!). It should return either a string value or an array like in: return array('path' => 'node/add/video or alias', 'query' => 'param1=100¶m2=200');.", array('%php' => '')) ); return system_settings_form($form); } /** * Implementation of hook_user. */ function login_destination_user($op, &$edit, &$account, $category = NULL) { $url = NULL; if ($op == 'login') { global $language; $destination = variable_get('ld_url_destination', 'user'); if (variable_get('ld_url_type', LOGIN_DEST_STATIC) == LOGIN_DEST_SNIPPET) { ob_start(); $url = eval($destination); ob_end_clean(); } else { $url = $destination; } if (variable_get('ld_url_type', LOGIN_DEST_STATIC) == LOGIN_DEST_SNIPPET) { ob_start(); $url = eval($destination); ob_end_clean(); } else { $url = $destination; } if (is_array($url) && !empty($url['path'])) { $path = $url['path']; unset($url['path']); $base = base_path(); if (!empty($language->prefix)) { $base .= $language->prefix. '/'; } $url = str_replace($base, '', url($path, $url)); } if (login_destination_apply_redirect()) { $_REQUEST['destination'] = $url; } } } /** * A helper function to determine whether redirection should happen. * * @return bool TRUE - apply redirect, FALSE - not to apply redirect. */ function login_destination_apply_redirect() { if (!empty($_GET['destination']) && $_GET['destination'] != $_GET['q'] && variable_get('ld_destination', TRUE)) { return FALSE; } $mode = variable_get('ld_condition_type', LOGIN_COND_ALWAYS); if (LOGIN_COND_ALWAYS == $mode) { return TRUE; } else { $cond = variable_get('ld_condition_snippet', ''); if (LOGIN_COND_PAGES == $mode) { $paths = split("[\n\r]", $cond); return in_array($_GET['q'], $paths); } elseif (LOGIN_COND_SNIPPET == $mode) { // $destination = variable_get('ld_url_destination', 'user'); return drupal_eval(''); } } }