From 816550102a69f222a4be67e59c63aea2accf5836 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 17 Nov 2010 11:57:15 -0700 Subject: [PATCH] Convert Ansel to Horde_Session --- ansel/disclamer.php | 2 +- ansel/lib/Ajax/Imple/LocationAutoCompleter.php | 6 +++--- ansel/lib/Gallery.php | 26 +++++++++++++++++--------- ansel/lib/Search.php | 6 ++---- ansel/lib/Search/Tag.php | 8 ++++---- ansel/protect.php | 2 +- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/ansel/disclamer.php b/ansel/disclamer.php index 405961225..a414c5db6 100644 --- a/ansel/disclamer.php +++ b/ansel/disclamer.php @@ -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; } diff --git a/ansel/lib/Ajax/Imple/LocationAutoCompleter.php b/ansel/lib/Ajax/Imple/LocationAutoCompleter.php index 5134d0241..c45f12f6a 100644 --- a/ansel/lib/Ajax/Imple/LocationAutoCompleter.php +++ b/ansel/lib/Ajax/Imple/LocationAutoCompleter.php @@ -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)) { diff --git a/ansel/lib/Gallery.php b/ansel/lib/Gallery.php index fa84e8752..ee2e7f838 100644 --- a/ansel/lib/Gallery.php +++ b/ansel/lib/Gallery.php @@ -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; } diff --git a/ansel/lib/Search.php b/ansel/lib/Search.php index 75f09ef9e..b489c340a 100644 --- a/ansel/lib/Search.php +++ b/ansel/lib/Search.php @@ -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 diff --git a/ansel/lib/Search/Tag.php b/ansel/lib/Search/Tag.php index 51ce0ae02..5868141dc 100644 --- a/ansel/lib/Search/Tag.php +++ b/ansel/lib/Search/Tag.php @@ -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 +} diff --git a/ansel/protect.php b/ansel/protect.php index c7128e53d..b640afc27 100644 --- a/ansel/protect.php +++ b/ansel/protect.php @@ -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); -- 2.11.0