]> 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 2c2054750c5f0d06fb631b66d0ee65fe97ac034c..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",
@@ -1743,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;
@@ -1915,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);
@@ -1959,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);