mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-03 05:41:37 +01:00
* Calling a template which has a nocache section could fail if it was called from a cached and a not cached subtemplate. * Calling the same subtemplate cached and not cached with the $smarty->merge_compiled_includes enabled could cause problems * Many smaller related changes
86 lines
2.8 KiB
PHP
86 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Smarty Internal Plugin Compile Function_Call
|
|
* Compiles the calls of user defined tags defined by {function}
|
|
*
|
|
* @package Smarty
|
|
* @subpackage Compiler
|
|
* @author Uwe Tews
|
|
*/
|
|
|
|
/**
|
|
* Smarty Internal Plugin Compile Function_Call Class
|
|
*
|
|
* @package Smarty
|
|
* @subpackage Compiler
|
|
*/
|
|
class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
|
|
{
|
|
/**
|
|
* Attribute definition: Overwrites base class.
|
|
*
|
|
* @var array
|
|
* @see Smarty_Internal_CompileBase
|
|
*/
|
|
public $required_attributes = array('name');
|
|
/**
|
|
* Attribute definition: Overwrites base class.
|
|
*
|
|
* @var array
|
|
* @see Smarty_Internal_CompileBase
|
|
*/
|
|
public $shorttag_order = array('name');
|
|
/**
|
|
* Attribute definition: Overwrites base class.
|
|
*
|
|
* @var array
|
|
* @see Smarty_Internal_CompileBase
|
|
*/
|
|
public $optional_attributes = array('_any');
|
|
|
|
/**
|
|
* Compiles the calls of user defined tags defined by {function}
|
|
*
|
|
* @param array $args array with attributes from parser
|
|
* @param object $compiler compiler object
|
|
*
|
|
* @return string compiled code
|
|
*/
|
|
public function compile($args, $compiler)
|
|
{
|
|
// check and get attributes
|
|
$_attr = $this->getAttributes($compiler, $args);
|
|
// save possible attributes
|
|
if (isset($_attr['assign'])) {
|
|
// output will be stored in a smarty variable instead of being displayed
|
|
$_assign = $_attr['assign'];
|
|
}
|
|
$_name = trim($_attr['name'], "'\"");
|
|
unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
|
|
// set flag (compiled code of {function} must be included in cache file
|
|
if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) {
|
|
$compiler->parent_compiler->templateProperties['tpl_function']['to_cache'][$_name] = true;
|
|
$_nocache = 'true';
|
|
} else {
|
|
$_nocache = 'false';
|
|
}
|
|
$_paramsArray = array();
|
|
foreach ($_attr as $_key => $_value) {
|
|
if (is_int($_key)) {
|
|
$_paramsArray[] = "$_key=>$_value";
|
|
} else {
|
|
$_paramsArray[] = "'$_key'=>$_value";
|
|
}
|
|
}
|
|
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
|
//$compiler->suppressNocacheProcessing = true;
|
|
// was there an assign attribute
|
|
if (isset($_assign)) {
|
|
$_output = "<?php ob_start();\$_smarty_tpl->callTemplateFunction ('{$_name}', \$_smarty_tpl, {$_params}, {$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
|
|
} else {
|
|
$_output = "<?php \$_smarty_tpl->callTemplateFunction ('{$_name}', \$_smarty_tpl, {$_params}, {$_nocache});?>\n";
|
|
}
|
|
return $_output;
|
|
}
|
|
}
|