Convert Folks to Horde_Session
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 17 Nov 2010 19:02:43 +0000 (12:02 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 18 Nov 2010 16:39:14 +0000 (09:39 -0700)
folks/account/resetpassword.php
folks/lib/Driver.php
folks/lib/Folks.php
folks/lib/Forms/Login.php
folks/save_search.php
folks/search.php

index 7882be7..f216d2c 100644 (file)
 
 require_once dirname(__FILE__) . '/tabs.php';
 
-/**
- * Returns a new or the current CAPTCHA string.
- *
- * @param boolean $new string
- */
-function _getCAPTCHA($new = false)
-{
-    if ($new || empty($_SESSION['folks']['CAPTCHA'])) {
-        $_SESSION['folks']['CAPTCHA'] = '';
-        for ($i = 0; $i < 5; $i++) {
-            $_SESSION['folks']['CAPTCHA'] .= chr(rand(65, 90));
-        }
-    }
-    return $_SESSION['folks']['CAPTCHA'];
-}
-
 // We are already logged
 if ($registry->isAuthenticated()) {
     Folks::getUrlFor('user', $GLOBALS['registry']->getAuth())->redirect();
@@ -71,7 +55,7 @@ if (!empty($answer)) {
 } else {
     $desc = _("The picture above is for antispam checking. Please retype the characters from the picture. They are case sensitive.");
     $form->addVariable(_("Human check"), 'captcha', 'captcha', true, false, $desc,
-                        array(_getCAPTCHA(!$form->isSubmitted()), HORDE_BASE . '/config/couri.ttf'));
+                        array(Folks::getCAPTCHA(!$form->isSubmitted()), HORDE_BASE . '/config/couri.ttf'));
 }
 
 /* Validate the form. */
index 72b536a..4e090c4 100644 (file)
@@ -257,8 +257,8 @@ class Folks_Driver {
         // is not added site wide to a general template file
         // scripts/online.sql
         if ($GLOBALS['conf']['online']['autoupdate'] &&
-            (!isset($_SESSION['folks']['last_update']) ||
-                $_SESSION['folks']['last_update'] + $GLOBALS['conf']['online']['ttl'] < $_SERVER['REQUEST_TIME'])) {
+            (!$GLOBALS['session']->exists('folks', 'last_update') ||
+             $GLOBALS['session']->get('folks', 'last_update') + $GLOBALS['conf']['online']['ttl'] < $_SERVER['REQUEST_TIME'])) {
 
             // Update online status
             $this->_updateOnlineStatus();
index a63e27f..ca1d3ea 100644 (file)
@@ -196,14 +196,17 @@ class Folks {
      */
     static public function getCAPTCHA($new = false)
     {
-        if ($new || empty($_SESSION['folks']['CAPTCHA'])) {
-            $_SESSION['folks']['CAPTCHA'] = '';
-            for ($i = 0; $i < 5; $i++) {
-                $_SESSION['folks']['CAPTCHA'] .= chr(rand(65, 90));
+        global $session;
+
+        if ($new || !$session->get('folks', 'captcha')) {
+            $captcha = '';
+            for ($i = 0; $i < 5; ++$i) {
+                $captcha .= chr(rand(65, 90));
             }
+            $session->set('folks', 'captcha', $captcha);
         }
 
-        return $_SESSION['folks']['CAPTCHA'];
+        return $session->get('folks', 'captcha');
     }
 
     /**
index 7715e0e..dc6277c 100644 (file)
@@ -48,12 +48,17 @@ class Folks_Login_Form extends Horde_Form {
      */
     private function _getCAPTCHA($new = false)
     {
-        if ($new || empty($_SESSION['folks']['login_CAPTCHA'])) {
-            $_SESSION['folks']['login_CAPTCHA'] = '';
-            for ($i = 0; $i < 5; $i++) {
-                $_SESSION['folks']['login_CAPTCHA'] .= chr(rand(65, 90));
+        global $session;
+
+        if ($new || !$session->get('agora', 'login_captcha')) {
+            $captcha = '';
+            for ($i = 0; $i < 5; ++$i) {
+                $captcha .= chr(rand(65, 90));
             }
+            $session->set('agora', 'login_captcha', $captcha);
         }
-        return $_SESSION['folks']['login_CAPTCHA'];
+
+        return $session->get('agora', 'login_captcha');
     }
+
 }
index 2a3cfdf..320c1ea 100644 (file)
@@ -41,7 +41,7 @@ if (Horde_Util::getFormData('submitbutton') == _("Close")) {
 
 // Render
 $vars = Horde_Variables::getDefaultVariables();
-$vars->set('search_criteria', $_SESSION['folks']['last_search']);
+$vars->set('search_criteria', $session->get('folks', 'last_search'));
 $form = new Horde_Form($vars, '', 'savesearch');
 $form->addVariable(_("Name"), 'search_name', 'text', true);
 $form->addHidden('', 'search_criteria', 'text', true);
index 007f200..7637330 100644 (file)
@@ -18,8 +18,9 @@ $title = _("Search");
 $vars = Horde_Variables::getDefaultVariables();
 $form = new Folks_Search_Form($vars, $title, 'search');
 
-if (isset($_SESSION['folks']['last_search']) && !$form->isSubmitted()) {
-    $criteria = unserialize($_SESSION['folks']['last_search']);
+if (($last_search = $session->get('folks', 'last_search')) &&
+    !$form->isSubmitted()) {
+    $criteria = unserialize($last_search);
 }
 if (Horde_Util::getGet('query') && !$form->isSubmitted()) {
     $criteria = $folks_driver->getSearchCriteria(Horde_Util::getGet('query'));
@@ -29,7 +30,7 @@ if (Horde_Util::getGet('query') && !$form->isSubmitted()) {
     }
 } else {
     $form->getInfo(null, $criteria);
-    $_SESSION['folks']['last_search'] = serialize($criteria);
+    $session->set('folks', 'last_search', serialize($criteria));
 }
 
 if (!empty($criteria)) {