mirror of
https://github.com/e107inc/e107.git
synced 2025-08-07 15:16:30 +02:00
Wysiwyg bbcode-selection and introduction of <bbcode> tag for conversion of bbcodes within html.
This commit is contained in:
@@ -1421,14 +1421,15 @@ class e_parse extends e_parser
|
|||||||
|
|
||||||
case 'html' : // This overrides and deprecates html.bb
|
case 'html' : // This overrides and deprecates html.bb
|
||||||
$proc_funcs = TRUE;
|
$proc_funcs = TRUE;
|
||||||
$convertNL = FALSE;
|
$noBreak = TRUE;
|
||||||
$code_text = str_replace("\r\n", " ", $code_text);
|
// $code_text = str_replace("\r\n", " ", $code_text);
|
||||||
$code_text = html_entity_decode($code_text, ENT_QUOTES, CHARSET);
|
$code_text = html_entity_decode($code_text, ENT_QUOTES, CHARSET);
|
||||||
$html_start = "<!-- bbcode-html-start -->"; // markers for html-to-bbcode replacement.
|
$html_start = "<!-- bbcode-html-start -->"; // markers for html-to-bbcode replacement.
|
||||||
$html_end = "<!-- bbcode-html-end -->";
|
$html_end = "<!-- bbcode-html-end -->";
|
||||||
$full_text = str_replace(array("[html]","[/html]"), "",$code_text); // quick fix.. security issue?
|
$full_text = str_replace(array("[html]","[/html]"), "",$code_text); // quick fix.. security issue?
|
||||||
$full_text =$this->replaceConstants($full_text,'abs');
|
$full_text =$this->replaceConstants($full_text,'abs');
|
||||||
$full_text = $html_start.$full_text.$html_end;
|
$full_text = $html_start.$full_text.$html_end;
|
||||||
|
$full_text = $this->parseBBTags($full_text); // strip <bbcode> tags.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'table' : // strip <br /> from end of <table>
|
case 'table' : // strip <br /> from end of <table>
|
||||||
@@ -1558,9 +1559,10 @@ class e_parse extends e_parser
|
|||||||
// Reduce newlines in all forms to a single newline character (finds '\n', '\r\n', '\n\r')
|
// Reduce newlines in all forms to a single newline character (finds '\n', '\r\n', '\n\r')
|
||||||
if (!$opts['nobreak'])
|
if (!$opts['nobreak'])
|
||||||
{
|
{
|
||||||
if ($convertNL)
|
if ($convertNL && substr($sub_blk,0,6) != '[html]') //XXX Quick Fix, find a cleaner way.
|
||||||
{
|
{
|
||||||
// We may need to convert to <br /> later
|
// We may need to convert to <br /> later
|
||||||
|
|
||||||
$sub_blk = preg_replace("#[\r]*\n[\r]*#", E_NL, $sub_blk);
|
$sub_blk = preg_replace("#[\r]*\n[\r]*#", E_NL, $sub_blk);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -2431,19 +2433,32 @@ class e_parser
|
|||||||
{
|
{
|
||||||
$tmp = $doc->getElementsByTagName($find);
|
$tmp = $doc->getElementsByTagName($find);
|
||||||
|
|
||||||
|
|
||||||
foreach($tmp as $k=>$node)
|
foreach($tmp as $k=>$node)
|
||||||
{
|
{
|
||||||
$tag = $node->nodeName;
|
$tag = $node->nodeName;
|
||||||
|
$inner = $node->C14N();
|
||||||
|
$inner = str_replace("
","",$inner);
|
||||||
|
|
||||||
foreach ($node->attributes as $attr)
|
foreach ($node->attributes as $attr)
|
||||||
{
|
{
|
||||||
$name = $attr->nodeName;
|
$name = $attr->nodeName;
|
||||||
$value = $attr->nodeValue;
|
$value = $attr->nodeValue;
|
||||||
$ret[$tag][$k][$name] = $value;
|
$ret[$tag][$k][$name] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ret[$tag][$k]['@value'] = $inner;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($header == false)
|
||||||
|
{
|
||||||
|
unset($ret['html'],$ret['body']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2456,6 +2471,29 @@ class e_parser
|
|||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse new <bbcode> tags into bbcode output.
|
||||||
|
* @param $retainTags : when you want to replace html and retain the <bbcode> tags wrapping it.
|
||||||
|
* @return html
|
||||||
|
*/
|
||||||
|
function parseBBTags($text,$retainTags = false)
|
||||||
|
{
|
||||||
|
$bbcodes = $this->getTags($text, 'bbcode');
|
||||||
|
|
||||||
|
foreach($bbcodes as $v)
|
||||||
|
{
|
||||||
|
foreach($v as $val)
|
||||||
|
{
|
||||||
|
$tag = urldecode($val['alt']);
|
||||||
|
$repl = ($retainTags == true) ? '$1'.$tag.'$2' : $tag;
|
||||||
|
$text = preg_replace('/(<bbcode[^>]*>).*(<\/bbcode>)/s',$repl, $text); //FIXME - handle multiple instances of bbcodes.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform and render XSS Test Comparison
|
* Perform and render XSS Test Comparison
|
||||||
|
@@ -4,7 +4,7 @@ define("e_ADMIN_AREA", true);
|
|||||||
require_once("../../../../class2.php");
|
require_once("../../../../class2.php");
|
||||||
//e107::lan('core','admin',TRUE);
|
//e107::lan('core','admin',TRUE);
|
||||||
define("e_IFRAME",true);
|
define("e_IFRAME",true);
|
||||||
require_once(e_ADMIN."auth.php");
|
//require_once(e_ADMIN."auth.php");
|
||||||
|
|
||||||
|
|
||||||
if(!USER || check_class($pref['post_html']) == FALSE){
|
if(!USER || check_class($pref['post_html']) == FALSE){
|
||||||
@@ -71,7 +71,33 @@ $(document).ready(function()
|
|||||||
tinyMCEPopup.close();
|
tinyMCEPopup.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#bbcodeInsert').click(function ()
|
||||||
|
{
|
||||||
|
s = $('#bbcodeValue').val();
|
||||||
|
s = s.trim(s);
|
||||||
|
|
||||||
|
var html = $.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: './parser.php',
|
||||||
|
data: { content: s, mode: 'tohtml' },
|
||||||
|
async : false,
|
||||||
|
|
||||||
|
dataType: 'html',
|
||||||
|
success: function(html) {
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
}).responseText;
|
||||||
|
|
||||||
|
html = '<bbcode alt=\"'+encodeURIComponent(s)+'\">' + html + '</bbcode> ' ;
|
||||||
|
|
||||||
|
tinyMCEPopup.editor.execCommand('mceInsertContent', false, html);
|
||||||
|
tinyMCEPopup.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('a.bbcodeSelect').click(function () {
|
||||||
|
var html = $(this).html();
|
||||||
|
$('#bbcodeValue').val(html);
|
||||||
|
});
|
||||||
|
|
||||||
$('#e-cancel').click(function () {
|
$('#e-cancel').click(function () {
|
||||||
|
|
||||||
@@ -95,6 +121,19 @@ class e_bootstrap
|
|||||||
{
|
{
|
||||||
$ns = e107::getRender();
|
$ns = e107::getRender();
|
||||||
|
|
||||||
|
|
||||||
|
if(e_QUERY == 'bbcode')
|
||||||
|
{
|
||||||
|
echo $this->bbcodeForm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$text = '
|
$text = '
|
||||||
<ul class="nav nav-tabs">';
|
<ul class="nav nav-tabs">';
|
||||||
|
|
||||||
@@ -103,6 +142,7 @@ class e_bootstrap
|
|||||||
$text .= '<li><a href="#badges" data-toggle="tab">Labels & Badges</a></li>';
|
$text .= '<li><a href="#badges" data-toggle="tab">Labels & Badges</a></li>';
|
||||||
|
|
||||||
$text .= '<li><a href="#glyphs" data-toggle="tab">Glyphicons</a></li>';
|
$text .= '<li><a href="#glyphs" data-toggle="tab">Glyphicons</a></li>';
|
||||||
|
|
||||||
$text .= '</ul>';
|
$text .= '</ul>';
|
||||||
|
|
||||||
$text .= '<div class="tab-content">';
|
$text .= '<div class="tab-content">';
|
||||||
@@ -112,6 +152,8 @@ class e_bootstrap
|
|||||||
$text .= '<div class="tab-pane left" id="badges">'.$this->badgeForm().'</div>';
|
$text .= '<div class="tab-pane left" id="badges">'.$this->badgeForm().'</div>';
|
||||||
|
|
||||||
$text .= '<div class="tab-pane left" id="glyphs">'.$this->glyphicons().'</div>';
|
$text .= '<div class="tab-pane left" id="glyphs">'.$this->glyphicons().'</div>';
|
||||||
|
|
||||||
|
|
||||||
$text .= '</div>';
|
$text .= '</div>';
|
||||||
|
|
||||||
echo $text;
|
echo $text;
|
||||||
@@ -204,9 +246,46 @@ class e_bootstrap
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function bbcodeForm()
|
||||||
|
{
|
||||||
|
$list = e107::getPref('bbcode_list');
|
||||||
|
|
||||||
|
$text .= "
|
||||||
|
<h4>e107 Bbcodes</h4>
|
||||||
|
<div class='well'>
|
||||||
|
<table class='table table-striped'>
|
||||||
|
<tr><th>Plugin</th>
|
||||||
|
<th>Bbcode</th>
|
||||||
|
</tr>
|
||||||
|
";
|
||||||
|
foreach($list as $plugin=>$val)
|
||||||
|
{
|
||||||
|
$text .= "<tr><td>".$plugin."</td>
|
||||||
|
<td>";
|
||||||
|
|
||||||
|
foreach($val as $bb=>$v)
|
||||||
|
{
|
||||||
|
$text .= "<a href='#' class='bbcodeSelect' style='cursor:pointer'>[".$bb."][/".$bb."]</a>";
|
||||||
|
}
|
||||||
|
$text .= "</td>
|
||||||
|
</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$text .= "</table>
|
||||||
|
</div>";
|
||||||
|
|
||||||
|
$frm = e107::getForm();
|
||||||
|
$text .= $frm->text('bbcodeValue','',false,'size=xlarge');
|
||||||
|
$text .= $frm->button('bbcodeInsert','go','other','Insert');
|
||||||
|
|
||||||
|
|
||||||
|
return $text;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function glyphicons()
|
function glyphicons()
|
||||||
{
|
{
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
tinymce.create('tinymce.plugins.e107BBCodePlugin', {
|
tinymce.create('tinymce.plugins.e107BBCodePlugin', {
|
||||||
init : function(ed, url) {
|
init : function(ed, url) {
|
||||||
|
|
||||||
|
// Bootstrap
|
||||||
ed.addCommand('mceBoot', function() {
|
ed.addCommand('mceBoot', function() {
|
||||||
ed.windowManager.open({
|
ed.windowManager.open({
|
||||||
file : url + '/dialog.php',
|
file : url + '/dialog.php',
|
||||||
@@ -22,11 +23,33 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Register button
|
// Register button
|
||||||
ed.addButton('e107bbcode', {
|
ed.addButton('bootstrap', {
|
||||||
title : 'example.desc',
|
title : 'Insert Bootstrap Elements',
|
||||||
cmd : 'mceBoot',
|
cmd : 'mceBoot',
|
||||||
image : url + '/img/bootstrap.png'
|
image : url + '/img/bootstrap.png'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// e107 Bbcode
|
||||||
|
ed.addCommand('mcee107', function() {
|
||||||
|
ed.windowManager.open({
|
||||||
|
file : url + '/dialog.php?bbcode',
|
||||||
|
width : 900 , // + parseInt(ed.getLang('e107bbcode.delta_width', 0)),
|
||||||
|
height : 450, // + parseInt(ed.getLang('e107bbcode.delta_height', 0)),
|
||||||
|
inline : 1
|
||||||
|
}, {
|
||||||
|
plugin_url : url, // Plugin absolute URL
|
||||||
|
some_custom_arg : 'custom arg' // Custom argument
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Register button
|
||||||
|
ed.addButton('e107bbcode', {
|
||||||
|
title : 'Insert e107 Bbcode',
|
||||||
|
cmd : 'mcee107',
|
||||||
|
image : url + '/img/bbcode.png'
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Add a node change handler, selects the button in the UI when a image is selected
|
// Add a node change handler, selects the button in the UI when a image is selected
|
||||||
ed.onNodeChange.add(function(ed, cm, n) {
|
ed.onNodeChange.add(function(ed, cm, n) {
|
||||||
|
@@ -26,6 +26,9 @@ if($_POST['mode'] == 'tohtml')
|
|||||||
|
|
||||||
// XXX @Cam possible fix - convert to BB first, see news admin AJAX request/response values for reference why
|
// XXX @Cam possible fix - convert to BB first, see news admin AJAX request/response values for reference why
|
||||||
$content = stripslashes($_POST['content']);
|
$content = stripslashes($_POST['content']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// $content = e107::getBB()->htmltoBBcode($content); //XXX This breaks inserted images from media-manager. :/
|
// $content = e107::getBB()->htmltoBBcode($content); //XXX This breaks inserted images from media-manager. :/
|
||||||
e107::getBB()->setClass($_SESSION['media_category']);
|
e107::getBB()->setClass($_SESSION['media_category']);
|
||||||
@@ -47,6 +50,7 @@ if($_POST['mode'] == 'tohtml')
|
|||||||
|
|
||||||
$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!
|
||||||
echo $content;
|
echo $content;
|
||||||
}
|
}
|
||||||
else // bbcode Mode.
|
else // bbcode Mode.
|
||||||
@@ -76,13 +80,14 @@ if($_POST['mode'] == 'tobbcode')
|
|||||||
$repl = array('src="{e_BASE}thumb.php?','src="{e_BASE}thumb.php?src=e_MEDIA_IMAGE/');
|
$repl = array('src="{e_BASE}thumb.php?','src="{e_BASE}thumb.php?src=e_MEDIA_IMAGE/');
|
||||||
|
|
||||||
$content = str_replace($srch, $repl, $content);
|
$content = str_replace($srch, $repl, $content);
|
||||||
|
|
||||||
// resize the thumbnail to match wysiwyg width/height.
|
// resize the thumbnail to match wysiwyg width/height.
|
||||||
|
|
||||||
$psrch = '/<img[^>]*src="{e_BASE}thumb.php\?src=([\S]*)w=([\d]*)&h=([\d]*)"(.*)width="([\d]*)" height="([\d]*)"/i';
|
$psrch = '/<img[^>]*src="{e_BASE}thumb.php\?src=([\S]*)w=([\d]*)&h=([\d]*)"(.*)width="([\d]*)" height="([\d]*)"/i';
|
||||||
$prepl = '<img src="{e_BASE}thumb.php?src=$1w=$5&h=$6"$4width="$5" height="$6" ';
|
$prepl = '<img src="{e_BASE}thumb.php?src=$1w=$5&h=$6"$4width="$5" height="$6" ';
|
||||||
|
|
||||||
$content = preg_replace($psrch, $prepl, $content);
|
$content = preg_replace($psrch, $prepl, $content);
|
||||||
|
$content = $tp->parseBBTags($content,true); // replace html with bbcode equivalent
|
||||||
|
|
||||||
echo ($content) ? "[html]".$content."[/html]" : ""; // Add the tags before saving to DB.
|
echo ($content) ? "[html]".$content."[/html]" : ""; // Add the tags before saving to DB.
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,6 @@
|
|||||||
<tinymce>
|
<tinymce>
|
||||||
<tinymce_name>Main Admin</tinymce_name>
|
<tinymce_name>Main Admin</tinymce_name>
|
||||||
<tinymce_plugins>advhr,advlink,autosave,contextmenu,directionality,e107bbcode,emoticons,ibrowser,jqueryinlinepopups,paste,table,visualchars,wordcount,xhtmlxtras,youtube,fullscreen</tinymce_plugins>
|
<tinymce_plugins>advhr,advlink,autosave,contextmenu,directionality,e107bbcode,emoticons,ibrowser,jqueryinlinepopups,paste,table,visualchars,wordcount,xhtmlxtras,youtube,fullscreen</tinymce_plugins>
|
||||||
<tinymce_buttons1>link, unlink, bold, italic, underline, undo, redo,formatselect,justifyleft,justifycenter,justifyright,justifyfull, |, ibrowser, forecolor, removeformat, table, bullist, numlist, outdent, indent, cleanup, emoticons, youtube, e107bbcode, fullscreen</tinymce_buttons1>
|
<tinymce_buttons1>link, unlink, bold, italic, underline, undo, redo,formatselect,justifyleft,justifycenter,justifyright,justifyfull, |, ibrowser, forecolor, removeformat, table, bullist, numlist, outdent, indent, cleanup, emoticons, youtube, e107bbcode, bootstrap, fullscreen</tinymce_buttons1>
|
||||||
<extended_valid_elements>i[*], object[*],embed[*]</extended_valid_elements>
|
<extended_valid_elements>i[*], object[*],embed[*],bbcode[*]</extended_valid_elements>
|
||||||
</tinymce>
|
</tinymce>
|
||||||
|
@@ -326,6 +326,8 @@ class wysiwyg
|
|||||||
'cleanup' => 'true',
|
'cleanup' => 'true',
|
||||||
'convert_fonts_to_spans' => 'true',
|
'convert_fonts_to_spans' => 'true',
|
||||||
'content_css' => $tp->replaceConstants($content_css),
|
'content_css' => $tp->replaceConstants($content_css),
|
||||||
|
'popup_css' => 'false',
|
||||||
|
|
||||||
'trim_span_elements' => 'true',
|
'trim_span_elements' => 'true',
|
||||||
'inline_styles' => 'true',
|
'inline_styles' => 'true',
|
||||||
'auto_resize' => 'false',
|
'auto_resize' => 'false',
|
||||||
|
Reference in New Issue
Block a user