You are here

function sweaver_session in Sweaver 6

Same name and namespace in other branches
  1. 7 sweaver.module \sweaver_session()

Session handler for sweaver.

Parameters

$value: The value hold by the session key.

$session_key: Name of the session key.

$action: Action to perform. TRUE will remove the session key.

$return_string: Whether to return the value of the session key as string or simply return the value.

Return value

Either FALSE, a value from the key or nothing.

11 calls to sweaver_session()
Sweaver::get_current_style in ./sweaver.inc
Return a style for a theme.
Sweaver::__construct in ./sweaver.inc
* Constructor. * Private constructor to make sure this is never * instantiated by the constructor.
sweaver_frontend in ./sweaver.module
Rock 'n' roll: the sweaver editor.
sweaver_plugin_images::sweaver_form_submit in plugins/sweaver_plugin_images/sweaver_plugin_images.inc
Frontend form submit handler.
sweaver_plugin_styles::sweaver_autosave in plugins/sweaver_plugin_styles/sweaver_plugin_styles.inc
Autosave post.

... See full list

File

./sweaver.module, line 432
Sweaver functions.

Code

function sweaver_session($value = NULL, $session_key = 'sweaver_editor_messages', $remove = FALSE, $return_string = TRUE) {

  // Add value to session key.
  if (isset($session_key) && isset($value) && !$remove) {
    if (!isset($_SESSION[$session_key])) {
      $_SESSION[$session_key] = array();
    }
    $_SESSION[$session_key][] = $value;
  }
  elseif (isset($_SESSION[$session_key]) && !isset($value) && $remove) {
    if (isset($_SESSION[$session_key])) {
      unset($_SESSION[$session_key]);
    }
  }
  elseif (isset($_SESSION[$session_key])) {
    if ($return_string) {
      $return = FALSE;
      $values = $_SESSION[$session_key];
      if (count($values) > 1) {
        foreach ($values as $key => $value) {
          $return .= $value . "\n";
        }
      }
      elseif (isset($values[0])) {
        $return = $values[0];
      }
      return $return;
    }
    else {
      return $_SESSION[$session_key];
    }
  }
}