Wicked: Convert to new Horde_Session API
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 3 Nov 2010 07:55:02 +0000 (01:55 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 4 Nov 2010 19:44:28 +0000 (13:44 -0600)
wicked/display.php
wicked/lib/Page/SyncPages.php
wicked/lib/Wicked.php
wicked/templates/display/standard.inc
wicked/templates/sync/diff.inc
wicked/templates/sync/list.inc

index 6dbc118..4693207 100644 (file)
@@ -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);
 }
index 0f38d23..f6710db 100644 (file)
@@ -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  '<a href="' .  Wicked::url($pageName) . '" target="_blank">' . _("View local") . '</a>';
         } else {
-            return  '<a href="' .  $_SESSION['wicked']['sync']['display']  . $pageName . '" target="_blank">' . _("View remote") . '</a>';
+            return  '<a href="' .  $GLOBALS['session']->get('wicked', 'sync_display')  . $pageName . '" target="_blank">' . _("View remote") . '</a>';
         }
     }
 
@@ -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'));
     }
 
 }
index ac5e129..830b848 100644 (file)
@@ -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');
     }
 
     /**
index a76bdb2..b73994f 100644 (file)
@@ -103,10 +103,10 @@ if ($GLOBALS['registry']->isAdmin()) {
                        'widget', '_blank', '', _("Permissio_ns"));
 }
 ?>
-<?php if (empty($isBlock) && !empty($_SESSION['wickedSession']['history'])): ?>
+<?php if (empty($isBlock) && $GLOBALS['session']->get('wicked', 'history')): ?>
   <?php separator(); echo Horde::widget('#', _("Back to"), 'widget', '', 'document.location = document.display.history[document.display.history.selectedIndex].value;', _("Ba_ck to")) ?>
   <select name="history" onchange="document.location = document.display.history[document.display.history.selectedIndex].value">
-<?php foreach ($_SESSION['wickedSession']['history'] as $history): if (!strlen($history)) continue; ?>
+<?php foreach ($GLOBALS['session']->get('wicked', 'history') as $history): if (!strlen($history)) continue; ?>
    <option value="<?php echo Wicked::url($history) ?>"><?php echo htmlspecialchars($history) ?></option>
 <?php endforeach; ?>
   </select>
index c299378..4feece7 100644 (file)
@@ -96,7 +96,7 @@ $GLOBALS['notification']->notify(array('listeners' => 'status'));
 <a href="" target="_blank"><?php echo _("Download") ?></a> |
 <a href="" target="_blank"><?php echo _("Upload") ?></a> |
 <a href="<?php  echo Horde_Util::addParameter(Wicked::url('EditPage'), 'referrer', $this->_pageName) ?>" target="_blank"><?php echo _("Edit local") ?></a> |
-<a href="<?php  echo $_SESSION['wicked']['sync']['edit'] . $this->_pageName ?>" target="_blank"><?php echo _("Edit remote") ?></a>
+<a href="<?php  echo $GLOBALS['session']->get('wicked', 'sync_edit') . $this->_pageName ?>" target="_blank"><?php echo _("Edit remote") ?></a>
 </span>
 <?php echo sprintf(_("Diff for %s between %s and %s"), $page->pageTitle(), $name1, $name2) ?>
 </h1>
index f23fa5f..8e436a0 100644 (file)
@@ -13,7 +13,7 @@ function _format_date($timestamp)
 }
 
 /* Find new pages to download */
-echo  '<h2>' . _("New pages on remote server") . ': ' . $_SESSION['wicked']['sync']['url'] . ' (' . $_SESSION['wicked']['sync']['user'] . ')</h2>';
+echo  '<h2>' . _("New pages on remote server") . ': ' . $GLOBALS['session']->get('wicked', 'sync_url') . ' (' . $GLOBALS['session']->get('wicked', 'sync_user') . ')</h2>';
 if (empty($new_remote)) {
     echo _("No pages found");
 } else {