You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_internal_compile_eval.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. $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. // create template object
  58. $_output = "\$_template = new {$compiler->smarty->template_class}('eval:'." . $_attr['var'] . ", \$_smarty_tpl->smarty, \$_smarty_tpl);";
  59. //was there an assign attribute?
  60. if (isset($_assign)) {
  61. $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
  62. } else {
  63. $_output .= "echo \$_template->fetch();";
  64. }
  65. return "<?php $_output ?>";
  66. }
  67. }