]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Text/BBCode.php
Improve reshare format for Diaspora destinations
[friendica.git] / src / Content / Text / BBCode.php
index 357dc89d9a6cd5af40a55dffed9aee1c961a69a6..e49b14f47cbcaa7ab2324302574032a8770e0702 100644 (file)
@@ -67,6 +67,7 @@ class BBCode extends BaseObject
                                        $post["after"] = trim(substr($body, $pos + strlen($data[0])));
                                } else {
                                        $post["text"] = trim(str_replace($data[0], "", $body));
+                                       $post["after"] = '';
                                }
 
                                $attacheddata = $data[2];
@@ -949,15 +950,19 @@ class BBCode extends BaseObject
                                $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ': </p>' . "\n" . $content;
                                break;
                        case 3: // Diaspora
-                               $headline = '<p><b>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . $mention . ':</b></p>' . "\n";
-
                                if (stripos(Strings::normaliseLink($attributes['link']), 'http://twitter.com/') === 0) {
                                        $text = ($is_quote_share? '<hr />' : '') . '<p><a href="' . $attributes['link'] . '">' . $attributes['link'] . '</a></p>' . "\n";
                                } else {
+                                       $headline = '<p><b>♲ <a href="' . $attributes['profile'] . '">' . $attributes['author'] . '</a>:</b></p>' . "\n";
+
+                                       if (!empty($attributes['posted']) && !empty($attributes['link'])) {
+                                               $headline = '<p><b>♲ <a href="' . $attributes['profile'] . '">' . $attributes['author'] . '</a></b> - <a href="' . $attributes['link'] . '">' . $attributes['posted'] . ' GMT</a></p>' . "\n";
+                                       }
+
                                        $text = ($is_quote_share? '<hr />' : '') . $headline . '<blockquote>' . trim($content) . '</blockquote>' . "\n";
 
-                                       if ($attributes['link'] != '') {
-                                               $text .= '<p><a href="' . $attributes['link'] . '">[l]</a></p>' . "\n";
+                                       if (empty($attributes['posted']) && !empty($attributes['link'])) {
+                                               $text .= '<p><a href="' . $attributes['link'] . '">[Source]</a></p>' . "\n";
                                        }
                                }
 
@@ -1027,7 +1032,7 @@ class BBCode extends BaseObject
                        @curl_exec($ch);
                        $curl_info = @curl_getinfo($ch);
 
-                       $a->saveTimestamp($stamp1, "network");
+                       $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack());
 
                        if (substr($curl_info["content_type"], 0, 6) == "image/") {
                                $text = "[url=" . $match[1] . "]" . $match[1] . "[/url]";
@@ -1086,7 +1091,7 @@ class BBCode extends BaseObject
                        @curl_exec($ch);
                        $curl_info = @curl_getinfo($ch);
 
-                       $a->saveTimestamp($stamp1, "network");
+                       $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack());
 
                        // if its a link to a picture then embed this picture
                        if (substr($curl_info["content_type"], 0, 6) == "image/") {
@@ -1178,7 +1183,7 @@ class BBCode extends BaseObject
                // Extracting multi-line code blocks before the whitespace processing
                $codeblocks = [];
 
-               $text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#is",
+               $text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#ism",
                        function ($matches) use (&$codeblocks) {
                                $return = $matches[0];
                                if (strpos($matches[2], "\n") !== false) {
@@ -1293,7 +1298,7 @@ class BBCode extends BaseObject
                                $text);
                } elseif ($simple_html == 7) {
                        $text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
-                               '$1<span class="vcard"><a href="$2" class="url" title="$3"><span class="fn nickname mention">$3</span></a></span>',
+                               '$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",
@@ -1361,6 +1366,12 @@ class BBCode extends BaseObject
                                . '</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);
 
@@ -1683,7 +1694,7 @@ class BBCode extends BaseObject
 
                // Replace non graphical smilies for external posts
                if ($simple_html) {
-                       $text = Smilies::replace($text, false, true);
+                       $text = Smilies::replace($text);
                }
 
                // Unhide all [noparse] contained bbtags unspacefying them
@@ -1737,7 +1748,7 @@ class BBCode extends BaseObject
 
                // Clean up the HTML by loading and saving the HTML with the DOM.
                // Bad structured html can break a whole page.
-               // For performance reasons do it only with ativated item cache or at export.
+               // For performance reasons do it only with activated item cache or at export.
                if (!$try_oembed || (get_itemcachepath() != "")) {
                        $doc = new DOMDocument();
                        $doc->preserveWhiteSpace = false;
@@ -1909,7 +1920,7 @@ class BBCode extends BaseObject
                // unmask the special chars back to HTML
                $text = str_replace(['&\_lt\_;', '&\_gt\_;', '&\_amp\_;'], ['&lt;', '&gt;', '&amp;'], $text);
 
-               $a->saveTimestamp($stamp1, "parser");
+               $a->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack());
 
                // Libertree has a problem with escaped hashtags.
                $text = str_replace(['\#'], ['#'], $text);
@@ -1953,7 +1964,7 @@ class BBCode extends BaseObject
         $string = preg_replace('/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism', '#$2', $string);
 
         // ignore anything in a code block
-        $string = preg_replace('/\[code\](.*?)\[\/code\]/sm', '', $string);
+        $string = preg_replace('/\[code.*?\].*?\[\/code\]/sm', '', $string);
 
         // Force line feeds at bbtags
         $string = str_replace(['[', ']'], ["\n[", "]\n"], $string);