- // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text
- if (!$for_plaintext) {
- $text = preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text);
- if ($simple_html == 7) {
- $text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text);
- $text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text);
- }
- } else {
- $text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism", " $1 ", $text);
- $text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::removePictureLinksCallback', $text);
- }
-
- $text = str_replace(["\r","\n"], ['<br />', '<br />'], $text);
-
- // Remove all hashtag addresses
- if ((!$try_oembed || $simple_html) && !in_array($simple_html, [3, 7])) {
- $text = preg_replace("/([#@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $text);
- } elseif ($simple_html == 3) {
- // The ! is converted to @ since Diaspora only understands the @
- $text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
- '@<a href="$2">$3</a>',
- $text);
- } elseif ($simple_html == 7) {
- $text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
- '$1<span class="vcard"><a href="$2" class="url u-url mention" title="$3"><span class="fn nickname mention">$3</span></a></span>',
- $text);
- } elseif (!$simple_html) {
- $text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
- '$1<a href="$2" class="userinfo mention" title="$3">$3</a>',
- $text);
- }
-
- // Bookmarks in red - will be converted to bookmarks in friendica
- $text = preg_replace("/#\^\[url\]([$URLSearchString]*)\[\/url\]/ism", '[bookmark=$1]$1[/bookmark]', $text);
- $text = preg_replace("/#\^\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[bookmark=$1]$2[/bookmark]', $text);
- $text = preg_replace("/#\[url\=[$URLSearchString]*\]\^\[\/url\]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/i",
- "[bookmark=$1]$2[/bookmark]", $text);
-
- if (in_array($simple_html, [2, 6, 7, 8, 9])) {
- $text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", "self::expandLinksCallback", $text);
- //$Text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $Text);
- $text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", ' $2 [url]$1[/url]',$text);
- }
-
- if ($simple_html == 5) {
- $text = preg_replace("/[^#@!]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url]$1[/url]', $text);
- }
-
- // Perform URL Search
- if ($try_oembed) {
- $text = preg_replace_callback("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $try_oembed_callback, $text);
- }
-
- if ($simple_html == 5) {
- $text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", '[url]$1[/url]', $text);
- } else {
- $text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", '[url=$1]$2[/url]', $text);
- }
-
- // Handle Diaspora posts
- $text = preg_replace_callback(
- "&\[url=/?posts/([^\[\]]*)\](.*)\[\/url\]&Usi",
- function ($match) {
- return "[url=" . System::baseUrl() . "/display/" . $match[1] . "]" . $match[2] . "[/url]";
- }, $text
- );
-
- $text = preg_replace_callback(
- "&\[url=/people\?q\=(.*)\](.*)\[\/url\]&Usi",
- function ($match) {
- return "[url=" . System::baseUrl() . "/search?search=%40" . $match[1] . "]" . $match[2] . "[/url]";
- }, $text
- );
-
- // Server independent link to posts and comments
- // See issue: https://github.com/diaspora/diaspora_federation/issues/75
- $expression = "=diaspora://.*?/post/([0-9A-Za-z\-_@.:]{15,254}[0-9A-Za-z])=ism";
- $text = preg_replace($expression, System::baseUrl()."/display/$1", $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);
-
- // We need no target="_blank" for local links
- // convert links start with System::baseUrl() as local link without the target="_blank" attribute
- $escapedBaseUrl = preg_quote(System::baseUrl(), '/');
- $text = preg_replace("/\[url\](".$escapedBaseUrl."[$URLSearchString]*)\[\/url\]/ism", '<a href="$1">$1</a>', $text);
- $text = preg_replace("/\[url\=(".$escapedBaseUrl."[$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1">$2</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);
-
- // 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);
-
-
- // we may need to restrict this further if it picks up too many strays
- // link acct:user@host to a webfinger profile redirector
-
- $text = preg_replace('/acct:([^@]+)@((?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63})/', '<a href="' . System::baseUrl() . '/acctlink?addr=$1@$2" target="extlink">acct:$1@$2</a>', $text);
-
- // Perform MAIL Search
- $text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '<a href="mailto:$1">$1</a>', $text);
- $text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '<a href="mailto:$1">$2</a>', $text);
-