summaryrefslogtreecommitdiff
path: root/controllers/controllers.php
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2017-05-17 11:40:32 +0200
committerAaron Parecki <aaron@parecki.com>2017-05-17 11:40:32 +0200
commit0417646b55eb8b1637c740f0c39de649af84e5cd (patch)
tree0bbe72d7631aa0c013b23822479774161431adbf /controllers/controllers.php
parentf08de4043ee6b1a9a4a2282b1ea417f378a82164 (diff)
send syndication URL for twitter likes/reposts
likes and reposts the tweet on twitter first, then sends a syndication URL in the micropub endpoint
Diffstat (limited to 'controllers/controllers.php')
-rw-r--r--controllers/controllers.php32
1 files changed, 24 insertions, 8 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php
index ecc3a9e..1860f60 100644
--- a/controllers/controllers.php
+++ b/controllers/controllers.php
@@ -512,12 +512,9 @@ $app->get('/settings/html-content', function() use($app) {
});
function create_favorite(&$user, $url) {
- $micropub_request = array(
- 'like-of' => $url
- );
- $r = micropub_post_for_user($user, $micropub_request);
$tweet_id = false;
+ $twitter_syndication = false;
// POSSE favorites to Twitter
if($user->twitter_access_token && preg_match('/https?:\/\/(?:www\.)?twitter\.com\/[^\/]+\/status(?:es)?\/(\d+)/', $url, $match)) {
@@ -527,8 +524,19 @@ function create_favorite(&$user, $url) {
$result = $twitter->post('favorites/create', array(
'id' => $tweet_id
));
+ if(property_exists($result, 'id_str')) {
+ $twitter_syndication = 'https://twitter.com/'.$user->twitter_username.'/status/'.$result->id_str;
+ }
}
+ $micropub_request = array(
+ 'like-of' => $url
+ );
+ if($twitter_syndication) {
+ $micropub_request['syndication'] = $twitter_syndication;
+ }
+ $r = micropub_post_for_user($user, $micropub_request);
+
return $r;
}
@@ -545,20 +553,28 @@ function edit_favorite(&$user, $post_url, $like_of) {
}
function create_repost(&$user, $url) {
- $micropub_request = array(
- 'repost-of' => $url
- );
- $r = micropub_post_for_user($user, $micropub_request);
$tweet_id = false;
+ $twitter_syndication = false;
if($user->twitter_access_token && preg_match('/https?:\/\/(?:www\.)?twitter\.com\/[^\/]+\/status(?:es)?\/(\d+)/', $url, $match)) {
$tweet_id = $match[1];
$twitter = new TwitterOAuth(Config::$twitterClientID, Config::$twitterClientSecret,
$user->twitter_access_token, $user->twitter_token_secret);
$result = $twitter->post('statuses/retweet/'.$tweet_id);
+ if(property_exists($result, 'id_str')) {
+ $twitter_syndication = 'https://twitter.com/'.$user->twitter_username.'/status/'.$result->id_str;
+ }
}
+ $micropub_request = array(
+ 'repost-of' => $url
+ );
+ if($twitter_syndication) {
+ $micropub_request['syndication'] = $twitter_syndication;
+ }
+ $r = micropub_post_for_user($user, $micropub_request);
+
return $r;
}