1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-03 05:07:27 +02:00

Experimental: Insert e107 BBcodes using TinyMce (Insert Menu)

This commit is contained in:
Cameron
2017-12-14 17:44:29 -08:00
parent 8dee70cef5
commit bad3a54eee
3 changed files with 52 additions and 22 deletions

View File

@@ -3621,7 +3621,7 @@ class e_parser
'th' => array('id', 'style', 'class', 'colspan', 'rowspan'), 'th' => array('id', 'style', 'class', 'colspan', 'rowspan'),
'col' => array('id', 'span', 'class','style'), 'col' => array('id', 'span', 'class','style'),
'embed' => array('id', 'src', 'style', 'class', 'wmode', 'type', 'title', 'width', 'height'), 'embed' => array('id', 'src', 'style', 'class', 'wmode', 'type', 'title', 'width', 'height'),
'x-bbcode' => array('alt'),
); );
protected $badAttrValues = array('javascript[\s]*?:','alert\(','vbscript[\s]*?:','data:text\/html', 'mhtml[\s]*?:', 'data:[\s]*?image'); protected $badAttrValues = array('javascript[\s]*?:','alert\(','vbscript[\s]*?:','data:text\/html', 'mhtml[\s]*?:', 'data:[\s]*?image');
@@ -3633,7 +3633,7 @@ class e_parser
protected $allowedTags = array('html', 'body','div','a','img','table','tr', 'td', 'th', 'tbody', 'thead', 'colgroup', 'b', protected $allowedTags = array('html', 'body','div','a','img','table','tr', 'td', 'th', 'tbody', 'thead', 'colgroup', 'b',
'i', 'pre','code', 'strong', 'u', 'em','ul', 'ol', 'li','img','h1','h2','h3','h4','h5','h6','p', 'i', 'pre','code', 'strong', 'u', 'em','ul', 'ol', 'li','img','h1','h2','h3','h4','h5','h6','p',
'div','pre','section','article', 'blockquote','hgroup','aside','figure','figcaption', 'abbr','span', 'audio', 'video', 'br', 'div','pre','section','article', 'blockquote','hgroup','aside','figure','figcaption', 'abbr','span', 'audio', 'video', 'br',
'small', 'caption', 'noscript', 'hr', 'section', 'iframe', 'sub', 'sup', 'cite' 'small', 'caption', 'noscript', 'hr', 'section', 'iframe', 'sub', 'sup', 'cite', 'x-bbcode'
); );
protected $scriptTags = array('script','applet','form','input','button', 'embed', 'object', 'ins', 'select','textarea'); //allowed when $pref['post_script'] is enabled. protected $scriptTags = array('script','applet','form','input','button', 'embed', 'object', 'ins', 'select','textarea'); //allowed when $pref['post_script'] is enabled.
@@ -4654,29 +4654,31 @@ class e_parser
/** /**
* Parse new <bbcode> tags into bbcode output. * Parse new <x-bbcode> tags into bbcode output.
* @param $retainTags : when you want to replace html and retain the <bbcode> tags wrapping it. * @param bool $retainTags : when you want to replace html and retain the <bbcode> tags wrapping it.
* @return html * @return string html
*/ */
function parseBBTags($text,$retainTags = false) function parseBBTags($text,$retainTags = false)
{ {
$bbcodes = $this->getTags($text, 'bbcode'); $stext = str_replace("&quot;", '"', $text);
$bbcodes = $this->getTags($stext, 'x-bbcode');
foreach($bbcodes as $v) foreach($bbcodes as $v)
{ {
foreach($v as $val) foreach($v as $val)
{ {
$tag = urldecode($val['alt']); $tag = base64_decode($val['alt']);
$repl = ($retainTags == true) ? '$1'.$tag.'$2' : $tag; $repl = ($retainTags == true) ? '$1'.$tag.'$2' : $tag;
$text = preg_replace('/(<bbcode[^>]*>).*(<\/bbcode>)/s',$repl, $text); //FIXME - handle multiple instances of bbcodes. $text = preg_replace('/(<x-bbcode[^>]*>).*(<\/x-bbcode>)/i',$repl, $text);
} }
} }
return $text; return $text;
} }
/** /**
* Perform and render XSS Test Comparison * Perform and render XSS Test Comparison
*/ */
@@ -5044,7 +5046,7 @@ return;
} }
$tag = preg_replace('/([a-z0-9\[\]\/]*)?\/([\w]*)(\[(\d)*\])?$/i', "$2", $path); $tag = preg_replace('/([a-z0-9\[\]\/]*)?\/([\w\-]*)(\[(\d)*\])?$/i', "$2", $path);
if(!in_array($tag, $this->allowedTags)) if(!in_array($tag, $this->allowedTags))
{ {

View File

@@ -135,7 +135,9 @@ TEMPL;
$content = str_replace("{e_BASE}",e_HTTP,$content); // We want {e_BASE} in the final data going to the DB, but not the editor. $content = str_replace("{e_BASE}",e_HTTP,$content); // We want {e_BASE} in the final data going to the DB, but not the editor.
$srch = array("<!-- bbcode-html-start -->","<!-- bbcode-html-end -->","[html]","[/html]"); $srch = array("<!-- bbcode-html-start -->","<!-- bbcode-html-end -->","[html]","[/html]");
$content = str_replace($srch,"",$content); $content = str_replace($srch,"",$content);
$content = e107::getBB()->parseBBCodes($content); // parse the <bbcode> tag so we see the HTML equivalent while editing! $content = $tp->parseBBTags($content,true); // parse the <bbcode> tag so we see the HTML equivalent while editing!
$content = e107::getBB()->parseBBCodes($content);
if(!empty($content) && E107_DEBUG_LEVEL > 0) if(!empty($content) && E107_DEBUG_LEVEL > 0)
{ {
@@ -204,7 +206,7 @@ TEMPL;
// $content = preg_replace($psrch, $prepl, $content); // $content = preg_replace($psrch, $prepl, $content);
$content = $this->updateImg($content); $content = $this->updateImg($content);
$content = $tp->parseBBTags($content,true); // replace html with bbcode equivalent // $content = $tp->parseBBTags($content,true); // replace html with bbcode equivalent
if(strip_tags($content, '<i>') == '&nbsp;') // Avoid this: [html]<p>&nbsp;</p>[/html] if(strip_tags($content, '<i>') == '&nbsp;') // Avoid this: [html]<p>&nbsp;</p>[/html]
{ {

View File

@@ -49,29 +49,55 @@
}); });
/*
// Emoticons // Emoticons
ed.addButton('e107-bbcode', { // ed.addButton('e107-bbcode', {
text: 'bbcode', ed.addMenuItem('e107-bbcode', {
icon: 'emoticons', text: 'e107 BBcode',
context: 'insert',
icon: 'code',
onclick: function() { onclick: function() {
// Open window // Open window
ed.windowManager.open({ ed.windowManager.open({
title: 'Example plugin', title: 'Insert e107 BBcode',
body: [ body: [
{type: 'textbox', name: 'code', label: 'BbCode'}, {type: 'textbox', name: 'code', label: 'BbCode', text: 'widget', size: 80, tooltip: 'eg. [b]bold[/b]', autofocus: true} //,
{type: 'textbox', name: 'parm', label: 'Parameters'} // {type: 'textbox', name: 'parm', label: 'Parameters'}
], ],
onsubmit: function(e) { onsubmit: function(e) {
s = e.data.code;
s = s.trim(s);
var html = $.ajax({
type: 'POST',
url: url +'/parser.php',
data: { content: s, mode: 'tohtml' },
async : false,
dataType: 'html',
success: function(html) {
return html;
}
}).responseText;
html = '<x-bbcode alt=\"'+btoa(s)+'\">' + html + '</x-bbcode> ' ;
// Insert content when the window form is submitted // Insert content when the window form is submitted
ed.insertContent('Title: ' + e.data.title); // console.log(url);
// console.log(html);
ed.insertContent(html);
} }
}); });
} }
}); });
*/
// Media Manager Button // Media Manager Button
ed.addButton('e107-image', { ed.addButton('e107-image', {
text: '', text: '',