summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-04-14 15:58:42 +0200
committerBrion Vibber <brion@pobox.com>2010-04-14 15:58:42 +0200
commitc95bff77446f7ce3454ef62b0c22e298de1d3e69 (patch)
tree817507654fd75c12efe5926812f61375a50a1338 /plugins
parent3da50c19dfff7645dc46f1b836ebf4ecda726129 (diff)
parentefcdfabc1225a2fdcb37a6cc3c96982b24b88d8f (diff)
Merge branch 'master' into testing
Diffstat (limited to 'plugins')
-rw-r--r--plugins/TwitterBridge/twitter.php26
-rw-r--r--plugins/TwitterBridge/twitterbasicauthclient.php15
-rw-r--r--plugins/TwitterBridge/twitteroauthclient.php17
3 files changed, 44 insertions, 14 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/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;