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_parsetree_dq.php 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Double quoted string inside a tag.
  4. *
  5. * @package Smarty
  6. * @subpackage Compiler
  7. * @ignore
  8. */
  9. /**
  10. * Double quoted string inside a tag.
  11. *
  12. * @package Smarty
  13. * @subpackage Compiler
  14. * @ignore
  15. */
  16. class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree
  17. {
  18. /**
  19. * Create parse tree buffer for double quoted string subtrees
  20. *
  21. * @param object $parser parser object
  22. * @param Smarty_Internal_ParseTree $subtree parse tree buffer
  23. */
  24. public function __construct($parser, Smarty_Internal_ParseTree $subtree)
  25. {
  26. $this->subtrees[] = $subtree;
  27. if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
  28. $parser->block_nesting_level = count($parser->compiler->_tag_stack);
  29. }
  30. }
  31. /**
  32. * Append buffer to subtree
  33. *
  34. * @param \Smarty_Internal_Templateparser $parser
  35. * @param Smarty_Internal_ParseTree $subtree parse tree buffer
  36. */
  37. public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree)
  38. {
  39. $last_subtree = count($this->subtrees) - 1;
  40. if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof Smarty_Internal_ParseTree_Tag && $this->subtrees[$last_subtree]->saved_block_nesting < $parser->block_nesting_level) {
  41. if ($subtree instanceof Smarty_Internal_ParseTree_Code) {
  42. $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo ' . $subtree->data . ';?>');
  43. } elseif ($subtree instanceof Smarty_Internal_ParseTree_DqContent) {
  44. $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo "' . $subtree->data . '";?>');
  45. } else {
  46. $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, $subtree->data);
  47. }
  48. } else {
  49. $this->subtrees[] = $subtree;
  50. }
  51. if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
  52. $parser->block_nesting_level = count($parser->compiler->_tag_stack);
  53. }
  54. }
  55. /**
  56. * Merge subtree buffer content together
  57. *
  58. * @param \Smarty_Internal_Templateparser $parser
  59. *
  60. * @return string compiled template code
  61. */
  62. public function to_smarty_php(Smarty_Internal_Templateparser $parser)
  63. {
  64. $code = '';
  65. foreach ($this->subtrees as $subtree) {
  66. if ($code !== "") {
  67. $code .= ".";
  68. }
  69. if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
  70. $more_php = $subtree->assign_to_var($parser);
  71. } else {
  72. $more_php = $subtree->to_smarty_php($parser);
  73. }
  74. $code .= $more_php;
  75. if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) {
  76. $parser->compiler->has_variable_string = true;
  77. }
  78. }
  79. return $code;
  80. }
  81. }