You are here

function textsize_check in Text Size 5

Same name and namespace in other branches
  1. 6 textsize.module \textsize_check()
  2. 7 textsize.module \textsize_check()

Check the cookie "textsize" value of changing (bye JavaScript) for anonymus user.

See also

textsize_set()

1 call to textsize_check()
textsize_init in ./textsize.module
Implement hook_init().

File

./textsize.module, line 115
Display a text size changer on the page for a better web accessibility.

Code

function textsize_check() {
  $cache = variable_get('cache', 0);
  $textsize_post = array();
  $textsize_cookie = array();
  $textsize_post['textsize'] = 0;

  // allowed values
  $textsize_allowed = textsize_allowed_values();

  // check the type and the content
  if (isset($_POST['textsize_select'])) {
    if (in_array($_POST['textsize_select'], $textsize_allowed)) {
      $textsize_post['textsize'] = 1;
    }
  }
  if (isset($_COOKIE['textsize'])) {
    if (in_array($_COOKIE['textsize'], $textsize_allowed)) {
      if (function_exists('filter_xss')) {
        $textsize_cookie['textsize'] = (int) filter_xss($_COOKIE['textsize']);
      }
      else {
        $textsize_cookie['textsize'] = $_COOKIE['textsize'];
      }
    }
  }

  // set session
  if ($cache == 1 && isset($_COOKIE['textsize']) && isset($_SESSION['textsize']) && $textsize_post['textsize'] == 0) {
    if ($textsize_cookie['textsize'] != $_SESSION['textsize']) {
      $_SESSION['textsize'] = $textsize_cookie['textsize'];
      if (function_exists('drupal_goto')) {
        $dest['0'] = drupal_get_destination();
        drupal_goto('textsize/set', $dest['0']);
      }
      else {
        textsize_clear_cache();
      }
    }
  }
}