Browse Source

send syndication URL for twitter likes/reposts

likes and reposts the tweet on twitter first, then sends a syndication URL in the micropub endpoint
pull/82/head
Aaron Parecki 8 years ago
parent
commit
0417646b55
No known key found for this signature in database GPG Key ID: 276C2817346D6056
  1. 32
      controllers/controllers.php
  2. 2
      lib/helpers.php

32
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;
}

2
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);

Loading…
Cancel
Save