You are here

function pagestyle_set in Page Style 5

Same name and namespace in other branches
  1. 6 includes/pagestyle.block.inc \pagestyle_set()
  2. 7 includes/pagestyle.block.inc \pagestyle_set()

Menu callback; change the pagestyle to the cookie value, then redirects to the previous page.

1 string reference to 'pagestyle_set'
pagestyle_menu in ./pagestyle.module
Implement hook_menu().

File

includes/pagestyle.block.inc, line 130
Block, page and theme functions.

Code

function pagestyle_set() {
  $pagestyle_cookie_expires = pagestyle_cookie_expires($mode = 'php');
  $pagestyle_cookie_domain = variable_get('pagestyle_cookie_domain', base_path());
  $pagestyle_normal = variable_get('pagestyle_normal', 'standard');
  $pagestyle_text = array(
    'black_white' => t('Black') . '/' . t('White'),
    'white_black' => t('White') . '/' . t('Black'),
    'yellow_blue' => t('Yellow') . '/' . t('Blue'),
    'standard' => t('Standard'),
  );
  $pagestyle_message = variable_get('pagestyle_message', 1);
  $pagestyle_post = array();
  $pagestyle_cookie = array();

  // allowed values
  $pagestyle_allowed = pagestyle_allowed_values();

  // check the type and the content
  if (in_array($_COOKIE['pagestyle'], $pagestyle_allowed)) {
    $pagestyle_cookie['pagestyle'] = (string) filter_xss($_COOKIE['pagestyle']);
  }

  // set session/cookie
  if (!isset($_COOKIE['pagestyle']) && $pagestyle_message == 1) {
    drupal_set_message(t('The page style have not been saved, because your browser do not accept cookies.'), 'error');
  }
  elseif (isset($_COOKIE['pagestyle'])) {
    $_SESSION['pagestyle'] = $pagestyle_cookie['pagestyle'];
    setcookie("pagestyle", $pagestyle_cookie['pagestyle'], time() + $pagestyle_cookie_expires, $pagestyle_cookie_domain, "");
    if ($pagestyle_message == 1) {
      drupal_set_message(t('The page style have been saved as %pagestyle.', array(
        '%pagestyle' => $pagestyle_text[$pagestyle_cookie['pagestyle']],
      )));
    }
  }
  pagestyle_clear_cache();
  drupal_goto();
}