Convert Turba to using Horde_Session
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 11 Oct 2010 05:38:33 +0000 (23:38 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 12 Oct 2010 20:31:24 +0000 (14:31 -0600)
14 files changed:
turba/addressbooks/create.php
turba/addressbooks/delete.php
turba/addressbooks/edit.php
turba/addressbooks/index.php
turba/config/hooks.php.dist
turba/lib/Api.php
turba/lib/Application.php
turba/lib/Form/DeleteAddressBook.php
turba/lib/LoginTasks/SystemTask/UpgradeLists.php
turba/lib/LoginTasks/SystemTask/UpgradePrefs.php
turba/lib/Turba.php
turba/lib/View/List.php
turba/lib/tests/TestBase.php
turba/search.php

index a090472..4b3cc4b 100644 (file)
@@ -13,7 +13,7 @@ Horde_Registry::appInit('turba');
 
 // Exit if this isn't an authenticated user, or if there's no source
 // configured for shares.
-if (!$GLOBALS['registry']->getAuth() || empty($_SESSION['turba']['has_share'])) {
+if (!$GLOBALS['registry']->getAuth() || !$session['turba:has_share']) {
     require TURBA_BASE . '/'
         . ($browse_source_count ? basename($prefs->getValue('initial_page')) : 'search.php');
     exit;
index 7838ba5..47bc01e 100644 (file)
@@ -13,7 +13,7 @@ Horde_Registry::appInit('turba');
 
 // Exit if this isn't an authenticated user, or if there's no source
 // configured for shares.
-if (!$GLOBALS['registry']->getAuth() || empty($_SESSION['turba']['has_share'])) {
+if (!$GLOBALS['registry']->getAuth() || !$session['turba:has_share']) {
     require TURBA_BASE . '/'
         . ($browse_source_count ? basename($prefs->getValue('initial_page')) : 'search.php');
     exit;
index 63065c9..15fc5c0 100644 (file)
@@ -13,7 +13,7 @@ Horde_Registry::appInit('turba');
 
 // Exit if this isn't an authenticated user, or if there's no source
 // configured for shares.
-if (!$GLOBALS['registry']->getAuth() || empty($_SESSION['turba']['has_share'])) {
+if (!$GLOBALS['registry']->getAuth() || !$session['turba:has_share']) {
     require TURBA_BASE . '/'
         . ($browse_source_count ? basename($prefs->getValue('initial_page')) : 'search.php');
     exit;
index d0080e7..620f4b8 100644 (file)
@@ -13,7 +13,7 @@ Horde_Registry::appInit('turba');
 
 // Exit if this isn't an authenticated user, or if there's no source
 // configured for shares.
-if (!$GLOBALS['registry']->getAuth() || empty($_SESSION['turba']['has_share'])) {
+if (!$GLOBALS['registry']->getAuth() || !$session['turba:has_share']) {
     require TURBA_BASE . '/'
         . ($browse_source_count ? basename($prefs->getValue('initial_page')) : 'search.php');
     exit;
index d92457a..4ad0a0c 100644 (file)
@@ -25,7 +25,7 @@ class Turba_Hooks
      */
 //     public function default_dir($username = null)
 //     {
-//         if (!$username || empty($_SESSION['turba']['has_share'])) {
+//         if (!$username || !$GLOBALS['session']['turba:has_share']) {
 //             return;
 //         }
 //
index 94321ee..4cc527f 100644 (file)
@@ -120,12 +120,12 @@ class Turba_Api extends Horde_Registry_Api
      */
     public function getDefaultShare()
     {
-        global $prefs;
+        global $prefs, $session;
 
         // Bring in a clean copy of sources.
         require TURBA_BASE . '/config/backends.php';
 
-        if (!empty($_SESSION['turba']['has_share'])) {
+        if ($session['turba:has_share']) {
             $shares = Turba::listShares(true);
             foreach ($shares as $uid => $share) {
                 $params = @unserialize($share->get('params'));
@@ -182,7 +182,7 @@ class Turba_Api extends Horde_Registry_Api
      */
     public function browse($path = '', $properties = array())
     {
-        global $registry, $cfgSources;
+        global $registry, $session, $cfgSources;
 
         // Default properties.
         if (!$properties) {
@@ -257,7 +257,7 @@ class Turba_Api extends Horde_Registry_Api
             } else {
                 // Assume $parts[0] is a valid username and we need to list their
                 // shared addressbooks.
-                if (empty($_SESSION['turba']['has_share'])) {
+                if (!$session['turba:has_share']) {
                     // No backends are configured to provide shares
                     return array();
                 }
index 8f45240..18b2481 100644 (file)
@@ -80,7 +80,7 @@ class Turba_Application extends Horde_Registry_Application
         foreach ($cfgSources as $key => $cfg) {
             if (!empty($cfg['use_shares'])) {
                 // Create a share instance.
-                $_SESSION['turba']['has_share'] = true;
+                $GLOBALS['session']['turba:has_share'] = true;
                 $GLOBALS['turba_shares'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create();
                 $cfgSources = Turba::getConfigFromShares($cfgSources);
                 break;
@@ -93,9 +93,9 @@ class Turba_Application extends Horde_Registry_Application
         // Build the directory sources select widget.
         $default_source = Horde_Util::nonInputVar('source');
         if (empty($default_source)) {
-            $default_source = empty($_SESSION['turba']['source'])
-                ? Turba::getDefaultAddressBook()
-                : $_SESSION['turba']['source'];
+            if (!($default_source = $GLOBALS['session']['turba:source'])) {
+                $default_source = Turba::getDefaultAddressBook();
+            }
             $default_source = Horde_Util::getFormData('source', $default_source);
         }
 
@@ -119,7 +119,7 @@ class Turba_Application extends Horde_Registry_Application
         if (empty($cfgSources[$default_source]['browse'])) {
             $default_source = Turba::getDefaultAddressBook();
         }
-        $_SESSION['turba']['source'] = $default_source;
+        $GLOBALS['session']['turba:source'] = $default_source;
         $GLOBALS['default_source'] = $default_source;
 
         /* Only set $add_source_options if there is at least one editable
@@ -176,7 +176,7 @@ class Turba_Application extends Horde_Registry_Application
      */
     public function menu($menu)
     {
-        if (!empty($_SESSION['turba']['has_share'])) {
+        if ($GLOBALS['session']['turba:has_share']) {
             $menu->add(Horde::url('addressbooks/index.php'), _("_My Address Books"), 'turba.png');
         }
 
@@ -429,7 +429,7 @@ class Turba_Application extends Horde_Registry_Application
         }
 
         /* Only attempt share removal if we have shares configured */
-        if (empty($_SESSION['turba']['has_share'])) {
+        if (!$GLOBALS['session']['turba:has_share']) {
             return;
         }
 
index 19086bd..f8b93e7 100644 (file)
@@ -64,8 +64,8 @@ class Turba_Form_DeleteAddressBook extends Horde_Form
             throw new Turba_Exception($e);
         }
 
-        if (isset($_SESSION['turba']['source']) && $_SESSION['turba']['source'] == Horde_Util::getFormData('deleteshare')) {
-            unset($_SESSION['turba']['source']);
+        if ($GLOBALS['session']['turba:source'] == Horde_Util::getFormData('deleteshare')) {
+            unset($GLOBALS['session']['turba:source']);
         }
 
         $abooks = json_decode($GLOBALS['prefs']->getValue('addressbooks'));
index eb73117..c93d7a9 100644 (file)
@@ -35,7 +35,7 @@ class Turba_LoginTasks_SystemTask_UpgradeLists extends Horde_LoginTasks_SystemTa
      */
     public function execute()
     {
-        if (!empty($_SESSION['turba']['has_share'])) {
+        if ($GLOBALS['session']['turba:has_share']) {
             $criteria = array('__type' => 'Group');
             $sources = array_keys($GLOBALS['cfgSources']);
             foreach ($sources as $sourcekey) {
index 1006e0d..a10a4e5 100644 (file)
@@ -37,7 +37,7 @@ class Turba_LoginTasks_SystemTask_UpgradePrefs extends Horde_LoginTasks_SystemTa
     {
         global $registry;
 
-        if (!empty($_SESSION['turba']['has_share'])) {
+        if ($GLOBALS['session']['turba:has_share']) {
             $this->_doAddressbooks();
             $this->_doColumns();
             $this->_doAddSource();
index ce6db80..c336b1a 100644 (file)
@@ -527,7 +527,7 @@ class Turba {
      */
     function listShares($owneronly = false, $permission = Horde_Perms::READ)
     {
-        if (empty($_SESSION['turba']['has_share'])) {
+        if (!$GLOBALS['session']['turba:has_share']) {
             // No backends are configured to provide shares
             return array();
         }
index 9b96b60..efa04f1 100644 (file)
@@ -143,7 +143,7 @@ class Turba_View_List implements Countable
 
     function display()
     {
-        global $prefs, $default_source, $copymove_source_options;
+        global $prefs, $session, $default_source, $copymove_source_options;
 
         $driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($default_source);
 
@@ -177,7 +177,7 @@ class Turba_View_List implements Countable
             $listHtml = $this->getPage($numDisplayed, $min, $max);
 
             $crit = array();
-            if ($_SESSION['turba']['search_mode'] == 'advanced') {
+            if ($session['turba:search_mode'] == 'advanced') {
                 $map = $driver->getCriteria();
                 foreach ($map as $key => $value) {
                     if ($key != '__key') {
index 4d82022..ac6a1cf 100644 (file)
@@ -249,8 +249,8 @@ class Turba_TestBase extends PHPUnit_Framework_TestCase {
     {
         /* Turba_Driver::search() is coupled with authentication global
          * state. */
-        $_SESSION['__auth'] = array('authenticated' => true,
-                                    'userId' => '1');
+        //$_SESSION['__auth'] = array('authenticated' => true,
+        //                            'userId' => '1');
         $this->assertEqual('1', $GLOBALS['registry']->getAuth());
     }
 
index 9bfb2e0..fc5f080 100644 (file)
@@ -51,18 +51,17 @@ Horde_Registry::appInit('turba');
 /* Verify if the search mode variable is passed in form or is registered in
  * the session. Always use basic search by default. */
 if (Horde_Util::getFormData('search_mode')) {
-    $_SESSION['turba']['search_mode'] = Horde_Util::getFormData('search_mode');
+    $session['turba:search_mode'] = Horde_Util::getFormData('search_mode');
 }
-if (!isset($_SESSION['turba']['search_mode']) ||
-    !in_array($_SESSION['turba']['search_mode'], array('basic', 'advanced', 'duplicate'))) {
-    $_SESSION['turba']['search_mode'] = 'basic';
+if (!in_array($session['turba:search_mode'], array('basic', 'advanced', 'duplicate'))) {
+    $session['turba:search_mode'] = 'basic';
 }
 
 /* Get the current source. */
 $addressBooks = Turba::getAddressBooks();
 $editableAddressBooks = Turba::getAddressBooks(Horde_Perms::EDIT & Horde_Perms::DELETE,
                                                array('require_add' => true));
-if ($_SESSION['turba']['search_mode'] == 'duplicate') {
+if ($session['turba:search_mode'] == 'duplicate') {
     $addressBooks = $editableAddressBooks;
 }
 $source = Horde_Util::getFormData('source', $default_source);
@@ -94,7 +93,7 @@ try {
 
 if ($driver) {
     $map = $driver->getCriteria();
-    if ($_SESSION['turba']['search_mode'] == 'advanced') {
+    if ($session['turba:search_mode'] == 'advanced') {
         $criteria = array();
         foreach (array_keys($map) as $key) {
             if ($key != '__key') {
@@ -112,7 +111,7 @@ if ($driver) {
     /* Only try to perform a search if we actually have search criteria. */
     if ((is_array($criteria) && count($criteria)) ||
         !empty($val) ||
-        ($_SESSION['turba']['search_mode'] == 'duplicate' &&
+        ($session['turba:search_mode'] == 'duplicate' &&
          (Horde_Util::getFormData('search') ||
           Horde_Util::getFormData('dupe') ||
           count($addressBooks) == 1))) {
@@ -132,7 +131,7 @@ if ($driver) {
                 'params' => serialize(array(
                     'type' => 'vbook',
                     'source' => $source,
-                    'criteria' => $_SESSION['turba']['search_mode'] == 'basic' ? array($criteria => $val) : $criteria
+                    'criteria' => $session['turba:search_mode'] == 'basic' ? array($criteria => $val) : $criteria
                 ))
             );
 
@@ -152,7 +151,7 @@ if ($driver) {
         }
 
         /* Perform a search. */
-        if ($_SESSION['turba']['search_mode'] == 'duplicate') {
+        if ($session['turba:search_mode'] == 'duplicate') {
             try {
                 $duplicates = $driver->searchDuplicates();
                 $dupe = Horde_Util::getFormData('dupe');
@@ -164,9 +163,9 @@ if ($driver) {
             }
         } else {
             try {
-                if ((($_SESSION['turba']['search_mode'] == 'basic') &&
+                if ((($session['turba:search_mode'] == 'basic') &&
                      ($results = $driver->search(array($criteria => $val)))) ||
-                    (($_SESSION['turba']['search_mode'] == 'advanced') &&
+                    (($session['turba:search_mode'] == 'advanced') &&
                      ($results = $driver->search($criteria)))) {
                     /* Read the columns to display from the preferences. */
                     $sources = Turba::getColumns();
@@ -228,14 +227,14 @@ $searchView->criteria = $criteria;
 $searchView->value = $val;
 
 /* The form footer and vbook section. */
-if ($_SESSION['turba']['search_mode'] != 'duplicate') {
+if ($session['turba:search_mode'] != 'duplicate') {
     $vbookView = new Horde_View(array('templatePath' => TURBA_TEMPLATES . '/search'));
-    $vbookView->hasShare = !empty($_SESSION['turba']['has_share']);
+    $vbookView->hasShare = isset($session['turba:has_share']);
     $vbookView->shareSources = $shareSources;
     $vbookView->source = $source;
 }
 
-switch ($_SESSION['turba']['search_mode']) {
+switch ($session['turba:search_mode']) {
 case 'basic':
     $title = _("Basic Search");
     Horde::addInlineScript(array(
@@ -265,10 +264,10 @@ if (isset($view) && is_object($view)) {
 
 require TURBA_TEMPLATES . '/common-header.inc';
 require TURBA_TEMPLATES . '/menu.inc';
-echo $tabs->render($_SESSION['turba']['search_mode']);
+echo $tabs->render($session['turba:search_mode']);
 echo $headerView->render('header');
-echo $searchView->render($_SESSION['turba']['search_mode']);
-if ($_SESSION['turba']['search_mode'] != 'duplicate') {
+echo $searchView->render($session['turba:search_mode']);
+if ($session['turba:search_mode'] != 'duplicate') {
     echo $vbookView->render('vbook');
 }
 if (isset($view) && is_object($view)) {