Convert Ansel to Horde_Session
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 17 Nov 2010 18:57:15 +0000 (11:57 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 18 Nov 2010 16:39:14 +0000 (09:39 -0700)
ansel/disclamer.php
ansel/lib/Ajax/Imple/LocationAutoCompleter.php
ansel/lib/Gallery.php
ansel/lib/Search.php
ansel/lib/Search/Tag.php
ansel/protect.php

index 4059612..a414c5d 100644 (file)
@@ -35,7 +35,7 @@ if ($form->isSubmitted()) {
         Horde::url('view.php?view=List', true)->redirect();
         exit;
     } else {
-        $_SESSION['ansel']['user_age'] = (int)$gallery->get('age');
+        $session->set('ansel', 'user_age', (int)$gallery->get('age'));
         $url->redirect();
         exit;
     }
index 5134d02..c45f12f 100644 (file)
@@ -26,16 +26,16 @@ class Ansel_Ajax_Imple_LocationAutoCompleter extends Horde_Core_Ajax_Imple_AutoC
         );
 
         /* Use ajax? */
-        if (!isset($_SESSION['ansel']['ajax_locationac'])) {
+        if (!$GLOBALS['session']->exists('ansel', 'ajax_locationac')) {
             $results = $GLOBALS['injector']->getInstance('Ansel_Injector_Factory_Storage')->create()->searchLocations();
             if ($results instanceof PEAR_Error) {
                 Horde::logMessage($results, 'ERR');
             } else {
-                $_SESSION['ansel']['ajax_locationac'] = (count($results) > 50);
+                $GLOBALS['session']->set('ansel', 'ajax_locationac', (count($results) > 50));
             }
         }
 
-        if (!empty($_SESSION['ansel']['ajax_locationac'])) {
+        if ($GLOBALS['session']->get('ansel', 'ajax_locationac')) {
             $ret['ajax'] = 'LocationAutoCompleter';
         } else {
             if (empty($results)) {
index fa84e87..ee2e7f8 100644 (file)
@@ -793,6 +793,8 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria
      */
     public function isOldEnough()
     {
+        global $session;
+
         if (($GLOBALS['registry']->getAuth() &&
              $this->data['share_owner'] == $GLOBALS['registry']->getAuth()) ||
             empty($GLOBALS['conf']['ages']['limits']) ||
@@ -802,10 +804,14 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria
         }
 
         // Do we have the user age already cheked?
-        if (!isset($_SESSION['ansel']['user_age'])) {
-            $_SESSION['ansel']['user_age'] = 0;
-        } elseif ($_SESSION['ansel']['user_age'] >= $this->data['attribute_age']) {
-            return true;
+        if (!$session->exists('ansel', 'user_age')) {
+            $session->set('ansel', 'user_age', 0);
+            $user_age = 0;
+        } else {
+            $user_age = $session->get('ansel', 'user_age');
+            if ($user_age >= $this->data['attribute_age']) {
+                return true;
+            }
         }
 
         // Can we hook user's age?
@@ -813,11 +819,12 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria
             $GLOBALS['registry']->isAuthenticated()) {
             $result = Horde::callHook('_ansel_hook_user_age');
             if (is_int($result)) {
-                $_SESSION['ansel']['user_age'] = $result;
+                $session->set('ansel', 'user_age', $result);
+                $user_age = $result;
             }
         }
 
-        return ($_SESSION['ansel']['user_age'] >= $this->data['attribute_age']);
+        return ($user_age >= $this->data['attribute_age']);
     }
 
     /**
@@ -834,9 +841,10 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria
         }
 
         $passwd = $this->get('passwd');
-        if (empty($passwd) ||
-            (!empty($_SESSION['ansel']['passwd'][$this->id])
-                && $_SESSION['ansel']['passwd'][$this->id] = md5($this->get('passwd')))) {
+        if (empty($passwd)) {
+            return false;
+        } elseif ($GLOBALS['session']->get('ansel', 'passwd/' . $this->id)) {
+            $GLOBALS['session']->set('ansel', 'passwd/' . $this->id, hash('md5', $this->get('passwd')));
             return false;
         }
 
index 75f09ef..b489c34 100644 (file)
@@ -61,7 +61,7 @@ class Ansel_Search {
      */
     function save()
     {
-        $_SESSION['ansel_search'][$this->_type] = $this->_filter;
+        $GLOBALS['session']->set('ansel', 'search/' . $this->_type, $this->_filter);
     }
 
     /**
@@ -70,9 +70,7 @@ class Ansel_Search {
      */
     function load()
     {
-        $this->_filter = (!empty($_SESSION['ansel_search'][$this->_type]) ?
-            $_SESSION['ansel_search'][$this->_type] :
-            array());
+        $this->_filter = $GLOBALS['session']->get('ansel', 'search/' . $this->_type, Horde_Session::TYPE_ARRAY);
     }
     /**
      * retrieve a slice of the current search
index 51ce0ae..5868141 100644 (file)
@@ -73,7 +73,7 @@ class Ansel_Search_Tag
         if (!empty($tags)) {
             $this->_tags = $this->_tagger->getTagIds($tags);
         } else {
-            $this->_tags = (!empty($_SESSION['ansel_tags_search']) ? $_SESSION['ansel_tags_search'] : array());
+            $this->_tags = $GLOBALS['session']->get('ansel', 'tags_search', Horde_Session::TYPE_ARRAY);
         }
 
         $this->_owner = $owner;
@@ -86,7 +86,7 @@ class Ansel_Search_Tag
      */
     public function save()
     {
-        $_SESSION['ansel_tags_search'] = $this->_tags;
+        $GLOBALS['session']->set('ansel', 'tags_search', $this->_tags);
         $this->_dirty = false;
     }
 
@@ -285,7 +285,7 @@ class Ansel_Search_Tag
      */
     static public function clearSearch()
     {
-        unset($_SESSION['ansel_tags_search']);
+        $GLOBALS['session']->remove('ansel', 'tags_search');
     }
 
     /**
@@ -297,4 +297,4 @@ class Ansel_Search_Tag
         return $a['total']  <  $b['total'];
     }
 
-}
\ No newline at end of file
+}
index c7128e5..b640afc 100644 (file)
@@ -29,7 +29,7 @@ if ($form->validate()) {
     if ($gallery->get('passwd') != $vars->get('passwd')) {
         $notification->push(_("Incorrect password"), 'horde.warning');
     } else {
-        $_SESSION['ansel']['passwd'][$gallery->id] = md5($vars->get('passwd'));
+        $session->set('ansel', 'passwd/' . $gallery->id, hash('md5', $vars->get('passwd')));
         $url = $vars->get('url');
         if (empty($url)) {
             $url = Horde::url('view.php')->add('gallery', $gallery->id);