Twitter: if there is an embedded picture and a link, then use this picture for the link information.

pull/200/head
Michael Vogel 2014-06-15 23:34:51 +02:00
parent e5a1864089
commit d3e6c17108
1 changed files with 37 additions and 17 deletions

View File

@ -712,19 +712,23 @@ function twitter_fetchtimeline($a, $uid) {
$_REQUEST['body'] = $post->retweeted_status->text; $_REQUEST['body'] = $post->retweeted_status->text;
$picture = "";
// media // media
if (is_array($post->retweeted_status->entities->media)) { if (is_array($post->retweeted_status->entities->media)) {
foreach($post->retweeted_status->entities->media AS $media) { foreach($post->retweeted_status->entities->media AS $media) {
switch($media->type) { switch($media->type) {
case 'photo': case 'photo':
$_REQUEST['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']); //$_REQUEST['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']);
$has_picture = true; //$has_picture = true;
$_REQUEST['body'] = str_replace($media->url, "", $_REQUEST['body']);
$picture = $media->media_url_https;
break; break;
} }
} }
} }
$converted = twitter_expand_entities($a, $_REQUEST['body'], $post->retweeted_status, true, $has_picture); $converted = twitter_expand_entities($a, $_REQUEST['body'], $post->retweeted_status, true, $picture);
$_REQUEST['body'] = $converted["body"]; $_REQUEST['body'] = $converted["body"];
$_REQUEST['body'] = "[share author='".$post->retweeted_status->user->name. $_REQUEST['body'] = "[share author='".$post->retweeted_status->user->name.
@ -736,18 +740,22 @@ function twitter_fetchtimeline($a, $uid) {
} else { } else {
$_REQUEST["body"] = $post->text; $_REQUEST["body"] = $post->text;
$picture = "";
if (is_array($post->entities->media)) { if (is_array($post->entities->media)) {
foreach($post->entities->media AS $media) { foreach($post->entities->media AS $media) {
switch($media->type) { switch($media->type) {
case 'photo': case 'photo':
$_REQUEST['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']); //$_REQUEST['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']);
$has_picture = true; //$has_picture = true;
$_REQUEST['body'] = str_replace($media->url, "", $_REQUEST['body']);
$picture = $media->media_url_https;
break; break;
} }
} }
} }
$converted = twitter_expand_entities($a, $_REQUEST["body"], $post, true, $has_picture); $converted = twitter_expand_entities($a, $_REQUEST["body"], $post, true, $picture);
$_REQUEST['body'] = $converted["body"]; $_REQUEST['body'] = $converted["body"];
} }
@ -1019,7 +1027,7 @@ function twitter_fetchuser($a, $uid, $screen_name = "", $user_id = "") {
return $contact_id; return $contact_id;
} }
function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontincludemedia) { function twitter_expand_entities($a, $body, $item, $no_tags = false, $picture) {
require_once("include/oembed.php"); require_once("include/oembed.php");
require_once("include/network.php"); require_once("include/network.php");
@ -1054,11 +1062,12 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
$footerlink = "[url=".$expanded_url."]".$expanded_url."[/url]"; $footerlink = "[url=".$expanded_url."]".$expanded_url."[/url]";
$body = str_replace($url->url, $footerlink, $body); $body = str_replace($url->url, $footerlink, $body);
} elseif (($oembed_data->type == "photo") AND isset($oembed_data->url) AND !$dontincludemedia) { //} elseif (($oembed_data->type == "photo") AND isset($oembed_data->url) AND !$dontincludemedia) {
} elseif (($oembed_data->type == "photo") AND isset($oembed_data->url)) {
$body = str_replace($url->url, $body = str_replace($url->url,
"[url=".$expanded_url."][img]".$oembed_data->url."[/img][/url]", "[url=".$expanded_url."][img]".$oembed_data->url."[/img][/url]",
$body); $body);
$dontincludemedia = true; //$dontincludemedia = true;
} elseif ($oembed_data->type != "link") } elseif ($oembed_data->type != "link")
$body = str_replace($url->url, $body = str_replace($url->url,
"[url=".$expanded_url."]".$expanded_url."[/url]", "[url=".$expanded_url."]".$expanded_url."[/url]",
@ -1074,7 +1083,7 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
if (substr($mime, 0, 6) == "image/") { if (substr($mime, 0, 6) == "image/") {
$type = "photo"; $type = "photo";
$body = str_replace($url->url, "[img]".$expanded_url."[/img]", $body); $body = str_replace($url->url, "[img]".$expanded_url."[/img]", $body);
$dontincludemedia = true; //$dontincludemedia = true;
} else { } else {
$type = $oembed_data->type; $type = $oembed_data->type;
$footerurl = $expanded_url; $footerurl = $expanded_url;
@ -1087,7 +1096,7 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
} }
if ($footerurl != "") if ($footerurl != "")
$footer = add_page_info($footerurl); $footer = add_page_info($footerurl, false, $picture);
if (($footerlink != "") AND (trim($footer) != "")) { if (($footerlink != "") AND (trim($footer) != "")) {
$removedlink = trim(str_replace($footerlink, "", $body)); $removedlink = trim(str_replace($footerlink, "", $body));
@ -1098,6 +1107,9 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
$body .= $footer; $body .= $footer;
} }
if (($footer == "") AND ($picture != ""))
$body .= "\n\n[img]".$picture."[/img]\n";
if ($no_tags) if ($no_tags)
return(array("body" => $body, "tags" => "")); return(array("body" => $body, "tags" => ""));
@ -1252,13 +1264,17 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
$postarray['body'] = $post->text; $postarray['body'] = $post->text;
$picture = "";
// media // media
if (is_array($post->entities->media)) { if (is_array($post->entities->media)) {
foreach($post->entities->media AS $media) { foreach($post->entities->media AS $media) {
switch($media->type) { switch($media->type) {
case 'photo': case 'photo':
$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']); //$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']);
$has_picture = true; //$has_picture = true;
$postarray['body'] = str_replace($media->url, "", $postarray['body']);
$picture = $media->media_url_https;
break; break;
default: default:
$postarray['body'] .= print_r($media, true); $postarray['body'] .= print_r($media, true);
@ -1266,7 +1282,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
} }
} }
$converted = twitter_expand_entities($a, $postarray['body'], $post, false, $has_picture); $converted = twitter_expand_entities($a, $postarray['body'], $post, false, $picture);
$postarray['body'] = $converted["body"]; $postarray['body'] = $converted["body"];
$postarray['tag'] = $converted["tags"]; $postarray['tag'] = $converted["tags"];
@ -1289,13 +1305,17 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
$postarray['body'] = $post->retweeted_status->text; $postarray['body'] = $post->retweeted_status->text;
$picture = "";
// media // media
if (is_array($post->retweeted_status->entities->media)) { if (is_array($post->retweeted_status->entities->media)) {
foreach($post->retweeted_status->entities->media AS $media) { foreach($post->retweeted_status->entities->media AS $media) {
switch($media->type) { switch($media->type) {
case 'photo': case 'photo':
$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']); //$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']);
$has_picture = true; //$has_picture = true;
$postarray['body'] = str_replace($media->url, "", $postarray['body']);
$picture = $media->media_url_https;
break; break;
default: default:
$postarray['body'] .= print_r($media, true); $postarray['body'] .= print_r($media, true);
@ -1303,7 +1323,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
} }
} }
$converted = twitter_expand_entities($a, $postarray['body'], $post->retweeted_status, false, $has_picture); $converted = twitter_expand_entities($a, $postarray['body'], $post->retweeted_status, false, $picture);
$postarray['body'] = $converted["body"]; $postarray['body'] = $converted["body"];
$postarray['tag'] = $converted["tags"]; $postarray['tag'] = $converted["tags"];