aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/bbcode.php79
-rw-r--r--include/html2bbcode.php30
2 files changed, 72 insertions, 37 deletions
diff --git a/include/bbcode.php b/include/bbcode.php
index 87c09a775..aa1257a56 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -1055,6 +1055,15 @@ function bb_fixtable_lf($match) {
}
+function bb_fix_lf($match) {
+ // remove extraneous whitespace between element tags since newlines will all
+ // be converted to '<br />' and turn your neatly crafted tables into a whole lot of
+ // empty space.
+
+ $new_content = str_replace(["\n\r", "\n", "\r"], '', $match[1]);
+ return str_replace($match[1], $new_content, $match[0]);
+}
+
function bbtopoll($s) {
$pl = [];
@@ -1208,8 +1217,6 @@ function bbcode($text, $options = []) {
}
}
-
-
$text = bb_format_attachdata($text);
// If we find any event code, turn it into an event.
@@ -1250,7 +1257,7 @@ function bbcode($text, $options = []) {
$text = str_replace("<", "&lt;", $text);
$text = str_replace(">", "&gt;", $text);
- $text = preg_replace_callback("/\[table\](.*?)\[\/table\]/ism",'bb_fixtable_lf',$text);
+
$text = str_replace(array("\t", " "), array("&nbsp;&nbsp;&nbsp;&nbsp;", "&nbsp;&nbsp;"), $text);
// Check for [code] text here, before the linefeeds are messed with.
@@ -1434,32 +1441,32 @@ function bbcode($text, $options = []) {
// Check for h1
if (strpos($text,'[h1]') !== false) {
$text = preg_replace("(\[h1\](.*?)\[\/h1\])ism",'<h1>$1</h1>',$text);
- $text = str_replace(["</h1>\n\n", "</h1>\n"], '</h1>', $text);
+ $text = str_replace(["</h1>\r", "</h1>\n"], '</h1>', $text);
}
// Check for h2
if (strpos($text,'[h2]') !== false) {
$text = preg_replace("(\[h2\](.*?)\[\/h2\])ism",'<h2>$1</h2>',$text);
- $text = str_replace(["</h2>\n\n", "</h2>\n"], '</h2>', $text);
+ $text = str_replace(["</h2>\r", "</h2>\n"], '</h2>', $text);
}
// Check for h3
if (strpos($text,'[h3]') !== false) {
$text = preg_replace("(\[h3\](.*?)\[\/h3\])ism",'<h3>$1</h3>',$text);
- $text = str_replace(["</h3>\n\n", "</h3>\n"], '</h3>', $text);
+ $text = str_replace(["</h3>\r", "</h3>\n"], '</h3>', $text);
}
// Check for h4
if (strpos($text,'[h4]') !== false) {
$text = preg_replace("(\[h4\](.*?)\[\/h4\])ism",'<h4>$1</h4>',$text);
- $text = str_replace(["</h4>\n\n", "</h4>\n"], '</h4>', $text);
+ $text = str_replace(["</h4>\r", "</h4>\n"], '</h4>', $text);
}
// Check for h5
if (strpos($text,'[h5]') !== false) {
$text = preg_replace("(\[h5\](.*?)\[\/h5\])ism",'<h5>$1</h5>',$text);
- $text = str_replace(["</h5>\n\n", "</h5>\n"], '</h5>', $text);
+ $text = str_replace(["</h5>\r", "</h5>\n"], '</h5>', $text);
}
// Check for h6
if (strpos($text,'[h6]') !== false) {
$text = preg_replace("(\[h6\](.*?)\[\/h6\])ism",'<h6>$1</h6>',$text);
- $text = str_replace(["</h6>\n\n", "</h6>\n"], '</h6>', $text);
+ $text = str_replace(["</h6>\r", "</h6>\n"], '</h6>', $text);
}
// Check for table of content without params
@@ -1488,10 +1495,10 @@ function bbcode($text, $options = []) {
// Check for list text
- $text = preg_replace("/<br \/>\[\*\]/ism",'[*]',$text);
-
+ $text = str_replace(["\r\n[*]", "\r[*]", "\n[*]"], "[*]", $text);
$text = str_replace("[*]", "<li>", $text);
+
// handle nested lists
$endlessloop = 0;
@@ -1500,16 +1507,37 @@ function bbcode($text, $options = []) {
((strpos($text, "[/ul]") !== false) && (strpos($text, "[ul]") !== false)) ||
((strpos($text, "[/dl]") !== false) && (strpos($text, "[dl") !== false)) ||
((strpos($text, "[/li]") !== false) && (strpos($text, "[li]") !== false))) && (++$endlessloop < 20)) {
+
+ $text = str_replace(["[/list]\r", "[/list]\n"], '[/list]', $text);
+
+ $text = preg_replace_callback("/\[list\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
$text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '<ul class="listbullet">$1</ul>', $text);
+
+ $text = preg_replace_callback("/\[list=\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
$text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>', $text);
- $text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $text);
- $text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'<ul class="listlowerroman" style="list-style-type: lower-roman;">$2</ul>', $text);
- $text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '<ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul>', $text);
- $text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul>', $text);
- $text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul>', $text);
+
+ $text = preg_replace_callback("/\[list=1\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
+ $text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '<ol class="listdecimal" style="list-style-type: decimal;">$1</ol>', $text);
+
+ $text = preg_replace_callback("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
+ $text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'<ol class="listlowerroman" style="list-style-type: lower-roman;">$2</ol>', $text);
+
+ $text = preg_replace_callback("/\[list=((?-i)I)\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
+ $text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '<ol class="listupperroman" style="list-style-type: upper-roman;">$2</ol>', $text);
+
+ $text = preg_replace_callback("/\[list=((?-i)a)\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
+ $text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '<ol class="listloweralpha" style="list-style-type: lower-alpha;">$2</ol>', $text);
+
+ $text = preg_replace_callback("/\[list=((?-i)A)\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
+ $text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '<ol class="listupperalpha" style="list-style-type: upper-alpha;">$2</ol>', $text);
+
+ $text = preg_replace_callback("/\[ol\](.*?)\[\/ol\]/ism",'bb_fix_lf', $text);
+ $text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '<ol class="listdecimal" style="list-style-type: decimal;">$1</ol>', $text);
+
+ $text = preg_replace_callback("/\[ul\](.*?)\[\/ul\]/ism",'bb_fix_lf', $text);
$text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '<ul class="listbullet">$1</ul>', $text);
- $text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $text);
- $text = preg_replace("/\[\/li\]<br \/>\[li\]/ism",'[/li][li]',$text);
+
+ $text = preg_replace("/\[\/li\]<br \/>\[li\]/ism",'[/li][li]', $text);
$text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '<li>$1</li>', $text);
// [dl] tags have an optional [dl terms="bi"] form where bold/italic/underline/mono/large
@@ -1522,24 +1550,29 @@ function bbcode($text, $options = []) {
}
if (strpos($text,'[checklist]') !== false) {
+ $text = preg_replace_callback("/\[checklist\](.*?)\[\/checklist\]/ism",'bb_fix_lf', $text);
$text = preg_replace_callback("/\[checklist\](.*?)\[\/checklist\]/ism", 'bb_checklist', $text);
}
if (strpos($text,'[th]') !== false) {
$text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '<th>$1</th>', $text);
}
+
if (strpos($text,'[td]') !== false) {
$text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '<td>$1</td>', $text);
}
+
if (strpos($text,'[tr]') !== false) {
$text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '<tr>$1</tr>', $text);
}
+
if (strpos($text,'[/table]') !== false) {
+ $text = preg_replace_callback("/\[table\](.*?)\[\/table\]/ism",'bb_fix_lf',$text);
$text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '<table>$1</table>', $text);
$text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '<table class="table table-responsive table-bordered" >$1</table>', $text);
$text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '<table class="table table-responsive" >$1</table>', $text);
}
- $text = str_replace('</tr><br /><tr>', "</tr>\n<tr>", $text);
+
$text = str_replace('[hr]', '<hr />', $text);
// This is actually executed in prepare_body()
@@ -1699,10 +1732,12 @@ function bbcode($text, $options = []) {
}
// oembed tag
- $text = oembed_bbcode2html($text);
+ if (strpos($text,'[/embed]') !== false) {
+ $text = oembed_bbcode2html($text);
- // Avoid triple linefeeds through oembed
- $text = str_replace("<br style='clear:left'></span><br /><br />", "<br style='clear:left'></span><br />", $text);
+ // Avoid triple linefeeds through oembed
+ $text = str_replace("<br style='clear:left'></span><br /><br />", "<br style='clear:left'></span>", $text);
+ }
// If we found an event earlier, strip out all the event code and replace with a reformatted version.
// Replace the event-start section with the entire formatted event. The other bbcode is stripped.
diff --git a/include/html2bbcode.php b/include/html2bbcode.php
index 009c051e6..03e09cd62 100644
--- a/include/html2bbcode.php
+++ b/include/html2bbcode.php
@@ -187,25 +187,24 @@ function html2bbcode($message)
node2bbcode($doc, 'u', array(), '[u]', '[/u]');
node2bbcode($doc, 's', array(), '[s]', '[/s]');
node2bbcode($doc, 'mark', array(), '[mark]', '[/mark]');
+ node2bbcode($doc, 'span', array(), "", "");
node2bbcode($doc, 'big', array(), "[size=large]", "[/size]");
node2bbcode($doc, 'small', array(), "[size=small]", "[/size]");
- node2bbcode($doc, 'blockquote', array(), '[quote]', '[/quote]');
-
// Use a temporary tag to keep line breaks
node2bbcode($doc, 'br', array(), '[br]', '');
node2bbcode($doc, 'a', array('href'=>'/(.+)/'), '[url=$1]', '[/url]');
- node2bbcode($doc, 'p', array('class'=>'MsoNormal'), "\n", "");
- node2bbcode($doc, 'div', array('class'=>'MsoNormal'), "\r", "");
+ node2bbcode($doc, 'img', array('src'=>'/(.+)/', 'width'=>'/(\d+)/', 'height'=>'/(\d+)/'), '[img=$2x$3]$1', '[/img]');
+ node2bbcode($doc, 'img', array('src'=>'/(.+)/', 'alt'=>'/(.+)/'), '[img=$1]$2', '[/img]');
+ node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '[img]$1', '[/img]');
- node2bbcode($doc, 'span', array(), "", "");
+ node2bbcode($doc, 'video', array('src'=>'/(.+)/'), '[video]$1', '[/video]');
+ node2bbcode($doc, 'audio', array('src'=>'/(.+)/'), '[audio]$1', '[/audio]');
+// node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), '[iframe]$1', '[/iframe]');
- node2bbcode($doc, 'pre', array(), "", "");
- node2bbcode($doc, 'div', array(), "\r", "\r");
- node2bbcode($doc, 'p', array(), "\n", "\n");
node2bbcode($doc, 'ul', array(), "[list]", "[/list]");
node2bbcode($doc, 'ol', array(), "[list=1]", "[/list]");
@@ -229,18 +228,19 @@ function html2bbcode($message)
node2bbcode($doc, 'h5', array(), "[h5]", "[/h5]");
node2bbcode($doc, 'h6', array(), "[h6]", "[/h6]");
- node2bbcode($doc, 'img', array('src'=>'/(.+)/', 'width'=>'/(\d+)/', 'height'=>'/(\d+)/'), '[img=$2x$3]$1', '[/img]');
- node2bbcode($doc, 'img', array('src'=>'/(.+)/', 'alt'=>'/(.+)/'), '[img=$1]$2', '[/img]');
- node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '[img]$1', '[/img]');
-
- node2bbcode($doc, 'video', array('src'=>'/(.+)/'), '[video]$1', '[/video]');
- node2bbcode($doc, 'audio', array('src'=>'/(.+)/'), '[audio]$1', '[/audio]');
-// node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), '[iframe]$1', '[/iframe]');
+ node2bbcode($doc, 'blockquote', array(), '[quote]', '[/quote]');
+ node2bbcode($doc, 'pre', array(), "", "");
node2bbcode($doc, 'code', array('class'=>'/(.+)/'), '[code=$1]', '[/code]');
node2bbcode($doc, 'code', array(), '[code]', '[/code]');
+ node2bbcode($doc, 'p', array('class'=>'MsoNormal'), "\n", "");
+ node2bbcode($doc, 'p', array(), "\n", "\n");
+
+ node2bbcode($doc, 'div', array('class'=>'MsoNormal'), "\r", "");
+ node2bbcode($doc, 'div', array(), "\r", "\r");
+
$message = $doc->saveHTML();
// I'm removing the UTF-8 encoding of a NO-BREAK SPACE codepoint