2015-12-25 09:10:39 +01:00
< ? php
/**
* Smarty { block } tag class
*
* @ package Smarty
* @ subpackage PluginsInternal
* @ author Uwe Tews
*/
class Smarty_Internal_Block
{
/**
* Block name
*
* @ var string
*/
public $name = '' ;
/**
* Hide attribute
*
* @ var bool
*/
public $hide = false ;
/**
* Append attribute
*
* @ var bool
*/
public $append = false ;
/**
* prepend attribute
*
* @ var bool
*/
public $prepend = false ;
/**
* Block calls { $smarty . block . child }
*
* @ var bool
*/
public $callsChild = false ;
/**
* Inheritance child block
*
* @ var Smarty_Internal_Block | null
*/
public $child = null ;
/**
* Inheritance calling parent block
*
* @ var Smarty_Internal_Block | null
*/
public $parent = null ;
/**
* Inheritance Template index
*
* @ var int
*/
public $tplIndex = 0 ;
/**
* Smarty_Internal_Block constructor .
2015-12-27 04:02:21 +01:00
* - if outer level { block } of child template ( $state == 1 ) save it as child root block
* - otherwise process inheritance and render
2015-12-25 09:10:39 +01:00
*
2015-12-27 04:02:21 +01:00
* @ param \Smarty_Internal_Template $tpl
* @ param int | null $tplIndex index of outer level { block } if nested
2015-12-25 09:10:39 +01:00
*/
2015-12-27 04:02:21 +01:00
public function __construct ( Smarty_Internal_Template $tpl , $tplIndex = null )
2015-12-25 09:10:39 +01:00
{
2015-12-27 04:02:21 +01:00
$this -> tplIndex = $tplIndex ? $tplIndex : $tpl -> ext -> _inheritance -> tplIndex ;
if ( isset ( $tpl -> ext -> _inheritance -> childRoot [ $this -> name ])) {
$this -> child = $tpl -> ext -> _inheritance -> childRoot [ $this -> name ];
2015-12-25 09:10:39 +01:00
}
2015-12-27 04:02:21 +01:00
if ( $tpl -> ext -> _inheritance -> state == 1 ) {
$tpl -> ext -> _inheritance -> childRoot [ $this -> name ] = $this ;
2015-12-25 09:10:39 +01:00
return ;
}
2015-12-27 04:02:21 +01:00
// make sure we got child block of child template of current block
while ( $this -> child && $this -> tplIndex <= $this -> child -> tplIndex ) {
$this -> child = $this -> child -> child ;
}
$this -> process ( $tpl );
2015-12-25 09:10:39 +01:00
}
/**
* Goto child block or render this
*
2015-12-27 04:02:21 +01:00
* @ param \Smarty_Internal_Template $tpl
2015-12-25 09:10:39 +01:00
* @ param \Smarty_Internal_Block | null $parent
*/
2015-12-27 04:02:21 +01:00
public function process ( Smarty_Internal_Template $tpl , Smarty_Internal_Block $parent = null )
{
2015-12-25 09:10:39 +01:00
if ( $this -> hide && ! isset ( $this -> child )) {
2015-12-27 04:02:21 +01:00
return ;
2015-12-25 09:10:39 +01:00
}
if ( isset ( $this -> child ) && $this -> child -> hide && ! isset ( $this -> child -> child )) {
$this -> child = null ;
}
$this -> parent = $parent ;
if ( $this -> append && ! $this -> prepend && isset ( $parent )) {
2015-12-27 04:02:21 +01:00
$this -> callParent ( $tpl );
2015-12-25 09:10:39 +01:00
}
if ( $this -> callsChild || ! isset ( $this -> child ) || ( $this -> child -> hide && ! isset ( $this -> child -> child ))) {
2015-12-27 04:02:21 +01:00
$this -> callBlock ( $tpl );
2015-12-25 09:10:39 +01:00
} else {
2015-12-27 04:02:21 +01:00
$this -> child -> process ( $tpl , $this );
2015-12-25 09:10:39 +01:00
}
if ( $this -> prepend && isset ( $parent )) {
2015-12-27 04:02:21 +01:00
$this -> callParent ( $tpl );
2015-12-25 09:10:39 +01:00
if ( $this -> append ) {
if ( $this -> callsChild || ! isset ( $this -> child ) || ( $this -> child -> hide && ! isset ( $this -> child -> child ))) {
2015-12-27 04:02:21 +01:00
$this -> callBlock ( $tpl );
2015-12-25 09:10:39 +01:00
} else {
2015-12-27 04:02:21 +01:00
$this -> child -> process ( $tpl , $this );
2015-12-25 09:10:39 +01:00
}
2015-12-27 04:02:21 +01:00
}
2015-12-25 09:10:39 +01:00
}
$this -> parent = null ;
}
/**
* Compiled block code overloaded by { block } class
*
2015-12-27 04:02:21 +01:00
* @ param \Smarty_Internal_Template $tpl
2015-12-25 09:10:39 +01:00
*/
2015-12-27 04:02:21 +01:00
public function callBlock ( Smarty_Internal_Template $tpl )
{
2015-12-25 09:10:39 +01:00
}
/**
* Render child on { $smarty . block . child }
*
2015-12-27 04:02:21 +01:00
* @ param \Smarty_Internal_Template $tpl
2015-12-25 09:10:39 +01:00
*/
2015-12-27 04:02:21 +01:00
public function callChild ( Smarty_Internal_Template $tpl )
{
2015-12-25 09:10:39 +01:00
if ( isset ( $this -> child )) {
2015-12-27 04:02:21 +01:00
$this -> child -> process ( $tpl , $this );
2015-12-25 09:10:39 +01:00
}
}
/**
* Render parent on { $smarty . block . parent } or { block append / prepend } *
*
2015-12-27 04:02:21 +01:00
* @ param \Smarty_Internal_Template $tpl
2015-12-25 09:10:39 +01:00
*
* @ throws \SmartyException
*/
2015-12-27 04:02:21 +01:00
public function callParent ( Smarty_Internal_Template $tpl )
{
2015-12-25 09:10:39 +01:00
if ( isset ( $this -> parent )) {
2015-12-27 04:02:21 +01:00
$this -> parent -> callBlock ( $tpl );
2015-12-25 09:10:39 +01:00
} else {
2015-12-27 04:02:21 +01:00
throw new SmartyException ( " inheritance: illegal { \$ smarty.block.parent} or { block append/prepend} used in parent template ' { $tpl -> ext -> _inheritance -> templateResource [ $this -> tplIndex ] } ' block ' { $this -> name } ' " );
2015-12-25 09:10:39 +01:00
}
}
}