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
|
||||
$proc_funcs = TRUE;
|
||||
$convertNL = FALSE;
|
||||
$code_text = str_replace("\r\n", " ", $code_text);
|
||||
$noBreak = TRUE;
|
||||
// $code_text = str_replace("\r\n", " ", $code_text);
|
||||
$code_text = html_entity_decode($code_text, ENT_QUOTES, CHARSET);
|
||||
$html_start = "<!-- bbcode-html-start -->"; // markers for html-to-bbcode replacement.
|
||||
$html_end = "<!-- bbcode-html-end -->";
|
||||
$full_text = str_replace(array("[html]","[/html]"), "",$code_text); // quick fix.. security issue?
|
||||
$full_text =$this->replaceConstants($full_text,'abs');
|
||||
$full_text = $html_start.$full_text.$html_end;
|
||||
$full_text = $this->parseBBTags($full_text); // strip <bbcode> tags.
|
||||
break;
|
||||
|
||||
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')
|
||||
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
|
||||
|
||||
$sub_blk = preg_replace("#[\r]*\n[\r]*#", E_NL, $sub_blk);
|
||||
}
|
||||
else
|
||||
@@ -2431,9 +2433,12 @@ class e_parser
|
||||
{
|
||||
$tmp = $doc->getElementsByTagName($find);
|
||||
|
||||
|
||||
foreach($tmp as $k=>$node)
|
||||
{
|
||||
$tag = $node->nodeName;
|
||||
$inner = $node->C14N();
|
||||
$inner = str_replace("
","",$inner);
|
||||
|
||||
foreach ($node->attributes as $attr)
|
||||
{
|
||||
@@ -2441,9 +2446,19 @@ class e_parser
|
||||
$value = $attr->nodeValue;
|
||||
$ret[$tag][$k][$name] = $value;
|
||||
}
|
||||
|
||||
$ret[$tag][$k]['@value'] = $inner;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if($header == false)
|
||||
{
|
||||
unset($ret['html'],$ret['body']);
|
||||
}
|
||||
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@@ -2456,6 +2471,29 @@ class e_parser
|
||||
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
|
||||
|
@@ -4,7 +4,7 @@ define("e_ADMIN_AREA", true);
|
||||
require_once("../../../../class2.php");
|
||||
//e107::lan('core','admin',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){
|
||||
@@ -71,7 +71,33 @@ $(document).ready(function()
|
||||
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 () {
|
||||
|
||||
@@ -95,6 +121,19 @@ class e_bootstrap
|
||||
{
|
||||
$ns = e107::getRender();
|
||||
|
||||
|
||||
if(e_QUERY == 'bbcode')
|
||||
{
|
||||
echo $this->bbcodeForm();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$text = '
|
||||
<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="#glyphs" data-toggle="tab">Glyphicons</a></li>';
|
||||
|
||||
$text .= '</ul>';
|
||||
|
||||
$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="glyphs">'.$this->glyphicons().'</div>';
|
||||
|
||||
|
||||
$text .= '</div>';
|
||||
|
||||
echo $text;
|
||||
@@ -205,6 +247,43 @@ 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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -9,6 +9,7 @@
|
||||
tinymce.create('tinymce.plugins.e107BBCodePlugin', {
|
||||
init : function(ed, url) {
|
||||
|
||||
// Bootstrap
|
||||
ed.addCommand('mceBoot', function() {
|
||||
ed.windowManager.open({
|
||||
file : url + '/dialog.php',
|
||||
@@ -22,12 +23,34 @@
|
||||
});
|
||||
|
||||
// Register button
|
||||
ed.addButton('e107bbcode', {
|
||||
title : 'example.desc',
|
||||
ed.addButton('bootstrap', {
|
||||
title : 'Insert Bootstrap Elements',
|
||||
cmd : 'mceBoot',
|
||||
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
|
||||
ed.onNodeChange.add(function(ed, cm, n) {
|
||||
cm.setActive('example', n.nodeName == 'IMG');
|
||||
|
@@ -27,6 +27,9 @@ if($_POST['mode'] == 'tohtml')
|
||||
// XXX @Cam possible fix - convert to BB first, see news admin AJAX request/response values for reference why
|
||||
$content = stripslashes($_POST['content']);
|
||||
|
||||
|
||||
|
||||
|
||||
// $content = e107::getBB()->htmltoBBcode($content); //XXX This breaks inserted images from media-manager. :/
|
||||
e107::getBB()->setClass($_SESSION['media_category']);
|
||||
|
||||
@@ -47,6 +50,7 @@ if($_POST['mode'] == 'tohtml')
|
||||
|
||||
$srch = array("<!-- bbcode-html-start -->","<!-- bbcode-html-end -->","[html]","[/html]");
|
||||
$content = str_replace($srch,"",$content);
|
||||
$content = e107::getBB()->parseBBCodes($content); // parse the <bbcode> tag so we see the HTML equivalent while editing!
|
||||
echo $content;
|
||||
}
|
||||
else // bbcode Mode.
|
||||
@@ -83,6 +87,7 @@ if($_POST['mode'] == 'tobbcode')
|
||||
$prepl = '<img src="{e_BASE}thumb.php?src=$1w=$5&h=$6"$4width="$5" height="$6" ';
|
||||
|
||||
$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.
|
||||
}
|
||||
|
@@ -2,6 +2,6 @@
|
||||
<tinymce>
|
||||
<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_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>
|
||||
<extended_valid_elements>i[*], object[*],embed[*]</extended_valid_elements>
|
||||
<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[*],bbcode[*]</extended_valid_elements>
|
||||
</tinymce>
|
||||
|
@@ -326,6 +326,8 @@ class wysiwyg
|
||||
'cleanup' => 'true',
|
||||
'convert_fonts_to_spans' => 'true',
|
||||
'content_css' => $tp->replaceConstants($content_css),
|
||||
'popup_css' => 'false',
|
||||
|
||||
'trim_span_elements' => 'true',
|
||||
'inline_styles' => 'true',
|
||||
'auto_resize' => 'false',
|
||||
|
Reference in New Issue
Block a user