X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=inline;f=include%2Fbbcode.php;h=3caf2a6b179ebf916dc8ac7dea5e2e349d10b10c;hb=21769d7390a0bcfb5c74e53c05867ab52a54448b;hp=c55ebab00c152c09361c3d763998adbfe5cd41e9;hpb=971b16ea4aadf8a24427907619e482e4cafe6faa;p=friendica.git
diff --git a/include/bbcode.php b/include/bbcode.php
index c55ebab00c..3caf2a6b17 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -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,7 +12,10 @@ function bbcode($Text) {
$Text = str_replace(">", ">", $Text);
// Convert new line chars to html
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 = "^\[\]";
@@ -22,7 +25,7 @@ function bbcode($Text) {
// Perform URL Search
- $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%\$\!]+)/", ' $2', $Text);
+ $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%\$\!\+\,]+)/", ' $2', $Text);
$Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '$1', $Text);
$Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '$2', $Text);
@@ -77,7 +80,7 @@ function bbcode($Text) {
// Images
// [img]pathtoimage[/img]
- $Text = preg_replace("/\[img\](.+?)\[\/img\]/", '
', $Text);
+ $Text = preg_replace("/\[img\](.+?)\[\/img\]/", '
', $Text);
// html5 video and audio
@@ -87,15 +90,23 @@ function bbcode($Text) {
// [img=widthxheight]image source[/img]
- $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '
', $Text);
-
- // Youtube extensions
- $Text = preg_replace("/\[youtube\]http:\/\/www.youtube.com\/watch\?v\=(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text);
- $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '', $Text);
+ $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '
', $Text);
+
+ if (get_pconfig(local_user(), 'oembed', 'use_for_youtube' )==1){
+ // use oembed for youtube links
+ $Text = preg_replace("/\[youtube\]/",'[embed]',$Text);
+ $Text = preg_replace("/\[\/youtube\]/",'[/embed]',$Text);
+ } else {
+ // Youtube extensions
+ $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\]/", '', $Text);
+ }
+// $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '', $Text);
// oembed tag
$Text = oembed_bbcode2html($Text);
-
+
call_hooks('bbcode',$Text);
return $Text;