smarty_internal_compile_capture.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Capture
  4. *
  5. * Compiles the {capture} tag
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Capture Class
  13. */
  14. class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
  15. /**
  16. * Compiles code for the {capture} tag
  17. *
  18. * @param array $args array with attributes from parser
  19. * @param object $compiler compiler object
  20. * @return string compiled code
  21. */
  22. public function compile($args, $compiler)
  23. {
  24. $this->compiler = $compiler;
  25. $this->optional_attributes = array('name', 'assign', 'append');
  26. // check and get attributes
  27. $_attr = $this->_get_attributes($args);
  28. $buffer = isset($_attr['name']) ? $_attr['name'] : "'default'";
  29. $assign = isset($_attr['assign']) ? $_attr['assign'] : null;
  30. $append = isset($_attr['append']) ? $_attr['append'] : null;
  31. $this->compiler->_capture_stack[] = array($buffer, $assign, $append);
  32. $_output = "<?php ob_start(); ?>";
  33. return $_output;
  34. }
  35. }
  36. /**
  37. * Smarty Internal Plugin Compile Captureclose Class
  38. */
  39. class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase {
  40. /**
  41. * Compiles code for the {/capture} tag
  42. *
  43. * @param array $args array with attributes from parser
  44. * @param object $compiler compiler object
  45. * @return string compiled code
  46. */
  47. public function compile($args, $compiler)
  48. {
  49. $this->compiler = $compiler;
  50. // check and get attributes
  51. $_attr = $this->_get_attributes($args);
  52. list($buffer, $assign, $append) = array_pop($this->compiler->_capture_stack);
  53. $_output = "<?php ";
  54. if (isset($assign)) {
  55. $_output .= " \$_smarty_tpl->assign($assign, ob_get_contents());";
  56. }
  57. if (isset($append)) {
  58. $_output .= " \$_smarty_tpl->append($append, ob_get_contents());";
  59. }
  60. $_output .= " \$_smarty_tpl->smarty->_smarty_vars['capture'][$buffer]=ob_get_clean();?>";
  61. return $_output;
  62. }
  63. }
  64. ?>