From 2337b075a8825920eb72bf3a2e9bd7609e163848 Mon Sep 17 00:00:00 2001
From: Cameron
Date: Fri, 5 Feb 2021 18:31:54 -0800
Subject: [PATCH] Fixes #4346 - TinyMce parser issue. Hide side-panel help icon
on legacy admin theme.
---
class2.php | 2 +-
.../shortcodes/batch/admin_shortcodes.php | 4 +
e107_handlers/bbcode_handler.php | 53 ++++++--
e107_handlers/e_parse_class.php | 5 +
e107_handlers/session_handler.php | 2 +-
e107_plugins/tinymce4/plugins/e107/parser.php | 97 +++++---------
e107_tests/tests/unit/e_bbcodeTest.php | 33 ++++-
.../unit/plugins/e107TinyMceParserTest.php | 118 ++++++++++++++++--
8 files changed, 224 insertions(+), 90 deletions(-)
diff --git a/class2.php b/class2.php
index c9da5c827..0b27ffae0 100755
--- a/class2.php
+++ b/class2.php
@@ -83,7 +83,7 @@ if(!empty($_E107['minimal']))
$_E107['no_maintenance'] = true;
$_E107['no_forceuserupdate'] = true;
$_E107['no_event'] = true;
- $_E107['no_session'] = true;
+// $_E107['no_session'] = true;
// $_E107['no_parser'] = true;
$_E107['no_override'] = true;
$_E107['no_log'] = true;
diff --git a/e107_core/shortcodes/batch/admin_shortcodes.php b/e107_core/shortcodes/batch/admin_shortcodes.php
index d6d55b067..d958856b3 100644
--- a/e107_core/shortcodes/batch/admin_shortcodes.php
+++ b/e107_core/shortcodes/batch/admin_shortcodes.php
@@ -2658,6 +2658,10 @@ Inverse 10 10
*/
private function renderHelpIcon()
{
+ if(deftrue('THEME_STYLE') !== 'css/modern-light.css' && deftrue('THEME_STYLE') !=='css/modern-dark.css')
+ {
+ return null;
+ }
$text = '
diff --git a/e107_handlers/bbcode_handler.php b/e107_handlers/bbcode_handler.php
index 9811fb202..5f8971906 100644
--- a/e107_handlers/bbcode_handler.php
+++ b/e107_handlers/bbcode_handler.php
@@ -831,10 +831,35 @@ class e_bbcode
*/
function htmltoBBcode($text)
{
-
-
+ $allowedTags = array('html', 'body','div', 'a', 'img', 'table', 'thead', 'tbody', 'tr', 'td', 'th', 'b',
+ 'i', 'pre', 'code', 'strong', 'u', 'em', 'ul', 'ol', 'li', 'h2', 'h3', 'h4', 'h5', 'h6', 'p',
+ 'blockquote', /*'audio', 'video',*/ 'br', 'small'
+ );
+
+ $allowedAttributes = array(
+ 'default' => array(),
+ 'img' => array('src', 'alt', 'width', 'height'),
+ 'a' => array('href', 'target', 'rel'),
+ 'audio' => array('src', 'controls', 'autoplay', 'loop', 'muted', 'preload'),
+ 'video' => array('autoplay', 'controls', 'height', 'loop', 'muted', 'poster', 'preload', 'src', 'width'),
+ 'td' => array('colspan', 'rowspan'),
+ 'th' => array('colspan', 'rowspan'),
+ 'x-bbcode' => array('alt'),
+ );
+
+
+ $tp = e107::getParser();
+ $tp->setAllowedTags($allowedTags);
+ $tp->setAllowedAttributes($allowedAttributes);
+ $tp->setScriptAttibutes(null);
+
+ $text = $tp->cleanHtml($text);
+
+ $tp->init(); // reset to default; // FIXME needs to reset the above values to default.
+
$text = str_replace("","[html]",$text);
$text = str_replace("","[/html]",$text);
+
// $text = str_replace('',"[newpage=]",$text);
@@ -891,10 +916,16 @@ class e_bbcode
// Mostly closing tags.
- $convert = array(
+ $convert = array(
+
array( "\n", '
'),
// array( "\n", ''),
array( "\n", "
\n"),
+ array( "", "\n"),
+ array( "", "\t"),
+ array( "", "
\n"),
+ array( "\n", "\n"),
+ array( "\n", "\n"),
array( "\n", "
"),
array( "[/list]", '\n'),
array( "[/list]", ''),
@@ -906,14 +937,22 @@ class e_bbcode
array( "[h=3]", ''), // e107 bbcode markup
array( "[h=3]", ''),
array( "[/h]", '
'),
+ array( "[h=4]", ''),
+ array( "[/h]", '
'),
+ array( "[h=5]", ''),
+ array( "[/h]", '
'),
+ array( "[h=6]", ''),
+ array( "[/h]", '
'),
array( "[/b]", ''),
array( "[/i]", ''),
array( "[/block]", ''),
- array( "[/table]", ''),
- array( "[/tbody]", ''),
+ array( "[/table]", ''),
+ array( "[/tbody]", ''),
array( "[/code]\n", ''),
- array( "[/tr]", ''),
- array( "[/td]", ''),
+ array( "[/tr]", ''),
+ array( "[/td]", ''),
+ array( "[td]", ''),
+ array( "[/td]", ' | '),
array( "[/blockquote]",''),
array( "]", ' style=]')
diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php
index 99b382437..4973d6e6b 100644
--- a/e107_handlers/e_parse_class.php
+++ b/e107_handlers/e_parse_class.php
@@ -3457,6 +3457,11 @@ class e_parse
$this->scriptAccess = $val;
}
+ public function setScriptAttibutes($arr)
+ {
+ $this->scriptAttributes = (array) $arr;
+ }
+
public function getAllowedTags()
{
diff --git a/e107_handlers/session_handler.php b/e107_handlers/session_handler.php
index a254a08d3..2ae965058 100644
--- a/e107_handlers/session_handler.php
+++ b/e107_handlers/session_handler.php
@@ -990,7 +990,7 @@ class e_core_session extends e_session
return false;
}
- $this->log('Session Token Okay!', E_LOG_NOTICE);
+ $this->log('Session Token Okay!', defset('E_LOG_NOTICE', 1));
}
diff --git a/e107_plugins/tinymce4/plugins/e107/parser.php b/e107_plugins/tinymce4/plugins/e107/parser.php
index f4407e729..d2f725c61 100644
--- a/e107_plugins/tinymce4/plugins/e107/parser.php
+++ b/e107_plugins/tinymce4/plugins/e107/parser.php
@@ -7,23 +7,26 @@
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*/
-
if(empty($_POST['content']) && empty($_GET['debug']) && !defined('TINYMCE_DEBUG') && !defined('TINYMCE_UNIT_TEST'))
{
header('Content-Length: 0');
exit;
}
-$_E107['no_online'] = true;
-$_E107['no_menus'] = true;
-$_E107['no_forceuserupdate'] = true;
-$_E107['no_maintenance'] = true;
-$_E107['minimal'] = true;
+if(!defined('e_ADMIN_AREA'))
+{
+ define('e_ADMIN_AREA', true);
+}
-if (!defined('e_ADMIN_AREA')) define('e_ADMIN_AREA', true);
if(!defined('TINYMCE_DEBUG') && !defined('TINYMCE_UNIT_TEST'))
{
- require_once("../../../../class2.php");
+ $_E107['no_online'] = true;
+ $_E107['no_menus'] = true;
+ $_E107['no_forceuserupdate'] = true;
+ $_E107['no_maintenance'] = true;
+ $_E107['minimal'] = true;
+
+ require_once(__DIR__."/../../../../class2.php");
}
/**
@@ -35,15 +38,14 @@ if(!defined('TINYMCE_DEBUG') && !defined('TINYMCE_UNIT_TEST'))
*/
class e107TinyMceParser
{
-
protected $gzipCompression = false;
+ protected $postHtmlClass;
- /**
- *
- */
function __construct()
{
- $_POST['mode'] = isset($_POST['mode']) ? $_POST['mode'] : 'tohtml';
+ $this->postHtmlClass = (int) e107::getPref('post_html', e_UC_NOBODY);
+
+ $mode = isset($_POST['mode']) ? $_POST['mode'] : 'tohtml';
$_POST['content'] = isset($_POST['content']) ? $_POST['content'] : '';
$html = '';
@@ -80,24 +82,16 @@ TEMPL;
$debug = false;
}
- if($_POST['mode'] == 'tohtml')
+ if($mode === 'tohtml')
{
$html = $this->toHTML($_POST['content']);
}
-
- if($_POST['mode'] == 'tobbcode')
+ elseif($mode === 'tobbcode')
{
- $html = $this->toBBcode($_POST['content']);
+ $html = $this->toDB($_POST['content']);
}
- if($debug == true)
- {
- print_a($html);
- echo "
";
- echo "Rendered
";
- echo $html;
- }
- elseif($this->gzipCompression == true)
+ if($this->gzipCompression == true)
{
header('Content-Encoding: gzip');
$gzipoutput = gzencode($html,6);
@@ -111,12 +105,14 @@ TEMPL;
}
+ public function setHtmlClass($value)
+ {
+ $this->postHtmlClass = (int) $value;
+ }
public function toHTML($content)
{
- // global $pref; //XXX faster?
- $pref = e107::getPref();
$tp = e107::getParser();
// XXX @Cam possible fix - convert to BB first, see news admin AJAX request/response values for reference why
$content = stripslashes($content);
@@ -124,11 +120,8 @@ TEMPL;
// $content = e107::getBB()->htmltoBBcode($content); //XXX This breaks inserted images from media-manager. :/
e107::getBB()->setClass($this->getMediaCategory());
- if(check_class($pref['post_html'])) // raw HTML within [html] tags.
+ if(check_class($this->postHtmlClass)) // raw HTML within [html] tags.
{
-
- // $content = $tp->replaceConstants($content,'abs');
-
if(strpos($content,"[html]") === false) // BC - convert old BB code text to html.
{
e107::getBB()->clearClass();
@@ -147,22 +140,7 @@ TEMPL;
$content = $tp->parseBBTags($content,true); // parse the tag so we see the HTML equivalent while editing!
$content = e107::getBB()->parseBBCodes($content);
-
- if(!empty($content) && E107_DEBUG_LEVEL > 0)
- {
- // $content = "-- DEBUG MODE ACTIVE -- \n".$content;
- // echo htmlentities($content)."\n";
- // echo "".$content."
";
- $text = $content;
- return $text;
- // exit;
- }
- else
- {
- $text = $content;
- }
-
-
+ $text = $content;
}
else // bbcode Mode.
@@ -176,12 +154,6 @@ TEMPL;
$content = str_replace(e_MEDIA_IMAGE,"{e_MEDIA_IMAGE}",$content);
$text = "";
- if(!empty($content) && E107_DEBUG_LEVEL > 0)
- {
- $text .= "";
- //print_r(htmlentities($content))."\n";
- //exit;
- }
$text .= $content;
}
@@ -193,37 +165,26 @@ TEMPL;
- function toBBcode($content)
+ function toDB($content)
{
- // echo $_POST['content'];
- // global $pref;
- $pref = e107::getPref();
- // $tp = e107::getParser();
-
e107::getBB()->setClass($this->getMediaCategory());
$content = stripslashes($content);
- if(check_class($pref['post_html'])) // Plain HTML mode.
+ if(check_class($this->postHtmlClass)) // Plain HTML mode.
{
-
$content = trim($content);
- // $content = $this->updateImg($content);
$content = e107::getBB()->imgToBBcode($content);
- // $content = $tp->parseBBTags($content,true); // replace html with bbcode equivalent
if(strip_tags($content, '') == ' ') // Avoid this: [html]
[/html]
{
exit;
}
- $text = $content ? "[html]".$content."[/html]" : ""; // Add the tags before saving to DB.
+ $text = !empty($content) ? "[html]".$content."[/html]" : ''; // Add the tags before saving to DB.
}
- else // bbcode Mode. //XXX Disabled at the moment in tinymce/e_meta.php - post_html is required to activate.
+ else // User doesn't have HTML access - bbcode Mode.
{
- // [img width=400]/e107_2.0/thumb.php?src={e_MEDIA_IMAGE}2012-12/e107org_white_stripe.png&w=400&h=0[/img]
- // $content = str_replace("{e_BASE}","", $content); // We want {e_BASE} in the final data going to the DB, but not the editor.
-
$text = e107::getBB()->htmltoBBcode($content); // not reliable enough yet.
}
diff --git a/e107_tests/tests/unit/e_bbcodeTest.php b/e107_tests/tests/unit/e_bbcodeTest.php
index 5eee22222..9090ea2f1 100644
--- a/e107_tests/tests/unit/e_bbcodeTest.php
+++ b/e107_tests/tests/unit/e_bbcodeTest.php
@@ -13,7 +13,7 @@
{
/** @var e_bbcode */
- protected $bb;
+ protected e_bbcode $bb;
protected function _before()
{
@@ -47,12 +47,39 @@
{
}
-
+*/
public function testHtmltoBBcode()
{
+ $text = 'Heading 1
+Heading 2
+Heading 3
+Heading 4
+Heading 5
+Heading 6
+
+
Paragraph.
+
+
+
+
+
+
+Column 1 | Column 2 |
+
+
+ link | |
+
+
+
';
+
+ $result = $this->bb->htmltoBbcode($text);
+
+ $expected = strip_tags($result);
+
+ $this->assertSame($expected, $result);
}
-
+/*
public function testImgToBBcode()
{
diff --git a/e107_tests/tests/unit/plugins/e107TinyMceParserTest.php b/e107_tests/tests/unit/plugins/e107TinyMceParserTest.php
index 59aafe0c7..e996c3ddb 100644
--- a/e107_tests/tests/unit/plugins/e107TinyMceParserTest.php
+++ b/e107_tests/tests/unit/plugins/e107TinyMceParserTest.php
@@ -76,8 +76,10 @@ Plain text paragraph 3
';
/**
* Test parsing of input from user via TinyMce.
*/
- public function testToBBcode()
+ public function testToDB()
{
+ $this->tm->setHtmlClass(e_UC_ADMIN);
+
$test_1 = '