- load seldom used Smarty API methods dynamically to reduce memory footprint

This commit is contained in:
uwetews
2015-08-17 21:52:32 +02:00
parent eb7aa8fe92
commit 6cbcdf4d7b
65 changed files with 2552 additions and 1536 deletions

View File

@@ -1,6 +1,10 @@
 ===== 3.1.28-dev===== (xx.xx.2015)  ===== 3.1.28-dev===== (xx.xx.2015)
xx.xx.2015
- introduce Smarty::$resource_cache_mode and cache template object of {include} inside loop
- load seldom used Smarty API methods dynamically to reduce memory footprint
06.08.2015 06.08.2015
- avoid possible circular object referances caused by parser/lexer objects - avoid possible circular object references caused by parser/lexer objects
- rewrite compileAll... utility methods - rewrite compileAll... utility methods
- commit several internal improvements - commit several internal improvements
- bugfix Smarty failed when compile_id did contain "|" - bugfix Smarty failed when compile_id did contain "|"

View File

@@ -877,19 +877,19 @@ variable(res) ::= object(o). {
// config variable // config variable
variable(res) ::= HATCH ID(i) HATCH. { variable(res) ::= HATCH ID(i) HATCH. {
res = '$_smarty_tpl->getConfigVariable( \''. i .'\')'; res = '$_smarty_tpl->_getConfigVariable( \''. i .'\')';
} }
variable(res) ::= HATCH ID(i) HATCH arrayindex(a). { variable(res) ::= HATCH ID(i) HATCH arrayindex(a). {
res = '(is_array($tmp = $_smarty_tpl->getConfigVariable( \''. i .'\')) ? $tmp'.a.' :null)'; res = '(is_array($tmp = $_smarty_tpl->_getConfigVariable( \''. i .'\')) ? $tmp'.a.' :null)';
} }
variable(res) ::= HATCH variable(v) HATCH. { variable(res) ::= HATCH variable(v) HATCH. {
res = '$_smarty_tpl->getConfigVariable( '. v .')'; res = '$_smarty_tpl->_getConfigVariable( '. v .')';
} }
variable(res) ::= HATCH variable(v) HATCH arrayindex(a). { variable(res) ::= HATCH variable(v) HATCH arrayindex(a). {
res = '(is_array($tmp = $_smarty_tpl->getConfigVariable( '. v .')) ? $tmp'.a.' : null)'; res = '(is_array($tmp = $_smarty_tpl->_getConfigVariable( '. v .')) ? $tmp'.a.' : null)';
} }
varindexed(res) ::= DOLLARID(i) arrayindex(a). { varindexed(res) ::= DOLLARID(i) arrayindex(a). {
@@ -1075,7 +1075,7 @@ function(res) ::= ns1(f) OPENP params(p) CLOSEP. {
$this->compiler->trigger_template_error ('Illegal number of paramer in "isset()"'); $this->compiler->trigger_template_error ('Illegal number of paramer in "isset()"');
} }
$par = implode(',',p); $par = implode(',',p);
if (strncasecmp($par,'$_smarty_tpl->getConfigVariable',strlen('$_smarty_tpl->getConfigVariable')) === 0) { if (strncasecmp($par,'$_smarty_tpl->_getConfigVariable',strlen('$_smarty_tpl->_getConfigVariable')) === 0) {
self::$prefix_number++; self::$prefix_number++;
$this->compiler->prefix_code[] = '<?php $_tmp'.self::$prefix_number.'='.str_replace(')',', false)',$par).';?>'; $this->compiler->prefix_code[] = '<?php $_tmp'.self::$prefix_number.'='.str_replace(')',', false)',$par).';?>';
$isset_par = '$_tmp'.self::$prefix_number; $isset_par = '$_tmp'.self::$prefix_number;

View File

@@ -102,6 +102,12 @@ require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php';
* This is the main Smarty class * This is the main Smarty class
* *
* @package Smarty * @package Smarty
*
* @method int clearAllCache(int $exp_time = null, string $type = null)
* @method int clearCache(string $template_name, string $cache_id = null, string $compile_id = null, int $exp_time = null, string $type = null)
* @method int compileAllTemplates(Smarty $smarty, string $extension = '.tpl', bool $force_compile = false, int $time_limit = 0, int $max_errors = null)
* @method int compileAllConfig(Smarty $smarty, string $extension = '.conf', bool $force_compile = false, int $time_limit = 0, int $max_errors = null)
*
*/ */
class Smarty extends Smarty_Internal_TemplateBase class Smarty extends Smarty_Internal_TemplateBase
{ {
@@ -112,7 +118,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.28-dev/45'; const SMARTY_VERSION = '3.1.28-dev/47';
/** /**
* define variable scopes * define variable scopes
@@ -728,6 +734,13 @@ class Smarty extends Smarty_Internal_TemplateBase
*/ */
public $_parserdebug = false; public $_parserdebug = false;
/**
* This object type (Smarty = 1, template = 2, data = 4)
*
* @var int
*/
public $_objType = 1;
/** /**
* removed properties * removed properties
* *
@@ -735,6 +748,13 @@ class Smarty extends Smarty_Internal_TemplateBase
*/ */
public $obsoleteProperties = array('resource_caching', 'template_resource_caching'); public $obsoleteProperties = array('resource_caching', 'template_resource_caching');
/**
* Extension object cache
*
* @var array
*/
public static $extObjCache = array();
/**#@-*/ /**#@-*/
/** /**
@@ -851,43 +871,6 @@ class Smarty extends Smarty_Internal_TemplateBase
} }
} }
/**
* Empty cache folder
*
* @param integer $exp_time expiration time
* @param string $type resource type
*
* @return integer number of cache files deleted
*/
public function clearAllCache($exp_time = null, $type = null)
{
// load cache resource and call clearAll
$_cache_resource = Smarty_CacheResource::load($this, $type);
Smarty_CacheResource::invalidLoadedCache($this);
return $_cache_resource->clearAll($this, $exp_time);
}
/**
* Empty cache for a specific template
*
* @param string $template_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time
* @param string $type resource type
*
* @return integer number of cache files deleted
*/
public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
{
// load cache resource and call clear
$_cache_resource = Smarty_CacheResource::load($this, $type);
Smarty_CacheResource::invalidLoadedCache($this);
return $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time);
}
/** /**
* Loads security class and enables security * Loads security class and enables security
* *
@@ -1184,119 +1167,6 @@ class Smarty extends Smarty_Internal_TemplateBase
} }
} }
/**
* Set default modifiers
*
* @param array|string $modifiers modifier or list of modifiers to set
*
* @return Smarty current Smarty instance for chaining
*/
public function setDefaultModifiers($modifiers)
{
$this->default_modifiers = (array) $modifiers;
return $this;
}
/**
* Add default modifiers
*
* @param array|string $modifiers modifier or list of modifiers to add
*
* @return Smarty current Smarty instance for chaining
*/
public function addDefaultModifiers($modifiers)
{
if (is_array($modifiers)) {
$this->default_modifiers = array_merge($this->default_modifiers, $modifiers);
} else {
$this->default_modifiers[] = $modifiers;
}
return $this;
}
/**
* Get default modifiers
*
* @return array list of default modifiers
*/
public function getDefaultModifiers()
{
return $this->default_modifiers;
}
/**
* Set autoload filters
*
* @param array $filters filters to load automatically
* @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters'
* keys as the appropriate types
*
* @return Smarty current Smarty instance for chaining
*/
public function setAutoloadFilters($filters, $type = null)
{
Smarty_Internal_Extension_AutoLoadFilter::setAutoloadFilters($this, $filters, $type);
return $this;
}
/**
* Add autoload filters
*
* @param array $filters filters to load automatically
* @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters'
* keys as the appropriate types
*
* @return Smarty current Smarty instance for chaining
*/
public function addAutoloadFilters($filters, $type = null)
{
Smarty_Internal_Extension_AutoLoadFilter::addAutoloadFilters($this, $filters, $type);
return $this;
}
/**
* Get autoload filters
*
* @param string $type type of filter to get autoloads for. Defaults to all autoload filters
*
* @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type
* was specified
*/
public function getAutoloadFilters($type = null)
{
return Smarty_Internal_Extension_AutoLoadFilter::getAutoloadFilters($this, $type);
}
/**
* return name of debugging template
*
* @return string
*/
public function getDebugTemplate()
{
return $this->debug_tpl;
}
/**
* set the debug template
*
* @param string $tpl_name
*
* @return Smarty current Smarty instance for chaining
* @throws SmartyException if file is not readable
*/
public function setDebugTemplate($tpl_name)
{
if (!is_readable($tpl_name)) {
throw new SmartyException("Unknown file '{$tpl_name}'");
}
$this->debug_tpl = $tpl_name;
return $this;
}
/** /**
* creates a template object * creates a template object
* *
@@ -1384,74 +1254,6 @@ class Smarty extends Smarty_Internal_TemplateBase
return $path; return $path;
} }
/**
* Compile all template files
*
* @param string $extension file extension
* @param bool $force_compile force all to recompile
* @param int $time_limit
* @param int $max_errors
*
* @return integer number of template files recompiled
*/
public function compileAllTemplates($extension = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
{
return Smarty_Internal_Extension_CompileAll::compileAll($extension, $force_compile, $time_limit, $max_errors, $this);
}
/**
* Compile all config files
*
* @param string $extension file extension
* @param bool $force_compile force all to recompile<
* @param int $time_limit
* @param int $max_errors
*
* @return integer number of template files recompiled
*/
public function compileAllConfig($extension = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null)
{
return Smarty_Internal_Extension_CompileAll::compileAll($extension, $force_compile, $time_limit, $max_errors, $this, true);
}
/**
* Delete compiled template file
*
* @param string $resource_name template name
* @param string $compile_id compile id
* @param integer $exp_time expiration time
*
* @return integer number of template files deleted
*/
public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
{
return Smarty_Internal_Extension_ClearCompiled::clearCompiledTemplate($this, $resource_name, $compile_id, $exp_time);
}
/**
* Return array of tag/attributes of all tags used by an template
*
* @param Smarty_Internal_Template $template
*
* @return array of tag/attributes
*/
public function getTags(Smarty_Internal_Template $template)
{
return Smarty_Internal_Utility::getTags($template);
}
/**
* Run installation test
*
* @param array $errors Array to write errors into, rather than outputting them
*
* @return boolean true if setup is fine, false if something is wrong
*/
public function testInstall(&$errors = null)
{
return Smarty_Internal_TestInstall::testInstall($this, $errors);
}
/** /**
* @param boolean $compile_check * @param boolean $compile_check
*/ */
@@ -1468,38 +1270,6 @@ class Smarty extends Smarty_Internal_TemplateBase
$this->use_sub_dirs = $use_sub_dirs; $this->use_sub_dirs = $use_sub_dirs;
} }
/**
* @param boolean $caching
*/
public function setCaching($caching)
{
$this->caching = $caching;
}
/**
* @param int $cache_lifetime
*/
public function setCacheLifetime($cache_lifetime)
{
$this->cache_lifetime = $cache_lifetime;
}
/**
* @param string $compile_id
*/
public function setCompileId($compile_id)
{
$this->compile_id = $compile_id;
}
/**
* @param string $cache_id
*/
public function setCacheId($cache_id)
{
$this->cache_id = $cache_id;
}
/** /**
* @param int $error_reporting * @param int $error_reporting
*/ */
@@ -1596,6 +1366,32 @@ class Smarty extends Smarty_Internal_TemplateBase
$this->compile_locking = $compile_locking; $this->compile_locking = $compile_locking;
} }
/**
* @param string $default_resource_type
*/
public function setDefaultResourceType($default_resource_type)
{
$this->default_resource_type = $default_resource_type;
}
/**
* @param string $caching_type
*/
public function setCachingType($caching_type)
{
$this->caching_type = $caching_type;
}
/**
* Test install
*
* @param null $errors
*/
public function testInstall(&$errors = null)
{
Smarty_Internal_TestInstall::testInstall($this, $errors);
}
/** /**
* Class destructor * Class destructor
*/ */
@@ -1647,7 +1443,11 @@ class Smarty extends Smarty_Internal_TemplateBase
} elseif (in_array($name, $this->obsoleteProperties)) { } elseif (in_array($name, $this->obsoleteProperties)) {
return; return;
} else { } else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); if (is_object($value) && method_exists($value, $name)) {
$this->$name = $value;
} else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
}
} }
} }

View File

@@ -73,8 +73,8 @@ abstract class Smarty_CacheResource
{ {
if ($_template->cached->handler->process($_template)) { if ($_template->cached->handler->process($_template)) {
ob_start(); ob_start();
$_template->cached->unifunc($_template); $unifunc = $_template->cached->unifunc;
$unifunc($_template);
return ob_get_clean(); return ob_get_clean();
} }

View File

@@ -139,7 +139,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/ */
$_smarty_tpl = $_template; $_smarty_tpl = $_template;
eval("?>" . $content); eval("?>" . $content);
$cached->content = null;
return true; return true;
} }
@@ -190,7 +190,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/ */
public function clearAll(Smarty $smarty, $exp_time = null) public function clearAll(Smarty $smarty, $exp_time = null)
{ {
return $this->delete(null, null, null, $exp_time); return $this->delete(null, null, null, $exp_time);
} }
/** /**

View File

@@ -30,6 +30,7 @@ class Smarty_Data extends Smarty_Internal_Data
* @var string * @var string
*/ */
public $dataObjectName = ''; public $dataObjectName = '';
/** /**
* Smarty object * Smarty object
* *
@@ -37,6 +38,13 @@ class Smarty_Data extends Smarty_Internal_Data
*/ */
public $smarty = null; public $smarty = null;
/**
* This object type (Smarty = 1, template = 2, data = 4)
*
* @var int
*/
public $_objType = 4;
/** /**
* create Smarty data object * create Smarty data object
* *

View File

@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array('file'); public $required_attributes = array('file');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $shorttag_order = array('file', 'section'); public $shorttag_order = array('file', 'section');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -41,7 +43,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
/** /**
* Compiles code for the {config_load} tag * Compiles code for the {config_load} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @return string compiled code * @return string compiled code
@@ -75,7 +77,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
} }
} }
// create config object // create config object
$_output = "<?php Smarty_Internal_Extension_Config::configLoad(\$_smarty_tpl, $conf_file, $section, '$scope');?>"; $_output = "<?php \$_smarty_tpl->configLoad($conf_file, $section, '$scope');?>";
return $_output; return $_output;
} }

View File

@@ -99,9 +99,9 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
case 'config': case 'config':
if (isset($_index[2])) { if (isset($_index[2])) {
return "(is_array(\$tmp = \$_smarty_tpl->getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)"; return "(is_array(\$tmp = \$_smarty_tpl->_getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)";
} else { } else {
return "\$_smarty_tpl->getConfigVariable($_index[1])"; return "\$_smarty_tpl->_getConfigVariable($_index[1])";
} }
case 'ldelim': case 'ldelim':
$_ldelim = $compiler->smarty->left_delimiter; $_ldelim = $compiler->smarty->left_delimiter;

View File

@@ -143,7 +143,7 @@ class Smarty_Internal_Config_File_Compiler
strftime("%Y-%m-%d %H:%M:%S") . "\n"; strftime("%Y-%m-%d %H:%M:%S") . "\n";
$template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n"; $template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n";
$code = '<?php Smarty_Internal_Extension_Config::loadConfigVars($_smarty_tpl, ' . $code = '<?php Smarty_Internal_Method_ConfigLoad::_loadConfigVars($_smarty_tpl, ' .
var_export($this->config_data, true) . '); ?>'; var_export($this->config_data, true) . '); ?>';
return $template_header . Smarty_Internal_Extension_CodeFrame::create($this->template, $code); return $template_header . Smarty_Internal_Extension_CodeFrame::create($this->template, $code);
} }

View File

@@ -13,6 +13,15 @@
* *
* @package Smarty * @package Smarty
* @subpackage Template * @subpackage Template
*
* @method mixed getConfigVars(string $varname = null, bool $search_parents = true)
* @method mixed getStreamVariable(string $variable)
* @local_method mixed getTemplateVars(string $varname = null, Smarty_Internal_Data $_ptr = null, bool $search_parents = true)
* @method Smarty_Internal_Data clearAssign(mixed $tpl_var)
* @method Smarty_Internal_Data clearAllAssign()
* @method Smarty_Internal_Data clearConfig(string $varname = null)
* @method Smarty_Internal_Data configLoad(string $config_file, mixed $sections = null, string $scope = 'local')
* @property int $_objType
*/ */
class Smarty_Internal_Data class Smarty_Internal_Data
{ {
@@ -33,7 +42,7 @@ class Smarty_Internal_Data
/** /**
* parent template (if any) * parent template (if any)
* *
* @var Smarty_Internal_Template * @var Smarty|Smarty_Internal_Template|Smarty_Internal_Data
*/ */
public $parent = null; public $parent = null;
@@ -51,6 +60,16 @@ class Smarty_Internal_Data
*/ */
public $_cache = array(); public $_cache = array();
/**
* Cache for property information from generic getter/setter
* Preloaded with names which should not use with generic getter/setter
*
* @var array
*/
private $_property_info = array('AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0,
'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0,
'TemplateVars' => 0,);
/** /**
* assigns a Smarty variable * assigns a Smarty variable
* *
@@ -78,6 +97,57 @@ class Smarty_Internal_Data
return $this; return $this;
} }
/**
* appends values to template variables
*
* @api Smarty::append()
* @link http://www.smarty.net/docs/en/api.append.tpl
*
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param bool $merge flag if array elements shall be merged
* @param bool $nocache if true any output of this variable will
* be not cached
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
public function append($tpl_var, $value = null, $merge = false, $nocache = false)
{
if (is_array($tpl_var)) {
// $tpl_var is an array, ignore $value
foreach ($tpl_var as $_key => $_val) {
if ($_key != '') {
$this->append($_key, $_val, $merge, $nocache);
}
}
} else {
if ($tpl_var != '' && isset($value)) {
if (!isset($this->tpl_vars[$tpl_var])) {
$tpl_var_inst = $this->_getVariable($tpl_var, null, true, false);
if ($tpl_var_inst instanceof Smarty_Undefined_Variable) {
$this->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache);
} else {
$this->tpl_vars[$tpl_var] = clone $tpl_var_inst;
}
}
if (!(is_array($this->tpl_vars[$tpl_var]->value) ||
$this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)
) {
settype($this->tpl_vars[$tpl_var]->value, 'array');
}
if ($merge && is_array($value)) {
foreach ($value as $_mkey => $_mval) {
$this->tpl_vars[$tpl_var]->value[$_mkey] = $_mval;
}
} else {
$this->tpl_vars[$tpl_var]->value[] = $value;
}
}
}
return $this;
}
/** /**
* assigns a global Smarty variable * assigns a global Smarty variable
* *
@@ -98,7 +168,22 @@ class Smarty_Internal_Data
$ptr = $ptr->parent; $ptr = $ptr->parent;
} }
} }
return $this;
}
/**
* appends values to template variables by reference
*
* @param string $tpl_var the template variable name
* @param mixed &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
* chaining
*/
public function appendByRef($tpl_var, &$value, $merge = false)
{
Smarty_Internal_Method_AppendByRef::appendByRef($this, $tpl_var, $value, $merge);
return $this; return $this;
} }
@@ -122,167 +207,173 @@ class Smarty_Internal_Data
return $this; return $this;
} }
/**
* appends values to template variables
*
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param boolean $merge flag if array elements shall be merged
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
* chaining
*/
public function append($tpl_var, $value = null, $merge = false, $nocache = false)
{
Smarty_Internal_Extension_Append::append($this, $tpl_var, $value, $merge, $nocache);
return $this;
}
/**
* appends values to template variables by reference
*
* @param string $tpl_var the template variable name
* @param mixed &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
* chaining
*/
public function appendByRef($tpl_var, &$value, $merge = false)
{
Smarty_Internal_Extension_Append::appendByRef($this, $tpl_var, $value, $merge);
return $this;
}
/** /**
* Returns a single or all template variables * Returns a single or all template variables
* *
* @param string $varname variable name or null * @api Smarty::getTemplateVars()
* @param object $_ptr optional pointer to data object * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl
* @param boolean $search_parents include parent templates?
* *
* @return string variable value or or array of variables * @param string $varname variable name or null
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
* @param bool $search_parents include parent templates?
*
* @return mixed variable value or or array of variables
*/ */
public function getTemplateVars($varname = null, $_ptr = null, $search_parents = true) public function getTemplateVars($varname = null, Smarty_Internal_Data $_ptr = null, $search_parents = true)
{ {
return Smarty_Internal_Extension_GetVars::getTemplateVars($this, $varname, $_ptr, $search_parents); if (isset($varname)) {
} $_var = $this->_getVariable($varname, $_ptr, $search_parents, false);
if (is_object($_var)) {
/** return $_var->value;
* clear the given assigned template variable. } else {
* return null;
* @param string|array $tpl_var the template variable(s) to clear
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
* chaining
*/
public function clearAssign($tpl_var)
{
if (is_array($tpl_var)) {
foreach ($tpl_var as $curr_var) {
unset($this->tpl_vars[$curr_var]);
} }
} else { } else {
unset($this->tpl_vars[$tpl_var]); $_result = array();
if ($_ptr === null) {
$_ptr = $this;
}
while ($_ptr !== null) {
foreach ($_ptr->tpl_vars AS $key => $var) {
if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value;
}
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if ($search_parents && isset(Smarty::$global_tpl_vars)) {
foreach (Smarty::$global_tpl_vars AS $key => $var) {
if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value;
}
}
}
return $_result;
} }
return $this;
} }
/**
* clear all the assigned template variables.
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
* chaining
*/
public function clearAllAssign()
{
$this->tpl_vars = array();
return $this;
}
/**
* load a config file, optionally load just selected sections
*
* @param string $config_file filename
* @param mixed $sections array of section names, single section or null
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
* chaining
*/
public function configLoad($config_file, $sections = null)
{
// load Config class
Smarty_Internal_Extension_Config::configLoad($this, $config_file, $sections);
return $this;
}
/** /**
* gets the object of a Smarty variable * gets the object of a Smarty variable
* *
* @param string $variable the name of the Smarty variable * @param string $variable the name of the Smarty variable
* @param object $_ptr optional pointer to data object * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
* @param boolean $search_parents search also in parent data * @param bool $search_parents search also in parent data
* @param bool $error_enable * @param bool $error_enable
* *
* @return object the object of the variable * @return \Smarty_Variable
*/ */
public function getVariable($variable, $_ptr = null, $search_parents = true, $error_enable = true) public function _getVariable($variable, Smarty_Internal_Data $_ptr = null, $search_parents = true, $error_enable = true)
{ {
return Smarty_Internal_Extension_GetVars::getVariable($this, $variable, $_ptr, $search_parents, $error_enable); if ($_ptr === null) {
$_ptr = $this;
}
while ($_ptr !== null) {
if (isset($_ptr->tpl_vars[$variable])) {
// found it, return it
return $_ptr->tpl_vars[$variable];
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if (isset(Smarty::$global_tpl_vars[$variable])) {
// found it, return it
return Smarty::$global_tpl_vars[$variable];
}
/* @var \Smarty $smarty */
$smarty = isset($this->smarty) ? $this->smarty : $this;
if ($smarty->error_unassigned && $error_enable) {
// force a notice
$x = $$variable;
}
return new Smarty_Undefined_Variable;
} }
/** /**
* gets a config variable * gets a config variable value
* *
* @param string $variable the name of the config variable * @param string $variable the name of the config variable
* @param bool $error_enable * @param bool $error_enable
* *
* @return mixed the value of the config variable * @return mixed the value of the config variable
*/ */
public function getConfigVariable($variable, $error_enable = true) public function _getConfigVariable($variable, $error_enable = true)
{ {
return Smarty_Internal_Extension_Config::getConfigVariable($this, $variable, $error_enable = true); $_ptr = $this;
while ($_ptr !== null) {
if (isset($_ptr->config_vars[$variable])) {
// found it, return it
return $_ptr->config_vars[$variable];
}
// not found, try at parent
$_ptr = $_ptr->parent;
}
/* @var \Smarty $smarty */
$smarty = isset($this->smarty) ? $this->smarty : $this;
if ($smarty->error_unassigned && $error_enable) {
// force a notice
$x = $$variable;
}
return null;
} }
/** /**
* Returns a single or all config variables * Handle unknown class methods
* *
* @param string $varname variable name or null * @param string $name unknown method-name
* @param bool $search_parents * @param array $args argument array
*
* @return string variable value or or array of variables
*/
public function getConfigVars($varname = null, $search_parents = true)
{
return Smarty_Internal_Extension_Config::getConfigVars($this, $varname, $search_parents);
}
/**
* Deassigns a single or all config variables
*
* @param string $varname variable name or null
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
* chaining
*/
public function clearConfig($varname = null)
{
return Smarty_Internal_Extension_Config::clearConfig($this, $varname);
}
/**
* gets a stream variable
*
* @param string $variable the stream of the variable
* *
* @return mixed
* @throws SmartyException * @throws SmartyException
* @return mixed the value of the stream variable
*/ */
public function getStreamVariable($variable) public function __call($name, $args)
{ {
return Smarty_Internal_Extension_GetStreamVar::getStreamVariable($this, $variable); static $_resolved_property_name = array();
if (!isset(Smarty::$extObjCache[$name])) {
$class = 'Smarty_Internal_Method_' . ucfirst($name);
if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) {
if (!isset($this->_property_info[$prop = $match[2]])) {
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (!isset($this->_property_info[$prop])) {
// convert camel case to underscored name
$_resolved_property_name[$prop] = $pn = strtolower(join('_', preg_split('/([A-Z][^A-Z]*)/', $prop, - 1, PREG_SPLIT_NO_EMPTY |
PREG_SPLIT_DELIM_CAPTURE)));
$this->_property_info[$prop] = property_exists($this, $pn) ? 1 : ($this->_objType == 2 &&
property_exists($smarty, $pn) ? 2 : 0);
}
}
if ($this->_property_info[$prop]) {
$pn = $_resolved_property_name[$prop];
if ($match[1] == 'get') {
return $this->_property_info[$prop] == 1 ? $this->$pn : $this->smarty->$pn;
} else {
return $this->_property_info[$prop] ==
1 ? $this->$pn = $args[0] : $this->smarty->$pn = $args[0];
}
} elseif (!class_exists($class)) {
throw new SmartyException("property '$pn' does not exist.");
}
}
if (class_exists($class)) {
$callback = array(Smarty::$extObjCache[$name] = new $class(), $name);
}
} else {
$callback = array(Smarty::$extObjCache[$name], $name);
}
if (isset($callback) && $callback[0]->objMap | $this->_objType) {
array_unshift($args, $this);
return call_user_func_array($callback, $args);
}
throw new SmartyException("method '$name' does not exist.");
} }
} }

View File

@@ -1,160 +0,0 @@
<?php
/**
* @package Smarty
* @subpackage PluginsInternal
*/
class Smarty_Internal_Extension_Config
{
/**
* @param $obj
* @param $config_file
* @param null $sections
* @param string $scope
*/
static function configLoad($obj, $config_file, $sections = null, $scope = 'local')
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$confObj = new $smarty->template_class($config_file, $smarty, $obj);
$confObj->caching = Smarty::CACHING_OFF;
$confObj->source = Smarty_Template_Config::load($confObj);
$confObj->source->config_sections = $sections;
$confObj->source->scope = $scope;
$confObj->compiled = Smarty_Template_Compiled::load($confObj);
if ($confObj->smarty->debugging) {
Smarty_Internal_Debug::start_render($confObj);
}
$confObj->compiled->render($confObj);
if ($confObj->smarty->debugging) {
Smarty_Internal_Debug::end_render($confObj);
}
if ($obj instanceof Smarty_Internal_Template) {
$obj->compiled->file_dependency[$confObj->source->uid] = array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type);
}
}
/**
* load config variables
*
* @param mixed $sections array of section names, single section or null
* @param string $scope global,parent or local
*
* @throws Exception
*/
static function loadConfigVars($_template, $_config_vars)
{
$scope = $_template->source->scope;
// pointer to scope (local scope is parent of template object
$scope_ptr = $_template->parent;
if ($scope == 'parent') {
if (isset($_template->parent->parent)) {
$scope_ptr = $_template->parent->parent;
}
} elseif ($scope == 'root' || $scope == 'global') {
while (isset($scope_ptr->parent)) {
$scope_ptr = $scope_ptr->parent;
}
}
// copy global config vars
foreach ($_config_vars['vars'] as $variable => $value) {
if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
$scope_ptr->config_vars[$variable] = $value;
} else {
$scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
}
}
// scan sections
$sections = $_template->source->config_sections;
if (!empty($sections)) {
foreach ((array) $sections as $_template_section) {
if (isset($_config_vars['sections'][$_template_section])) {
foreach ($_config_vars['sections'][$_template_section]['vars'] as $variable => $value) {
if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
$scope_ptr->config_vars[$variable] = $value;
} else {
$scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
}
}
}
}
}
}
/**
* Returns a single or all config variables
*
* @param string $varname variable name or null
* @param bool $search_parents
*
* @return string variable value or or array of variables
*/
static function getConfigVars($obj, $varname = null, $search_parents = true)
{
$_ptr = $obj;
$var_array = array();
while ($_ptr !== null) {
if (isset($varname)) {
if (isset($_ptr->config_vars[$varname])) {
return $_ptr->config_vars[$varname];
}
} else {
$var_array = array_merge($_ptr->config_vars, $var_array);
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if (isset($varname)) {
return '';
} else {
return $var_array;
}
}
/**
* gets a config variable
*
* @param string $variable the name of the config variable
* @param bool $error_enable
*
* @return mixed the value of the config variable
*/
static function getConfigVariable($obj, $variable, $error_enable = true)
{
$_ptr = $obj;
while ($_ptr !== null) {
if (isset($_ptr->config_vars[$variable])) {
// found it, return it
return $_ptr->config_vars[$variable];
}
// not found, try at parent
$_ptr = $_ptr->parent;
}
if ($obj->error_unassigned && $error_enable) {
// force a notice
$x = $$variable;
}
return null;
}
/**
* remove a single or all config variables
*
* @param string $name variable name or null
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
static function clearConfig($obj, $name = null)
{
if (isset($name)) {
unset($obj->config_vars[$name]);
} else {
$obj->config_vars = array();
}
return $obj;
}
}

View File

@@ -1,84 +0,0 @@
<?php
/**
* Smarty Resource Extension
*
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
*/
/**
* Smarty Resource Extension
* Default template and config file handling
*
* @package Smarty
* @subpackage TemplateResources
*/
class Smarty_Internal_Extension_DefaultTemplateHandler
{
/**
* get default content from template of config resource handler
*
* @param Smarty_Internal_Template $_template
* @param Smarty_Template_Source $source
*/
static function _getDefault(Smarty_Internal_Template $_template, $source)
{
if ($source->isConfig) {
$default_handler = $_template->smarty->default_config_handler_func;
} else {
$default_handler = $_template->smarty->default_template_handler_func;
}
$_content = $_timestamp = null;
$_return = call_user_func_array($default_handler,
array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty));
if (is_string($_return)) {
$source->exists = is_file($_return);
if ($source->exists) {
$source->timestamp = filemtime($_return);
}
$source->filepath = $_return;
} elseif ($_return === true) {
$source->content = $_content;
$source->timestamp = $_timestamp;
$source->exists = true;
$source->recompiled = true;
$source->filepath = false;
}
}
/**
* register template default handler
*
* @param Smarty $smarty
* @param mixed $callback
*
* @throws SmartyException
*/
static function registerDefaultTemplateHandler(Smarty $smarty, $callback)
{
if (is_callable($callback)) {
$smarty->default_template_handler_func = $callback;
} else {
throw new SmartyException("Default template handler not callable");
}
}
/**
* register config default handler
*
* @param Smarty $smarty
* @param mixed $callback
*
* @throws SmartyException
*/
static function registerDefaultConfigHandler(Smarty $smarty, $callback)
{
if (is_callable($callback)) {
$smarty->default_config_handler_func = $callback;
} else {
throw new SmartyException("Default config handler not callable");
}
}
}

View File

@@ -1,150 +0,0 @@
<?php
/**
* Smarty Extension Filter
*
* Register filter methods
* Load filter method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Extension_Filter
{
/**
* Valid filter types
*
* @var array
*/
static $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true);
/**
* Registers a filter function
*
* @param \Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type
* @param callback $callback
* @param string|null $name optional filter name
*
* @throws \SmartyException
*/
static function registerFilter($obj, $type, $callback, $name)
{
self::_checkFilterType($type);
$name = isset($name) ? $name : self::_getFilterName($callback);
if (!is_callable($callback)) {
throw new SmartyException("{$type}filter \"{$name}\" not callable");
}
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty->registered_filters[$type][$name] = $callback;
}
/**
* Unregisters a filter function
*
* @param \Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type
* @param callback|string $callback
*
*/
static function unregisterFilter($obj, $type, $callback)
{
self::_checkFilterType($type);
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (isset($smarty->registered_filters[$type])) {
$name = is_string($callback) ? $callback : self::_getFilterName($callback);
if (isset($smarty->registered_filters[$type][$name])) {
unset($smarty->registered_filters[$type][$name]);
if (empty($smarty->registered_filters[$type])) {
unset($smarty->registered_filters[$type]);
}
}
}
}
/**
* load a filter of specified type and name
*
* @param \Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type
* @param string $name filter name
*
* @return bool
* @throws SmartyException if filter could not be loaded
*/
static function loadFilter($obj, $type, $name)
{
self::_checkFilterType($type);
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$_plugin = "smarty_{$type}filter_{$name}";
$_filter_name = $_plugin;
if ($smarty->loadPlugin($_plugin)) {
if (class_exists($_plugin, false)) {
$_plugin = array($_plugin, 'execute');
}
if (is_callable($_plugin)) {
$smarty->registered_filters[$type][$_filter_name] = $_plugin;
return true;
}
}
throw new SmartyException("{$type}filter \"{$name}\" not callable");
}
/**
* unload a filter of specified type and name
*
* @param \Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type
* @param string $name filter name
*
*/
static function unloadFilter($obj, $type, $name)
{
self::_checkFilterType($type);
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (isset($smarty->registered_filters[$type])) {
$_filter_name = "smarty_{$type}filter_{$name}";
if (isset($smarty->registered_filters[$type][$_filter_name])) {
unset ($smarty->registered_filters[$type][$_filter_name]);
if (empty($smarty->registered_filters[$type])) {
unset($smarty->registered_filters[$type]);
}
}
}
}
/**
* Return internal filter name
*
* @param callback $function_name
*
* @return string internal filter name
*/
static function _getFilterName($function_name)
{
if (is_array($function_name)) {
$_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]);
return $_class_name . '_' . $function_name[1];
} elseif (is_string($function_name)) {
return $function_name;
} else {
return 'closure';
}
}
/**
* Check if filter type is valid
*
* @param string $type
*
* @throws \SmartyException
*/
static function _checkFilterType($type)
{
if (!isset(self::$filterTypes[$type])) {
throw new SmartyException("Illegal filter type \"{$type}\"");
}
}
}

View File

@@ -1,103 +0,0 @@
<?php
/**
* Smarty Extension GetVars
*
* getTemplateVars() and getVariable() methods
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Extension_GetVars
{
/**
* Returns a single or all template variables
*
* @param $obj
* @param string $varname variable name or null
* @param object $_ptr optional pointer to data object
* @param boolean $search_parents include parent templates?
*
* @return string variable value or or array of variables
*/
public static function getTemplateVars($obj, $varname, $_ptr, $search_parents)
{
if (isset($varname)) {
$_var = self::getVariable($obj, $varname, $_ptr, $search_parents, false);
if (is_object($_var)) {
return $_var->value;
} else {
return null;
}
} else {
$_result = array();
if ($_ptr === null) {
$_ptr = $obj;
}
while ($_ptr !== null) {
foreach ($_ptr->tpl_vars AS $key => $var) {
if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value;
}
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if ($search_parents && isset(Smarty::$global_tpl_vars)) {
foreach (Smarty::$global_tpl_vars AS $key => $var) {
if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value;
}
}
}
return $_result;
}
}
/**
* gets the object of a Smarty variable
*
* @param $obj
* @param string $variable the name of the Smarty variable
* @param object $_ptr optional pointer to data object
* @param boolean $search_parents search also in parent data
* @param bool $error_enable
*
* @return object the object of the variable
*/
public static function getVariable($obj, $variable, $_ptr, $search_parents, $error_enable)
{
if ($_ptr === null) {
$_ptr = $obj;
}
while ($_ptr !== null) {
if (isset($_ptr->tpl_vars[$variable])) {
// found it, return it
return $_ptr->tpl_vars[$variable];
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if (isset(Smarty::$global_tpl_vars[$variable])) {
// found it, return it
return Smarty::$global_tpl_vars[$variable];
}
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if ($smarty->error_unassigned && $error_enable) {
// force a notice
$x = $$variable;
}
return new Smarty_Undefined_Variable;
}
}

View File

@@ -1,110 +0,0 @@
<?php
/**
* Smarty Extension Object
*
* Register object methods
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Extension_Object
{
/**
* Registers object to be used in templates
*
* @param \Smarty_Internal_Template|\Smarty $obj
* @param string $object_name
* @param object $object_impl the referenced PHP object to register
* @param array $allowed list of allowed methods (empty = all)
* @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of block-methods
*
* @return \Smarty_Internal_Templatebase
* @throws \SmartyException
*/
static function registerObject($obj, $object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
{
// test if allowed methods callable
if (!empty($allowed)) {
foreach ((array) $allowed as $method) {
if (!is_callable(array($object_impl, $method)) && !property_exists($object_impl, $method)) {
throw new SmartyException("Undefined method or property '$method' in registered object");
}
}
}
// test if block methods callable
if (!empty($block_methods)) {
foreach ((array) $block_methods as $method) {
if (!is_callable(array($object_impl, $method))) {
throw new SmartyException("Undefined method '$method' in registered object");
}
}
}
// register the object
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty->registered_objects[$object_name] = array($object_impl, (array) $allowed, (boolean) $smarty_args,
(array) $block_methods);
}
/**
* return a reference to a registered object
*
* @param \Smarty_Internal_Template|\Smarty $obj
* @param string $name object name
*
* @return object
* @throws \SmartyException if no such object is found
*/
static function getRegisteredObject($obj, $name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (!isset($smarty->registered_objects[$name])) {
throw new SmartyException("'$name' is not a registered object");
}
if (!is_object($smarty->registered_objects[$name][0])) {
throw new SmartyException("registered '$name' is not an object");
}
return $smarty->registered_objects[$name][0];
}
/**
* unregister an object
*
* @param \Smarty_Internal_Template|\Smarty $obj
* @param string $name object name
*
* @return \Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
static function unregisterObject($obj, $name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (isset($smarty->registered_objects[$name])) {
unset($smarty->registered_objects[$name]);
}
}
/**
* Registers static classes to be used in templates
*
* @param \Smarty_Internal_Template|\Smarty $obj
* @param string $class_name
* @param string $class_impl the referenced PHP class to register
*
* @return \Smarty_Internal_Templatebase
* @throws \SmartyException
*/
static function registerClass($obj, $class_name, $class_impl)
{
// test if exists
if (!class_exists($class_impl)) {
throw new SmartyException("Undefined class '$class_impl' in register template class");
}
// register the class
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty->registered_classes[$class_name] = $class_impl;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* Smarty Method AddAutoloadFilters
*
* Smarty::addAutoloadFilters() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_AddAutoloadFilters extends Smarty_Internal_Method_SetAutoloadFilters
{
/**
* Add autoload filters
*
* @api Smarty::setAutoloadFilters()
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param array $filters filters to load automatically
* @param string $type "pre", "output", … specify the
* filter type to set. Defaults to
* none treating $filters' keys as
* the appropriate types
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function addAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if ($type !== null) {
$this->_checkFilterType($type);
if (!empty($smarty->autoload_filters[$type])) {
$smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $filters);
} else {
$smarty->autoload_filters[$type] = (array) $filters;
}
} else {
foreach ((array) $filters as $type => $value) {
$this->_checkFilterType($type);
if (!empty($smarty->autoload_filters[$type])) {
$smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $value);
} else {
$smarty->autoload_filters[$type] = (array) $value;
}
}
}
return $obj;
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* Smarty Method AddDefaultModifiers
*
* Smarty::addDefaultModifiers() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_AddDefaultModifiers
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Add default modifiers
*
* @api Smarty::addDefaultModifiers()
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param array|string $modifiers modifier or list of modifiers
* to add
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function addDefaultModifiers(Smarty_Internal_TemplateBase $obj, $modifiers)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (is_array($modifiers)) {
$this->default_modifiers = array_merge($smarty->default_modifiers, $modifiers);
} else {
$smarty->default_modifiers[] = $modifiers;
}
return $obj;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* Smarty Method Append
*
* Smarty::append() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_Append
{
/**
* Valid for all objects
*
* @var int
*/
public $objMap = 7;
/**
* appends values to template variables
*
* @api Smarty::append()
* @link http://www.smarty.net/docs/en/api.append.tpl
*
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param bool $merge flag if array elements shall be merged
* @param bool $nocache if true any output of this variable will
* be not cached
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
public function append(Smarty_Internal_Data $data, $tpl_var, $value = null, $merge = false, $nocache = false)
{
if (is_array($tpl_var)) {
// $tpl_var is an array, ignore $value
foreach ($tpl_var as $_key => $_val) {
if ($_key != '') {
self::append($data, $_key, $_val, $merge, $nocache);
}
}
} else {
if ($tpl_var != '' && isset($value)) {
if (!isset($data->tpl_vars[$tpl_var])) {
$tpl_var_inst = $data->_getVariable($tpl_var, null, true, false);
if ($tpl_var_inst instanceof Smarty_Undefined_Variable) {
$data->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache);
} else {
$data->tpl_vars[$tpl_var] = clone $tpl_var_inst;
}
}
if (!(is_array($data->tpl_vars[$tpl_var]->value) ||
$data->tpl_vars[$tpl_var]->value instanceof ArrayAccess)
) {
settype($data->tpl_vars[$tpl_var]->value, 'array');
}
if ($merge && is_array($value)) {
foreach ($value as $_mkey => $_mval) {
$data->tpl_vars[$tpl_var]->value[$_mkey] = $_mval;
}
} else {
$data->tpl_vars[$tpl_var]->value[] = $value;
}
}
}
return $data;
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* Smarty Method AppendByRef
*
* Smarty::appendByRef() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_AppendByRef
{
/**
* appends values to template variables by reference
*
* @api Smarty::appendByRef()
* @link http://www.smarty.net/docs/en/api.append.by.ref.tpl
*
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $tpl_var the template variable name
* @param mixed &$value the referenced value to append
* @param bool $merge flag if array elements shall be merged
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
public static function appendByRef(Smarty_Internal_Data $data, $tpl_var, &$value, $merge = false)
{
if ($tpl_var != '' && isset($value)) {
if (!isset($data->tpl_vars[$tpl_var])) {
$data->tpl_vars[$tpl_var] = new Smarty_Variable();
}
if (!is_array($data->tpl_vars[$tpl_var]->value)) {
settype($data->tpl_vars[$tpl_var]->value, 'array');
}
if ($merge && is_array($value)) {
foreach ($value as $_key => $_val) {
$data->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key];
}
} else {
$data->tpl_vars[$tpl_var]->value[] = &$value;
}
}
return $data;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Smarty Method ClearAllAssign
*
* Smarty::clearAllAssign() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_ClearAllAssign
{
/**
* Valid for all objects
*
* @var int
*/
public $objMap = 7;
/**
* clear all the assigned template variables.
*
* @api Smarty::clearAllAssign()
* @link http://www.smarty.net/docs/en/api.clear.all.assign.tpl
*
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
public function clearAllAssign(Smarty_Internal_Data $data)
{
$data->tpl_vars = array();
return $data;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Smarty Method ClearAllCache
*
* Smarty::clearAllCache() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_ClearAllCache
{
/**
* Valid for Smarty object
*
* @var int
*/
public $objMap = 1;
/**
* Empty cache folder
*
* @api Smarty::clearAllCache()
* @link http://www.smarty.net/docs/en/api.clear.all.cache.tpl
*
* @param \Smarty $smarty
* @param integer $exp_time expiration time
* @param string $type resource type
*
* @return integer number of cache files deleted
*/
public function clearAllCache(Smarty $smarty, $exp_time = null, $type = null)
{
// load cache resource and call clearAll
$_cache_resource = Smarty_CacheResource::load($smarty, $type);
Smarty_CacheResource::invalidLoadedCache($smarty);
return $_cache_resource->clearAll($smarty, $exp_time);
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* Smarty Method ClearAssign
*
* Smarty::clearAssign() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_ClearAssign
{
/**
* Valid for all objects
*
* @var int
*/
public $objMap = 7;
/**
* clear the given assigned template variable(s).
*
* @api Smarty::clearAssign()
* @link http://www.smarty.net/docs/en/api.clear.assign.tpl
*
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string|array $tpl_var the template variable(s) to clear
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
public function clearAssign(Smarty_Internal_Data $data, $tpl_var)
{
if (is_array($tpl_var)) {
foreach ($tpl_var as $curr_var) {
unset($data->tpl_vars[$curr_var]);
}
} else {
unset($data->tpl_vars[$tpl_var]);
}
return $data;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* Smarty Method ClearCache
*
* Smarty::clearCache() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_ClearCache
{
/**
* Valid for Smarty object
*
* @var int
*/
public $objMap = 1;
/**
* Empty cache for a specific template
*
* @api Smarty::clearCache()
* @link http://www.smarty.net/docs/en/api.clear.cache.tpl
*
* @param \Smarty $smarty
* @param string $template_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time
* @param string $type resource type
*
* @return integer number of cache files deleted
*/
public function clearCache(Smarty $smarty, $template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
{
// load cache resource and call clear
$_cache_resource = Smarty_CacheResource::load($smarty, $type);
Smarty_CacheResource::invalidLoadedCache($smarty);
return $_cache_resource->clear($smarty, $template_name, $cache_id, $compile_id, $exp_time);
}
}

View File

@@ -1,28 +1,39 @@
<?php <?php
/** /**
* Smarty Extension ClearCompiled * Smarty Method ClearCompiledTemplate
* *
* $smarty->clearCompiledTemplate() method * Smarty::clearCompiledTemplate() method
* *
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @author Uwe Tews * @author Uwe Tews
*/ */
class Smarty_Internal_Extension_ClearCompiled class Smarty_Internal_Method_ClearCompiledTemplate
{ {
/**
* Valid for Smarty object
*
* @var int
*/
public $objMap = 1;
/** /**
* Delete compiled template file * Delete compiled template file
* *
* @param Smarty $smarty Smarty instance * @api Smarty::clearCompiledTemplate()
* @link http://www.smarty.net/docs/en/api.clear.compiled.template.tpl
*
* @param \Smarty $smarty
* @param string $resource_name template name * @param string $resource_name template name
* @param string $compile_id compile id * @param string $compile_id compile id
* @param integer $exp_time expiration time * @param integer $exp_time expiration time
* *
* @return integer number of template files deleted * @return integer number of template files deleted
*/ */
public static function clearCompiledTemplate(Smarty $smarty, $resource_name, $compile_id, $exp_time) public function clearCompiledTemplate(Smarty $smarty, $resource_name = null, $compile_id = null, $exp_time = null)
{ {
$_compile_dir = $smarty->getCompileDir(); $_compile_dir = $smarty->getCompileDir();
if ($_compile_dir == '/') { //We should never want to delete this! if ($_compile_dir == '/') { //We should never want to delete this!
return 0; return 0;
@@ -32,6 +43,7 @@ class Smarty_Internal_Extension_ClearCompiled
if (isset($resource_name)) { if (isset($resource_name)) {
$_save_stat = $smarty->caching; $_save_stat = $smarty->caching;
$smarty->caching = false; $smarty->caching = false;
/* @var Smarty_Internal_Template $tpl */
$tpl = new $smarty->template_class($resource_name, $smarty); $tpl = new $smarty->template_class($resource_name, $smarty);
$smarty->caching = $_save_stat; $smarty->caching = $_save_stat;
if ($tpl->source->exists) { if ($tpl->source->exists) {
@@ -47,7 +59,6 @@ class Smarty_Internal_Extension_ClearCompiled
} else { } else {
return 0; return 0;
} }
$_resource_part_2 = str_replace('.php', '.cache.php', $_resource_part_1); $_resource_part_2 = str_replace('.php', '.cache.php', $_resource_part_1);
$_resource_part_2_length = strlen($_resource_part_2); $_resource_part_2_length = strlen($_resource_part_2);
} }

View File

@@ -0,0 +1,41 @@
<?php
/**
* Smarty Method ClearConfig
*
* Smarty::clearConfig() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_ClearConfig
{
/**
* Valid for all objects
*
* @var int
*/
public $objMap = 7;
/**
* clear a single or all config variables
*
* @api Smarty::clearConfig()
* @link http://www.smarty.net/docs/en/api.clear.config.tpl
*
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string|null $name variable name or null
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
public function clearConfig(Smarty_Internal_Data $data, $name = null)
{
if (isset($name)) {
unset($data->config_vars[$name]);
} else {
$data->config_vars = array();
}
return $data;
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Smarty Method CompileAllConfig
*
* Smarty::compileAllConfig() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_CompileAllConfig extends Smarty_Internal_Method_CompileAllTemplates
{
/**
* Compile all config files
*
* @api Smarty::compileAllConfig()
*
* @param \Smarty $smarty
* @param string $extension file extension
* @param bool $force_compile force all to recompile
* @param int $time_limit
* @param int $max_errors
*
* @return integer number of template files recompiled
*/
public function compileAllConfig(Smarty $smarty, $extension = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null)
{
return $this->compileAll($smarty, $extension, $force_compile, $time_limit, $max_errors, true);
}
}

View File

@@ -1,29 +1,54 @@
<?php <?php
/** /**
* Smarty Extension CompileAll * Smarty Method CompileAllTemplates
* *
* $smarty->clearCompiledTemplate() method * Smarty::compileAllTemplates() method
* *
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @author Uwe Tews * @author Uwe Tews
*/ */
class Smarty_Internal_Extension_CompileAll class Smarty_Internal_Method_CompileAllTemplates
{ {
/**
* Valid for Smarty object
*
* @var int
*/
public $objMap = 1;
/**
* Compile all template files
*
* @api Smarty::compileAllTemplates()
*
* @param \Smarty $smarty
* @param string $extension file extension
* @param bool $force_compile force all to recompile
* @param int $time_limit
* @param int $max_errors
*
* @return integer number of template files recompiled
*/
public function compileAllTemplates(Smarty $smarty, $extension = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
{
return $this->compileAll($smarty, $extension, $force_compile, $time_limit, $max_errors);
}
/** /**
* Compile all template or config files * Compile all template or config files
* *
* @param \Smarty $smarty
* @param string $extension template file name extension * @param string $extension template file name extension
* @param bool $force_compile force all to recompile * @param bool $force_compile force all to recompile
* @param int $time_limit set maximum execution time * @param int $time_limit set maximum execution time
* @param int $max_errors set maximum allowed errors * @param int $max_errors set maximum allowed errors
* @param Smarty $smarty Smarty instance
* @param bool $isConfig flag true if called for config files * @param bool $isConfig flag true if called for config files
* *
* @return int number of template files compiled * @return int number of template files compiled
*/ */
public static function compileAll($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty, $isConfig = false) protected function compileAll(Smarty $smarty, $extension, $force_compile, $time_limit, $max_errors, $isConfig = false)
{ {
// switch off time limit // switch off time limit
if (function_exists('set_time_limit')) { if (function_exists('set_time_limit')) {
@@ -53,6 +78,7 @@ class Smarty_Internal_Extension_CompileAll
$_smarty = clone $smarty; $_smarty = clone $smarty;
$_smarty->force_compile = $force_compile; $_smarty->force_compile = $force_compile;
try { try {
/* @var Smarty_Internal_Template $_tpl */
$_tpl = new $smarty->template_class($_file, $_smarty); $_tpl = new $smarty->template_class($_file, $_smarty);
$_tpl->caching = Smarty::CACHING_OFF; $_tpl->caching = Smarty::CACHING_OFF;
$_tpl->source = $isConfig ? Smarty_Template_Config::load($_tpl) : Smarty_Template_Source::load($_tpl); $_tpl->source = $isConfig ? Smarty_Template_Config::load($_tpl) : Smarty_Template_Source::load($_tpl);

View File

@@ -0,0 +1,107 @@
<?php
/**
* Smarty Method ConfigLoad
*
* Smarty::configLoad() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_ConfigLoad
{
/**
* Valid for all objects
*
* @var int
*/
public $objMap = 7;
/**
* load a config file, optionally load just selected sections
*
* @api Smarty::configLoad()
* @link http://www.smarty.net/docs/en/api.config.load.tpl
*
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $config_file filename
* @param mixed $sections array of section names, single
* section or null
* @param string $scope scope into which config variables
* shall be loaded
*
* @return \Smarty|\Smarty_Internal_Data|\Smarty_Internal_Template
* @throws \SmartyException
*/
public function configLoad(Smarty_Internal_Data $data, $config_file, $sections = null, $scope = 'local')
{
/* @var \Smarty $smarty */
$smarty = isset($data->smarty) ? $data->smarty : $data;
/* @var \Smarty_Internal_Template $confObj */
$confObj = new $smarty->template_class($config_file, $smarty, $data);
$confObj->caching = Smarty::CACHING_OFF;
$confObj->source = Smarty_Template_Config::load($confObj);
$confObj->source->config_sections = $sections;
$confObj->source->scope = $scope;
$confObj->compiled = Smarty_Template_Compiled::load($confObj);
if ($confObj->smarty->debugging) {
Smarty_Internal_Debug::start_render($confObj);
}
$confObj->compiled->render($confObj);
if ($confObj->smarty->debugging) {
Smarty_Internal_Debug::end_render($confObj);
}
if ($data instanceof Smarty_Internal_Template) {
$data->compiled->file_dependency[$confObj->source->uid] = array($confObj->source->filepath,
$confObj->source->getTimeStamp(),
$confObj->source->type);
}
return $data;
}
/**
* load config variables into template object
*
* @param \Smarty_Internal_Template $_template
* @param array $_config_vars
*/
static function _loadConfigVars(Smarty_Internal_Template $_template, $_config_vars)
{
$scope = $_template->source->scope;
// pointer to scope (local scope is parent of template object
$scope_ptr = $_template->parent;
if ($scope == 'parent') {
if (isset($_template->parent->parent)) {
$scope_ptr = $_template->parent->parent;
}
} elseif ($scope == 'root' || $scope == 'global') {
while (isset($scope_ptr->parent)) {
$scope_ptr = $scope_ptr->parent;
}
}
// copy global config vars
foreach ($_config_vars['vars'] as $variable => $value) {
if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
$scope_ptr->config_vars[$variable] = $value;
} else {
$scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
}
}
// scan sections
$sections = $_template->source->config_sections;
if (!empty($sections)) {
foreach ((array) $sections as $_template_section) {
if (isset($_config_vars['sections'][$_template_section])) {
foreach ($_config_vars['sections'][$_template_section]['vars'] as $variable => $value) {
if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
$scope_ptr->config_vars[$variable] = $value;
} else {
$scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
}
}
}
}
}
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* Smarty Method CreateData
*
* Smarty::createData() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_CreateData
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* creates a data object
*
* @api Smarty::createData()
* @link http://www.smarty.net/docs/en/api.create.data.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param \Smarty_Internal_Template|\Smarty_Internal_Data|\Smarty_Data|\Smarty $parent next higher level of Smarty
* variables
* @param string $name optional data block name
*
* @returns Smarty_Data data object
*/
public function createData(Smarty_Internal_TemplateBase $obj, Smarty_Internal_Data $parent = null, $name = null)
{
/* @var Smarty $smarty */
$smarty = isset($this->smarty) ? $this->smarty : $obj;
$dataObj = new Smarty_Data($parent, $smarty, $name);
if ($smarty->debugging) {
Smarty_Internal_Debug::register_data($dataObj);
}
return $dataObj;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Smarty Method GetAutoloadFilters
*
* Smarty::getAutoloadFilters() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_GetAutoloadFilters extends Smarty_Internal_Method_SetAutoloadFilters
{
/**
* Get autoload filters
*
* @api Smarty::getAutoloadFilters()
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type type of filter to get auto loads
* for. Defaults to all autoload
* filters
*
* @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type
* was specified
*/
public function getAutoloadFilters(Smarty_Internal_TemplateBase $obj, $type = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if ($type !== null) {
$this->_checkFilterType($type);
return isset($smarty->autoload_filters[$type]) ? $smarty->autoload_filters[$type] : array();
}
return $smarty->autoload_filters;
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* Smarty Method GetConfigVars
*
* Smarty::getConfigVars() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_GetConfigVars
{
/**
* Valid for all objects
*
* @var int
*/
public $objMap = 7;
/**
* Returns a single or all config variables
*
* @api Smarty::getConfigVars()
* @link http://www.smarty.net/docs/en/api.get.config.vars.tpl
*
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $varname variable name or null
* @param bool $search_parents include parent templates?
*
* @return mixed variable value or or array of variables
*/
public function getConfigVars(Smarty_Internal_Data $data, $varname = null, $search_parents = true)
{
$_ptr = $data;
$var_array = array();
while ($_ptr !== null) {
if (isset($varname)) {
if (isset($_ptr->config_vars[$varname])) {
return $_ptr->config_vars[$varname];
}
} else {
$var_array = array_merge($_ptr->config_vars, $var_array);
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if (isset($varname)) {
return '';
} else {
return $var_array;
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* Smarty Method GetDebugTemplate
*
* Smarty::getDebugTemplate() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_GetDebugTemplate
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* return name of debugging template
*
* @api Smarty::getDebugTemplate()
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
*
* @return string
*/
public function getDebugTemplate(Smarty_Internal_TemplateBase $obj)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
return $smarty->debug_tpl;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* Smarty Method GetDefaultModifiers
*
* Smarty::getDefaultModifiers() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_GetDefaultModifiers
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Get default modifiers
*
* @api Smarty::getDefaultModifiers()
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
*
* @return array list of default modifiers
*/
public function getDefaultModifiers(Smarty_Internal_TemplateBase $obj)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
return $smarty->default_modifiers;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* Smarty Method GetRegisteredObject
*
* Smarty::getRegisteredObject() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_GetRegisteredObject
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* return a reference to a registered object
*
* @api Smarty::getRegisteredObject()
* @link http://www.smarty.net/docs/en/api.get.registered.object.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $object_name object name
*
* @return object
* @throws \SmartyException if no such object is found
*/
public function getRegisteredObject(Smarty_Internal_TemplateBase $obj, $object_name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (!isset($smarty->registered_objects[$object_name])) {
throw new SmartyException("'$object_name' is not a registered object");
}
if (!is_object($smarty->registered_objects[$object_name][0])) {
throw new SmartyException("registered '$object_name' is not an object");
}
return $smarty->registered_objects[$object_name][0];
}
}

View File

@@ -1,26 +1,35 @@
<?php <?php
/** /**
* Smarty Extension GetStreamVar * Smarty Method GetStreamVariable
* *
* getStreamVariable() method * Smarty::getStreamVariable() method
* *
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @author Uwe Tews * @author Uwe Tews
*/ */
class Smarty_Internal_Extension_GetStreamVar class Smarty_Internal_Method_GetStreamVariable
{ {
/**
* Valid for all objects
*
* @var int
*/
public $objMap = 7;
/** /**
* gets a stream variable * gets a stream variable
* *
* @param $obj * @api Smarty::getStreamVariable()
* @param string $variable the stream of the variable *
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $variable the stream of the variable
* *
* @return mixed * @return mixed
* @throws \SmartyException * @throws \SmartyException
*/ */
public static function getStreamVariable($obj, $variable) public function getStreamVariable(Smarty_Internal_Data $data, $variable)
{ {
$_result = ''; $_result = '';
$fp = fopen($variable, 'r+'); $fp = fopen($variable, 'r+');
@@ -32,7 +41,7 @@ class Smarty_Internal_Extension_GetStreamVar
return $_result; return $_result;
} }
$smarty = isset($obj->smarty) ? $obj->smarty : $obj; $smarty = isset($data->smarty) ? $data->smarty : $data;
if ($smarty->error_unassigned) { if ($smarty->error_unassigned) {
throw new SmartyException('Undefined stream variable "' . $variable . '"'); throw new SmartyException('Undefined stream variable "' . $variable . '"');
} else { } else {

View File

@@ -0,0 +1,61 @@
<?php
/**
* Smarty Method GetTags
*
* Smarty::getTags() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_GetTags
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Return array of tag/attributes of all tags used by an template
*
* @api Smarty::getTags()
* @link http://www.smarty.net/docs/en/api.get.tags.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param null|string|Smarty_Internal_Template $template
*
* @return array of tag/attributes
* @throws \SmartyException
*/
public function getTags(Smarty_Internal_TemplateBase $obj, $template = null)
{
/* @var Smarty $smarty */
$smarty = isset($this->smarty) ? $this->smarty : $obj;
if ($obj instanceof Smarty_Internal_Template && !isset($template)) {
$tpl = clone $obj;
} elseif (isset($template) && $template instanceof Smarty_Internal_Template) {
$tpl = clone $template;
} elseif (isset($template) && is_string($template)) {
/* @var Smarty_Internal_Template $tpl */
$tpl = new $smarty->template_class($template, $smarty);
// checks if template exists
if (!$tpl->source->exists) {
throw new SmartyException("Unable to load template {$tpl->source->type} '{$tpl->source->name}'");
}
}
if (isset($tpl)) {
$tpl->smarty = clone $tpl->smarty;
$tpl->smarty->get_used_tags = true;
$tpl->smarty->merge_compiled_includes = false;
$tpl->smarty->disableSecurity();
$tpl->caching = false;
$tpl->loadCompiler();
$tpl->compiler->compileTemplate($tpl);
return $tpl->used_tags;
}
throw new SmartyException("Missing template specification");
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* Smarty Method GetTemplateVars
*
* Smarty::getTemplateVars() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_GetTemplateVars
{
/**
* Valid for all objects
*
* @var int
*/
public $objMap = 7;
/**
* Returns a single or all template variables
*
* @api Smarty::getTemplateVars()
* @link http://www.smarty.net/docs/en/api.get.template.vars.tpl
*
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $varname variable name or null
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
* @param bool $search_parents include parent templates?
*
* @return mixed variable value or or array of variables
*/
public function getTemplateVars(Smarty_Internal_Data $data, $varname = null, Smarty_Internal_Data $_ptr = null, $search_parents = true)
{
if (isset($varname)) {
$_var = $data->_getVariable($varname, $_ptr, $search_parents, false);
if (is_object($_var)) {
return $_var->value;
} else {
return null;
}
} else {
$_result = array();
if ($_ptr === null) {
$_ptr = $data;
}
while ($_ptr !== null) {
foreach ($_ptr->tpl_vars AS $key => $var) {
if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value;
}
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if ($search_parents && isset(Smarty::$global_tpl_vars)) {
foreach (Smarty::$global_tpl_vars AS $key => $var) {
if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value;
}
}
}
return $_result;
}
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* Smarty Method LoadFilter
*
* Smarty::loadFilter() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_LoadFilter
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Valid filter types
*
* @var array
*/
private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true);
/**
* load a filter of specified type and name
*
* @api Smarty::loadFilter()
*
* @link http://www.smarty.net/docs/en/api.load.filter.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type
* @param string $name filter name
*
* @return bool
* @throws SmartyException if filter could not be loaded
*/
public function loadFilter(Smarty_Internal_TemplateBase $obj, $type, $name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$this->_checkFilterType($type);
$_plugin = "smarty_{$type}filter_{$name}";
$_filter_name = $_plugin;
if (is_callable($_plugin)) {
$smarty->registered_filters[$type][$_filter_name] = $_plugin;
return true;
}
if ($smarty->loadPlugin($_plugin)) {
if (class_exists($_plugin, false)) {
$_plugin = array($_plugin, 'execute');
}
if (is_callable($_plugin)) {
$smarty->registered_filters[$type][$_filter_name] = $_plugin;
return true;
}
}
throw new SmartyException("{$type}filter \"{$name}\" not found or callable");
}
/**
* Check if filter type is valid
*
* @param string $type
*
* @throws \SmartyException
*/
public function _checkFilterType($type)
{
if (!isset($this->filterTypes[$type])) {
throw new SmartyException("Illegal filter type \"{$type}\"");
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Smarty Method UnloadFilter
*
* Smarty_Internal_Template::mustCompile() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_MustCompile
{
/**
* Valid for template object
*
* @var int
*/
public $objMap = 2;
/**
* Returns if the current template must be compiled by the Smarty compiler
* It does compare the timestamps of template source and the compiled templates and checks the force compile
* configuration
*
* @param \Smarty_Internal_Template $_template
*
* @return bool
* @throws \SmartyException
*/
public function mustCompile(Smarty_Internal_Template $_template)
{
if (!$_template->source->exists) {
if ($_template->parent instanceof Smarty_Internal_Template) {
$parent_resource = " in '$_template->parent->template_resource}'";
} else {
$parent_resource = '';
}
throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}");
}
if ($_template->mustCompile === null) {
$_template->mustCompile = (!$_template->source->uncompiled &&
($_template->smarty->force_compile || $_template->source->recompiled || !$_template->compiled->exists ||
($_template->smarty->compile_check && $_template->compiled->getTimeStamp() < $_template->source->getTimeStamp())));
}
return $_template->mustCompile;
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* Smarty Method RegisterCacheResource
*
* Smarty::registerCacheResource() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_RegisterCacheResource
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Registers a resource to fetch a template
*
* @api Smarty::registerCacheResource()
* @link http://www.smarty.net/docs/en/api.register.cacheresource.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $name name of resource type
* @param \Smarty_CacheResource $resource_handler
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function registerCacheResource(Smarty_Internal_TemplateBase $obj, $name, Smarty_CacheResource $resource_handler)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty->registered_cache_resources[$name] = $resource_handler;
return $obj;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* Smarty Method RegisterClass
*
* Smarty::registerClass() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_RegisterClass
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Registers static classes to be used in templates
*
* @api Smarty::registerClass()
* @link http://www.smarty.net/docs/en/api.register.class.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $class_name
* @param string $class_impl the referenced PHP class to
* register
*
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
*/
public function registerClass(Smarty_Internal_TemplateBase $obj, $class_name, $class_impl)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
// test if exists
if (!class_exists($class_impl)) {
throw new SmartyException("Undefined class '$class_impl' in register template class");
}
// register the class
$smarty->registered_classes[$class_name] = $class_impl;
return $obj;
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* Smarty Method RegisterDefaultConfigHandler
*
* Smarty::registerDefaultConfigHandler() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_RegisterDefaultConfigHandler
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Register config default handler
*
* @api Smarty::registerDefaultConfigHandler()
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param callable $callback class/method name
*
* @return \Smarty|\Smarty_Internal_Template
* @throws SmartyException if $callback is not callable
*/
public function registerDefaultConfigHandler(Smarty_Internal_TemplateBase $obj, $callback)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (is_callable($callback)) {
$smarty->default_config_handler_func = $callback;
} else {
throw new SmartyException("Default config handler not callable");
}
return $obj;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* Smarty Method RegisterDefaultPluginHandler
*
* Smarty::registerDefaultPluginHandler() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_RegisterDefaultPluginHandler
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Registers a default plugin handler
*
* @api Smarty::registerDefaultPluginHandler()
* @link http://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param callable $callback class/method name
*
* @return \Smarty|\Smarty_Internal_Template
* @throws SmartyException if $callback is not callable
*/
public function registerDefaultPluginHandler(Smarty_Internal_TemplateBase $obj, $callback)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (is_callable($callback)) {
$smarty->default_plugin_handler_func = $callback;
} else {
throw new SmartyException("Default plugin handler '$callback' not callable");
}
return $obj;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* Smarty Method RegisterDefaultTemplateHandler
*
* Smarty::registerDefaultTemplateHandler() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_RegisterDefaultTemplateHandler
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Register template default handler
*
* @api Smarty::registerDefaultTemplateHandler()
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param callable $callback class/method name
*
* @return \Smarty|\Smarty_Internal_Template
* @throws SmartyException if $callback is not callable
*/
public function registerDefaultTemplateHandler(Smarty_Internal_TemplateBase $obj, $callback)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (is_callable($callback)) {
$smarty->default_template_handler_func = $callback;
} else {
throw new SmartyException("Default template handler not callable");
}
return $obj;
}
/**
* get default content from template or config resource handler
*
* @param Smarty_Template_Source $source
*/
public static function _getDefaultTemplate(Smarty_Template_Source $source)
{
if ($source->isConfig) {
$default_handler = $source->smarty->default_config_handler_func;
} else {
$default_handler = $source->smarty->default_template_handler_func;
}
$_content = $_timestamp = null;
$_return = call_user_func_array($default_handler, array($source->type, $source->name, &$_content, &$_timestamp,
$source->smarty));
if (is_string($_return)) {
$source->exists = is_file($_return);
if ($source->exists) {
$source->timestamp = filemtime($_return);
}
$source->filepath = $_return;
} elseif ($_return === true) {
$source->content = $_content;
$source->timestamp = $_timestamp;
$source->exists = true;
$source->recompiled = true;
$source->filepath = false;
}
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* Smarty Method RegisterFilter
*
* Smarty::registerFilter() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_RegisterFilter
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Valid filter types
*
* @var array
*/
private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true);
/**
* Registers a filter function
*
* @api Smarty::registerFilter()
*
* @link http://www.smarty.net/docs/en/api.register.filter.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type
* @param callback $callback
* @param string|null $name optional filter name
*
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
*/
public function registerFilter(Smarty_Internal_TemplateBase $obj, $type, $callback, $name = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$this->_checkFilterType($type);
$name = isset($name) ? $name : $this->_getFilterName($callback);
if (!is_callable($callback)) {
throw new SmartyException("{$type}filter \"{$name}\" not callable");
}
$smarty->registered_filters[$type][$name] = $callback;
return $obj;
}
/**
* Return internal filter name
*
* @param callback $function_name
*
* @return string internal filter name
*/
public function _getFilterName($function_name)
{
if (is_array($function_name)) {
$_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]);
return $_class_name . '_' . $function_name[1];
} elseif (is_string($function_name)) {
return $function_name;
} else {
return 'closure';
}
}
/**
* Check if filter type is valid
*
* @param string $type
*
* @throws \SmartyException
*/
public function _checkFilterType($type)
{
if (!isset($this->filterTypes[$type])) {
throw new SmartyException("Illegal filter type \"{$type}\"");
}
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* Smarty Method RegisterObject
*
* Smarty::registerObject() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_RegisterObject
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Registers object to be used in templates
*
* @api Smarty::registerObject()
* @link http://www.smarty.net/docs/en/api.register.object.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $object_name
* @param object $object the
* referenced
* PHP object to
* register
* @param array $allowed_methods_properties list of
* allowed
* methods
* (empty = all)
* @param bool $format smarty
* argument
* format, else
* traditional
* @param array $block_methods list of
* block-methods
*
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
*/
public function registerObject(Smarty_Internal_TemplateBase $obj, $object_name, $object, $allowed_methods_properties = array(), $format = true, $block_methods = array())
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
// test if allowed methods callable
if (!empty($allowed_methods_properties)) {
foreach ((array) $allowed_methods_properties as $method) {
if (!is_callable(array($object, $method)) && !property_exists($object, $method)) {
throw new SmartyException("Undefined method or property '$method' in registered object");
}
}
}
// test if block methods callable
if (!empty($block_methods)) {
foreach ((array) $block_methods as $method) {
if (!is_callable(array($object, $method))) {
throw new SmartyException("Undefined method '$method' in registered object");
}
}
}
// register the object
$smarty->registered_objects[$object_name] = array($object, (array) $allowed_methods_properties,
(boolean) $format, (array) $block_methods);
return $obj;
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Smarty Method RegisterPlugin
*
* Smarty::registerPlugin() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_RegisterPlugin
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Registers plugin to be used in templates
*
* @api Smarty::registerPlugin()
* @link http://www.smarty.net/docs/en/api.register.plugin.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type plugin type
* @param string $name name of template tag
* @param callback $callback PHP callback to register
* @param bool $cacheable if true (default) this
* function is cache able
* @param mixed $cache_attr caching attributes if any
*
* @return \Smarty|\Smarty_Internal_Template
* @throws SmartyException when the plugin tag is invalid
*/
public function registerPlugin(Smarty_Internal_TemplateBase $obj, $type, $name, $callback, $cacheable = true, $cache_attr = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (isset($smarty->registered_plugins[$type][$name])) {
throw new SmartyException("Plugin tag \"{$name}\" already registered");
} elseif (!is_callable($callback)) {
throw new SmartyException("Plugin \"{$name}\" not callable");
} else {
$smarty->registered_plugins[$type][$name] = array($callback, (bool) $cacheable, (array) $cache_attr);
}
return $obj;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* Smarty Method RegisterResource
*
* Smarty::registerResource() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_RegisterResource
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Registers a resource to fetch a template
*
* @api Smarty::registerResource()
* @link http://www.smarty.net/docs/en/api.register.resource.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $name name of resource type
* @param Smarty_Resource|array $resource_handler or instance of
* Smarty_Resource, or
* array of callbacks to
* handle resource
* (deprecated)
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function registerResource(Smarty_Internal_TemplateBase $obj, $name, $resource_handler)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty->registered_resources[$name] = $resource_handler instanceof
Smarty_Resource ? $resource_handler : array($resource_handler, false);
return $obj;
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* Smarty Method SetAutoloadFilters
*
* Smarty::setAutoloadFilters() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_SetAutoloadFilters
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Valid filter types
*
* @var array
*/
private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true);
/**
* Set autoload filters
*
* @api Smarty::setAutoloadFilters()
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param array $filters filters to load automatically
* @param string $type "pre", "output", … specify the
* filter type to set. Defaults to
* none treating $filters' keys as
* the appropriate types
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function setAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if ($type !== null) {
$this->_checkFilterType($type);
$smarty->autoload_filters[$type] = (array) $filters;
} else {
foreach ((array) $filters as $type => $value) {
$this->_checkFilterType($type);
}
$smarty->autoload_filters = (array) $filters;
}
return $obj;
}
/**
* Check if filter type is valid
*
* @param string $type
*
* @throws \SmartyException
*/
public function _checkFilterType($type)
{
if (!isset($this->filterTypes[$type])) {
throw new SmartyException("Illegal filter type \"{$type}\"");
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Smarty Method SetDebugTemplate
*
* Smarty::setDebugTemplate() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_SetDebugTemplate
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* set the debug template
*
* @api Smarty::setDebugTemplate()
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $tpl_name
*
* @return \Smarty|\Smarty_Internal_Template
* @throws SmartyException if file is not readable
*/
public function setDebugTemplate(Smarty_Internal_TemplateBase $obj, $tpl_name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (!is_readable($tpl_name)) {
throw new SmartyException("Unknown file '{$tpl_name}'");
}
$smarty->debug_tpl = $tpl_name;
return $obj;
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* Smarty Method SetDefaultModifiers
*
* Smarty::setDefaultModifiers() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_SetDefaultModifiers
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Set default modifiers
*
* @api Smarty::setDefaultModifiers()
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param array|string $modifiers modifier or list of modifiers
* to set
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function setDefaultModifiers(Smarty_Internal_TemplateBase $obj, $modifiers)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty->default_modifiers = (array) $modifiers;
return $obj;
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* Smarty Method UnloadFilter
*
* Smarty::unloadFilter() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_UnloadFilter extends Smarty_Internal_Method_LoadFilter
{
/**
* load a filter of specified type and name
*
* @api Smarty::unloadFilter()
*
* @link http://www.smarty.net/docs/en/api.unload.filter.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type
* @param string $name filter name
*
* @return bool
*/
public function unloadFilter(Smarty_Internal_TemplateBase $obj, $type, $name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$this->_checkFilterType($type);
if (isset($smarty->registered_filters[$type])) {
$_filter_name = "smarty_{$type}filter_{$name}";
if (isset($smarty->registered_filters[$type][$_filter_name])) {
unset ($smarty->registered_filters[$type][$_filter_name]);
if (empty($smarty->registered_filters[$type])) {
unset($smarty->registered_filters[$type]);
}
}
}
return $obj;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Smarty Method UnregisterCacheResource
*
* Smarty::unregisterCacheResource() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_UnregisterCacheResource
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Registers a resource to fetch a template
*
* @api Smarty::unregisterCacheResource()
* @link http://www.smarty.net/docs/en/api.unregister.cacheresource.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type name of cache resource type
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function unregisterCacheResource(Smarty_Internal_TemplateBase $obj, $name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (isset($smarty->registered_cache_resources[$name])) {
unset($smarty->registered_cache_resources[$name]);
}
return $obj;
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* Smarty Method UnregisterFilter
*
* Smarty::unregisterFilter() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_UnregisterFilter extends Smarty_Internal_Method_RegisterFilter
{
/**
* Unregisters a filter function
*
* @api Smarty::unregisterFilter()
*
* @link http://www.smarty.net/docs/en/api.unregister.filter.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type
* @param callback|string $callback
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function unregisterFilter(Smarty_Internal_TemplateBase $obj, $type, $callback)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$this->_checkFilterType($type);
if (isset($smarty->registered_filters[$type])) {
$name = is_string($callback) ? $callback : $this->_getFilterName($callback);
if (isset($smarty->registered_filters[$type][$name])) {
unset($smarty->registered_filters[$type][$name]);
if (empty($smarty->registered_filters[$type])) {
unset($smarty->registered_filters[$type]);
}
}
}
return $obj;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Smarty Method UnregisterObject
*
* Smarty::unregisterObject() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_UnregisterObject
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Registers plugin to be used in templates
*
* @api Smarty::unregisterObject()
* @link http://www.smarty.net/docs/en/api.unregister.object.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $object_name name of object
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function unregisterObject(Smarty_Internal_TemplateBase $obj, $object_name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (isset($smarty->registered_objects[$object_name])) {
unset($smarty->registered_objects[$object_name]);
}
return $obj;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Smarty Method UnregisterPlugin
*
* Smarty::unregisterPlugin() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_UnregisterPlugin
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Registers plugin to be used in templates
*
* @api Smarty::unregisterPlugin()
* @link http://www.smarty.net/docs/en/api.unregister.plugin.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type plugin type
* @param string $name name of template tag
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function unregisterPlugin(Smarty_Internal_TemplateBase $obj, $type, $name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (isset($smarty->registered_plugins[$type][$name])) {
unset($smarty->registered_plugins[$type][$name]);
}
return $obj;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Smarty Method UnregisterResource
*
* Smarty::unregisterResource() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Method_UnregisterResource
{
/**
* Valid for Smarty and template object
*
* @var int
*/
public $objMap = 3;
/**
* Registers a resource to fetch a template
*
* @api Smarty::unregisterResource()
* @link http://www.smarty.net/docs/en/api.unregister.resource.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type name of resource type
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function unregisterResource(Smarty_Internal_TemplateBase $obj, $type)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (isset($smarty->registered_resources[$type])) {
unset($smarty->registered_resources[$type]);
}
return $obj;
}
}

View File

@@ -17,9 +17,17 @@
* @property Smarty_Template_Source|Smarty_Template_Config $source * @property Smarty_Template_Source|Smarty_Template_Config $source
* @property Smarty_Template_Compiled $compiled * @property Smarty_Template_Compiled $compiled
* @property Smarty_Template_Cached $cached * @property Smarty_Template_Cached $cached
* @method bool mustCompile()
*/ */
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
{ {
/**
* This object type (Smarty = 1, template = 2, data = 4)
*
* @var int
*/
public $_objType = 2;
/** /**
* Global smarty instance * Global smarty instance
* *
@@ -399,33 +407,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
} }
} }
/**
* Returns if the current template must be compiled by the Smarty compiler
* It does compare the timestamps of template source and the compiled templates and checks the force compile
* configuration
*
* @throws SmartyException
* @return boolean true if the template must be compiled
*/
public function mustCompile()
{
if (!$this->source->exists) {
if ($this->parent instanceof Smarty_Internal_Template) {
$parent_resource = " in '$this->parent->template_resource}'";
} else {
$parent_resource = '';
}
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
}
if ($this->mustCompile === null) {
$this->mustCompile = (!$this->source->uncompiled &&
($this->smarty->force_compile || $this->source->recompiled || !$this->compiled->exists ||
($this->smarty->compile_check && $this->compiled->getTimeStamp() < $this->source->getTimeStamp())));
}
return $this->mustCompile;
}
/** /**
* Compiles the template * Compiles the template
* If the template is not evaluated the compiled template is saved on disk * If the template is not evaluated the compiled template is saved on disk
@@ -806,20 +787,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
throw new SmartyException("Not matching {capture} open/close in \"{$this->template_resource}\""); throw new SmartyException("Not matching {capture} open/close in \"{$this->template_resource}\"");
} }
/**
* Empty cache for this template
*
* @param integer $exp_time expiration time
*
* @return integer number of cache files deleted
*/
public function clearCache($exp_time = null)
{
Smarty_CacheResource::invalidLoadedCache($this->smarty);
return $this->cached->handler->clear($this->smarty, $this->template_resource, $this->cache_id, $this->compile_id, $exp_time);
}
/** /**
* Load compiled object * Load compiled object
* *

View File

@@ -11,8 +11,36 @@
/** /**
* Class with shared template methods * Class with shared template methods
* *
* @package Smarty * @package Smarty
* @subpackage Template * @subpackage Template
*
* @method Smarty_Internal_TemplateBase setAutoloadFilters(mixed $filters, string $type = null)
* @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null)
* @method array getAutoloadFilters(string $type = null)
* @local_method Smarty_Internal_TemplateBase registerFilter(string $type, callback $callback, string $name = null)
* @method Smarty_Internal_TemplateBase unregisterFilter(string $type, mixed $callback)
* @local_method bool loadFilter(string $type, string $name)
* @method Smarty_Internal_TemplateBase unloadFilter(string $type, string $name)
* @method string getDebugTemplate()
* @method Smarty_Internal_TemplateBase setDebugTemplate(string $tpl_name)
* @method Smarty_Internal_TemplateBase setDefaultModifier(mixed $modifiers)
* @method Smarty_Internal_TemplateBase addDefaultModifier(mixed $modifiers)
* @method array getDefaultModifier()
* @method Smarty_Internal_TemplateBase registerDefaultPluginHandler(callback $callback)
* @method Smarty_Internal_TemplateBase registerResource(string $name, Smarty_Resource $resource_handler)
* @method Smarty_Internal_TemplateBase unregisterResource(string $name)
* @method Smarty_Internal_TemplateBase registerCacheResource(string $name, Smarty_CacheResource $resource_handler)
* @method Smarty_Internal_TemplateBase unregisterCacheResource(string $name)
* @local_method Smarty_Internal_TemplateBase registerPlugin(string $type, string $name, callback $callback, bool
* $cacheable = true, mixed $cache_attr = null)
* @method Smarty_Internal_TemplateBase unregisterPlugin(string $type, string $name)
* @local_method Smarty_Internal_TemplateBase registerObject(string $object_name, object $object, array
* $allowed_methods_properties = array(), bool $format = true, array $block_methods = array())
* @method Smarty_Internal_TemplateBase unregisterObject(string $object_name)
* @method object getRegisteredObject(string $object_name)
* @method Smarty_Internal_TemplateBase registerClass(string $class_name, string $class_impl)
* @method Smarty_Internal_TemplateBase createData(Smarty_Internal_Data $parent = null, string $name = null)
* @method array getTags(mixed $template = null)
*/ */
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
{ {
@@ -46,9 +74,171 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
*/ */
public $cache_lifetime = 3600; public $cache_lifetime = 3600;
/**
* Registers plugin to be used in templates
* NOTE: this method can be safely removed for dynamic loading
*
* @api Smarty::registerPlugin()
* @link http://www.smarty.net/docs/en/api.register.plugin.tpl
*
* @param string $type plugin type
* @param string $name name of template tag
* @param callback $callback PHP callback to register
* @param bool $cacheable if true (default) this function is cache able
* @param mixed $cache_attr caching attributes if any
*
* @return \Smarty|\Smarty_Internal_Template
* @throws SmartyException when the plugin tag is invalid
*/
public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null)
{
/* @var Smarty $smarty */
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (isset($smarty->registered_plugins[$type][$name])) {
throw new SmartyException("Plugin tag \"{$name}\" already registered");
} elseif (!is_callable($callback)) {
throw new SmartyException("Plugin \"{$name}\" not callable");
} else {
$smarty->registered_plugins[$type][$name] = array($callback, (bool) $cacheable, (array) $cache_attr);
}
return $this;
}
/**
* load a filter of specified type and name
* NOTE: this method can be safely removed for dynamic loading
*
* @api Smarty::loadFilter()
* @link http://www.smarty.net/docs/en/api.load.filter.tpl
*
* @param string $type filter type
* @param string $name filter name
*
* @return bool
* @throws SmartyException if filter could not be loaded
*/
public function loadFilter($type, $name)
{
/* @var Smarty $smarty */
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (!in_array($type, array('pre', 'post', 'output', 'variable'))) {
throw new SmartyException("Illegal filter type \"{$type}\"");
}
$_plugin = "smarty_{$type}filter_{$name}";
$_filter_name = $_plugin;
if (is_callable($_plugin)) {
$smarty->registered_filters[$type][$_filter_name] = $_plugin;
return true;
}
if ($smarty->loadPlugin($_plugin)) {
if (class_exists($_plugin, false)) {
$_plugin = array($_plugin, 'execute');
}
if (is_callable($_plugin)) {
$smarty->registered_filters[$type][$_filter_name] = $_plugin;
return true;
}
}
throw new SmartyException("{$type}filter \"{$name}\" not found or callable");
}
/**
* Registers a filter function
* NOTE: this method can be safely removed for dynamic loading
*
* @api Smarty::registerFilter()
* @link http://www.smarty.net/docs/en/api.register.filter.tpl
*
* @param string $type filter type
* @param callback $callback
* @param string|null $name optional filter name
*
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
*/
public function registerFilter($type, $callback, $name = null)
{
/* @var Smarty $smarty */
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (!in_array($type, array('pre', 'post', 'output', 'variable'))) {
throw new SmartyException("Illegal filter type \"{$type}\"");
}
$name = isset($name) ? $name : $this->_getFilterName($callback);
if (!is_callable($callback)) {
throw new SmartyException("{$type}filter \"{$name}\" not callable");
}
$smarty->registered_filters[$type][$name] = $callback;
return $this;
}
/**
* Return internal filter name
*
* @param callback $function_name
*
* @return string internal filter name
*/
public function _getFilterName($function_name)
{
if (is_array($function_name)) {
$_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]);
return $_class_name . '_' . $function_name[1];
} elseif (is_string($function_name)) {
return $function_name;
} else {
return 'closure';
}
}
/**
* Registers object to be used in templates
* NOTE: this method can be safely removed for dynamic loading
*
* @api Smarty::registerObject()
* @link http://www.smarty.net/docs/en/api.register.object.tpl
*
* @param string $object_name
* @param object $object the referenced PHP object to register
* @param array $allowed_methods_properties list of allowed methods (empty = all)
* @param bool $format smarty argument format, else traditional
* @param array $block_methods list of block-methods
*
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
*/
public function registerObject($object_name, $object, $allowed_methods_properties = array(), $format = true, $block_methods = array())
{
/* @var Smarty $smarty */
$smarty = isset($this->smarty) ? $this->smarty : $this;
// test if allowed methods callable
if (!empty($allowed_methods_properties)) {
foreach ((array) $allowed_methods_properties as $method) {
if (!is_callable(array($object, $method)) && !property_exists($object, $method)) {
throw new SmartyException("Undefined method or property '$method' in registered object");
}
}
}
// test if block methods callable
if (!empty($block_methods)) {
foreach ((array) $block_methods as $method) {
if (!is_callable(array($object, $method))) {
throw new SmartyException("Undefined method '$method' in registered object");
}
}
}
// register the object
$smarty->registered_objects[$object_name] = array($object, (array) $allowed_methods_properties,
(boolean) $format, (array) $block_methods);
return $this;
}
/** /**
* test if cache is valid * test if cache is valid
* *
* @api Smarty::isCached()
* @link http://www.smarty.net/docs/en/api.is.cached.tpl
*
* @param string|\Smarty_Internal_Template $template the resource handle of the template file or template object * @param string|\Smarty_Internal_Template $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template * @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template * @param mixed $compile_id compile id to be used with this template
@@ -65,6 +255,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
if ($parent === null) { if ($parent === null) {
$parent = $this; $parent = $this;
} }
/* @var Smarty $smarty */
$smarty = isset($this->smarty) ? $this->smarty : $this; $smarty = isset($this->smarty) ? $this->smarty : $this;
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
} }
@@ -77,408 +268,36 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
} }
/** /**
* creates a data object * @param boolean $caching
*
* @param object $parent next higher level of Smarty variables
* @param string $name optional data block name
*
* @returns Smarty_Data data object
*/ */
public function createData($parent = null, $name = null) public function setCaching($caching)
{ {
$dataObj = new Smarty_Data($parent, $this, $name); $this->caching = $caching;
if ($this->debugging) {
Smarty_Internal_Debug::register_data($dataObj);
}
return $dataObj;
} }
/** /**
* Get unique template id * @param int $cache_lifetime
*
* @param string $template_name
* @param null|mixed $cache_id
* @param null|mixed $compile_id
*
* @return string
*/ */
public function getTemplateId($template_name, $cache_id = null, $compile_id = null) public function setCacheLifetime($cache_lifetime)
{ {
$cache_id = isset($cache_id) ? $cache_id : $this->cache_id; $this->cache_lifetime = $cache_lifetime;
$compile_id = isset($compile_id) ? $compile_id : $this->compile_id;
$smarty = isset($this->smarty) ? $this->smarty : $this;
if ($smarty->allow_ambiguous_resources) {
$_templateId = Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}";
} else {
$_templateId = $smarty->joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}";
}
if (isset($_templateId[150])) {
$_templateId = sha1($_templateId);
}
return $_templateId;
} }
/** /**
* Registers plugin to be used in templates * @param string $compile_id
*
* @param string $type plugin type
* @param string $tag name of template tag
* @param callback $callback PHP callback to register
* @param boolean $cacheable if true (default) this function is cache able
* @param array $cache_attr caching attributes if any
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
* @throws SmartyException when the plugin tag is invalid
*/ */
public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null) public function setCompileId($compile_id)
{ {
$smarty = isset($this->smarty) ? $this->smarty : $this; $this->compile_id = $compile_id;
if (isset($smarty->registered_plugins[$type][$tag])) {
throw new SmartyException("Plugin tag \"{$tag}\" already registered");
} elseif (!is_callable($callback)) {
throw new SmartyException("Plugin \"{$tag}\" not callable");
} else {
$smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr);
}
return $this;
} }
/** /**
* Unregister Plugin * @param string $cache_id
*
* @param string $type of plugin
* @param string $tag name of plugin
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/ */
public function unregisterPlugin($type, $tag) public function setCacheId($cache_id)
{ {
$smarty = isset($this->smarty) ? $this->smarty : $this; $this->cache_id = $cache_id;
if (isset($smarty->registered_plugins[$type][$tag])) {
unset($smarty->registered_plugins[$type][$tag]);
}
return $this;
} }
/**
* Registers a resource to fetch a template
*
* @param string $type name of resource type
* @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource
* (deprecated)
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function registerResource($type, $callback)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
$smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback,
false);
return $this;
}
/**
* Unregisters a resource
*
* @param string $type name of resource type
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function unregisterResource($type)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (isset($smarty->registered_resources[$type])) {
unset($smarty->registered_resources[$type]);
}
return $this;
}
/**
* Registers a cache resource to cache a template's output
*
* @param string $type name of cache resource type
* @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function registerCacheResource($type, Smarty_CacheResource $callback)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
$smarty->registered_cache_resources[$type] = $callback;
return $this;
}
/**
* Unregisters a cache resource
*
* @param string $type name of cache resource type
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function unregisterCacheResource($type)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (isset($smarty->registered_cache_resources[$type])) {
unset($smarty->registered_cache_resources[$type]);
}
return $this;
}
/**
* Registers object to be used in templates
*
* @param $object_name
* @param object $object_impl the referenced PHP object to register
* @param array $allowed list of allowed methods (empty = all)
* @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of block-methods
*
* @throws SmartyException
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
{
Smarty_Internal_Extension_Object::registerObject($this, $object_name, $object_impl, $allowed, $smarty_args, $block_methods);
return $this;
}
/**
* return a reference to a registered object
*
* @param string $name object name
*
* @return object
* @throws SmartyException if no such object is found
*/
public function getRegisteredObject($name)
{
return Smarty_Internal_Extension_Object::getRegisteredObject($this, $name);
}
/**
* unregister an object
*
* @param string $name object name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function unregisterObject($name)
{
Smarty_Internal_Extension_Object::unregisterObject($this, $name);
return $this;
}
/**
* Registers static classes to be used in templates
*
* @param $class_name
* @param string $class_impl the referenced PHP class to register
*
* @throws SmartyException
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function registerClass($class_name, $class_impl)
{
Smarty_Internal_Extension_Object::registerClass($this, $class_name, $class_impl);
return $this;
}
/**
* Registers a default plugin handler
*
* @param callable $callback class/method name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
* @throws SmartyException if $callback is not callable
*/
public function registerDefaultPluginHandler($callback)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (is_callable($callback)) {
$smarty->default_plugin_handler_func = $callback;
} else {
throw new SmartyException("Default plugin handler '$callback' not callable");
}
return $this;
}
/**
* Registers a default template handler
*
* @param callable $callback class/method name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
* @throws SmartyException if $callback is not callable
*/
public function registerDefaultTemplateHandler($callback)
{
Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultTemplateHandler($this, $callback);
return $this;
}
/**
* Registers a default template handler
*
* @param callable $callback class/method name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
* @throws SmartyException if $callback is not callable
*/
public function registerDefaultConfigHandler($callback)
{
Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultConfigHandler($this, $callback);
return $this;
}
/**
* Registers a filter function
*
* @param string $type filter type
* @param callback $callback
* @param null|string $name option filter name
*
* @return \Smarty_Internal_TemplateBase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
* @throws \SmartyException
*/
public function registerFilter($type, $callback, $name = null)
{
Smarty_Internal_Extension_Filter::registerFilter($this, $type, $callback, $name);
return $this;
}
/**
* Unregisters a filter function
*
* @param string $type filter type
* @param callback|string $callback
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function unregisterFilter($type, $callback)
{
Smarty_Internal_Extension_Filter::unregisterFilter($this, $type, $callback);
return $this;
}
/**
* load a filter of specified type and name
*
* @param string $type filter type
* @param string $name filter name
*
* @return bool
* @throws SmartyException if filter could not be loaded
*/
public function loadFilter($type, $name)
{
return Smarty_Internal_Extension_Filter::loadFilter($this, $type, $name);
}
/**
* unload a filter of specified type and name
*
* @param string $type filter type
* @param string $name filter name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function unloadFilter($type, $name)
{
Smarty_Internal_Extension_Filter::unloadFilter($this, $type, $name);
return $this;
}
/**
* preg_replace callback to convert camelcase getter/setter to underscore property names
*
* @param string $match match string
*
* @return string replacement
*/
private function replaceCamelcase($match)
{
return "_" . strtolower($match[1]);
}
/**
* Handle unknown class methods
*
* @param string $name unknown method-name
* @param array $args argument array
*
* @throws SmartyException
*/
public function __call($name, $args)
{
static $_prefixes = array('set' => true, 'get' => true);
static $_resolved_property_name = array();
static $_resolved_property_source = array();
// see if this is a set/get for a property
$first3 = strtolower(substr($name, 0, 3));
if (isset($_prefixes[$first3]) && isset($name[3]) && $name[3] !== '_') {
if (isset($_resolved_property_name[$name])) {
$property_name = $_resolved_property_name[$name];
} else {
// try to keep case correct for future PHP 6.0 case-sensitive class methods
// lcfirst() not available < PHP 5.3.0, so improvise
$property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
// convert camel case to underscored name
$property_name = preg_replace_callback('/([A-Z])/', array($this, 'replaceCamelcase'), $property_name);
$_resolved_property_name[$name] = $property_name;
}
if (isset($_resolved_property_source[$property_name])) {
$status = $_resolved_property_source[$property_name];
} else {
$status = null;
if (property_exists($this, $property_name)) {
$status = true;
} elseif (property_exists($this->smarty, $property_name)) {
$status = false;
} elseif (in_array($name, $this->smarty->obsoleteProperties)) {
return null;
} else {
}
$_resolved_property_source[$property_name] = $status;
}
$smarty = null;
if ($status === true) {
$smarty = $this;
} elseif ($status === false) {
$smarty = $this->smarty;
}
if ($smarty) {
if ($first3 == 'get') {
return $smarty->$property_name;
} else {
return $smarty->$property_name = $args[0];
}
}
throw new SmartyException("property '$property_name' does not exist.");
}
throw new SmartyException("Call of unknown method '$name'.");
}
} }

View File

@@ -785,7 +785,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (strpos($variable, '(') == 0) { if (strpos($variable, '(') == 0) {
// not a variable variable // not a variable variable
$var = trim($variable, '\''); $var = trim($variable, '\'');
$this->tag_nocache = $this->tag_nocache | $this->template->getVariable($var, null, true, false)->nocache; $this->tag_nocache = $this->tag_nocache | $this->template->_getVariable($var, null, true, false)->nocache;
// todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache; // todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache;
} }
return '$_smarty_tpl->tpl_vars[' . $variable . ']->value'; return '$_smarty_tpl->tpl_vars[' . $variable . ']->value';

View File

@@ -2093,13 +2093,13 @@ class Smarty_Internal_Templateparser
#line 879 "../smarty/lexer/smarty_internal_templateparser.y" #line 879 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r116() function yy_r116()
{ {
$this->_retvalue = '$_smarty_tpl->getConfigVariable( \'' . $this->yystack[$this->yyidx + - 1]->minor . '\')'; $this->_retvalue = '$_smarty_tpl->_getConfigVariable( \'' . $this->yystack[$this->yyidx + - 1]->minor . '\')';
} }
#line 883 "../smarty/lexer/smarty_internal_templateparser.y" #line 883 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r117() function yy_r117()
{ {
$this->_retvalue = '(is_array($tmp = $_smarty_tpl->getConfigVariable( \'' . $this->_retvalue = '(is_array($tmp = $_smarty_tpl->_getConfigVariable( \'' .
$this->yystack[$this->yyidx + - 2]->minor . '\')) ? $tmp' . $this->yystack[$this->yyidx + 0]->minor . $this->yystack[$this->yyidx + - 2]->minor . '\')) ? $tmp' . $this->yystack[$this->yyidx + 0]->minor .
' :null)'; ' :null)';
} }
@@ -2107,13 +2107,13 @@ class Smarty_Internal_Templateparser
#line 887 "../smarty/lexer/smarty_internal_templateparser.y" #line 887 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r118() function yy_r118()
{ {
$this->_retvalue = '$_smarty_tpl->getConfigVariable( ' . $this->yystack[$this->yyidx + - 1]->minor . ')'; $this->_retvalue = '$_smarty_tpl->_getConfigVariable( ' . $this->yystack[$this->yyidx + - 1]->minor . ')';
} }
#line 891 "../smarty/lexer/smarty_internal_templateparser.y" #line 891 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r119() function yy_r119()
{ {
$this->_retvalue = '(is_array($tmp = $_smarty_tpl->getConfigVariable( ' . $this->_retvalue = '(is_array($tmp = $_smarty_tpl->_getConfigVariable( ' .
$this->yystack[$this->yyidx + - 2]->minor . ')) ? $tmp' . $this->yystack[$this->yyidx + 0]->minor . $this->yystack[$this->yyidx + - 2]->minor . ')) ? $tmp' . $this->yystack[$this->yyidx + 0]->minor .
' : null)'; ' : null)';
} }
@@ -2332,7 +2332,7 @@ class Smarty_Internal_Templateparser
$this->compiler->trigger_template_error('Illegal number of paramer in "isset()"'); $this->compiler->trigger_template_error('Illegal number of paramer in "isset()"');
} }
$par = implode(',', $this->yystack[$this->yyidx + - 1]->minor); $par = implode(',', $this->yystack[$this->yyidx + - 1]->minor);
if (strncasecmp($par, '$_smarty_tpl->getConfigVariable', strlen('$_smarty_tpl->getConfigVariable')) === if (strncasecmp($par, '$_smarty_tpl->_getConfigVariable', strlen('$_smarty_tpl->_getConfigVariable')) ===
0 0
) { ) {
self::$prefix_number ++; self::$prefix_number ++;

View File

@@ -19,7 +19,6 @@ class Smarty_Internal_TestInstall
* diagnose Smarty setup * diagnose Smarty setup
* If $errors is secified, the diagnostic report will be appended to the array, rather than being output. * If $errors is secified, the diagnostic report will be appended to the array, rather than being output.
* *
* @param Smarty $smarty Smarty instance to test
* @param array $errors array to push results into rather than outputting them * @param array $errors array to push results into rather than outputting them
* *
* @return bool status, true if everything is fine, false else * @return bool status, true if everything is fine, false else
@@ -47,7 +46,7 @@ class Smarty_Internal_TestInstall
if ($_stream_resolve_include_path) { if ($_stream_resolve_include_path) {
$template_dir = stream_resolve_include_path($_template_dir); $template_dir = stream_resolve_include_path($_template_dir);
} else { } else {
$template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir); $template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir, null, $smarty);
} }
if ($template_dir !== false) { if ($template_dir !== false) {
@@ -166,7 +165,7 @@ class Smarty_Internal_TestInstall
if ($_stream_resolve_include_path) { if ($_stream_resolve_include_path) {
$plugin_dir = stream_resolve_include_path($_plugin_dir); $plugin_dir = stream_resolve_include_path($_plugin_dir);
} else { } else {
$plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir); $plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir, null, $smarty);
} }
if ($plugin_dir !== false) { if ($plugin_dir !== false) {
@@ -288,7 +287,6 @@ class Smarty_Internal_TestInstall
// test if all registered config_dir are accessible // test if all registered config_dir are accessible
foreach ($smarty->getConfigDir() as $config_dir) { foreach ($smarty->getConfigDir() as $config_dir) {
$_config_dir = $config_dir; $_config_dir = $config_dir;
$config_dir = realpath($config_dir);
// resolve include_path or fail existence // resolve include_path or fail existence
if (!$config_dir) { if (!$config_dir) {
if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) { if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) {
@@ -296,7 +294,7 @@ class Smarty_Internal_TestInstall
if ($_stream_resolve_include_path) { if ($_stream_resolve_include_path) {
$config_dir = stream_resolve_include_path($_config_dir); $config_dir = stream_resolve_include_path($_config_dir);
} else { } else {
$config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir); $config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir, null, $smarty);
} }
if ($config_dir !== false) { if ($config_dir !== false) {
@@ -404,8 +402,6 @@ class Smarty_Internal_TestInstall
"smarty_internal_data.php" => true, "smarty_internal_data.php" => true,
"smarty_internal_debug.php" => true, "smarty_internal_debug.php" => true,
"smarty_internal_extension_codeframe.php" => true, "smarty_internal_extension_codeframe.php" => true,
"smarty_internal_extension_config.php" => true,
"smarty_internal_extension_defaulttemplatehandler.php" => true,
"smarty_internal_filter_handler.php" => true, "smarty_internal_filter_handler.php" => true,
"smarty_internal_function_call_handler.php" => true, "smarty_internal_function_call_handler.php" => true,
"smarty_internal_get_include_path.php" => true, "smarty_internal_get_include_path.php" => true,
@@ -430,7 +426,6 @@ class Smarty_Internal_TestInstall
"smarty_internal_templatecompilerbase.php" => true, "smarty_internal_templatecompilerbase.php" => true,
"smarty_internal_templatelexer.php" => true, "smarty_internal_templatelexer.php" => true,
"smarty_internal_templateparser.php" => true, "smarty_internal_templateparser.php" => true,
"smarty_internal_utility.php" => true,
"smarty_internal_write_file.php" => true, "smarty_internal_write_file.php" => true,
"smarty_resource.php" => true, "smarty_resource.php" => true,
"smarty_resource_custom.php" => true, "smarty_resource_custom.php" => true,

View File

@@ -1,62 +0,0 @@
<?php
/**
* Project: Smarty: the PHP compiling template engine
* File: smarty_internal_utility.php
* SVN: $Id: $
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* For questions, help, comments, discussion, etc., please join the
* Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com
*
* @link http://www.smarty.net/
* @copyright 2008 New Digital Group, Inc.
* @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews
* @package Smarty
* @subpackage PluginsInternal
* @version 3-SVN$Rev: 3286 $
*/
/**
* Utility class
*
* @package Smarty
* @subpackage Security
*/
class Smarty_Internal_Utility
{
/**
* private constructor to prevent calls creation of new instances
*/
final private function __construct()
{
// intentionally left blank
}
/**
* Return array of tag/attributes of all tags used by an template
*
* @param Smarty_Internal_Template $template
*
* @throws Exception
* @throws SmartyException
* @return array of tag/attributes
*/
public static function getTags(Smarty_Internal_Template $template)
{
$template->smarty->get_used_tags = true;
$template->compileTemplateSource();
return $template->used_tags;
}
}

View File

@@ -14,10 +14,7 @@
* @package Smarty * @package Smarty
* @subpackage TemplateResources * @subpackage TemplateResources
* @author Uwe Tews * @author Uwe Tews
* @property integer $timestamp Source Timestamp *
* @property boolean $exists Source Existence
* @property boolean $template Extended Template reference
* @property string $content Source Content
*/ */
class Smarty_Template_Config extends Smarty_Template_Source class Smarty_Template_Config extends Smarty_Template_Source
{ {
@@ -89,7 +86,7 @@ class Smarty_Template_Config extends Smarty_Template_Source
* @param Smarty $smarty smarty object * @param Smarty $smarty smarty object
* @param string $template_resource resource identifier * @param string $template_resource resource identifier
* *
* @return Smarty_Template_Source Source Object * @return Smarty_Template_Config Source Object
* @throws SmartyException * @throws SmartyException
*/ */
public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null)
@@ -110,7 +107,7 @@ class Smarty_Template_Config extends Smarty_Template_Source
$source = new Smarty_Template_Config($resource, $smarty, $template_resource, $type, $name); $source = new Smarty_Template_Config($resource, $smarty, $template_resource, $type, $name);
$resource->populate($source, $_template); $resource->populate($source, $_template);
if (!$source->exists && isset($_template->smarty->default_config_handler_func)) { if (!$source->exists && isset($_template->smarty->default_config_handler_func)) {
Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source); Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
} }
$source->unique_resource = $resource->buildUniqueResourceName($smarty, $name, true); $source->unique_resource = $resource->buildUniqueResourceName($smarty, $name, true);
return $source; return $source;

View File

@@ -7,10 +7,7 @@
* @package Smarty * @package Smarty
* @subpackage TemplateResources * @subpackage TemplateResources
* @author Rodney Rehm * @author Rodney Rehm
* @property integer $timestamp Source Timestamp *
* @property boolean $exists Source Existence
* @property boolean $template Extended Template reference
* @property string $content Source Content
*/ */
class Smarty_Template_Source class Smarty_Template_Source
{ {
@@ -217,7 +214,7 @@ class Smarty_Template_Source
$source = new Smarty_Template_Source($resource, $smarty, $template_resource, $type, $name); $source = new Smarty_Template_Source($resource, $smarty, $template_resource, $type, $name);
$resource->populate($source, $_template); $resource->populate($source, $_template);
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) { if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source); Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
} }
// on recompiling resources we are done // on recompiling resources we are done
if (($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) && !$resource->recompiled) { if (($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) && !$resource->recompiled) {