smarty_internal_compile_eval.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Eval
  4. *
  5. * Compiles the {eval} tag.
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  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. * Compiles code for the {eval} tag
  41. *
  42. * @param array $args array with attributes from parser
  43. * @param object $compiler compiler object
  44. * @return string compiled code
  45. */
  46. public function compile($args, $compiler)
  47. {
  48. $this->required_attributes = array('var');
  49. $this->optional_attributes = array('assign');
  50. // check and get attributes
  51. $_attr = $this->getAttributes($compiler, $args);
  52. if (isset($_attr['assign'])) {
  53. // output will be stored in a smarty variable instead of beind displayed
  54. $_assign = $_attr['assign'];
  55. }
  56. // create template object
  57. $_output = "\$_template = new {$compiler->smarty->template_class}('eval:'.".$_attr['var'].", \$_smarty_tpl->smarty, \$_smarty_tpl);";
  58. //was there an assign attribute?
  59. if (isset($_assign)) {
  60. $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
  61. } else {
  62. $_output .= "echo \$_template->fetch();";
  63. }
  64. return "<?php $_output ?>";
  65. }
  66. }
  67. ?>