2012-07-04 01:23:08 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Smarty Internal Plugin Compile Eval
|
|
|
|
* Compiles the {eval} tag.
|
|
|
|
*
|
2014-09-07 07:38:28 -04:00
|
|
|
* @package Smarty
|
2012-07-04 01:23:08 -04:00
|
|
|
* @subpackage Compiler
|
2014-09-07 07:38:28 -04:00
|
|
|
* @author Uwe Tews
|
2012-07-04 01:23:08 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Smarty Internal Plugin Compile Eval Class
|
|
|
|
*
|
2014-09-07 07:38:28 -04:00
|
|
|
* @package Smarty
|
2012-07-04 01:23:08 -04:00
|
|
|
* @subpackage Compiler
|
|
|
|
*/
|
2014-09-07 07:38:28 -04:00
|
|
|
class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
|
|
|
|
{
|
2012-07-04 01:23:08 -04:00
|
|
|
/**
|
|
|
|
* Attribute definition: Overwrites base class.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @see Smarty_Internal_CompileBase
|
|
|
|
*/
|
|
|
|
public $required_attributes = array('var');
|
|
|
|
/**
|
|
|
|
* Attribute definition: Overwrites base class.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @see Smarty_Internal_CompileBase
|
|
|
|
*/
|
|
|
|
public $optional_attributes = array('assign');
|
|
|
|
/**
|
|
|
|
* Attribute definition: Overwrites base class.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @see Smarty_Internal_CompileBase
|
|
|
|
*/
|
2014-09-07 07:38:28 -04:00
|
|
|
public $shorttag_order = array('var', 'assign');
|
2012-07-04 01:23:08 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compiles code for the {eval} tag
|
|
|
|
*
|
2014-09-07 07:38:28 -04:00
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param object $compiler compiler object
|
|
|
|
*
|
2012-07-04 01:23:08 -04:00
|
|
|
* @return string compiled code
|
|
|
|
*/
|
|
|
|
public function compile($args, $compiler)
|
|
|
|
{
|
|
|
|
$this->required_attributes = array('var');
|
|
|
|
$this->optional_attributes = array('assign');
|
|
|
|
// check and get attributes
|
|
|
|
$_attr = $this->getAttributes($compiler, $args);
|
|
|
|
if (isset($_attr['assign'])) {
|
2014-09-07 07:38:28 -04:00
|
|
|
// output will be stored in a smarty variable instead of being displayed
|
2012-07-04 01:23:08 -04:00
|
|
|
$_assign = $_attr['assign'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// create template object
|
2014-09-07 07:38:28 -04:00
|
|
|
$_output = "\$_template = new {$compiler->smarty->template_class}('eval:'." . $_attr['var'] . ", \$_smarty_tpl->smarty, \$_smarty_tpl);";
|
2012-07-04 01:23:08 -04:00
|
|
|
//was there an assign attribute?
|
|
|
|
if (isset($_assign)) {
|
|
|
|
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
|
|
|
|
} else {
|
|
|
|
$_output .= "echo \$_template->fetch();";
|
|
|
|
}
|
2014-09-07 07:38:28 -04:00
|
|
|
|
2012-07-04 01:23:08 -04:00
|
|
|
return "<?php $_output ?>";
|
|
|
|
}
|
|
|
|
}
|