mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- move some code into runtime extensions
This commit is contained in:
@@ -119,7 +119,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.28-dev/66';
|
const SMARTY_VERSION = '3.1.28-dev/68';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -61,7 +61,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
// compiled output
|
// compiled output
|
||||||
if (isset($parameter['smarty_internal_index'])) {
|
if (isset($parameter['smarty_internal_index'])) {
|
||||||
$output = "<?php \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
|
$output = "<?php \$_smarty_tpl->_var->createLocalArrayVariable(\$_smarty_tpl, $_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
|
||||||
} else {
|
} else {
|
||||||
// implement Smarty2's behaviour of variables assigned by reference
|
// implement Smarty2's behaviour of variables assigned by reference
|
||||||
if ($compiler->template->smarty instanceof SmartyBC) {
|
if ($compiler->template->smarty instanceof SmartyBC) {
|
||||||
|
@@ -79,10 +79,10 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
|
|||||||
// was there an assign attribute
|
// was there an assign attribute
|
||||||
if (isset($_assign)) {
|
if (isset($_assign)) {
|
||||||
$_output =
|
$_output =
|
||||||
"<?php ob_start();\n\$_smarty_tpl->callTemplateFunction({$_name}, \$_smarty_tpl, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
|
"<?php ob_start();\n\$_smarty_tpl->_tplfunc->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
|
||||||
} else {
|
} else {
|
||||||
$_output =
|
$_output =
|
||||||
"<?php \$_smarty_tpl->callTemplateFunction({$_name}, \$_smarty_tpl, {$_params}, {$_nocache});?>\n";
|
"<?php \$_smarty_tpl->_tplfunc->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n";
|
||||||
}
|
}
|
||||||
return $_output;
|
return $_output;
|
||||||
}
|
}
|
||||||
|
@@ -184,7 +184,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
|||||||
$output .= "{$local}{$k} = {$code}\n";
|
$output .= "{$local}{$k} = {$code}\n";
|
||||||
}
|
}
|
||||||
$output .= "{$itemVar} = new Smarty_Variable();\n";
|
$output .= "{$itemVar} = new Smarty_Variable();\n";
|
||||||
$output .= "{$local}total = \$_smarty_tpl->_count(\$_from);\n";
|
$output .= "{$local}total = \$_smarty_tpl->_foreach->count(\$_from);\n";
|
||||||
if (isset($itemAttr['show'])) {
|
if (isset($itemAttr['show'])) {
|
||||||
$output .= "{$itemVar}->show = ({$local}total > 0);\n";
|
$output .= "{$itemVar}->show = ({$local}total > 0);\n";
|
||||||
}
|
}
|
||||||
|
@@ -58,7 +58,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
|||||||
if (is_array($parameter['if condition']['var'])) {
|
if (is_array($parameter['if condition']['var'])) {
|
||||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
||||||
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
||||||
"]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] .
|
"]->value)) \$_smarty_tpl->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] .
|
||||||
"$_nocache);\n";
|
"$_nocache);\n";
|
||||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
||||||
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
||||||
@@ -162,7 +162,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
|||||||
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" .
|
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" .
|
||||||
$parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" .
|
$parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" .
|
||||||
$parameter['if condition']['var']['var'] .
|
$parameter['if condition']['var']['var'] .
|
||||||
"]->value)) \$_smarty_tpl->createLocalArrayVariable(" .
|
"]->value)) \$_smarty_tpl->_var->createLocalArrayVariable(\$_smarty_tpl, " .
|
||||||
$parameter['if condition']['var']['var'] . "$_nocache);\n";
|
$parameter['if condition']['var']['var'] . "$_nocache);\n";
|
||||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
||||||
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
||||||
@@ -195,7 +195,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
|||||||
$parameter['if condition']['var']['var'] .
|
$parameter['if condition']['var']['var'] .
|
||||||
"]) || !is_array(\$_smarty_tpl->tpl_vars[" .
|
"]) || !is_array(\$_smarty_tpl->tpl_vars[" .
|
||||||
$parameter['if condition']['var']['var'] .
|
$parameter['if condition']['var']['var'] .
|
||||||
"]->value)) \$_smarty_tpl->createLocalArrayVariable(" .
|
"]->value)) \$_smarty_tpl->_var->createLocalArrayVariable(\$_smarty_tpl, " .
|
||||||
$parameter['if condition']['var']['var'] . "$_nocache);\n");
|
$parameter['if condition']['var']['var'] . "$_nocache);\n");
|
||||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
||||||
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
||||||
|
@@ -248,7 +248,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
if (isset($_assign)) {
|
if (isset($_assign)) {
|
||||||
$_output .= "ob_start();\n";
|
$_output .= "ob_start();\n";
|
||||||
}
|
}
|
||||||
$_output .= "\$_smarty_tpl->renderInline(\$_smarty_tpl->setupSubTemplate({$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid']}'), '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func']}');\n";
|
$_output .= "\$_smarty_tpl->_inline->render(\$_smarty_tpl, {$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func']}');\n";
|
||||||
if (isset($_assign)) {
|
if (isset($_assign)) {
|
||||||
$_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(ob_get_clean());\n";
|
$_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(ob_get_clean());\n";
|
||||||
}
|
}
|
||||||
@@ -271,7 +271,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
if (isset($_assign)) {
|
if (isset($_assign)) {
|
||||||
$_output .= "ob_start();\n";
|
$_output .= "ob_start();\n";
|
||||||
}
|
}
|
||||||
$_output .= "\$_smarty_tpl->setupSubTemplate({$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, {$_cache_tpl})->render();\n";
|
$_output .= "\$_smarty_tpl->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, {$_cache_tpl});\n";
|
||||||
if (isset($_assign)) {
|
if (isset($_assign)) {
|
||||||
$_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(ob_get_clean());\n";
|
$_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(ob_get_clean());\n";
|
||||||
}
|
}
|
||||||
|
@@ -60,7 +60,7 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
|
|||||||
if (is_array($parameter['if condition']['var'])) {
|
if (is_array($parameter['if condition']['var'])) {
|
||||||
$_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
$_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
||||||
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
||||||
"]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] .
|
"]->value)) \$_smarty_tpl->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] .
|
||||||
"$_nocache);\n";
|
"$_nocache);\n";
|
||||||
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
||||||
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
||||||
|
44
libs/sysplugins/smarty_internal_runtime_foreach.php
Normal file
44
libs/sysplugins/smarty_internal_runtime_foreach.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Foreach Runtime Methods count
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage PluginsInternal
|
||||||
|
* @author Uwe Tews
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
class Smarty_Internal_Runtime_Foreach
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* [util function] counts an array, arrayAccess/traversable or PDOStatement object
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
*
|
||||||
|
* @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0
|
||||||
|
* for empty elements
|
||||||
|
*/
|
||||||
|
public function count($value)
|
||||||
|
{
|
||||||
|
if (is_array($value) === true || $value instanceof Countable) {
|
||||||
|
return count($value);
|
||||||
|
} elseif ($value instanceof IteratorAggregate) {
|
||||||
|
// Note: getIterator() returns a Traversable, not an Iterator
|
||||||
|
// thus rewind() and valid() methods may not be present
|
||||||
|
return iterator_count($value->getIterator());
|
||||||
|
} elseif ($value instanceof Iterator) {
|
||||||
|
return iterator_count($value);
|
||||||
|
} elseif ($value instanceof PDOStatement) {
|
||||||
|
return $value->rowCount();
|
||||||
|
} elseif ($value instanceof Traversable) {
|
||||||
|
return iterator_count($value);
|
||||||
|
} elseif ($value instanceof ArrayAccess) {
|
||||||
|
if ($value->offsetExists(0)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} elseif (is_object($value)) {
|
||||||
|
return count($value);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runtime Method callBlock,callParentBlock, callChildBlock, registerBlock
|
* Inheritance Runtime Methods processBlock, endChild, init
|
||||||
*
|
*
|
||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsInternal
|
* @subpackage PluginsInternal
|
||||||
|
76
libs/sysplugins/smarty_internal_runtime_inline.php
Normal file
76
libs/sysplugins/smarty_internal_runtime_inline.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inline Runtime Methods render
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage PluginsInternal
|
||||||
|
* @author Uwe Tews
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
class Smarty_Internal_Runtime_Inline extends Smarty_Internal_Runtime_Subtemplate
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template code runtime function to set up an inline subtemplate
|
||||||
|
*
|
||||||
|
* @param \Smarty_Internal_Template $parent
|
||||||
|
* @param string $template template name
|
||||||
|
* @param mixed $cache_id cache id
|
||||||
|
* @param mixed $compile_id compile id
|
||||||
|
* @param integer $caching cache mode
|
||||||
|
* @param integer $cache_lifetime life time of cache data
|
||||||
|
* @param array $data passed parameter template variables
|
||||||
|
* @param int $parent_scope scope in which {include} should execute
|
||||||
|
* @param bool $cache_tpl_obj cache template object
|
||||||
|
* @param string $uid file dependency uid
|
||||||
|
* @param string $content_func function name
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function render(\Smarty_Internal_Template $parent, $template, $cache_id, $compile_id, $caching,
|
||||||
|
$cache_lifetime, $data, $parent_scope, $cache_tpl_obj, $uid, $content_func)
|
||||||
|
{
|
||||||
|
$tpl = $this->setupSubtemplate($parent, $template, $cache_id, $compile_id, $caching, $cache_lifetime, $data,
|
||||||
|
$parent_scope, $cache_tpl_obj, $uid);
|
||||||
|
if ($parent->smarty->debugging) {
|
||||||
|
$parent->smarty->_debug->start_template($tpl);
|
||||||
|
$parent->smarty->_debug->start_render($tpl);
|
||||||
|
}
|
||||||
|
$tpl->compiled->getRenderedTemplateCode($tpl, $content_func);
|
||||||
|
if ($parent->smarty->debugging) {
|
||||||
|
$parent->smarty->_debug->end_template($tpl);
|
||||||
|
$parent->smarty->_debug->end_render($tpl);
|
||||||
|
}
|
||||||
|
if ($tpl->caching == 9999 && $tpl->compiled->has_nocache_code) {
|
||||||
|
$parent->cached->hashes[$tpl->compiled->nocache_hash] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set source object of inline template by $uid
|
||||||
|
*
|
||||||
|
* @param \Smarty_Internal_Template $tpl
|
||||||
|
* @param string $uid
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function setSourceByUid(Smarty_Internal_Template $tpl, $uid)
|
||||||
|
{
|
||||||
|
// inline templates have same compiled resource
|
||||||
|
$tpl->compiled = $tpl->parent->compiled;
|
||||||
|
if (isset($tpl->compiled->file_dependency[$uid])) {
|
||||||
|
list($filepath, $timestamp, $resource) = $tpl->compiled->file_dependency[$uid];
|
||||||
|
$tpl->source = new Smarty_Template_Source(isset($tpl->smarty->_cache['resource_handlers'][$resource]) ?
|
||||||
|
$tpl->smarty->_cache['resource_handlers'][$resource] :
|
||||||
|
Smarty_Resource::load($tpl->smarty, $resource), $tpl->smarty,
|
||||||
|
$filepath, $resource, $filepath);
|
||||||
|
$tpl->source->filepath = $filepath;
|
||||||
|
$tpl->source->timestamp = $timestamp;
|
||||||
|
$tpl->source->exists = true;
|
||||||
|
$tpl->source->uid = $uid;
|
||||||
|
} else {
|
||||||
|
$tpl->source = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
147
libs/sysplugins/smarty_internal_runtime_subtemplate.php
Normal file
147
libs/sysplugins/smarty_internal_runtime_subtemplate.php
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subtemplate Runtime Methods render, setupSubtemplate
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage PluginsInternal
|
||||||
|
* @author Uwe Tews
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
class Smarty_Internal_Runtime_Subtemplate
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runtime function to render subtemplate
|
||||||
|
*
|
||||||
|
* @param \Smarty_Internal_Template $parent
|
||||||
|
* @param string $template template name
|
||||||
|
* @param mixed $cache_id cache id
|
||||||
|
* @param mixed $compile_id compile id
|
||||||
|
* @param integer $caching cache mode
|
||||||
|
* @param integer $cache_lifetime life time of cache data
|
||||||
|
* @param array $data passed parameter template variables
|
||||||
|
* @param int $parent_scope scope in which {include} should execute
|
||||||
|
* @param bool $cache_tpl_obj cache template object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function render(Smarty_Internal_Template $parent, $template, $cache_id, $compile_id, $caching,
|
||||||
|
$cache_lifetime, $data, $parent_scope, $cache_tpl_obj)
|
||||||
|
{
|
||||||
|
$this->setupSubtemplate($parent, $template, $cache_id, $compile_id, $caching, $cache_lifetime, $data,
|
||||||
|
$parent_scope, $cache_tpl_obj)
|
||||||
|
->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runtime function to get subtemplate object from cache or clone from parent
|
||||||
|
*
|
||||||
|
* @param \Smarty_Internal_Template $parent calling template
|
||||||
|
* @param string $template template name
|
||||||
|
* @param mixed $cache_id cache id
|
||||||
|
* @param mixed $compile_id compile id
|
||||||
|
* @param integer $caching cache mode
|
||||||
|
* @param integer $cache_lifetime life time of cache data
|
||||||
|
* @param array $data passed parameter template variables
|
||||||
|
* @param int $parent_scope scope in which {include} should execute
|
||||||
|
* @param bool $cache_tpl_obj cache template object
|
||||||
|
* @param string|null $uid source uid
|
||||||
|
*
|
||||||
|
* @return \Smarty_Internal_Template template object
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function setupSubtemplate(Smarty_Internal_Template $parent, $template, $cache_id, $compile_id, $caching,
|
||||||
|
$cache_lifetime, $data, $parent_scope, $cache_tpl_obj, $uid = null)
|
||||||
|
{
|
||||||
|
// if there are cached template objects calculate $templateID
|
||||||
|
$_templateId = isset($parent->smarty->_cache['template_objects']) ?
|
||||||
|
$parent->smarty->_getTemplateId($template, $cache_id, $compile_id) : null;
|
||||||
|
// already in template cache?
|
||||||
|
/* @var Smarty_Internal_Template $tpl */
|
||||||
|
if (isset($parent->smarty->_cache['template_objects'][$_templateId])) {
|
||||||
|
// clone cached template object because of possible recursive call
|
||||||
|
$tpl = clone $parent->smarty->_cache['template_objects'][$_templateId];
|
||||||
|
$tpl->parent = $parent;
|
||||||
|
// if $caching mode changed the compiled resource is invalid
|
||||||
|
if ((bool) $tpl->caching !== (bool) $caching) {
|
||||||
|
unset($tpl->compiled);
|
||||||
|
}
|
||||||
|
// get variables from calling scope
|
||||||
|
if ($parent_scope == Smarty::SCOPE_LOCAL) {
|
||||||
|
$tpl->tpl_vars = $parent->tpl_vars;
|
||||||
|
$tpl->config_vars = $parent->config_vars;
|
||||||
|
}
|
||||||
|
$tpl->tpl_function = $parent->tpl_function;
|
||||||
|
// copy inheritance object?
|
||||||
|
if (isset($parent->_inheritance)) {
|
||||||
|
$tpl->_inheritance = $parent->_inheritance;
|
||||||
|
} else {
|
||||||
|
unset($tpl->_inheritance);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$tpl = clone $parent;
|
||||||
|
$tpl->parent = $parent;
|
||||||
|
if (!isset($tpl->templateId) || $tpl->templateId !== $_templateId) {
|
||||||
|
$tpl->templateId = $_templateId;
|
||||||
|
$tpl->template_resource = $template;
|
||||||
|
$tpl->cache_id = $cache_id;
|
||||||
|
$tpl->compile_id = $compile_id;
|
||||||
|
// $uid is set if template is inline
|
||||||
|
if (isset($uid)) {
|
||||||
|
$this->setSourceByUid($tpl, $uid);
|
||||||
|
// if template is called multiple times set flag to to cache template objects
|
||||||
|
$cache_tpl_obj = $cache_tpl_obj || (isset($tpl->compiled->includes[$tpl->template_resource]) &&
|
||||||
|
$tpl->compiled->includes[$tpl->template_resource] > 1);
|
||||||
|
} else {
|
||||||
|
$tpl->source = null;
|
||||||
|
unset($tpl->compiled);
|
||||||
|
}
|
||||||
|
if (!isset($tpl->source)) {
|
||||||
|
$tpl->source = Smarty_Template_Source::load($tpl);
|
||||||
|
}
|
||||||
|
unset($tpl->cached);
|
||||||
|
// check if template object should be cached
|
||||||
|
if (!$tpl->source->handler->recompiled && (isset($tpl->parent->templateId) &&
|
||||||
|
isset($tpl->smarty->_cache['template_objects'][$tpl->parent->templateId]) ||
|
||||||
|
($cache_tpl_obj && $tpl->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_AUTOMATIC) ||
|
||||||
|
$tpl->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)
|
||||||
|
) {
|
||||||
|
$tpl->smarty->_cache['template_objects'][$tpl->_getTemplateId()] = $tpl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$tpl->caching = $caching;
|
||||||
|
$tpl->cache_lifetime = $cache_lifetime;
|
||||||
|
if ($caching == 9999) {
|
||||||
|
$tpl->cached = $parent->cached;
|
||||||
|
}
|
||||||
|
// get variables from calling scope
|
||||||
|
if ($parent_scope != Smarty::SCOPE_LOCAL) {
|
||||||
|
if ($parent_scope == Smarty::SCOPE_PARENT) {
|
||||||
|
$tpl->tpl_vars = &$parent->tpl_vars;
|
||||||
|
$tpl->config_vars = &$parent->config_vars;
|
||||||
|
} elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
|
||||||
|
$tpl->tpl_vars = &Smarty::$global_tpl_vars;
|
||||||
|
$tpl->config_vars = $parent->config_vars;
|
||||||
|
} elseif ($parent_scope == Smarty::SCOPE_ROOT) {
|
||||||
|
$ptr = $tpl->parent;
|
||||||
|
while (!empty($ptr->parent)) {
|
||||||
|
$ptr = $ptr->parent;
|
||||||
|
}
|
||||||
|
$tpl->tpl_vars = &$ptr->tpl_vars;
|
||||||
|
$tpl->config_vars = &$ptr->config_vars;
|
||||||
|
} else {
|
||||||
|
$tpl->tpl_vars = $parent->tpl_vars;
|
||||||
|
$tpl->config_vars = $parent->config_vars;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data)) {
|
||||||
|
// set up variable values
|
||||||
|
foreach ($data as $_key => $_val) {
|
||||||
|
$tpl->tpl_vars[$_key] = new Smarty_Variable($_val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $tpl;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,36 +1,63 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin Function Call Handler
|
* Tplfunc Runtime Methods callTemplateFunction
|
||||||
*
|
*
|
||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsInternal
|
* @subpackage PluginsInternal
|
||||||
* @author Uwe Tews
|
* @author Uwe Tews
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class does handles template functions defined with the {function} tag missing in cache file.
|
|
||||||
* It can happen when the template function was called with the nocache option or within a nocache section.
|
|
||||||
* The template function will be loaded from it's compiled template file, executed and added to the cache file
|
|
||||||
* for later use.
|
|
||||||
*
|
*
|
||||||
* @package Smarty
|
**/
|
||||||
* @subpackage PluginsInternal
|
class Smarty_Internal_Runtime_Tplfunc
|
||||||
*/
|
|
||||||
class Smarty_Internal_Function_Call_Handler
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* This function handles calls to template functions defined by {function}
|
* Call template function
|
||||||
* It does create a PHP function at the first call
|
|
||||||
*
|
*
|
||||||
|
* @param \Smarty_Internal_Template $tpl template object
|
||||||
|
* @param string $name template function name
|
||||||
|
* @param array $params parameter array
|
||||||
|
* @param bool $nocache true if called nocache
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function callTemplateFunction(\Smarty_Internal_Template $tpl, $name, $params, $nocache)
|
||||||
|
{
|
||||||
|
if (isset($tpl->tpl_function[$name])) {
|
||||||
|
if (!$tpl->caching || ($tpl->caching && $nocache)) {
|
||||||
|
$function = $tpl->tpl_function[$name]['call_name'];
|
||||||
|
} else {
|
||||||
|
if (isset($tpl->tpl_function[$name]['call_name_caching'])) {
|
||||||
|
$function = $tpl->tpl_function[$name]['call_name_caching'];
|
||||||
|
} else {
|
||||||
|
$function = $tpl->tpl_function[$name]['call_name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (function_exists($function)) {
|
||||||
|
$function ($tpl, $params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// try to load template function dynamically
|
||||||
|
if ($this->addTplFuncToCache($tpl, $name, $function)) {
|
||||||
|
$function ($tpl, $params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new SmartyException("Unable to find template function '{$name}'");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Add template function to cache file for nocache calls
|
||||||
|
*
|
||||||
|
* @param Smarty_Internal_Template $tpl
|
||||||
* @param string $_name template function name
|
* @param string $_name template function name
|
||||||
* @param Smarty_Internal_Template $_smarty_tpl
|
|
||||||
* @param string $_function PHP function name
|
* @param string $_function PHP function name
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function call($_name, Smarty_Internal_Template $_smarty_tpl, $_function)
|
public function addTplFuncToCache(Smarty_Internal_Template $tpl, $_name, $_function)
|
||||||
{
|
{
|
||||||
$funcParam = $_smarty_tpl->tpl_function[$_name];
|
$funcParam = $tpl->tpl_function[$_name];
|
||||||
if (is_file($funcParam['compiled_filepath'])) {
|
if (is_file($funcParam['compiled_filepath'])) {
|
||||||
// read compiled file
|
// read compiled file
|
||||||
$code = file_get_contents($funcParam['compiled_filepath']);
|
$code = file_get_contents($funcParam['compiled_filepath']);
|
||||||
@@ -43,7 +70,7 @@ class Smarty_Internal_Function_Call_Handler
|
|||||||
eval($match[0]);
|
eval($match[0]);
|
||||||
if (function_exists($_function)) {
|
if (function_exists($_function)) {
|
||||||
// search cache file template
|
// search cache file template
|
||||||
$tplPtr = $_smarty_tpl;
|
$tplPtr = $tpl;
|
||||||
while (!isset($tplPtr->cached) && isset($tplPtr->parent)) {
|
while (!isset($tplPtr->cached) && isset($tplPtr->parent)) {
|
||||||
$tplPtr = $tplPtr->parent;
|
$tplPtr = $tplPtr->parent;
|
||||||
}
|
}
|
38
libs/sysplugins/smarty_internal_runtime_var.php
Normal file
38
libs/sysplugins/smarty_internal_runtime_var.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runtime Methods createLocalArrayVariable
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage PluginsInternal
|
||||||
|
* @author Uwe Tews
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
class Smarty_Internal_Runtime_Var
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Template code runtime function to create a local Smarty variable for array assignments
|
||||||
|
*
|
||||||
|
* @param \Smarty_Internal_Template $tpl template object
|
||||||
|
* @param string $tpl_var template variable name
|
||||||
|
* @param bool $nocache cache mode of variable
|
||||||
|
* @param int $scope scope of variable
|
||||||
|
*/
|
||||||
|
public function createLocalArrayVariable(\Smarty_Internal_Template $tpl, $tpl_var, $nocache = false,
|
||||||
|
$scope = Smarty::SCOPE_LOCAL)
|
||||||
|
{
|
||||||
|
if (!isset($tpl->tpl_vars[$tpl_var])) {
|
||||||
|
$tpl->tpl_vars[$tpl_var] = new Smarty_Variable(array(), $nocache, $scope);
|
||||||
|
} else {
|
||||||
|
$tpl->tpl_vars[$tpl_var] = clone $tpl->tpl_vars[$tpl_var];
|
||||||
|
if ($scope != Smarty::SCOPE_LOCAL) {
|
||||||
|
$tpl->tpl_vars[$tpl_var]->scope = $scope;
|
||||||
|
}
|
||||||
|
if (!(is_array($tpl->tpl_vars[$tpl_var]->value) ||
|
||||||
|
$tpl->tpl_vars[$tpl_var]->value instanceof ArrayAccess)
|
||||||
|
) {
|
||||||
|
settype($tpl->tpl_vars[$tpl_var]->value, 'array');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -18,6 +18,11 @@
|
|||||||
* @property Smarty_Template_Compiled $compiled
|
* @property Smarty_Template_Compiled $compiled
|
||||||
* @property Smarty_Template_Cached $cached
|
* @property Smarty_Template_Cached $cached
|
||||||
* @property Smarty_Internal_Runtime_Inheritance $_inheritance
|
* @property Smarty_Internal_Runtime_Inheritance $_inheritance
|
||||||
|
* @property Smarty_Internal_Runtime_Subtemplate $_subtemplate
|
||||||
|
* @property Smarty_Internal_Runtime_Inline $_inline
|
||||||
|
* @property Smarty_Internal_Runtime_Tplfunc $_tplfunc
|
||||||
|
* @property Smarty_Internal_Runtime_Var $_var
|
||||||
|
* @property Smarty_Internal_Runtime_Foreach $_foreach
|
||||||
* @method bool mustCompile()
|
* @method bool mustCompile()
|
||||||
*/
|
*/
|
||||||
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||||
@@ -203,9 +208,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
$this->smarty->_debug->end_template($this);
|
$this->smarty->_debug->end_template($this);
|
||||||
}
|
// debug output
|
||||||
// debug output
|
|
||||||
if ($this->smarty->debugging) {
|
|
||||||
$this->smarty->_debug->display_debug($this, true);
|
$this->smarty->_debug->display_debug($this, true);
|
||||||
}
|
}
|
||||||
if ($merge_tpl_vars) {
|
if ($merge_tpl_vars) {
|
||||||
@@ -222,9 +225,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
$this->smarty->_debug->end_template($this);
|
$this->smarty->_debug->end_template($this);
|
||||||
}
|
if ($this->smarty->debugging == 2 and $display === false) {
|
||||||
if ($this->smarty->debugging == 2 and $display === false) {
|
|
||||||
if ($this->smarty->debugging) {
|
|
||||||
$this->smarty->_debug->display_debug($this, true);
|
$this->smarty->_debug->display_debug($this, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,192 +284,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
$this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id);
|
$this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Template code runtime function to set up an inline subtemplate
|
|
||||||
*
|
|
||||||
* @param string $template template name
|
|
||||||
* @param mixed $cache_id cache id
|
|
||||||
* @param mixed $compile_id compile id
|
|
||||||
* @param integer $caching cache mode
|
|
||||||
* @param integer $cache_lifetime life time of cache data
|
|
||||||
* @param array $data passed parameter template variables
|
|
||||||
* @param int $parent_scope scope in which {include} should execute
|
|
||||||
* @param bool $cache_tpl_obj cache template object
|
|
||||||
* @param string|null $uid source uid
|
|
||||||
*
|
|
||||||
* @return \Smarty_Internal_Template template object
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function setupSubtemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope,
|
|
||||||
$cache_tpl_obj, $uid = null)
|
|
||||||
{
|
|
||||||
// if there are cached template objects calculate $templateID
|
|
||||||
$_templateId = isset($this->smarty->_cache['template_objects']) ?
|
|
||||||
$this->smarty->_getTemplateId($template, $cache_id, $compile_id) : null;
|
|
||||||
// already in template cache?
|
|
||||||
/* @var Smarty_Internal_Template $tpl */
|
|
||||||
if (isset($this->smarty->_cache['template_objects'][$_templateId])) {
|
|
||||||
// clone cached template object because of possible recursive call
|
|
||||||
$tpl = clone $this->smarty->_cache['template_objects'][$_templateId];
|
|
||||||
$tpl->parent = $this;
|
|
||||||
// if $caching mode changed the compiled resource is invalid
|
|
||||||
if ((bool) $tpl->caching !== (bool) $caching) {
|
|
||||||
unset($tpl->compiled);
|
|
||||||
}
|
|
||||||
// get variables from calling scope
|
|
||||||
if ($parent_scope == Smarty::SCOPE_LOCAL) {
|
|
||||||
$tpl->tpl_vars = $this->tpl_vars;
|
|
||||||
$tpl->config_vars = $this->config_vars;
|
|
||||||
}
|
|
||||||
$tpl->tpl_function = $this->tpl_function;
|
|
||||||
// copy inheritance object?
|
|
||||||
if (isset($this->_inheritance)) {
|
|
||||||
$tpl->_inheritance = $this->_inheritance;
|
|
||||||
} else {
|
|
||||||
unset($tpl->_inheritance);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$tpl = clone $this;
|
|
||||||
$tpl->parent = $this;
|
|
||||||
if (!isset($tpl->templateId) || $tpl->templateId !== $_templateId) {
|
|
||||||
$tpl->templateId = $_templateId;
|
|
||||||
$tpl->template_resource = $template;
|
|
||||||
$tpl->cache_id = $cache_id;
|
|
||||||
$tpl->compile_id = $compile_id;
|
|
||||||
// $uid is set if template is inline
|
|
||||||
if (isset($uid)) {
|
|
||||||
// inline templates have same compiled resource
|
|
||||||
$tpl->compiled = $this->compiled;
|
|
||||||
// if template is called multiple times set flag to to cache template objects
|
|
||||||
if (isset($tpl->compiled->includes[$template]) && $tpl->compiled->includes[$template] > 1) {
|
|
||||||
$cache_tpl_obj = true;
|
|
||||||
}
|
|
||||||
if (isset($tpl->compiled->file_dependency[$uid])) {
|
|
||||||
list($filepath, $timestamp, $resource) = $tpl->compiled->file_dependency[$uid];
|
|
||||||
$tpl->source =
|
|
||||||
new Smarty_Template_Source(isset($tpl->smarty->_cache['resource_handlers'][$resource]) ?
|
|
||||||
$tpl->smarty->_cache['resource_handlers'][$resource] :
|
|
||||||
Smarty_Resource::load($tpl->smarty, $resource), $tpl->smarty,
|
|
||||||
$filepath, $resource, $filepath);
|
|
||||||
$tpl->source->filepath = $filepath;
|
|
||||||
$tpl->source->timestamp = $timestamp;
|
|
||||||
$tpl->source->exist = true;
|
|
||||||
$tpl->source->uid = $uid;
|
|
||||||
} else {
|
|
||||||
$tpl->source = null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$tpl->source = null;
|
|
||||||
unset($tpl->compiled);
|
|
||||||
}
|
|
||||||
if (!isset($tpl->source)) {
|
|
||||||
$tpl->source = Smarty_Template_Source::load($tpl);
|
|
||||||
}
|
|
||||||
unset($tpl->cached);
|
|
||||||
// check if template object should be cached
|
|
||||||
if (!$tpl->source->handler->recompiled && (isset($tpl->parent->templateId) &&
|
|
||||||
isset($tpl->smarty->_cache['template_objects'][$tpl->parent->templateId]) ||
|
|
||||||
($cache_tpl_obj && $tpl->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_AUTOMATIC) ||
|
|
||||||
$tpl->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)
|
|
||||||
) {
|
|
||||||
$tpl->smarty->_cache['template_objects'][$tpl->_getTemplateId()] = $tpl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$tpl->caching = $caching;
|
|
||||||
$tpl->cache_lifetime = $cache_lifetime;
|
|
||||||
if ($caching == 9999) {
|
|
||||||
$tpl->cached = $this->cached;
|
|
||||||
}
|
|
||||||
// get variables from calling scope
|
|
||||||
if ($parent_scope != Smarty::SCOPE_LOCAL) {
|
|
||||||
if ($parent_scope == Smarty::SCOPE_PARENT) {
|
|
||||||
$tpl->tpl_vars = &$this->tpl_vars;
|
|
||||||
$tpl->config_vars = &$this->config_vars;
|
|
||||||
} elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
|
|
||||||
$tpl->tpl_vars = &Smarty::$global_tpl_vars;
|
|
||||||
$tpl->config_vars = $this->config_vars;
|
|
||||||
} elseif ($parent_scope == Smarty::SCOPE_ROOT) {
|
|
||||||
$ptr = $tpl->parent;
|
|
||||||
while (!empty($ptr->parent)) {
|
|
||||||
$ptr = $ptr->parent;
|
|
||||||
}
|
|
||||||
$tpl->tpl_vars = &$ptr->tpl_vars;
|
|
||||||
$tpl->config_vars = &$ptr->config_vars;
|
|
||||||
} else {
|
|
||||||
$tpl->tpl_vars = $this->tpl_vars;
|
|
||||||
$tpl->config_vars = $this->config_vars;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($data)) {
|
|
||||||
// set up variable values
|
|
||||||
foreach ($data as $_key => $_val) {
|
|
||||||
$tpl->tpl_vars[$_key] = new Smarty_Variable($_val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $tpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template code runtime function to render inline subtemplate
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $tpl
|
|
||||||
* @param string $content_func name of content function
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function renderInline(Smarty_Internal_Template $tpl, $content_func)
|
|
||||||
{
|
|
||||||
if ($this->smarty->debugging) {
|
|
||||||
$this->smarty->_debug->start_template($tpl);
|
|
||||||
$this->smarty->_debug->start_render($tpl);
|
|
||||||
}
|
|
||||||
$tpl->compiled->getRenderedTemplateCode($tpl, $content_func);
|
|
||||||
if ($this->smarty->debugging) {
|
|
||||||
$this->smarty->_debug->end_template($tpl);
|
|
||||||
$this->smarty->_debug->end_render($tpl);
|
|
||||||
}
|
|
||||||
if ($tpl->caching == 9999 && $tpl->compiled->has_nocache_code) {
|
|
||||||
$this->cached->hashes[$tpl->compiled->nocache_hash] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call template function
|
|
||||||
*
|
|
||||||
* @param string $name template function name
|
|
||||||
* @param object|\Smarty_Internal_Template $_smarty_tpl template object
|
|
||||||
* @param array $params parameter array
|
|
||||||
* @param bool $nocache true if called nocache
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function callTemplateFunction($name, Smarty_Internal_Template $_smarty_tpl, $params, $nocache)
|
|
||||||
{
|
|
||||||
if (isset($_smarty_tpl->tpl_function[$name])) {
|
|
||||||
if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache)) {
|
|
||||||
$function = $_smarty_tpl->tpl_function[$name]['call_name'];
|
|
||||||
} else {
|
|
||||||
if (isset($_smarty_tpl->tpl_function[$name]['call_name_caching'])) {
|
|
||||||
$function = $_smarty_tpl->tpl_function[$name]['call_name_caching'];
|
|
||||||
} else {
|
|
||||||
$function = $_smarty_tpl->tpl_function[$name]['call_name'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (function_exists($function)) {
|
|
||||||
$function ($_smarty_tpl, $params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// try to load template function dynamically
|
|
||||||
if (Smarty_Internal_Function_Call_Handler::call($name, $_smarty_tpl, $function)) {
|
|
||||||
$function ($_smarty_tpl, $params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new SmartyException("Unable to find template function '{$name}'");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is executed automatically when a compiled or cached template file is included
|
* This function is executed automatically when a compiled or cached template file is included
|
||||||
* - Decode saved properties from compiled template and cache files
|
* - Decode saved properties from compiled template and cache files
|
||||||
@@ -538,62 +353,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
return $is_valid;
|
return $is_valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Template code runtime function to create a local Smarty variable for array assignments
|
|
||||||
*
|
|
||||||
* @param string $tpl_var template variable name
|
|
||||||
* @param bool $nocache cache mode of variable
|
|
||||||
* @param int $scope scope of variable
|
|
||||||
*/
|
|
||||||
public function createLocalArrayVariable($tpl_var, $nocache = false, $scope = Smarty::SCOPE_LOCAL)
|
|
||||||
{
|
|
||||||
if (!isset($this->tpl_vars[$tpl_var])) {
|
|
||||||
$this->tpl_vars[$tpl_var] = new Smarty_Variable(array(), $nocache, $scope);
|
|
||||||
} else {
|
|
||||||
$this->tpl_vars[$tpl_var] = clone $this->tpl_vars[$tpl_var];
|
|
||||||
if ($scope != Smarty::SCOPE_LOCAL) {
|
|
||||||
$this->tpl_vars[$tpl_var]->scope = $scope;
|
|
||||||
}
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [util function] counts an array, arrayAccess/traversable or PDOStatement object
|
|
||||||
*
|
|
||||||
* @param mixed $value
|
|
||||||
*
|
|
||||||
* @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0
|
|
||||||
* for empty elements
|
|
||||||
*/
|
|
||||||
public function _count($value)
|
|
||||||
{
|
|
||||||
if (is_array($value) === true || $value instanceof Countable) {
|
|
||||||
return count($value);
|
|
||||||
} elseif ($value instanceof IteratorAggregate) {
|
|
||||||
// Note: getIterator() returns a Traversable, not an Iterator
|
|
||||||
// thus rewind() and valid() methods may not be present
|
|
||||||
return iterator_count($value->getIterator());
|
|
||||||
} elseif ($value instanceof Iterator) {
|
|
||||||
return iterator_count($value);
|
|
||||||
} elseif ($value instanceof PDOStatement) {
|
|
||||||
return $value->rowCount();
|
|
||||||
} elseif ($value instanceof Traversable) {
|
|
||||||
return iterator_count($value);
|
|
||||||
} elseif ($value instanceof ArrayAccess) {
|
|
||||||
if ($value->offsetExists(0)) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} elseif (is_object($value)) {
|
|
||||||
return count($value);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* runtime error not matching capture tags
|
* runtime error not matching capture tags
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user