Start moving some framework stuff to Horde_Session.
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 8 Oct 2010 22:55:33 +0000 (16:55 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sat, 9 Oct 2010 07:30:31 +0000 (01:30 -0600)
framework/Alarm/lib/Horde/Alarm.php
framework/Block/lib/Horde/Block/Collection.php
framework/Core/lib/Horde.php
framework/Core/lib/Horde/Core/Prefs/Ui.php
framework/Form/Form.php

index c5a8365..bf14631 100644 (file)
@@ -109,8 +109,11 @@ abstract class Horde_Alarm
      */
     public function load($user = null, $preload = true)
     {
-        if (isset($_SESSION['horde']['alarm']['loaded']) &&
-            (time() - $_SESSION['horde']['alarm']['loaded']) < $this->_params['ttl']) {
+        // TODO: This must be moved to horde/Core.
+        global $session;
+
+        if (isset($session['horde:alarm_loaded']) &&
+            (time() - $session['horde:alarm_loaded']) < $this->_params['ttl']) {
             return;
         }
 
@@ -132,8 +135,7 @@ abstract class Horde_Alarm
 
             /* Load current alarms if no preloading requested or if this
              * is the first call in this session. */
-            if (!$preload ||
-                !isset($_SESSION['horde']['alarm']['loaded'])) {
+            if (!$preload || !$session['horde:alarm_loaded']) {
                 try {
                     $app_alarms = $GLOBALS['registry']->callByPackage($app, 'listAlarms', array(time(), $user), array('noperms' => true));
                 } catch (Horde_Exception $e) {
@@ -150,7 +152,7 @@ abstract class Horde_Alarm
             }
         }
 
-        $_SESSION['horde']['alarm']['loaded'] = time();
+        $session['horde:alarm_loaded'] = time();
     }
 
     /**
index 61b7e58..9e6b1f4 100644 (file)
@@ -63,9 +63,10 @@ class Horde_Block_Collection
      */
     public function __construct($apps = array())
     {
+        global $session;
+
         $signature = serialize($apps);
-        if (isset($_SESSION['horde']['blocks'][$signature])) {
-            $this->_blocks = &$_SESSION['horde']['blocks'][$signature];
+        if ($this->_blocks = $session['horde:blocks/' . $signature]) {
             return;
         }
 
@@ -107,7 +108,7 @@ class Horde_Block_Collection
         }
 
         uksort($this->_blocks, array($this, 'sortBlockCollection'));
-        $_SESSION['horde']['blocks'][$signature] = &$this->_blocks;
+        $session['horde:blocks/' . $signature] = $this->_blocks;
     }
 
     /**
index 8414863..13e297c 100644 (file)
@@ -356,7 +356,8 @@ HTML;
     static public function getRequestToken($slug)
     {
         $token = Horde_Token::generateId($slug);
-        $_SESSION['horde_form_secrets'][$token] = time();
+        $GLOBALS['session']['horde:form_secrets/' . $token] = time();
+
         return $token;
     }
 
@@ -370,11 +371,13 @@ HTML;
      */
     static public function checkRequestToken($slug, $token)
     {
-        if (empty($_SESSION['horde_form_secrets'][$token])) {
+        global $conf, $session;
+
+        if (!isset($session['horde:form_secrets/' . $token])) {
             throw new Horde_Exception(_("We cannot verify that this request was really sent by you. It could be a malicious request. If you intended to perform this action, you can retry it now."));
         }
 
-        if (($_SESSION['horde_form_secrets'][$token] + $GLOBALS['conf']['urls']['token_lifetime'] * 60) < time()) {
+        if (($session['horde:form_secrets/' . $token] + $GLOBALS['conf']['urls']['token_lifetime'] * 60) < time()) {
             throw new Horde_Exception(sprintf(_("This request cannot be completed because the link you followed or the form you submitted was only valid for %s minutes. Please try again now."), $GLOBALS['conf']['urls']['token_lifetime']));
         }
     }
index b6ee271..8060efa 100644 (file)
@@ -157,7 +157,7 @@ class Horde_Core_Prefs_Ui
                 if (!$GLOBALS['prefs']->isLocked($pref) &&
                     !in_array($pref, $this->suppress) &&
                     (empty($this->prefs[$pref]['advanced']) ||
-                     !empty($_SESSION['horde_prefs']['advanced'])) &&
+                     $GLOBALS['session']['horde:prefs_advanced']) &&
                     ((!empty($this->prefs[$pref]['type']) &&
                      ($this->prefs[$pref]['type'] != 'implicit')))) {
                     $prefs[] = $pref;
@@ -177,7 +177,7 @@ class Horde_Core_Prefs_Ui
         /* Toggle Advanced/Basic mode. */
         if (!empty($this->vars->show_advanced) ||
             !empty($this->vars->show_basic)) {
-            $_SESSION['horde_prefs']['advanced'] = !empty($this->vars->show_advanced);
+            $GLOBALS['session']['horde:prefs_advanced'] = !empty($this->vars->show_advanced);
         }
 
         if (!$this->group || !$this->groupIsEditable($this->group)) {
@@ -587,7 +587,7 @@ class Horde_Core_Prefs_Ui
         $t->set('apps', $tmp);
         $t->set('header', htmlspecialchars(($this->app == 'horde') ? _("Global Preferences") : sprintf(_("Preferences for %s"), $registry->get('name', $this->app))));
 
-        if (empty($_SESSION['horde_prefs']['advanced'])) {
+        if ($GLOBALS['session']['horde:prefs_advanced'])) {
             $t->set('advanced', $this->selfUrl()->add('show_advanced', 1));
         } else {
             $t->set('basic', $this->selfUrl()->add('show_basic', 1));
index 9f7bb94..a20476a 100644 (file)
@@ -413,7 +413,7 @@ class Horde_Form {
 
         if ($this->_useFormToken) {
             $token = Horde_Token::generateId($this->_name);
-            $_SESSION['horde_form_secrets'][$token] = true;
+            $GLOBALS['session']['horde:form_secrets/' . $token] = true;
             $this->_preserveVarByPost($this->_name . '_formToken', $token);
         }
 
@@ -473,7 +473,7 @@ class Horde_Form {
 
         if ($this->_useFormToken) {
             $token = Horde_Token::generateId($this->_name);
-            $_SESSION['horde_form_secrets'][$token] = true;
+            $GLOBALS['session']['horde:form_secrets/' . $token] = true;
             $this->_preserveVarByPost($this->_name . '_formToken', $token);
         }
 
@@ -530,7 +530,7 @@ class Horde_Form {
     {
         if ($this->_useFormToken) {
             $token = Horde_Token::generateId($this->_name);
-            $_SESSION['horde_form_secrets'][$token] = true;
+            $GLOBALS['session']['horde:form_secrets/' . $token] = true;
             $this->_preserveVarByPost($this->_name . '_formToken', $token);
         }
 
@@ -614,7 +614,7 @@ class Horde_Form {
             if (!empty($passedToken) && !$tokenSource->verify($passedToken)) {
                 $this->_errors['_formToken'] = _("This form has already been processed.");
             }
-            if (empty($_SESSION['horde_form_secrets'][$passedToken])) {
+            if (!$GLOBALS['session']['horde:form_secrets/' . $passedToken]) {
                 $this->_errors['_formSecret'] = _("Required secret is invalid - potentially malicious request.");
             }
         }