2009-03-22 16:09:05 +00:00
|
|
|
<?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.
|
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2010-08-17 15:39:51 +00:00
|
|
|
* @subpackage Compiler
|
2014-06-06 02:40:04 +00:00
|
|
|
* @author Uwe Tews
|
2010-08-17 15:39:51 +00:00
|
|
|
*/
|
|
|
|
|
2009-03-22 16:09:05 +00:00
|
|
|
/**
|
2010-08-17 15:39:51 +00:00
|
|
|
* Smarty Internal Plugin Compile Eval Class
|
2011-09-16 14:19:56 +00:00
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2011-09-16 14:19:56 +00:00
|
|
|
* @subpackage Compiler
|
|
|
|
*/
|
2013-07-14 22:15:45 +00:00
|
|
|
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
|
|
|
|
*/
|
2010-11-11 21:34:36 +00:00
|
|
|
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
|
|
|
|
*/
|
2014-06-06 02:40:04 +00:00
|
|
|
public $shorttag_order = array('var', 'assign');
|
2010-11-11 21:34:36 +00:00
|
|
|
|
2009-03-22 16:09:05 +00:00
|
|
|
/**
|
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
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
2010-08-17 15:39:51 +00:00
|
|
|
* @return string compiled code
|
|
|
|
*/
|
2009-03-22 16:09:05 +00:00
|
|
|
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' ])) {
|
2014-06-06 02:40:04 +00:00
|
|
|
// output will be stored in a smarty variable instead of being displayed
|
2016-02-09 01:27:15 +01:00
|
|
|
$_assign = $_attr[ 'assign' ];
|
2009-03-22 16:09:05 +00:00
|
|
|
}
|
|
|
|
// create template object
|
2018-08-31 16:45:09 +02:00
|
|
|
$_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?
|
2009-03-22 16:09:05 +00:00
|
|
|
if (isset($_assign)) {
|
2011-09-16 14:19:56 +00:00
|
|
|
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
|
2009-03-22 16:09:05 +00:00
|
|
|
} else {
|
2017-11-06 01:02:56 +01:00
|
|
|
$_output .= 'echo $_template->fetch();';
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2009-03-22 16:09:05 +00:00
|
|
|
return "<?php $_output ?>";
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
}
|