Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

smarty_internal_compile_capture.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Capture
  4. * Compiles the {capture} tag
  5. *
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Capture Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
  17. {
  18. /**
  19. * Attribute definition: Overwrites base class.
  20. *
  21. * @var array
  22. * @see Smarty_Internal_CompileBase
  23. */
  24. public $shorttag_order = array('name');
  25. /**
  26. * Attribute definition: Overwrites base class.
  27. *
  28. * @var array
  29. * @see Smarty_Internal_CompileBase
  30. */
  31. public $optional_attributes = array('name', 'assign', 'append');
  32. /**
  33. * Compiles code for the {$smarty.capture.xxx}
  34. *
  35. * @param array $args array with attributes from parser
  36. * @param \Smarty_Internal_TemplateCompilerBase$compiler compiler object
  37. * @param array $parameter array with compilation parameter
  38. *
  39. * @return string compiled code
  40. * @throws \SmartyCompilerException
  41. */
  42. public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
  43. {
  44. $tag = trim($parameter[ 0 ], '"\'');
  45. $name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : null;
  46. if (!$name) {
  47. //$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
  48. }
  49. return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl'.(isset($name)?", '{$name}')":')');
  50. }
  51. /**
  52. * Compiles code for the {capture} tag
  53. *
  54. * @param array $args array with attributes from parser
  55. * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
  56. * @param null $parameter
  57. *
  58. * @return string compiled code
  59. */
  60. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
  61. {
  62. // check and get attributes
  63. $_attr = $this->getAttributes($compiler, $args, $parameter, 'capture');
  64. $buffer = isset($_attr[ 'name' ]) ? $_attr[ 'name' ] : "'default'";
  65. $assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : 'null';
  66. $append = isset($_attr[ 'append' ]) ? $_attr[ 'append' ] : 'null';
  67. $compiler->_cache[ 'capture_stack' ][] = array($compiler->nocache);
  68. // maybe nocache because of nocache variables
  69. $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
  70. $_output = "<?php \$_smarty_tpl->smarty->ext->_capture->open(\$_smarty_tpl, $buffer, $assign, $append);?>";
  71. return $_output;
  72. }
  73. }
  74. /**
  75. * Smarty Internal Plugin Compile Captureclose Class
  76. *
  77. * @package Smarty
  78. * @subpackage Compiler
  79. */
  80. class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
  81. {
  82. /**
  83. * Compiles code for the {/capture} tag
  84. *
  85. * @param array $args array with attributes from parser
  86. * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
  87. * @param null $parameter
  88. *
  89. * @return string compiled code
  90. */
  91. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
  92. {
  93. // check and get attributes
  94. $_attr = $this->getAttributes($compiler, $args, $parameter, '/capture');
  95. // must endblock be nocache?
  96. if ($compiler->nocache) {
  97. $compiler->tag_nocache = true;
  98. }
  99. list($compiler->nocache) = array_pop($compiler->_cache[ 'capture_stack' ]);
  100. return "<?php \$_smarty_tpl->smarty->ext->_capture->close(\$_smarty_tpl);?>";
  101. }
  102. }