Horde: Horde_Session conversions
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 11 Oct 2010 05:18:45 +0000 (23:18 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 12 Oct 2010 20:31:24 +0000 (14:31 -0600)
horde/admin/sqlshell.php
horde/config/hooks.php.dist
horde/docs/CODING_STANDARDS
horde/lib/Prefs/Ui.php
horde/services/twitter.php

index 7765cc3..94eb679 100644 (file)
@@ -25,6 +25,8 @@ require HORDE_TEMPLATES . '/admin/menu.inc';
 <?php
 
 $db = $injector->getInstance('Horde_Db_Adapter');
+$q_cache_id = Horde_Session::DATA . ':sql_query_cache;array';
+$q_cache = $session[$q_cache_id];
 
 if (Horde_Util::getFormData('list-tables')) {
     $description = 'LIST TABLES';
@@ -32,16 +34,12 @@ if (Horde_Util::getFormData('list-tables')) {
     $command = null;
 } elseif ($command = trim(Horde_Util::getFormData('sql'))) {
     // Keep a cache of prior queries for convenience.
-    if (!isset($_SESSION['_sql_query_cache'])) {
-        $_SESSION['_sql_query_cache'] = array();
-    }
-    if (($key = array_search($command, $_SESSION['_sql_query_cache'])) !== false) {
-        unset($_SESSION['_sql_query_cache'][$key]);
-    }
-    array_unshift($_SESSION['_sql_query_cache'], $command);
-    while (count($_SESSION['_sql_query_cache']) > 20) {
-        array_pop($_SESSION['_sql_query_cache']);
+    if (($key = array_search($command, $q_cache)) !== false) {
+        unset($q_cache[$key]);
     }
+    $q_cache[] = $command;
+    $q_cache = array_slice($q_cache, -20);
+    $session[$q_cache_id] = $q_cache;
 
     // Parse out the query results.
     $result = $db->execute(Horde_String::convertCharset($command, 'UTF-8', $conf['sql']['charset']));
@@ -92,11 +90,10 @@ if (isset($result)) {
 }
 ?>
 
-<?php if (isset($_SESSION['_sql_query_cache']) &&
-          count($_SESSION['_sql_query_cache'])): ?>
+<?php if (count($q_cache)): ?>
   <label for="query_cache" class="hidden"><?php echo ("Query cache") ?></label>
   <select id="query_cache" name="query_cache" onchange="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value;">
-  <?php foreach ($_SESSION['_sql_query_cache'] as $query): ?>
+  <?php foreach ($q_cache as $query): ?>
     <option value="<?php echo htmlspecialchars($query) ?>"><?php echo htmlspecialchars($query) ?></option>
   <?php endforeach; ?>
   </select>
index c06340a..44f32de 100644 (file)
@@ -284,7 +284,7 @@ class Horde_Hooks
 //        // Example #2: Set the fullname from LDAP information. In this
 //        // example we look if a Spanish name exists and return this or the
 //        // standard 'cn' entry if not.
-//        $ldapServer = 'ldap.example.com';
+//        $$dapServer = 'ldap.example.com';
 //        $ldapPort = '389';
 //        $searchBase = 'ou=people,o=example.com';
 //
@@ -340,7 +340,7 @@ class Horde_Hooks
 //             : $userId;
 //        $entry['sn'] = $userId;
 //        $entry['objectclass'][0] = 'top';
-//        $entry['objectclass'][1] = 'person';
+//        $   $y['objectclass'][1] = 'person';
 //        $entry['objectclass'][2] = 'qmailuser';
 //        $entry['objectclass'][3] = 'CourierMailACcount';
 //        $entry['mailhost'] = 'mail.example.com';
@@ -404,7 +404,7 @@ class Horde_Hooks
 //            $searchResult = @ldap_search($ds, $searchBase, $userAttr . '=' . $userId, array($groupAttr), 0, 1, 5);
 //            if ($information = @ldap_get_entries($ds, $searchResult)) {
 //                // Make pattern case-insensitive
-//                $pattern = '/' . $groupdn . '/i';
+//                $pattern = '/' . $$roupdn . '/i';
 //                foreach ($information[0][$groupAttr] as $group) {
 //                    if (preg_match($pattern, $group)) {
 //                        $ret = true;
@@ -488,7 +488,7 @@ class Horde_Hooks
 //    {
 //        // Example #1: Send a notification message to the web server
 //        // administrator's e-mail address.
-//        $headers = array(
+//        $ $aders = array(
 //            'To'      => $_SERVER['SERVER_ADMIN'],
 //            'From'    => $_SERVER['SERVER_ADMIN'],
 //            'Subject' => 'New ' . $GLOBALS['registry']->get('name', 'horde') . ' Signup'
@@ -624,7 +624,7 @@ class Horde_Hooks
 //    public function perms_denied($permission)
 //    {
 //        // Example #1: Provide link to upgrade script.
-//        $app = (($pos = strpos($permission, ':')) === false)
+//        $app = (($pos = strpos($? $mission, ':')) === false)
 //            ? $permission
 //            : substr($permission, 0, $pos);
 //
@@ -672,18 +672,20 @@ class Horde_Hooks
      */
 //    public function share_init($share_obj, $app)
 //    {
+//        global $cfgSources, $prefs, $session;
+//
 //        // TODO: Move to turba?
 //        if (($app == 'turba') &&
-//            (!empty($GLOBALS['cfgSources']['imsp']['use_shares']))) {
+//            (!empty($cfgSources['imsp']['use_shares']))) {
 //            // Only do this once per session or when this session variable
 //            // is purposely unset.
-//            if (!empty($_SESSION['imsp_synched'])) {
+//            if ($session['horde:imsp_synched']) {
 //                return;
 //            }
 //
-//            $results = Net_IMSP_Utils::synchShares($share_obj, $GLOBALS['cfgSources']['imsp']);
+//            $results = Net_IMSP_Utils::synchShares($share_obj, $cfgSources['imsp']);
 //            if (!$results instanceof PEAR_Error) {
-//                $_SESSION['imsp_synched'] = true;
+//                $session['horde:imsp_synched'] = true;
 //
 //                // Now deal with adding or removing address books from prefs.
 //                // FIXME: Updating prefs seems to hang the server. Narrowed
@@ -691,10 +693,10 @@ class Horde_Hooks
 //                // call a hook. (Commenting out the callHook call fixes). Can
 //                // anyone verify this on their install?
 //                $dirty = false;
-//                $abooks = $GLOBALS['prefs']->getValue('addressbooks');
+//                $abooks = $prefs->getValue('addressbooks');
 //                $abooks = empty($abooks)
 //                    ? array()
-//                    : explode("\n", $GLOBALS['prefs']->getValue('addressbooks'));
+//                    : explode("\n", $prefs->getValue('addressbooks'));
 //
 //                if (count($results['removed'] > 0)) {
 //                    foreach ($results['removed'] as $sharename) {
@@ -716,13 +718,13 @@ class Horde_Hooks
 //                }
 //
 //                if ($dirty) {
-//                    $result = $GLOBALS['prefs']->setValue('addressbooks', implode("\n", $abooks));
+//                    $result = $prefs->setValue('addressbooks', implode("\n", $abooks));
 //                }
 //
 //                // We have to save the connection info for the imsp server
 //                // since the share_modify hook will not occur from within
 //                // turba's context.
-//                $_SESSION['imsp_config'] = $GLOBALS['cfgSources']['imsp']['params'];
+//                $session['horde:imsp_config'] = $cfgSources['imsp']['params'];
 //            }
 //        }
 //    }
@@ -735,25 +737,26 @@ class Horde_Hooks
      */
 //    public function share_modify($share)
 //    {
+//        global $injector, $session, $share;
+//
 //        $params = unserialize($share->get('params'));
-//        if (is_array($params) && !empty($params['source']) &&
-//            $params['source'] = 'imsp' &&
-//            !empty($_SESSION['imsp_config'])) {
+//        if (is_array($params) &&
+//            !empty($params['source']) &&
+//            ($params['source'] == 'imsp') &&
+//            $session['horde:imsp_config']) {
 //            // Ensure we don't try to change ownership.
 //            $params = @unserialize($share->get('params'));
 //            $bookName = $params['name'];
 //            if (strpos($bookName, $share->get('owner')) !== 0) {
-//                $err = new Horde_Exception('Changing ownership of IMSP address books is not supported.');
-//                $GLOBALS['notification']->push($err);
-//                throw $err;
+//                throw new Horde_Exception('Changing ownership of IMSP address books is not supported.');
 //            }
-
+//
 //            // Update the ACLS
-//            $perms = $GLOBALS['share']->getPermission();
-//            $users = $GLOBALS['injector']->getInstance('Horde_Perms')->getUserPermissions();
+//            $perms = $share->getPermission();
+//            $users = $injector->getInstance('Horde_Perms')->getUserPermissions();
 //            foreach ($users as $user => $perm) {
 //                $acl = Net_IMSP_Utils::permsToACL($perm);
-//                $result = Net_IMSP_Utils::setACL($_SESSION['imsp_config'], $bookName, $user, $acl);
+//                $result = Net_IMSP_Utils::setACL($session['horde:imsp_config'], $bookName, $user, $acl);
 //            }
 //        }
 //    }
index 80126dd..163da59 100644 (file)
@@ -717,10 +717,10 @@ Double Quotes:
   * Should be used in the gettext shortcut ``_("")`` format.
   * Use with care, as many correct looking strings are really invalid.
 
-The following are all incorrect::
+The following are incorrect::
 
     echo "Today is the $date['day'] of $date['month']"
-    $_SESSION[index] = $_SESSION["old_index"];
+    $foo[index] = $foo["old_index"];
 
 .. _sprintf: http://www.php.net/sprintf
 
index 440016a..a84db9f 100644 (file)
@@ -580,7 +580,7 @@ class Horde_Prefs_Ui
                 //require HORDE_TEMPLATES . '/common-footer.inc';
                 exit;
             }
-            $_SESSION['twitter_request_secret'] = $results->secret;
+            $GLOBALS['session']->store($results->secret, false, 'twitter_request_secret');
 
             $t->set('appname', $registry->get('name'));
             $t->set('link', Horde::link(Horde::externalUrl($twitter->auth->getUserAuthorizationUrl($results), false), '', 'button', '', 'openTwitterWindow(); return false;') . 'Twitter</a>');
index 92156eb..b4c9afd 100644 (file)
@@ -120,18 +120,19 @@ case 'getPage':
 /* No requested action, check to see if we have a valid token */
 if (!empty($auth_token)) {
     $profile = Horde_Serialize::unserialize($twitter->account->verifyCredentials(), Horde_Serialize::JSON);
-} elseif (!empty($_SESSION['twitter_request_secret'])) {
+} elseif ($r_secret = $session->retrieve('twitter_request_secret'])) {
      /* No existing auth token, maybe we are in the process of getting it? */
     try {
-        $auth_token = $twitter->auth->getAccessToken($GLOBALS['injector']->getInstance('Horde_Controller_Request'), $_SESSION['twitter_request_secret']);
+        $auth_token = $twitter->auth->getAccessToken($GLOBALS['injector']->getInstance('Horde_Controller_Request'), $r_secret);
     } catch (Horde_Service_Twitter_Exception $e) {
         echo '<div class="fberrorbox">' . sprintf(_("Error connecting to Twitter: %s Details have been logged for the administrator."), $e->getMessage()) . '</div>';
         echo '</form>';
         require HORDE_TEMPLATES . '/common-footer.inc';
         exit;
     }
+
     /* Clear the temporary request secret */
-    $_SESSION['twitter_request_secret'] = '';
+    $session->purge('twitter_request_secret');
     if ($auth_token === false || empty($auth_token)) {
         // We had a request secret, but something went wrong. maybe navigated
         // back here between requests?