]> git.mxchange.org Git - friendica.git/blobdiff - include/bbcode.php
patches for youtube's change in link and embed formats, please test
[friendica.git] / include / bbcode.php
index eb0806dc527fee8b6b36a89d6d6239e807ca665e..195fc91819ed1e8625c0d02b91dae2eb5742ab53 100644 (file)
@@ -3,7 +3,7 @@ require_once("include/oembed.php");
        // BBcode 2 HTML was written by WAY2WEB.net
        // extended to work with Mistpark/Friendika - Mike Macgirvin
 
-function bbcode($Text) {
+function bbcode($Text,$preserve_nl = false) {
 
        // Replace any html brackets with HTML Entities to prevent executing HTML or script
        // Don't use strip_tags here because it breaks [url] search by replacing & with amp
@@ -12,17 +12,20 @@ function bbcode($Text) {
        $Text = str_replace(">", ">", $Text);
 
        // Convert new line chars to html <br /> tags
+
        $Text = nl2br($Text);
+       if($preserve_nl)
+               $Text = str_replace(array("\n","\r"), array('',''),$Text);
 
        // Set up the parameters for a URL search string
-       $URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%";
+       $URLSearchString = "^\[\]";
        // Set up the parameters for a MAIL search string
-       $MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@";
+       $MAILSearchString = $URLSearchString;
 
        // Perform URL Search
 
 
-       $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%]+)/", ' <a href="$2" target="external-link">$2</a>', $Text);
+       $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%\$\!\+\,]+)/", ' <a href="$2" target="external-link">$2</a>', $Text);
 
        $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '<a href="$1" target="external-link">$1</a>', $Text);
        $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '<a href="$1" target="external-link">$2</a>', $Text);
@@ -49,10 +52,10 @@ function bbcode($Text) {
        $Text = preg_replace("(\[o\](.+?)\[\/o\])is",'<span class="overline">$1</span>',$Text);
 
        // Check for colored text
-       $Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","<span style=\"color: $1\">$2</span>",$Text);
+       $Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","<span style=\"color: $1;\">$2</span>",$Text);
 
        // Check for sized text
-       $Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","<span style=\"font-size: $1px\">$2</span>",$Text);
+       $Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","<span style=\"font-size: $1;\">$2</span>",$Text);
 
        // Check for list text
        $Text = preg_replace("/\[list\](.+?)\[\/list\]/is", '<ul class="listbullet">$1</ul>' ,$Text);
@@ -77,7 +80,7 @@ function bbcode($Text) {
          
        // Images
        // [img]pathtoimage[/img]
-       $Text = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="$1">', $Text);
+       $Text = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
 
        // html5 video and audio
 
@@ -90,8 +93,12 @@ function bbcode($Text) {
        $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '<img src="$3" height="$2" width="$1">', $Text);
 
        // Youtube extensions
-        $Text = preg_replace("/\[youtube\]http:\/\/www.youtube.com\/watch\?v\=(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text); 
-       $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text);
+        $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text); 
+        $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text); 
+
+       $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '<iframe width="425" height="349" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $Text);
+
+//     $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text);
 
        // oembed tag
        $Text = oembed_bbcode2html($Text);