From a041f4b564ace8f377ec4bf8acc7fd941596d080 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 3 Nov 2010 01:55:02 -0600 Subject: [PATCH] Wicked: Convert to new Horde_Session API --- wicked/display.php | 19 ++++++++------- wicked/lib/Page/SyncPages.php | 45 ++++++++++++++++++++++------------- wicked/lib/Wicked.php | 14 +++++++---- wicked/templates/display/standard.inc | 4 ++-- wicked/templates/sync/diff.inc | 2 +- wicked/templates/sync/list.inc | 2 +- 6 files changed, 51 insertions(+), 35 deletions(-) diff --git a/wicked/display.php b/wicked/display.php index 6dbc1182b..469320748 100644 --- a/wicked/display.php +++ b/wicked/display.php @@ -123,14 +123,12 @@ if (!$page->allows(Wicked::MODE_DISPLAY)) { $params = Horde_Util::getFormData('params'); $page->preDisplay(Wicked::MODE_DISPLAY, $params); -if (!isset($_SESSION['wickedSession']['history'])) { - $_SESSION['wickedSession']['history'] = array(); -} - if ($page->isLocked()) { $notification->push(sprintf(_("This page is locked by %s for %d Minutes."), $page->getLockRequestor(), $page->getLockTime()), 'horde.message'); } +$history = $session->get('wicked', 'history', Horde_Session::TYPE_ARRAY); + $title = $page->pageTitle(); require WICKED_TEMPLATES . '/common-header.inc'; require WICKED_TEMPLATES . '/menu.inc'; @@ -138,10 +136,13 @@ $page->render(Wicked::MODE_DISPLAY, $params); require $registry->get('templates', 'horde') . '/common-footer.inc'; if ($page instanceof Wicked_Page_StandardPage && - (!isset($_SESSION['wickedSession']['history'][0]) || - $_SESSION['wickedSession']['history'][0] != $page->pageName())) { - array_unshift($_SESSION['wickedSession']['history'], $page->pageName()); + (!isset($history[0]) || + $history[0] != $page->pageName())) { + array_unshift($history, $page->pageName()); + $session->set('wicked', 'history', $history); } -if (count($_SESSION['wickedSession']['history']) > 10) { - array_pop($_SESSION['wickedSession']['history']); + +if (count($history) > 10) { + array_pop($history); + $session->set('wicked', 'history', $history); } diff --git a/wicked/lib/Page/SyncPages.php b/wicked/lib/Page/SyncPages.php index 0f38d2355..f6710dbf8 100644 --- a/wicked/lib/Page/SyncPages.php +++ b/wicked/lib/Page/SyncPages.php @@ -52,13 +52,13 @@ class Wicked_Page_SyncPages extends Wicked_Page { */ public function content() { - global $wicked; + global $session, $wicked; // Used in all cases. $form = $this->_syncForm(); // We have no data to check - if (empty($_SESSION['wicked']['sync'])) { + if (!$session->get('wicked', 'sync')) { ob_start(); require WICKED_TEMPLATES . '/sync/header.inc'; require WICKED_TEMPLATES . '/sync/footer.inc'; @@ -67,7 +67,7 @@ class Wicked_Page_SyncPages extends Wicked_Page { // New pages on remote server $new_remote = array(); - foreach ($_SESSION['wicked']['sync']['pages'] as $pageName => $info) { + foreach ($session->get('wicked', 'sync_pages/') as $pageName => $info) { if (!$wicked->pageExists($pageName)) { $new_remote[$pageName] = array( 'page_majorversion' => $info['page_majorversion'], @@ -84,7 +84,7 @@ class Wicked_Page_SyncPages extends Wicked_Page { $new_local = array(); $local_pages = $wicked->getPages(false); foreach ($local_pages as $pageName) { - if (isset($_SESSION['wicked']['sync']['pages'][$pageName])) { + if ($session->exists('wicked', 'sync_pages/' . $pageName)) { continue; } $page = Wicked_Page::getPage($pageName); @@ -109,7 +109,8 @@ class Wicked_Page_SyncPages extends Wicked_Page { // Compare checksum $page = Wicked_Page::getPage($pageName); - if (md5($page->getText()) == $_SESSION['wicked']['sync']['pages'][$pageName]['page_checksum']) { + $spage = $session->get('wicked', 'sync_pages/' . $pageName); + if (md5($page->getText()) == $spage['page_checksum']) { continue; } @@ -160,7 +161,7 @@ class Wicked_Page_SyncPages extends Wicked_Page { if ($local) { return '' . _("View local") . ''; } else { - return '' . _("View remote") . ''; + return '' . _("View remote") . ''; } } @@ -171,6 +172,8 @@ class Wicked_Page_SyncPages extends Wicked_Page { */ protected function _syncForm() { + global $session; + require_once 'Horde/Form.php'; $vars = Horde_Variables::getDefaultVariables(); @@ -191,7 +194,7 @@ class Wicked_Page_SyncPages extends Wicked_Page { // Prepare default values $stored = @unserialize($GLOBALS['prefs']->getValue('sync_data')); if (isset($_GET['__old_sync_select'])) { - unset($_SESSION['wicked']['sync']); + $session->remove('wicked', 'sync'); } if ($vars->get('sync_select') && isset($stored[$vars->get('sync_select')])) { $defaults = $stored[$vars->get('sync_select')]; @@ -201,8 +204,9 @@ class Wicked_Page_SyncPages extends Wicked_Page { } } } - if (!empty($_SESSION['wicked']['sync'])) { - $defaults = $_SESSION['wicked']['sync']; + + if ($session->exists('wicked', 'sync')) { + $defaults = $session->get('wicked', 'sync'); } // Add stored info selection @@ -254,13 +258,15 @@ class Wicked_Page_SyncPages extends Wicked_Page { switch (Horde_Util::getFormData('submitbutton')) { case _("Fetch page list"): // Load driver - $_SESSION['wicked']['sync'] = $info; + $session->set('wicked', 'sync', $info); $this->_loadSyncDriver(); // We submitted the form so we should fetch pages $pages = $this->_sync->getMultiplePageInfo(); if (!empty($pages)) { - $_SESSION['wicked']['sync']['pages'] = $pages; + foreach ($pages as $key => $val) { + $session->set('wicked', 'sync_pages/' . $key, $val); + } } break; @@ -318,10 +324,13 @@ class Wicked_Page_SyncPages extends Wicked_Page { */ public function getRemotePageInfo($pageName) { - if (!isset($_SESSION['wicked']['sync']['pages'][$pageName])) { - $_SESSION['wicked']['sync']['pages'][$pageName] = $this->_sync->getPageInfo($pageName); + global $session; + + if (!$session->exists('wicked', 'sync_pages/' . $pageName)) { + $session->set('wicked', 'sync_pages/' . $pageName, $this->_sync->getPageInfo($pageName)); } - return $_SESSION['wicked']['sync']['pages'][$pageName]; + + return $session->get('wicked', 'sync_pages/' . $pageName); } /** @@ -377,14 +386,16 @@ class Wicked_Page_SyncPages extends Wicked_Page { */ protected function _loadSyncDriver() { + global $session; + if ($this->_sync) { return true; - } elseif (empty($_SESSION['wicked']['sync']['driver'])) { + } elseif (!$session->get('wicked', 'sync_driver')) { return false; } - $this->_sync = Wicked_Sync::factory($_SESSION['wicked']['sync']['driver'], - $_SESSION['wicked']['sync']); + $this->_sync = Wicked_Sync::factory($session->get('wicked', 'sync_driver'), + $session->get('wicked', 'sync')); } } diff --git a/wicked/lib/Wicked.php b/wicked/lib/Wicked.php index ac5e12942..830b8484a 100644 --- a/wicked/lib/Wicked.php +++ b/wicked/lib/Wicked.php @@ -204,13 +204,17 @@ class Wicked */ public static function getCAPTCHA($new = false) { - if ($new || empty($_SESSION['wickedSession']['CAPTCHA'])) { - $_SESSION['wickedSession']['CAPTCHA'] = ''; - for ($i = 0; $i < 5; $i++) { - $_SESSION['wickedSession']['CAPTCHA'] .= chr(rand(65, 90)); + global $session; + + if ($new || !$session->get('wicked', 'captcha')) { + $captcha = ''; + for ($i = 0; $i < 5; ++$i) { + $captcha .= chr(rand(65, 90)); } + $session->set('wicked', 'captcha', $captcha); } - return $_SESSION['wickedSession']['CAPTCHA']; + + return $session->get('wicked', 'captcha'); } /** diff --git a/wicked/templates/display/standard.inc b/wicked/templates/display/standard.inc index a76bdb2c6..b73994f17 100644 --- a/wicked/templates/display/standard.inc +++ b/wicked/templates/display/standard.inc @@ -103,10 +103,10 @@ if ($GLOBALS['registry']->isAdmin()) { 'widget', '_blank', '', _("Permissio_ns")); } ?> - +get('wicked', 'history')): ?> diff --git a/wicked/templates/sync/diff.inc b/wicked/templates/sync/diff.inc index c299378b9..4feece794 100644 --- a/wicked/templates/sync/diff.inc +++ b/wicked/templates/sync/diff.inc @@ -96,7 +96,7 @@ $GLOBALS['notification']->notify(array('listeners' => 'status')); | | | - + pageTitle(), $name1, $name2) ?> diff --git a/wicked/templates/sync/list.inc b/wicked/templates/sync/list.inc index f23fa5f63..8e436a08d 100644 --- a/wicked/templates/sync/list.inc +++ b/wicked/templates/sync/list.inc @@ -13,7 +13,7 @@ function _format_date($timestamp) } /* Find new pages to download */ -echo '

' . _("New pages on remote server") . ': ' . $_SESSION['wicked']['sync']['url'] . ' (' . $_SESSION['wicked']['sync']['user'] . ')

'; +echo '

' . _("New pages on remote server") . ': ' . $GLOBALS['session']->get('wicked', 'sync_url') . ' (' . $GLOBALS['session']->get('wicked', 'sync_user') . ')

'; if (empty($new_remote)) { echo _("No pages found"); } else { -- 2.11.0