📄 class.template.php
字号:
{
//no end curly bracket '}' found
//so, the curly bracket is part of the text. Save as code, with the '{'
$this->defBlock[$blockname]["_C:$coderow"] = '{'. current( $sstr );
$coderow++;
}
}
}
}
else
{
$this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index];
$coderow++;
}
}
$index++;
}
$initdev["varrow"] = $varrow;
$initdev["coderow"] = $coderow;
$initdev["index"] = $index;
return $initdev;
}
function version()
{
return $this->version;
}
function assignInclude( $iblockname, $value, $type=T_BYFILE )
{
$this->tpl_include["$iblockname"] = Array( $value, $type );
}
}
class TemplatePower extends TemplatePowerParser
{
var $index = Array(); // $index[{blockname}] = {indexnumber}
var $content = Array();
var $currentBlock;
var $showUnAssigned;
var $serialized;
var $globalvars = Array();
var $prepared;
function TemplatePower( $tpl_file='', $type= T_BYFILE )
{
TemplatePowerParser::TemplatePowerParser( $tpl_file, $type );
$this->prepared = false;
$this->showUnAssigned = false;
$this->serialized = false; //added: 26 April 2002
}
function __deSerializeTPL( $stpl_file, $type )
{
if( $type == T_BYFILE )
{
$serializedTPL = @file( $stpl_file ) or
die( $this->__errorAlert('TemplatePower Error: Can\'t open [ '. $stpl_file .' ]!'));
}
else
{
$serializedTPL = $stpl_file;
}
$serializedStuff = unserialize( join ('', $serializedTPL) );
$this->defBlock = $serializedStuff["defBlock"];
$this->index = $serializedStuff["index"];
$this->parent = $serializedStuff["parent"];
}
function __makeContentRoot()
{
$this->content[ TP_ROOTBLOCK ."_0" ][0] = Array( TP_ROOTBLOCK );
$this->currentBlock = &$this->content[ TP_ROOTBLOCK ."_0" ][0];
}
function __assign( $varname, $value)
{
if( sizeof( $regs = explode('.', $varname ) ) == 2 ) //this is faster then preg_match
{
$ind_blockname = $regs[0] .'_'. $this->index[ $regs[0] ];
$lastitem = sizeof( $this->content[ $ind_blockname ] );
$lastitem > 1 ? $lastitem-- : $lastitem = 0;
$block = &$this->content[ $ind_blockname ][ $lastitem ];
$varname = $regs[1];
}
else
{
$block = &$this->currentBlock;
}
$block["_V:$varname"] = $value;
}
function __assignGlobal( $varname, $value )
{
$this->globalvars[ $varname ] = $value;
}
function __outputContent( $blockname )
{
$numrows = sizeof( $this->content[ $blockname ] );
for( $i=0; $i < $numrows; $i++)
{
$defblockname = $this->content[ $blockname ][$i][0];
for( reset( $this->defBlock[ $defblockname ]); $k = key( $this->defBlock[ $defblockname ]); next( $this->defBlock[ $defblockname ] ) )
{
if ($k[1] == 'C')
{
print( $this->defBlock[ $defblockname ][$k] );
}
else
if ($k[1] == 'V')
{
$defValue = $this->defBlock[ $defblockname ][$k];
if( !isset( $this->content[ $blockname ][$i][ "_V:". $defValue ] ) )
{
if( isset( $this->globalvars[ $defValue ] ) )
{
$value = $this->globalvars[ $defValue ];
}
else
{
if( $this->showUnAssigned )
{
//$value = '{'. $this->defBlock[ $defblockname ][$k] .'}';
$value = '{'. $defValue .'}';
}
else
{
$value = '';
}
}
}
else
{
$value = $this->content[ $blockname ][$i][ "_V:". $defValue ];
}
print( $value );
}
else
if ($k[1] == 'B')
{
if( isset( $this->content[ $blockname ][$i][$k] ) )
{
$this->__outputContent( $this->content[ $blockname ][$i][$k] );
}
}
}
}
}
function __printVars()
{
var_dump($this->defBlock);
print("<br>--------------------<br>");
var_dump($this->content);
}
function serializedBase()
{
$this->serialized = true;
$this->__deSerializeTPL( $this->tpl_base[0], $this->tpl_base[1] );
}
function showUnAssigned( $state = true )
{
$this->showUnAssigned = $state;
}
function prepare()
{
if (!$this->serialized)
{
TemplatePowerParser::__prepare();
}
$this->prepared = true;
$this->index[ TP_ROOTBLOCK ] = 0;
$this->__makeContentRoot();
}
function newBlock( $blockname )
{
$parent = &$this->content[ $this->parent[$blockname] .'_'. $this->index[$this->parent[$blockname]] ];
$lastitem = sizeof( $parent );
$lastitem > 1 ? $lastitem-- : $lastitem = 0;
$ind_blockname = $blockname .'_'. $this->index[ $blockname ];
if ( !isset( $parent[ $lastitem ]["_B:$blockname"] ))
{
//ok, there is no block found in the parentblock with the name of {$blockname}
//so, increase the index counter and create a new {$blockname} block
$this->index[ $blockname ] += 1;
$ind_blockname = $blockname .'_'. $this->index[ $blockname ];
if (!isset( $this->content[ $ind_blockname ] ) )
{
$this->content[ $ind_blockname ] = Array();
}
//tell the parent where his (possible) children are located
$parent[ $lastitem ]["_B:$blockname"] = $ind_blockname;
}
//now, make a copy of the block defenition
$blocksize = sizeof( $this->content[ $ind_blockname ] );
$this->content[ $ind_blockname ][ $blocksize ] = Array( $blockname );
//link the current block to the block we just created
$this->currentBlock = &$this->content[ $ind_blockname ][ $blocksize ];
}
function assignGlobal( $varname, $value='' )
{
if (is_array( $varname ))
{
foreach($varname as $var => $value)
{
$this->__assignGlobal( $var, $value );
}
}
else
{
$this->__assignGlobal( $varname, $value );
}
}
function assign( $varname, $value='' )
{
if (is_array( $varname ))
{
foreach($varname as $var => $value)
{
$this->__assign( $var, $value );
}
}
else
{
$this->__assign( $varname, $value );
}
}
function gotoBlock( $blockname )
{
if ( isset( $this->defBlock[ $blockname ] ) )
{
$ind_blockname = $blockname .'_'. $this->index[ $blockname ];
//get lastitem indexnumber
$lastitem = sizeof( $this->content[ $ind_blockname ] );
$lastitem > 1 ? $lastitem-- : $lastitem = 0;
//link the current block
$this->currentBlock = &$this->content[ $ind_blockname ][ $lastitem ];
}
}
function getVarValue( $varname )
{
if( sizeof( $regs = explode('.', $varname ) ) == 2 ) //this is faster then preg_match
{
$ind_blockname = $regs[0] .'_'. $this->index[ $regs[0] ];
$lastitem = sizeof( $this->content[ $ind_blockname ] );
$lastitem > 1 ? $lastitem-- : $lastitem = 0;
$block = &$this->content[ $ind_blockname ][ $lastitem ];
$varname = $regs[1];
}
else
{
$block = &$this->currentBlock;
}
return $block["_V:$varname"];
}
function printToScreen()
{
if ($this->prepared)
{
$this->__outputContent( TP_ROOTBLOCK .'_0' );
}
else
{
$this->__errorAlert('TemplatePower Error: Template isn\'t prepared!');
}
}
function getOutputContent()
{
ob_start();
$this->printToScreen();
$content = ob_get_contents();
ob_end_clean();
return $content;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -