[twitter] Perform mention/hashtags replacements before expanding links
- Move mention/hashtags replacement out of URL existence check
This commit is contained in:
parent
91a9d5e2ef
commit
471b3788eb
|
@ -1151,6 +1151,20 @@ function twitter_expand_entities(App $a, $body, $item, $picture)
|
||||||
{
|
{
|
||||||
$plain = $body;
|
$plain = $body;
|
||||||
|
|
||||||
|
$tags_arr = [];
|
||||||
|
|
||||||
|
foreach ($item->entities->hashtags AS $hashtag) {
|
||||||
|
$url = "#[url=" . $a->get_baseurl() . "/search?tag=" . rawurlencode($hashtag->text) . "]" . $hashtag->text . "[/url]";
|
||||||
|
$tags_arr["#" . $hashtag->text] = $url;
|
||||||
|
$body = str_replace("#" . $hashtag->text, $url, $body);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($item->entities->user_mentions AS $mention) {
|
||||||
|
$url = "@[url=https://twitter.com/" . rawurlencode($mention->screen_name) . "]" . $mention->screen_name . "[/url]";
|
||||||
|
$tags_arr["@" . $mention->screen_name] = $url;
|
||||||
|
$body = str_replace("@" . $mention->screen_name, $url, $body);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($item->entities->urls)) {
|
if (isset($item->entities->urls)) {
|
||||||
$type = "";
|
$type = "";
|
||||||
$footerurl = "";
|
$footerurl = "";
|
||||||
|
@ -1231,19 +1245,6 @@ function twitter_expand_entities(App $a, $body, $item, $picture)
|
||||||
} elseif (($footer == "") && ($picture == "")) {
|
} elseif (($footer == "") && ($picture == "")) {
|
||||||
$body = add_page_info_to_body($body);
|
$body = add_page_info_to_body($body);
|
||||||
}
|
}
|
||||||
|
|
||||||
$tags_arr = [];
|
|
||||||
|
|
||||||
foreach ($item->entities->hashtags AS $hashtag) {
|
|
||||||
$url = "#[url=" . $a->get_baseurl() . "/search?tag=" . rawurlencode($hashtag->text) . "]" . $hashtag->text . "[/url]";
|
|
||||||
$tags_arr["#" . $hashtag->text] = $url;
|
|
||||||
$body = str_replace("#" . $hashtag->text, $url, $body);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($item->entities->user_mentions AS $mention) {
|
|
||||||
$url = "@[url=https://twitter.com/" . rawurlencode($mention->screen_name) . "]" . $mention->screen_name . "[/url]";
|
|
||||||
$tags_arr["@" . $mention->screen_name] = $url;
|
|
||||||
$body = str_replace("@" . $mention->screen_name, $url, $body);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// it seems as if the entities aren't always covering all mentions. So the rest will be checked here
|
// it seems as if the entities aren't always covering all mentions. So the rest will be checked here
|
||||||
|
@ -1286,7 +1287,7 @@ function twitter_expand_entities(App $a, $body, $item, $picture)
|
||||||
}
|
}
|
||||||
|
|
||||||
$tags = implode($tags_arr, ",");
|
$tags = implode($tags_arr, ",");
|
||||||
}
|
|
||||||
return ["body" => $body, "tags" => $tags, "plain" => $plain];
|
return ["body" => $body, "tags" => $tags, "plain" => $plain];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user