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 /** |
|
12 * Smarty Internal Plugin Compile Capture Class |
|
13 * |
|
14 * @package Smarty |
|
15 * @subpackage Compiler |
|
16 */ |
|
17 class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase { |
|
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 /** |
|
34 * Compiles code for the {capture} tag |
|
35 * |
|
36 * @param array $args array with attributes from parser |
|
37 * @param object $compiler compiler object |
|
38 * |
|
39 * @return string compiled code |
|
40 */ |
|
41 public function compile($args, $compiler) { |
|
42 // check and get attributes |
|
43 $_attr = $this->getAttributes($compiler, $args); |
|
44 |
|
45 $buffer = isset($_attr['name']) ? $_attr['name'] : "'default'"; |
|
46 $assign = isset($_attr['assign']) ? $_attr['assign'] : 'null'; |
|
47 $append = isset($_attr['append']) ? $_attr['append'] : 'null'; |
|
48 |
|
49 $compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache); |
|
50 // maybe nocache because of nocache variables |
|
51 $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |
|
52 $_output = "<?php \$_smarty_tpl->_capture_stack[0][] = array($buffer, $assign, $append); ob_start(); ?>"; |
|
53 |
|
54 return $_output; |
|
55 } |
|
56 } |
|
57 |
|
58 /** |
|
59 * Smarty Internal Plugin Compile Captureclose Class |
|
60 * |
|
61 * @package Smarty |
|
62 * @subpackage Compiler |
|
63 */ |
|
64 class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase { |
|
65 /** |
|
66 * Compiles code for the {/capture} tag |
|
67 * |
|
68 * @param array $args array with attributes from parser |
|
69 * @param object $compiler compiler object |
|
70 * |
|
71 * @return string compiled code |
|
72 */ |
|
73 public function compile($args, $compiler) { |
|
74 // check and get attributes |
|
75 $_attr = $this->getAttributes($compiler, $args); |
|
76 // must endblock be nocache? |
|
77 if ($compiler->nocache) { |
|
78 $compiler->tag_nocache = true; |
|
79 } |
|
80 |
|
81 list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]); |
|
82 |
|
83 $_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack[0]);\n"; |
|
84 $_output .= "if (!empty(\$_capture_buffer)) {\n"; |
|
85 $_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n"; |
|
86 $_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n"; |
|
87 $_output .= " Smarty::\$_smarty_vars['capture'][\$_capture_buffer]=ob_get_clean();\n"; |
|
88 $_output .= "} else \$_smarty_tpl->capture_error();?>"; |
|
89 |
|
90 return $_output; |
|
91 } |
|
92 } |
|