Files
smarty/libs/sysplugins/smarty_internal_compile_eval.php

71 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
/**
2010-08-17 15:39:51 +00:00
* Smarty Internal Plugin Compile Eval
2011-09-16 14:19:56 +00:00
* Compiles the {eval} tag.
*
* @package Smarty
2010-08-17 15:39:51 +00:00
* @subpackage Compiler
* @author Uwe Tews
2010-08-17 15:39:51 +00:00
*/
/**
2010-08-17 15:39:51 +00:00
* Smarty Internal Plugin Compile Eval 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_Eval 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('var');
2016-02-09 01:27:15 +01:00
2011-09-16 14:19:56 +00:00
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('assign');
2016-02-09 01:27:15 +01:00
2011-09-16 14:19:56 +00:00
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('var', 'assign');
/**
2010-08-17 15:39:51 +00:00
* Compiles code for the {eval} tag
2011-09-16 14:19:56 +00:00
*
2018-06-12 09:58:15 +02:00
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
2010-08-17 15:39:51 +00:00
* @return string compiled code
*/
public function compile($args, $compiler)
{
// check and get attributes
2011-09-16 14:19:56 +00:00
$_attr = $this->getAttributes($compiler, $args);
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' ];
}
// create template object
$_output =
"\$_template = new {$compiler->smarty->template_class}('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);";
2011-09-16 14:19:56 +00:00
//was there an assign attribute?
if (isset($_assign)) {
2011-09-16 14:19:56 +00:00
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
} else {
$_output .= 'echo $_template->fetch();';
2011-09-16 14:19:56 +00:00
}
return "<?php $_output ?>";
2011-09-16 14:19:56 +00:00
}
}