[twitter] Fix external link picture
- Ensure the media url is the same as one of the external links url before showing only a picture
This commit is contained in:
parent
face0c02f0
commit
70fba8a985
|
@ -1298,20 +1298,22 @@ function twitter_media_entities($post, array &$postarray)
|
||||||
{
|
{
|
||||||
// There are no media entities? So we quit.
|
// There are no media entities? So we quit.
|
||||||
if (empty($post->extended_entities->media)) {
|
if (empty($post->extended_entities->media)) {
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the post links to an external page, we only take one picture.
|
// When the post links to an external page, we only take one picture.
|
||||||
// We only do this when there is exactly one media.
|
// We only do this when there is exactly one media.
|
||||||
if ((count($post->entities->urls) > 0) && (count($post->extended_entities->media) == 1)) {
|
if ((count($post->entities->urls) > 0) && (count($post->extended_entities->media) == 1)) {
|
||||||
$picture = "";
|
$medium = $post->extended_entities->media[0];
|
||||||
foreach ($post->extended_entities->media AS $medium) {
|
$picture = '';
|
||||||
if (isset($medium->media_url_https)) {
|
foreach ($post->entities->urls as $link) {
|
||||||
|
// Let's make sure the external link url matches the media url
|
||||||
|
if ($medium->url == $link->url && isset($medium->media_url_https)) {
|
||||||
$picture = $medium->media_url_https;
|
$picture = $medium->media_url_https;
|
||||||
$postarray['body'] = str_replace($medium->url, "", $postarray['body']);
|
$postarray['body'] = str_replace($medium->url, '', $postarray['body']);
|
||||||
|
return $picture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $picture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a pure media post, first search for all media urls
|
// This is a pure media post, first search for all media urls
|
||||||
|
@ -1322,19 +1324,19 @@ function twitter_media_entities($post, array &$postarray)
|
||||||
}
|
}
|
||||||
switch ($medium->type) {
|
switch ($medium->type) {
|
||||||
case 'photo':
|
case 'photo':
|
||||||
$media[$medium->url] .= "\n[img]" . $medium->media_url_https . "[/img]";
|
$media[$medium->url] .= "\n[img]" . $medium->media_url_https . '[/img]';
|
||||||
$postarray['object-type'] = ACTIVITY_OBJ_IMAGE;
|
$postarray['object-type'] = ACTIVITY_OBJ_IMAGE;
|
||||||
break;
|
break;
|
||||||
case 'video':
|
case 'video':
|
||||||
case 'animated_gif':
|
case 'animated_gif':
|
||||||
$media[$medium->url] .= "\n[img]" . $medium->media_url_https . "[/img]";
|
$media[$medium->url] .= "\n[img]" . $medium->media_url_https . '[/img]';
|
||||||
$postarray['object-type'] = ACTIVITY_OBJ_VIDEO;
|
$postarray['object-type'] = ACTIVITY_OBJ_VIDEO;
|
||||||
if (is_array($medium->video_info->variants)) {
|
if (is_array($medium->video_info->variants)) {
|
||||||
$bitrate = 0;
|
$bitrate = 0;
|
||||||
// We take the video with the highest bitrate
|
// We take the video with the highest bitrate
|
||||||
foreach ($medium->video_info->variants AS $variant) {
|
foreach ($medium->video_info->variants AS $variant) {
|
||||||
if (($variant->content_type == "video/mp4") && ($variant->bitrate >= $bitrate)) {
|
if (($variant->content_type == 'video/mp4') && ($variant->bitrate >= $bitrate)) {
|
||||||
$media[$medium->url] = "\n[video]" . $variant->url . "[/video]";
|
$media[$medium->url] = "\n[video]" . $variant->url . '[/video]';
|
||||||
$bitrate = $variant->bitrate;
|
$bitrate = $variant->bitrate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1350,7 +1352,8 @@ function twitter_media_entities($post, array &$postarray)
|
||||||
foreach ($media AS $key => $value) {
|
foreach ($media AS $key => $value) {
|
||||||
$postarray['body'] = str_replace($key, "\n" . $value . "\n", $postarray['body']);
|
$postarray['body'] = str_replace($key, "\n" . $value . "\n", $postarray['body']);
|
||||||
}
|
}
|
||||||
return "";
|
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $only_existing_contact, $noquote)
|
function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $only_existing_contact, $noquote)
|
||||||
|
@ -1617,23 +1620,12 @@ function twitter_fetchhometimeline(App $a, $uid)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
|
$self = User::getOwnerDataById($uid);
|
||||||
intval($uid));
|
if ($self === false) {
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
|
||||||
$self = $r[0];
|
|
||||||
} else {
|
|
||||||
logger("Own contact not found for user " . $uid);
|
logger("Own contact not found for user " . $uid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$u = q("SELECT * FROM user WHERE uid = %d LIMIT 1",
|
|
||||||
intval($uid));
|
|
||||||
if (!DBA::isResult($u)) {
|
|
||||||
logger("Own user not found for user " . $uid);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$parameters = ["exclude_replies" => false, "trim_user" => false, "contributor_details" => true, "include_rts" => true, "tweet_mode" => "extended"];
|
$parameters = ["exclude_replies" => false, "trim_user" => false, "contributor_details" => true, "include_rts" => true, "tweet_mode" => "extended"];
|
||||||
//$parameters["count"] = 200;
|
//$parameters["count"] = 200;
|
||||||
// Fetching timeline
|
// Fetching timeline
|
||||||
|
|
Loading…
Reference in New Issue
Block a user