]> git.mxchange.org Git - friendica.git/blobdiff - include/bbcode.php
Mentions are now displayed much faster. Attention: The related database update can...
[friendica.git] / include / bbcode.php
index 384fd5ebd90a8aa1b156908143cc5e720705858a..a7cfa079d1c38d3072a56a3a01fa62c15388d35c 100644 (file)
@@ -310,6 +310,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
 
        // remove some newlines before the general conversion
        $Text = preg_replace("/\s?\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","[share$1]$2[/share]",$Text);
+       $Text = preg_replace("/\s?\[quote(.*?)\]\s?(.*?)\s?\[\/quote\]\s?/ism","[quote$1]$2[/quote]",$Text);
 
        // when the content is meant exporting to other systems then remove the avatar picture since this doesn't really look good on these systems
        if (!$tryoembed)
@@ -324,6 +325,15 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
 
        $Text = trim($Text);
        $Text = str_replace("\r\n","\n", $Text);
+
+       // removing multiplicated newlines
+       $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]");
+       $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]");
+       do {
+               $oldtext = $Text;
+               $Text = str_replace($search, $replace, $Text);
+       } while ($oldtext != $Text);
+
        $Text = str_replace(array("\r","\n"), array('<br />','<br />'), $Text);
 
        if($preserve_nl)
@@ -593,7 +603,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
 
        // Clean up the HTML by loading and saving the HTML with the DOM
        // Only do it when it has to be done - for performance reasons
-       if (!$tryoembed) {
+       // Update: Now it is done every time - since bad structured html can break a whole page
+       //if (!$tryoembed) {
                $doc = new DOMDocument();
                $doc->preserveWhiteSpace = false;
 
@@ -608,7 +619,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
                $Text = str_replace('<br></li>','</li>', $Text);
 
                $Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES');
-       }
+       //}
 
        call_hooks('bbcode',$Text);