From 8edb8520af6f212bd5e28bb108b1cb4b497602de Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sun, 10 Oct 2010 23:38:33 -0600 Subject: [PATCH] Convert Turba to using Horde_Session --- turba/addressbooks/create.php | 2 +- turba/addressbooks/delete.php | 2 +- turba/addressbooks/edit.php | 2 +- turba/addressbooks/index.php | 2 +- turba/config/hooks.php.dist | 2 +- turba/lib/Api.php | 8 +++--- turba/lib/Application.php | 14 +++++----- turba/lib/Form/DeleteAddressBook.php | 4 +-- turba/lib/LoginTasks/SystemTask/UpgradeLists.php | 2 +- turba/lib/LoginTasks/SystemTask/UpgradePrefs.php | 2 +- turba/lib/Turba.php | 2 +- turba/lib/View/List.php | 4 +-- turba/lib/tests/TestBase.php | 4 +-- turba/search.php | 33 ++++++++++++------------ 14 files changed, 41 insertions(+), 42 deletions(-) diff --git a/turba/addressbooks/create.php b/turba/addressbooks/create.php index a09047282..4b3cc4b35 100644 --- a/turba/addressbooks/create.php +++ b/turba/addressbooks/create.php @@ -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; diff --git a/turba/addressbooks/delete.php b/turba/addressbooks/delete.php index 7838ba50a..47bc01eb3 100644 --- a/turba/addressbooks/delete.php +++ b/turba/addressbooks/delete.php @@ -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; diff --git a/turba/addressbooks/edit.php b/turba/addressbooks/edit.php index 63065c947..15fc5c00f 100644 --- a/turba/addressbooks/edit.php +++ b/turba/addressbooks/edit.php @@ -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; diff --git a/turba/addressbooks/index.php b/turba/addressbooks/index.php index d0080e71c..620f4b88d 100644 --- a/turba/addressbooks/index.php +++ b/turba/addressbooks/index.php @@ -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; diff --git a/turba/config/hooks.php.dist b/turba/config/hooks.php.dist index d92457aa0..4ad0a0cf3 100644 --- a/turba/config/hooks.php.dist +++ b/turba/config/hooks.php.dist @@ -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; // } // diff --git a/turba/lib/Api.php b/turba/lib/Api.php index 94321eeeb..4cc527f7c 100644 --- a/turba/lib/Api.php +++ b/turba/lib/Api.php @@ -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(); } diff --git a/turba/lib/Application.php b/turba/lib/Application.php index 8f452400d..18b248198 100644 --- a/turba/lib/Application.php +++ b/turba/lib/Application.php @@ -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; } diff --git a/turba/lib/Form/DeleteAddressBook.php b/turba/lib/Form/DeleteAddressBook.php index 19086bdce..f8b93e77b 100644 --- a/turba/lib/Form/DeleteAddressBook.php +++ b/turba/lib/Form/DeleteAddressBook.php @@ -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')); diff --git a/turba/lib/LoginTasks/SystemTask/UpgradeLists.php b/turba/lib/LoginTasks/SystemTask/UpgradeLists.php index eb7311737..c93d7a9b5 100644 --- a/turba/lib/LoginTasks/SystemTask/UpgradeLists.php +++ b/turba/lib/LoginTasks/SystemTask/UpgradeLists.php @@ -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) { diff --git a/turba/lib/LoginTasks/SystemTask/UpgradePrefs.php b/turba/lib/LoginTasks/SystemTask/UpgradePrefs.php index 1006e0d47..a10a4e5ab 100644 --- a/turba/lib/LoginTasks/SystemTask/UpgradePrefs.php +++ b/turba/lib/LoginTasks/SystemTask/UpgradePrefs.php @@ -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(); diff --git a/turba/lib/Turba.php b/turba/lib/Turba.php index ce6db80a7..c336b1a32 100644 --- a/turba/lib/Turba.php +++ b/turba/lib/Turba.php @@ -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(); } diff --git a/turba/lib/View/List.php b/turba/lib/View/List.php index 9b96b6085..efa04f16d 100644 --- a/turba/lib/View/List.php +++ b/turba/lib/View/List.php @@ -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') { diff --git a/turba/lib/tests/TestBase.php b/turba/lib/tests/TestBase.php index 4d820220a..ac6a1cfe3 100644 --- a/turba/lib/tests/TestBase.php +++ b/turba/lib/tests/TestBase.php @@ -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()); } diff --git a/turba/search.php b/turba/search.php index 9bfb2e0fc..fc5f08089 100644 --- a/turba/search.php +++ b/turba/search.php @@ -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)) { -- 2.11.0