Initial repo created
[timetracker.git] / WEB-INF / lib / smarty / sysplugins / smarty_internal_compile_eval.php
1 <?php
2
3 /**
4  * Smarty Internal Plugin Compile Eval
5  *
6  * Compiles the {eval} tag 
7  * @package Smarty
8  * @subpackage Compiler
9  * @author Uwe Tews
10  */
11
12 /**
13  * Smarty Internal Plugin Compile Eval Class
14  */ 
15 class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase {
16     public $required_attributes = array('var');
17     public $optional_attributes = array('assign'); 
18     public $shorttag_order = array('var','assign');
19
20     /**
21      * Compiles code for the {eval} tag
22      * 
23      * @param array $args array with attributes from parser
24      * @param object $compiler compiler object
25      * @return string compiled code
26      */
27     public function compile($args, $compiler)
28     {
29         $this->compiler = $compiler; 
30         $this->required_attributes = array('var');
31         $this->optional_attributes = array('assign'); 
32         // check and get attributes
33         $_attr = $this->_get_attributes($args); 
34         if (isset($_attr['assign'])) {
35               // output will be stored in a smarty variable instead of beind displayed
36             $_assign = $_attr['assign'];
37         }
38   
39         // create template object
40         $_output = "\$_template = new {$compiler->smarty->template_class}('eval:'.".$_attr['var'].", \$_smarty_tpl->smarty, \$_smarty_tpl);"; 
41         //was there an assign attribute? 
42         if (isset($_assign)) {
43             $_output .= "\$_smarty_tpl->assign($_assign,\$_template->getRenderedTemplate());";
44         } else {
45             $_output .= "echo \$_template->getRenderedTemplate();";
46         } 
47         return "<?php $_output ?>";
48     } 
49
50
51 ?>