summaryrefslogtreecommitdiff
path: root/lib/smarty3/sysplugins/smarty_internal_templatebase.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/smarty3/sysplugins/smarty_internal_templatebase.php')
-rw-r--r--lib/smarty3/sysplugins/smarty_internal_templatebase.php164
1 files changed, 106 insertions, 58 deletions
diff --git a/lib/smarty3/sysplugins/smarty_internal_templatebase.php b/lib/smarty3/sysplugins/smarty_internal_templatebase.php
index 0b123f6..4476f12 100644
--- a/lib/smarty3/sysplugins/smarty_internal_templatebase.php
+++ b/lib/smarty3/sysplugins/smarty_internal_templatebase.php
@@ -11,20 +11,22 @@
/**
* Class with shared smarty/template methods
*
- * @package Smarty
- * @subpackage Template
+ * @package Smarty
+ * @subpackage Template
*
- * @property Smarty $smarty
+ * @property int $_objType
*
* The following methods will be dynamically loaded by the extension handler when they are called.
* They are located in a corresponding Smarty_Internal_Method_xxxx class
*
* @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null)
- * @method Smarty_Internal_TemplateBase addDefaultModifier(mixed $modifiers)
+ * @method Smarty_Internal_TemplateBase addDefaultModifiers(mixed $modifiers)
+ * @method Smarty_Internal_TemplateBase addLiterals(mixed $literals)
* @method Smarty_Internal_TemplateBase createData(Smarty_Internal_Data $parent = null, string $name = null)
* @method array getAutoloadFilters(string $type = null)
* @method string getDebugTemplate()
* @method array getDefaultModifier()
+ * @method array getLiterals()
* @method array getTags(mixed $template = null)
* @method object getRegisteredObject(string $object_name)
* @method Smarty_Internal_TemplateBase registerCacheResource(string $name, Smarty_CacheResource $resource_handler)
@@ -35,7 +37,8 @@
* @method Smarty_Internal_TemplateBase registerResource(string $name, mixed $resource_handler)
* @method Smarty_Internal_TemplateBase setAutoloadFilters(mixed $filters, string $type = null)
* @method Smarty_Internal_TemplateBase setDebugTemplate(string $tpl_name)
- * @method Smarty_Internal_TemplateBase setDefaultModifier(mixed $modifiers)
+ * @method Smarty_Internal_TemplateBase setDefaultModifiers(mixed $modifiers)
+ * @method Smarty_Internal_TemplateBase setLiterals(mixed $literals)
* @method Smarty_Internal_TemplateBase unloadFilter(string $type, string $name)
* @method Smarty_Internal_TemplateBase unregisterCacheResource(string $name)
* @method Smarty_Internal_TemplateBase unregisterObject(string $object_name)
@@ -64,9 +67,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* caching enabled
*
- * @var boolean
+ * @var int
+ */
+ public $caching = Smarty::CACHING_OFF;
+
+ /**
+ * check template for modifications?
+ *
+ * @var int
*/
- public $caching = false;
+ public $compile_check = Smarty::COMPILECHECK_ON;
/**
* cache lifetime in seconds
@@ -76,6 +86,13 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
public $cache_lifetime = 3600;
/**
+ * Array of source information for known template functions
+ *
+ * @var array
+ */
+ public $tplFunctions = array();
+
+ /**
* universal cache
*
* @var array()
@@ -85,10 +102,10 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* fetches a rendered Smarty template
*
- * @param string $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 $compile_id compile id to be used with this template
- * @param object $parent next higher level of Smarty variables
+ * @param string $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 $compile_id compile id to be used with this template
+ * @param object $parent next higher level of Smarty variables
*
* @throws Exception
* @throws SmartyException
@@ -107,6 +124,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @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 object $parent next higher level of Smarty variables
+ *
+ * @throws \Exception
+ * @throws \SmartyException
*/
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
@@ -120,12 +140,15 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @api Smarty::isCached()
* @link http://www.smarty.net/docs/en/api.is.cached.tpl
*
- * @param null|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 $compile_id compile id to be used with this template
- * @param object $parent next higher level of Smarty variables
+ * @param null|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 $compile_id compile id to be used with this template
+ * @param object $parent next higher level of Smarty variables
*
- * @return boolean cache status
+ * @return bool cache status
+ * @throws \Exception
+ * @throws \SmartyException
*/
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
@@ -135,11 +158,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* fetches a rendered Smarty template
*
- * @param string $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 $compile_id compile id to be used with this template
- * @param object $parent next higher level of Smarty variables
- * @param string $function function type 0 = fetch, 1 = display, 2 = isCache
+ * @param string $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 $compile_id compile id to be used with this template
+ * @param object $parent next higher level of Smarty variables
+ * @param string $function function type 0 = fetch, 1 = display, 2 = isCache
*
* @return mixed
* @throws \Exception
@@ -147,42 +170,52 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
*/
private function _execute($template, $cache_id, $compile_id, $parent, $function)
{
- $smarty = $this->_objType == 1 ? $this : $this->smarty;
+ $smarty = $this->_getSmartyObj();
$saveVars = true;
if ($template === null) {
- if ($this->_objType != 2) {
+ if (!$this->_isTplObj()) {
throw new SmartyException($function . '():Missing \'$template\' parameter');
} else {
$template = $this;
}
} elseif (is_object($template)) {
- if (!isset($template->_objType) || $template->_objType != 2) {
+ /* @var Smarty_Internal_Template $template */
+ if (!isset($template->_objType) || !$template->_isTplObj()) {
throw new SmartyException($function . '():Template object expected');
}
} else {
// get template object
- /* @var Smarty_Internal_Template $template */
$saveVars = false;
-
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false);
- if ($this->_objType == 1) {
+ if ($this->_objType === 1) {
// set caching in template object
$template->caching = $this->caching;
}
}
+ // make sure we have integer values
+ $template->caching = (int)$template->caching;
// fetch template content
$level = ob_get_level();
try {
$_smarty_old_error_level =
isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null;
- if ($function == 2) {
+ if ($this->_objType === 2) {
+ /* @var Smarty_Internal_Template $this */
+ $template->tplFunctions = $this->tplFunctions;
+ $template->inheritance = $this->inheritance;
+ }
+ /* @var Smarty_Internal_Template $parent */
+ if (isset($parent->_objType) && ($parent->_objType === 2) && !empty($parent->tplFunctions)) {
+ $template->tplFunctions = array_merge($parent->tplFunctions, $template->tplFunctions);
+ }
+ if ($function === 2) {
if ($template->caching) {
// return cache status of template
if (!isset($template->cached)) {
$template->loadCached();
}
$result = $template->cached->isCached($template);
- $template->smarty->_cache[ 'isCached' ][ $template->_getTemplateId() ] = $template;
+ Smarty_Internal_Template::$isCacheTplObj[ $template->_getTemplateId() ] = $template;
} else {
return false;
}
@@ -202,10 +235,10 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
$template->tpl_vars = $savedTplVars;
$template->config_vars = $savedConfigVars;
} else {
- if (!$function && !isset($smarty->_cache[ 'tplObjects' ][ $template->templateId ])) {
+ if (!$function && !isset(Smarty_Internal_Template::$tplObjCache[ $template->templateId ])) {
$template->parent = null;
$template->tpl_vars = $template->config_vars = array();
- $smarty->_cache[ 'tplObjects' ][ $template->templateId ] = $template;
+ Smarty_Internal_Template::$tplObjCache[ $template->templateId ] = $template;
}
}
}
@@ -213,8 +246,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
error_reporting($_smarty_old_error_level);
}
return $result;
- }
- catch (Exception $e) {
+ } catch (Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
@@ -231,14 +263,14 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @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
+ * @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
+ * @throws \SmartyException
*/
public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null)
{
@@ -251,11 +283,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @api Smarty::loadFilter()
* @link http://www.smarty.net/docs/en/api.load.filter.tpl
*
- * @param string $type filter type
- * @param string $name filter name
+ * @param string $type filter type
+ * @param string $name filter name
*
* @return bool
- * @throws SmartyException if filter could not be loaded
+ * @throws \SmartyException
*/
public function loadFilter($type, $name)
{
@@ -268,9 +300,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @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
+ * @param string $type filter type
+ * @param callback $callback
+ * @param string|null $name optional filter name
*
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
@@ -286,28 +318,46 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @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
+ * @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())
+ public function registerObject(
+ $object_name,
+ $object,
+ $allowed_methods_properties = array(),
+ $format = true,
+ $block_methods = array()
+ ) {
+ return $this->ext->registerObject->registerObject(
+ $this,
+ $object_name,
+ $object,
+ $allowed_methods_properties,
+ $format,
+ $block_methods
+ );
+ }
+
+ /**
+ * @param int $compile_check
+ */
+ public function setCompileCheck($compile_check)
{
- return $this->ext->registerObject->registerObject($this, $object_name, $object, $allowed_methods_properties,
- $format, $block_methods);
+ $this->compile_check = (int)$compile_check;
}
/**
- * @param boolean $caching
+ * @param int $caching
*/
public function setCaching($caching)
{
- $this->caching = $caching;
+ $this->caching = (int)$caching;
}
/**
@@ -333,6 +383,4 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
{
$this->cache_id = $cache_id;
}
-
}
-