library/smarty/libs/sysplugins/smarty_internal_compile_eval.php
changeset 0 4869aea77e21
equal deleted inserted replaced
-1:000000000000 0:4869aea77e21
       
     1 <?php
       
     2 /**
       
     3  * Smarty Internal Plugin Compile Eval
       
     4  * Compiles the {eval} tag.
       
     5  *
       
     6  * @package    Smarty
       
     7  * @subpackage Compiler
       
     8  * @author     Uwe Tews
       
     9  */
       
    10 
       
    11 /**
       
    12  * Smarty Internal Plugin Compile Eval Class
       
    13  *
       
    14  * @package    Smarty
       
    15  * @subpackage Compiler
       
    16  */
       
    17 class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase {
       
    18     /**
       
    19      * Attribute definition: Overwrites base class.
       
    20      *
       
    21      * @var array
       
    22      * @see Smarty_Internal_CompileBase
       
    23      */
       
    24     public $required_attributes = array('var');
       
    25     /**
       
    26      * Attribute definition: Overwrites base class.
       
    27      *
       
    28      * @var array
       
    29      * @see Smarty_Internal_CompileBase
       
    30      */
       
    31     public $optional_attributes = array('assign');
       
    32     /**
       
    33      * Attribute definition: Overwrites base class.
       
    34      *
       
    35      * @var array
       
    36      * @see Smarty_Internal_CompileBase
       
    37      */
       
    38     public $shorttag_order = array('var', 'assign');
       
    39 
       
    40     /**
       
    41      * Compiles code for the {eval} tag
       
    42      *
       
    43      * @param  array $args array with attributes from parser
       
    44      * @param  object $compiler compiler object
       
    45      *
       
    46      * @return string compiled code
       
    47      */
       
    48     public function compile($args, $compiler) {
       
    49         $this->required_attributes = array('var');
       
    50         $this->optional_attributes = array('assign');
       
    51         // check and get attributes
       
    52         $_attr = $this->getAttributes($compiler, $args);
       
    53         if (isset($_attr['assign'])) {
       
    54             // output will be stored in a smarty variable instead of being displayed
       
    55             $_assign = $_attr['assign'];
       
    56         }
       
    57 
       
    58         // create template object
       
    59         $_output = "\$_template = new {$compiler->smarty->template_class}('eval:'." . $_attr['var'] . ", \$_smarty_tpl->smarty, \$_smarty_tpl);";
       
    60         //was there an assign attribute?
       
    61         if (isset($_assign)) {
       
    62             $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
       
    63         } else {
       
    64             $_output .= "echo \$_template->fetch();";
       
    65         }
       
    66 
       
    67         return "<?php $_output ?>";
       
    68     }
       
    69 }