You are here

redirect_after_logout.module in Redirect after logout 7

Same filename and directory in other branches
  1. 8 redirect_after_logout.module

Redirect after logout - module file

File

redirect_after_logout.module
View source
<?php

/**
 * @file
 * Redirect after logout - module file
 */

/**
 * Implements hook_help().
 */
function redirect_after_logout_help($path, $arg) {
  switch ($path) {
    case 'admin/help#redirect_after_logout':
      return check_markup(file_get_contents(dirname(__FILE__) . "/README.txt"));
  }
}

/**
 * Implements hook_menu().
 */
function redirect_after_logout_menu() {
  $items['admin/config/system/redirect_after_logout'] = array(
    'title' => 'Redirect after logout',
    'description' => 'Redirect after logout settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'redirect_after_logout_settings_form',
    ),
    'access arguments' => array(
      'redirect after logout administer',
    ),
  );
  return $items;
}

/**
 * Implements hook_permission().
 */
function redirect_after_logout_permission() {
  return array(
    'redirect after logout administer' => array(
      'title' => t('Administer Redirect after logout'),
      'description' => t('Perform administration tasks for Redirect after logout.'),
    ),
    'redirect after logout user' => array(
      'title' => t('Redirect user after logout'),
      'description' => t('Redirect user after logout.'),
    ),
  );
}

/**
 * Implements hook_user_logout().
 */
function redirect_after_logout_user_logout($account) {
  if (user_access('redirect after logout user')) {
    $destination =& drupal_static(__FUNCTION__);
    $destination = token_replace(variable_get('redirect_after_logout_destination', ''));
  }
}

/**
 * Implements hook_drupal_goto_alter().
 */
function redirect_after_logout_drupal_goto_alter(&$path, &$options, &$http_response_code) {
  $destination =& drupal_static('redirect_after_logout_user_logout');
  if (!$path && $destination) {
    $options = array();
    $logout_message = variable_get('redirect_after_logout_message', '');
    if (!empty($logout_message)) {
      $options['query'] = array(
        'logout-message' => 1,
      );
    }
    drupal_goto($destination, $options);
  }
}

/**
 * Implements hook_page_build().
 */
function redirect_after_logout_page_build(&$page) {

  // Set logout message.
  if (!empty($_GET['logout-message']) && !user_is_logged_in()) {
    $logout_message = variable_get('redirect_after_logout_message', '');
    drupal_set_message(t(filter_xss(token_replace($logout_message))));
  }
  elseif (!empty($_GET['logout-message']) && user_is_logged_in()) {
    $destination = drupal_get_destination();
    $arg = arg();
    if (!empty($arg)) {
      $destination = implode('/', $arg);
    }
    drupal_goto($destination);
  }
}

/**
 * Settings form.
 */
function redirect_after_logout_settings_form() {
  $form = array();
  $form['redirect_after_logout_destination'] = array(
    '#type' => 'textfield',
    '#title' => t('Default user redirect destination'),
    '#description' => t('%front is the front page. Tokens are allowed.', array(
      '%front' => '<front>',
    )),
    '#default_value' => variable_get('redirect_after_logout_destination'),
  );
  $form['redirect_after_logout_message'] = array(
    '#type' => 'textfield',
    '#title' => t('Default user redirect message, after logout'),
    '#description' => t('Tokens are allowed.'),
    '#default_value' => variable_get('redirect_after_logout_message'),
  );
  if (module_exists('token')) {

    // Add the token help to a collapsed fieldset at the end of the configuration page.
    $form['token_help'] = array(
      '#type' => 'fieldset',
      '#title' => t('Available Tokens List'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['token_help']['content'] = array(
      '#theme' => 'token_tree',
      '#token_types' => array(),
    );
  }
  return system_settings_form($form);
}