123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
-
-
- class Smarty_Internal_Runtime_Inheritance
- {
-
-
-
- public $state = 0;
-
-
-
- public $blockParameter = array();
-
-
-
- public $inheritanceLevel = 0;
-
-
-
- public $tplIndex = - 1;
-
-
-
- public $compiledFilePath = array();
-
-
-
- public $blockNesting = 0;
-
-
-
- public function init(Smarty_Internal_Template $tpl, $initChild, $blockNames = array())
- {
-
- if ($initChild && ($this->blockNesting || $this->state == 3)) {
- $tpl->ext->_inheritance = new Smarty_Internal_Runtime_Inheritance();
- $tpl->ext->_inheritance->init($tpl, $initChild, $blockNames);
- return;
- }
-
- if ($initChild) {
- $this->state = 1;
- if (!$this->inheritanceLevel) {
-
- ob_start();
- }
- $this->inheritanceLevel ++;
- }
-
- if ($this->state != 3) {
- $this->tplIndex ++;
- }
-
- if ($this->state == 2) {
- $this->state = 3;
- }
- }
-
-
-
- public function endChild(Smarty_Internal_Template $tpl)
- {
- $this->inheritanceLevel --;
- if (!$this->inheritanceLevel) {
- ob_end_clean();
- $this->state = 2;
- }
- }
-
-
-
- public function processBlock(Smarty_Internal_Template $tpl, $type = 0, $name, $block, $callStack = array())
- {
- if (!isset($this->blockParameter[ $name ])) {
- $this->blockParameter[ $name ] = array();
- }
- if ($this->state == 1) {
- $block[ 2 ] = count($this->blockParameter[ $name ]);
- $block[ 3 ] = $this->tplIndex;
- $this->blockParameter[ $name ][] = $block;
- return;
- }
- if ($type == 3) {
- if (!empty($callStack)) {
- $block = array_shift($callStack);
- } else {
- return;
- }
- } elseif ($type == 4) {
- if (!empty($callStack)) {
- array_shift($callStack);
- if (empty($callStack)) {
- throw new SmartyException("inheritance: tag {\$smarty.block.parent} used in parent template block '{$name}'");
- }
- $block = array_shift($callStack);
- } else {
- return;
- }
- } else {
- $index = 0;
- $blockParameter = &$this->blockParameter[ $name ];
- if ($type == 0) {
- $index = $block[ 2 ] = count($blockParameter);
- $block[ 3 ] = $this->tplIndex;
- $callStack = array(&$block);
- } elseif ($type == 1) {
- $block[ 3 ] = $callStack[ 0 ][ 3 ];
- for ($i = 0; $i < count($blockParameter); $i ++) {
- if ($blockParameter[ $i ][ 3 ] <= $block[ 3 ]) {
- $index = $blockParameter[ $i ][ 2 ];
- }
- }
- $block[ 2 ] = $index;
- $callStack = array(&$block);
- } elseif ($type == 2) {
- $index = $callStack[ 0 ][ 2 ];
- if ($index == 0) {
- return;
- }
- $callStack = $block = array(1 => false);
- }
- $index --;
-
- while ($index >= 0 && ($type || !$block[ 1 ])) {
- $block = &$blockParameter[ $index ];
- array_unshift($callStack, $block);
- if ($block[ 1 ]) {
- break;
- }
- $index --;
- }
- if (isset($block[ 'hide' ]) && $index <= 0) {
- return;
- }
- }
- $this->blockNesting ++;
-
- if (isset($block[ 'append' ])) {
- $appendStack = $callStack;
- if ($type == 0) {
- array_shift($appendStack);
- }
- $this->processBlock($tpl, 3, $name, null, $appendStack);
- }
-
- if (isset($block[6])) {
- $block[6]($tpl, $callStack);
- } else {
- $block[0]($tpl, $callStack);
- }
-
- if (isset($block[ 'prepend' ])) {
- $prependStack = $callStack;
- if ($type == 0) {
- array_shift($prependStack);
- }
- $this->processBlock($tpl, 3, $name, null, $prependStack);
- }
- $this->blockNesting --;
- }
- }
|