2012-10-17 19:42:03 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* class.templatePower.php
|
|
|
|
|
*
|
|
|
|
|
* @package gulliver.system
|
|
|
|
|
*
|
|
|
|
|
* ProcessMaker Open Source Edition
|
|
|
|
|
* Copyright (C) 2004 - 2011 Colosa Inc.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
|
|
|
|
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
2019-08-12 09:58:19 -04:00
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
|
// | TemplatePower: |
|
|
|
|
|
// | offers you the ability to separate your PHP code and your HTML |
|
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
|
// | |
|
|
|
|
|
// | Copyright (C) 2001,2002 R.P.J. Velzeboer, The Netherlands |
|
|
|
|
|
// | |
|
|
|
|
|
// | This program is free software; you can redistribute it and/or |
|
|
|
|
|
// | modify it under the terms of the GNU General Public License |
|
|
|
|
|
// | as published by the Free Software Foundation; either version 2 |
|
|
|
|
|
// | of the License, or (at your option) any later version. |
|
|
|
|
|
// | |
|
|
|
|
|
// | This program is distributed in the hope that it will be useful, |
|
|
|
|
|
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
|
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
|
// | GNU General Public License for more details. |
|
|
|
|
|
// | |
|
|
|
|
|
// | You should have received a copy of the GNU General Public License |
|
|
|
|
|
// | along with this program; if not, write to the Free Software |
|
|
|
|
|
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|
|
|
|
|
// | 02111-1307, USA. |
|
|
|
|
|
// | |
|
|
|
|
|
// | Author: R.P.J. Velzeboer, rovel@codocad.nl The Netherlands |
|
|
|
|
|
// | |
|
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
|
// | http://templatepower.codocad.com |
|
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
|
//
|
|
|
|
|
// $Id: Version 3.0.2$
|
2012-10-17 19:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @package gulliver.system
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-12 09:58:19 -04:00
|
|
|
define("T_BYFILE", 0);
|
|
|
|
|
define("T_BYVAR", 1);
|
2012-10-17 19:42:03 +00:00
|
|
|
|
2019-08-12 09:58:19 -04:00
|
|
|
define("TP_ROOTBLOCK", '_ROOT');
|
2012-10-17 19:42:03 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* class TemplatePowerParser
|
|
|
|
|
*
|
|
|
|
|
* @package gulliver.system
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class TemplatePowerParser
|
|
|
|
|
{
|
2012-10-23 21:14:04 +00:00
|
|
|
public $tpl_base;
|
2019-08-12 09:58:19 -04:00
|
|
|
//Array( [filename/varcontent], [T_BYFILE/T_BYVAR] )
|
2012-10-23 21:14:04 +00:00
|
|
|
public $tpl_include;
|
2019-08-12 09:58:19 -04:00
|
|
|
//Array( [filename/varcontent], [T_BYFILE/T_BYVAR] )
|
2012-10-23 21:14:04 +00:00
|
|
|
public $tpl_count;
|
2019-08-12 09:58:19 -04:00
|
|
|
public $parent = [];
|
|
|
|
|
// $parent[{blockname}] = {parentblockname}
|
|
|
|
|
public $defBlock = [];
|
2012-10-23 21:14:04 +00:00
|
|
|
public $rootBlockName;
|
|
|
|
|
public $ignore_stack;
|
|
|
|
|
public $version;
|
|
|
|
|
public $unhtmlentities = 0;
|
2012-10-17 19:42:03 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePowerParser::TemplatePowerParser()
|
|
|
|
|
*
|
|
|
|
|
* @param string $tpl_file
|
|
|
|
|
* @param string $type
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function __construct($tpl_file, $type)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
|
|
|
|
$this->version = '3.0.2';
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->tpl_base = [$tpl_file, $type];
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->tpl_count = 0;
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->ignore_stack = [false];
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* TemplatePowerParser::errorAlert()
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @param string $message
|
|
|
|
|
*
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function errorAlert($message)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
print ('<br>' . $message . '<br>' . "\r\n");
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* TemplatePowerParser::prepare()
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @access private
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function prepare()
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->defBlock[TP_ROOTBLOCK] = [];
|
|
|
|
|
$tplvar = $this->prepareTemplate($this->tpl_base[0], $this->tpl_base[1]);
|
2012-10-17 19:42:03 +00:00
|
|
|
$initdev["varrow"] = 0;
|
|
|
|
|
$initdev["coderow"] = 0;
|
|
|
|
|
$initdev["index"] = 0;
|
|
|
|
|
$initdev["ignore"] = false;
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->parseTemplate($tplvar, TP_ROOTBLOCK, $initdev);
|
|
|
|
|
$this->cleanUp();
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* TemplatePowerParser::cleanUp()
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function cleanUp()
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
for ($i = 0; $i <= $this->tpl_count; $i++) {
|
2012-10-17 19:42:03 +00:00
|
|
|
$tplvar = 'tpl_rawContent' . $i;
|
2019-08-12 09:58:19 -04:00
|
|
|
unset($this->{$tplvar});
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* TemplatePowerParser::prepareTemplate()
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @param string $tpl_file
|
|
|
|
|
* @param string $type
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function prepareTemplate($tpl_file, $type)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
|
|
|
|
$tplvar = 'tpl_rawContent' . $this->tpl_count;
|
|
|
|
|
if ($type == T_BYVAR) {
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->{$tplvar}["content"] = preg_split("/\r\n/", $tpl_file, -1, PREG_SPLIT_DELIM_CAPTURE);
|
2012-10-17 19:42:03 +00:00
|
|
|
} else {
|
2012-10-23 21:14:04 +00:00
|
|
|
//Trigger the error in the local scope of the function
|
|
|
|
|
//trigger_error ("Some error", E_USER_WARNING);
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->{$tplvar}["content"] = @file($tpl_file) or die($this->errorAlert('TemplatePower Error: Couldn\'t open [ ' . $tpl_file . ' ]!'));
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->{$tplvar}["size"] = sizeof($this->{$tplvar}["content"]);
|
|
|
|
|
$this->tpl_count++;
|
2012-10-17 19:42:03 +00:00
|
|
|
return $tplvar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* TemplatePowerParser::parseTemplate()
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @param string $tplvar
|
|
|
|
|
* @param string $blockname
|
|
|
|
|
* @param string $initdev
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function parseTemplate($tplvar, $blockname, $initdev)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
|
|
|
|
$coderow = $initdev["coderow"];
|
|
|
|
|
$varrow = $initdev["varrow"];
|
|
|
|
|
$index = $initdev["index"];
|
|
|
|
|
$ignore = $initdev["ignore"];
|
|
|
|
|
while ($index < $this->{$tplvar}["size"]) {
|
2019-08-12 09:58:19 -04:00
|
|
|
if (preg_match('/<!--[ ]?(START|END) IGNORE -->/', $this->{$tplvar}["content"][$index], $ignreg)) {
|
2012-10-17 19:42:03 +00:00
|
|
|
if ($ignreg[1] == 'START') {
|
2019-08-12 09:58:19 -04:00
|
|
|
//$ignore = true;
|
|
|
|
|
array_push($this->ignore_stack, true);
|
2012-10-17 19:42:03 +00:00
|
|
|
} else {
|
2019-08-12 09:58:19 -04:00
|
|
|
//$ignore = false;
|
|
|
|
|
array_pop($this->ignore_stack);
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2019-08-12 09:58:19 -04:00
|
|
|
if (!end($this->ignore_stack)) {
|
|
|
|
|
if (preg_match('/<!--[ ]?(START|END|INCLUDE|INCLUDESCRIPT|REUSE) BLOCK : (.+)-->/',
|
|
|
|
|
$this->{$tplvar}["content"][$index], $regs)) {
|
|
|
|
|
//remove trailing and leading spaces
|
|
|
|
|
$regs[2] = trim($regs[2]);
|
2012-10-17 19:42:03 +00:00
|
|
|
if ($regs[1] == 'INCLUDE') {
|
|
|
|
|
$include_defined = true;
|
2012-10-23 21:14:04 +00:00
|
|
|
//check if the include file is assigned
|
2019-08-12 09:58:19 -04:00
|
|
|
if (isset($this->tpl_include[$regs[2]])) {
|
2012-10-17 19:42:03 +00:00
|
|
|
$tpl_file = $this->tpl_include[$regs[2]][0];
|
|
|
|
|
$type = $this->tpl_include[$regs[2]][1];
|
2019-08-12 09:58:19 -04:00
|
|
|
} elseif (file_exists($regs[2])) {
|
2012-10-23 21:14:04 +00:00
|
|
|
//check if defined as constant in template
|
2012-10-17 19:42:03 +00:00
|
|
|
$tpl_file = $regs[2];
|
|
|
|
|
$type = T_BYFILE;
|
|
|
|
|
} else {
|
|
|
|
|
$include_defined = false;
|
|
|
|
|
}
|
2012-10-23 21:14:04 +00:00
|
|
|
|
2012-10-17 19:42:03 +00:00
|
|
|
if ($include_defined) {
|
2019-08-12 09:58:19 -04:00
|
|
|
//initialize startvalues for recursive call
|
2012-10-17 19:42:03 +00:00
|
|
|
$initdev["varrow"] = $varrow;
|
|
|
|
|
$initdev["coderow"] = $coderow;
|
|
|
|
|
$initdev["index"] = 0;
|
|
|
|
|
$initdev["ignore"] = false;
|
2019-08-12 09:58:19 -04:00
|
|
|
$tplvar2 = $this->prepareTemplate($tpl_file, $type);
|
|
|
|
|
$initdev = $this->parseTemplate($tplvar2, $blockname, $initdev);
|
2012-10-17 19:42:03 +00:00
|
|
|
$coderow = $initdev["coderow"];
|
|
|
|
|
$varrow = $initdev["varrow"];
|
|
|
|
|
}
|
2012-10-23 21:14:04 +00:00
|
|
|
} elseif ($regs[1] == 'INCLUDESCRIPT') {
|
2012-10-17 19:42:03 +00:00
|
|
|
$include_defined = true;
|
2019-08-12 09:58:19 -04:00
|
|
|
//check if the includescript file is assigned by the assignInclude function
|
|
|
|
|
if (isset($this->tpl_include[$regs[2]])) {
|
2012-10-17 19:42:03 +00:00
|
|
|
$include_file = $this->tpl_include[$regs[2]][0];
|
|
|
|
|
$type = $this->tpl_include[$regs[2]][1];
|
2019-08-12 09:58:19 -04:00
|
|
|
} elseif (file_exists($regs[2])) {
|
|
|
|
|
//check if defined as constant in template
|
2012-10-17 19:42:03 +00:00
|
|
|
$include_file = $regs[2];
|
|
|
|
|
$type = T_BYFILE;
|
|
|
|
|
} else {
|
|
|
|
|
$include_defined = false;
|
|
|
|
|
}
|
|
|
|
|
if ($include_defined) {
|
|
|
|
|
ob_start();
|
|
|
|
|
if ($type == T_BYFILE) {
|
2019-08-12 09:58:19 -04:00
|
|
|
if (!@include_once($include_file)) {
|
|
|
|
|
$this->errorAlert('TemplatePower Error: Couldn\'t include script [ ' . $include_file . ' ]!');
|
2012-10-17 19:42:03 +00:00
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-08-12 09:58:19 -04:00
|
|
|
eval("?>" . $include_file);
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
$this->defBlock[$blockname]["_C:$coderow"] = ob_get_contents();
|
2019-08-12 09:58:19 -04:00
|
|
|
$coderow++;
|
2012-10-17 19:42:03 +00:00
|
|
|
ob_end_clean();
|
|
|
|
|
}
|
2012-10-23 21:14:04 +00:00
|
|
|
} elseif ($regs[1] == 'REUSE') {
|
2019-08-12 09:58:19 -04:00
|
|
|
//do match for 'AS'
|
|
|
|
|
if (preg_match('/(.+) AS (.+)/', $regs[2], $reuse_regs)) {
|
|
|
|
|
$originalbname = trim($reuse_regs[1]);
|
|
|
|
|
$copybname = trim($reuse_regs[2]);
|
|
|
|
|
//test if original block exist
|
|
|
|
|
if (isset($this->defBlock[$originalbname])) {
|
|
|
|
|
//copy block
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->defBlock[$copybname] = $this->defBlock[$originalbname];
|
2019-08-12 09:58:19 -04:00
|
|
|
//tell the parent that he has a child block
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->defBlock[$blockname]["_B:" . $copybname] = '';
|
2019-08-12 09:58:19 -04:00
|
|
|
//create index and parent info
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->index[$copybname] = 0;
|
|
|
|
|
$this->parent[$copybname] = $blockname;
|
|
|
|
|
} else {
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->errorAlert('TemplatePower Error: Can\'t find block \'' . $originalbname . '\' to REUSE as \'' . $copybname . '\'');
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2019-08-12 09:58:19 -04:00
|
|
|
//so it isn't a correct REUSE tag, save as code
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index];
|
2019-08-12 09:58:19 -04:00
|
|
|
$coderow++;
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2012-10-23 21:14:04 +00:00
|
|
|
if ($regs[2] == $blockname) {
|
2019-08-12 09:58:19 -04:00
|
|
|
//is it the end of a block
|
2012-10-17 19:42:03 +00:00
|
|
|
break;
|
2012-10-23 21:14:04 +00:00
|
|
|
} else {
|
2019-08-12 09:58:19 -04:00
|
|
|
//its the start of a block
|
|
|
|
|
//make a child block and tell the parent that he has a child
|
|
|
|
|
$this->defBlock[$regs[2]] = [];
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->defBlock[$blockname]["_B:" . $regs[2]] = '';
|
2019-08-12 09:58:19 -04:00
|
|
|
//set some vars that we need for the assign functions etc.
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->index[$regs[2]] = 0;
|
|
|
|
|
$this->parent[$regs[2]] = $blockname;
|
2019-08-12 09:58:19 -04:00
|
|
|
//prepare for the recursive call
|
|
|
|
|
$index++;
|
2012-10-17 19:42:03 +00:00
|
|
|
$initdev["varrow"] = 0;
|
|
|
|
|
$initdev["coderow"] = 0;
|
|
|
|
|
$initdev["index"] = $index;
|
|
|
|
|
$initdev["ignore"] = false;
|
2019-08-12 09:58:19 -04:00
|
|
|
$initdev = $this->parseTemplate($tplvar, $regs[2], $initdev);
|
2012-10-17 19:42:03 +00:00
|
|
|
$index = $initdev["index"];
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-23 21:14:04 +00:00
|
|
|
} else {
|
|
|
|
|
//is it code and/or var(s)
|
|
|
|
|
//explode current template line on the curly bracket '{'
|
2019-08-12 09:58:19 -04:00
|
|
|
$sstr = explode('{', $this->{$tplvar}["content"][$index]);
|
|
|
|
|
reset($sstr);
|
|
|
|
|
if (current($sstr) != '') {
|
2012-10-23 21:14:04 +00:00
|
|
|
//the template didn't start with a '{',
|
|
|
|
|
//so the first element of the array $sstr is just code
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->defBlock[$blockname]["_C:$coderow"] = current($sstr);
|
|
|
|
|
$coderow++;
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
2019-08-12 09:58:19 -04:00
|
|
|
while (next($sstr)) {
|
2012-10-23 21:14:04 +00:00
|
|
|
//find the position of the end curly bracket '}'
|
2019-08-12 09:58:19 -04:00
|
|
|
$pos = strpos(current($sstr), "}");
|
2012-10-17 19:42:03 +00:00
|
|
|
if (($pos !== false) && ($pos > 0)) {
|
2012-10-23 21:14:04 +00:00
|
|
|
//a curly bracket '}' is found
|
|
|
|
|
//and at least on position 1, to eliminate '{}'
|
|
|
|
|
//note: position 1 taken without '{', because we did explode on '{'
|
2019-08-12 09:58:19 -04:00
|
|
|
$strlength = strlen(current($sstr));
|
|
|
|
|
$varname = substr(current($sstr), 0, $pos);
|
|
|
|
|
if (strstr($varname, ' ')) {
|
2012-10-23 21:14:04 +00:00
|
|
|
//the varname contains one or more spaces
|
|
|
|
|
//so, it isn't a variable, save as code
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->defBlock[$blockname]["_C:$coderow"] = '{' . current($sstr);
|
|
|
|
|
$coderow++;
|
2012-10-17 19:42:03 +00:00
|
|
|
} else {
|
2012-10-23 21:14:04 +00:00
|
|
|
//save the variable
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->defBlock[$blockname]["_V:$varrow"] = $varname;
|
2019-08-12 09:58:19 -04:00
|
|
|
$varrow++;
|
2012-10-23 21:14:04 +00:00
|
|
|
//is there some code after the varname left?
|
2012-10-17 19:42:03 +00:00
|
|
|
if (($pos + 1) != $strlength) {
|
2012-10-23 21:14:04 +00:00
|
|
|
//yes, save that code
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->defBlock[$blockname]["_C:$coderow"] = substr(current($sstr), ($pos + 1),
|
|
|
|
|
($strlength - ($pos + 1)));
|
|
|
|
|
$coderow++;
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-08-12 09:58:19 -04:00
|
|
|
//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++;
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index];
|
2019-08-12 09:58:19 -04:00
|
|
|
$coderow++;
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-08-12 09:58:19 -04:00
|
|
|
$index++;
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
$initdev["varrow"] = $varrow;
|
|
|
|
|
$initdev["coderow"] = $coderow;
|
|
|
|
|
$initdev["index"] = $index;
|
|
|
|
|
return $initdev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePowerParser::version()
|
|
|
|
|
*
|
2019-08-12 09:58:19 -04:00
|
|
|
* @return string
|
2012-10-17 19:42:03 +00:00
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function version()
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
|
|
|
|
return $this->version;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePowerParser::assignInclude()
|
|
|
|
|
*
|
|
|
|
|
* @param string $iblockname
|
|
|
|
|
* @param string $value
|
|
|
|
|
* @param string $type
|
|
|
|
|
* @return void
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function assignInclude($iblockname, $value, $type = T_BYFILE)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->tpl_include["$iblockname"] = [$value, $type];
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* class TemplatePower
|
|
|
|
|
*
|
|
|
|
|
* @package gulliver.system
|
|
|
|
|
*/
|
|
|
|
|
class TemplatePower extends TemplatePowerParser
|
|
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
public $index = [];
|
2012-10-23 21:14:04 +00:00
|
|
|
// $index[{blockname}] = {indexnumber}
|
2019-08-12 09:58:19 -04:00
|
|
|
public $content = [];
|
2012-10-23 21:14:04 +00:00
|
|
|
public $currentBlock;
|
|
|
|
|
public $showUnAssigned;
|
|
|
|
|
public $serialized;
|
2019-08-12 09:58:19 -04:00
|
|
|
public $globalvars = [];
|
2012-10-23 21:14:04 +00:00
|
|
|
public $prepared;
|
2012-10-17 19:42:03 +00:00
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* TemplatePower::__construct()
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @param string $tpl_file
|
|
|
|
|
* @param string $type
|
|
|
|
|
* @return void
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function __construct($tpl_file = '', $type = T_BYFILE)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
TemplatePowerParser::__construct($tpl_file, $type);
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->prepared = false;
|
|
|
|
|
$this->showUnAssigned = false;
|
2012-10-23 21:14:04 +00:00
|
|
|
$this->serialized = false;
|
2019-08-12 09:58:19 -04:00
|
|
|
//added: 26 April 2002
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* TemplatePower::deSerializeTPL()
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @param string $stpl_file
|
|
|
|
|
* @param string $tplvar
|
|
|
|
|
* @return void
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function deSerializeTPL($stpl_file, $type)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
|
|
|
|
if ($type == T_BYFILE) {
|
2019-08-12 09:58:19 -04:00
|
|
|
$serializedTPL = @file($stpl_file) or die($this->errorAlert('TemplatePower Error: Can\'t open [ ' . $stpl_file . ' ]!'));
|
2012-10-17 19:42:03 +00:00
|
|
|
} else {
|
|
|
|
|
$serializedTPL = $stpl_file;
|
|
|
|
|
}
|
2019-08-12 09:58:19 -04:00
|
|
|
$serializedStuff = unserialize(join('', $serializedTPL));
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->defBlock = $serializedStuff["defBlock"];
|
|
|
|
|
$this->index = $serializedStuff["index"];
|
|
|
|
|
$this->parent = $serializedStuff["parent"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* TemplatePower::makeContentRoot()
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function makeContentRoot()
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->content[TP_ROOTBLOCK . "_0"][0] = [TP_ROOTBLOCK];
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->currentBlock = &$this->content[TP_ROOTBLOCK . "_0"][0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* TemplatePower::assignPrivate()
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @param string $varname
|
|
|
|
|
* @param string $value
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function assignPrivate($varname, $value)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
if (sizeof($regs = explode('.', $varname)) == 2) {
|
2012-10-23 21:14:04 +00:00
|
|
|
//this is faster then preg_match
|
2012-10-17 19:42:03 +00:00
|
|
|
$ind_blockname = $regs[0] . '_' . $this->index[$regs[0]];
|
2019-08-12 09:58:19 -04:00
|
|
|
$lastitem = sizeof($this->content[$ind_blockname]);
|
|
|
|
|
$lastitem > 1 ? $lastitem-- : $lastitem = 0;
|
2012-10-17 19:42:03 +00:00
|
|
|
$block = &$this->content[$ind_blockname][$lastitem];
|
|
|
|
|
$varname = $regs[1];
|
|
|
|
|
} else {
|
|
|
|
|
$block = &$this->currentBlock;
|
|
|
|
|
}
|
|
|
|
|
$block["_V:$varname"] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* TemplatePower::assignGlobalPrivate()
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @param string $varname
|
|
|
|
|
* @param string $value
|
|
|
|
|
* @return void
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function assignGlobalPrivate($varname, $value)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
|
|
|
|
$this->globalvars[$varname] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* TemplatePower::outputContent()
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @param string $blockname
|
|
|
|
|
* @return void
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function outputContent($blockname)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
$numrows = sizeof($this->content[$blockname]);
|
|
|
|
|
for ($i = 0; $i < $numrows; $i++) {
|
2012-10-17 19:42:03 +00:00
|
|
|
$defblockname = $this->content[$blockname][$i][0];
|
2019-08-12 09:58:19 -04:00
|
|
|
for (reset($this->defBlock[$defblockname]); $k = key($this->defBlock[$defblockname]); next($this->defBlock[$defblockname])) {
|
2012-10-17 19:42:03 +00:00
|
|
|
if ($k[1] == 'C') {
|
2019-08-12 09:58:19 -04:00
|
|
|
print ($this->defBlock[$defblockname][$k]);
|
2012-10-23 21:14:04 +00:00
|
|
|
} elseif ($k[1] == 'V') {
|
2012-10-17 19:42:03 +00:00
|
|
|
$defValue = $this->defBlock[$defblockname][$k];
|
2019-08-12 09:58:19 -04:00
|
|
|
if (!isset($this->content[$blockname][$i]["_V:" . $defValue])) {
|
|
|
|
|
if (isset($this->globalvars[$defValue])) {
|
2012-10-17 19:42:03 +00:00
|
|
|
$value = $this->globalvars[$defValue];
|
|
|
|
|
} else {
|
2019-08-12 09:58:19 -04:00
|
|
|
//Verify if $defValue is like
|
|
|
|
|
// "xmlfile:ID_LABEL"
|
|
|
|
|
//if it is load an xml label.
|
|
|
|
|
//if not continues with non assigned value.
|
|
|
|
|
if (preg_match("/(.+):(.+)/", $defValue, $xmlreg)) {
|
|
|
|
|
$value = G::LoadTranslation(/*$xmlreg[1],*/
|
|
|
|
|
$xmlreg[2]);
|
2012-10-17 19:42:03 +00:00
|
|
|
} else {
|
|
|
|
|
if ($this->showUnAssigned) {
|
2019-08-12 09:58:19 -04:00
|
|
|
//$value = '{'. $this->defBlock[ $defblockname ][$k] .'}';
|
2012-10-17 19:42:03 +00:00
|
|
|
$value = '{' . $defValue . '}';
|
|
|
|
|
} else {
|
|
|
|
|
$value = '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$value = $this->content[$blockname][$i]["_V:" . $defValue];
|
|
|
|
|
}
|
2019-08-12 09:58:19 -04:00
|
|
|
if ($this->unhtmlentities) {
|
|
|
|
|
$value = G::unhtmlentities($value);
|
|
|
|
|
}
|
|
|
|
|
print ($value);
|
2012-10-23 21:14:04 +00:00
|
|
|
} elseif ($k[1] == 'B') {
|
2019-08-12 09:58:19 -04:00
|
|
|
if (isset($this->content[$blockname][$i][$k])) {
|
|
|
|
|
$this->outputContent($this->content[$blockname][$i][$k]);
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 09:58:19 -04:00
|
|
|
* function printVars
|
2012-10-17 19:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function printVars()
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
var_dump($this->defBlock);
|
|
|
|
|
print ("<br>--------------------<br>");
|
|
|
|
|
var_dump($this->content);
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ********
|
|
|
|
|
* public members
|
|
|
|
|
* *********
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePower::serializedBase()
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function serializedBase()
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
|
|
|
|
$this->serialized = true;
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->deSerializeTPL($this->tpl_base[0], $this->tpl_base[1]);
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePower::showUnAssigned()
|
|
|
|
|
*
|
|
|
|
|
* @param $state
|
|
|
|
|
* @return void
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function showUnAssigned($state = true)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
|
|
|
|
$this->showUnAssigned = $state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePower::prepare()
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function prepare()
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
if (!$this->serialized) {
|
|
|
|
|
TemplatePowerParser::prepare();
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
$this->prepared = true;
|
|
|
|
|
$this->index[TP_ROOTBLOCK] = 0;
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->makeContentRoot();
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePower::newBlock()
|
|
|
|
|
*
|
|
|
|
|
* @param string $blockname
|
|
|
|
|
* @return void
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function newBlock($blockname)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
|
|
|
|
$parent = &$this->content[$this->parent[$blockname] . '_' . $this->index[$this->parent[$blockname]]];
|
2019-08-12 09:58:19 -04:00
|
|
|
$lastitem = sizeof($parent);
|
|
|
|
|
$lastitem > 1 ? $lastitem-- : $lastitem = 0;
|
2012-10-17 19:42:03 +00:00
|
|
|
$ind_blockname = $blockname . '_' . $this->index[$blockname];
|
2019-08-12 09:58:19 -04:00
|
|
|
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
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->index[$blockname] += 1;
|
|
|
|
|
$ind_blockname = $blockname . '_' . $this->index[$blockname];
|
2019-08-12 09:58:19 -04:00
|
|
|
if (!isset($this->content[$ind_blockname])) {
|
|
|
|
|
$this->content[$ind_blockname] = [];
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
2019-08-12 09:58:19 -04:00
|
|
|
//tell the parent where his (possible) children are located
|
2012-10-17 19:42:03 +00:00
|
|
|
$parent[$lastitem]["_B:$blockname"] = $ind_blockname;
|
|
|
|
|
}
|
2019-08-12 09:58:19 -04:00
|
|
|
//now, make a copy of the block defenition
|
|
|
|
|
$blocksize = sizeof($this->content[$ind_blockname]);
|
|
|
|
|
$this->content[$ind_blockname][$blocksize] = [
|
|
|
|
|
$blockname
|
|
|
|
|
];
|
|
|
|
|
//link the current block to the block we just created
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->currentBlock = &$this->content[$ind_blockname][$blocksize];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePower::assignGlobal()
|
|
|
|
|
*
|
|
|
|
|
* @param string $varname
|
|
|
|
|
* @param string $value
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function assignGlobal($varname, $value = '')
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
if (is_array($varname)) {
|
2012-10-17 19:42:03 +00:00
|
|
|
foreach ($varname as $var => $value) {
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->assignGlobalPrivate($var, $value);
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->assignGlobalPrivate($varname, $value);
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePower::assign()
|
|
|
|
|
*
|
|
|
|
|
* @param string $varname
|
|
|
|
|
* @param string $value
|
|
|
|
|
* @return void
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function assign($varname, $value = '')
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
if (is_array($varname)) {
|
2012-10-17 19:42:03 +00:00
|
|
|
foreach ($varname as $var => $value) {
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->assignPrivate($var, $value);
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->assignPrivate($varname, $value);
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePower::gotoBlock()
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
* @param string $blockname
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function gotoBlock($blockname)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
if (isset($this->defBlock[$blockname])) {
|
2012-10-17 19:42:03 +00:00
|
|
|
$ind_blockname = $blockname . '_' . $this->index[$blockname];
|
2019-08-12 09:58:19 -04:00
|
|
|
//get lastitem indexnumber
|
|
|
|
|
$lastitem = sizeof($this->content[$ind_blockname]);
|
|
|
|
|
$lastitem > 1 ? $lastitem-- : $lastitem = 0;
|
|
|
|
|
//link the current block
|
2012-10-17 19:42:03 +00:00
|
|
|
$this->currentBlock = &$this->content[$ind_blockname][$lastitem];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePower::getVarValue()
|
|
|
|
|
*
|
|
|
|
|
* @param $varname
|
|
|
|
|
* @param string $varname
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function getVarValue($varname)
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
2019-08-12 09:58:19 -04:00
|
|
|
if (sizeof($regs = explode('.', $varname)) == 2) {
|
|
|
|
|
//this is faster then preg_match{
|
2012-10-17 19:42:03 +00:00
|
|
|
$ind_blockname = $regs[0] . '_' . $this->index[$regs[0]];
|
2019-08-12 09:58:19 -04:00
|
|
|
$lastitem = sizeof($this->content[$ind_blockname]);
|
|
|
|
|
$lastitem > 1 ? $lastitem-- : $lastitem = 0;
|
2012-10-17 19:42:03 +00:00
|
|
|
$block = &$this->content[$ind_blockname][$lastitem];
|
|
|
|
|
$varname = $regs[1];
|
|
|
|
|
} else {
|
|
|
|
|
$block = &$this->currentBlock;
|
|
|
|
|
}
|
|
|
|
|
return $block["_V:$varname"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePower::printToScreen()
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function printToScreen()
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
|
|
|
|
if ($this->prepared) {
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->outputContent(TP_ROOTBLOCK . '_0');
|
2012-10-17 19:42:03 +00:00
|
|
|
} else {
|
2019-08-12 09:58:19 -04:00
|
|
|
$this->errorAlert('TemplatePower Error: Template isn\'t prepared!');
|
2012-10-17 19:42:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TemplatePower::getOutputContent()
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2019-08-12 09:58:19 -04:00
|
|
|
public function getOutputContent()
|
2012-10-17 19:42:03 +00:00
|
|
|
{
|
|
|
|
|
ob_start();
|
|
|
|
|
$this->printToScreen();
|
|
|
|
|
$content = ob_get_contents();
|
|
|
|
|
ob_end_clean();
|
|
|
|
|
return $content;
|
|
|
|
|
}
|
2012-10-23 21:14:04 +00:00
|
|
|
}
|
|
|
|
|
|