Files
smarty/libs/sysplugins/smarty_internal_compile_call.php

64 lines
2.2 KiB
PHP
Raw Normal View History

2009-04-24 19:59:51 +00:00
<?php
/**
* Smarty Internal Plugin Compile Function_Call
2009-04-24 19:59:51 +00:00
*
* Compiles the calls of user defined tags defined by {function}
2009-04-24 19:59:51 +00:00
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Function_Call Class
2009-04-24 19:59:51 +00:00
*/
class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
2009-04-24 19:59:51 +00:00
/**
* Compiles the calls of user defined tags defined by {function}
2009-04-24 19:59:51 +00:00
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @return string compiled code
*/
public function compile($args, $compiler)
{
$this->compiler = $compiler;
$this->required_attributes = array('name');
$this->optional_attributes = array('_any');
// check and get attributes
$_attr = $this->_get_attributes($args);
// save posible attributes
if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of beind displayed
$_assign = $_attr['assign'];
}
// set flag (compiled code of {function} must be included in cache file
if ($this->compiler->nocache || $this->compiler->tag_nocache) {
$nocache = 'true';
} else {
$nocache = 'false';
2009-04-24 19:59:51 +00:00
}
// create template object
$_output = "<?php \$_template = new Smarty_Internal_Function_Call_Handler ({$_attr['name']}, \$_smarty_tpl->smarty, \$_smarty_tpl, {$nocache});\n";
2009-04-24 19:59:51 +00:00
// delete {include} standard attributes
unset($_attr['name'], $_attr['assign']);
// remaining attributes must be assigned as smarty variable
if (!empty($_attr)) {
// create variables
foreach ($_attr as $_key => $_value) {
$_output .= "\$_template->assign('$_key',$_value);\n";
2009-04-24 19:59:51 +00:00
}
}
2009-04-24 19:59:51 +00:00
// was there an assign attribute
if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign({$_assign},\$_template->getRenderedTemplate());\n";
2009-04-24 19:59:51 +00:00
} else {
$_output .= "echo \$_template->getRenderedTemplate();\n";
2009-04-24 19:59:51 +00:00
}
$_output .= 'unset($_template);?>';
2009-04-24 19:59:51 +00:00
return $_output;
}
}
?>