From 39e5fd1c8178d03a46be8bf19af366d72c193fae Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sun, 10 Oct 2010 23:18:45 -0600 Subject: [PATCH] Horde: Horde_Session conversions --- horde/admin/sqlshell.php | 21 +++++++++---------- horde/config/hooks.php.dist | 49 ++++++++++++++++++++++++--------------------- horde/docs/CODING_STANDARDS | 4 ++-- horde/lib/Prefs/Ui.php | 2 +- horde/services/twitter.php | 7 ++++--- 5 files changed, 42 insertions(+), 41 deletions(-) diff --git a/horde/admin/sqlshell.php b/horde/admin/sqlshell.php index 7765cc32d..94eb679d6 100644 --- a/horde/admin/sqlshell.php +++ b/horde/admin/sqlshell.php @@ -25,6 +25,8 @@ require HORDE_TEMPLATES . '/admin/menu.inc'; 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)) { } ?> - + diff --git a/horde/config/hooks.php.dist b/horde/config/hooks.php.dist index c06340a8d..44f32de53 100644 --- a/horde/config/hooks.php.dist +++ b/horde/config/hooks.php.dist @@ -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); // } // } // } diff --git a/horde/docs/CODING_STANDARDS b/horde/docs/CODING_STANDARDS index 80126ddda..163da59df 100644 --- a/horde/docs/CODING_STANDARDS +++ b/horde/docs/CODING_STANDARDS @@ -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 diff --git a/horde/lib/Prefs/Ui.php b/horde/lib/Prefs/Ui.php index 440016a59..a84db9fd6 100644 --- a/horde/lib/Prefs/Ui.php +++ b/horde/lib/Prefs/Ui.php @@ -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'); diff --git a/horde/services/twitter.php b/horde/services/twitter.php index 92156eb22..b4c9afdda 100644 --- a/horde/services/twitter.php +++ b/horde/services/twitter.php @@ -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 '
' . sprintf(_("Error connecting to Twitter: %s Details have been logged for the administrator."), $e->getMessage()) . '
'; echo ''; 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? -- 2.11.0