forked from friendica/friendica-addons
twitter: Repeating twitter items now does a native twitter retweet
This commit is contained in:
parent
6de8e46728
commit
a5ad8f947b
|
@ -685,9 +685,14 @@ function twitter_post_hook(&$a,&$b) {
|
|||
if($ckey && $csecret && $otoken && $osecret) {
|
||||
logger('twitter: we have customer key and oauth stuff, going to send.', LOGGER_DEBUG);
|
||||
|
||||
// If it's a repeated message from twitter then do a native retweet and exit
|
||||
if (twitter_is_retweet($a, $b['uid'], $b['body']))
|
||||
return;
|
||||
|
||||
require_once('library/twitteroauth.php');
|
||||
require_once('include/bbcode.php');
|
||||
$tweet = new TwitterOAuth($ckey,$csecret,$otoken,$osecret);
|
||||
|
||||
// in theory max char is 140 but T. uses t.co to make links
|
||||
// longer so we give them 10 characters extra
|
||||
if (!$intelligent_shortening) {
|
||||
|
@ -772,6 +777,7 @@ function twitter_post_hook(&$a,&$b) {
|
|||
$msg = $msgarr["msg"];
|
||||
$image = $msgarr["image"];
|
||||
}
|
||||
|
||||
// and now tweet it :-)
|
||||
if(strlen($msg) and ($image != "")) {
|
||||
$img_str = fetch_url($image);
|
||||
|
@ -797,16 +803,6 @@ function twitter_post_hook(&$a,&$b) {
|
|||
$result = $cb->statuses_updateWithMedia($post);
|
||||
unlink($tempfile);
|
||||
|
||||
/*
|
||||
// Old Code
|
||||
$mime = image_type_to_mime_type(exif_imagetype($tempfile));
|
||||
unlink($tempfile);
|
||||
|
||||
$filename = "upload";
|
||||
|
||||
$result = $tweet->post('statuses/update_with_media', array('media[]' => "{$img_str};type=".$mime.";filename={$filename}" , 'status' => $msg));
|
||||
*/
|
||||
|
||||
logger('twitter_post_with_media send, result: ' . print_r($result, true), LOGGER_DEBUG);
|
||||
if ($result->errors OR $result->error) {
|
||||
logger('Send to Twitter failed: "' . print_r($result->errors, true) . '"');
|
||||
|
@ -1465,6 +1461,10 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
|
|||
$postarray['author-name'] = $post->retweeted_status->user->name;
|
||||
$postarray['author-link'] = "https://twitter.com/".$post->retweeted_status->user->screen_name;
|
||||
$postarray['author-avatar'] = $post->retweeted_status->user->profile_image_url_https;
|
||||
//if (($post->retweeted_status->user->screen_name != "") AND ($post->retweeted_status->id_str != "")) {
|
||||
// $postarray['plink'] = "https://twitter.com/".$post->retweeted_status->user->screen_name."/status/".$post->retweeted_status->id_str;
|
||||
// $postarray['uri'] = "twitter::".$post->retweeted_status->id_str;
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1816,17 +1816,6 @@ function twitter_convertmsg($a, $body, $no_tags = false, $dontincludemedia) {
|
|||
if ($type == "")
|
||||
$type = $oembed_data->type;
|
||||
|
||||
// To-Do:
|
||||
// Twitlonger
|
||||
|
||||
// if (strstr($expanded_url, "//www.youtube.com/"))
|
||||
// $body = str_replace($match[2], "\n[youtube]".$expanded_url."[/youtube]\n", $body);
|
||||
// elseif (strstr($expanded_url, "//player.vimeo.com/"))
|
||||
// $body = str_replace($match[2], "\n[vimeo]".$expanded_url."[/vimeo]\n", $body);
|
||||
// elseif (strstr($expanded_url, "//twitpic.com/")) // Test
|
||||
// $body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body);
|
||||
// elseif (strstr($expanded_url, "//instagram.com/"))
|
||||
// $body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body);
|
||||
if ($oembed_data->type != "link")
|
||||
$body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body);
|
||||
else {
|
||||
|
@ -1948,4 +1937,50 @@ function twitter_fetch_own_contact($a, $uid) {
|
|||
|
||||
return($contact_id);
|
||||
}
|
||||
|
||||
function twitter_is_retweet($a, $uid, $body) {
|
||||
$body = trim($body);
|
||||
|
||||
// Skip if it isn't a pure repeated messages
|
||||
// Does it start with a share?
|
||||
if (strpos($body, "[share") > 0)
|
||||
return(false);
|
||||
|
||||
// Does it end with a share?
|
||||
if (strlen($body) > (strrpos($body, "[/share]") + 8))
|
||||
return(false);
|
||||
|
||||
$attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
|
||||
// Skip if there is no shared message in there
|
||||
if ($body == $attributes)
|
||||
return(false);
|
||||
|
||||
$link = "";
|
||||
preg_match("/link='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$link = $matches[1];
|
||||
|
||||
preg_match('/link="(.*?)"/ism', $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$link = $matches[1];
|
||||
|
||||
$id = preg_replace("=https?://twitter.com/(.*)/status/(.*)=ism", "$2", $link);
|
||||
if ($id == $link)
|
||||
return(false);
|
||||
|
||||
logger('twitter_is_retweet: Retweeting id '.$id.' for user '.$uid, LOGGER_DEBUG);
|
||||
|
||||
$ckey = get_config('twitter', 'consumerkey');
|
||||
$csecret = get_config('twitter', 'consumersecret');
|
||||
$otoken = get_pconfig($uid, 'twitter', 'oauthtoken');
|
||||
$osecret = get_pconfig($uid, 'twitter', 'oauthsecret');
|
||||
|
||||
require_once('library/twitteroauth.php');
|
||||
$connection = new TwitterOAuth($ckey,$csecret,$otoken,$osecret);
|
||||
|
||||
$result = $connection->post('statuses/retweet/'.$id);
|
||||
|
||||
return(!isset($result->errors));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue