]> git.mxchange.org Git - friendica.git/blobdiff - include/bbcode.php
Add a group with one click
[friendica.git] / include / bbcode.php
index 5395548f51b90279c6497bc2fcdec0c50893a87b..c2ebf35e6308b7464359a8af2b3efe36d13628f7 100644 (file)
@@ -3,10 +3,10 @@ require_once("include/oembed.php");
 require_once('include/event.php');
 
 function bb_attachment($Text, $plaintext = false, $tryoembed = true) {
-       $Text = preg_replace_callback("/\[attachment(.*?)\](.*?)\[\/attachment\]/ism",
+       $Text = preg_replace_callback("/(.*?)\[attachment(.*?)\](.*?)\[\/attachment\]/ism",
                function ($match) use ($plaintext){
 
-                       $attributes = $match[1];
+                       $attributes = $match[2];
 
                        $type = "";
                        preg_match("/type='(.*?)'/ism", $attributes, $matches);
@@ -41,7 +41,9 @@ function bb_attachment($Text, $plaintext = false, $tryoembed = true) {
                        if ($matches[1] != "")
                                $title = $matches[1];
 
-                       $title = htmlentities($title, ENT_QUOTES, 'UTF-8', false);
+                       //$title = htmlentities($title, ENT_QUOTES, 'UTF-8', false);
+                       $title = bbcode(html_entity_decode($title), false, false, true);
+                       $title = str_replace(array("[", "]"), array("[", "]"), $title);
 
                        $image = "";
                        if ($type != "video") {
@@ -65,6 +67,11 @@ function bb_attachment($Text, $plaintext = false, $tryoembed = true) {
                                        $preview = $matches[1];
                        }
 
+                       if (((strpos($match[1], "[img=") !== false) OR (strpos($match[1], "[img]") !== false)) AND ($image != "")) {
+                               $preview = $image;
+                               $image = "";
+                       }
+
                        if ($plaintext)
                                $text = sprintf('<a href="%s" target="_blank">%s</a><br>', $url, $title);
                        else {
@@ -83,10 +90,10 @@ function bb_attachment($Text, $plaintext = false, $tryoembed = true) {
 
                                $text .= $oembed;
 
-                               $text .= sprintf('<blockquote>%s</blockquote></span>', trim($match[2]));
+                               $text .= sprintf('<blockquote>%s</blockquote></span>', trim($match[3]));
                        }
 
-                       return($text);
+                       return($match[1].$text);
                },$Text);
 
        return($Text);
@@ -612,6 +619,17 @@ function GetProfileUsername($profile, $username, $compact = false, $getnetwork =
                        return($username." (".$diaspora.")");
        }
 
+       $red = preg_replace("=https?://(.*)/channel/(.*)=ism", "$2@$1", $profile);
+       if ($red != $profile) {
+               if ($getnetwork)
+                       // red is identified as Diaspora - friendica can't connect directly to it
+                       return(NETWORK_DIASPORA);
+               elseif ($compact)
+                       return($red);
+               else
+                       return($username." (".$red.")");
+       }
+
        $StatusnetHost = preg_replace("=https?://(.*)/user/(.*)=ism", "$1", $profile);
        if ($StatusnetHost != $profile) {
                $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile);
@@ -690,7 +708,7 @@ function bb_RemovePictureLinks($match) {
 }
 
 function bb_expand_links($match) {
-       if (stristr($match[2], $match[3]) OR ($match[2] == $match[3]))
+       if (($match[3] == "") OR ($match[2] == $match[3]) OR stristr($match[2], $match[3]))
                return ($match[1]."[url]".$match[2]."[/url]");
        else
                return ($match[1].$match[3]." [url]".$match[2]."[/url]");
@@ -1166,6 +1184,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
 
        $a->save_timestamp($stamp1, "parser");
 
-       return $Text;
+       return trim($Text);
 }
 ?>