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,5 +1,7 @@
<?php <?php
if (!defined('MSD_VERSION')) die('No direct access.'); if (!defined('MSD_VERSION')) {
die('No direct access.');
}
define('TPL_DEBUG', 0); // used if evaluationg of template fails define('TPL_DEBUG', 0); // used if evaluationg of template fails
/*************************************************************************** /***************************************************************************
* template.php * template.php
@ -28,7 +30,6 @@ 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";
@ -57,8 +58,9 @@ class MSDTemplate
/** /**
* 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);
} }
@ -67,7 +69,7 @@ class MSDTemplate
* Destroys this template object. Should be called when you're done with it, in order * 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. * 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();
} }
@ -75,13 +77,13 @@ class MSDTemplate
/** /**
* 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;
} }
@ -89,16 +91,14 @@ class MSDTemplate
* Sets the template filenames for handles. $filename_array * Sets the template filenames for handles. $filename_array
* should be a hash of handle => filename pairs. * 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);
} }
@ -110,27 +110,28 @@ class MSDTemplate
* 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.
*/ */
function pparse($handle) public function pparse($handle)
{ {
// Edit DSB: autimatically assign language vars // Edit DSB: automatically 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. // actually compile the template now.
if (!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle])) if (!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle])) {
{
// Actually compile the code now. // Actually compile the code now.
$this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]); $this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]);
} }
// Run the compiled code. // Run the compiled code.
if (defined(TPL_DEBUG) && TPL_DEBUG>0) echo '<pre>'.htmlspecialchars($this->compiled_code[$handle]).'</pre>'; 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;
} }
@ -142,10 +143,9 @@ class MSDTemplate
* 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");
} }
@ -166,16 +166,14 @@ class MSDTemplate
* 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.
*/ */
function assign_block_vars($blockname, $vararray) public function assign_block_vars($blockname, $vararray)
{
if (strstr($blockname,'.'))
{ {
if (strstr($blockname, '.')) {
// Nested block. // Nested block.
$blocks = explode('.', $blockname); $blocks = explode('.', $blockname);
$blockcount = sizeof($blocks) - 1; $blockcount = sizeof($blocks) - 1;
$str = '$this->_tpldata'; $str = '$this->_tpldata';
for ($i=0; $i < $blockcount; $i++) for ($i = 0; $i < $blockcount; $i++) {
{
$str .= '[\'' . $blocks[$i] . '.\']'; $str .= '[\'' . $blocks[$i] . '.\']';
eval('$lastiteration = sizeof(' . $str . ') - 1;'); eval('$lastiteration = sizeof(' . $str . ') - 1;');
$str .= '[' . $lastiteration . ']'; $str .= '[' . $lastiteration . ']';
@ -187,9 +185,7 @@ class MSDTemplate
// Now we evaluate this assignment we've built up. // Now we evaluate this assignment we've built up.
eval($str); eval($str);
} } else {
else
{
// Top-level block. // Top-level block.
// Add a new iteration to this block with the variable assignments // Add a new iteration to this block with the variable assignments
// we were given. // we were given.
@ -203,11 +199,10 @@ class MSDTemplate
* Root-level variable assignment. Adds to current assignments, overriding * Root-level variable assignment. Adds to current assignments, overriding
* any existing variable assignment with the same name. * any existing variable assignment with the same name.
*/ */
function assign_vars($vararray) public function assign_vars($vararray)
{ {
global $lang; global $lang;
while (list ($key, $val)=each($vararray)) while (list ($key, $val) = each($vararray)) {
{
$this->_tpldata['.'][0][$key] = $val; $this->_tpldata['.'][0][$key] = $val;
} }
@ -218,7 +213,7 @@ class MSDTemplate
* Root-level variable assignment. Adds to current assignments, overriding * Root-level variable assignment. Adds to current assignments, overriding
* any existing variable assignment with the same name. * any existing variable assignment with the same name.
*/ */
function assign_var($varname, $varval) public function assign_var($varname, $varval)
{ {
$this->_tpldata['.'][0][$varname] = $varval; $this->_tpldata['.'][0][$varname] = $varval;
@ -230,7 +225,7 @@ class MSDTemplate
* be an absolute name, or a name relative to the rootdir for this Template * be an absolute name, or a name relative to the rootdir for this Template
* object. * object.
*/ */
function make_filename($filename) public function make_filename($filename)
{ {
// Check if it's an absolute or relative path. // Check if it's an absolute or relative path.
/* /*
@ -239,8 +234,7 @@ class MSDTemplate
$filename = $this->root . '/' . $filename; $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");
} }
@ -251,25 +245,22 @@ class MSDTemplate
* If not already done, load the file for the given handle and populate * If not already done, load the file for the given handle and populate
* the uncompiled_code[] hash with its code. Do not compile. * the uncompiled_code[] hash with its code. Do not compile.
*/ */
function loadfile($handle) public function loadfile($handle)
{ {
// If the file for this handle is already loaded and compiled, do nothing. // If the file for this handle is already loaded and compiled, do nothing.
if (isset($this->uncompiled_code[$handle]) && !empty($this->uncompiled_code[$handle])) if (isset($this->uncompiled_code[$handle]) && !empty($this->uncompiled_code[$handle])) {
{
return true; return true;
} }
// If we don't have a file assigned to this handle, die. // If we don't have a file assigned to this handle, die.
if (!isset($this->files[$handle])) if (!isset($this->files[$handle])) {
{
die("Template->loadfile(): No file specified for handle $handle"); die("Template->loadfile(): No file specified for handle $handle");
} }
$filename = $this->files[$handle]; $filename = $this->files[$handle];
$str = implode("", @file($filename)); $str = implode("", @file($filename));
if (empty($str)) if (empty($str)) {
{
die("Template->loadfile(): File $filename for handle $handle is empty"); die("Template->loadfile(): File $filename for handle $handle is empty");
} }
@ -285,7 +276,7 @@ class MSDTemplate
* executable, but can be used as part of a variable assignment * executable, but can be used as part of a variable assignment
* for use in assign_code_from_handle(). * for use in assign_code_from_handle().
*/ */
function compile($code, $do_not_echo=false, $retvar='') public function compile($code, $do_not_echo = false, $retvar = '')
{ {
// replace \ with \\ and then ' with \'. // replace \ with \\ and then ' with \'.
$code = str_replace('\\', '\\\\', $code); $code = str_replace('\\', '\\\\', $code);
@ -299,8 +290,7 @@ class MSDTemplate
$varrefs = array(); $varrefs = array();
preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs); preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs);
$varcount = sizeof($varrefs[1]); $varcount = sizeof($varrefs[1]);
for ($i=0; $i < $varcount; $i++) for ($i = 0; $i < $varcount; $i++) {
{
$namespace = $varrefs[1][$i]; $namespace = $varrefs[1][$i];
$varname = $varrefs[3][$i]; $varname = $varrefs[3][$i];
$new = $this->generate_block_varref($namespace, $varname); $new = $this->generate_block_varref($namespace, $varname);
@ -309,7 +299,11 @@ class MSDTemplate
} }
// This will handle the remaining root-level varrefs // 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); $code = preg_replace(
'#\{([a-z0-9\-_]*?)\}#is',
'\' . ( ( isset($this->_tpldata[\'.\'][0][\'\1\']) ) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\' ) . \'',
$code
);
// Break it up into lines. // Break it up into lines.
$code_lines = explode("\n", $code); $code_lines = explode("\n", $code);
@ -320,28 +314,24 @@ class MSDTemplate
// Second: prepend echo ', append ' . "\n"; to each line. // Second: prepend echo ', append ' . "\n"; to each line.
$line_count = sizeof($code_lines); $line_count = sizeof($code_lines);
for ($i=0; $i < $line_count; $i++) for ($i = 0; $i < $line_count; $i++) {
{
$code_lines[$i] = chop($code_lines[$i]); $code_lines[$i] = chop($code_lines[$i]);
if (preg_match('#<!-- BEGIN (.*?) -->#',$code_lines[$i],$m)) if (preg_match('#<!-- BEGIN (.*?) -->#', $code_lines[$i], $m)) {
{
$n[0] = $m[0]; $n[0] = $m[0];
$n[1] = $m[1]; $n[1] = $m[1];
// Added: dougk_ff7-Keeps templates from bombing if begin is on the same line as end.. I think. :) // 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)) if (preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $n)) {
{
$block_nesting_level++; $block_nesting_level++;
$block_names[$block_nesting_level] = $m[1]; $block_names[$block_nesting_level] = $m[1];
if ($block_nesting_level < 2) if ($block_nesting_level < 2) {
{
// Block is not nested. // 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[1] . '_count = ( isset($this->_tpldata[\'' . $n[1]
$code_lines[$i].="\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)'; . '.\']) ) ? 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" . '{'; $code_lines[$i] .= "\n" . '{';
} } else {
else
{
// This block is nested. // This block is nested.
@ -353,8 +343,10 @@ class MSDTemplate
// current indices of all parent blocks. // current indices of all parent blocks.
$varref = $this->generate_block_data_ref($namespace, false); $varref = $this->generate_block_data_ref($namespace, false);
// Create the for loop code to iterate over this block. // 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[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref
$code_lines[$i].="\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)'; . ') : 0;';
$code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1]
. '_count; $_' . $n[1] . '_i++)';
$code_lines[$i] .= "\n" . '{'; $code_lines[$i] .= "\n" . '{';
} }
@ -364,21 +356,18 @@ class MSDTemplate
$code_lines[$i] .= '} // END ' . $n[1]; $code_lines[$i] .= '} // END ' . $n[1];
$m[0] = $n[0]; $m[0] = $n[0];
$m[1] = $n[1]; $m[1] = $n[1];
} } else {
else
{
// We have the start of a block. // We have the start of a block.
$block_nesting_level++; $block_nesting_level++;
$block_names[$block_nesting_level] = $m[1]; $block_names[$block_nesting_level] = $m[1];
if ($block_nesting_level < 2) if ($block_nesting_level < 2) {
{
// Block is not nested. // Block is not nested.
$code_lines[$i]='$_' . $m[1] . '_count = ( isset($this->_tpldata[\'' . $m[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $m[1] . '.\']) : 0;'; $code_lines[$i] = '$_' . $m[1] . '_count = ( isset($this->_tpldata[\'' . $m[1]
$code_lines[$i].="\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)'; . '.\']) ) ? 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" . '{'; $code_lines[$i] .= "\n" . '{';
} } else {
else
{
// This block is nested. // This block is nested.
@ -390,35 +379,33 @@ class MSDTemplate
// current indices of all parent blocks. // current indices of all parent blocks.
$varref = $this->generate_block_data_ref($namespace, false); $varref = $this->generate_block_data_ref($namespace, false);
// Create the for loop code to iterate over this block. // Create the for loop code to iterate over this block.
$code_lines[$i]='$_' . $m[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;'; $code_lines[$i] = '$_' . $m[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref
$code_lines[$i].="\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)'; . ') : 0;';
$code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1]
. '_count; $_' . $m[1] . '_i++)';
$code_lines[$i] .= "\n" . '{'; $code_lines[$i] .= "\n" . '{';
} }
} }
} } else {
else if (preg_match('#<!-- END (.*?) -->#',$code_lines[$i],$m)) if (preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $m)) {
{
// We have the end of a block. // We have the end of a block.
unset($block_names[$block_nesting_level]); unset($block_names[$block_nesting_level]);
$block_nesting_level--; $block_nesting_level--;
$code_lines[$i] = '} // END ' . $m[1]; $code_lines[$i] = '} // END ' . $m[1];
} } else {
else
{
// We have an ordinary line of code. // We have an ordinary line of code.
if (!$do_not_echo) if (!$do_not_echo) {
{
$code_lines[$i] = 'echo \'' . $code_lines[$i] . '\' . "\\n";'; $code_lines[$i] = 'echo \'' . $code_lines[$i] . '\' . "\\n";';
} } else {
else
{
$code_lines[$i] = '$' . $retvar . '.= \'' . $code_lines[$i] . '\' . "\\n";'; $code_lines[$i] = '$' . $retvar . '.= \'' . $code_lines[$i] . '\' . "\\n";';
} }
} }
} }
}
// Bring it back into a single string of lines of code. // Bring it back into a single string of lines of code.
$code = implode("\n", $code_lines); $code = implode("\n", $code_lines);
return $code; return $code;
} }
@ -430,7 +417,7 @@ class MSDTemplate
* It's ready to be inserted into an "echo" line in one of the templates. * It's ready to be inserted into an "echo" line in one of the templates.
* NOTE: expects a trailing "." on the namespace. * NOTE: expects a trailing "." on the namespace.
*/ */
function generate_block_varref($namespace, $varname) public function generate_block_varref($namespace, $varname)
{ {
// Strip the trailing period. // Strip the trailing period.
$namespace = substr($namespace, 0, strlen($namespace) - 1); $namespace = substr($namespace, 0, strlen($namespace) - 1);
@ -457,22 +444,20 @@ class MSDTemplate
* If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above. * 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. * NOTE: does not expect a trailing "." on the blockname.
*/ */
function generate_block_data_ref($blockname, $include_last_iterator) public function generate_block_data_ref($blockname, $include_last_iterator)
{ {
// Get an array of the blocks involved. // Get an array of the blocks involved.
$blocks = explode(".", $blockname); $blocks = explode(".", $blockname);
$blockcount = sizeof($blocks) - 1; $blockcount = sizeof($blocks) - 1;
$varref = '$this->_tpldata'; $varref = '$this->_tpldata';
// Build up the string with everything but the last child. // Build up the string with everything but the last child.
for ($i=0; $i < $blockcount; $i++) for ($i = 0; $i < $blockcount; $i++) {
{
$varref .= '[\'' . $blocks[$i] . '.\'][$_' . $blocks[$i] . '_i]'; $varref .= '[\'' . $blocks[$i] . '.\'][$_' . $blocks[$i] . '_i]';
} }
// Add the block reference for the last child. // Add the block reference for the last child.
$varref .= '[\'' . $blocks[$blockcount] . '.\']'; $varref .= '[\'' . $blocks[$blockcount] . '.\']';
// Add the iterator for the last child if requried. // Add the iterator for the last child if requried.
if ($include_last_iterator) if ($include_last_iterator) {
{
$varref .= '[$_' . $blocks[$blockcount] . '_i]'; $varref .= '[$_' . $blocks[$blockcount] . '_i]';
} }
@ -480,5 +465,3 @@ class MSDTemplate
} }
} }
?>