From 43afa0adbeb16b0f56f541bffa6be6bd4a4bd6a4 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sun, 18 Jul 2010 12:20:02 -0400 Subject: [PATCH] Twitter prefs fixes --- horde/lib/Prefs/Ui.php | 76 ++++++++++++++++++++++++++++++++++++++ horde/services/twitter.php | 30 --------------- horde/templates/prefs/twitter.html | 24 ++++++++++++ 3 files changed, 100 insertions(+), 30 deletions(-) create mode 100644 horde/templates/prefs/twitter.html diff --git a/horde/lib/Prefs/Ui.php b/horde/lib/Prefs/Ui.php index 6a0b9fd6a..fa267ac48 100644 --- a/horde/lib/Prefs/Ui.php +++ b/horde/lib/Prefs/Ui.php @@ -147,6 +147,9 @@ class Horde_Prefs_Ui case 'facebookmanagement': return $this->_facebookManagement($ui); + case 'twittermanagement': + return $this->_twitterManagement($ui); + return ''; } } @@ -180,6 +183,9 @@ class Horde_Prefs_Ui case 'facebookmanagement': $this->_updateFacebookManagement($ui); break; + + case 'twittermanagement': + $this->_updateTwitterManagement($ui); } return false; @@ -555,6 +561,55 @@ class Horde_Prefs_Ui return $t->fetch(HORDE_TEMPLATES . '/prefs/facebook.html'); } + protected function _twitterManagement($ui) + { + global $prefs, $registry; + + $twitter = $GLOBALS['injector']->getInstance('Horde_Service_Twitter'); + $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); + } + try { + $profile = Horde_Serialize::unserialize($twitter->account->verifyCredentials(), Horde_Serialize::JSON); + } catch (Horde_Service_Twitter_Exception $e) {} + + $t = $GLOBALS['injector']->createInstance('Horde_Template'); + $t->setOption('gettext', true); + $t->set('css_link', $GLOBALS['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 { + $results = $twitter->auth->getRequestToken(); + } catch (Horde_Service_Twitter_Exception $e) { + $t->set('error', sprintf(_("Error connecting to Twitter: %s Details have been logged for the administrator."), $e->getMessage()), true); + //echo '
' . sprintf(_("Error connecting to Twitter: %s Details have been logged for the administrator."), $e->getMessage()) . '
'; + //echo ''; + //require HORDE_TEMPLATES . '/common-footer.inc'; + exit; + } + $_SESSION['twitter_request_secret'] = $results->secret; + + $t->set('appname', $registry->get('name')); + $t->set('link', Horde::link(Horde::externalUrl($twitter->auth->getUserAuthorizationUrl($results), false), '', 'fbbutton', '', 'openTwitterWindow(); return false;') . 'Twitter'); + $t->set('popupjs', Horde::popupJs(Horde::externalUrl($twitter->auth->getUserAuthorizationUrl($results), false), array('urlencode' => true))); + } else { + /* We know we have a good Twitter token here, so check for any actions... */ + $t->set('haveSession', true, true); + $t->set('profile_image_url', $profile->profile_image_url); + $t->set('profile_screenname', htmlspecialchars($profile->screen_name)); + $t->set('profile_name', htmlspecialchars($profile->name)); + $t->set('profile_location', htmlspecialchars($profile->location)); + $t->set('appname', $registry->get('name')); + } + + return $t->fetch(HORDE_TEMPLATES . '/prefs/twitter.html'); + } + /** * Update category related preferences. * @@ -765,4 +820,25 @@ class Horde_Prefs_Ui } } + protected function _updateTwitterManagement($ui) + { + global $prefs, $registry; + + $twitter = $GLOBALS['injector']->getInstance('Horde_Service_Twitter'); + $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); + } + + switch ($ui->vars->twitteractionID) { + case 'revokeInfinite': + $twitter->account->endSession(); + $prefs->setValue('twitter', 'a:0:{}'); + echo ''; + exit; + } + } } diff --git a/horde/services/twitter.php b/horde/services/twitter.php index 004b8761d..e81fece0c 100644 --- a/horde/services/twitter.php +++ b/horde/services/twitter.php @@ -32,11 +32,6 @@ if (!empty($token['key']) && !empty($token['secret'])) { /* See if we are here for any actions */ $action = Horde_Util::getPost('actionID'); switch ($action) { -case 'revokeInfinite': - $twitter->account->endSession(); - $prefs->setValue('twitter', 'a:0:{}'); - echo ''; - exit; case 'updateStatus': $result = $twitter->statuses->update(Horde_Util::getPost('statusText'), Horde_Util::getPost('inReplyTo', '')); @@ -148,28 +143,3 @@ if (!empty($auth_token)) { } } } - -/* Could not find a valid auth token, and we are not in the process of getting one */ -if (empty($profile)) { - try { - $results = $twitter->auth->getRequestToken(); - } 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; - } - $_SESSION['twitter_request_secret'] = $results->secret; - echo '
' . sprintf(_("Could not find authorization for %s to interact with your Twitter account."), $registry->get('name')) . '
'; - $link = Horde::link(Horde::externalUrl($twitter->auth->getUserAuthorizationUrl($results), false), '', 'fbbutton', '', 'openTwitterWindow(); return false;'); - echo ''; - echo sprintf(_("Login to Twitter and authorize the %s application:"), $registry->get('name')) . $link . 'Twitter'; -} else { - /* We know we have a good Twitter token here, so check for any actions... */ - echo '
'; - echo '' . htmlspecialchars($profile->screen_name) . ''; - echo '
' . htmlspecialchars($profile->name) . '
' . htmlspecialchars($profile->location) . '
'; - echo '
 
'; - echo '
' . sprintf(_("%s can interact with your Twitter account."), $registry->get('name')); - echo '
'; -} diff --git a/horde/templates/prefs/twitter.html b/horde/templates/prefs/twitter.html new file mode 100644 index 000000000..c03b9673f --- /dev/null +++ b/horde/templates/prefs/twitter.html @@ -0,0 +1,24 @@ + + + +
+ <tag:profile_screenname /> +
+
+
 
+
+ can interact with your Twitter account. +
+
+ +
+ Could not find authorization for to interact with your Twitter account +
+ + Login to Twitter and authorize the application: +
+
\ No newline at end of file -- 2.11.0