1
0
Fork 0

Removed some PHP7 deprecated stuff.

Dieser Commit ist enthalten in:
dsb 2016-11-09 18:21:03 +01:00
Ursprung de695bf97f
Commit bbfad7128b
2 geänderte Dateien mit 431 neuen und 447 gelöschten Zeilen

Datei anzeigen

@ -670,7 +670,8 @@ function CreateDirsFTP()
function ftp_mkdirs($config, $dirname) function ftp_mkdirs($config, $dirname)
{ {
$dir = split("/", $dirname); $path = '';
$dir = explode("/", $dirname);
for ($i = 0; $i < count($dir) - 1; $i++) { for ($i = 0; $i < count($dir) - 1; $i++) {
$path .= $dir[$i] . "/"; $path .= $dir[$i] . "/";
@ftp_mkdir($config['dbconnection'], $path); @ftp_mkdir($config['dbconnection'], $path);

Datei anzeigen

@ -1,6 +1,8 @@
<?php <?php
if (!defined('MSD_VERSION')) die('No direct access.'); if (!defined('MSD_VERSION')) {
define('TPL_DEBUG',0); // used if evaluationg of template fails die('No direct access.');
}
define('TPL_DEBUG', 0); // used if evaluationg of template fails
/*************************************************************************** /***************************************************************************
* template.php * template.php
* ------------------- * -------------------
@ -28,457 +30,438 @@ define('TPL_DEBUG',0); // used if evaluationg of template fails
* and the template file formats are quite similar. * and the template file formats are quite similar.
* *
*/ */
class MSDTemplate class MSDTemplate
{ {
var $classname="MSDTemplate"; var $classname = "MSDTemplate";
// variable that holds all the data we'll be substituting into // variable that holds all the data we'll be substituting into
// the compiled templates. // the compiled templates.
// ... // ...
// This will end up being a multi-dimensional array like this: // This will end up being a multi-dimensional array like this:
// $this->_tpldata[block.][iteration#][child.][iteration#][child2.][iteration#][variablename] == value // $this->_tpldata[block.][iteration#][child.][iteration#][child2.][iteration#][variablename] == value
// if it's a root-level variable, it'll be like this: // if it's a root-level variable, it'll be like this:
// $this->_tpldata[.][0][varname] == value // $this->_tpldata[.][0][varname] == value
var $_tpldata=array(); var $_tpldata = array();
// Hash of filenames for each template handle. // Hash of filenames for each template handle.
var $files=array(); var $files = array();
// Root template directory. // Root template directory.
var $root=""; var $root = "";
// this will hash handle names to the compiled code for that handle. // this will hash handle names to the compiled code for that handle.
var $compiled_code=array(); var $compiled_code = array();
// This will hold the uncompiled code for that handle. // This will hold the uncompiled code for that handle.
var $uncompiled_code=array(); var $uncompiled_code = array();
/** /**
* Constructor. Simply sets the root dir. * Constructor. Simply sets the root dir.
* *
*/ * @param string $root
function MSDTemplate($root=".") */
{ public function __construct($root = '.')
$this->set_rootdir($root); {
} $this->set_rootdir($root);
}
/**
* Destroys this template object. Should be called when you're done with it, in order /**
* to clear out the template data so you can load/parse a new template set. * Destroys this template object. Should be called when you're done with it, in order
*/ * to clear out the template data so you can load/parse a new template set.
function destroy() */
{ public function destroy()
$this->_tpldata=array(); {
} $this->_tpldata = array();
}
/**
* Sets the template root directory for this Template object. /**
*/ * Sets the template root directory for this Template object.
function set_rootdir($dir) */
{ public function set_rootdir($dir)
if (!is_dir($dir)) {
{ if (!is_dir($dir)) {
return false; return false;
} }
$this->root=$dir; $this->root = $dir;
return true;
} return true;
}
/**
* Sets the template filenames for handles. $filename_array /**
* should be a hash of handle => filename pairs. * Sets the template filenames for handles. $filename_array
*/ * should be a hash of handle => filename pairs.
function set_filenames($filename_array) */
{ public function set_filenames($filename_array)
if (!is_array($filename_array)) {
{ if (!is_array($filename_array)) {
return false; return false;
} }
reset($filename_array); reset($filename_array);
while (list ($handle, $filename)=each($filename_array)) while (list ($handle, $filename) = each($filename_array)) {
{ $this->files[$handle] = $this->make_filename($filename);
$this->files[$handle]=$this->make_filename($filename); }
}
return true;
return true; }
}
/**
/** * Load the file for the handle, compile the file,
* Load the file for the handle, compile the file, * and run the compiled code. This will print out
* and run the compiled code. This will print out * the results of executing the template.
* the results of executing the template. */
*/ public function pparse($handle)
function pparse($handle) {
{ // Edit DSB: automatically assign language vars
// Edit DSB: autimatically assign language vars global $lang;
global $lang; $this->assign_vars($lang);
$this->assign_vars($lang);
if (!$this->loadfile($handle)) {
if (!$this->loadfile($handle)) die("Template->pparse(): Couldn't load template file for handle $handle");
{ }
die("Template->pparse(): Couldn't load template file for handle $handle");
} // actually compile the template now.
if (!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle])) {
// actually compile the template now. // Actually compile the code now.
if (!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle])) $this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]);
{ }
// Actually compile the code now.
$this->compiled_code[$handle]=$this->compile($this->uncompiled_code[$handle]); // Run the compiled code.
} if (defined(TPL_DEBUG) && TPL_DEBUG > 0) {
echo '<pre>' . htmlspecialchars($this->compiled_code[$handle]) . '</pre>';
// Run the compiled code. }
if (defined(TPL_DEBUG) && TPL_DEBUG>0) echo '<pre>'.htmlspecialchars($this->compiled_code[$handle]).'</pre>'; eval($this->compiled_code[$handle]);
eval($this->compiled_code[$handle]);
return true; return true;
} }
/** /**
* Inserts the uncompiled code for $handle as the * Inserts the uncompiled code for $handle as the
* value of $varname in the root-level. This can be used * value of $varname in the root-level. This can be used
* to effectively include a template in the middle of another * to effectively include a template in the middle of another
* template. * template.
* Note that all desired assignments to the variables in $handle should be done * Note that all desired assignments to the variables in $handle should be done
* BEFORE calling this function. * BEFORE calling this function.
*/ */
function assign_var_from_handle($varname, $handle) public function assign_var_from_handle($varname, $handle)
{ {
if (!$this->loadfile($handle)) if (!$this->loadfile($handle)) {
{ die("Template->assign_var_from_handle(): Couldn't load template file for handle $handle");
die("Template->assign_var_from_handle(): Couldn't load template file for handle $handle"); }
}
// Compile it, with the "no echo statements" option on.
// Compile it, with the "no echo statements" option on. $_str = "";
$_str=""; $code = $this->compile($this->uncompiled_code[$handle], true, '_str');
$code=$this->compile($this->uncompiled_code[$handle],true,'_str');
// evaluate the variable assignment.
// evaluate the variable assignment. eval($code);
eval($code); // assign the value of the generated variable to the given varname.
// assign the value of the generated variable to the given varname. $this->assign_var($varname, $_str);
$this->assign_var($varname,$_str);
return true;
return true; }
}
/**
/** * Block-level variable assignment. Adds a new block iteration with the given
* Block-level variable assignment. Adds a new block iteration with the given * variable assignments. Note that this should only be called once per block
* variable assignments. Note that this should only be called once per block * iteration.
* iteration. */
*/ public function assign_block_vars($blockname, $vararray)
function assign_block_vars($blockname, $vararray) {
{ if (strstr($blockname, '.')) {
if (strstr($blockname,'.')) // Nested block.
{ $blocks = explode('.', $blockname);
// Nested block. $blockcount = sizeof($blocks) - 1;
$blocks=explode('.',$blockname); $str = '$this->_tpldata';
$blockcount=sizeof($blocks) - 1; for ($i = 0; $i < $blockcount; $i++) {
$str='$this->_tpldata'; $str .= '[\'' . $blocks[$i] . '.\']';
for ($i=0; $i < $blockcount; $i++) eval('$lastiteration = sizeof(' . $str . ') - 1;');
{ $str .= '[' . $lastiteration . ']';
$str.='[\'' . $blocks[$i] . '.\']'; }
eval('$lastiteration = sizeof(' . $str . ') - 1;'); // Now we add the block that we're actually assigning to.
$str.='[' . $lastiteration . ']'; // We're adding a new iteration to this block with the given
} // variable assignments.
// Now we add the block that we're actually assigning to. $str .= '[\'' . $blocks[$blockcount] . '.\'][] = $vararray;';
// We're adding a new iteration to this block with the given
// variable assignments. // Now we evaluate this assignment we've built up.
$str.='[\'' . $blocks[$blockcount] . '.\'][] = $vararray;'; eval($str);
} else {
// Now we evaluate this assignment we've built up. // Top-level block.
eval($str); // Add a new iteration to this block with the variable assignments
} // we were given.
else $this->_tpldata[$blockname . '.'][] = $vararray;
{ }
// Top-level block.
// Add a new iteration to this block with the variable assignments return true;
// we were given. }
$this->_tpldata[$blockname . '.'][]=$vararray;
} /**
* Root-level variable assignment. Adds to current assignments, overriding
return true; * any existing variable assignment with the same name.
} */
public function assign_vars($vararray)
/** {
* Root-level variable assignment. Adds to current assignments, overriding global $lang;
* any existing variable assignment with the same name. while (list ($key, $val) = each($vararray)) {
*/ $this->_tpldata['.'][0][$key] = $val;
function assign_vars($vararray) }
{
global $lang; return true;
while (list ($key, $val)=each($vararray)) }
{
$this->_tpldata['.'][0][$key]=$val; /**
} * Root-level variable assignment. Adds to current assignments, overriding
* any existing variable assignment with the same name.
return true; */
} public function assign_var($varname, $varval)
{
/** $this->_tpldata['.'][0][$varname] = $varval;
* Root-level variable assignment. Adds to current assignments, overriding
* any existing variable assignment with the same name. return true;
*/ }
function assign_var($varname, $varval)
{ /**
$this->_tpldata['.'][0][$varname]=$varval; * Generates a full path+filename for the given filename, which can either
* be an absolute name, or a name relative to the rootdir for this Template
return true; * object.
} */
public function make_filename($filename)
/** {
* Generates a full path+filename for the given filename, which can either // Check if it's an absolute or relative path.
* be an absolute name, or a name relative to the rootdir for this Template /*
* object. if (substr($filename, 0, 1) != '/')
*/ {
function make_filename($filename) $filename = $this->root . '/' . $filename;
{ }
// Check if it's an absolute or relative path.
/*
if (substr($filename, 0, 1) != '/')
{
$filename = $this->root . '/' . $filename;
}
*/ */
if (!file_exists($filename)) if (!file_exists($filename)) {
{ die("Template->make_filename(): Error - file $filename does not exist");
die("Template->make_filename(): Error - file $filename does not exist"); }
}
return $filename;
}
/**
* If not already done, load the file for the given handle and populate
* the uncompiled_code[] hash with its code. Do not compile.
*/
function loadfile($handle)
{
// If the file for this handle is already loaded and compiled, do nothing.
if (isset($this->uncompiled_code[$handle]) && !empty($this->uncompiled_code[$handle]))
{
return true;
}
// If we don't have a file assigned to this handle, die.
if (!isset($this->files[$handle]))
{
die("Template->loadfile(): No file specified for handle $handle");
}
$filename=$this->files[$handle];
$str=implode("",@file($filename));
if (empty($str))
{
die("Template->loadfile(): File $filename for handle $handle is empty");
}
$this->uncompiled_code[$handle]=$str;
return true;
}
/**
* Compiles the given string of code, and returns
* the result in a string.
* If "do_not_echo" is true, the returned code will not be directly
* executable, but can be used as part of a variable assignment
* for use in assign_code_from_handle().
*/
function compile($code, $do_not_echo=false, $retvar='')
{
// replace \ with \\ and then ' with \'.
$code=str_replace('\\','\\\\',$code);
$code=str_replace('\'','\\\'',$code);
return $filename;
// change template varrefs into PHP varrefs }
// This one will handle varrefs WITH namespaces /**
$varrefs=array(); * If not already done, load the file for the given handle and populate
preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is',$code,$varrefs); * the uncompiled_code[] hash with its code. Do not compile.
$varcount=sizeof($varrefs[1]); */
for ($i=0; $i < $varcount; $i++) public function loadfile($handle)
{ {
$namespace=$varrefs[1][$i]; // If the file for this handle is already loaded and compiled, do nothing.
$varname=$varrefs[3][$i]; if (isset($this->uncompiled_code[$handle]) && !empty($this->uncompiled_code[$handle])) {
$new=$this->generate_block_varref($namespace,$varname); return true;
}
$code=str_replace($varrefs[0][$i],$new,$code);
}
// This will handle the remaining root-level varrefs
$code=preg_replace('#\{([a-z0-9\-_]*?)\}#is','\' . ( ( isset($this->_tpldata[\'.\'][0][\'\1\']) ) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\' ) . \'',$code);
// Break it up into lines.
$code_lines=explode("\n",$code);
$block_nesting_level=0;
$block_names=array();
$block_names[0]=".";
// Second: prepend echo ', append ' . "\n"; to each line.
$line_count=sizeof($code_lines);
for ($i=0; $i < $line_count; $i++)
{
$code_lines[$i]=chop($code_lines[$i]);
if (preg_match('#<!-- BEGIN (.*?) -->#',$code_lines[$i],$m))
{
$n[0]=$m[0];
$n[1]=$m[1];
// Added: dougk_ff7-Keeps templates from bombing if begin is on the same line as end.. I think. :)
if (preg_match('#<!-- END (.*?) -->#',$code_lines[$i],$n))
{
$block_nesting_level++;
$block_names[$block_nesting_level]=$m[1];
if ($block_nesting_level < 2)
{
// Block is not nested.
$code_lines[$i]='$_' . $n[1] . '_count = ( isset($this->_tpldata[\'' . $n[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $n[1] . '.\']) : 0;';
$code_lines[$i].="\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)';
$code_lines[$i].="\n" . '{';
}
else
{
// This block is nested.
// Generate a namespace string for this block. // If we don't have a file assigned to this handle, die.
$namespace=implode('.',$block_names); if (!isset($this->files[$handle])) {
// strip leading period from root level.. die("Template->loadfile(): No file specified for handle $handle");
$namespace=substr($namespace,2); }
// Get a reference to the data array for this block that depends on the
// current indices of all parent blocks.
$varref=$this->generate_block_data_ref($namespace,false);
// Create the for loop code to iterate over this block.
$code_lines[$i]='$_' . $n[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;';
$code_lines[$i].="\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)';
$code_lines[$i].="\n" . '{';
}
// We have the end of a block.
unset($block_names[$block_nesting_level]);
$block_nesting_level--;
$code_lines[$i].='} // END ' . $n[1];
$m[0]=$n[0];
$m[1]=$n[1];
}
else
{
// We have the start of a block.
$block_nesting_level++;
$block_names[$block_nesting_level]=$m[1];
if ($block_nesting_level < 2)
{
// Block is not nested.
$code_lines[$i]='$_' . $m[1] . '_count = ( isset($this->_tpldata[\'' . $m[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $m[1] . '.\']) : 0;';
$code_lines[$i].="\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)';
$code_lines[$i].="\n" . '{';
}
else
{
// This block is nested.
// Generate a namespace string for this block. $filename = $this->files[$handle];
$namespace=implode('.',$block_names);
// strip leading period from root level..
$namespace=substr($namespace,2);
// Get a reference to the data array for this block that depends on the
// current indices of all parent blocks.
$varref=$this->generate_block_data_ref($namespace,false);
// Create the for loop code to iterate over this block.
$code_lines[$i]='$_' . $m[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;';
$code_lines[$i].="\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)';
$code_lines[$i].="\n" . '{';
}
}
}
else if (preg_match('#<!-- END (.*?) -->#',$code_lines[$i],$m))
{
// We have the end of a block.
unset($block_names[$block_nesting_level]);
$block_nesting_level--;
$code_lines[$i]='} // END ' . $m[1];
}
else
{
// We have an ordinary line of code.
if (!$do_not_echo)
{
$code_lines[$i]='echo \'' . $code_lines[$i] . '\' . "\\n";';
}
else
{
$code_lines[$i]='$' . $retvar . '.= \'' . $code_lines[$i] . '\' . "\\n";';
}
}
}
// Bring it back into a single string of lines of code.
$code=implode("\n",$code_lines);
return $code;
}
/**
* Generates a reference to the given variable inside the given (possibly nested)
* block namespace. This is a string of the form:
* ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . '
* It's ready to be inserted into an "echo" line in one of the templates.
* NOTE: expects a trailing "." on the namespace.
*/
function generate_block_varref($namespace, $varname)
{
// Strip the trailing period.
$namespace=substr($namespace,0,strlen($namespace) - 1);
// Get a reference to the data block for this namespace.
$varref=$this->generate_block_data_ref($namespace,true);
// Prepend the necessary code to stick this in an echo line.
// Append the variable reference. $str = implode("", @file($filename));
$varref.='[\'' . $varname . '\']'; if (empty($str)) {
die("Template->loadfile(): File $filename for handle $handle is empty");
$varref='\' . ( ( isset(' . $varref . ') ) ? ' . $varref . ' : \'\' ) . \''; }
return $varref; $this->uncompiled_code[$handle] = $str;
} return true;
}
/**
* Generates a reference to the array of data values for the given /**
* (possibly nested) block namespace. This is a string of the form: * Compiles the given string of code, and returns
* $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN'] * the result in a string.
* * If "do_not_echo" is true, the returned code will not be directly
* If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above. * executable, but can be used as part of a variable assignment
* NOTE: does not expect a trailing "." on the blockname. * for use in assign_code_from_handle().
*/ */
function generate_block_data_ref($blockname, $include_last_iterator) public function compile($code, $do_not_echo = false, $retvar = '')
{ {
// Get an array of the blocks involved. // replace \ with \\ and then ' with \'.
$blocks=explode(".",$blockname); $code = str_replace('\\', '\\\\', $code);
$blockcount=sizeof($blocks) - 1; $code = str_replace('\'', '\\\'', $code);
$varref='$this->_tpldata';
// Build up the string with everything but the last child.
for ($i=0; $i < $blockcount; $i++) // change template varrefs into PHP varrefs
{
$varref.='[\'' . $blocks[$i] . '.\'][$_' . $blocks[$i] . '_i]';
} // This one will handle varrefs WITH namespaces
// Add the block reference for the last child. $varrefs = array();
$varref.='[\'' . $blocks[$blockcount] . '.\']'; preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs);
// Add the iterator for the last child if requried. $varcount = sizeof($varrefs[1]);
if ($include_last_iterator) for ($i = 0; $i < $varcount; $i++) {
{ $namespace = $varrefs[1][$i];
$varref.='[$_' . $blocks[$blockcount] . '_i]'; $varname = $varrefs[3][$i];
} $new = $this->generate_block_varref($namespace, $varname);
return $varref; $code = str_replace($varrefs[0][$i], $new, $code);
} }
// This will handle the remaining root-level varrefs
$code = preg_replace(
'#\{([a-z0-9\-_]*?)\}#is',
'\' . ( ( isset($this->_tpldata[\'.\'][0][\'\1\']) ) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\' ) . \'',
$code
);
// Break it up into lines.
$code_lines = explode("\n", $code);
$block_nesting_level = 0;
$block_names = array();
$block_names[0] = ".";
// Second: prepend echo ', append ' . "\n"; to each line.
$line_count = sizeof($code_lines);
for ($i = 0; $i < $line_count; $i++) {
$code_lines[$i] = chop($code_lines[$i]);
if (preg_match('#<!-- BEGIN (.*?) -->#', $code_lines[$i], $m)) {
$n[0] = $m[0];
$n[1] = $m[1];
// Added: dougk_ff7-Keeps templates from bombing if begin is on the same line as end.. I think. :)
if (preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $n)) {
$block_nesting_level++;
$block_names[$block_nesting_level] = $m[1];
if ($block_nesting_level < 2) {
// Block is not nested.
$code_lines[$i] = '$_' . $n[1] . '_count = ( isset($this->_tpldata[\'' . $n[1]
. '.\']) ) ? sizeof($this->_tpldata[\'' . $n[1] . '.\']) : 0;';
$code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1]
. '_count; $_' . $n[1] . '_i++)';
$code_lines[$i] .= "\n" . '{';
} else {
// This block is nested.
// Generate a namespace string for this block.
$namespace = implode('.', $block_names);
// strip leading period from root level..
$namespace = substr($namespace, 2);
// Get a reference to the data array for this block that depends on the
// current indices of all parent blocks.
$varref = $this->generate_block_data_ref($namespace, false);
// Create the for loop code to iterate over this block.
$code_lines[$i] = '$_' . $n[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref
. ') : 0;';
$code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1]
. '_count; $_' . $n[1] . '_i++)';
$code_lines[$i] .= "\n" . '{';
}
// We have the end of a block.
unset($block_names[$block_nesting_level]);
$block_nesting_level--;
$code_lines[$i] .= '} // END ' . $n[1];
$m[0] = $n[0];
$m[1] = $n[1];
} else {
// We have the start of a block.
$block_nesting_level++;
$block_names[$block_nesting_level] = $m[1];
if ($block_nesting_level < 2) {
// Block is not nested.
$code_lines[$i] = '$_' . $m[1] . '_count = ( isset($this->_tpldata[\'' . $m[1]
. '.\']) ) ? sizeof($this->_tpldata[\'' . $m[1] . '.\']) : 0;';
$code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1]
. '_count; $_' . $m[1] . '_i++)';
$code_lines[$i] .= "\n" . '{';
} else {
// This block is nested.
// Generate a namespace string for this block.
$namespace = implode('.', $block_names);
// strip leading period from root level..
$namespace = substr($namespace, 2);
// Get a reference to the data array for this block that depends on the
// current indices of all parent blocks.
$varref = $this->generate_block_data_ref($namespace, false);
// Create the for loop code to iterate over this block.
$code_lines[$i] = '$_' . $m[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref
. ') : 0;';
$code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1]
. '_count; $_' . $m[1] . '_i++)';
$code_lines[$i] .= "\n" . '{';
}
}
} else {
if (preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $m)) {
// We have the end of a block.
unset($block_names[$block_nesting_level]);
$block_nesting_level--;
$code_lines[$i] = '} // END ' . $m[1];
} else {
// We have an ordinary line of code.
if (!$do_not_echo) {
$code_lines[$i] = 'echo \'' . $code_lines[$i] . '\' . "\\n";';
} else {
$code_lines[$i] = '$' . $retvar . '.= \'' . $code_lines[$i] . '\' . "\\n";';
}
}
}
}
// Bring it back into a single string of lines of code.
$code = implode("\n", $code_lines);
return $code;
}
/**
* Generates a reference to the given variable inside the given (possibly nested)
* block namespace. This is a string of the form:
* ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . '
* It's ready to be inserted into an "echo" line in one of the templates.
* NOTE: expects a trailing "." on the namespace.
*/
public function generate_block_varref($namespace, $varname)
{
// Strip the trailing period.
$namespace = substr($namespace, 0, strlen($namespace) - 1);
// Get a reference to the data block for this namespace.
$varref = $this->generate_block_data_ref($namespace, true);
// Prepend the necessary code to stick this in an echo line.
// Append the variable reference.
$varref .= '[\'' . $varname . '\']';
$varref = '\' . ( ( isset(' . $varref . ') ) ? ' . $varref . ' : \'\' ) . \'';
return $varref;
}
/**
* Generates a reference to the array of data values for the given
* (possibly nested) block namespace. This is a string of the form:
* $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN']
*
* If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above.
* NOTE: does not expect a trailing "." on the blockname.
*/
public function generate_block_data_ref($blockname, $include_last_iterator)
{
// Get an array of the blocks involved.
$blocks = explode(".", $blockname);
$blockcount = sizeof($blocks) - 1;
$varref = '$this->_tpldata';
// Build up the string with everything but the last child.
for ($i = 0; $i < $blockcount; $i++) {
$varref .= '[\'' . $blocks[$i] . '.\'][$_' . $blocks[$i] . '_i]';
}
// Add the block reference for the last child.
$varref .= '[\'' . $blocks[$blockcount] . '.\']';
// Add the iterator for the last child if requried.
if ($include_last_iterator) {
$varref .= '[$_' . $blocks[$blockcount] . '_i]';
}
return $varref;
}
} }
?>