1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 05:37:32 +02:00

Tinymce parser now loads up to 3x faster.

This commit is contained in:
Cameron
2015-04-11 20:40:29 -07:00
parent 71500fc723
commit f5a5a64e98
3 changed files with 215 additions and 160 deletions

View File

@@ -130,7 +130,7 @@ $text = "
<tr> <tr>
<th><!-- --></th> <th><!-- --></th>
<th class='left'>".CACLAN_17."</th> <th class='left'>".CACLAN_17."</th>
<th class='center last'>".CACLAN_1."</th> <th class='left last'>".CACLAN_1."</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -140,7 +140,7 @@ $text = "
<div class='field-help'>".CACLAN_13."</div> <div class='field-help'>".CACLAN_13."</div>
</td> </td>
<td>{$contentcache_label}</td> <td>{$contentcache_label}</td>
<td class='center middle'> <td class='left middle'>
".$frm->radio_switch('cachestatus', e107::getPref('cachestatus'))." ".$frm->radio_switch('cachestatus', e107::getPref('cachestatus'))."
</td> </td>
</tr> </tr>
@@ -150,7 +150,7 @@ $text = "
<div class='field-help'>".CACLAN_14."</div> <div class='field-help'>".CACLAN_14."</div>
</td> </td>
<td>{$syscache_label}</td> <td>{$syscache_label}</td>
<td class='center middle'> <td class='left middle'>
".$frm->radio_switch('syscachestatus', e107::getPref('syscachestatus'))." ".$frm->radio_switch('syscachestatus', e107::getPref('syscachestatus'))."
</td> </td>
</tr> </tr>
@@ -160,7 +160,7 @@ $text = "
<div class='field-help'>".CACLAN_21."</div> <div class='field-help'>".CACLAN_21."</div>
</td> </td>
<td>{$dbcache_label}</td> <td>{$dbcache_label}</td>
<td class='center middle'> <td class='left middle'>
".LAN_ENABLED." ".LAN_ENABLED."
</td> </td>
</tr> </tr>
@@ -170,13 +170,13 @@ $text = "
<div class='field-help'>".CACLAN_23."</div> <div class='field-help'>".CACLAN_23."</div>
</td> </td>
<td>{$imgcache_label}</td> <td>{$imgcache_label}</td>
<td class='center middle'> <td class='left middle'>
".LAN_ENABLED." ".LAN_ENABLED."
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<div class='buttons-bar'> <div class='buttons-bar form-inline'>
<div class='f-right'>".$frm->admin_button('submit_cache', CACLAN_2, 'update')."</div> <div class='f-right'>".$frm->admin_button('submit_cache', CACLAN_2, 'update')."</div>
".$frm->select('option_clear_cache', array( ".$frm->select('option_clear_cache', array(
'empty_all' => CACLAN_26, 'empty_all' => CACLAN_26,

View File

@@ -90,7 +90,7 @@ class e_bbcode
* *
* Code uses a crude stack-based syntax analyser to handle nested bbcodes (including nested 'size' bbcodes, for example) * Code uses a crude stack-based syntax analyser to handle nested bbcodes (including nested 'size' bbcodes, for example)
*/ */
function parseBBCodes($value, $p_ID, $force_lower = 'default', $bbStrip = FALSE) function parseBBCodes($value, $p_ID='', $force_lower = 'default', $bbStrip = FALSE)
{ {
global $postID; global $postID;
$postID = $p_ID; $postID = $p_ID;

View File

@@ -5,10 +5,18 @@
* Copyright (C) e107 Inc (e107.org) * Copyright (C) e107 Inc (e107.org)
* Released under the terms and conditions of the * Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 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 $
*/ */
if(empty($_POST['content']))
{
header('Content-Length: 0');
exit;
}
$_E107['no_online'] = true;
$_E107['no_menus'] = true;
$_E107['no_forceuserupdate'] = true;
require_once("../../../../class2.php"); require_once("../../../../class2.php");
/** /**
@@ -16,29 +24,58 @@ require_once("../../../../class2.php");
* 1) When the post_html pref is active - raw html is used in the editor and wrapped in [html] [/html] bbcodes in the background. * 1) When the post_html pref is active - raw html is used in the editor and wrapped in [html] [/html] bbcodes in the background.
* 2) When the post_html pref is disabled - bbcodes are used in the background and converted to html for the editor. * 2) When the post_html pref is disabled - bbcodes are used in the background and converted to html for the editor.
* Tested extensively over 24 hours with Images - check with Cameron first if issues arise. * Tested extensively over 24 hours with Images - check with Cameron first if issues arise.
* TODO Test Lines breaks and out html tags.
* TODO Check with html5 tags active. * TODO Check with html5 tags active.
*/ */
class e107TinyMceParser
if($_POST['mode'] == 'tohtml')
{ {
protected $gzipCompression = true;
/**
*
*/
function __construct()
{
$html = '';
if($_POST['mode'] == 'tohtml')
{
$html = $this->toHtml($_POST['content']);
}
if($_POST['mode'] == 'tobbcode')
{
$html = $this->toBBcode($_POST['content']);
}
if($this->gzipCompression == true)
{
header('Content-Encoding: gzip');
$gzipoutput = gzencode($html,6);
header('Content-Length: '.strlen($gzipoutput));
echo $gzipoutput;
}
else
{
echo $html;
}
}
function toHtml($content)
{
global $pref, $tp; //XXX faster?
// 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($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']);
if(check_class($pref['post_html'])) // raw HTML within [html] tags. if(check_class($pref['post_html'])) // raw HTML within [html] tags.
{ {
// $content = $tp->replaceConstants($content,'abs'); // $content = $tp->replaceConstants($content,'abs');
if(strstr($content,"[html]") === false) // BC - convert old BB code text to html. if(strstr($content,"[html]") === false) // BC - convert old BB code text to html.
@@ -50,8 +87,6 @@ if($_POST['mode'] == 'tohtml')
$content = $tp->toHtml($content, true); $content = $tp->toHtml($content, true);
} }
$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);
@@ -62,12 +97,16 @@ if($_POST['mode'] == 'tohtml')
$content = "-- DEBUG MODE ACTIVE -- \n".$content; $content = "-- DEBUG MODE ACTIVE -- \n".$content;
// echo htmlentities($content)."\n"; // echo htmlentities($content)."\n";
// echo "<pre>".$content."</pre>"; // echo "<pre>".$content."</pre>";
echo $content; $text = $content;
exit; return $text;
// exit;
}
else
{
$text = $content;
} }
echo $content;
} }
else // bbcode Mode. else // bbcode Mode.
@@ -80,23 +119,29 @@ if($_POST['mode'] == 'tohtml')
$content = $tp->toHtml($content, true); $content = $tp->toHtml($content, true);
$content = str_replace(e_MEDIA_IMAGE,"{e_MEDIA_IMAGE}",$content); $content = str_replace(e_MEDIA_IMAGE,"{e_MEDIA_IMAGE}",$content);
$text = "";
if(!empty($content) && E107_DEBUG_LEVEL > 0) if(!empty($content) && E107_DEBUG_LEVEL > 0)
{ {
echo "<!-- bbcode mode -->"; $text .= "<!-- bbcode mode -->";
//print_r(htmlentities($content))."\n"; //print_r(htmlentities($content))."\n";
//exit; //exit;
} }
echo $content; $text .= $content;
} }
e107::getBB()->clearClass(); e107::getBB()->clearClass();
} return $text;
if($_POST['mode'] == 'tobbcode') }
{
function toBBcode($content)
{
// echo $_POST['content']; // echo $_POST['content'];
$content = stripslashes($_POST['content']); global $pref, $tp;
$content = stripslashes($content);
if(check_class($pref['post_html'])) // Plain HTML mode. if(check_class($pref['post_html'])) // Plain HTML mode.
{ {
@@ -110,7 +155,7 @@ if($_POST['mode'] == 'tobbcode')
// $prepl = '<img src="{e_BASE}thumb.php?src=$1w=$5&amp;h=$6"$4width="$5" height="$6" '; // $prepl = '<img src="{e_BASE}thumb.php?src=$1w=$5&amp;h=$6"$4width="$5" height="$6" ';
// $content = preg_replace($psrch, $prepl, $content); // $content = preg_replace($psrch, $prepl, $content);
$content = 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]
@@ -118,23 +163,26 @@ if($_POST['mode'] == 'tobbcode')
exit; exit;
} }
echo $content ? "[html]".$content."[/html]" : ""; // Add the tags before saving to DB. $text = $content ? "[html]".$content."[/html]" : ""; // Add the tags before saving to DB.
} }
else // bbcode Mode. //XXX Disabled at the moment in tinymce/e_meta.php - post_html is required to activate. else // bbcode Mode. //XXX Disabled at the moment in tinymce/e_meta.php - post_html is required to activate.
{ {
// [img width=400]/e107_2.0/thumb.php?src={e_MEDIA_IMAGE}2012-12/e107org_white_stripe.png&w=400&h=0[/img] // [img width=400]/e107_2.0/thumb.php?src={e_MEDIA_IMAGE}2012-12/e107org_white_stripe.png&w=400&h=0[/img]
// $content = str_replace("{e_BASE}","", $content); // We want {e_BASE} in the final data going to the DB, but not the editor. // $content = str_replace("{e_BASE}","", $content); // We want {e_BASE} in the final data going to the DB, but not the editor.
echo e107::getBB()->htmltoBBcode($content); // not reliable enough yet. $text = e107::getBB()->htmltoBBcode($content); // not reliable enough yet.
} }
} return $text;
/** }
/**
* Rebuld <img> tags with modified thumbnail size. * Rebuld <img> tags with modified thumbnail size.
*/ */
function updateImg($text) function updateImg($text)
{ {
$arr = e107::getParser()->getTags($text,'img'); $arr = e107::getParser()->getTags($text,'img');
@@ -169,6 +217,13 @@ function updateImg($text)
return $text; return $text;
}
} }
new e107TinyMceParser();
?> ?>