From d8c667288ecf6cd358751df250f2b45e476ff40c Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 9 Feb 2013 03:40:56 -0800 Subject: this seems to cut load times in half --- include/bbcode.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 881f5777b..d43929ef5 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -105,6 +105,7 @@ function bb_replace_images($body, $images) { function bbcode($Text,$preserve_nl = false, $tryoembed = true) { + $a = get_app(); // Extract the private images which use data url's since preg has issues with -- cgit v1.2.3 From ea3940c4b0b8232e2de0771811b9f90ade9ee45f Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 25 Feb 2013 17:09:40 -0800 Subject: start formatting for Doxygen --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index d43929ef5..6d29954cb 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1,4 +1,4 @@ - Date: Mon, 25 Feb 2013 19:06:31 -0800 Subject: partial port of embedded shares --- include/bbcode.php | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 6d29954cb..4938db37d 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -99,6 +99,96 @@ function bb_replace_images($body, $images) { }} +function bb_ShareAttributes($match) { + + $attributes = $match[1]; + + $author = ""; + preg_match("/author='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + + preg_match('/author="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $author = $matches[1]; + + $link = ""; + preg_match("/link='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $link = $matches[1]; + + preg_match('/link="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $link = $matches[1]; + + $avatar = ""; + preg_match("/avatar='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $avatar = $matches[1]; + + preg_match('/avatar="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $avatar = $matches[1]; + + $profile = ""; + preg_match("/profile='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; + + preg_match('/profile="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; + + $posted = ""; + preg_match("/posted='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $posted = $matches[1]; + + preg_match('/posted="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $posted = $matches[1]; + $reldate = (($posted) ? " " . relative_date($posted) : ''); + + $headline = '
'; + + if ($avatar != "") + $headline .= ''; + + $headline .= sprintf(t('%s wrote the following post'.$reldate.':'), $profile, $author, $link); + + $headline .= "
"; + + $text = $headline.'
'.trim($match[2])."
"; + + return($text); +} + +function bb_ShareAttributesSimple($match) { + + $attributes = $match[1]; + + $author = ""; + preg_match("/author='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + + preg_match('/author="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $author = $matches[1]; + + $profile = ""; + preg_match("/profile='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; + + preg_match('/profile="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; + + $text = "
".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$author.":
»".$match[2]."«"; + + return($text); +} // BBcode 2 HTML was written by WAY2WEB.net // extended to work with Mistpark/Friendica - Mike Macgirvin @@ -312,6 +402,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // [img]pathtoimage[/img] $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); -- cgit v1.2.3 From 70e766c2bfb4f145564912837864f27aafc82ea2 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Feb 2013 19:41:44 -0800 Subject: xss attack vector in bbcode.php - check for proc_open being disabled for security reasons in install --- include/bbcode.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 4938db37d..021f2ac27 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -502,22 +502,22 @@ 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) { - $doc = new DOMDocument(); - $doc->preserveWhiteSpace = false; +// if (!$tryoembed) {// +// $doc = new DOMDocument(); +// $doc->preserveWhiteSpace = false; - $Text = mb_convert_encoding($Text, 'HTML-ENTITIES', "UTF-8"); +// $Text = mb_convert_encoding($Text, 'HTML-ENTITIES', "UTF-8"); - $doctype = ''; - @$doc->loadHTML($doctype."".$Text.""); +// $doctype = ''; +// @$doc->loadHTML($doctype."".$Text.""); - $Text = $doc->saveHTML(); - $Text = str_replace(array("", "", $doctype), array("", "", ""), $Text); +// $Text = $doc->saveHTML(); +// $Text = str_replace(array("", "", $doctype), array("", "", ""), $Text); - $Text = str_replace('
','', $Text); +// $Text = str_replace('
','', $Text); - $Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES'); - } +// $Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES'); +// } call_hooks('bbcode',$Text); -- cgit v1.2.3 From b86277b0ff7aa7ea5e04a646b628785fc31f0c3e Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 11 Mar 2013 16:13:09 -0700 Subject: dangerous typo that removes all your hublocs, fix reshare formatting --- include/bbcode.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 021f2ac27..0a40313a4 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -151,15 +151,15 @@ function bb_ShareAttributes($match) { $headline = '
'; - if ($avatar != "") - $headline .= ''; + if ($avatar != "") + $headline .= ''; - $headline .= sprintf(t('%s wrote the following post'.$reldate.':'), $profile, $author, $link); + $headline .= sprintf(t('%s wrote the following post'.$reldate.':'), $profile, $author, $link); $headline .= "
"; - $text = $headline.'
'.trim($match[2])."
"; - + $text = $headline . '
' . trim($match[2]) . '
'; + logger('bbshare: ' . $text); return($text); } @@ -232,9 +232,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = str_replace("<", "<", $Text); $Text = str_replace(">", ">", $Text); - // This only matters when looking for tags - otherwise has no meaning - - $Text = str_replace(array('[share]','[/share]'), array('',''), $Text); // Convert new line chars to html
tags @@ -259,13 +256,15 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Perform URL Search - $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); + $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); if ($tryoembed) $Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text); $Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$Text); + $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); + if ($tryoembed) $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text); @@ -402,7 +401,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // [img]pathtoimage[/img] $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); - $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); + $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); -- cgit v1.2.3 From d568f4d0291f41ca27d259d2688e948199956dd9 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 11 Mar 2013 16:50:24 -0700 Subject: class def for reshared content --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 0a40313a4..84c9bda71 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -158,7 +158,7 @@ function bb_ShareAttributes($match) { $headline .= ""; - $text = $headline . '
' . trim($match[2]) . '
'; + $text = $headline . '
' . trim($match[2]) . '
'; logger('bbshare: ' . $text); return($text); } -- cgit v1.2.3 From f988213af83d57dbef00ab275929ce70faadb79b Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 11 Mar 2013 18:22:40 -0700 Subject: fix typos --- include/bbcode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 84c9bda71..758a0891c 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -159,7 +159,7 @@ function bb_ShareAttributes($match) { $headline .= ""; $text = $headline . '
' . trim($match[2]) . '
'; - logger('bbshare: ' . $text); + return($text); } @@ -185,7 +185,7 @@ function bb_ShareAttributesSimple($match) { if ($matches[1] != "") $profile = $matches[1]; - $text = "
".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$author.":
»".$match[2]."«"; + $text = "
".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$author.": div class=\"reshared-content\">" .$match[2].""; return($text); } -- cgit v1.2.3 From 6c9db5a1cf7e47081bfe1205f5e03bf6ca39b704 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 11 Mar 2013 21:29:43 -0700 Subject: make reshares translateable --- include/bbcode.php | 150 ++++++++++++++++++++++++++++------------------------- 1 file changed, 79 insertions(+), 71 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 758a0891c..301fbdcc6 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -101,93 +101,101 @@ function bb_replace_images($body, $images) { function bb_ShareAttributes($match) { - $attributes = $match[1]; + $attributes = $match[1]; - $author = ""; - preg_match("/author='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + $author = ""; + preg_match("/author='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); - preg_match('/author="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $author = $matches[1]; + preg_match('/author="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $author = $matches[1]; - $link = ""; - preg_match("/link='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $link = $matches[1]; + $link = ""; + preg_match("/link='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $link = $matches[1]; - preg_match('/link="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $link = $matches[1]; + preg_match('/link="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $link = $matches[1]; - $avatar = ""; - preg_match("/avatar='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $avatar = $matches[1]; + $avatar = ""; + preg_match("/avatar='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $avatar = $matches[1]; - preg_match('/avatar="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $avatar = $matches[1]; + preg_match('/avatar="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $avatar = $matches[1]; - $profile = ""; - preg_match("/profile='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; + $profile = ""; + preg_match("/profile='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; - preg_match('/profile="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; + preg_match('/profile="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; - $posted = ""; - preg_match("/posted='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $posted = $matches[1]; + $posted = ""; + preg_match("/posted='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $posted = $matches[1]; - preg_match('/posted="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $posted = $matches[1]; - $reldate = (($posted) ? " " . relative_date($posted) : ''); + preg_match('/posted="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $posted = $matches[1]; - $headline = '
'; + // FIXME - this should really be a wall-item-ago so it will get updated on the client + $reldate = (($posted) ? relative_date($posted) : ''); - if ($avatar != "") - $headline .= ''; + $headline = '
'; - $headline .= sprintf(t('%s wrote the following post'.$reldate.':'), $profile, $author, $link); + if ($avatar != "") + $headline .= '' . $author . ''; - $headline .= "
"; + // Bob Smith wrote the following post 2 hours ago - $text = $headline . '
' . trim($match[2]) . '
'; + $fmt = sprintf( t('%1$s wrote the following %2$s %3$s'), + '' . $author, + '' . t('post'), + $reldate + ); - return($text); + $headline .= '' . $fmt . '
'; + + $text = $headline . '
' . trim($match[2]) . '
'; + + return($text); } function bb_ShareAttributesSimple($match) { - $attributes = $match[1]; + $attributes = $match[1]; - $author = ""; - preg_match("/author='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + $author = ""; + preg_match("/author='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); - preg_match('/author="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $author = $matches[1]; + preg_match('/author="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $author = $matches[1]; - $profile = ""; - preg_match("/profile='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; + $profile = ""; + preg_match("/profile='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; - preg_match('/profile="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; + preg_match('/profile="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; - $text = "
".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').'
'.$author.": div class=\"reshared-content\">" .$match[2].""; + $text = "
".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$author.": div class=\"reshared-content\">" .$match[2].""; - return($text); + return($text); } // BBcode 2 HTML was written by WAY2WEB.net @@ -295,7 +303,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("(\[color=(.*?)\](.*?)\[\/color\])ism","$2",$Text); // Check for sized text - // [size=50] --> font-size: 50px (with the unit). + // [size=50] --> font-size: 50px (with the unit). $Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism","$2",$Text); $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","$2",$Text); @@ -315,9 +323,9 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $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)) || - ((strpos($Text, "[/li]") !== false) && (strpos($Text, "[li]") !== false))) && (++$endlessloop < 20)) { + ((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false)) || + ((strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false)) || + ((strpos($Text, "[/li]") !== false) && (strpos($Text, "[li]") !== false))) && (++$endlessloop < 20)) { $Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '
    $1
' ,$Text); $Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '
    $1
' ,$Text); $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '
    $1
' ,$Text); @@ -370,8 +378,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $endlessloop = 0; while ((strpos($Text, "[/spoiler]")!== false) and (strpos($Text, "[spoiler=") !== false) and (++$endlessloop < 20)) $Text = preg_replace("/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism", - "
" . $t_wrote . "
$2
", - $Text); + "
" . $t_wrote . "
$2
", + $Text); // Declare the format for [quote] layout $QuoteLayout = '
$1
'; @@ -390,8 +398,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $endlessloop = 0; while ((strpos($Text, "[/quote]")!== false) and (strpos($Text, "[quote=") !== false) and (++$endlessloop < 20)) $Text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism", - "
" . $t_wrote . "
$2
", - $Text); + "
" . $t_wrote . "
$2
", + $Text); // [img=widthxheight]image source[/img] //$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); @@ -428,8 +436,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Youtube extensions if ($tryoembed) { - $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); - $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); + $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); + $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text); } -- cgit v1.2.3 From f3f341eb8d301262756f75b40276b90b2f6b8595 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 12 Mar 2013 00:55:29 -0700 Subject: tell it like it is. --- include/bbcode.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 301fbdcc6..6285b16be 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -203,7 +203,6 @@ function bb_ShareAttributesSimple($match) { function bbcode($Text,$preserve_nl = false, $tryoembed = true) { - $a = get_app(); // Extract the private images which use data url's since preg has issues with -- cgit v1.2.3 From 022316fd49b6c8ecd713a4d198b587dd13565f8b Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 12 Mar 2013 01:55:25 -0700 Subject: tell it like it is --- include/bbcode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 6285b16be..82d25ffc8 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -159,8 +159,8 @@ function bb_ShareAttributes($match) { // Bob Smith wrote the following post 2 hours ago $fmt = sprintf( t('%1$s wrote the following %2$s %3$s'), - '' . $author, - '' . t('post'), + '' . $author . '', + '' . t('post') . '', $reldate ); -- cgit v1.2.3 From e411a4bdc27cd443abf613a0044effb4604223f0 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 14 Apr 2013 20:41:58 -0700 Subject: IMPORTANT: magic-auth protocol update, plus 'zrl' bbcode tag for the privacy-is-more-important-than-ease-of-use folks. --- include/bbcode.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 82d25ffc8..930337c5d 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -263,21 +263,24 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Perform URL Search - $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); + $urlchars = '[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,]'; - if ($tryoembed) - $Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text); - $Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$Text); + $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); + +// $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)\{zid\}($urlchars*)/ism", '$1$2$3', $Text); $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); - if ($tryoembed) + if($tryoembed) $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text); $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text); $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text); - //$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '$2', $Text); + + + $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '$1', $Text); + $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text); // Perform MAIL Search $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '$1', $Text); -- cgit v1.2.3 From ab5151c470e630aa3864bbed927dd02f7b192166 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 14 Apr 2013 22:44:11 -0700 Subject: more Friendica removals --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 930337c5d..44bde9acb 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -199,7 +199,7 @@ function bb_ShareAttributesSimple($match) { } // BBcode 2 HTML was written by WAY2WEB.net - // extended to work with Mistpark/Friendica - Mike Macgirvin + // extended to work with Mistpark/Friendica/Red - Mike Macgirvin function bbcode($Text,$preserve_nl = false, $tryoembed = true) { -- cgit v1.2.3 From db038c56542f7fb9658c3b7a703e50efe7823014 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 18 Apr 2013 17:55:35 -0700 Subject: turn naked links in posts into zrl's if we've got a hubloc for the site --- include/bbcode.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 44bde9acb..7a1e3a5e8 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -268,7 +268,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); -// $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)\{zid\}($urlchars*)/ism", '$1$2$3', $Text); $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); -- cgit v1.2.3 From 9fda0a3fd5a78945f818f80bd45dc9e6e3995c4c Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 27 May 2013 21:23:43 -0700 Subject: add support for zmg bbcode tag (img with class=zrl) which will eventually get turned into a zid link when rendered for display. TODO - turn photo items and photos uploaded into posts into zmg, then run all incoming bbcode posts through a filter to see if there's a photo from a known hubloc (with an http(s): src attr - not data:) and if so turn it into a zmg. Then fix the zidify functions to look for class="zrl" and we're done. --- include/bbcode.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 7a1e3a5e8..4f99a8038 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -91,7 +91,7 @@ function bb_replace_images($body, $images) { // We're depending on the property of 'foreach' (specified on the PHP website) that // it loops over the array starting from the first element and going sequentially // to the last element - $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '' . t('Image/photo') . '', $newbody); + $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '' . t('Image/photo') . '', $newbody); $cnt++; } @@ -405,10 +405,12 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // [img=widthxheight]image source[/img] //$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); + $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '', $Text); // Images // [img]pathtoimage[/img] $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); -- cgit v1.2.3 From 2fbc78e6cdf9ca01c404d1bf539008a4b384964f Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 21 Jun 2013 21:39:06 -0700 Subject: fix non-embeddable videos by returning plain links --- include/bbcode.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 4f99a8038..a06d8c4d8 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -424,11 +424,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text); $Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text); - } else { - $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text); - $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); } + // if video couldn't be embedded, link to it instead. + + $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text); + $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); + + // html5 video and audio -- cgit v1.2.3 From b841f825b5befc1fd03dfe49b3af3f31403c9d97 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 21 Jun 2013 21:50:02 -0700 Subject: linkify the non-embeddable video --- include/bbcode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index a06d8c4d8..862570348 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -428,8 +428,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // if video couldn't be embedded, link to it instead. - $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text); - $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); + $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text); + $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); // html5 video and audio -- cgit v1.2.3 From d2d1e54bfe928fe4cdfdcfc7e9acf658cda76898 Mon Sep 17 00:00:00 2001 From: Christian Vogeley Date: Sun, 28 Jul 2013 02:28:35 +0200 Subject: Check existance of bbcode tags before executing regexes, to avoid unnecessary execution --- include/bbcode.php | 269 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 160 insertions(+), 109 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 862570348..a0a53a310 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -219,10 +219,15 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text); // Hide all [noparse] contained bbtags by spacefying them - - $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text); - $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text); - $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text); + if (strpos($Text,'[noparse]') !== false) { + $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text); + } + if (strpos($Text,'[nobb]') !== false) { + $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text); + } + if (strpos($Text,'[pre]') !== false) { + $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text); + } @@ -265,61 +270,75 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $urlchars = '[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,]'; - - $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); - - - $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); - - if($tryoembed) - $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text); - - $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text); - $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text); - - - $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '$1', $Text); - $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text); - + if (strpos($Text,'http') !== false) { + $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); + } + if (strpos($Text,'[/share]') !== false) { + $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); + } + if($tryoembed) { + if (strpos($Text,'[/url]') !== false) { + $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text); + } + } + if (strpos($Text,'[/url]') !== false) { + $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text); + $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text); + } + if (strpos($Text,'[/zrl]') !== false) { + $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '$1', $Text); + $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text); + } // Perform MAIL Search - $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '$1', $Text); - $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '$2', $Text); - + if (strpos($Text,'[/mail]') !== false) { + $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '$1', $Text); + $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '$2', $Text); + } // Check for bold text - $Text = preg_replace("(\[b\](.*?)\[\/b\])ism",'$1',$Text); - + if (strpos($Text,'[b]') !== false) { + $Text = preg_replace("(\[b\](.*?)\[\/b\])ism",'$1',$Text); + } // Check for Italics text - $Text = preg_replace("(\[i\](.*?)\[\/i\])ism",'$1',$Text); - + if (strpos($Text,'[i]') !== false) { + $Text = preg_replace("(\[i\](.*?)\[\/i\])ism",'$1',$Text); + } // Check for Underline text - $Text = preg_replace("(\[u\](.*?)\[\/u\])ism",'$1',$Text); - + if (strpos($Text,'[u]') !== false) { + $Text = preg_replace("(\[u\](.*?)\[\/u\])ism",'$1',$Text); + } // Check for strike-through text - $Text = preg_replace("(\[s\](.*?)\[\/s\])ism",'$1',$Text); - + if (strpos($Text,'[s]') !== false) { + $Text = preg_replace("(\[s\](.*?)\[\/s\])ism",'$1',$Text); + } // Check for over-line text - $Text = preg_replace("(\[o\](.*?)\[\/o\])ism",'$1',$Text); - + if (strpos($Text,'[o]') !== false) { + $Text = preg_replace("(\[o\](.*?)\[\/o\])ism",'$1',$Text); + } // Check for colored text - $Text = preg_replace("(\[color=(.*?)\](.*?)\[\/color\])ism","$2",$Text); - + if (strpos($Text,'[/color]') !== false) { + $Text = preg_replace("(\[color=(.*?)\](.*?)\[\/color\])ism","$2",$Text); + } // Check for sized text // [size=50] --> font-size: 50px (with the unit). - $Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism","$2",$Text); - $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","$2",$Text); - + if (strpos($Text,'[/size]') !== false) { + $Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism","$2",$Text); + $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","$2",$Text); + } // Check for centered text + if (strpos($Text,'[/center]') !== false) { $Text = preg_replace("(\[center\](.*?)\[\/center\])ism","
$1
",$Text); - + } // Check for list text $Text = str_replace("[*]", "
  • ", $Text); // Check for style sheet commands - $Text = preg_replace("(\[style=(.*?)\](.*?)\[\/style\])ism","$2",$Text); - + if (strpos($Text,'[/style]') !== false) { + $Text = preg_replace("(\[style=(.*?)\](.*?)\[\/style\])ism","$2",$Text); + } // Check for CSS classes - $Text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism","$2",$Text); - + if (strpos($Text,'[/class]') !== false) { + $Text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism","$2",$Text); + } // handle nested lists $endlessloop = 0; @@ -338,15 +357,20 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '
      $1
    ' ,$Text); $Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '
  • $1
  • ' ,$Text); } - - $Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '$1' ,$Text); - $Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '$1' ,$Text); - $Text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '$1' ,$Text); - $Text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '$1
    ' ,$Text); - - $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '$1
    ' ,$Text); - $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '$1
    ' ,$Text); - + if (strpos($Text,'[th]') !== false) { + $Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '$1' ,$Text); + } + if (strpos($Text,'[td]') !== false) { + $Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '$1' ,$Text); + } + if (strpos($Text,'[tr]') !== false) { + $Text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '$1' ,$Text); + } + if (strpos($Text,'[table]') !== false) { + $Text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '$1
    ' ,$Text); + $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '$1
    ' ,$Text); + $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '$1
    ' ,$Text); + } $Text = str_replace('[hr]','
    ', $Text); // This is actually executed in prepare_body() @@ -354,14 +378,16 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = str_replace('[nosmile]','',$Text); // Check for font change text - $Text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm","$2",$Text); - + if (strpos($Text,'[/font]') !== false) { + $Text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm","$2",$Text); + } // Declare the format for [code] layout $CodeLayout = '$1'; // Check for [code] text - $Text = preg_replace("/\[code\](.*?)\[\/code\]/ism","$CodeLayout", $Text); - + if (strpos($Text,'[code]') !== false) { + $Text = preg_replace("/\[code\](.*?)\[\/code\]/ism","$CodeLayout", $Text); + } // Declare the format for [spoiler] layout $SpoilerLayout = '
    $1
    '; @@ -404,72 +430,93 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // [img=widthxheight]image source[/img] //$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); - $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); - $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '', $Text); - + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '', $Text); + } // Images // [img]pathtoimage[/img] - $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); - $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); - - - - $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); - $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[crypt]') !== false) { + $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); + $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); + } // Try to Oembed if ($tryoembed) { - $Text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", '', $Text); - $Text = preg_replace("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\[\/audio\]/ism", '', $Text); - - $Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text); - $Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text); + if (strpos($Text,'[/video]') !== false) { + $Text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", '', $Text); + } + if (strpos($Text,'[/audio]') !== false) { + $Text = preg_replace("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\[\/audio\]/ism", '', $Text); + } + if (strpos($Text,'[/video]') !== false) { + $Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text); + } + if (strpos($Text,'[/audio]') !== false) { + $Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text); + } } // if video couldn't be embedded, link to it instead. - - $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text); - $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); + if (strpos($Text,'[/video]') !== false) { + $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text); + } + if (strpos($Text,'[/audio]') !== false) { + $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); + } // html5 video and audio - if ($tryoembed) - $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '', $Text); - else - $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '$1', $Text); - + if ($tryoembed){ + if (strpos($Text,'[/iframe]') !== false) { + $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '', $Text); + } + } + else { + if (strpos($Text,'[/iframe]') !== false) { + $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '$1', $Text); + } + } // Youtube extensions - if ($tryoembed) { - $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); - $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); - $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text); + if (strpos($Text,'[youtube]') !== false) { + if ($tryoembed) { + $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); + $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); + $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text); + } + $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); + $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); + $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); + + if ($tryoembed) + $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text); + else + $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "http://www.youtube.com/watch?v=$1", $Text); } + if (strpos($Text,'[vimeo]') !== false) { + if ($tryoembed) { + $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); + $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); + } - $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); - $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); - $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); - - if ($tryoembed) - $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text); - else - $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "http://www.youtube.com/watch?v=$1", $Text); - + $Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); + $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); - if ($tryoembed) { - $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); - $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); + if ($tryoembed) + $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '', $Text); + else + $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", "http://vimeo.com/$1", $Text); } - - $Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); - $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); - - if ($tryoembed) - $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '', $Text); - else - $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", "http://vimeo.com/$1", $Text); - // $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '', $Text); @@ -497,11 +544,15 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Unhide all [noparse] contained bbtags unspacefying them // and triming the [noparse] tag. - - $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_unspacefy_and_trim',$Text); - $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_unspacefy_and_trim',$Text); - $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_unspacefy_and_trim',$Text); - + if (strpos($Text,'[noparse]') !== false) { + $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_unspacefy_and_trim',$Text); + } + if (strpos($Text,'[nobb]') !== false) { + $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_unspacefy_and_trim',$Text); + } + if (strpos($Text,'[pre]') !== false) { + $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_unspacefy_and_trim',$Text); + } $Text = preg_replace('/\[\&\;([#a-z0-9]+)\;\]/','&$1;',$Text); -- cgit v1.2.3 From 2f2a316b27221759d433a786fb3485238f032a37 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 26 Aug 2013 03:54:27 -0700 Subject: regex patch --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index a0a53a310..9f9489893 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -271,7 +271,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $urlchars = '[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,]'; if (strpos($Text,'http') !== false) { - $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); + $Text = preg_replace("/([^\"\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); } if (strpos($Text,'[/share]') !== false) { $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); -- cgit v1.2.3 From 2e72b136c558652ca9a9b755b29cdb99ee27ee7f Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 26 Aug 2013 17:48:05 -0700 Subject: fix profile change activity where the change is a solitary url - and includes a stray right quote --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 9f9489893..a0a53a310 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -271,7 +271,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $urlchars = '[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,]'; if (strpos($Text,'http') !== false) { - $Text = preg_replace("/([^\"\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); + $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); } if (strpos($Text,'[/share]') !== false) { $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); -- cgit v1.2.3 From c6e527f6fec7f3a5350f8cf794decfd35cea134a Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 27 Aug 2013 05:02:40 -0700 Subject: when using the bbcode mimetype a space is just a space. A return is a return. But as opposed to HTML, two spaces are now non-breaking. A tab (assuming you can figure out how to enter one in a text field) is now four non-breaking spaces. This should let us insert code snippets with much more readable indentation. --- include/bbcode.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index a0a53a310..4647b8567 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -259,6 +259,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = str_replace(array("\n","\r"), array('',''),$Text); + $Text = str_replace(array("\t"," "),array("    ","  "),$Text); // Set up the parameters for a URL search string $URLSearchString = "^\[\]"; -- cgit v1.2.3 From d194ee091af0ee15c7f63def7e8c07ee29e38f39 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 6 Sep 2013 05:25:10 -0700 Subject: encode and decode channel names containing HTML special characters and quotes so they will survive a reshare without mangling --- include/bbcode.php | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 4647b8567..997cbac2e 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -106,48 +106,28 @@ function bb_ShareAttributes($match) { $author = ""; preg_match("/author='(.*?)'/ism", $attributes, $matches); if ($matches[1] != "") - $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); - - preg_match('/author="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $author = $matches[1]; + $author = urldecode($matches[1]); $link = ""; preg_match("/link='(.*?)'/ism", $attributes, $matches); if ($matches[1] != "") $link = $matches[1]; - preg_match('/link="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $link = $matches[1]; - $avatar = ""; preg_match("/avatar='(.*?)'/ism", $attributes, $matches); if ($matches[1] != "") $avatar = $matches[1]; - preg_match('/avatar="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $avatar = $matches[1]; - $profile = ""; preg_match("/profile='(.*?)'/ism", $attributes, $matches); if ($matches[1] != "") $profile = $matches[1]; - preg_match('/profile="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; - $posted = ""; preg_match("/posted='(.*?)'/ism", $attributes, $matches); if ($matches[1] != "") $posted = $matches[1]; - preg_match('/posted="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $posted = $matches[1]; - // FIXME - this should really be a wall-item-ago so it will get updated on the client $reldate = (($posted) ? relative_date($posted) : ''); -- cgit v1.2.3 From e79bc2924422578a9eb8fc44be59e619a1c158b5 Mon Sep 17 00:00:00 2001 From: zottel Date: Mon, 23 Sep 2013 13:26:23 +0200 Subject: add [observer] tags and [observer.baseurl] --- include/bbcode.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 997cbac2e..30bfdad56 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -217,6 +217,18 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $ev = bbtoevent($Text); + // process [observer] tags before we do anything else because we might + // be stripping away stuff that then doesn't need to be worked on anymore + $observer = $a->get_observer(); + if (strpos($Text,'[/observer]') !== false) { + if ($observer) { + $Text = preg_replace("/\[observer(\=1)?\](.*?)\[\/observer\]/ism", '$2', $Text); + $Text = preg_replace("/\[observer\=0\].*?\[\/observer\]/ism", '', $Text); + } else { + $Text = preg_replace("/\[observer(\=1)?\].*?\[\/observer\]/ism", '', $Text); + $Text = preg_replace("/\[observer\=0\](.*?)\[\/observer\]/ism", '$1', $Text); + } + } // 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 @@ -246,6 +258,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Set up the parameters for a MAIL search string $MAILSearchString = $URLSearchString; + // replace [observer.baseurl] + if ($observer) { + $obsBaseURL = $observer['xchan_url']; + $obsBaseURL = preg_replace("/\/channel\/.*$/", '', $obsBaseURL); + $Text = str_replace('[observer.baseurl]', $obsBaseURL, $Text); + } else { + $Text = str_replace('[observer.baseurl]', '', $Text); + } // Perform URL Search -- cgit v1.2.3 From 1f916adfb889c877ff975be75274fb7f3ac37b1f Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 23 Sep 2013 18:38:08 -0700 Subject: spice this up a little bit... --- include/bbcode.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 30bfdad56..7d7bf1de4 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -263,8 +263,16 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $obsBaseURL = $observer['xchan_url']; $obsBaseURL = preg_replace("/\/channel\/.*$/", '', $obsBaseURL); $Text = str_replace('[observer.baseurl]', $obsBaseURL, $Text); + $Text = str_replace('[observer.url]',$observer['xchan_url'], $Text); + $Text = str_replace('[observer.name]',$observer['xchan_name'], $Text); + $Text = str_replace('[observer.address]',$observer['xchan_addr'], $Text); + $Text = str_replace('[observer.photo]','[zmg]'.$observer['xchan_photo_l'].'[/zmg]', $Text); } else { $Text = str_replace('[observer.baseurl]', '', $Text); + $Text = str_replace('[observer.url]','', $Text); + $Text = str_replace('[observer.name]','', $Text); + $Text = str_replace('[observer.address]','', $Text); + $Text = str_replace('[observer.photo]','', $Text); } // Perform URL Search -- cgit v1.2.3 From 5092ae9e2bd5edfc67a82c56e803bdcb203386f8 Mon Sep 17 00:00:00 2001 From: zottel Date: Tue, 24 Sep 2013 14:35:47 +0200 Subject: Fix observer=1 tag. Using only observer without =1 won't work anymore now. --- include/bbcode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 7d7bf1de4..9b9c954c1 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -222,10 +222,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $observer = $a->get_observer(); if (strpos($Text,'[/observer]') !== false) { if ($observer) { - $Text = preg_replace("/\[observer(\=1)?\](.*?)\[\/observer\]/ism", '$2', $Text); + $Text = preg_replace("/\[observer\=1\](.*?)\[\/observer\]/ism", '$1', $Text); $Text = preg_replace("/\[observer\=0\].*?\[\/observer\]/ism", '', $Text); } else { - $Text = preg_replace("/\[observer(\=1)?\].*?\[\/observer\]/ism", '', $Text); + $Text = preg_replace("/\[observer\=1\].*?\[\/observer\]/ism", '', $Text); $Text = preg_replace("/\[observer\=0\](.*?)\[\/observer\]/ism", '$1', $Text); } } -- cgit v1.2.3 From b25d2e0d12046786290b95b465643b8cb9bc8c12 Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Wed, 2 Oct 2013 05:03:09 +0100 Subject: Slightly modify reshares so they can be themed as a whole. --- include/bbcode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 9b9c954c1..756d73aba 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -131,7 +131,7 @@ function bb_ShareAttributes($match) { // FIXME - this should really be a wall-item-ago so it will get updated on the client $reldate = (($posted) ? relative_date($posted) : ''); - $headline = '
    '; + $headline = '
    '; if ($avatar != "") $headline .= '' . $author . ''; @@ -146,7 +146,7 @@ function bb_ShareAttributes($match) { $headline .= '' . $fmt . '
    '; - $text = $headline . '
    ' . trim($match[2]) . '
    '; + $text = $headline . '
    ' . trim($match[2]) . '
    '; return($text); } -- cgit v1.2.3 From 75ba7ae1166562f48356b445b10cce2e57a42f4a Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 29 Oct 2013 18:46:51 -0700 Subject: rpost bbcode tag --- include/bbcode.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 756d73aba..de8a34b80 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -2,7 +2,7 @@ require_once("include/oembed.php"); require_once('include/event.php'); - +require_once('include/zot.php'); function tryoembed($match) { @@ -178,6 +178,11 @@ function bb_ShareAttributesSimple($match) { return($text); } +function rpost_callback($match) { + return str_replace($match[0],get_rpost_path(get_app()->get_observer()) . '&body=' . urlencode($match[1]),$match[0]); +} + + // BBcode 2 HTML was written by WAY2WEB.net // extended to work with Mistpark/Friendica/Red - Mike Macgirvin @@ -220,13 +225,15 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // process [observer] tags before we do anything else because we might // be stripping away stuff that then doesn't need to be worked on anymore $observer = $a->get_observer(); - if (strpos($Text,'[/observer]') !== false) { + if ((strpos($Text,'[/observer]') !== false) || (strpos($Text,'[/rpost]') !== false)) { if ($observer) { $Text = preg_replace("/\[observer\=1\](.*?)\[\/observer\]/ism", '$1', $Text); $Text = preg_replace("/\[observer\=0\].*?\[\/observer\]/ism", '', $Text); + $Text = preg_replace_callback("/\[rpost\](.*?)\[\/rpost\]/ism", 'rpost_callback', $Text); } else { $Text = preg_replace("/\[observer\=1\].*?\[\/observer\]/ism", '', $Text); $Text = preg_replace("/\[observer\=0\](.*?)\[\/observer\]/ism", '$1', $Text); + $Text = preg_replace("/\[rpost\](.*?)\[\/rpost\]/ism", '', $Text); } } @@ -266,7 +273,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = str_replace('[observer.url]',$observer['xchan_url'], $Text); $Text = str_replace('[observer.name]',$observer['xchan_name'], $Text); $Text = str_replace('[observer.address]',$observer['xchan_addr'], $Text); - $Text = str_replace('[observer.photo]','[zmg]'.$observer['xchan_photo_l'].'[/zmg]', $Text); + $Text = str_replace('[observer.photo]','[zmg]'.$observer['xchan_photo_l'].'[/zmg]', $Text); } else { $Text = str_replace('[observer.baseurl]', '', $Text); $Text = str_replace('[observer.url]','', $Text); -- cgit v1.2.3 From 4cae5249d4e037459838c16ba3d81aa99a2bc52c Mon Sep 17 00:00:00 2001 From: zottel Date: Wed, 30 Oct 2013 22:29:25 +0100 Subject: Allow setting of title in rpost tag with [rpost=title]body[/rpost] --- include/bbcode.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index de8a34b80..48e13b06f 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -179,7 +179,11 @@ function bb_ShareAttributesSimple($match) { } function rpost_callback($match) { - return str_replace($match[0],get_rpost_path(get_app()->get_observer()) . '&body=' . urlencode($match[1]),$match[0]); + if (count($match) == 3) { + return str_replace($match[0],get_rpost_path(get_app()->get_observer()) . '&title=' . urlencode($match[1]) . '&body=' . urlencode($match[2]),$match[0]); + } else { + return str_replace($match[0],get_rpost_path(get_app()->get_observer()) . '&body=' . urlencode($match[1]),$match[0]); + } } @@ -230,6 +234,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/\[observer\=1\](.*?)\[\/observer\]/ism", '$1', $Text); $Text = preg_replace("/\[observer\=0\].*?\[\/observer\]/ism", '', $Text); $Text = preg_replace_callback("/\[rpost\](.*?)\[\/rpost\]/ism", 'rpost_callback', $Text); + $Text = preg_replace_callback("/\[rpost\=(.*?)\](.*?)\[\/rpost\]/ism", 'rpost_callback', $Text); } else { $Text = preg_replace("/\[observer\=1\].*?\[\/observer\]/ism", '', $Text); $Text = preg_replace("/\[observer\=0\](.*?)\[\/observer\]/ism", '$1', $Text); -- cgit v1.2.3 From 09d5fa6a64e9cf7d3e0cf182dbdd492546db198b Mon Sep 17 00:00:00 2001 From: zottel Date: Thu, 31 Oct 2013 00:08:32 +0100 Subject: Use only one regex for title matching in rpost tag --- include/bbcode.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 48e13b06f..9ca8e3f03 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -179,10 +179,10 @@ function bb_ShareAttributesSimple($match) { } function rpost_callback($match) { - if (count($match) == 3) { - return str_replace($match[0],get_rpost_path(get_app()->get_observer()) . '&title=' . urlencode($match[1]) . '&body=' . urlencode($match[2]),$match[0]); + if ($match[2]) { + return str_replace($match[0],get_rpost_path(get_app()->get_observer()) . '&title=' . urlencode($match[2]) . '&body=' . urlencode($match[3]),$match[0]); } else { - return str_replace($match[0],get_rpost_path(get_app()->get_observer()) . '&body=' . urlencode($match[1]),$match[0]); + return str_replace($match[0],get_rpost_path(get_app()->get_observer()) . '&body=' . urlencode($match[3]),$match[0]); } } @@ -233,12 +233,11 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { if ($observer) { $Text = preg_replace("/\[observer\=1\](.*?)\[\/observer\]/ism", '$1', $Text); $Text = preg_replace("/\[observer\=0\].*?\[\/observer\]/ism", '', $Text); - $Text = preg_replace_callback("/\[rpost\](.*?)\[\/rpost\]/ism", 'rpost_callback', $Text); - $Text = preg_replace_callback("/\[rpost\=(.*?)\](.*?)\[\/rpost\]/ism", 'rpost_callback', $Text); + $Text = preg_replace_callback("/\[rpost(=(.*?))?\](.*?)\[\/rpost\]/ism", 'rpost_callback', $Text); } else { $Text = preg_replace("/\[observer\=1\].*?\[\/observer\]/ism", '', $Text); $Text = preg_replace("/\[observer\=0\](.*?)\[\/observer\]/ism", '$1', $Text); - $Text = preg_replace("/\[rpost\](.*?)\[\/rpost\]/ism", '', $Text); + $Text = preg_replace("/\[rpost(=.*?)?\](.*?)\[\/rpost\]/ism", '', $Text); } } -- cgit v1.2.3 From fc317172d5c6632df50aa8e25509ee2b6b830d2f Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 7 Nov 2013 20:18:52 -0800 Subject: more e2ee infrastructure - at this point if somebody wants it they're going to have to work for it. --- include/bbcode.php | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 9ca8e3f03..14d0ce14a 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -99,6 +99,43 @@ function bb_replace_images($body, $images) { }} + +function bb_parse_crypt($match) { + + $attributes = $match[1]; + + $algorithm = ""; + preg_match("/alg='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $algorithm = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + + preg_match("/alg=\"\;(.*?)\"\;/ism", $attributes, $matches); + if ($matches[1] != "") + $algorithm = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + + $hint = ""; + preg_match("/hint='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $hint = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + preg_match("/hint=\"\;(.*?)\"\;/ism", $attributes, $matches); + if ($matches[1] != "") + $hint = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + + // Next we really should link to a JS routine based on the algorithm which prompts for a key + // something like zdecrypt_{algorithm}, which will be a no-op if the decryption algorithm is not present + // We can either pass the text or pass a message ID and let the decryption module call /viewsrc or something + // to get the text. The text might be large so the message ID might be preferable. But if we pass the + // text directly we won't have to do a network fetch; and can potentially display the results in a popup. + + + $Text = '
    ' . t('Encrypted content') . '
    ' . t('Algorithm: ') . $algorithm . '
    ' . t('Key hint: ') . $hint . '
    '; + + return $Text; + +} + + + function bb_ShareAttributes($match) { $attributes = $match[1]; @@ -465,9 +502,9 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); } - if (strpos($Text,'[crypt]') !== false) { + if (strpos($Text,'[/crypt]') !== false) { $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); - $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); + $Text = preg_replace_callback("/\[crypt (.*?)\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $Text); } // Try to Oembed if ($tryoembed) { -- cgit v1.2.3 From 3a10e698c9932df64c6e4fa9e0785efaf4357362 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 10 Nov 2013 19:58:08 -0800 Subject: Didn't finish it. Gotta' pee. --- include/bbcode.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 14d0ce14a..de71eb4e3 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -121,14 +121,7 @@ function bb_parse_crypt($match) { if ($matches[1] != "") $hint = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); - // Next we really should link to a JS routine based on the algorithm which prompts for a key - // something like zdecrypt_{algorithm}, which will be a no-op if the decryption algorithm is not present - // We can either pass the text or pass a message ID and let the decryption module call /viewsrc or something - // to get the text. The text might be large so the message ID might be preferable. But if we pass the - // text directly we won't have to do a network fetch; and can potentially display the results in a popup. - - - $Text = '
    ' . t('Encrypted content') . '
    ' . t('Algorithm: ') . $algorithm . '
    ' . t('Key hint: ') . $hint . '
    '; + $Text = '
    ' . t('Encrypted content') . '
    '; return $Text; @@ -503,7 +496,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } if (strpos($Text,'[/crypt]') !== false) { - $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); + $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); $Text = preg_replace_callback("/\[crypt (.*?)\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $Text); } // Try to Oembed -- cgit v1.2.3 From 435e2dae0e9204afd7288c14748e88f680276969 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 11 Nov 2013 00:21:00 -0800 Subject: display encrypted text inline --- include/bbcode.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index de71eb4e3..271cace73 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -121,7 +121,9 @@ function bb_parse_crypt($match) { if ($matches[1] != "") $hint = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); - $Text = '
    ' . t('Encrypted content') . '
    '; + $x = random_string(); + + $Text = '
    ' . t('Encrypted content') . '

    '; return $Text; @@ -496,7 +498,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } if (strpos($Text,'[/crypt]') !== false) { - $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); + $x = random_string(); + $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); $Text = preg_replace_callback("/\[crypt (.*?)\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $Text); } // Try to Oembed -- cgit v1.2.3 From 63a42480c7eb36bdc8b63b31b2a4d222ba5751cd Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 23 Dec 2013 15:13:09 -0800 Subject: add account_level, is_foreigner and is_member functions; convert all e2ee user input and prompts to hex to avoid javascipt's lame handling of quotes. !!This breaks all prior encrypted posts.!! --- include/bbcode.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 271cace73..6374675f1 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -105,21 +105,24 @@ function bb_parse_crypt($match) { $attributes = $match[1]; $algorithm = ""; + preg_match("/alg='(.*?)'/ism", $attributes, $matches); if ($matches[1] != "") - $algorithm = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + $algorithm = $matches[1]; preg_match("/alg=\"\;(.*?)\"\;/ism", $attributes, $matches); if ($matches[1] != "") - $algorithm = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + $algorithm = $matches[1]; $hint = ""; + + preg_match("/hint='(.*?)'/ism", $attributes, $matches); if ($matches[1] != "") - $hint = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + $hint = $matches[1]; preg_match("/hint=\"\;(.*?)\"\;/ism", $attributes, $matches); if ($matches[1] != "") - $hint = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + $hint = $matches[1]; $x = random_string(); -- cgit v1.2.3 From e635dcb3092da962c29fe4c8e4ddc53de368002d Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 6 Jan 2014 23:54:40 -0800 Subject: bbcode convenience variables for producing documentation. --- include/bbcode.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 6374675f1..01d5df9e3 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -276,6 +276,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } } + $Text = str_replace(array('[baseurl]','[sitename]'),array(z_root(),get_config('system','sitename')),$Text); + // 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 -- cgit v1.2.3 From 8b93881ce7ab4e0a8b0c8426da1ddfeed19c2309 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 7 Jan 2014 20:36:16 -0800 Subject: qr code support --- include/bbcode.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 01d5df9e3..35ce2b918 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -132,6 +132,9 @@ function bb_parse_crypt($match) { } +function bb_qr($match) { + return '' . t('QR code') . ''; +} function bb_ShareAttributes($match) { @@ -277,6 +280,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } $Text = str_replace(array('[baseurl]','[sitename]'),array(z_root(),get_config('system','sitename')),$Text); + // 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 @@ -330,6 +334,12 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { if (strpos($Text,'http') !== false) { $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); } + + if (strpos($Text,'[/qr]') !== false) { + $Text = preg_replace_callback("/\[qr\](.*?)\[\/qr\]/ism","bb_qr",$Text); + } + + if (strpos($Text,'[/share]') !== false) { $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); } -- cgit v1.2.3 From 29db2369811ba35515d285491ce089d937ed8d29 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 8 Jan 2014 14:11:39 -0800 Subject: qr enhancements --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 35ce2b918..dfb0b9fb8 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -133,7 +133,7 @@ function bb_parse_crypt($match) { } function bb_qr($match) { - return '' . t('QR code') . ''; + return '' . t('QR code') . ''; } -- cgit v1.2.3 From c6b9e443530fa2598f931571a0aa026b7bef8992 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 9 Jan 2014 00:53:33 -0800 Subject: fix table bbcode --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index dfb0b9fb8..9f07b71ce 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -433,7 +433,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { if (strpos($Text,'[tr]') !== false) { $Text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '$1' ,$Text); } - if (strpos($Text,'[table]') !== false) { + if (strpos($Text,'[/table]') !== false) { $Text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '$1
    ' ,$Text); $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '$1
    ' ,$Text); $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '$1
    ' ,$Text); -- cgit v1.2.3 From ab6b6794b4763f864ff29ff9748c669c88f2a1a5 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 23 Jan 2014 15:43:35 -0800 Subject: fix marital partner linking --- include/bbcode.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 9f07b71ce..7e6ef3a2b 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -189,6 +189,10 @@ function bb_ShareAttributes($match) { return($text); } +function bb_location($match) { + // not yet implemented +} + function bb_ShareAttributesSimple($match) { $attributes = $match[1]; @@ -256,6 +260,11 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text); } +// Not yet implemented - thinking this should display a map or perhaps be a map directive +// if (strpos($Text,'[location]') !== false) { +// $Text = preg_replace_callback("/\[location\](.*?)\[\/location\]/ism", 'bb_location',$Text); +// } + // If we find any event code, turn it into an event. @@ -266,6 +275,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // process [observer] tags before we do anything else because we might // be stripping away stuff that then doesn't need to be worked on anymore + $observer = $a->get_observer(); if ((strpos($Text,'[/observer]') !== false) || (strpos($Text,'[/rpost]') !== false)) { if ($observer) { -- cgit v1.2.3 From 357ddd1bf708bfa1c3973bf9a69a333b3338a5ce Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 23 Jan 2014 15:53:29 -0800 Subject: display a somewhat more pleasant hovertip on qr codes --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 7e6ef3a2b..697260668 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -133,7 +133,7 @@ function bb_parse_crypt($match) { } function bb_qr($match) { - return '' . t('QR code') . ''; + return '' . t('QR code') . ''; } -- cgit v1.2.3 From 34906049269853f58ab70f4a64441f3f8f1f2c5b Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 23 Jan 2014 23:46:43 -0800 Subject: add zid to audio/video (again) --- include/bbcode.php | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 697260668..084c02125 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -16,6 +16,40 @@ function tryoembed($match) { return $html; } +function tryzrlaudio($match) { + + $link = $match[1]; + $m = @parse_url($link); + $zrl = false; + if($m['host']) { + $r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1", + dbesc($m['host']) + ); + if($r) + $zrl = true; + } + if($zrl) + $link = zid($link); + return ''; +} + +function tryzrlvideo($match) { + $link = $match[1]; + $m = @parse_url($link); + $zrl = false; + if($m['host']) { + $r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1", + dbesc($m['host']) + ); + if($r) + $zrl = true; + } + if($zrl) + $link = zid($link); + return ''; + +} + // [noparse][i]italic[/i][/noparse] turns into // [noparse][ i ]italic[ /i ][/noparse], // to hide them from parser. @@ -527,14 +561,18 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); $Text = preg_replace_callback("/\[crypt (.*?)\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $Text); } + + // html5 video and audio + if (strpos($Text,'[/video]') !== false) { + $Text = preg_replace_callback("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", 'tryzrlvideo', $Text); + } + if (strpos($Text,'[/audio]') !== false) { + $Text = preg_replace_callback("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\[\/audio\]/ism", 'tryzrlaudio', $Text); + } + // Try to Oembed if ($tryoembed) { - if (strpos($Text,'[/video]') !== false) { - $Text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", '', $Text); - } - if (strpos($Text,'[/audio]') !== false) { - $Text = preg_replace("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\[\/audio\]/ism", '', $Text); - } + if (strpos($Text,'[/video]') !== false) { $Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text); } @@ -552,7 +590,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } - // html5 video and audio if ($tryoembed){ -- cgit v1.2.3 From 3dfd38021f193d16d3c6ed4824fa24e42a62238f Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 28 Jan 2014 16:35:10 -0800 Subject: SECURITY: remove style and class bbcodes --- include/bbcode.php | 8 -------- 1 file changed, 8 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 084c02125..fec8750e9 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -442,14 +442,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Check for list text $Text = str_replace("[*]", "
  • ", $Text); - // Check for style sheet commands - if (strpos($Text,'[/style]') !== false) { - $Text = preg_replace("(\[style=(.*?)\](.*?)\[\/style\])ism","$2",$Text); - } - // Check for CSS classes - if (strpos($Text,'[/class]') !== false) { - $Text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism","$2",$Text); - } // handle nested lists $endlessloop = 0; -- cgit v1.2.3 From fe2b6f3dfb4a9473905dde49b7741a6c03699c23 Mon Sep 17 00:00:00 2001 From: marijus Date: Thu, 30 Jan 2014 00:01:19 +0100 Subject: add image floating to bbcode --- include/bbcode.php | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index fec8750e9..57494bd7a 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -439,6 +439,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { if (strpos($Text,'[/center]') !== false) { $Text = preg_replace("(\[center\](.*?)\[\/center\])ism","
    $1
    ",$Text); } + // Check for list text $Text = str_replace("[*]", "
  • ", $Text); @@ -531,23 +532,52 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { "
    " . $t_wrote . "
    $2
    ", $Text); - // [img=widthxheight]image source[/img] - //$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); - if (strpos($Text,'[/img]') !== false) { - $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); - } - if (strpos($Text,'[/zmg]') !== false) { - $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '', $Text); - } // Images // [img]pathtoimage[/img] - if (strpos($Text,'[/img]') !== false) { + if (strpos($Text,'[/img]') !== false) { $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); } - if (strpos($Text,'[/zmg]') !== false) { + if (strpos($Text,'[/zmg]') !== false) { $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); } + // [img float={left, right}]pathtoimage[/img] + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img float=left\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img float=right\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg float=left\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg float=right\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + } + + // [img=widthxheight]pathtoimage[/img] + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + } + + // [img=widthxheight float={left, right}]pathtoimage[/img] + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*) float=left\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*) float=right\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*) float=left\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*) float=right\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + } + + // crypt if (strpos($Text,'[/crypt]') !== false) { $x = random_string(); $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); -- cgit v1.2.3 From 75022367e5c3ecec24ec66acff162d6dd534486c Mon Sep 17 00:00:00 2001 From: marijus Date: Thu, 30 Jan 2014 00:15:13 +0100 Subject: minor whitespace cleanup --- include/bbcode.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 57494bd7a..2e2faddd6 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -439,7 +439,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { if (strpos($Text,'[/center]') !== false) { $Text = preg_replace("(\[center\](.*?)\[\/center\])ism","
    $1
    ",$Text); } - // Check for list text $Text = str_replace("[*]", "
  • ", $Text); -- cgit v1.2.3 From a606fc0ba39fc5f672fec389b5130b07fe1a1a5d Mon Sep 17 00:00:00 2001 From: marijus Date: Wed, 5 Feb 2014 14:34:25 +0100 Subject: add a sanitized style tag to bbcode --- include/bbcode.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 2e2faddd6..bd2c7d11a 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -262,6 +262,56 @@ function rpost_callback($match) { } } +function bb_sanitize_style($input) { + //whitelist property limits (0 = no limitation) + $w = array( // color properties + "color" => 0, + "background-color" => 0, + // box properties + "padding" => array("px"=>100, "%"=>0, "em"=>2, "ex"=>2, "mm"=>0, "cm"=>0, "in"=>0, "pt"=>0, "pc"=>0), + "margin" => array("px"=>100, "%"=>0, "em"=>2, "ex"=>2, "mm"=>0, "cm"=>0, "in"=>0, "pt"=>0, "pc"=>0), + "border" => array("px"=>100, "%"=>0, "em"=>2, "ex"=>2, "mm"=>0, "cm"=>0, "in"=>0, "pt"=>0, "pc"=>0), + "float" => 0, + "clear" => 0, + // text properties + "text-decoration" => 0, + + ); + + $css_string = $input[1]; + $a = explode(';',$css_string); + foreach($a as $parts){ + list($k, $v) = explode(':', $parts); + $css[ trim($k) ] = trim($v); + } + + // sanitize properties + $b = array_merge(array_diff_key($css, $w), array_diff_key($w, $css)); + $css = array_diff_key($css, $b); + + foreach($css as $key => $value) { + if($w[$key] != null) { + foreach($w[$key] as $limit_key => $limit_value) { + //sanitize values + if(strpos($value, $limit_key)) { + $value = preg_replace_callback( + "/(\S.*?)$limit_key/ism", + function($match) use($limit_value, $limit_key) { + if($match[1] > $limit_value) { + return $limit_value . $limit_key; + } else { + return $match[1] . $limit_key; + } + }, + $value + ); + } + } + } + $css_string_san .= $key . ":" . $value ."; "; + } + return "" . $input[2] . ""; +} // BBcode 2 HTML was written by WAY2WEB.net // extended to work with Mistpark/Friendica/Red - Mike Macgirvin @@ -576,6 +626,11 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*) float=right\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); } + // style (sanitized) + if (strpos($Text,'[/style]') !== false) { + $Text = preg_replace_callback("(\[style=(.*?)\](.*?)\[\/style\])ism", "bb_sanitize_style", $Text); + } + // crypt if (strpos($Text,'[/crypt]') !== false) { $x = random_string(); -- cgit v1.2.3 From c9192991c95a5145e5d515f7c6268c61e6400476 Mon Sep 17 00:00:00 2001 From: Christian Vogeley Date: Sun, 9 Feb 2014 01:37:09 +0100 Subject: Add class to bookmark links to make it better them able E.g.: css (not yet included) .bookmark-identifier{ display:none; } .bookmark:hover:before{ text-decoration:none; content:"#^"; color:#000000; background:#FFFFFF; } .bookmark:hover{ color: #FFFFFF; background: #3465A4; } --- include/bbcode.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index bd2c7d11a..9cd5ad58c 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -443,10 +443,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } } if (strpos($Text,'[/url]') !== false) { + $Text = preg_replace("/\#\^\[url\]([$URLSearchString]*)\[\/url\]/ism", '#^$1', $Text); + $Text = preg_replace("/\#\^\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '#^$2', $Text); $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text); $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text); } if (strpos($Text,'[/zrl]') !== false) { + $Text = preg_replace("/\#\^\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '#^$1', $Text); + $Text = preg_replace("/\#\^\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '#^$2', $Text); $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '$1', $Text); $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text); } -- cgit v1.2.3 From e47035f85a680344f2d5f58971ca2629c70c7838 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 12 Feb 2014 11:42:33 -0800 Subject: bbcode element of where you are on a site. perhaps this is less than generally useful but I plan to use it in a demo video where there is no other way to accomplish this --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 9cd5ad58c..c6ec060af 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -373,7 +373,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } } - $Text = str_replace(array('[baseurl]','[sitename]'),array(z_root(),get_config('system','sitename')),$Text); + $Text = str_replace(array('[baseurl]','[sitename]','[sitepath]'),array(z_root(),get_config('system','sitename'),$_SESSION['return_url']),$Text); // Replace any html brackets with HTML Entities to prevent executing HTML or script -- cgit v1.2.3 From 7c0101899da879dc52008bd9c0445d4a24ab9fcb Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 12 Feb 2014 13:45:11 -0800 Subject: another bbcode addition for the demo, however this one is potentially useful for other purposes --- include/bbcode.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index c6ec060af..630be0b89 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -373,6 +373,20 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } } + $channel = $a->get_channel(); + if (strpos($Text,'[/channel]') !== false) { + if ($channel) { + $Text = preg_replace("/\[channel\=1\](.*?)\[\/channel\]/ism", '$1', $Text); + $Text = preg_replace("/\[channel\=0\].*?\[\/channel\]/ism", '', $Text); + } else { + $Text = preg_replace("/\[channel\=1\].*?\[\/channel\]/ism", '', $Text); + $Text = preg_replace("/\[channel\=0\](.*?)\[\/channel\]/ism", '$1', $Text); + } + } + + + + $Text = str_replace(array('[baseurl]','[sitename]','[sitepath]'),array(z_root(),get_config('system','sitename'),$_SESSION['return_url']),$Text); -- cgit v1.2.3 From bff92e7a219341e69e2078e6b989ee58ba149ee3 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 12 Feb 2014 19:57:22 -0800 Subject: remove some obsolete bbcode tags --- include/bbcode.php | 95 +++++++++++++++++------------------------------------- 1 file changed, 30 insertions(+), 65 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 630be0b89..9d50cade2 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -320,15 +320,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $a = get_app(); - // Extract the private images which use data url's since preg has issues with - // large data sizes. Stash them away while we do bbcode conversion, and then put them back - // in after we've done all the regex matching. We cannot use any preg functions to do this. - - $extracted = bb_extract_images($Text); - $Text = $extracted['body']; - $saved_image = $extracted['images']; - - // Move all spaces out of the tags $Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text); $Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text); @@ -385,9 +376,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } - - - $Text = str_replace(array('[baseurl]','[sitename]','[sitepath]'),array(z_root(),get_config('system','sitename'),$_SESSION['return_url']),$Text); + $Text = str_replace(array('[baseurl]','[sitename]'),array(z_root(),get_config('system','sitename')),$Text); // Replace any html brackets with HTML Entities to prevent executing HTML or script @@ -697,37 +686,35 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } } // Youtube extensions - if (strpos($Text,'[youtube]') !== false) { - if ($tryoembed) { - $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); - $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); - $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text); - } - $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); - $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); - $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); - - if ($tryoembed) - $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text); - else - $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "http://www.youtube.com/watch?v=$1", $Text); - } - if (strpos($Text,'[vimeo]') !== false) { - if ($tryoembed) { - $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); - $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); - } - - $Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); - $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); - - if ($tryoembed) - $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '', $Text); - else - $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", "http://vimeo.com/$1", $Text); - } -// $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '', $Text); - +// if (strpos($Text,'[youtube]') !== false) { +// if ($tryoembed) { +// $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); +// $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); +// $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text); +// } +// $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); +// $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); +// $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); + +// if ($tryoembed) +// $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text); +// else +// $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "http://www.youtube.com/watch?v=$1", $Text); +// } +// if (strpos($Text,'[vimeo]') !== false) { +// if ($tryoembed) { +// $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); +// $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); +// } + +// $Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); +// $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); + +// if ($tryoembed) +// $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '', $Text); +// else +// $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", "http://vimeo.com/$1", $Text); +// } // oembed tag $Text = oembed_bbcode2html($Text); @@ -770,28 +757,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/\<(.*?)(src|href)=\"[^hfm](.*?)\>/ism",'<$1$2="">',$Text); - if($saved_image) - $Text = bb_replace_images($Text, $saved_image); - - // 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) {// -// $doc = new DOMDocument(); -// $doc->preserveWhiteSpace = false; - -// $Text = mb_convert_encoding($Text, 'HTML-ENTITIES', "UTF-8"); - -// $doctype = ''; -// @$doc->loadHTML($doctype."".$Text.""); - -// $Text = $doc->saveHTML(); -// $Text = str_replace(array("", "", $doctype), array("", "", ""), $Text); - -// $Text = str_replace('
  • ','', $Text); - -// $Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES'); -// } - call_hooks('bbcode',$Text); return $Text; -- cgit v1.2.3 From d4d44f9878b9eb0532c574d7d93229e7cb9920d9 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 12 Feb 2014 19:59:24 -0800 Subject: oops - still using the !@#$ youtube bbcodes --- include/bbcode.php | 58 +++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 9d50cade2..1969f8444 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -686,35 +686,35 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } } // Youtube extensions -// if (strpos($Text,'[youtube]') !== false) { -// if ($tryoembed) { -// $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); -// $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); -// $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text); -// } -// $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); -// $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); -// $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); - -// if ($tryoembed) -// $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text); -// else -// $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "http://www.youtube.com/watch?v=$1", $Text); -// } -// if (strpos($Text,'[vimeo]') !== false) { -// if ($tryoembed) { -// $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); -// $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); -// } - -// $Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); -// $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); - -// if ($tryoembed) -// $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '', $Text); -// else -// $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", "http://vimeo.com/$1", $Text); -// } + if (strpos($Text,'[youtube]') !== false) { + if ($tryoembed) { + $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); + $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text); + $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text); + } + $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); + $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); + $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); + + if ($tryoembed) + $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text); + else + $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "http://www.youtube.com/watch?v=$1", $Text); + } + if (strpos($Text,'[vimeo]') !== false) { + if ($tryoembed) { + $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); + $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); + } + + $Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); + $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); + + if ($tryoembed) + $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '', $Text); + else + $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", "http://vimeo.com/$1", $Text); + } // oembed tag $Text = oembed_bbcode2html($Text); -- cgit v1.2.3 From 44d7047fce57085fe63ad5e1088911e9fc07a32e Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 20 Feb 2014 21:15:35 -0800 Subject: SECURITY: do not automatically open an iframe which points into the local website. --- include/bbcode.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 1969f8444..8bbf7ae01 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -227,6 +227,13 @@ function bb_location($match) { // not yet implemented } +function bbiframe($match) { + $a = get_app(); + if(strpos($match[1],get_app()->get_hostname())) + return '' . $match[1] . ''; + return ''; +} + function bb_ShareAttributesSimple($match) { $attributes = $match[1]; @@ -677,7 +684,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { if ($tryoembed){ if (strpos($Text,'[/iframe]') !== false) { - $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '', $Text); + $Text = preg_replace_callback("/\[iframe\](.*?)\[\/iframe\]/ism", 'bbiframe', $Text); } } else { -- cgit v1.2.3 From 34fd387438f5f3d06b0a1c26d5c7ca5c1f5bd270 Mon Sep 17 00:00:00 2001 From: marijus Date: Mon, 10 Mar 2014 17:17:49 +0100 Subject: this commit is an attempt to make conv items better scalable on smaller screens. also save some horizontal space. --- include/bbcode.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 8bbf7ae01..cd0bf527e 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -46,7 +46,7 @@ function tryzrlvideo($match) { } if($zrl) $link = zid($link); - return ''; + return ''; } @@ -620,24 +620,24 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // [img=widthxheight]pathtoimage[/img] if (strpos($Text,'[/img]') !== false) { - $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); } if (strpos($Text,'[/zmg]') !== false) { - $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); } // [img=widthxheight float={left, right}]pathtoimage[/img] if (strpos($Text,'[/img]') !== false) { - $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*) float=left\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*) float=left\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); } if (strpos($Text,'[/img]') !== false) { - $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*) float=right\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*) float=right\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); } if (strpos($Text,'[/zmg]') !== false) { - $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*) float=left\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*) float=left\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); } if (strpos($Text,'[/zmg]') !== false) { - $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*) float=right\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*) float=right\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); } // style (sanitized) -- cgit v1.2.3 From ecb2e52a7411a8a39b8030964604f0f28f2facce Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 16 Mar 2014 20:34:21 -0700 Subject: little fixes of hopefully nil significance --- include/bbcode.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index cd0bf527e..c8d1ab425 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -229,9 +229,12 @@ function bb_location($match) { function bbiframe($match) { $a = get_app(); - if(strpos($match[1],get_app()->get_hostname())) - return '' . $match[1] . ''; - return ''; + + // use sandbox mode to prevent malicious goings on rather than host restriction + // if(strpos($match[1],get_app()->get_hostname())) + // return '' . $match[1] . ''; + + return ''; } function bb_ShareAttributesSimple($match) { -- cgit v1.2.3 From b00478d3b5e6d12e2c726fbdde931b5e64ad5da9 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 30 Mar 2014 15:01:51 -0700 Subject: revise the sandbox --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index c8d1ab425..6f6e43568 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -234,7 +234,7 @@ function bbiframe($match) { // if(strpos($match[1],get_app()->get_hostname())) // return '' . $match[1] . ''; - return ''; + return ''; } function bb_ShareAttributesSimple($match) { -- cgit v1.2.3 From 57a9ba4574e61a803c0a732135fe457733901850 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 31 Mar 2014 15:56:58 -0700 Subject: this is a mess and makes a complicated security model that one can probably drive a truck through. It will have to be fixed. It does make youtubes work again. --- include/bbcode.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 6f6e43568..96242fdac 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -230,11 +230,10 @@ function bb_location($match) { function bbiframe($match) { $a = get_app(); - // use sandbox mode to prevent malicious goings on rather than host restriction - // if(strpos($match[1],get_app()->get_hostname())) - // return '' . $match[1] . ''; - return ''; + $sandbox = ((strpos($match[1],get_app()->get_hostname())) ? ' sandbox="allow-scripts" ' : ''); + + return ''; } function bb_ShareAttributesSimple($match) { -- cgit v1.2.3 From bdbda6074cb3bc06b748a557b9c16f775ecc3508 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 5 May 2014 16:16:32 -0700 Subject: add message_id to reshared items so that we can eventually notify the original poster via an activity that their item was shared. --- include/bbcode.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 96242fdac..326676b72 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -200,6 +200,12 @@ function bb_ShareAttributes($match) { if ($matches[1] != "") $posted = $matches[1]; + $message_id = ""; + preg_match("/message_id='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $message_id = $matches[1]; + + // FIXME - this should really be a wall-item-ago so it will get updated on the client $reldate = (($posted) ? relative_date($posted) : ''); -- cgit v1.2.3 From 711719ce0ce340fbcda7559bf20582e85e4b1e3d Mon Sep 17 00:00:00 2001 From: root Date: Wed, 7 May 2014 12:01:12 -0700 Subject: Made some changes to img tags to enforce max-width everywhere, and to the page headers to allow user scaling. --- include/bbcode.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 326676b72..92d979638 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -606,24 +606,24 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Images // [img]pathtoimage[/img] if (strpos($Text,'[/img]') !== false) { - $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); } if (strpos($Text,'[/zmg]') !== false) { - $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); } // [img float={left, right}]pathtoimage[/img] if (strpos($Text,'[/img]') !== false) { - $Text = preg_replace("/\[img float=left\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[img float=left\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); } if (strpos($Text,'[/img]') !== false) { - $Text = preg_replace("/\[img float=right\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[img float=right\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); } if (strpos($Text,'[/zmg]') !== false) { - $Text = preg_replace("/\[zmg float=left\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[zmg float=left\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); } if (strpos($Text,'[/zmg]') !== false) { - $Text = preg_replace("/\[zmg float=right\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + $Text = preg_replace("/\[zmg float=right\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); } // [img=widthxheight]pathtoimage[/img] -- cgit v1.2.3 From 0e336fc09258e255d8bc01daad703cde11dbcad2 Mon Sep 17 00:00:00 2001 From: Michael Johnston Date: Sat, 10 May 2014 00:54:59 -0400 Subject: add support for h1, h2, etc. to bbcode --- include/bbcode.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 326676b72..17b25c206 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -507,6 +507,30 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism","$2",$Text); $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","$2",$Text); } + // Check for h1 + if (strpos($Text,'[h1]') !== false) { + $Text = preg_replace("(\[h1\](.*?)\[\/h1\])ism",'

    $1

    ',$Text); + } + // Check for h2 + if (strpos($Text,'[h2]') !== false) { + $Text = preg_replace("(\[h2\](.*?)\[\/h2\])ism",'

    $1

    ',$Text); + } + // Check for h3 + if (strpos($Text,'[h3]') !== false) { + $Text = preg_replace("(\[h3\](.*?)\[\/h3\])ism",'

    $1

    ',$Text); + } + // Check for h4 + if (strpos($Text,'[h4]') !== false) { + $Text = preg_replace("(\[h4\](.*?)\[\/h4\])ism",'

    $1

    ',$Text); + } + // Check for h5 + if (strpos($Text,'[h5]') !== false) { + $Text = preg_replace("(\[h5\](.*?)\[\/h5\])ism",'
    $1
    ',$Text); + } + // Check for h6 + if (strpos($Text,'[h6]') !== false) { + $Text = preg_replace("(\[h6\](.*?)\[\/h6\])ism",'
    $1
    ',$Text); + } // Check for centered text if (strpos($Text,'[/center]') !== false) { $Text = preg_replace("(\[center\](.*?)\[\/center\])ism","
    $1
    ",$Text); -- cgit v1.2.3 From 3f5852c30e9db9c1b62688db61a1756ffd7db1a7 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 10 May 2014 12:50:20 -0700 Subject: correct minor typo --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 96242fdac..526007306 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -63,7 +63,7 @@ function bb_spacefy($st) { } // The previously spacefied [noparse][ i ]italic[ /i ][/noparse], -// now turns back and the [noparse] tags are trimed +// now turns back and the [noparse] tags are trimmed // returning [i]italic[/i] function bb_unspacefy_and_trim($st) { -- cgit v1.2.3 From 466fe725bc056ad7ed2c3bf24783b65565293472 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 18 May 2014 18:21:20 -0700 Subject: start to build out the apps --- include/bbcode.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index a4e7560d6..674b5f45a 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -166,6 +166,15 @@ function bb_parse_crypt($match) { } +function bb_parse_app($match) { + require_once('include/apps.php'); + + $app = app_decode($match[1]); + if($app) + return app_render($app); + +} + function bb_qr($match) { return '' . t('QR code') . ''; } @@ -684,6 +693,11 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace_callback("/\[crypt (.*?)\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $Text); } + if(strpos($Text,'[/app]') !== false) { + $Text = preg_replace_callback("/\[app\](.*?)\[\/app\]/ism",'bb_parse_app', $Text); + } + + // html5 video and audio if (strpos($Text,'[/video]') !== false) { $Text = preg_replace_callback("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", 'tryzrlvideo', $Text); -- cgit v1.2.3 From 525daa7475f219f51258dcdb5ed634e7112020de Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 19 Jun 2014 20:38:38 -0700 Subject: fix space around brackets changing. --- include/bbcode.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 674b5f45a..60463fc00 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -344,9 +344,15 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $a = get_app(); - // Move all spaces out of the tags - $Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text); - $Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text); + // Move all spaces out of the tags + // ....Uhm why? + // This is basically doing a trim() on the stuff in between tags, but it messes up + // carefully crafted bbcode and especially other pre-formatted code. + // Commenting out until we come up with a use case where it's needed. Then let's try and + // special case rather than a heavy-handed approach like this. + +// $Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text); +// $Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text); // Hide all [noparse] contained bbtags by spacefying them if (strpos($Text,'[noparse]') !== false) { -- cgit v1.2.3