mirror of
https://github.com/e107inc/e107.git
synced 2025-05-04 11:24:54 +02:00
TinyMce rework of parser.
This commit is contained in:
parent
cb9f160e38
commit
89c8da6881
@ -449,9 +449,9 @@ class e_bbcode
|
||||
// NEW bbcode button rendering function. replacing displayHelp();
|
||||
function renderButtons($template,$id='')
|
||||
{
|
||||
|
||||
|
||||
$tp = e107::getParser();
|
||||
require_once(e107::coreTemplatePath('bbcode')); //correct way to load a core template.
|
||||
require(e107::coreTemplatePath('bbcode')); //correct way to load a core template.
|
||||
|
||||
$pref = e107::getPref('e_bb_list');
|
||||
|
||||
@ -481,7 +481,12 @@ class e_bbcode
|
||||
{
|
||||
$BBCODE_TEMPLATE = $temp[$template];
|
||||
}
|
||||
else
|
||||
{
|
||||
$BBCODE_TEMPLATE = $BBCODE_TEMPLATE;
|
||||
}
|
||||
|
||||
|
||||
$bbcode_shortcodes = e107::getScBatch('bbcode');
|
||||
|
||||
$data = array(
|
||||
@ -498,6 +503,47 @@ class e_bbcode
|
||||
return "<div id='bbcode-panel-".$id."' class='mceToolbar bbcode-panel' {$visible}>".$tp->parseTemplate($BBCODE_TEMPLATE,TRUE)."</div>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert HTML to bbcode.
|
||||
*/
|
||||
function htmltoBbcode($text)
|
||||
{
|
||||
$convert = array(
|
||||
array( "\n", '<br />'),
|
||||
array( "[list]", '<ul class="bbcode">'),
|
||||
array( "\n[/list]", '</ul>'),
|
||||
array( "\n[*]", '<li class="bbcode bbcode-list">'),
|
||||
array( "[h2]", '<h2 class="bbcode-center" style="text-align: center;">'), // e107 bbcode markup
|
||||
array( "[h2]", '<h2>'),
|
||||
array( "[/h2]", '</h2>'),
|
||||
array( "[b]", '<strong>'), // Tinymce markup
|
||||
array( "[b]", '<strong class="bbcode bold bbcode-b">'), // e107 bbcode markup
|
||||
array( "[/b]", '</strong>'),
|
||||
array( "[i]", '<em class="bbcode italic bbcode-i">'), // e107 bbcode markup
|
||||
array( "[i]", '<em>'),
|
||||
array( "[/i]", '</em>'),
|
||||
);
|
||||
|
||||
foreach($convert as $arr)
|
||||
{
|
||||
$repl[] = $arr[0];
|
||||
$srch[] = $arr[1];
|
||||
}
|
||||
|
||||
$text = preg_replace("/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/i","[link=$1]$2[/link]",$text);
|
||||
$text = preg_replace('/<div style="text-align: center;">([\s\S]*)<\/div>/i',"[center]$1[/center]",$text); // verified
|
||||
$text = preg_replace('/<div class="bbcode-([\w]*)" style="text-align: (?:[\w]*);">([\s\S]*)<\/div>/i',"[$1]$2[/$1]",$text); // left / right / center
|
||||
$text = preg_replace('/<img(?:\s*)?(?:style="([^"]*)")?\s?(?:src="([^"]*)")(?:\s*)?(?:alt="(\S*)")?(?:\s*)?(?:width="([\d]*)")?\s*(?:height="([\d]*)")?(?:\s*)?\/>/i',"[img style=width:$4px;height:$5px;$1]$2[/img]",$text );
|
||||
$text = preg_replace('/<img class="bbcode bbcode-img"(?:\s*)?(?:style="([^"]*)")?\s?(?:src="([^"]*)")(?:\s*)?(?:alt="(\S*)")?(?:\s*)?(?:width="([\d]*)")?\s*(?:height="([\d]*)")?(?:\s*)?\/>/i',"[img style=width:$4px;height:$5px;$1]$2[/img]",$text );
|
||||
$text = preg_replace('/<span (?:class="bbcode-color" )?style=\"color: ?(.*?);\">(.*?)<\/span>/i',"[color=$1]$2[/color]",$text);
|
||||
|
||||
$blank = array('</li>','width:px;height:px;');
|
||||
$text = str_replace($blank,"",$text); // Cleanup
|
||||
|
||||
return str_replace($srch,$repl,$text);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -527,35 +527,6 @@ function admin_config_adminmenu()
|
||||
$ef->show_options($action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle page DOM within the page header
|
||||
*
|
||||
* @return string JS source
|
||||
*/
|
||||
function headerjs()
|
||||
{
|
||||
require_once(e_HANDLER.'js_helper.php');
|
||||
$ret = "
|
||||
<script type='text/javascript'>
|
||||
if(typeof e107Admin == 'undefined') var e107Admin = {}
|
||||
|
||||
/**
|
||||
* OnLoad Init Control
|
||||
*/
|
||||
e107Admin.initRules = {
|
||||
'Helper': true,
|
||||
'AdminMenu': false
|
||||
}
|
||||
</script>
|
||||
<script type='text/javascript' src='".e_FILE_ABS."jslib/core/admin.js'></script>
|
||||
";
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if($_POST['save_settings']) // Needs to be saved before e_meta.php is loaded by auth.php.
|
||||
{
|
||||
@ -680,19 +651,5 @@ function edit_theme()
|
||||
|
||||
require_once(e_ADMIN."footer.php");
|
||||
|
||||
/*
|
||||
function headerjs()
|
||||
{
|
||||
require_once(e_HANDLER.'js_helper.php');
|
||||
//FIXME - how exactly to auto-call JS lan? This and more should be solved in Stage II.
|
||||
$ret = "
|
||||
<script type='text/javascript'>
|
||||
//add required core lan - delete confirm message
|
||||
</script>
|
||||
<script type='text/javascript' src='".e_FILE_ABS."jslib/core/admin.js'></script>
|
||||
";
|
||||
|
||||
// return $ret;
|
||||
}*/
|
||||
|
||||
?>
|
@ -36,18 +36,19 @@ if(e_WYSIWYG || strpos(e_SELF,"tinymce/admin_config.php") )
|
||||
var id = $(this).attr('id'); // 'e-wysiwyg';
|
||||
$('#'+id).after('<div><a href=\"#\" id=\"' + id + '\" class=\"e-wysiwyg-toggle\">Switch to BBCODE</a></div>');
|
||||
// alert(id);
|
||||
$('#bbcode-panel-'+id+'--preview').hide();
|
||||
|
||||
});
|
||||
|
||||
|
||||
$('a.e-wysiwyg-toggle').toggle(function(){
|
||||
var id = $(this).attr('id'); // eg. news-body
|
||||
$('#bbcode-panel-'+id).show();
|
||||
$('#bbcode-panel-'+id+'--preview').show();
|
||||
$(this).text('Switch to WYSIWYG');
|
||||
tinyMCE.execCommand('mceRemoveControl', false, id);
|
||||
}, function () {
|
||||
var id = $(this).attr('id');
|
||||
$('#bbcode-panel-'+id).hide();
|
||||
$('#bbcode-panel-'+id+'--preview').hide();
|
||||
$(this).text('Switch to BBCODE');
|
||||
tinyMCE.execCommand('mceAddControl', false, id);
|
||||
});
|
||||
|
@ -11,15 +11,16 @@
|
||||
var t = this, dialect = ed.getParam('bbcode_dialect', 'e107').toLowerCase();
|
||||
|
||||
ed.onBeforeSetContent.add(function(ed, o) {
|
||||
o.content = t['_' + dialect + '_bbcode2html'](o.content);
|
||||
|
||||
o.content = t['_' + dialect + '_bbcode2html'](o.content,url);
|
||||
});
|
||||
|
||||
ed.onPostProcess.add(function(ed, o) {
|
||||
if (o.set)
|
||||
o.content = t['_' + dialect + '_bbcode2html'](o.content);
|
||||
o.content = t['_' + dialect + '_bbcode2html'](o.content,url);
|
||||
|
||||
if (o.get)
|
||||
o.content = t['_' + dialect + '_html2bbcode'](o.content);
|
||||
o.content = t['_' + dialect + '_html2bbcode'](o.content,url);
|
||||
});
|
||||
},
|
||||
|
||||
@ -36,8 +37,26 @@
|
||||
// Private methods
|
||||
|
||||
// HTML -> BBCode in PunBB dialect
|
||||
_e107_html2bbcode : function(s) {
|
||||
_e107_html2bbcode : function(s,url) {
|
||||
s = tinymce.trim(s);
|
||||
|
||||
|
||||
var p = $.ajax({
|
||||
type: "POST",
|
||||
url: url + "/parser.php",
|
||||
data: { content: s, mode: 'tobbcode' },
|
||||
async : false,
|
||||
|
||||
dataType: "html",
|
||||
success: function(html) {
|
||||
return html;
|
||||
}
|
||||
}).responseText;
|
||||
|
||||
return p;
|
||||
|
||||
|
||||
|
||||
|
||||
function rep(re, str) {
|
||||
s = s.replace(re, str);
|
||||
@ -137,10 +156,28 @@
|
||||
|
||||
return s;
|
||||
},
|
||||
|
||||
|
||||
// BBCode -> HTML from PunBB dialect
|
||||
_e107_bbcode2html : function(s) {
|
||||
_e107_bbcode2html : function(s,url) {
|
||||
s = tinymce.trim(s);
|
||||
|
||||
var p = $.ajax({
|
||||
type: "POST",
|
||||
url: url + "/parser.php",
|
||||
data: { content: s, mode: 'tohtml' },
|
||||
async : false,
|
||||
|
||||
dataType: "html",
|
||||
success: function(html) {
|
||||
return html;
|
||||
}
|
||||
}).responseText;
|
||||
|
||||
return p;
|
||||
|
||||
|
||||
return s;
|
||||
|
||||
|
||||
function rep(re, str) {
|
||||
s = s.replace(re, str);
|
||||
|
28
e107_plugins/tinymce/plugins/e107bbcode/parser.php
Normal file
28
e107_plugins/tinymce/plugins/e107bbcode/parser.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/*
|
||||
* e107 website system
|
||||
*
|
||||
* Copyright (C) e107 Inc (e107.org)
|
||||
* Released under the terms and conditions of the
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
* $URL: https://e107.svn.sourceforge.net/svnroot/e107/trunk/e107_0.8/e107_handlers/bbcode_handler.php $
|
||||
* $Id: bbcode_handler.php 12778 2012-06-02 08:12:16Z e107coders $
|
||||
*/
|
||||
require_once("../../../../class2.php");
|
||||
|
||||
|
||||
if($_POST['mode'] == 'tohtml')
|
||||
{
|
||||
echo $tp->toHtml($_POST['content'],true);
|
||||
}
|
||||
|
||||
if($_POST['mode'] == 'tobbcode')
|
||||
{
|
||||
//echo $_POST['content'];
|
||||
echo e107::getBB()->htmltoBbcode($_POST['content']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
@ -278,9 +278,9 @@ class wysiwyg
|
||||
|
||||
// 'theme_advanced_statusbar_location' => 'bottom',
|
||||
'theme_advanced_resizing' => 'true',
|
||||
'remove_linebreaks' => 'false',
|
||||
'remove_linebreaks' => 'true',
|
||||
'extended_valid_elements' => '',
|
||||
'apply_source_formatting' => 'true',
|
||||
'apply_source_formatting' => 'false',
|
||||
'invalid_elements' => 'p,font,align,script,applet,iframe',
|
||||
'auto_cleanup_word' => 'true',
|
||||
'convert_fonts_to_spans' => 'true',
|
||||
@ -290,7 +290,7 @@ class wysiwyg
|
||||
'debug' => 'false',
|
||||
'force_br_newlines' => 'true',
|
||||
'forced_root_block' => '',
|
||||
'convert_newlines_to_brs' => 'false', // will break [list] if set to true
|
||||
'convert_newlines_to_brs' => 'true', // will break [list] if set to true
|
||||
'force_p_newlines' => 'false',
|
||||
'entity_encoding' => 'raw',
|
||||
'convert_fonts_to_styles' => 'true',
|
||||
|
Loading…
x
Reference in New Issue
Block a user