diff options
author | Evan Prodromou <evan@status.net> | 2010-04-26 02:43:33 -0400 |
---|---|---|
committer | Evan Prodromou <evan@status.net> | 2010-04-26 02:43:33 -0400 |
commit | 5c05cd2b1a93d360bde7cb7dfc9ba39e5a5a7624 (patch) | |
tree | 5b4092e365023c7729fcdd8260431d3ffb28b519 /plugins/TwitterBridge | |
parent | 14adb7cc41e3d5d4e543c1f13f7a60d3cadb5c71 (diff) | |
parent | d7d3a50d8751f071aa95541813af1d190e71430e (diff) |
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
Diffstat (limited to 'plugins/TwitterBridge')
-rw-r--r-- | plugins/TwitterBridge/twitter.php | 26 | ||||
-rw-r--r-- | plugins/TwitterBridge/twitterauthorization.php | 18 | ||||
-rw-r--r-- | plugins/TwitterBridge/twitterbasicauthclient.php | 15 | ||||
-rw-r--r-- | plugins/TwitterBridge/twitteroauthclient.php | 17 |
4 files changed, 58 insertions, 18 deletions
diff --git a/plugins/TwitterBridge/twitter.php b/plugins/TwitterBridge/twitter.php index 2805b3ab5..21adc7a90 100644 --- a/plugins/TwitterBridge/twitter.php +++ b/plugins/TwitterBridge/twitter.php @@ -124,15 +124,36 @@ function broadcast_twitter($notice) return true; } +/** + * Pull any extra information from a notice that we should transfer over + * to Twitter beyond the notice text itself. + * + * @param Notice $notice + * @return array of key-value pairs for Twitter update submission + * @access private + */ +function twitter_update_params($notice) +{ + $params = array(); + if ($notice->lat || $notice->lon) { + $params['lat'] = $notice->lat; + $params['long'] = $notice->lon; + } + return $params; +} + + function broadcast_oauth($notice, $flink) { $user = $flink->getUser(); $statustxt = format_status($notice); + $params = twitter_update_params($notice); + $token = TwitterOAuthClient::unpackToken($flink->credentials); $client = new TwitterOAuthClient($token->key, $token->secret); $status = null; try { - $status = $client->statusesUpdate($statustxt); + $status = $client->statusesUpdate($statustxt, $params); } catch (OAuthClientException $e) { return process_error($e, $flink, $notice); } @@ -171,12 +192,13 @@ function broadcast_basicauth($notice, $flink) $user = $flink->getUser(); $statustxt = format_status($notice); + $params = twitter_update_params($notice); $client = new TwitterBasicAuthClient($flink); $status = null; try { - $status = $client->statusesUpdate($statustxt); + $status = $client->statusesUpdate($statustxt, $params); } catch (BasicAuthException $e) { return process_error($e, $flink, $notice); } diff --git a/plugins/TwitterBridge/twitterauthorization.php b/plugins/TwitterBridge/twitterauthorization.php index bc004cb95..7a896e168 100644 --- a/plugins/TwitterBridge/twitterauthorization.php +++ b/plugins/TwitterBridge/twitterauthorization.php @@ -332,6 +332,11 @@ class TwitterauthorizationAction extends Action parent::showPage(); } + /** + * @fixme much of this duplicates core code, which is very fragile. + * Should probably be replaced with an extensible mini version of + * the core registration form. + */ function showContent() { if (!empty($this->message_text)) { @@ -353,10 +358,15 @@ class TwitterauthorizationAction extends Action 'name' => 'license', 'value' => 'true')); $this->elementStart('label', array('class' => 'checkbox', 'for' => 'license')); - $this->text(_('My text and files are available under ')); - $this->element('a', array('href' => common_config('license', 'url')), - common_config('license', 'title')); - $this->text(_(' except this private data: password, email address, IM address, phone number.')); + $message = _('My text and files are available under %s ' . + 'except this private data: password, ' . + 'email address, IM address, and phone number.'); + $link = '<a href="' . + htmlspecialchars(common_config('license', 'url')) . + '">' . + htmlspecialchars(common_config('license', 'title')) . + '</a>'; + $this->raw(sprintf(htmlspecialchars($message), $link)); $this->elementEnd('label'); $this->elementEnd('li'); $this->elementEnd('ul'); diff --git a/plugins/TwitterBridge/twitterbasicauthclient.php b/plugins/TwitterBridge/twitterbasicauthclient.php index fd26293f9..2c18c9469 100644 --- a/plugins/TwitterBridge/twitterbasicauthclient.php +++ b/plugins/TwitterBridge/twitterbasicauthclient.php @@ -76,18 +76,21 @@ class TwitterBasicAuthClient /** * Calls Twitter's /statuses/update API method * - * @param string $status text of the status - * @param int $in_reply_to_status_id optional id of the status it's - * a reply to + * @param string $status text of the status + * @param mixed $params optional other parameters to pass to Twitter, + * as defined. For back-compatibility, if an int + * is passed we'll consider it a reply-to ID. * * @return mixed the status */ function statusesUpdate($status, $in_reply_to_status_id = null) { $url = 'https://twitter.com/statuses/update.json'; - $params = array('status' => $status, - 'source' => common_config('integration', 'source'), - 'in_reply_to_status_id' => $in_reply_to_status_id); + if (is_numeric($params)) { + $params = array('in_reply_to_status_id' => intval($params)); + } + $params['status'] = $status; + $params['source'] = common_config('integration', 'source'); $response = $this->httpRequest($url, $params); $status = json_decode($response); return $status; diff --git a/plugins/TwitterBridge/twitteroauthclient.php b/plugins/TwitterBridge/twitteroauthclient.php index 93f6aadd1..d895d8c73 100644 --- a/plugins/TwitterBridge/twitteroauthclient.php +++ b/plugins/TwitterBridge/twitteroauthclient.php @@ -166,17 +166,22 @@ class TwitterOAuthClient extends OAuthClient /** * Calls Twitter's /statuses/update API method * - * @param string $status text of the status - * @param int $in_reply_to_status_id optional id of the status it's - * a reply to + * @param string $status text of the status + * @param mixed $params optional other parameters to pass to Twitter, + * as defined. For back-compatibility, if an int + * is passed we'll consider it a reply-to ID. * * @return mixed the status */ - function statusesUpdate($status, $in_reply_to_status_id = null) + function statusesUpdate($status, $params=array()) { $url = 'https://twitter.com/statuses/update.json'; - $params = array('status' => $status, - 'in_reply_to_status_id' => $in_reply_to_status_id); + if (is_numeric($params)) { + $params = array('in_reply_to_status_id' => intval($params)); + } + $params['status'] = $status; + // We don't have to pass 'source' as the oauth key is tied to an app. + $response = $this->oAuthPost($url, $params); $status = json_decode($response); return $status; |