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
@@ -25,8 +27,10 @@
*/ */
/** /**
*
* @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,8 +55,11 @@
// //
// $Id: Version 3.0.2$ // $Id: Version 3.0.2$
/** /**
*
* @package gulliver.system * @package gulliver.system
*
*/ */
define( "T_BYFILE", 0 ); define( "T_BYFILE", 0 );
@@ -65,6 +69,7 @@ define("TP_ROOTBLOCK", '_ROOT');
/** /**
* class TemplatePowerParser * class TemplatePowerParser
*
* @package gulliver.system * @package gulliver.system
* *
*/ */
@@ -90,9 +95,11 @@ class TemplatePowerParser
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
);
} }
/** /**
@@ -109,6 +116,7 @@ class TemplatePowerParser
/** /**
* TemplatePowerParser::__prepare() * TemplatePowerParser::__prepare()
*
* @access private * @access private
* @return void * @return void
*/ */
@@ -151,12 +159,10 @@ class TemplatePowerParser
$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 $this->{$tplvar}["content"] = @file( $tpl_file ) or die( $this->__errorAlert( 'TemplatePower Error: Couldn\'t open [ ' . $tpl_file . ' ]!' ) );
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 ++;
@@ -182,13 +188,11 @@ class TemplatePowerParser
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
@@ -199,13 +203,10 @@ class TemplatePowerParser
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) {
@@ -219,21 +220,16 @@ 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) {
@@ -243,17 +239,14 @@ class TemplatePowerParser
$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] );
@@ -267,22 +260,18 @@ class TemplatePowerParser
//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 {
else{
$this->__errorAlert( 'TemplatePower Error: Can\'t find block \'' . $originalbname . '\' to REUSE as \'' . $copybname . '\'' ); $this->__errorAlert( 'TemplatePower Error: Can\'t find block \'' . $originalbname . '\' to REUSE as \'' . $copybname . '\'' );
} }
} } else {
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]] = '';
@@ -299,8 +288,7 @@ 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 );
@@ -324,8 +312,7 @@ class TemplatePowerParser
//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 ++;
@@ -336,8 +323,7 @@ class TemplatePowerParser
$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 );
@@ -345,8 +331,7 @@ class TemplatePowerParser
} }
} }
} }
} } else {
else{
$this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index]; $this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index];
$coderow ++; $coderow ++;
} }
@@ -359,7 +344,6 @@ class TemplatePowerParser
return $initdev; return $initdev;
} }
/** /**
* TemplatePowerParser::version() * TemplatePowerParser::version()
* *
@@ -382,12 +366,14 @@ class TemplatePowerParser
*/ */
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
@@ -427,10 +413,8 @@ class TemplatePower extends TemplatePowerParser
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 ) );
@@ -447,7 +431,8 @@ class TemplatePower extends TemplatePowerParser
*/ */
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];
} }
@@ -468,8 +453,7 @@ class TemplatePower extends TemplatePowerParser
$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;
@@ -488,7 +472,6 @@ class TemplatePower extends TemplatePowerParser
$this->globalvars[$varname] = $value; $this->globalvars[$varname] = $value;
} }
/** /**
* TemplatePower::__outputContent() * TemplatePower::__outputContent()
* *
@@ -504,42 +487,34 @@ class TemplatePower extends TemplatePowerParser
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
if ($k[1] == 'V'){
$defValue = $this->defBlock[$defblockname][$k]; $defValue = $this->defBlock[$defblockname][$k];
if (! isset( $this->content[$blockname][$i]["_V:" . $defValue] )) { if (! isset( $this->content[$blockname][$i]["_V:" . $defValue] )) {
if (isset( $this->globalvars[$defValue] )) { if (isset( $this->globalvars[$defValue] )) {
$value = $this->globalvars[$defValue]; $value = $this->globalvars[$defValue];
} } else {
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 ($k[1] == 'B'){
if (isset( $this->content[$blockname][$i][$k] )) { if (isset( $this->content[$blockname][$i][$k] )) {
$this->__outputContent( $this->content[$blockname][$i][$k] ); $this->__outputContent( $this->content[$blockname][$i][$k] );
} }
@@ -561,10 +536,11 @@ class TemplatePower extends TemplatePowerParser
var_dump( $this->content ); var_dump( $this->content );
} }
/**
/********** * ********
public members * public members
***********/ * *********
*/
/** /**
* TemplatePower::serializedBase() * TemplatePower::serializedBase()
@@ -633,7 +609,8 @@ class TemplatePower extends TemplatePowerParser
} }
//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];
} }
@@ -653,8 +630,7 @@ class TemplatePower extends TemplatePowerParser
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 );
} }
} }
@@ -673,8 +649,7 @@ class TemplatePower extends TemplatePowerParser
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 );
} }
} }
@@ -713,8 +688,7 @@ class TemplatePower extends TemplatePowerParser
$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"];
@@ -730,8 +704,7 @@ class TemplatePower extends TemplatePowerParser
{ {
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!' );
} }
} }