1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-16 04:26:20 +02:00

Hopefully speed up shortcode rendering

This commit is contained in:
mcfly
2008-02-13 02:57:17 +00:00
parent e1bb11a047
commit 144d3e4297

View File

@ -12,9 +12,9 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/shortcode_handler.php,v $
| $Revision: 1.9 $
| $Date: 2007-11-30 22:23:10 $
| $Author: e107steved $
| $Revision: 1.10 $
| $Date: 2008-02-13 02:57:17 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@ -29,7 +29,8 @@ function register_shortcode($code, $filename, $function, $force=false)
}
}
class e_shortcode {
class e_shortcode
{
var $scList; // The actual code - added by parsing files or when plugin codes encountered. Array key is the shortcode name.
var $parseSCFiles; // True if shortcode file has been parsed
var $addedCodes; // Apparently not used
@ -71,22 +72,17 @@ class e_shortcode {
}
function parseCodes($text, $useSCFiles = TRUE, $extraCodes = '') {
function parseCodes($text, $useSCFiles = true, $extraCodes = '')
{
$this->parseSCFiles = $useSCFiles;
$ret = '';
if (is_array($extraCodes)) {
foreach($extraCodes as $sc => $code) {
if(is_array($extraCodes))
{
foreach($extraCodes as $sc => $code)
{
$this->scList[$sc] = $code;
}
}
$tmp = explode("\n", $text);
foreach($tmp as $line) {
if (preg_match("/{.+?}/", $line, $match)) {
$ret .= preg_replace_callback("#\{(\S[^\x02]*?\S)\}#", array($this, 'doCode'), $line);
} else {
$ret .= $line;
}
}
$ret = preg_replace_callback('#\{(\S[^\x02]*?\S)\}#', array(&$this, 'doCode'), $text);
return $ret;
}
@ -139,7 +135,6 @@ class e_shortcode {
}
else
{
if (is_array($this->scList) && array_key_exists($code, $this->scList))
{
$shortcode = $this->scList[$code];
@ -199,9 +194,9 @@ class e_shortcode {
if($ret != '' || is_numeric($ret))
{
//if $sc_mode exists, we need it to parse $sc_style
if($sc_mode){
if($sc_mode)
{
$code = $code."|".$sc_mode;
}
if(isset($sc_style) && is_array($sc_style) && array_key_exists($code,$sc_style))
@ -216,7 +211,8 @@ class e_shortcode {
}
}
}
if (E107_DBG_SC) {
if (E107_DBG_SC)
{
$sql->db_Mark_Time("(SC $code Done)");
}
return $ret;
@ -274,13 +270,18 @@ class e_shortcode {
foreach(array_keys($cur_shortcodes) as $cur_sc)
{
if (is_array($this -> registered_codes) && array_key_exists($cur_sc, $this -> registered_codes)) {
if ($this -> registered_codes[$cur_sc]['type'] == 'plugin') {
if (is_array($this -> registered_codes) && array_key_exists($cur_sc, $this -> registered_codes))
{
if ($this -> registered_codes[$cur_sc]['type'] == 'plugin')
{
$scFile = e_PLUGIN.strtolower($this -> registered_codes[$cur_sc]['path']).'/'.strtolower($cur_sc).'.sc';
} else {
}
else
{
$scFile = THEME.strtolower($cur_sc).'.sc';
}
if (is_readable($scFile)) {
if (is_readable($scFile))
{
$cur_shortcodes[$cur_sc] = file_get_contents($scFile);
}
}