diff options
-rw-r--r-- | controllers/controllers.php | 32 | ||||
-rw-r--r-- | lib/helpers.php | 2 |
2 files changed, 25 insertions, 9 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; } diff --git a/lib/helpers.php b/lib/helpers.php index 198534f..f48c986 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -151,7 +151,7 @@ function micropub_post($endpoint, $params, $access_token, $file_path = NULL, $js $multipart->addArray($params); $multipart->addFile($file_prop, $file_path, $mimetype); $post = $multipart->data(); - array_push($httpheaders, 'Content-Type: ' . $multipart->contentType()); + $httpheaders[] = 'Content-Type: ' . $multipart->contentType(); } curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheaders); |