smarty_internal_compile_eval.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * Smarty Internal Plugin Compile Eval Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
  17. {
  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. *
  45. * @return string compiled code
  46. */
  47. public function compile($args, $compiler)
  48. {
  49. // check and get attributes
  50. $_attr = $this->getAttributes($compiler, $args);
  51. if (isset($_attr[ 'assign' ])) {
  52. // output will be stored in a smarty variable instead of being displayed
  53. $_assign = $_attr[ 'assign' ];
  54. }
  55. // create template object
  56. $_output = "\$_template = new {$compiler->smarty->template_class}('eval:'." . $_attr[ 'var' ] .
  57. ", \$_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. }