mirror of
https://github.com/friendica/friendica
synced 2024-12-21 15:04:54 +01:00
Merge pull request #6184 from MrPetovan/task/normalize-bbcode-hashtags
Normalize BBCode hashtags links
This commit is contained in:
commit
42a3610a79
8 changed files with 44 additions and 35 deletions
|
@ -97,7 +97,7 @@ function add_page_info_data(array $data, $no_photos = false)
|
|||
/// @TODO make a positive list of allowed characters
|
||||
$hashtag = str_replace([" ", "+", "/", ".", "#", "'", "’", "`", "(", ")", "„", "“"],
|
||||
["", "", "", "", "", "", "", "", "", "", "", ""], $keyword);
|
||||
$hashtags .= "#[url=" . System::baseUrl() . "/search?tag=" . rawurlencode($hashtag) . "]" . $hashtag . "[/url] ";
|
||||
$hashtags .= "#[url=" . System::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url] ";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ function add_page_keywords($url, $photo = "", $keywords = false, $keyword_blackl
|
|||
$tags .= ", ";
|
||||
}
|
||||
|
||||
$tags .= "#[url=" . System::baseUrl() . "/search?tag=" . rawurlencode($hashtag) . "]" . $hashtag . "[/url]";
|
||||
$tags .= "#[url=" . System::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url]";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -613,7 +613,7 @@ function photos_post(App $a)
|
|||
}
|
||||
|
||||
$profile = str_replace(',', '%2c', $profile);
|
||||
$str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
|
||||
$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
|
||||
}
|
||||
} elseif (strpos($tag, '#') === 0) {
|
||||
$tagname = substr($tag, 1);
|
||||
|
|
|
@ -93,7 +93,7 @@ function tagger_content(App $a) {
|
|||
</target>
|
||||
EOT;
|
||||
|
||||
$tagid = System::baseUrl() . '/search?tag=' . $term;
|
||||
$tagid = System::baseUrl() . '/search?tag=' . $xterm;
|
||||
$objtype = ACTIVITY_OBJ_TAGTERM;
|
||||
|
||||
$obj = <<< EOT
|
||||
|
@ -113,7 +113,7 @@ EOT;
|
|||
return;
|
||||
}
|
||||
|
||||
$termlink = html_entity_decode('⌗') . '[url=' . System::baseUrl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
|
||||
$termlink = html_entity_decode('⌗') . '[url=' . System::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]';
|
||||
|
||||
$arr = [];
|
||||
|
||||
|
@ -170,7 +170,7 @@ EOT;
|
|||
$term_objtype,
|
||||
TERM_HASHTAG,
|
||||
DBA::escape($term),
|
||||
DBA::escape(System::baseUrl() . '/search?tag=' . $term),
|
||||
'',
|
||||
intval($owner_uid)
|
||||
);
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ EOT;
|
|||
$term_objtype,
|
||||
TERM_HASHTAG,
|
||||
DBA::escape($term),
|
||||
DBA::escape(System::baseUrl() . '/search?tag=' . $term),
|
||||
'',
|
||||
intval($owner_uid)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ use Friendica\Util\Network;
|
|||
use Friendica\Util\ParseUrl;
|
||||
use Friendica\Util\Proxy as ProxyUtils;
|
||||
use Friendica\Util\Strings;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
class BBCode extends BaseObject
|
||||
{
|
||||
|
@ -1340,15 +1341,21 @@ class BBCode extends BaseObject
|
|||
$expression = "=diaspora://.*?/post/([0-9A-Za-z\-_@.:]{15,254}[0-9A-Za-z])=ism";
|
||||
$text = preg_replace($expression, System::baseUrl()."/display/$1", $text);
|
||||
|
||||
$text = preg_replace("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
|
||||
'$1<a href="' . System::baseUrl() . '/search?tag=$3" class="tag" title="$3">$3</a>', $text);
|
||||
|
||||
$text = preg_replace("/\[url\=([$URLSearchString]*)\]#(.*?)\[\/url\]/ism",
|
||||
'#<a href="' . System::baseUrl() . '/search?tag=$2" class="tag" title="$2">$2</a>', $text);
|
||||
/* Tag conversion
|
||||
* Supports:
|
||||
* - #[url=<anything>]<term>[/url]
|
||||
* - [url=<anything>]#<term>[/url]
|
||||
*/
|
||||
$text = preg_replace_callback("/(?:#\[url\=[$URLSearchString]*\]|\[url\=[$URLSearchString]*\]#)(.*?)\[\/url\]/ism", function($matches) {
|
||||
return '#<a href="'
|
||||
. System::baseUrl() . '/search?tag=' . rawurlencode($matches[1])
|
||||
. '" class="tag" title="' . XML::escape($matches[1]) . '">'
|
||||
. XML::escape($matches[1])
|
||||
. '</a>';
|
||||
}, $text);
|
||||
|
||||
$text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$1</a>', $text);
|
||||
$text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $text);
|
||||
//$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
|
||||
|
||||
// Red compatibility, though the link can't be authenticated on Friendica
|
||||
$text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '<a href="$1" target="_blank">$2</a>', $text);
|
||||
|
|
|
@ -2448,15 +2448,15 @@ class Item extends BaseObject
|
|||
|
||||
$basetag = str_replace('_',' ',substr($tag,1));
|
||||
|
||||
$newtag = '#[url=' . System::baseUrl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
|
||||
$newtag = '#[url=' . System::baseUrl() . '/search?tag=' . $basetag . ']' . $basetag . '[/url]';
|
||||
|
||||
$item["body"] = str_replace($tag, $newtag, $item["body"]);
|
||||
|
||||
if (!stristr($item["tag"], "/search?tag=" . $basetag . "]" . $basetag . "[/url]")) {
|
||||
if (strlen($item["tag"])) {
|
||||
$item["tag"] = ','.$item["tag"];
|
||||
$item["tag"] = ',' . $item["tag"];
|
||||
}
|
||||
$item["tag"] = $newtag.$item["tag"];
|
||||
$item["tag"] = $newtag . $item["tag"];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -140,6 +140,7 @@ class Term
|
|||
|
||||
$type = TERM_HASHTAG;
|
||||
$term = substr($tag, 1);
|
||||
$link = '';
|
||||
} elseif ((substr(trim($tag), 0, 1) == '@') || (substr(trim($tag), 0, 1) == '!')) {
|
||||
$type = TERM_MENTION;
|
||||
|
||||
|
@ -152,6 +153,7 @@ class Term
|
|||
} else { // This shouldn't happen
|
||||
$type = TERM_HASHTAG;
|
||||
$term = $tag;
|
||||
$link = '';
|
||||
}
|
||||
|
||||
if (DBA::exists('term', ['uid' => $message['uid'], 'otype' => TERM_OBJ_POST, 'oid' => $itemid, 'url' => $link])) {
|
||||
|
@ -262,29 +264,29 @@ class Term
|
|||
);
|
||||
|
||||
while ($tag = DBA::fetch($taglist)) {
|
||||
if ($tag["url"] == "") {
|
||||
$tag["url"] = $searchpath . $tag["term"];
|
||||
if ($tag['url'] == '') {
|
||||
$tag['url'] = $searchpath . rawurlencode($tag['term']);
|
||||
}
|
||||
|
||||
$orig_tag = $tag["url"];
|
||||
$orig_tag = $tag['url'];
|
||||
|
||||
$author = ['uid' => 0, 'id' => $item['author-id'],
|
||||
'network' => $item['author-network'], 'url' => $item['author-link']];
|
||||
$tag["url"] = Contact::magicLinkByContact($author, $tag['url']);
|
||||
$tag['url'] = Contact::magicLinkByContact($author, $tag['url']);
|
||||
|
||||
if ($tag["type"] == TERM_HASHTAG) {
|
||||
if ($orig_tag != $tag["url"]) {
|
||||
$item['body'] = str_replace($orig_tag, $tag["url"], $item['body']);
|
||||
if ($tag['type'] == TERM_HASHTAG) {
|
||||
if ($orig_tag != $tag['url']) {
|
||||
$item['body'] = str_replace($orig_tag, $tag['url'], $item['body']);
|
||||
}
|
||||
|
||||
$return['hashtags'][] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
|
||||
$prefix = "#";
|
||||
} elseif ($tag["type"] == TERM_MENTION) {
|
||||
$return['mentions'][] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
|
||||
$prefix = "@";
|
||||
$return['hashtags'][] = '#<a href="' . $tag['url'] . '" target="_blank">' . $tag['term'] . '</a>';
|
||||
$prefix = '#';
|
||||
} elseif ($tag['type'] == TERM_MENTION) {
|
||||
$return['mentions'][] = '@<a href="' . $tag['url'] . '" target="_blank">' . $tag['term'] . '</a>';
|
||||
$prefix = '@';
|
||||
}
|
||||
|
||||
$return['tags'][] = $prefix . "<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
|
||||
$return['tags'][] = $prefix . '<a href="' . $tag['url'] . '" target="_blank">' . $tag['term'] . '</a>';
|
||||
}
|
||||
DBA::close($taglist);
|
||||
|
||||
|
|
|
@ -350,7 +350,7 @@ class Feed {
|
|||
$tags .= ', ';
|
||||
}
|
||||
|
||||
$taglink = "#[url=" . System::baseUrl() . "/search?tag=" . rawurlencode($hashtag) . "]" . $hashtag . "[/url]";
|
||||
$taglink = "#[url=" . System::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url]";
|
||||
$tags .= $taglink;
|
||||
}
|
||||
|
||||
|
|
|
@ -634,15 +634,15 @@ class OStatus
|
|||
if ($categories) {
|
||||
foreach ($categories as $category) {
|
||||
foreach ($category->attributes as $attributes) {
|
||||
if ($attributes->name == "term") {
|
||||
if ($attributes->name == 'term') {
|
||||
$term = $attributes->textContent;
|
||||
if (!empty($item["tag"])) {
|
||||
$item["tag"] .= ',';
|
||||
if (!empty($item['tag'])) {
|
||||
$item['tag'] .= ',';
|
||||
} else {
|
||||
$item["tag"] = '';
|
||||
$item['tag'] = '';
|
||||
}
|
||||
|
||||
$item["tag"] .= "#[url=".System::baseUrl()."/search?tag=".$term."]".$term."[/url]";
|
||||
$item['tag'] .= '#[url=' . System::baseUrl() . '/search?tag=' . $term . ']' . $term . '[/url]';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue