Merge branch 'testing' into 0.9.x
This commit is contained in:
commit
c748933132
@ -124,15 +124,36 @@ function broadcast_twitter($notice)
|
|||||||
return true;
|
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) {
|
function broadcast_oauth($notice, $flink) {
|
||||||
$user = $flink->getUser();
|
$user = $flink->getUser();
|
||||||
$statustxt = format_status($notice);
|
$statustxt = format_status($notice);
|
||||||
|
$params = twitter_update_params($notice);
|
||||||
|
|
||||||
$token = TwitterOAuthClient::unpackToken($flink->credentials);
|
$token = TwitterOAuthClient::unpackToken($flink->credentials);
|
||||||
$client = new TwitterOAuthClient($token->key, $token->secret);
|
$client = new TwitterOAuthClient($token->key, $token->secret);
|
||||||
$status = null;
|
$status = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$status = $client->statusesUpdate($statustxt);
|
$status = $client->statusesUpdate($statustxt, $params);
|
||||||
} catch (OAuthClientException $e) {
|
} catch (OAuthClientException $e) {
|
||||||
return process_error($e, $flink, $notice);
|
return process_error($e, $flink, $notice);
|
||||||
}
|
}
|
||||||
@ -171,12 +192,13 @@ function broadcast_basicauth($notice, $flink)
|
|||||||
$user = $flink->getUser();
|
$user = $flink->getUser();
|
||||||
|
|
||||||
$statustxt = format_status($notice);
|
$statustxt = format_status($notice);
|
||||||
|
$params = twitter_update_params($notice);
|
||||||
|
|
||||||
$client = new TwitterBasicAuthClient($flink);
|
$client = new TwitterBasicAuthClient($flink);
|
||||||
$status = null;
|
$status = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$status = $client->statusesUpdate($statustxt);
|
$status = $client->statusesUpdate($statustxt, $params);
|
||||||
} catch (BasicAuthException $e) {
|
} catch (BasicAuthException $e) {
|
||||||
return process_error($e, $flink, $notice);
|
return process_error($e, $flink, $notice);
|
||||||
}
|
}
|
||||||
|
@ -76,18 +76,21 @@ class TwitterBasicAuthClient
|
|||||||
/**
|
/**
|
||||||
* Calls Twitter's /statuses/update API method
|
* Calls Twitter's /statuses/update API method
|
||||||
*
|
*
|
||||||
* @param string $status text of the status
|
* @param string $status text of the status
|
||||||
* @param int $in_reply_to_status_id optional id of the status it's
|
* @param mixed $params optional other parameters to pass to Twitter,
|
||||||
* a reply to
|
* as defined. For back-compatibility, if an int
|
||||||
|
* is passed we'll consider it a reply-to ID.
|
||||||
*
|
*
|
||||||
* @return mixed the status
|
* @return mixed the status
|
||||||
*/
|
*/
|
||||||
function statusesUpdate($status, $in_reply_to_status_id = null)
|
function statusesUpdate($status, $in_reply_to_status_id = null)
|
||||||
{
|
{
|
||||||
$url = 'https://twitter.com/statuses/update.json';
|
$url = 'https://twitter.com/statuses/update.json';
|
||||||
$params = array('status' => $status,
|
if (is_numeric($params)) {
|
||||||
'source' => common_config('integration', 'source'),
|
$params = array('in_reply_to_status_id' => intval($params));
|
||||||
'in_reply_to_status_id' => $in_reply_to_status_id);
|
}
|
||||||
|
$params['status'] = $status;
|
||||||
|
$params['source'] = common_config('integration', 'source');
|
||||||
$response = $this->httpRequest($url, $params);
|
$response = $this->httpRequest($url, $params);
|
||||||
$status = json_decode($response);
|
$status = json_decode($response);
|
||||||
return $status;
|
return $status;
|
||||||
|
@ -166,17 +166,22 @@ class TwitterOAuthClient extends OAuthClient
|
|||||||
/**
|
/**
|
||||||
* Calls Twitter's /statuses/update API method
|
* Calls Twitter's /statuses/update API method
|
||||||
*
|
*
|
||||||
* @param string $status text of the status
|
* @param string $status text of the status
|
||||||
* @param int $in_reply_to_status_id optional id of the status it's
|
* @param mixed $params optional other parameters to pass to Twitter,
|
||||||
* a reply to
|
* as defined. For back-compatibility, if an int
|
||||||
|
* is passed we'll consider it a reply-to ID.
|
||||||
*
|
*
|
||||||
* @return mixed the status
|
* @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';
|
$url = 'https://twitter.com/statuses/update.json';
|
||||||
$params = array('status' => $status,
|
if (is_numeric($params)) {
|
||||||
'in_reply_to_status_id' => $in_reply_to_status_id);
|
$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);
|
$response = $this->oAuthPost($url, $params);
|
||||||
$status = json_decode($response);
|
$status = json_decode($response);
|
||||||
return $status;
|
return $status;
|
||||||
|
Loading…
Reference in New Issue
Block a user