forked from GNUsocial/gnu-social
Notify Twitter when StatusNet user faves/disfaves a Twitter notice
This commit is contained in:
parent
5944fe57e6
commit
ba8a24073f
@ -428,4 +428,77 @@ class TwitterBridgePlugin extends Plugin
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify remote users when their notices get favorited.
|
||||
*
|
||||
* @param Profile or User $profile of local user doing the faving
|
||||
* @param Notice $notice being favored
|
||||
* @return hook return value
|
||||
*/
|
||||
|
||||
function onEndFavorNotice(Profile $profile, Notice $notice)
|
||||
{
|
||||
$flink = Foreign_link::getByUserID($profile->id,
|
||||
TWITTER_SERVICE); // twitter service
|
||||
|
||||
if (empty($flink)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!TwitterOAuthClient::isPackedToken($flink->credentials)) {
|
||||
$this->log(LOG_INFO, "Skipping fave processing for {$profile->id} since link is not OAuth.");
|
||||
return true;
|
||||
}
|
||||
|
||||
$status_id = twitter_status_id($notice);
|
||||
|
||||
if (empty($status_id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$token = TwitterOAuthClient::unpackToken($flink->credentials);
|
||||
$client = new TwitterOAuthClient($token->key, $token->secret);
|
||||
|
||||
$client->favoritesCreate($status_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify remote users when their notices get de-favorited.
|
||||
*
|
||||
* @param Profile $profile Profile person doing the de-faving
|
||||
* @param Notice $notice Notice being favored
|
||||
*
|
||||
* @return hook return value
|
||||
*/
|
||||
|
||||
function onEndDisfavorNotice(Profile $profile, Notice $notice)
|
||||
{
|
||||
$flink = Foreign_link::getByUserID($profile->id,
|
||||
TWITTER_SERVICE); // twitter service
|
||||
|
||||
if (empty($flink)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!TwitterOAuthClient::isPackedToken($flink->credentials)) {
|
||||
$this->log(LOG_INFO, "Skipping fave processing for {$profile->id} since link is not OAuth.");
|
||||
return true;
|
||||
}
|
||||
|
||||
$status_id = twitter_status_id($notice);
|
||||
|
||||
if (empty($status_id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$token = TwitterOAuthClient::unpackToken($flink->credentials);
|
||||
$client = new TwitterOAuthClient($token->key, $token->secret);
|
||||
|
||||
$client->favoritesDestroy($status_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -292,4 +292,36 @@ class TwitterOAuthClient extends OAuthClient
|
||||
$status = json_decode($response);
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls Twitter's /favorites/create API method
|
||||
*
|
||||
* @param int $id ID of the status to favorite
|
||||
*
|
||||
* @return object faved status
|
||||
*/
|
||||
|
||||
function favoritesCreate($id)
|
||||
{
|
||||
$url = "http://api.twitter.com/1/favorites/create/$id.json";
|
||||
$response = $this->oAuthPost($url);
|
||||
$status = json_decode($response);
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls Twitter's /favorites/destroy API method
|
||||
*
|
||||
* @param int $id ID of the status to unfavorite
|
||||
*
|
||||
* @return object unfaved status
|
||||
*/
|
||||
|
||||
function favoritesDestroy($id)
|
||||
{
|
||||
$url = "http://api.twitter.com/1/favorites/destroy/$id.json";
|
||||
$response = $this->oAuthPost($url);
|
||||
$status = json_decode($response);
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user