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 */
12 /**
13 * Smarty Internal Plugin Compile Capture Class
14 */
15 class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
16 // attribute definitions
17 public $shorttag_order = array('name');
18 public $optional_attributes = array('name', 'assign', 'append');
20 /**
21 * Compiles code for the {capture} tag
22 *
23 * @param array $args array with attributes from parser
24 * @param object $compiler compiler object
25 * @return string compiled code
26 */
27 public function compile($args, $compiler)
28 {
29 $this->compiler = $compiler;
30 // check and get attributes
31 $_attr = $this->_get_attributes($args);
33 $buffer = isset($_attr['name']) ? $_attr['name'] : "'default'";
34 $assign = isset($_attr['assign']) ? $_attr['assign'] : null;
35 $append = isset($_attr['append']) ? $_attr['append'] : null;
37 $this->compiler->_capture_stack[] = array($buffer, $assign, $append, $this->compiler->nocache);
38 // maybe nocache because of nocache variables
39 $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
40 $_output = "<?php ob_start(); ?>";
42 return $_output;
43 }
44 }
46 /**
47 * Smarty Internal Plugin Compile Captureclose Class
48 */
49 class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase {
50 /**
51 * Compiles code for the {/capture} tag
52 *
53 * @param array $args array with attributes from parser
54 * @param object $compiler compiler object
55 * @return string compiled code
56 */
57 public function compile($args, $compiler)
58 {
59 $this->compiler = $compiler;
60 // check and get attributes
61 $_attr = $this->_get_attributes($args);
62 // must endblock be nocache?
63 if ($this->compiler->nocache) {
64 $this->compiler->tag_nocache = true;
65 }
67 list($buffer, $assign, $append, $this->compiler->nocache) = array_pop($this->compiler->_capture_stack);
69 $_output = "<?php ";
70 if (isset($assign)) {
71 $_output .= " \$_smarty_tpl->assign($assign, ob_get_contents());";
72 }
73 if (isset($append)) {
74 $_output .= " \$_smarty_tpl->append($append, ob_get_contents());";
75 }
76 $_output .= " Smarty::\$_smarty_vars['capture'][$buffer]=ob_get_clean();?>";
77 return $_output;
78 }
79 }
81 ?>