Files
smarty/libs/sysplugins/smarty_internal_compile_call.php

90 lines
2.8 KiB
PHP
Raw Normal View History

2009-04-24 19:59:51 +00:00
<?php
/**
* Smarty Internal Plugin Compile Function_Call
* Compiles the calls of user defined tags defined by {function}
2011-09-16 14:19:56 +00:00
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
2010-08-17 15:39:51 +00:00
2009-04-24 19:59:51 +00:00
/**
* Smarty Internal Plugin Compile Function_Call Class
2011-09-16 14:19:56 +00:00
*
* @package Smarty
2011-09-16 14:19:56 +00:00
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
{
2011-09-16 14:19:56 +00:00
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('name');
2011-09-16 14:19:56 +00:00
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('name');
2011-09-16 14:19:56 +00:00
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('_any');
2009-04-24 19:59:51 +00:00
/**
* Compiles the calls of user defined tags defined by {function}
2011-09-16 14:19:56 +00:00
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
2009-04-24 19:59:51 +00:00
public function compile($args, $compiler)
{
// check and get attributes
2011-09-16 14:19:56 +00:00
$_attr = $this->getAttributes($compiler, $args);
// save possible attributes
2016-02-09 01:27:15 +01:00
if (isset($_attr[ 'assign' ])) {
// output will be stored in a smarty variable instead of being displayed
2016-02-09 01:27:15 +01:00
$_assign = $_attr[ 'assign' ];
2011-09-16 14:19:56 +00:00
}
//$_name = trim($_attr['name'], "'\"");
2016-02-09 01:27:15 +01:00
$_name = $_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) {
$_nocache = 'true';
} else {
$_nocache = 'false';
2011-09-16 14:19:56 +00:00
}
$_paramsArray = array();
foreach ($_attr as $_key => $_value) {
if (is_int($_key)) {
$_paramsArray[] = "$_key=>$_value";
} else {
$_paramsArray[] = "'$_key'=>$_value";
2011-09-16 14:19:56 +00:00
}
}
$_params = 'array(' . implode(",", $_paramsArray) . ')';
//$compiler->suppressNocacheProcessing = true;
2009-04-24 19:59:51 +00:00
// was there an assign attribute
if (isset($_assign)) {
$_output =
"<?php ob_start();\n\$_smarty_tpl->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
2009-04-24 19:59:51 +00:00
} else {
$_output =
"<?php \$_smarty_tpl->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n";
2011-09-16 14:19:56 +00:00
}
2009-04-24 19:59:51 +00:00
return $_output;
2011-09-16 14:19:56 +00:00
}
}