1: | <?php
|
2: |
|
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: |
|
10: | class Smarty_Internal_Runtime_Inheritance
|
11: | {
|
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: |
|
22: | public $state = 0;
|
23: |
|
24: | |
25: | |
26: | |
27: | |
28: |
|
29: | public $childRoot = array();
|
30: |
|
31: | |
32: | |
33: | |
34: | |
35: |
|
36: | public $inheritanceLevel = 0;
|
37: |
|
38: | |
39: | |
40: | |
41: | |
42: |
|
43: | public $tplIndex = -1;
|
44: |
|
45: | |
46: | |
47: | |
48: | |
49: |
|
50: | public $sources = array();
|
51: |
|
52: | |
53: | |
54: | |
55: | |
56: |
|
57: | public $sourceStack = array();
|
58: |
|
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: |
|
66: | public function init(Smarty_Internal_Template $tpl, $initChild, $blockNames = array())
|
67: | {
|
68: |
|
69: | if ($initChild && $this->state === 3 && (strpos($tpl->template_resource, 'extendsall') === false)) {
|
70: | $tpl->inheritance = new Smarty_Internal_Runtime_Inheritance();
|
71: | $tpl->inheritance->init($tpl, $initChild, $blockNames);
|
72: | return;
|
73: | }
|
74: | ++$this->tplIndex;
|
75: | $this->sources[ $this->tplIndex ] = $tpl->source;
|
76: |
|
77: | if ($initChild) {
|
78: | $this->state = 1;
|
79: | if (!$this->inheritanceLevel) {
|
80: |
|
81: | ob_start();
|
82: | }
|
83: | ++$this->inheritanceLevel;
|
84: |
|
85: |
|
86: | }
|
87: |
|
88: | if ($this->state === 2) {
|
89: | $this->state = 3;
|
90: | }
|
91: | }
|
92: |
|
93: | |
94: | |
95: | |
96: | |
97: | |
98: | |
99: | |
100: | |
101: | |
102: | |
103: | |
104: |
|
105: | public function endChild(Smarty_Internal_Template $tpl, $template = null, $uid = null, $func = null)
|
106: | {
|
107: | --$this->inheritanceLevel;
|
108: | if (!$this->inheritanceLevel) {
|
109: | ob_end_clean();
|
110: | $this->state = 2;
|
111: | }
|
112: | if (isset($template) && (($tpl->parent->_isTplObj() && $tpl->parent->source->type !== 'extends')
|
113: | || $tpl->smarty->extends_recursion)
|
114: | ) {
|
115: | $tpl->_subTemplateRender(
|
116: | $template,
|
117: | $tpl->cache_id,
|
118: | $tpl->compile_id,
|
119: | $tpl->caching ? 9999 : 0,
|
120: | $tpl->cache_lifetime,
|
121: | array(),
|
122: | 2,
|
123: | false,
|
124: | $uid,
|
125: | $func
|
126: | );
|
127: | }
|
128: | }
|
129: |
|
130: | |
131: | |
132: | |
133: | |
134: | |
135: | |
136: | |
137: | |
138: | |
139: | |
140: | |
141: |
|
142: | public function instanceBlock(Smarty_Internal_Template $tpl, $className, $name, $tplIndex = null)
|
143: | {
|
144: | $block = new $className($name, isset($tplIndex) ? $tplIndex : $this->tplIndex);
|
145: | if (isset($this->childRoot[ $name ])) {
|
146: | $block->child = $this->childRoot[ $name ];
|
147: | }
|
148: | if ($this->state === 1) {
|
149: | $this->childRoot[ $name ] = $block;
|
150: | return;
|
151: | }
|
152: |
|
153: | while ($block->child && $block->child->child && $block->tplIndex <= $block->child->tplIndex) {
|
154: | $block->child = $block->child->child;
|
155: | }
|
156: | $this->process($tpl, $block);
|
157: | }
|
158: |
|
159: | |
160: | |
161: | |
162: | |
163: | |
164: | |
165: | |
166: | |
167: |
|
168: | public function process(
|
169: | Smarty_Internal_Template $tpl,
|
170: | Smarty_Internal_Block $block,
|
171: | Smarty_Internal_Block $parent = null
|
172: | ) {
|
173: | if ($block->hide && !isset($block->child)) {
|
174: | return;
|
175: | }
|
176: | if (isset($block->child) && $block->child->hide && !isset($block->child->child)) {
|
177: | $block->child = null;
|
178: | }
|
179: | $block->parent = $parent;
|
180: | if ($block->append && !$block->prepend && isset($parent)) {
|
181: | $this->callParent($tpl, $block, '\'{block append}\'');
|
182: | }
|
183: | if ($block->callsChild || !isset($block->child) || ($block->child->hide && !isset($block->child->child))) {
|
184: | $this->callBlock($block, $tpl);
|
185: | } else {
|
186: | $this->process($tpl, $block->child, $block);
|
187: | }
|
188: | if ($block->prepend && isset($parent)) {
|
189: | $this->callParent($tpl, $block, '{block prepend}');
|
190: | if ($block->append) {
|
191: | if ($block->callsChild || !isset($block->child)
|
192: | || ($block->child->hide && !isset($block->child->child))
|
193: | ) {
|
194: | $this->callBlock($block, $tpl);
|
195: | } else {
|
196: | $this->process($tpl, $block->child, $block);
|
197: | }
|
198: | }
|
199: | }
|
200: | $block->parent = null;
|
201: | }
|
202: |
|
203: | |
204: | |
205: | |
206: | |
207: | |
208: | |
209: | |
210: | |
211: |
|
212: | public function callChild(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block)
|
213: | {
|
214: | if (isset($block->child)) {
|
215: | $this->process($tpl, $block->child, $block);
|
216: | }
|
217: | }
|
218: |
|
219: | |
220: | |
221: | |
222: | |
223: | |
224: | |
225: | |
226: | |
227: | |
228: |
|
229: | public function callParent(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block, $tag)
|
230: | {
|
231: | if (isset($block->parent)) {
|
232: | $this->callBlock($block->parent, $tpl);
|
233: | } else {
|
234: | throw new SmartyException("inheritance: illegal '{$tag}' used in child template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'");
|
235: | }
|
236: | }
|
237: |
|
238: | |
239: | |
240: | |
241: | |
242: | |
243: |
|
244: | public function callBlock(Smarty_Internal_Block $block, Smarty_Internal_Template $tpl)
|
245: | {
|
246: | $this->sourceStack[] = $tpl->source;
|
247: | $tpl->source = $this->sources[ $block->tplIndex ];
|
248: | $block->callBlock($tpl);
|
249: | $tpl->source = array_pop($this->sourceStack);
|
250: | }
|
251: | }
|
252: | |