]> git.mxchange.org Git - friendica.git/blobdiff - include/bb2diaspora.php
Improvments of the HTML to make a better bb2markdown conversion (nested lists, youtub...
[friendica.git] / include / bb2diaspora.php
index d509a2e31c3dd68b0827020b050595cbd7765a56..4a82635e57f065246adc702dc8d9d49b042ede47 100644 (file)
@@ -109,23 +109,23 @@ function bb2diaspora($Text,$preserve_nl = false) {
        // "<li>" into a deeper nested element until it crashes. So pre-format
        // the lists as Diaspora lists before sending the $Text to bbcode()
        //
-       // Note that regular expressions are really not suitable for parsing
-       // text with opening and closing tags, so nested lists may make things
-       // wonky
-       $endlessloop = 0;
-       while ((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false) &&
-              (strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false) && 
-              (strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false) && (++$endlessloop < 20)) {
+       // Note that to get nested lists to work for Diaspora, we would need
+       // to define the closing tag for the list elements. So nested lists
+       // are going to be flattened out in Diaspora for now
+/*     $endlessloop = 0;
+       while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) ||
+              ((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false)) || 
+              ((strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false))) && (++$endlessloop < 20)) {
                $Text = preg_replace_callback("/\[list\](.*?)\[\/list\]/is", 'diaspora_ul', $Text);
-               $Text = preg_replace_callback("/\[ul\](.*?)\[\/ul\]/is", 'diaspora_ul', $Text);
                $Text = preg_replace_callback("/\[list=1\](.*?)\[\/list\]/is", 'diaspora_ol', $Text);
                $Text = preg_replace_callback("/\[list=i\](.*?)\[\/list\]/s",'diaspora_ol', $Text);
                $Text = preg_replace_callback("/\[list=I\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
                $Text = preg_replace_callback("/\[list=a\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
                $Text = preg_replace_callback("/\[list=A\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
+               $Text = preg_replace_callback("/\[ul\](.*?)\[\/ul\]/is", 'diaspora_ul', $Text);
                $Text = preg_replace_callback("/\[ol\](.*?)\[\/ol\]/is", 'diaspora_ol', $Text);
        }
-
+*/
        // Convert it to HTML - don't try oembed
        $Text = bbcode($Text, $preserve_nl, false);
 
@@ -133,6 +133,12 @@ function bb2diaspora($Text,$preserve_nl = false) {
        $md = new Markdownify(false, false, false);
        $Text = $md->parseString($Text);
 
+       // If the text going into bbcode() has a plain URL in it, i.e.
+       // with no [url] tags around it, it will come out of parseString()
+       // looking like: <http://url.com>, which gets removed by strip_tags().
+       // So take off the angle brackets of any such URL
+       $Text = preg_replace("/<http(.*?)>/is", "http$1", $Text);
+
        // Remove all unconverted tags
        $Text = strip_tags($Text);