From f650a35d67982bfe8c4409eca3a55680752a34ef Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Thu, 1 Jul 2010 12:52:50 -0400 Subject: [PATCH] Add a Binder for Horde_Service_Twitter --- framework/Core/lib/Horde/Registry.php | 3 +- framework/Core/package.xml | 256 +++++++++++++++++++--------------- horde/lib/Block/twitter_timeline.php | 64 ++------- horde/services/twitter.php | 48 +------ 4 files changed, 163 insertions(+), 208 deletions(-) diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 1f9968920..11ce32672 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -264,7 +264,8 @@ class Horde_Registry 'Horde_Template' => new Horde_Core_Binder_Template(), 'Horde_Token' => new Horde_Core_Binder_Token(), 'Horde_Vfs' => new Horde_Core_Binder_Vfs(), - 'Net_DNS_Resolver' => new Horde_Core_Binder_Dns() + 'Net_DNS_Resolver' => new Horde_Core_Binder_Dns(), + 'Horde_Service_Twitter' => new Horde_Core_Binder_Twitter() ); /* Define factories. */ diff --git a/framework/Core/package.xml b/framework/Core/package.xml index 5630b9f06..79406433d 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -1,14 +1,10 @@ - + Core pear.horde.org Horde Core Framework libraries These classes provide the core functionality of the Horde -Application Framework. - +Application Framework. Chuck Hagenbuch chuck @@ -27,7 +23,8 @@ Application Framework. slusarz@horde.org yes - 2009-07-08 + 2010-07-01 + 0.1.0 0.1.0 @@ -37,7 +34,8 @@ Application Framework. beta LGPL - * Import application auth driver from horde/Auth. + +* Import application auth driver from horde/Auth. * Import signup code from horde/Auth. * Import Horde backend driver from horde/LoginTasks. * Import perms UI handling class from horde/Perms. @@ -54,19 +52,14 @@ Application Framework. * Converted Horde to Horde 4 coding conventions. - + - - - - - @@ -74,9 +67,12 @@ Application Framework. + + + + - @@ -93,6 +89,7 @@ Application Framework. + @@ -106,17 +103,17 @@ Application Framework. + + - - + - @@ -148,14 +145,11 @@ Application Framework. + - - - - @@ -164,24 +158,32 @@ Application Framework. - + + + + + + - - + + + + + @@ -271,90 +273,109 @@ Application Framework. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0.0.1 + 0.0.1 + + + beta + beta + + 2004-02-13 + LGPL + +Initial packaging + + + 2006-05-08 @@ -367,21 +388,36 @@ Application Framework. LGPL - * Converted to package.xml 2.0 for pear.horde.org +* Converted to package.xml 2.0 for pear.horde.org - 0.0.1 - 0.0.1 + 0.1.0 + 0.1.0 beta beta - 2004-02-13 + 2010-07-01 LGPL - Initial packaging + +* Import application auth driver from horde/Auth. + * Import signup code from horde/Auth. + * Import Horde backend driver from horde/LoginTasks. + * Import perms UI handling class from horde/Perms. + * Import prefs UI handling class from horde/Prefs. + * Convert from PEAR Log to Horde_Log for logging. + * Add Horde_Themes:: class. + * Add Horde::nocacheUrl(). + * Remove dependency on Horde_DOM package. + * Added Horde_Registry_Api:: and Horde_Registry_Application:: classes. + * Moved Horde_Exception to Exception package. + * Renamed Menu:: as Horde_Menu::. + * Renamed Help:: as Horde_Help::. + * Removed Text::/Horde_Text::. + * Converted Horde to Horde 4 coding conventions. diff --git a/horde/lib/Block/twitter_timeline.php b/horde/lib/Block/twitter_timeline.php index d1d99564c..2a9064f40 100644 --- a/horde/lib/Block/twitter_timeline.php +++ b/horde/lib/Block/twitter_timeline.php @@ -286,65 +286,17 @@ EOF; private function _getTwitterObject() { - if (!empty($this->_twitter)) { - return $this->_twitter; + $token = unserialize($GLOBALS['prefs']->getValue('twitter')); + if (empty($token['key']) && empty($token['secret'])) { + $pref_link = Horde::link(Horde::url('services/twitter.php', true)); + throw new Horde_Exception(sprintf(_("You have not properly connected your Twitter account with Horde. You should check your Twitter settings in your %s."), $pref_link . _("preferences") . '')); } - $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); + $this->_twitter = $GLOBALS['injector']->getInstance('Horde_Service_Twitter'); + $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']); + $this->_twitter->auth->setToken($auth_token); - if (!empty($GLOBALS['conf']['twitter']['key']) && - !empty($GLOBALS['conf']['twitter']['secret'])) { - - // Using OAuth but make sure the user has gotten a token - $token = unserialize($GLOBALS['prefs']->getValue('twitter')); - if (empty($token['key']) && empty($token['secret'])) { - // No token - try HTTP Basic Auth - $pref_link = Horde::link(Horde::url('services/twitter.php', true)); - throw new Horde_Exception(sprintf(_("You have not properly connected your Twitter account with Horde. You should check your Twitter settings in your %s."), $pref_link . _("preferences") . '')); - } - - $consumer_key = $GLOBALS['conf']['twitter']['key']; - $consumer_secret = $GLOBALS['conf']['twitter']['secret']; - - /* Parameters required for the Horde_Oauth_Consumer */ - $params = array('key' => $consumer_key, - 'secret' => $consumer_secret, - 'requestTokenUrl' => Horde_Service_Twitter::REQUEST_TOKEN_URL, - 'authorizeTokenUrl' => Horde_Service_Twitter::USER_AUTHORIZE_URL, - 'accessTokenUrl' => Horde_Service_Twitter::ACCESS_TOKEN_URL, - 'signatureMethod' => new Horde_Oauth_SignatureMethod_HmacSha1()); - - /* Create the Consumer */ - $oauth = new Horde_Oauth_Consumer($params); - - /* Create the Twitter client */ - // @TODO: use a binder - especially once we start integrating other - // apps with Twitter - $twitter = new Horde_Service_Twitter(array('oauth' => $oauth, - 'cache' => $cache)); - $twitter->setHttpClient($GLOBALS['injector']->getInstance('Horde_Http_Client')); - $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']); - $twitter->auth->setToken($auth_token); - - $this->_twitter = $twitter; - return $twitter; - - } elseif (!empty($this->_params['username']) || - !empty($this->_params['password'])) { - - // Store the username and password in the session to enable - // services/twitterapi.php's functionality. - $_SESSION['horde']['twitterblock']['username'] = $this->_params['username']; - $_SESSION['horde']['twitterblock']['password'] = $this->_params['password']; - $twitter = new Horde_Service_Twitter(array('username' => $this->_params['username'], - 'password' => $this->_params['password'], - 'cache' => $cache)); - - $this->_twitter = $twitter; - return $twitter; - } - - throw new Horde_Exception(_("Must configure a Twitter username and password to use this block.")); + return $this->_twitter; } } diff --git a/horde/services/twitter.php b/horde/services/twitter.php index fb886aa9e..67b9939a6 100644 --- a/horde/services/twitter.php +++ b/horde/services/twitter.php @@ -18,46 +18,15 @@ if (empty($conf['twitter']['enabled'])) { exit; } -/* Using OAuth or Http Basic? */ -if (!empty($conf['twitter']['key']) && !empty($conf['twitter']['secret'])) { - /* Keys - these are obtained when registering for the service */ - $consumer_key = $conf['twitter']['key']; - $consumer_secret = $conf['twitter']['secret']; +$twitter = $GLOBALS['injector']->getInstance('Horde_Service_Twitter'); - /* Parameters required for the Horde_Oauth_Consumer */ - $params = array( - 'key' => $consumer_key, - 'secret' => $consumer_secret, - 'requestTokenUrl' => Horde_Service_Twitter::REQUEST_TOKEN_URL, - 'authorizeTokenUrl' => Horde_Service_Twitter::USER_AUTHORIZE_URL, - 'accessTokenUrl' => Horde_Service_Twitter::ACCESS_TOKEN_URL, - 'signatureMethod' => new Horde_Oauth_SignatureMethod_HmacSha1() - ); +/* See if we have an existing token for the current user */ +$token = unserialize($prefs->getValue('twitter')); - /* Create the Consumer */ - $oauth = new Horde_Oauth_Consumer($params); - - /* Create the Twitter client */ - $twitter = new Horde_Service_Twitter(array( - 'cache' => $injector->getInstance('Horde_Cache'), - 'oauth' => $oauth - )); - - /* See if we have an existing token for the current user */ - $token = unserialize($prefs->getValue('twitter')); - - /* Check for an existing token */ - if (!empty($token['key']) && !empty($token['secret'])) { - $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']); - $twitter->auth->setToken($auth_token); - } -} elseif (!empty($_SESSION['horde']['twitterblock']['username']) && - !empty($_SESSION['horde']['twitterblock']['password'])) { - $twitter = new Horde_Service_Twitter(array( - 'cache' => $injector->getInstance('Horde_Cache'), - 'password' => $_SESSION['horde']['twitterblock']['password'], - 'username' => $_SESSION['horde']['twitterblock']['username'] - )); +/* Check for an existing token */ +if (!empty($token['key']) && !empty($token['secret'])) { + $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']); + $twitter->auth->setToken($auth_token); } /* See if we are here for any actions */ @@ -128,9 +97,6 @@ if (!empty($auth_token)) { } } -// Start rendering the prefs page -//$csslink = $registry->get('themesuri', 'horde') . '/facebook.css'; - /* Could not find a valid auth token, and we are not in the process of getting one */ if (empty($profile)) { try { -- 2.11.0