mirror of
https://github.com/e107inc/e107.git
synced 2025-10-09 12:06:29 +02:00
TinyMce rework of parser.
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user