123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- <?php
- class Smarty_Internal_Runtime_Inheritance
- {
-
- public $state = 0;
-
- public $childRoot = array();
-
- public $inheritanceLevel = 0;
-
- public $tplIndex = - 1;
-
- public $sources = array();
-
- public $sourceStack = array();
-
- public function init(Smarty_Internal_Template $tpl, $initChild, $blockNames = array())
- {
-
- if ($initChild && $this->state == 3 && (strpos($tpl->template_resource, 'extendsall') === false)) {
- $tpl->inheritance = new Smarty_Internal_Runtime_Inheritance();
- $tpl->inheritance->init($tpl, $initChild, $blockNames);
- return;
- }
- $this->tplIndex ++;
- $this->sources[ $this->tplIndex ] = $tpl->source;
-
- if ($initChild) {
- $this->state = 1;
- if (!$this->inheritanceLevel) {
-
- ob_start();
- }
- $this->inheritanceLevel ++;
-
-
- }
-
- if ($this->state == 2) {
- $this->state = 3;
- }
- }
-
- public function endChild(Smarty_Internal_Template $tpl, $template = null, $uid = null, $func = null)
- {
- $this->inheritanceLevel --;
- if (!$this->inheritanceLevel) {
- ob_end_clean();
- $this->state = 2;
- }
- if (isset($template) && (($tpl->parent->_isTplObj() && $tpl->parent->source->type !== 'extends') || $tpl->smarty->extends_recursion)) {
- $tpl->_subTemplateRender($template, $tpl->cache_id, $tpl->compile_id, $tpl->caching ? 9999 : 0,
- $tpl->cache_lifetime, array(), 2, false, $uid, $func);
- }
- }
-
- public function instanceBlock(Smarty_Internal_Template $tpl, $className, $name, $tplIndex = null)
- {
- $block = new $className($name, isset($tplIndex) ? $tplIndex : $this->tplIndex);
- if (isset($this->childRoot[ $name ])) {
- $block->child = $this->childRoot[ $name ];
- }
- if ($this->state == 1) {
- $this->childRoot[ $name ] = $block;
- return;
- }
-
- while ($block->child && $block->tplIndex <= $block->child->tplIndex) {
- $block->child = $block->child->child;
- }
- $this->process($tpl, $block);
- }
-
- public function process(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block,
- Smarty_Internal_Block $parent = null)
- {
- if ($block->hide && !isset($block->child)) {
- return;
- }
- if (isset($block->child) && $block->child->hide && !isset($block->child->child)) {
- $block->child = null;
- }
- $block->parent = $parent;
- if ($block->append && !$block->prepend && isset($parent)) {
- $this->callParent($tpl, $block);
- }
- if ($block->callsChild || !isset($block->child) || ($block->child->hide && !isset($block->child->child))) {
- $this->callBlock($block, $tpl);
- } else {
- $this->process($tpl, $block->child, $block);
- }
- if ($block->prepend && isset($parent)) {
- $this->callParent($tpl, $block);
- if ($block->append) {
- if ($block->callsChild || !isset($block->child) ||
- ($block->child->hide && !isset($block->child->child))
- ) {
- $this->callBlock($block, $tpl);
- } else {
- $this->process($tpl, $block->child, $block);
- }
- }
- }
- $block->parent = null;
- }
-
- public function callChild(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block)
- {
- if (isset($block->child)) {
- $this->process($tpl, $block->child, $block);
- }
- }
-
- public function callParent(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block, $name = null)
- {
- if (isset($name)) {
- $block = $block->parent;
- while (isset($block)) {
- if (isset($block->subBlocks[ $name ])) {
- } else {
- $block = $block->parent;
- }
- }
- return;
- } else if (isset($block->parent)) {
- $this->callBlock($block->parent, $tpl);
- } else {
- throw new SmartyException("inheritance: illegal {\$smarty.block.parent} or {block append/prepend} used in parent template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'");
- }
- }
-
- public function callBlock(Smarty_Internal_Block $block, Smarty_Internal_Template $tpl)
- {
- $this->sourceStack[] = $tpl->source;
- $tpl->source = $this->sources[ $block->tplIndex ];
- $block->callBlock($tpl);
- $tpl->source = array_pop($this->sourceStack);
- }
- }
|