1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-03 21:27:25 +02:00

New functionality to allow parsing of vars and shortcodes with single pass or parseTemplate

This commit is contained in:
mcfly
2010-01-23 16:41:56 +00:00
parent de2aa2821a
commit 3042ab26c2
2 changed files with 56 additions and 22 deletions

View File

@@ -9,8 +9,8 @@
* Text processing and parsing functions * Text processing and parsing functions
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/e_parse_class.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/e_parse_class.php,v $
* $Revision: 1.92 $ * $Revision: 1.93 $
* $Date: 2010-01-23 03:25:31 $ * $Date: 2010-01-23 16:41:50 $
* $Author: mcfly_e107 $ * $Author: mcfly_e107 $
* *
*/ */
@@ -1892,10 +1892,20 @@ class e_parse
} }
} }
class templateVars class e_vars
{ {
private $vars; private $vars;
public function __construct($array='')
{
$this->setVars($array);
}
public function __set($key, $value)
{
$this->vars[$key] = $value;
}
public function __get($key) public function __get($key)
{ {
if(isset($this->vars[$key])) if(isset($this->vars[$key]))
@@ -1907,13 +1917,27 @@ class templateVars
return false; return false;
} }
} }
public function emptyVars() public function emptyVars()
{ {
$this->vars = array(); $this->vars = array();
} }
public function __set($key, $value) public function setVars($array='', $empty = true)
{ {
$this->vars[$key] = $value; if($empty) { $this->vars = array(); }
if(is_array($array))
{
foreach($array as $key => $val)
{
$this->vars[$key] = $val;
}
}
} }
public function addVars($array='')
{
$this->setVars($array);
}
} }

View File

@@ -9,9 +9,9 @@
* e107 Shortcode handler * e107 Shortcode handler
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/shortcode_handler.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/shortcode_handler.php,v $
* $Revision: 1.40 $ * $Revision: 1.41 $
* $Date: 2009-12-17 22:47:20 $ * $Date: 2010-01-23 16:41:56 $
* $Author: e107steved $ * $Author: mcfly_e107 $
*/ */
if (!defined('e107_INIT')) { exit; } if (!defined('e107_INIT')) { exit; }
@@ -149,10 +149,11 @@ class e_shortcode
var $registered_codes = array(); // Shortcodes added by plugins var $registered_codes = array(); // Shortcodes added by plugins
var $scClasses = array(); // Batch shortcode classes var $scClasses = array(); // Batch shortcode classes
var $scOverride = array(); // Array of codes found in override/ dir var $scOverride = array(); // Array of codes found in override/ dir
private $eVars = '';
function e_shortcode($noload=false) function e_shortcode($noload=false)
{ {
global $pref; global $pref;
$this->parseSCFiles = true; // Default probably never used, but make sure its defined. $this->parseSCFiles = true; // Default probably never used, but make sure its defined.
@@ -181,7 +182,7 @@ class e_shortcode
$this->registered_codes[$code]['type'] = 'override'; $this->registered_codes[$code]['type'] = 'override';
$this->scOverride[] = $code; $this->scOverride[] = $code;
} }
} }
} }
/** /**
@@ -204,7 +205,7 @@ class e_shortcode
$this->registered_codes[$code]['type'] = 'theme'; $this->registered_codes[$code]['type'] = 'theme';
} }
} }
} }
} }
@@ -214,7 +215,7 @@ class e_shortcode
* @return void * @return void
*/ */
protected function loadPluginSCFiles() protected function loadPluginSCFiles()
{ {
$pref = e107::getConfig('core')->getPref(); $pref = e107::getConfig('core')->getPref();
if(varset($pref['shortcode_list'], '') != '') if(varset($pref['shortcode_list'], '') != '')
@@ -239,12 +240,12 @@ class e_shortcode
} }
} }
} }
} }
} }
/** /**
* Register Plugin Shortcode Batch files (e_shortcode.php) for use site-wide. * Register Plugin Shortcode Batch files (e_shortcode.php) for use site-wide.
* Equivalent to multiple .sc files in the plugin's folder. * Equivalent to multiple .sc files in the plugin's folder.
* *
* @return void * @return void
*/ */
@@ -269,7 +270,7 @@ class e_shortcode
$tmp = get_class_methods($classFunc); $tmp = get_class_methods($classFunc);
foreach($tmp as $c) foreach($tmp as $c)
{ {
if(strpos($c, 'sc_') === 0) if(strpos($c, 'sc_') === 0)
{ {
$sc_func = substr($c, 3); $sc_func = substr($c, 3);
@@ -277,14 +278,14 @@ class e_shortcode
if(!$this->isRegistered($code)) if(!$this->isRegistered($code))
{ {
$this->registered_codes[$code] = array('type' => 'class', 'path' => $path, 'class' => $classFunc); $this->registered_codes[$code] = array('type' => 'class', 'path' => $path, 'class' => $classFunc);
} }
} }
} }
} }
} }
/** /**
* Register Core Shortcode Batches. * Register Core Shortcode Batches.
* FIXME - currently loaded all the time (even on front-end) * FIXME - currently loaded all the time (even on front-end)
* *
* @return void * @return void
@@ -321,11 +322,15 @@ class e_shortcode
return in_array($code, $this->scOverride); return in_array($code, $this->scOverride);
} }
function parseCodes($text, $useSCFiles = true, $extraCodes = '') function parseCodes($text, $useSCFiles = true, $extraCodes = '', &$eVars='')
{ {
$saveParseSCFiles = $this->parseSCFiles; // In case of nested call $saveParseSCFiles = $this->parseSCFiles; // In case of nested call
$this->parseSCFiles = $useSCFiles; $this->parseSCFiles = $useSCFiles;
if(is_object($eVars)) {
$this->eVars = $eVars;
}
//object support //object support
if(is_object($extraCodes)) if(is_object($extraCodes))
{ {
@@ -356,6 +361,11 @@ class e_shortcode
{ {
global $pref, $e107cache, $menu_pref, $sc_style, $parm, $sql; global $pref, $e107cache, $menu_pref, $sc_style, $parm, $sql;
if(is_object($this->eVars)) {
if($this->eVars->$matches[1]) {
return $this->eVars->$matches[1];
}
}
if(strpos($matches[1], E_NL) !== false) { return $matches[0]; } if(strpos($matches[1], E_NL) !== false) { return $matches[0]; }
if (strpos($matches[1], '=')) if (strpos($matches[1], '='))