]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
do a real retweet for a local repeat
authorEvan Prodromou <evan@status.net>
Fri, 3 Sep 2010 21:34:10 +0000 (17:34 -0400)
committerEvan Prodromou <evan@status.net>
Fri, 3 Sep 2010 21:34:10 +0000 (17:34 -0400)
plugins/TwitterBridge/twitter.php
plugins/TwitterBridge/twitteroauthclient.php

index 9c2ba502bfa58b701bc9f111c5c7310e3e3a0712..20cdf42b823276f477dfc5240020037d2efe6299 100644 (file)
@@ -145,17 +145,43 @@ function broadcast_twitter($notice)
     $flink = Foreign_link::getByUserID($notice->profile_id,
                                        TWITTER_SERVICE);
 
-    if (is_twitter_bound($notice, $flink)) {
-        if (TwitterOAuthClient::isPackedToken($flink->credentials)) {
+    // Don't bother with basic auth, since it's no longer allowed
+
+    if (!empty($flink) && TwitterOAuthClient::isPackedToken($flink->credentials)) {
+        if (!empty($notice->repeat_of) && is_twitter_notice($notice->repeat_of)) {
+            return retweet_notice($flink, Notice::staticGet('id', $notice->repeat_of));
+        } else if (is_twitter_bound($notice, $flink)) {
             return broadcast_oauth($notice, $flink);
-        } else {
-            return broadcast_basicauth($notice, $flink);
         }
     }
 
     return true;
 }
 
+function retweet_notice($flink, $notice)
+{
+    $token = TwitterOAuthClient::unpackToken($flink->credentials);
+    $client = new TwitterOAuthClient($token->key, $token->secret);
+
+    $id = twitter_status_id($notice);
+
+    try {
+        $status = $client->statusesRetweet($id);
+    } catch (OAuthClientException $e) {
+        return process_error($e, $flink, $notice);
+    }
+}
+
+function twitter_status_id($notice)
+{
+    if ($notice->source == 'twitter' &&
+        preg_match('#^http://twitter.com/[\w_.]+/status/(\d+)$#', $notice->uri, $match)) {
+        return $match[1];
+    }
+
+    return null;
+}
+
 /**
  * Pull any extra information from a notice that we should transfer over
  * to Twitter beyond the notice text itself.
index d895d8c73cbbac3d754f9694f7d18884bff223d0..5e5761360c0932abc1820ee70646cc0aa9c07d99 100644 (file)
@@ -277,4 +277,19 @@ class TwitterOAuthClient extends OAuthClient
         return $ids;
     }
 
+    /**
+     * Calls Twitter's /statuses/retweet/id.json API method
+     *
+     * @param int $id id of the notice to retweet
+     *
+     * @return retweeted status
+     */
+
+    function statusesRetweet($id)
+    {
+        $url = "http://api.twitter.com/1/statuses/retweet/$id.json";
+        $response = $this->oAuthPost($url);
+        $status = json_decode($response);
+        return $status;
+    }
 }