1: | <?php
|
2: |
|
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: |
|
10: | class Smarty_Internal_Runtime_Capture
|
11: | {
|
12: | |
13: | |
14: | |
15: | |
16: |
|
17: | public $isPrivateExtension = true;
|
18: |
|
19: | |
20: | |
21: | |
22: | |
23: |
|
24: | private $captureStack = array();
|
25: |
|
26: | |
27: | |
28: | |
29: | |
30: |
|
31: | private $captureCount = 0;
|
32: |
|
33: | |
34: | |
35: | |
36: | |
37: |
|
38: | private $countStack = array();
|
39: |
|
40: | |
41: | |
42: | |
43: | |
44: |
|
45: | private $namedBuffer = array();
|
46: |
|
47: | |
48: | |
49: | |
50: | |
51: |
|
52: | private $isRegistered = false;
|
53: |
|
54: | |
55: | |
56: | |
57: | |
58: | |
59: | |
60: | |
61: |
|
62: | public function open(Smarty_Internal_Template $_template, $buffer, $assign, $append)
|
63: | {
|
64: | if (!$this->isRegistered) {
|
65: | $this->register($_template);
|
66: | }
|
67: | $this->captureStack[] = array(
|
68: | $buffer,
|
69: | $assign,
|
70: | $append
|
71: | );
|
72: | $this->captureCount++;
|
73: | ob_start();
|
74: | }
|
75: |
|
76: | |
77: | |
78: | |
79: | |
80: |
|
81: | private function register(Smarty_Internal_Template $_template)
|
82: | {
|
83: | $_template->startRenderCallbacks[] = array(
|
84: | $this,
|
85: | 'startRender'
|
86: | );
|
87: | $_template->endRenderCallbacks[] = array(
|
88: | $this,
|
89: | 'endRender'
|
90: | );
|
91: | $this->startRender($_template);
|
92: | $this->isRegistered = true;
|
93: | }
|
94: |
|
95: | |
96: | |
97: | |
98: | |
99: |
|
100: | public function startRender(Smarty_Internal_Template $_template)
|
101: | {
|
102: | $this->countStack[] = $this->captureCount;
|
103: | $this->captureCount = 0;
|
104: | }
|
105: |
|
106: | |
107: | |
108: | |
109: | |
110: | |
111: | |
112: |
|
113: | public function close(Smarty_Internal_Template $_template)
|
114: | {
|
115: | if ($this->captureCount) {
|
116: | list($buffer, $assign, $append) = array_pop($this->captureStack);
|
117: | $this->captureCount--;
|
118: | if (isset($assign)) {
|
119: | $_template->assign($assign, ob_get_contents());
|
120: | }
|
121: | if (isset($append)) {
|
122: | $_template->append($append, ob_get_contents());
|
123: | }
|
124: | $this->namedBuffer[ $buffer ] = ob_get_clean();
|
125: | } else {
|
126: | $this->error($_template);
|
127: | }
|
128: | }
|
129: |
|
130: | |
131: | |
132: | |
133: | |
134: | |
135: | |
136: |
|
137: | public function error(Smarty_Internal_Template $_template)
|
138: | {
|
139: | throw new SmartyException("Not matching {capture}{/capture} in '{$_template->template_resource}'");
|
140: | }
|
141: |
|
142: | |
143: | |
144: | |
145: | |
146: | |
147: | |
148: | |
149: |
|
150: | public function getBuffer(Smarty_Internal_Template $_template, $name = null)
|
151: | {
|
152: | if (isset($name)) {
|
153: | return isset($this->namedBuffer[ $name ]) ? $this->namedBuffer[ $name ] : null;
|
154: | } else {
|
155: | return $this->namedBuffer;
|
156: | }
|
157: | }
|
158: |
|
159: | |
160: | |
161: | |
162: | |
163: | |
164: | |
165: |
|
166: | public function endRender(Smarty_Internal_Template $_template)
|
167: | {
|
168: | if ($this->captureCount) {
|
169: | $this->error($_template);
|
170: | } else {
|
171: | $this->captureCount = array_pop($this->countStack);
|
172: | }
|
173: | }
|
174: | }
|
175: | |