Merge pull request #794 from norahmollo/master

CODE STYLE Formating gulliver/system/class.templatePower.php
This commit is contained in:
ferOnti
2012-10-17 12:57:11 -07:00
2 changed files with 756 additions and 778 deletions

View File

@@ -1,6 +1,8 @@
<?php <?php
/** /**
* class.htmlArea.php * class.htmlArea.php
*
* @package gulliver.system * @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
@@ -24,9 +26,11 @@
* *
*/ */
/** /**
*
* @package gulliver.system * @package gulliver.system
**/ *
*/
class XmlForm_Field_HTML extends XmlForm_Field_Textarea class XmlForm_Field_HTML extends XmlForm_Field_Textarea
{ {
@@ -51,7 +55,6 @@ class XmlForm_Field_HTML extends XmlForm_Field_Textarea
} }
return $html; return $html;
}*/ }*/
/** /**
* attachEvents function is putting its events * attachEvents function is putting its events
* *
@@ -60,8 +63,10 @@ class XmlForm_Field_HTML extends XmlForm_Field_Textarea
* @return string * @return string
* *
*/ */
function attachEvents($element) { function attachEvents ($element)
$html='var _editor_url = "";editor_generate("form['.$this->name.']");'; {
$html = 'var _editor_url = "";editor_generate("form[' . $this->name . ']");';
return $html; return $html;
} }
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** /**
* class.templatePower.php * class.templatePower.php
*
* @package gulliver.system * @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
@@ -54,17 +55,21 @@
// //
// $Id: Version 3.0.2$ // $Id: Version 3.0.2$
/** /**
*
* @package gulliver.system * @package gulliver.system
*/ *
*/
define("T_BYFILE", 0); define( "T_BYFILE", 0 );
define("T_BYVAR", 1); define( "T_BYVAR", 1 );
define("TP_ROOTBLOCK", '_ROOT'); define( "TP_ROOTBLOCK", '_ROOT' );
/** /**
* class TemplatePowerParser * class TemplatePowerParser
*
* @package gulliver.system * @package gulliver.system
* *
*/ */
@@ -73,8 +78,8 @@ class TemplatePowerParser
var $tpl_base; //Array( [filename/varcontent], [T_BYFILE/T_BYVAR] ) var $tpl_base; //Array( [filename/varcontent], [T_BYFILE/T_BYVAR] )
var $tpl_include; //Array( [filename/varcontent], [T_BYFILE/T_BYVAR] ) var $tpl_include; //Array( [filename/varcontent], [T_BYFILE/T_BYVAR] )
var $tpl_count; var $tpl_count;
var $parent = Array(); // $parent[{blockname}] = {parentblockname} var $parent = Array (); // $parent[{blockname}] = {parentblockname}
var $defBlock = Array(); var $defBlock = Array ();
var $rootBlockName; var $rootBlockName;
var $ignore_stack; var $ignore_stack;
var $version; var $version;
@@ -87,12 +92,14 @@ class TemplatePowerParser
* @param string $type * @param string $type
* @access private * @access private
*/ */
function TemplatePowerParser( $tpl_file, $type ) function TemplatePowerParser ($tpl_file, $type)
{ {
$this->version = '3.0.2'; $this->version = '3.0.2';
$this->tpl_base = Array( $tpl_file, $type ); $this->tpl_base = Array ($tpl_file,$type
);
$this->tpl_count = 0; $this->tpl_count = 0;
$this->ignore_stack = Array( false ); $this->ignore_stack = Array (false
);
} }
/** /**
@@ -102,19 +109,20 @@ class TemplatePowerParser
* *
* @access private * @access private
*/ */
function __errorAlert( $message ) function __errorAlert ($message)
{ {
print( '<br>'. $message .'<br>'."\r\n"); print ('<br>' . $message . '<br>' . "\r\n") ;
} }
/** /**
* TemplatePowerParser::__prepare() * TemplatePowerParser::__prepare()
*
* @access private * @access private
* @return void * @return void
*/ */
function __prepare() function __prepare ()
{ {
$this->defBlock[ TP_ROOTBLOCK ] = Array(); $this->defBlock[TP_ROOTBLOCK] = Array ();
$tplvar = $this->__prepareTemplate( $this->tpl_base[0], $this->tpl_base[1] ); $tplvar = $this->__prepareTemplate( $this->tpl_base[0], $this->tpl_base[1] );
$initdev["varrow"] = 0; $initdev["varrow"] = 0;
$initdev["coderow"] = 0; $initdev["coderow"] = 0;
@@ -131,10 +139,10 @@ class TemplatePowerParser
* *
* @access private * @access private
*/ */
function __cleanUp() function __cleanUp ()
{ {
for( $i=0; $i <= $this->tpl_count; $i++ ){ for ($i = 0; $i <= $this->tpl_count; $i ++) {
$tplvar = 'tpl_rawContent'. $i; $tplvar = 'tpl_rawContent' . $i;
unset( $this->{$tplvar} ); unset( $this->{$tplvar} );
} }
} }
@@ -146,20 +154,18 @@ class TemplatePowerParser
* @param string $type * @param string $type
* @access private * @access private
*/ */
function __prepareTemplate( $tpl_file, $type ) function __prepareTemplate ($tpl_file, $type)
{ {
$tplvar = 'tpl_rawContent'. $this->tpl_count; $tplvar = 'tpl_rawContent' . $this->tpl_count;
if( $type == T_BYVAR ){ if ($type == T_BYVAR) {
$this->{$tplvar}["content"] = preg_split("/\n/", $tpl_file, -1, PREG_SPLIT_DELIM_CAPTURE); $this->{$tplvar}["content"] = preg_split( "/\n/", $tpl_file, - 1, PREG_SPLIT_DELIM_CAPTURE );
} } else {
else{ // Trigger the error in the local scope of the function
// Trigger the error in the local scope of the function // trigger_error ("Some error", E_USER_WARNING);
// trigger_error ("Some error", E_USER_WARNING); $this->{$tplvar}["content"] = @file( $tpl_file ) or die( $this->__errorAlert( 'TemplatePower Error: Couldn\'t open [ ' . $tpl_file . ' ]!' ) );
$this->{$tplvar}["content"] = @file( $tpl_file ) or
die( $this->__errorAlert('TemplatePower Error: Couldn\'t open [ '. $tpl_file .' ]!'));
} }
$this->{$tplvar}["size"] = sizeof( $this->{$tplvar}["content"] ); $this->{$tplvar}["size"] = sizeof( $this->{$tplvar}["content"] );
$this->tpl_count++; $this->tpl_count ++;
return $tplvar; return $tplvar;
} }
@@ -171,44 +177,39 @@ class TemplatePowerParser
* @param string $initdev * @param string $initdev
* @access private * @access private
*/ */
function __parseTemplate( $tplvar, $blockname, $initdev ) function __parseTemplate ($tplvar, $blockname, $initdev)
{ {
$coderow = $initdev["coderow"]; $coderow = $initdev["coderow"];
$varrow = $initdev["varrow"]; $varrow = $initdev["varrow"];
$index = $initdev["index"]; $index = $initdev["index"];
$ignore = $initdev["ignore"]; $ignore = $initdev["ignore"];
while( $index < $this->{$tplvar}["size"] ){ while ($index < $this->{$tplvar}["size"]) {
if ( preg_match('/<!--[ ]?(START|END) IGNORE -->/', $this->{$tplvar}["content"][$index], $ignreg) ){ if (preg_match( '/<!--[ ]?(START|END) IGNORE -->/', $this->{$tplvar}["content"][$index], $ignreg )) {
if( $ignreg[1] == 'START'){ if ($ignreg[1] == 'START') {
//$ignore = true; //$ignore = true;
array_push( $this->ignore_stack, true ); array_push( $this->ignore_stack, true );
} } else {
else{
//$ignore = false; //$ignore = false;
array_pop( $this->ignore_stack ); array_pop( $this->ignore_stack );
} }
} } else {
else{ if (! end( $this->ignore_stack )) {
if( !end( $this->ignore_stack ) ){ if (preg_match( '/<!--[ ]?(START|END|INCLUDE|INCLUDESCRIPT|REUSE) BLOCK : (.+)-->/', $this->{$tplvar}["content"][$index], $regs )) {
if( preg_match('/<!--[ ]?(START|END|INCLUDE|INCLUDESCRIPT|REUSE) BLOCK : (.+)-->/', $this->{$tplvar}["content"][$index], $regs)){
//remove trailing and leading spaces //remove trailing and leading spaces
$regs[2] = trim( $regs[2] ); $regs[2] = trim( $regs[2] );
if( $regs[1] == 'INCLUDE'){ if ($regs[1] == 'INCLUDE') {
$include_defined = true; $include_defined = true;
//check if the include file is assigned //check if the include file is assigned
if( isset( $this->tpl_include[ $regs[2] ]) ){ if (isset( $this->tpl_include[$regs[2]] )) {
$tpl_file = $this->tpl_include[ $regs[2] ][0]; $tpl_file = $this->tpl_include[$regs[2]][0];
$type = $this->tpl_include[ $regs[2] ][1]; $type = $this->tpl_include[$regs[2]][1];
} } else if (file_exists( $regs[2] )) { //check if defined as constant in template
else
if (file_exists( $regs[2] )){ //check if defined as constant in template
$tpl_file = $regs[2]; $tpl_file = $regs[2];
$type = T_BYFILE; $type = T_BYFILE;
} } else {
else{
$include_defined = false; $include_defined = false;
} }
if( $include_defined ){ if ($include_defined) {
//initialize startvalues for recursive call //initialize startvalues for recursive call
$initdev["varrow"] = $varrow; $initdev["varrow"] = $varrow;
$initdev["coderow"] = $coderow; $initdev["coderow"] = $coderow;
@@ -219,78 +220,66 @@ class TemplatePowerParser
$coderow = $initdev["coderow"]; $coderow = $initdev["coderow"];
$varrow = $initdev["varrow"]; $varrow = $initdev["varrow"];
} }
} } else if ($regs[1] == 'INCLUDESCRIPT') {
else
if( $regs[1] == 'INCLUDESCRIPT' ){
$include_defined = true; $include_defined = true;
//check if the includescript file is assigned by the assignInclude function //check if the includescript file is assigned by the assignInclude function
if( isset( $this->tpl_include[ $regs[2] ]) ){ if (isset( $this->tpl_include[$regs[2]] )) {
$include_file = $this->tpl_include[ $regs[2] ][0]; $include_file = $this->tpl_include[$regs[2]][0];
$type = $this->tpl_include[ $regs[2] ][1]; $type = $this->tpl_include[$regs[2]][1];
} } else if (file_exists( $regs[2] )) { //check if defined as constant in template
else
if (file_exists( $regs[2] )){ //check if defined as constant in template
$include_file = $regs[2]; $include_file = $regs[2];
$type = T_BYFILE; $type = T_BYFILE;
} } else {
else{
$include_defined = false; $include_defined = false;
} }
if( $include_defined ){ if ($include_defined) {
ob_start(); ob_start();
if( $type == T_BYFILE ){ if ($type == T_BYFILE) {
if( !@include_once( $include_file ) ){ if (! @include_once ($include_file)) {
$this->__errorAlert( 'TemplatePower Error: Couldn\'t include script [ '. $include_file .' ]!' ); $this->__errorAlert( 'TemplatePower Error: Couldn\'t include script [ ' . $include_file . ' ]!' );
exit(); exit();
} }
} } else {
else{
eval( "?>" . $include_file ); eval( "?>" . $include_file );
} }
$this->defBlock[$blockname]["_C:$coderow"] = ob_get_contents(); $this->defBlock[$blockname]["_C:$coderow"] = ob_get_contents();
$coderow++; $coderow ++;
ob_end_clean(); ob_end_clean();
} }
} } else if ($regs[1] == 'REUSE') {
else
if( $regs[1] == 'REUSE' ){
//do match for 'AS' //do match for 'AS'
if (preg_match('/(.+) AS (.+)/', $regs[2], $reuse_regs)){ if (preg_match( '/(.+) AS (.+)/', $regs[2], $reuse_regs )) {
$originalbname = trim( $reuse_regs[1] ); $originalbname = trim( $reuse_regs[1] );
$copybname = trim( $reuse_regs[2] ); $copybname = trim( $reuse_regs[2] );
//test if original block exist //test if original block exist
if (isset( $this->defBlock[ $originalbname ] )){ if (isset( $this->defBlock[$originalbname] )) {
//copy block //copy block
$this->defBlock[ $copybname ] = $this->defBlock[ $originalbname ]; $this->defBlock[$copybname] = $this->defBlock[$originalbname];
//tell the parent that he has a child block //tell the parent that he has a child block
$this->defBlock[ $blockname ]["_B:". $copybname ] = ''; $this->defBlock[$blockname]["_B:" . $copybname] = '';
//create index and parent info //create index and parent info
$this->index[ $copybname ] = 0; $this->index[$copybname] = 0;
$this->parent[ $copybname ] = $blockname; $this->parent[$copybname] = $blockname;
} else {
$this->__errorAlert( 'TemplatePower Error: Can\'t find block \'' . $originalbname . '\' to REUSE as \'' . $copybname . '\'' );
} }
else{ } else {
$this->__errorAlert('TemplatePower Error: Can\'t find block \''. $originalbname .'\' to REUSE as \''. $copybname .'\'');
}
}
else{
//so it isn't a correct REUSE tag, save as code //so it isn't a correct REUSE tag, save as code
$this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index]; $this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index];
$coderow++; $coderow ++;
} }
} } else {
else{ if ($regs[2] == $blockname) { //is it the end of a block
if( $regs[2] == $blockname ){ //is it the end of a block
break; break;
} } else { //its the start of a block
else{ //its the start of a block
//make a child block and tell the parent that he has a child //make a child block and tell the parent that he has a child
$this->defBlock[ $regs[2] ] = Array(); $this->defBlock[$regs[2]] = Array ();
$this->defBlock[ $blockname ]["_B:". $regs[2]] = ''; $this->defBlock[$blockname]["_B:" . $regs[2]] = '';
//set some vars that we need for the assign functions etc. //set some vars that we need for the assign functions etc.
$this->index[ $regs[2] ] = 0; $this->index[$regs[2]] = 0;
$this->parent[ $regs[2] ] = $blockname; $this->parent[$regs[2]] = $blockname;
//prepare for the recursive call //prepare for the recursive call
$index++; $index ++;
$initdev["varrow"] = 0; $initdev["varrow"] = 0;
$initdev["coderow"] = 0; $initdev["coderow"] = 0;
$initdev["index"] = $index; $initdev["index"] = $index;
@@ -299,59 +288,55 @@ class TemplatePowerParser
$index = $initdev["index"]; $index = $initdev["index"];
} }
} }
} } else { //is it code and/or var(s)
else{ //is it code and/or var(s)
//explode current template line on the curly bracket '{' //explode current template line on the curly bracket '{'
$sstr = explode( '{', $this->{$tplvar}["content"][$index] ); $sstr = explode( '{', $this->{$tplvar}["content"][$index] );
reset( $sstr ); reset( $sstr );
if (current($sstr) != ''){ if (current( $sstr ) != '') {
//the template didn't start with a '{', //the template didn't start with a '{',
//so the first element of the array $sstr is just code //so the first element of the array $sstr is just code
$this->defBlock[$blockname]["_C:$coderow"] = current( $sstr ); $this->defBlock[$blockname]["_C:$coderow"] = current( $sstr );
$coderow++; $coderow ++;
} }
while (next($sstr)){ while (next( $sstr )) {
//find the position of the end curly bracket '}' //find the position of the end curly bracket '}'
$pos = strpos( current($sstr), "}" ); $pos = strpos( current( $sstr ), "}" );
if ( ($pos !== false) && ($pos > 0) ){ if (($pos !== false) && ($pos > 0)) {
//a curly bracket '}' is found //a curly bracket '}' is found
//and at least on position 1, to eliminate '{}' //and at least on position 1, to eliminate '{}'
//note: position 1 taken without '{', because we did explode on '{' //note: position 1 taken without '{', because we did explode on '{'
$strlength = strlen( current($sstr) ); $strlength = strlen( current( $sstr ) );
$varname = substr( current($sstr), 0, $pos ); $varname = substr( current( $sstr ), 0, $pos );
if (strstr( $varname, ' ' )){ if (strstr( $varname, ' ' )) {
//the varname contains one or more spaces //the varname contains one or more spaces
//so, it isn't a variable, save as code //so, it isn't a variable, save as code
$this->defBlock[$blockname]["_C:$coderow"] = '{'. current( $sstr ); $this->defBlock[$blockname]["_C:$coderow"] = '{' . current( $sstr );
$coderow++; $coderow ++;
} } else {
else{
//save the variable //save the variable
$this->defBlock[$blockname]["_V:$varrow" ] = $varname; $this->defBlock[$blockname]["_V:$varrow"] = $varname;
$varrow++; $varrow ++;
//is there some code after the varname left? //is there some code after the varname left?
if( ($pos + 1) != $strlength ){ if (($pos + 1) != $strlength) {
//yes, save that code //yes, save that code
$this->defBlock[$blockname]["_C:$coderow"] = substr( current( $sstr ), ($pos + 1), ($strlength - ($pos + 1)) ); $this->defBlock[$blockname]["_C:$coderow"] = substr( current( $sstr ), ($pos + 1), ($strlength - ($pos + 1)) );
$coderow++; $coderow ++;
} }
} }
} } else {
else{
//no end curly bracket '}' found //no end curly bracket '}' found
//so, the curly bracket is part of the text. Save as code, with the '{' //so, the curly bracket is part of the text. Save as code, with the '{'
$this->defBlock[$blockname]["_C:$coderow"] = '{'. current( $sstr ); $this->defBlock[$blockname]["_C:$coderow"] = '{' . current( $sstr );
$coderow++; $coderow ++;
} }
} }
} }
} } else {
else{
$this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index]; $this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index];
$coderow++; $coderow ++;
} }
} }
$index++; $index ++;
} }
$initdev["varrow"] = $varrow; $initdev["varrow"] = $varrow;
$initdev["coderow"] = $coderow; $initdev["coderow"] = $coderow;
@@ -359,14 +344,13 @@ class TemplatePowerParser
return $initdev; return $initdev;
} }
/** /**
* TemplatePowerParser::version() * TemplatePowerParser::version()
* *
* @return void * @return void
* @access public * @access public
*/ */
function version() function version ()
{ {
return $this->version; return $this->version;
} }
@@ -380,24 +364,26 @@ class TemplatePowerParser
* @return void * @return void
* @access public * @access public
*/ */
function assignInclude( $iblockname, $value, $type=T_BYFILE ) function assignInclude ($iblockname, $value, $type = T_BYFILE)
{ {
$this->tpl_include["$iblockname"] = Array( $value, $type ); $this->tpl_include["$iblockname"] = Array ($value,$type
);
} }
} }
/** /**
* class TemplatePower * class TemplatePower
*
* @package gulliver.system * @package gulliver.system
*/ */
class TemplatePower extends TemplatePowerParser class TemplatePower extends TemplatePowerParser
{ {
var $index = Array(); // $index[{blockname}] = {indexnumber} var $index = Array (); // $index[{blockname}] = {indexnumber}
var $content = Array(); var $content = Array ();
var $currentBlock; var $currentBlock;
var $showUnAssigned; var $showUnAssigned;
var $serialized; var $serialized;
var $globalvars = Array(); var $globalvars = Array ();
var $prepared; var $prepared;
/** /**
@@ -408,7 +394,7 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access public * @access public
*/ */
function TemplatePower( $tpl_file='', $type= T_BYFILE ) function TemplatePower ($tpl_file = '', $type = T_BYFILE)
{ {
TemplatePowerParser::TemplatePowerParser( $tpl_file, $type ); TemplatePowerParser::TemplatePowerParser( $tpl_file, $type );
$this->prepared = false; $this->prepared = false;
@@ -424,16 +410,14 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access private * @access private
*/ */
function __deSerializeTPL( $stpl_file, $type ) function __deSerializeTPL ($stpl_file, $type)
{ {
if( $type == T_BYFILE ){ if ($type == T_BYFILE) {
$serializedTPL = @file( $stpl_file ) or $serializedTPL = @file( $stpl_file ) or die( $this->__errorAlert( 'TemplatePower Error: Can\'t open [ ' . $stpl_file . ' ]!' ) );
die( $this->__errorAlert('TemplatePower Error: Can\'t open [ '. $stpl_file .' ]!')); } else {
}
else{
$serializedTPL = $stpl_file; $serializedTPL = $stpl_file;
} }
$serializedStuff = unserialize( join ('', $serializedTPL) ); $serializedStuff = unserialize( join( '', $serializedTPL ) );
$this->defBlock = $serializedStuff["defBlock"]; $this->defBlock = $serializedStuff["defBlock"];
$this->index = $serializedStuff["index"]; $this->index = $serializedStuff["index"];
$this->parent = $serializedStuff["parent"]; $this->parent = $serializedStuff["parent"];
@@ -445,10 +429,11 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access private * @access private
*/ */
function __makeContentRoot() function __makeContentRoot ()
{ {
$this->content[ TP_ROOTBLOCK ."_0" ][0] = Array( TP_ROOTBLOCK ); $this->content[TP_ROOTBLOCK . "_0"][0] = Array (TP_ROOTBLOCK
$this->currentBlock = &$this->content[ TP_ROOTBLOCK ."_0" ][0]; );
$this->currentBlock = &$this->content[TP_ROOTBLOCK . "_0"][0];
} }
/** /**
@@ -460,16 +445,15 @@ class TemplatePower extends TemplatePowerParser
* *
* @access private * @access private
*/ */
function __assign( $varname, $value) function __assign ($varname, $value)
{ {
if( sizeof( $regs = explode('.', $varname ) ) == 2 ){ //this is faster then preg_match if (sizeof( $regs = explode( '.', $varname ) ) == 2) { //this is faster then preg_match
$ind_blockname = $regs[0] .'_'. $this->index[ $regs[0] ]; $ind_blockname = $regs[0] . '_' . $this->index[$regs[0]];
$lastitem = sizeof( $this->content[ $ind_blockname ] ); $lastitem = sizeof( $this->content[$ind_blockname] );
$lastitem > 1 ? $lastitem-- : $lastitem = 0; $lastitem > 1 ? $lastitem -- : $lastitem = 0;
$block = &$this->content[ $ind_blockname ][ $lastitem ]; $block = &$this->content[$ind_blockname][$lastitem];
$varname = $regs[1]; $varname = $regs[1];
} } else {
else{
$block = &$this->currentBlock; $block = &$this->currentBlock;
} }
$block["_V:$varname"] = $value; $block["_V:$varname"] = $value;
@@ -483,12 +467,11 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access private * @access private
*/ */
function __assignGlobal( $varname, $value ) function __assignGlobal ($varname, $value)
{ {
$this->globalvars[ $varname ] = $value; $this->globalvars[$varname] = $value;
} }
/** /**
* TemplatePower::__outputContent() * TemplatePower::__outputContent()
* *
@@ -496,52 +479,44 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access private * @access private
*/ */
function __outputContent( $blockname ) function __outputContent ($blockname)
{ {
$numrows = sizeof( $this->content[ $blockname ] ); $numrows = sizeof( $this->content[$blockname] );
for( $i=0; $i < $numrows; $i++){ for ($i = 0; $i < $numrows; $i ++) {
$defblockname = $this->content[ $blockname ][$i][0]; $defblockname = $this->content[$blockname][$i][0];
for( reset( $this->defBlock[ $defblockname ]); $k = key( $this->defBlock[ $defblockname ]); next( $this->defBlock[ $defblockname ] ) ){ for (reset( $this->defBlock[$defblockname] ); $k = key( $this->defBlock[$defblockname] ); next( $this->defBlock[$defblockname] )) {
if ($k[1] == 'C'){ if ($k[1] == 'C') {
print( $this->defBlock[ $defblockname ][$k] ); print ($this->defBlock[$defblockname][$k]) ;
} } else if ($k[1] == 'V') {
else $defValue = $this->defBlock[$defblockname][$k];
if ($k[1] == 'V'){ if (! isset( $this->content[$blockname][$i]["_V:" . $defValue] )) {
$defValue = $this->defBlock[ $defblockname ][$k]; if (isset( $this->globalvars[$defValue] )) {
if( !isset( $this->content[ $blockname ][$i][ "_V:". $defValue ] ) ){ $value = $this->globalvars[$defValue];
if( isset( $this->globalvars[ $defValue ] ) ){ } else {
$value = $this->globalvars[ $defValue ];
}
else{
//Verify if $defValue is like //Verify if $defValue is like
// "xmlfile:ID_LABEL" // "xmlfile:ID_LABEL"
//if it is load an xml label. //if it is load an xml label.
//if not continues with non assigned value. //if not continues with non assigned value.
if (preg_match("/(.+):(.+)/",$defValue,$xmlreg)){ if (preg_match( "/(.+):(.+)/", $defValue, $xmlreg )) {
$value=G::LoadTranslation(/*$xmlreg[1],*/$xmlreg[2]); $value = G::LoadTranslation(/*$xmlreg[1],*/$xmlreg[2] );
} } else {
else { if ($this->showUnAssigned) {
if( $this->showUnAssigned ){
//$value = '{'. $this->defBlock[ $defblockname ][$k] .'}'; //$value = '{'. $this->defBlock[ $defblockname ][$k] .'}';
$value = '{'. $defValue .'}'; $value = '{' . $defValue . '}';
} } else {
else{
$value = ''; $value = '';
} }
} }
} }
} } else {
else{ $value = $this->content[$blockname][$i]["_V:" . $defValue];
$value = $this->content[ $blockname ][$i][ "_V:". $defValue ];
} }
if ($this->unhtmlentities) if ($this->unhtmlentities)
$value = G::unhtmlentities($value); $value = G::unhtmlentities( $value );
print( $value ); print ($value) ;
} } else if ($k[1] == 'B') {
else if (isset( $this->content[$blockname][$i][$k] )) {
if ($k[1] == 'B'){ $this->__outputContent( $this->content[$blockname][$i][$k] );
if( isset( $this->content[ $blockname ][$i][$k] ) ){
$this->__outputContent( $this->content[ $blockname ][$i][$k] );
} }
} }
} }
@@ -554,17 +529,18 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access public * @access public
*/ */
function __printVars() function __printVars ()
{ {
var_dump($this->defBlock); var_dump( $this->defBlock );
print("<br>--------------------<br>"); print ("<br>--------------------<br>") ;
var_dump($this->content); var_dump( $this->content );
} }
/**
/********** * ********
public members * public members
***********/ * *********
*/
/** /**
* TemplatePower::serializedBase() * TemplatePower::serializedBase()
@@ -573,7 +549,7 @@ class TemplatePower extends TemplatePowerParser
* *
* @access public * @access public
*/ */
function serializedBase() function serializedBase ()
{ {
$this->serialized = true; $this->serialized = true;
$this->__deSerializeTPL( $this->tpl_base[0], $this->tpl_base[1] ); $this->__deSerializeTPL( $this->tpl_base[0], $this->tpl_base[1] );
@@ -586,7 +562,7 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access public * @access public
*/ */
function showUnAssigned( $state = true ) function showUnAssigned ($state = true)
{ {
$this->showUnAssigned = $state; $this->showUnAssigned = $state;
} }
@@ -597,13 +573,13 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access public * @access public
*/ */
function prepare() function prepare ()
{ {
if (!$this->serialized){ if (! $this->serialized) {
TemplatePowerParser::__prepare(); TemplatePowerParser::__prepare();
} }
$this->prepared = true; $this->prepared = true;
$this->index[ TP_ROOTBLOCK ] = 0; $this->index[TP_ROOTBLOCK] = 0;
$this->__makeContentRoot(); $this->__makeContentRoot();
} }
@@ -614,28 +590,29 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access public * @access public
*/ */
function newBlock( $blockname ) function newBlock ($blockname)
{ {
$parent = &$this->content[ $this->parent[$blockname] .'_'. $this->index[$this->parent[$blockname]] ]; $parent = &$this->content[$this->parent[$blockname] . '_' . $this->index[$this->parent[$blockname]]];
$lastitem = sizeof( $parent ); $lastitem = sizeof( $parent );
$lastitem > 1 ? $lastitem-- : $lastitem = 0; $lastitem > 1 ? $lastitem -- : $lastitem = 0;
$ind_blockname = $blockname .'_'. $this->index[ $blockname ]; $ind_blockname = $blockname . '_' . $this->index[$blockname];
if ( !isset( $parent[ $lastitem ]["_B:$blockname"] )){ if (! isset( $parent[$lastitem]["_B:$blockname"] )) {
//ok, there is no block found in the parentblock with the name of {$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 //so, increase the index counter and create a new {$blockname} block
$this->index[ $blockname ] += 1; $this->index[$blockname] += 1;
$ind_blockname = $blockname .'_'. $this->index[ $blockname ]; $ind_blockname = $blockname . '_' . $this->index[$blockname];
if (!isset( $this->content[ $ind_blockname ] ) ){ if (! isset( $this->content[$ind_blockname] )) {
$this->content[ $ind_blockname ] = Array(); $this->content[$ind_blockname] = Array ();
} }
//tell the parent where his (possible) children are located //tell the parent where his (possible) children are located
$parent[ $lastitem ]["_B:$blockname"] = $ind_blockname; $parent[$lastitem]["_B:$blockname"] = $ind_blockname;
} }
//now, make a copy of the block defenition //now, make a copy of the block defenition
$blocksize = sizeof( $this->content[ $ind_blockname ] ); $blocksize = sizeof( $this->content[$ind_blockname] );
$this->content[ $ind_blockname ][ $blocksize ] = Array( $blockname ); $this->content[$ind_blockname][$blocksize] = Array ($blockname
);
//link the current block to the block we just created //link the current block to the block we just created
$this->currentBlock = &$this->content[ $ind_blockname ][ $blocksize ]; $this->currentBlock = &$this->content[$ind_blockname][$blocksize];
} }
/** /**
@@ -647,14 +624,13 @@ class TemplatePower extends TemplatePowerParser
* *
* @access public * @access public
*/ */
function assignGlobal( $varname, $value='' ) function assignGlobal ($varname, $value = '')
{ {
if (is_array( $varname )){ if (is_array( $varname )) {
foreach($varname as $var => $value){ foreach ($varname as $var => $value) {
$this->__assignGlobal( $var, $value ); $this->__assignGlobal( $var, $value );
} }
} } else {
else{
$this->__assignGlobal( $varname, $value ); $this->__assignGlobal( $varname, $value );
} }
} }
@@ -667,14 +643,13 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access public * @access public
*/ */
function assign( $varname, $value='' ) function assign ($varname, $value = '')
{ {
if (is_array( $varname )){ if (is_array( $varname )) {
foreach($varname as $var => $value){ foreach ($varname as $var => $value) {
$this->__assign( $var, $value ); $this->__assign( $var, $value );
} }
} } else {
else{
$this->__assign( $varname, $value ); $this->__assign( $varname, $value );
} }
} }
@@ -686,15 +661,15 @@ class TemplatePower extends TemplatePowerParser
* @param string $blockname * @param string $blockname
* @access public * @access public
*/ */
function gotoBlock( $blockname ) function gotoBlock ($blockname)
{ {
if ( isset( $this->defBlock[ $blockname ] ) ){ if (isset( $this->defBlock[$blockname] )) {
$ind_blockname = $blockname .'_'. $this->index[ $blockname ]; $ind_blockname = $blockname . '_' . $this->index[$blockname];
//get lastitem indexnumber //get lastitem indexnumber
$lastitem = sizeof( $this->content[ $ind_blockname ] ); $lastitem = sizeof( $this->content[$ind_blockname] );
$lastitem > 1 ? $lastitem-- : $lastitem = 0; $lastitem > 1 ? $lastitem -- : $lastitem = 0;
//link the current block //link the current block
$this->currentBlock = &$this->content[ $ind_blockname ][ $lastitem ]; $this->currentBlock = &$this->content[$ind_blockname][$lastitem];
} }
} }
@@ -705,16 +680,15 @@ class TemplatePower extends TemplatePowerParser
* @param string $varname * @param string $varname
* @access public * @access public
*/ */
function getVarValue( $varname ) function getVarValue ($varname)
{ {
if( sizeof( $regs = explode('.', $varname ) ) == 2 ){ //this is faster then preg_match{ if (sizeof( $regs = explode( '.', $varname ) ) == 2) { //this is faster then preg_match{
$ind_blockname = $regs[0] .'_'. $this->index[ $regs[0] ]; $ind_blockname = $regs[0] . '_' . $this->index[$regs[0]];
$lastitem = sizeof( $this->content[ $ind_blockname ] ); $lastitem = sizeof( $this->content[$ind_blockname] );
$lastitem > 1 ? $lastitem-- : $lastitem = 0; $lastitem > 1 ? $lastitem -- : $lastitem = 0;
$block = &$this->content[ $ind_blockname ][ $lastitem ]; $block = &$this->content[$ind_blockname][$lastitem];
$varname = $regs[1]; $varname = $regs[1];
} } else {
else{
$block = &$this->currentBlock; $block = &$this->currentBlock;
} }
return $block["_V:$varname"]; return $block["_V:$varname"];
@@ -726,13 +700,12 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access public * @access public
*/ */
function printToScreen() function printToScreen ()
{ {
if ($this->prepared){ if ($this->prepared) {
$this->__outputContent( TP_ROOTBLOCK .'_0' ); $this->__outputContent( TP_ROOTBLOCK . '_0' );
} } else {
else{ $this->__errorAlert( 'TemplatePower Error: Template isn\'t prepared!' );
$this->__errorAlert('TemplatePower Error: Template isn\'t prepared!');
} }
} }
@@ -742,7 +715,7 @@ class TemplatePower extends TemplatePowerParser
* @return void * @return void
* @access public * @access public
*/ */
function getOutputContent() function getOutputContent ()
{ {
ob_start(); ob_start();
$this->printToScreen(); $this->printToScreen();