1
0
mirror of https://e.coding.net/circlecloud/MinecraftAccount.git synced 2025-11-25 21:36:08 +00:00

首次提交...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092
2015-11-01 22:25:03 +08:00
commit 2003fda7cb
409 changed files with 77938 additions and 0 deletions

View File

@@ -0,0 +1,986 @@
<?php
/*
* Project: template_lite, a smarter template engine
* File: class.compiler.php
* Author: Paul Lockaby <paul@paullockaby.com>, Mark Dickenson <akapanamajack@sourceforge.net>
* Copyright: 2003,2004,2005 by Paul Lockaby, 2005,2006 Mark Dickenson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* The latest version of template_lite can be obtained from:
* http://templatelite.sourceforge.net
*
*/
class Template_Lite_Compiler extends Template_Lite {
// public configuration variables
var $left_delimiter = "";
var $right_delimiter = "";
var $plugins_dir = "";
var $template_dir = "";
var $reserved_template_varname = "";
var $default_modifiers = array();
var $php_extract_vars = true; // Set this to false if you do not want the $this->_tpl variables to be extracted for use by PHP code inside the template.
// private internal variables
var $_vars = array(); // stores all internal assigned variables
var $_confs = array(); // stores all internal config variables
var $_plugins = array(); // stores all internal plugins
var $_linenum = 0; // the current line number in the file we are processing
var $_file = ""; // the current file we are processing
var $_literal = array(); // stores all literal blocks
var $_foreachelse_stack = array();
var $_for_stack = 0;
var $_sectionelse_stack = array(); // keeps track of whether section had 'else' part
var $_switch_stack = array();
var $_tag_stack = array();
var $_require_stack = array(); // stores all files that are "required" inside of the template
var $_php_blocks = array(); // stores all of the php blocks
var $_error_level = null;
var $_sl_md5 = '39fc70570b8b60cbc1b85839bf242aff';
var $_db_qstr_regexp = null; // regexps are setup in the constructor
var $_si_qstr_regexp = null;
var $_qstr_regexp = null;
var $_func_regexp = null;
var $_var_bracket_regexp = null;
var $_dvar_regexp = null;
var $_cvar_regexp = null;
var $_svar_regexp = null;
var $_mod_regexp = null;
var $_var_regexp = null;
var $_obj_params_regexp = null;
var $_templatelite_vars = array();
function Template_Lite_compiler()
{
// matches double quoted strings:
// "foobar"
// "foo\"bar"
// "foobar" . "foo\"bar"
$this->_db_qstr_regexp = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"';
// matches single quoted strings:
// 'foobar'
// 'foo\'bar'
$this->_si_qstr_regexp = '\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'';
// matches single or double quoted strings
$this->_qstr_regexp = '(?:' . $this->_db_qstr_regexp . '|' . $this->_si_qstr_regexp . ')';
// matches bracket portion of vars
// [0]
// [foo]
// [$bar]
// [#bar#]
$this->_var_bracket_regexp = '\[[\$|\#]?\w+\#?\]';
// $this->_var_bracket_regexp = '\[\$?[\w\.]+\]';
// matches section vars:
// %foo.bar%
$this->_svar_regexp = '\%\w+\.\w+\%';
// matches $ vars (not objects):
// $foo
// $foo[0]
// $foo[$bar]
// $foo[5][blah]
// $this->_dvar_regexp = '\$[a-zA-Z0-9_]{1,}(?:' . $this->_var_bracket_regexp . ')*(?:' . $this->_var_bracket_regexp . ')*';
$this->_dvar_regexp = '\$[a-zA-Z0-9_]{1,}(?:' . $this->_var_bracket_regexp . ')*(?:\.\$?\w+(?:' . $this->_var_bracket_regexp . ')*)*';
// matches config vars:
// #foo#
// #foobar123_foo#
$this->_cvar_regexp = '\#[a-zA-Z0-9_]{1,}(?:' . $this->_var_bracket_regexp . ')*(?:' . $this->_var_bracket_regexp . ')*\#';
// matches valid variable syntax:
// $foo
// 'text'
// "text"
$this->_var_regexp = '(?:(?:' . $this->_dvar_regexp . '|' . $this->_cvar_regexp . ')|' . $this->_qstr_regexp . ')';
// matches valid modifier syntax:
// |foo
// |@foo
// |foo:"bar"
// |foo:$bar
// |foo:"bar":$foobar
// |foo|bar
$this->_mod_regexp = '(?:\|@?[0-9a-zA-Z_]+(?::(?>-?\w+|' . $this->_dvar_regexp . '|' . $this->_qstr_regexp .'))*)';
// matches valid function name:
// foo123
// _foo_bar
$this->_func_regexp = '[a-zA-Z_]+';
// $this->_func_regexp = '[a-zA-Z_]\w*';
}
function _compile_file($file_contents)
{
$ldq = preg_quote($this->left_delimiter);
$rdq = preg_quote($this->right_delimiter);
$_match = array(); // a temp variable for the current regex match
$tags = array(); // all original tags
$text = array(); // all original text
$compiled_text = '<?php /* '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' */ ?>'."\n\n"; // stores the compiled result
$compiled_tags = array(); // all tags and stuff
$this->_require_stack = array();
$this->_load_filters();
if (count($this->_plugins['prefilter']) > 0)
{
foreach ($this->_plugins['prefilter'] as $function)
{
if ($function === false)
{
continue;
}
$file_contents = $function($file_contents, $this);
}
}
// remove all comments
$file_contents = preg_replace("!{$ldq}\*.*?\*{$rdq}!se","",$file_contents);
// replace all php start and end tags
$file_contents = preg_replace('%(<\?(?!php|=|$))%i', '<?php echo \'\\1\'?>'."\n", $file_contents);
// remove literal blocks
preg_match_all("!{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}!s", $file_contents, $_match);
$this->_literal = $_match[1];
$file_contents = preg_replace("!{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}!s", stripslashes($ldq . "literal" . $rdq), $file_contents);
// remove php blocks
preg_match_all("!{$ldq}\s*php\s*{$rdq}(.*?){$ldq}\s*/php\s*{$rdq}!s", $file_contents, $_match);
$this->_php_blocks = $_match[1];
$file_contents = preg_replace("!{$ldq}\s*php\s*{$rdq}(.*?){$ldq}\s*/php\s*{$rdq}!s", stripslashes($ldq . "php" . $rdq), $file_contents);
// gather all template tags
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $file_contents, $_match);
$tags = $_match[1];
// put all of the non-template tag text blocks into an array, using the template tags as delimiters
$text = preg_split("!{$ldq}.*?{$rdq}!s", $file_contents);
// compile template tags
$count_tags = count($tags);
for ($i = 0, $for_max = $count_tags; $i < $for_max; $i++)
{
$this->_linenum += substr_count($text[$i], "\n");
$compiled_tags[] = $this->_compile_tag($tags[$i]);
$this->_linenum += substr_count($tags[$i], "\n");
}
// build the compiled template by replacing and interleaving text blocks and compiled tags
$count_compiled_tags = count($compiled_tags);
for ($i = 0, $for_max = $count_compiled_tags; $i < $for_max; $i++)
{
if ($compiled_tags[$i] == '') {
$text[$i+1] = preg_replace('~^(\r\n|\r|\n)~', '', $text[$i+1]);
}
$compiled_text .= $text[$i].$compiled_tags[$i];
}
$compiled_text .= $text[$i];
foreach ($this->_require_stack as $key => $value)
{
$compiled_text = '<?php require_once(\''. $this->_get_plugin_dir($key) . $key . '\'); $this->register_' . $value[0] . '("' . $value[1] . '", "' . $value[2] . '"); ?>' . $compiled_text;
}
// remove unnecessary close/open tags
$compiled_text = preg_replace('!\?>\n?<\?php!', '', $compiled_text);
if (count($this->_plugins['postfilter']) > 0)
{
foreach ($this->_plugins['postfilter'] as $function)
{
if ($function === false)
{
continue;
}
$compiled_text = $function($compiled_text, $this);
}
}
return $compiled_text;
}
function _compile_tag($tag)
{
$_match = array(); // stores the tags
$_result = ""; // the compiled tag
$_variable = ""; // the compiled variable
// extract the tag command, modifier and arguments
preg_match_all('/(?:(' . $this->_var_regexp . '|' . $this->_svar_regexp . '|\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . '*)(?:\s*[,\.]\s*)?)(?:\s+(.*))?/xs', $tag, $_match);
if ($_match[1][0]{0} == '$' || ($_match[1][0]{0} == '#' && $_match[1][0]{strlen($_match[1][0]) - 1} == '#') || $_match[1][0]{0} == "'" || $_match[1][0]{0} == '"' || $_match[1][0]{0} == '%')
{
$_result = $this->_parse_variables($_match[1], $_match[2]);
return "<?php echo $_result; ?>\n";
}
// process a function
$tag_command = $_match[1][0];
$tag_modifiers = !empty($_match[2][0]) ? $_match[2][0] : null;
$tag_arguments = !empty($_match[3][0]) ? $_match[3][0] : null;
$_result = $this->_parse_function($tag_command, $tag_modifiers, $tag_arguments);
return $_result;
}
function _parse_function($function, $modifiers, $arguments)
{
switch ($function) {
case 'include':
if (!function_exists('compile_include'))
{
require_once(TEMPLATE_LITE_DIR . "internal/compile.include.php");
}
return compile_include($arguments, $this);
break;
case 'insert':
$_args = $this->_parse_arguments($arguments);
if (!isset($_args['name']))
{
$this->trigger_error("missing 'name' attribute in 'insert'", E_USER_ERROR, __FILE__, __LINE__);
}
foreach ($_args as $key => $value)
{
if (is_bool($value))
{
$value = $value ? 'true' : 'false';
}
$arg_list[] = "'$key' => $value";
}
return '<?php echo $this->_run_insert(array(' . implode(', ', (array)$arg_list) . ')); ?>';
break;
case 'ldelim':
return $this->left_delimiter;
break;
case 'rdelim':
return $this->right_delimiter;
break;
case 'literal':
list (,$literal) = each($this->_literal);
$this->_linenum += substr_count($literal, "\n");
return "<?php echo '" . str_replace("'", "\'", str_replace("\\", "\\\\", $literal)) . "'; ?>\n";
break;
case 'php':
list (,$php_block) = each($this->_php_blocks);
$this->_linenum += substr_count($php_block, "\n");
$php_extract = '';
if($this->php_extract_vars)
{
if (strnatcmp(PHP_VERSION, '4.3.0') >= 0)
{
$php_extract = '<?php extract($this->_vars, EXTR_REFS); ?>' . "\n";
}
else
{
$php_extract = '<?php extract($this->_vars); ?>' . "\n";
}
}
return $php_extract . '<?php '.$php_block.' ?>';
break;
case 'foreach':
array_push($this->_foreachelse_stack, false);
$_args = $this->_parse_arguments($arguments);
if (!isset($_args['from']))
{
$this->trigger_error("missing 'from' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
}
if (!isset($_args['value']) && !isset($_args['item']))
{
$this->trigger_error("missing 'value' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
}
if (isset($_args['value']))
{
$_args['value'] = $this->_dequote($_args['value']);
}
elseif (isset($_args['item']))
{
$_args['value'] = $this->_dequote($_args['item']);
}
isset($_args['key']) ? $_args['key'] = "\$this->_vars['".$this->_dequote($_args['key'])."'] => " : $_args['key'] = '';
$_result = '<?php if (count((array)' . $_args['from'] . ')): foreach ((array)' . $_args['from'] . ' as ' . $_args['key'] . '$this->_vars[\'' . $_args['value'] . '\']): ?>';
return $_result;
break;
case 'foreachelse':
$this->_foreachelse_stack[count($this->_foreachelse_stack)-1] = true;
return "<?php endforeach; else: ?>";
break;
case '/foreach':
if (array_pop($this->_foreachelse_stack))
{
return "<?php endif; ?>";
}
else
{
return "<?php endforeach; endif; ?>";
}
break;
case 'for':
$this->_for_stack++;
$_args = $this->_parse_arguments($arguments);
if (!isset($_args['start']))
{
$this->trigger_error("missing 'start' attribute in 'for'", E_USER_ERROR, __FILE__, __LINE__);
}
if (!isset($_args['stop']))
{
$this->trigger_error("missing 'stop' attribute in 'for'", E_USER_ERROR, __FILE__, __LINE__);
}
if (!isset($_args['step']))
{
$_args['step'] = 1;
}
$_result = '<?php for($for' . $this->_for_stack . ' = ' . $_args['start'] . '; ((' . $_args['start'] . ' < ' . $_args['stop'] . ') ? ($for' . $this->_for_stack . ' < ' . $_args['stop'] . ') : ($for' . $this->_for_stack . ' > ' . $_args['stop'] . ')); $for' . $this->_for_stack . ' += ((' . $_args['start'] . ' < ' . $_args['stop'] . ') ? ' . $_args['step'] . ' : -' . $_args['step'] . ')): ?>';
if (isset($_args['value']))
{
$_result .= '<?php $this->assign(\'' . $this->_dequote($_args['value']) . '\', $for' . $this->_for_stack . '); ?>';
}
return $_result;
break;
case '/for':
$this->_for_stack--;
return "<?php endfor; ?>";
break;
case 'section':
array_push($this->_sectionelse_stack, false);
if (!function_exists('compile_section_start'))
{
require_once(TEMPLATE_LITE_DIR . "internal/compile.section_start.php");
}
return compile_section_start($arguments, $this);
break;
case 'sectionelse':
$this->_sectionelse_stack[count($this->_sectionelse_stack)-1] = true;
return "<?php endfor; else: ?>";
break;
case '/section':
if (array_pop($this->_sectionelse_stack))
{
return "<?php endif; ?>";
}
else
{
return "<?php endfor; endif; ?>";
}
break;
case 'while':
$_args = $this->_compile_if($arguments, false, true);
return '<?php while(' . $_args . '): ?>';
break;
case '/while':
return "<?php endwhile; ?>";
break;
case 'if':
return $this->_compile_if($arguments);
break;
case 'else':
return "<?php else: ?>";
break;
case 'elseif':
return $this->_compile_if($arguments, true);
break;
case '/if':
return "<?php endif; ?>";
break;
case 'assign':
$_args = $this->_parse_arguments($arguments);
if (!isset($_args['var']))
{
$this->trigger_error("missing 'var' attribute in 'assign'", E_USER_ERROR, __FILE__, __LINE__);
}
if (!isset($_args['value']))
{
$this->trigger_error("missing 'value' attribute in 'assign'", E_USER_ERROR, __FILE__, __LINE__);
}
return '<?php $this->assign(\'' . $this->_dequote($_args['var']) . '\', ' . $_args['value'] . '); ?>';
break;
case 'switch':
$_args = $this->_parse_arguments($arguments);
if (!isset($_args['from']))
{
$this->trigger_error("missing 'from' attribute in 'switch'", E_USER_ERROR, __FILE__, __LINE__);
}
array_push($this->_switch_stack, array("matched" => false, "var" => $this->_dequote($_args['from'])));
return;
break;
case '/switch':
array_pop($this->_switch_stack);
return '<?php break; endswitch; ?>';
break;
case 'case':
if (count($this->_switch_stack) > 0)
{
$_result = "<?php ";
$_args = $this->_parse_arguments($arguments);
$_index = count($this->_switch_stack) - 1;
if (!$this->_switch_stack[$_index]["matched"])
{
$_result .= 'switch(' . $this->_switch_stack[$_index]["var"] . '): ';
$this->_switch_stack[$_index]["matched"] = true;
}
else
{
$_result .= 'break; ';
}
if (!empty($_args['value']))
{
$_result .= 'case '.$_args['value'].': ';
}
else
{
$_result .= 'default: ';
}
return $_result . ' ?>';
}
else
{
$this->trigger_error("unexpected 'case', 'case' can only be in a 'switch'", E_USER_ERROR, __FILE__, __LINE__);
}
break;
case 'config_load':
$_args = $this->_parse_arguments($arguments);
if (empty($_args['file']))
{
$this->trigger_error("missing 'file' attribute in 'config_load' tag", E_USER_ERROR, __FILE__, __LINE__);
}
isset($_args['section']) ? null : $_args['section'] = 'null';
isset($_args['var']) ? null : $_args['var'] = 'null';
return '<?php $this->config_load(' . $_args['file'] . ', ' . $_args['section'] . ', ' . $_args['var'] . '); ?>';
break;
default:
$_result = "";
if ($this->_compile_compiler_function($function, $arguments, $_result))
{
return $_result;
}
else if ($this->_compile_custom_block($function, $modifiers, $arguments, $_result))
{
return $_result;
}
elseif ($this->_compile_custom_function($function, $modifiers, $arguments, $_result))
{
return $_result;
}
else
{
$this->trigger_error($function." function does not exist", E_USER_ERROR, __FILE__, __LINE__);
}
break;
}
}
function _compile_compiler_function($function, $arguments, &$_result)
{
if ($function = $this->_plugin_exists($function, "compiler"))
{
$_args = $this->_parse_arguments($arguments);
$_result = '<?php ' . $function($_args, $this) . ' ?>';
return true;
}
else
{
return false;
}
}
function _compile_custom_function($function, $modifiers, $arguments, &$_result)
{
if (!function_exists('compile_compile_custom_function'))
{
require_once(TEMPLATE_LITE_DIR . "internal/compile.compile_custom_function.php");
}
return compile_compile_custom_function($function, $modifiers, $arguments, $_result, $this);
}
function _compile_custom_block($function, $modifiers, $arguments, &$_result)
{
if (!function_exists('compile_compile_custom_block'))
{
require_once(TEMPLATE_LITE_DIR . "internal/compile.compile_custom_block.php");
}
return compile_compile_custom_block($function, $modifiers, $arguments, $_result, $this);
}
function _compile_if($arguments, $elseif = false, $while = false)
{
if (!function_exists('compile_compile_if'))
{
require_once(TEMPLATE_LITE_DIR . "internal/compile.compile_if.php");
}
return compile_compile_if($arguments, $elseif, $while, $this);
}
function _parse_is_expr($is_arg, $_arg)
{
if (!function_exists('compile_parse_is_expr'))
{
require_once(TEMPLATE_LITE_DIR . "internal/compile.parse_is_expr.php");
}
return compile_parse_is_expr($is_arg, $_arg, $this);
}
function _compile_config($variable)
{
if (!function_exists('compile_compile_config'))
{
require_once(TEMPLATE_LITE_DIR . "internal/compile.compile_config.php");
}
return compile_compile_config($variable, $this);
}
function _dequote($string)
{
if (($string{0} == "'" || $string{0} == '"') && $string{strlen($string)-1} == $string{0})
{
return substr($string, 1, -1);
}
else
{
return $string;
}
}
function _parse_arguments($arguments)
{
$_match = array();
$_result = array();
$_variables = array();
preg_match_all('/(?:' . $this->_qstr_regexp . ' | (?>[^"\'=\s]+))+|[=]/x', $arguments, $_match);
/*
Parse state:
0 - expecting attribute name
1 - expecting '='
2 - expecting attribute value (not '=')
*/
$state = 0;
foreach($_match[0] as $value)
{
switch($state) {
case 0:
// valid attribute name
if (is_string($value))
{
$a_name = $value;
$state = 1;
}
else
{
$this->trigger_error("invalid attribute name: '$token'", E_USER_ERROR, __FILE__, __LINE__);
}
break;
case 1:
if ($value == '=')
{
$state = 2;
}
else
{
$this->trigger_error("expecting '=' after '$last_value'", E_USER_ERROR, __FILE__, __LINE__);
}
break;
case 2:
if ($value != '=')
{
if ($value == 'yes' || $value == 'on' || $value == 'true')
{
$value = true;
}
elseif ($value == 'no' || $value == 'off' || $value == 'false')
{
$value = false;
}
elseif ($value == 'null')
{
$value = null;
}
if(!preg_match_all('/(?:(' . $this->_var_regexp . '|' . $this->_svar_regexp . ')(' . $this->_mod_regexp . '*))(?:\s+(.*))?/xs', $value, $_variables))
{
$_result[$a_name] = $value;
}
else
{
$_result[$a_name] = $this->_parse_variables($_variables[1], $_variables[2]);
}
$state = 0;
}
else
{
$this->trigger_error("'=' cannot be an attribute value", E_USER_ERROR, __FILE__, __LINE__);
}
break;
}
$last_value = $value;
}
if($state != 0)
{
if($state == 1)
{
$this->trigger_error("expecting '=' after attribute name '$last_value'", E_USER_ERROR, __FILE__, __LINE__);
}
else
{
$this->trigger_error("missing attribute value", E_USER_ERROR, __FILE__, __LINE__);
}
}
return $_result;
}
function _parse_variables($variables, $modifiers)
{
$_result = "";
foreach($variables as $key => $value)
{
$tag_variable = trim($variables[$key]);
if(!empty($this->default_modifiers) && !preg_match('!(^|\|)templatelite:nodefaults($|\|)!',$modifiers[$key]))
{
$_default_mod_string = implode('|',(array)$this->default_modifiers);
$modifiers[$key] = empty($modifiers[$key]) ? $_default_mod_string : $_default_mod_string . '|' . $modifiers[$key];
}
if (empty($modifiers[$key]))
{
$_result .= $this->_parse_variable($tag_variable).'.';
}
else
{
$_result .= $this->_parse_modifier($this->_parse_variable($tag_variable), $modifiers[$key]).'.';
}
}
return substr($_result, 0, -1);
}
function _parse_variable($variable)
{
// replace variable with value
if ($variable{0} == "\$")
{
// replace the variable
return $this->_compile_variable($variable);
}
elseif ($variable{0} == '#')
{
// replace the config variable
return $this->_compile_config($variable);
}
elseif ($variable{0} == '"')
{
// expand the quotes to pull any variables out of it
// fortunately variables inside of a quote aren't fancy, no modifiers, no quotes
// just get everything from the $ to the ending space and parse it
// if the $ is escaped, then we won't expand it
$_result = "";
preg_match_all('/(?:[^\\\]' . $this->_dvar_regexp . ')/', substr($variable, 1, -1), $_expand); // old match
// preg_match_all('/(?:[^\\\]' . $this->_dvar_regexp . '[^\\\])/', $variable, $_expand);
$_expand = array_unique($_expand[0]);
foreach($_expand as $key => $value)
{
$_expand[$key] = trim($value);
if (strpos($_expand[$key], '$') > 0)
{
$_expand[$key] = substr($_expand[$key], strpos($_expand[$key], '$'));
}
}
$_result = $variable;
foreach($_expand as $value)
{
$value = trim($value);
$_result = str_replace($value, '" . ' . $this->_parse_variable($value) . ' . "', $_result);
}
$_result = str_replace("`", "", $_result);
return $_result;
}
elseif ($variable{0} == "'")
{
// return the value just as it is
return $variable;
}
elseif ($variable{0} == "%")
{
return $this->_parse_section_prop($variable);
}
else
{
// return it as is; i believe that there was a reason before that i did not just return it as is,
// but i forgot what that reason is ...
// the reason i return the variable 'as is' right now is so that unquoted literals are allowed
return $variable;
}
}
function _parse_section_prop($section_prop_expr)
{
$parts = explode('|', $section_prop_expr, 2);
$var_ref = $parts[0];
$modifiers = isset($parts[1]) ? $parts[1] : '';
preg_match('!%(\w+)\.(\w+)%!', $var_ref, $match);
$section_name = $match[1];
$prop_name = $match[2];
$output = "\$this->_sections['$section_name']['$prop_name']";
$this->_parse_modifier($output, $modifiers);
return $output;
}
function _compile_variable($variable)
{
$_result = "";
// remove the $
$variable = substr($variable, 1);
// get [foo] and .foo and (...) pieces
preg_match_all('!(?:^\w+)|(?:' . $this->_var_bracket_regexp . ')|\.\$?\w+|\S+!', $variable, $_match);
$variable = $_match[0];
$var_name = array_shift($variable);
if ($var_name == $this->reserved_template_varname)
{
if ($variable[0]{0} == '[' || $variable[0]{0} == '.')
{
$find = array("[", "]", ".");
switch(strtoupper(str_replace($find, "", $variable[0])))
{
case 'GET':
$_result = "\$_GET";
break;
case 'POST':
$_result = "\$_POST";
break;
case 'COOKIE':
$_result = "\$_COOKIE";
break;
case 'ENV':
$_result = "\$_ENV";
break;
case 'SERVER':
$_result = "\$_SERVER";
break;
case 'SESSION':
$_result = "\$_SESSION";
break;
case 'NOW':
$_result = "time()";
break;
case 'SECTION':
$_result = "\$this->_sections";
break;
case 'LDELIM':
$_result = "\$this->left_delimiter";
break;
case 'RDELIM':
$_result = "\$this->right_delimiter";
break;
case 'VERSION':
$_result = "\$this->_version";
break;
case 'CONFIG':
$_result = "\$this->_confs";
break;
case 'TEMPLATE':
$_result = "\$this->_file";
break;
case 'CONST':
$constant = str_replace($find, "", $_match[0][2]);
$_result = "constant('$constant')";
$variable = array();
break;
default:
$_var_name = str_replace($find, "", $variable[0]);
$_result = "\$this->_templatelite_vars['$_var_name']";
break;
}
array_shift($variable);
}
else
{
$this->trigger_error('$' . $var_name.implode('', $variable) . ' is an invalid $templatelite reference', E_USER_ERROR, __FILE__, __LINE__);
}
}
else
{
$_result = "\$this->_vars['$var_name']";
}
foreach ($variable as $var)
{
if ($var{0} == '[')
{
$var = substr($var, 1, -1);
if (is_numeric($var))
{
$_result .= "[$var]";
}
elseif ($var{0} == '$')
{
$_result .= "[" . $this->_compile_variable($var) . "]";
}
elseif ($var{0} == '#')
{
$_result .= "[" . $this->_compile_config($var) . "]";
}
else
{
// $_result .= "['$var']";
$parts = explode('.', $var);
$section = $parts[0];
$section_prop = isset($parts[1]) ? $parts[1] : 'index';
$_result .= "[\$this->_sections['$section']['$section_prop']]";
}
}
else if ($var{0} == '.')
{
if ($var{1} == '$')
{
$_result .= "[\$this->_TPL['" . substr($var, 2) . "']]";
}
else
{
$_result .= "['" . substr($var, 1) . "']";
}
}
else if (substr($var,0,2) == '->')
{
if(substr($var,2,2) == '__')
{
$this->trigger_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__);
}
else if (substr($var, 2, 1) == '$')
{
$_output .= '->{(($var=$this->_TPL[\''.substr($var,3).'\']) && substr($var,0,2)!=\'__\') ? $_var : $this->trigger_error("cannot access property \\"$var\\"")}';
}
}
else
{
$this->trigger_error('$' . $var_name.implode('', $variable) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
}
}
return $_result;
}
function _parse_modifier($variable, $modifiers)
{
$_match = array();
$_mods = array(); // stores all modifiers
$_args = array(); // modifier arguments
preg_match_all('!\|(@?\w+)((?>:(?:'. $this->_qstr_regexp . '|[^|]+))*)!', '|' . $modifiers, $_match);
list(, $_mods, $_args) = $_match;
$count_mods = count($_mods);
for ($i = 0, $for_max = $count_mods; $i < $for_max; $i++)
{
preg_match_all('!:(' . $this->_qstr_regexp . '|[^:]+)!', $_args[$i], $_match);
$_arg = $_match[1];
if ($_mods[$i]{0} == '@')
{
$_mods[$i] = substr($_mods[$i], 1);
$_map_array = 0;
} else {
$_map_array = 1;
}
foreach($_arg as $key => $value)
{
$_arg[$key] = $this->_parse_variable($value);
}
if ($this->_plugin_exists($_mods[$i], "modifier") || function_exists($_mods[$i]))
{
if (count($_arg) > 0)
{
$_arg = ', '.implode(', ', $_arg);
}
else
{
$_arg = '';
}
$php_function = "PHP";
if ($this->_plugin_exists($_mods[$i], "modifier"))
{
$php_function = "plugin";
}
$variable = "\$this->_run_modifier($variable, '$_mods[$i]', '$php_function', $_map_array$_arg)";
}
else
{
$variable = "\$this->trigger_error(\"'" . $_mods[$i] . "' modifier does not exist\", E_USER_NOTICE, __FILE__, __LINE__);";
}
}
return $variable;
}
function _plugin_exists($function, $type)
{
// check for object functions
if (isset($this->_plugins[$type][$function]) && is_array($this->_plugins[$type][$function]) && is_object($this->_plugins[$type][$function][0]) && method_exists($this->_plugins[$type][$function][0], $this->_plugins[$type][$function][1]))
{
return '$this->_plugins[\'' . $type . '\'][\'' . $function . '\'][0]->' . $this->_plugins[$type][$function][1];
}
// check for standard functions
if (isset($this->_plugins[$type][$function]) && function_exists($this->_plugins[$type][$function]))
{
return $this->_plugins[$type][$function];
}
// check for a plugin in the plugin directory
if (file_exists($this->_get_plugin_dir($type . '.' . $function . '.php') . $type . '.' . $function . '.php'))
{
require_once($this->_get_plugin_dir($type . '.' . $function . '.php') . $type . '.' . $function . '.php');
if (function_exists('tpl_' . $type . '_' . $function))
{
$this->_require_stack[$type . '.' . $function . '.php'] = array($type, $function, 'tpl_' . $type . '_' . $function);
return ('tpl_' . $type . '_' . $function);
}
}
return false;
}
function _load_filters()
{
if (count($this->_plugins['prefilter']) > 0)
{
foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter)
{
if (!function_exists($prefilter))
{
@include_once( $this->_get_plugin_dir("prefilter." . $filter_name . ".php") . "prefilter." . $filter_name . ".php");
}
}
}
if (count($this->_plugins['postfilter']) > 0)
{
foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter)
{
if (!function_exists($postfilter))
{
@include_once( $this->_get_plugin_dir("postfilter." . $filter_name . ".php") . "postfilter." . $filter_name . ".php");
}
}
}
}
}
?>

View File

@@ -0,0 +1,165 @@
<?php
/*
* Project: template_lite, a smarter template engine
* File: class.config.php
* Author: Paul Lockaby <paul@paullockaby.com>, Mark Dickenson <akapanamajack@sourceforge.net>
* Copyright: 2003,2004,2005 by Paul Lockaby, 2005,2006 Mark Dickenson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* The latest version of template_lite can be obtained from:
* http://templatelite.sourceforge.net
*
*/
class config {
var $overwrite = false; // overwrite variables of the same name? if false, an array will be created
var $booleanize = true; // turn true/false, yes/no, on/off, into 1/0
var $fix_new_lines = true; // turns \r\n into \n?
var $read_hidden = true; // read hidden sections?
var $_db_qstr_regexp = null;
var $_bool_true_regexp = null;
var $_bool_false_regexp = null;
var $_qstr_regexp = null;
function config()
{
$this->_db_qstr_regexp = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"';
$this->_bool_true_regexp = 'true|yes|on';
$this->_bool_false_regexp = 'false|no|off';
$this->_qstr_regexp = '(?:' . $this->_db_qstr_regexp . '|' . $this->_bool_true_regexp . '|' . $this->_bool_false_regexp . ')';
}
function config_load($file, $section_name = null, $var_name = null)
{
$_result = array();
$contents = file_get_contents($file);
if (empty($contents))
{
die("Could not open $file");
}
// insert new line into beginning of file
$contents = "\n" . $contents;
// fix new-lines
if ($this->fix_new_lines)
{
$contents = str_replace("\r\n","\n",$contents);
}
// match globals
if (preg_match("/^(.*?)(\n\[|\Z)/s", $contents, $match))
{
$_result["globals"] = $this->_parse_config_section($match[1]);
}
// match sections
if (preg_match_all("/^\[(.*?)\]/m", $contents, $match))
{
foreach ($match[1] as $section)
{
if ($section{0} == '.' && !$this->read_hidden)
{
continue;
}
preg_match("/\[".preg_quote($section)."\](.*?)(\n\[|\Z)/s",$contents,$match);
if ($section{0} == '.')
{
$section = substr($section, 1);
}
$_result[$section] = $this->_parse_config_section($match[1]);
}
}
if (!empty($var_name))
{
if (empty($section_name))
{
return $_result["globals"][$var_name];
}
else
{
if(isset($_result[$section_name][$var_name]))
{
return $_result[$section_name][$var_name];
}
else
{
return array();
}
}
}
else
{
if (empty($section_name))
{
return $_result;
}
else
{
if(isset($_result[$section_name]))
{
return $_result[$section_name];
}
else
{
return array();
}
}
}
}
function _parse_config_section($body)
{
$_result = array();
preg_match_all('!(\n\s*[a-zA-Z0-9_]+)\s*=\s*(' . $this->_qstr_regexp . ')!s', $body, $ini);
$keys = $ini[1];
$values = $ini[2];
for($i = 0, $for_max = count($ini[0]); $i < $for_max; $i++)
{
if ($this->booleanize)
{
if (preg_match('/^(' . $this->_bool_true_regexp . ')$/i', $values[$i]))
{
$values[$i] = true;
}
elseif (preg_match('/^(' . $this->_bool_false_regexp . ')$/i', $values[$i]))
{
$values[$i] = false;
}
}
if (!is_numeric($values[$i]) && !is_bool($values[$i]))
{
$values[$i] = str_replace("\n",'',stripslashes(substr($values[$i], 1, -1)));
}
if ($this->overwrite || !isset($_result[trim($keys[$i])]))
{
$_result[trim($keys[$i])] = $values[$i];
}
else
{
if (!is_array($_result[trim($keys[$i])]))
{
$_result[trim($keys[$i])] = array($_result[trim($keys[$i])]);
}
$_result[trim($keys[$i])][] = $values[$i];
}
}
return $_result;
}
}
?>

View File

@@ -0,0 +1,926 @@
<?php
/*
* Project: template_lite, a smarter template engine
* File: class.template.php
* Author: Paul Lockaby <paul@paullockaby.com>, Mark Dickenson <akapanamajack@sourceforge.net>
* Copyright: 2003,2004,2005 by Paul Lockaby, 2005,2006 Mark Dickenson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* The latest version of template_lite can be obtained from:
* http://templatelite.sourceforge.net
*
*/
if (!defined('TEMPLATE_LITE_DIR')) {
define('TEMPLATE_LITE_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
}
class Template_Lite {
// public configuration variables
var $left_delimiter = "{"; // the left delimiter for template tags
var $right_delimiter = "}"; // the right delimiter for template tags
var $cache = false; // whether or not to allow caching of files
var $force_compile = false; // force a compile regardless of saved state
var $template_dir = "templates"; // where the templates are to be found
var $plugins_dir = array("plugins"); // where the plugins are to be found
var $compile_dir = "compiled"; // the directory to store the compiled files in
var $config_dir = "templates"; // where the config files are
var $cache_dir = "cached"; // where cache files are stored
var $config_overwrite = false;
var $config_booleanize = true;
var $config_fix_new_lines = true;
var $config_read_hidden = true;
var $cache_lifetime = 0; // how long the file in cache should be considered "fresh"
var $encode_file_name = true; // Set this to false if you do not want the name of the compiled/cached file to be md5 encoded.
var $php_extract_vars = false; // Set this to true if you want the $this->_tpl variables to be extracted for use by PHP code inside the template.
var $reserved_template_varname = "templatelite";
var $default_modifiers = array();
var $debugging = false;
var $compiler_file = 'class.compiler.php';
var $compiler_class = 'Template_Lite_Compiler';
var $config_class = 'config';
// gzip output configuration
var $send_now = 1;
var $force_compression = 0;
var $compression_level = 9;
var $enable_gzip = 1;
// private internal variables
var $_vars = array(); // stores all internal assigned variables
var $_confs = array(); // stores all internal config variables
var $_plugins = array( 'modifier' => array(),
'function' => array(),
'block' => array(),
'compiler' => array(),
'resource' => array(),
'prefilter' => array(),
'postfilter' => array(),
'outputfilter' => array());
var $_linenum = 0; // the current line number in the file we are processing
var $_file = ""; // the current file we are processing
var $_config_obj = null;
var $_compile_obj = null;
var $_cache_id = null;
var $_cache_dir = ""; // stores where this specific file is going to be cached
var $_cache_info = array('config' => array(), 'template' => array());
var $_sl_md5 = '39fc70570b8b60cbc1b85839bf242aff';
var $_version = 'V2.10 Template Lite 4 January 2007 (c) 2005-2007 Mark Dickenson. All rights reserved. Released LGPL.';
var $_version_date = "2007-01-04 10:34:21";
var $_config_module_loaded = false;
var $_templatelite_debug_info = array();
var $_templatelite_debug_loop = false;
var $_templatelite_debug_dir = "";
var $_inclusion_depth = 0;
var $_null = null;
var $_resource_type = 1;
var $_resource_time;
var $_sections = array();
var $_foreach = array();
function Template_Lite()
{
$this->_version_date = strtotime($this->_version_date);
}
function load_filter($type, $name)
{
switch ($type)
{
case 'output':
include_once( $this->_get_plugin_dir($type . "filter." . $name . ".php") . $type . "filter." . $name . ".php");
$this->_plugins['outputfilter'][$name] = "template_" . $type . "filter_" . $name;
break;
case 'pre':
case 'post':
if (!isset($this->_plugins[$type . 'filter'][$name]))
{
$this->_plugins[$type . 'filter'][$name] = "template_" . $type . "filter_" . $name;
}
break;
}
}
function assign($key, $value = null)
{
if (is_array($key))
{
foreach($key as $var => $val)
if ($var != "")
{
$this->_vars[$var] = $val;
}
}
else
{
if ($key != "")
{
$this->_vars[$key] = $value;
}
}
}
function assign_by_ref($key, $value = null)
{
if ($key != '')
{
$this->_vars[$key] = &$value;
}
}
function assign_config($key, $value = null)
{
if (is_array($key))
{
foreach($key as $var => $val)
{
if ($var != "")
{
$this->_confs[$var] = $val;
}
}
}
else
{
if ($key != "")
{
$this->_confs[$key] = $value;
}
}
}
function append($key, $value=null, $merge=false)
{
if (is_array($key))
{
foreach ($key as $_key => $_value)
{
if ($_key != '')
{
if(!@is_array($this->_vars[$_key]))
{
settype($this->_vars[$_key],'array');
}
if($merge && is_array($_value))
{
foreach($_value as $_mergekey => $_mergevalue)
{
$this->_vars[$_key][$_mergekey] = $_mergevalue;
}
}
else
{
$this->_vars[$_key][] = $_value;
}
}
}
}
else
{
if ($key != '' && isset($value))
{
if(!@is_array($this->_vars[$key]))
{
settype($this->_vars[$key],'array');
}
if($merge && is_array($value))
{
foreach($value as $_mergekey => $_mergevalue)
{
$this->_vars[$key][$_mergekey] = $_mergevalue;
}
}
else
{
$this->_vars[$key][] = $value;
}
}
}
}
function append_by_ref($key, &$value, $merge=false)
{
if ($key != '' && isset($value))
{
if(!@is_array($this->_vars[$key]))
{
settype($this->_vars[$key],'array');
}
if ($merge && is_array($value))
{
foreach($value as $_key => $_val)
{
$this->_vars[$key][$_key] = &$value[$_key];
}
}
else
{
$this->_vars[$key][] = &$value;
}
}
}
function clear_assign($key = null)
{
if ($key == null)
{
$this->_vars = array();
}
else
{
if (is_array($key))
{
foreach($key as $index => $value)
{
if (in_array($value, $this->_vars))
{
unset($this->_vars[$index]);
}
}
}
else
{
if (in_array($key, $this->_vars))
{
unset($this->_vars[$index]);
}
}
}
}
function clear_all_assign()
{
$this->_vars = array();
}
function clear_config($key = null)
{
if ($key == null)
{
$this->_conf = array();
}
else
{
if (is_array($key))
{
foreach($key as $index => $value)
{
if (in_array($value, $this->_conf))
{
unset($this->_conf[$index]);
}
}
}
else
{
if (in_array($key, $this->_conf))
{
unset($this->_conf[$key]);
}
}
}
}
function &get_template_vars($key = null)
{
if ($key == null)
{
return $this->_vars;
}
else
{
if (isset($this->_vars[$key]))
{
return $this->_vars[$key];
}
else
{
return $this->_null;
}
}
}
function &get_config_vars($key = null)
{
if ($key == null)
{
return $this->_confs;
}
else
{
if (isset($this->_confs[$key]))
{
return $this->_confs[$key];
}
else
{
return $this->_null;
}
}
}
function clear_compiled_tpl($file = null)
{
$this->_destroy_dir($file, null, $this->_get_dir($this->compile_dir));
}
function clear_cache($file = null, $cache_id = null, $compile_id = null, $exp_time = null)
{
if (!$this->cache)
{
return;
}
$this->_destroy_dir($file, $cache_id, $this->_get_dir($this->cache_dir));
}
function clear_all_cache($exp_time = null)
{
$this->clear_cache();
}
function is_cached($file, $cache_id = null)
{
if (!$this->force_compile && $this->cache && $this->_is_cached($file, $cache_id))
{
return true;
}
else
{
return false;
}
}
function register_modifier($modifier, $implementation)
{
$this->_plugins['modifier'][$modifier] = $implementation;
}
function unregister_modifier($modifier)
{
unset($this->_plugins['modifier'][$modifier]);
}
function register_function($function, $implementation)
{
$this->_plugins['function'][$function] = $implementation;
}
function unregister_function($function)
{
unset($this->_plugins['function'][$function]);
}
function register_block($function, $implementation)
{
$this->_plugins['block'][$function] = $implementation;
}
function unregister_block($function)
{
unset($this->_plugins['block'][$function]);
}
function register_compiler($function, $implementation)
{
$this->_plugins['compiler'][$function] = $implementation;
}
function unregister_compiler($function)
{
unset($this->_plugins['compiler'][$function]);
}
function register_prefilter($function)
{
$_name = (is_array($function)) ? $function[1] : $function;
$this->_plugins['prefilter'][$_name] = $_name;
}
function unregister_prefilter($function)
{
unset($this->_plugins['prefilter'][$function]);
}
function register_postfilter($function)
{
$_name = (is_array($function)) ? $function[1] : $function;
$this->_plugins['postfilter'][$_name] = $_name;
}
function unregister_postfilter($function)
{
unset($this->_plugins['postfilter'][$function]);
}
function register_outputfilter($function)
{
$_name = (is_array($function)) ? $function[1] : $function;
$this->_plugins['outputfilter'][$_name] = $_name;
}
function unregister_outputfilter($function)
{
unset($this->_plugins['outputfilter'][$function]);
}
function register_resource($type, $functions)
{
if (count($functions) == 4)
{
$this->_plugins['resource'][$type] = $functions;
}
else
{
$this->trigger_error("malformed function-list for '$type' in register_resource");
}
}
function unregister_resource($type)
{
unset($this->_plugins['resource'][$type]);
}
function template_exists($file)
{
if (file_exists($this->_get_dir($this->template_dir).$file))
{
$this->_resource_time = filemtime($this->_get_dir($this->template_dir).$file);
$this->_resource_type = 1;
return true;
}
else
{
if (file_exists($file))
{
$this->_resource_time = filemtime($file);
$this->_resource_type = "file";
return true;
}
return false;
}
}
function _get_resource($file)
{
$_resource_name = explode(':', trim($file));
if (count($_resource_name) == 1 || $_resource_name[0] == "file")
{
if($_resource_name[0] == "file")
{
$file = substr($file, 5);
}
$exists = $this->template_exists($file);
if (!$exists)
{
$this->trigger_error("file '$file' does not exist", E_USER_ERROR);
}
}
else
{
$this->_resource_type = $_resource_name[0];
$file = substr($file, strlen($this->_resource_type) + 1);
$exists = isset($this->_plugins['resource'][$this->_resource_type]) && call_user_func_array($this->_plugins['resource'][$this->_resource_type][1], array($file, &$resource_timestamp, &$this));
if (!$exists)
{
$this->trigger_error("file '$file' does not exist", E_USER_ERROR);
}
$this->_resource_time = $resource_timestamp;
}
return $file;
}
function display($file, $cache_id = null)
{
$this->fetch($file, $cache_id, true);
}
function fetch($file, $cache_id = null, $display = false)
{
$file = $this->_get_resource($file);
if ($this->debugging)
{
$this->_templatelite_debug_info[] = array('type' => 'template',
'filename' => $file,
'depth' => 0,
'exec_time' => array_sum(explode(' ', microtime())) );
$included_tpls_idx = count($this->_templatelite_debug_info) - 1;
}
$this->_cache_id = $cache_id;
$this->template_dir = $this->_get_dir($this->template_dir);
$this->compile_dir = $this->_get_dir($this->compile_dir);
if ($this->cache)
{
$this->_cache_dir = $this->_build_dir($this->cache_dir, $this->_cache_id);
}
$name = ($this->encode_file_name) ? md5((($this->_resource_type == 1) ? $this->template_dir.$file : $this->_resource_type . "_" . $file)).'.php' : str_replace(".", "_", str_replace("/", "_", $this->_resource_type . "_" . $file)).'.php';
$this->_error_level = $this->debugging ? error_reporting() : error_reporting(error_reporting() & ~E_NOTICE);
// $this->_error_level = error_reporting(E_ALL);
if (!$this->force_compile && $this->cache && $this->_is_cached($file, $cache_id))
{
ob_start();
include($this->_cache_dir.$name);
$output = ob_get_contents();
ob_end_clean();
$output = substr($output, strpos($output, "\n") + 1);
}
else
{
$output = $this->_fetch_compile($file, $cache_id);
if ($this->cache)
{
$f = fopen($this->_cache_dir.$name, "w");
fwrite($f, serialize($this->_cache_info) . "\n$output");
fclose($f);
}
}
if (strpos($output, $this->_sl_md5) !== false)
{
preg_match_all('!' . $this->_sl_md5 . '{_run_insert (.*)}' . $this->_sl_md5 . '!U',$output,$_match);
foreach($_match[1] as $value)
{
$arguments = unserialize($value);
$output = str_replace($this->_sl_md5 . '{_run_insert ' . $value . '}' . $this->_sl_md5, call_user_func_array('insert_' . $arguments['name'], array((array)$arguments, $this)), $output);
}
}
foreach ($this->_plugins['outputfilter'] as $function)
{
$output = $function($output, $this);
}
error_reporting($this->_error_level);
if ($this->debugging)
{
$this->_templatelite_debug_info[$included_tpls_idx]['exec_time'] = array_sum(explode(' ', microtime())) - $this->_templatelite_debug_info[$included_tpls_idx]['exec_time'];
}
if ($display)
{
echo $output;
if($this->debugging && !$this->_templatelite_debug_loop)
{
$this->debugging = false;
if(!function_exists("template_generate_debug_output"))
{
require_once(TEMPLATE_LITE_DIR . "internal/template.generate_debug_output.php");
}
$debug_output = template_generate_debug_output($this);
$this->debugging = true;
echo $debug_output;
}
}
else
{
return $output;
}
}
function config_load($file, $section_name = null, $var_name = null)
{
require_once(TEMPLATE_LITE_DIR . "internal/template.config_loader.php");
}
function _is_cached($file, $cache_id)
{
$this->_cache_dir = $this->_get_dir($this->cache_dir, $cache_id);
$this->config_dir = $this->_get_dir($this->config_dir);
$this->template_dir = $this->_get_dir($this->template_dir);
$file = $this->_get_resource($file);
$name = ($this->encode_file_name) ? md5((($this->_resource_type == 1) ? $this->template_dir.$file : $this->_resource_type . "_" . $file)).'.php' : str_replace(".", "_", str_replace("/", "_", $this->_resource_type . "_" . $file)).'.php';
if (file_exists($this->_cache_dir.$name) && (((time() - filemtime($this->_cache_dir.$name)) < $this->cache_lifetime) || $this->cache_lifetime == -1) && (filemtime($this->_cache_dir.$name) > $this->_resource_time))
{
$fh = fopen($this->_cache_dir.$name, "r");
if (!feof($fh) && ($line = fgets($fh, filesize($this->_cache_dir.$name))))
{
$includes = unserialize($line);
if (isset($includes['template']))
{
foreach($includes['template'] as $value)
{
if (!(file_exists($this->template_dir.$value) && (filemtime($this->_cache_dir.$name) > filemtime($this->template_dir.$value))))
{
return false;
}
}
}
if (isset($includes['config']))
{
foreach($includes['config'] as $value)
{
if (!(file_exists($this->config_dir.$value) && (filemtime($this->_cache_dir.$name) > filemtime($this->config_dir.$value))))
{
return false;
}
}
}
}
fclose($fh);
}
else
{
return false;
}
return true;
}
function _fetch_compile_include($_templatelite_include_file, $_templatelite_include_vars)
{
if(!function_exists("template_fetch_compile_include"))
{
require_once(TEMPLATE_LITE_DIR . "internal/template.fetch_compile_include.php");
}
return template_fetch_compile_include($_templatelite_include_file, $_templatelite_include_vars, $this);
}
function _fetch_compile($file)
{
$this->template_dir = $this->_get_dir($this->template_dir);
$name = ($this->encode_file_name) ? md5((($this->_resource_type == 1) ? $this->template_dir.$file : $this->_resource_type . "_" . $file)).'.php' : str_replace(".", "_", str_replace("/", "_", $this->_resource_type . "_" . $file)).'.php';
if ($this->cache)
{
array_push($this->_cache_info['template'], $file);
}
if (!$this->force_compile && file_exists($this->compile_dir.'c_'.$name)
&& (filemtime($this->compile_dir.'c_'.$name) > $this->_resource_time)
&& (filemtime($this->compile_dir.'c_'.$name) > $this->_version_date))
{
ob_start();
include($this->compile_dir.'c_'.$name);
$output = ob_get_contents();
ob_end_clean();
error_reporting($this->_error_level);
return $output;
}
$file_contents = "";
if($this->_resource_type == 1)
{
$f = fopen($this->template_dir . $file, "r");
$size = filesize($this->template_dir . $file);
if ($size > 0)
{
$file_contents = fread($f, $size);
}
}
else
if($this->_resource_type == "file")
{
$f = fopen($file, "r");
$size = filesize($file);
if ($size > 0)
{
$file_contents = fread($f, $size);
}
}
else
{
call_user_func_array($this->_plugins['resource'][$this->_resource_type][0], array($file, &$file_contents, &$this));
}
$this->_file = $file;
fclose($f);
if (!is_object($this->_compile_obj))
{
if (file_exists(TEMPLATE_LITE_DIR . $this->compiler_file)) {
require_once(TEMPLATE_LITE_DIR . $this->compiler_file);
} else {
require_once($this->compiler_file);
}
$this->_compile_obj = new $this->compiler_class;
}
$this->_compile_obj->left_delimiter = $this->left_delimiter;
$this->_compile_obj->right_delimiter = $this->right_delimiter;
$this->_compile_obj->plugins_dir = &$this->plugins_dir;
$this->_compile_obj->template_dir = &$this->template_dir;
$this->_compile_obj->_vars = &$this->_vars;
$this->_compile_obj->_confs = &$this->_confs;
$this->_compile_obj->_plugins = &$this->_plugins;
$this->_compile_obj->_linenum = &$this->_linenum;
$this->_compile_obj->_file = &$this->_file;
$this->_compile_obj->php_extract_vars = &$this->php_extract_vars;
$this->_compile_obj->reserved_template_varname = &$this->reserved_template_varname;
$this->_compile_obj->default_modifiers = $this->default_modifiers;
$output = $this->_compile_obj->_compile_file($file_contents);
$f = fopen($this->compile_dir.'c_'.$name, "w");
fwrite($f, $output);
fclose($f);
ob_start();
eval(' ?>' . $output . '<?php ');
$output = ob_get_contents();
ob_end_clean();
return $output;
}
function _run_modifier()
{
$arguments = func_get_args();
list($variable, $modifier, $php_function, $_map_array) = array_splice($arguments, 0, 4);
array_unshift($arguments, $variable);
if ($_map_array && is_array($variable))
{
foreach($variable as $key => $value)
{
if($php_function == "PHP")
{
$variable[$key] = call_user_func_array($modifier, $arguments);
}
else
{
$variable[$key] = call_user_func_array($this->_plugins["modifier"][$modifier], $arguments);
}
}
}
else
{
if($php_function == "PHP")
{
$variable = call_user_func_array($modifier, $arguments);
}
else
{
$variable = call_user_func_array($this->_plugins["modifier"][$modifier], $arguments);
}
}
return $variable;
}
function _run_insert($arguments)
{
if ($this->cache)
{
return $this->_sl_md5 . '{_run_insert ' . serialize((array)$arguments) . '}' . $this->_sl_md5;
}
else
{
if (!function_exists('insert_' . $arguments['name']))
{
$this->trigger_error("function 'insert_" . $arguments['name'] . "' does not exist in 'insert'", E_USER_ERROR);
}
if (isset($arguments['assign']))
{
$this->assign($arguments['assign'], call_user_func_array('insert_' . $arguments['name'], array((array)$arguments, $this)));
}
else
{
return call_user_func_array('insert_' . $arguments['name'], array((array)$arguments, $this));
}
}
}
function _get_dir($dir, $id = null)
{
if (empty($dir))
{
$dir = '.';
}
if (substr($dir, -1) != DIRECTORY_SEPARATOR)
{
$dir .= DIRECTORY_SEPARATOR;
}
if (!empty($id))
{
$_args = explode('|', $id);
if (count($_args) == 1 && empty($_args[0]))
{
return $dir;
}
foreach($_args as $value)
{
$dir .= $value.DIRECTORY_SEPARATOR;
}
}
return $dir;
}
function _get_plugin_dir($plugin_name)
{
static $_path_array = null;
$plugin_dir_path = "";
$_plugin_dir_list = is_array($this->plugins_dir) ? $this->plugins_dir : (array)$this->plugins_dir;
foreach ($_plugin_dir_list as $_plugin_dir)
{
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir))
{
// path is relative
if (file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . $_plugin_dir . DIRECTORY_SEPARATOR . $plugin_name))
{
$plugin_dir_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . $_plugin_dir . DIRECTORY_SEPARATOR;
break;
}
}
else
{
// path is absolute
if(!isset($_path_array))
{
$_ini_include_path = ini_get('include_path');
if(strstr($_ini_include_path,';'))
{
// windows pathnames
$_path_array = explode(';',$_ini_include_path);
}
else
{
$_path_array = explode(':',$_ini_include_path);
}
}
if(!in_array($_plugin_dir,$_path_array))
{
array_unshift($_path_array,$_plugin_dir);
}
foreach ($_path_array as $_include_path)
{
if (file_exists($_include_path . DIRECTORY_SEPARATOR . $plugin_name))
{
$plugin_dir_path = $_include_path . DIRECTORY_SEPARATOR;
break 2;
}
}
}
}
return $plugin_dir_path;
}
// function _parse_resource_link($resource_link)
// {
// $stuffing = "file:/this/is/the/time_5-23.tpl";
// $stuffing_data = explode(":", $stuffing);
// preg_match_all('/(?:([0-9a-z._-]+))/i', $stuffing, $stuff);
// print_r($stuff);
// echo "<br>Path: " . str_replace($stuff[0][count($stuff[0]) - 1], "", $stuffing);
// echo "<br>Filename: " . $stuff[0][count($stuff[0]) - 1];
// }
function _build_dir($dir, $id)
{
if(!function_exists("template_build_dir"))
{
require_once(TEMPLATE_LITE_DIR . "internal/template.build_dir.php");
}
return template_build_dir($dir, $id, $this);
}
function _destroy_dir($file, $id, $dir)
{
if(!function_exists("template_destroy_dir"))
{
require_once(TEMPLATE_LITE_DIR . "internal/template.destroy_dir.php");
}
return template_destroy_dir($file, $id, $dir, $this);
}
function trigger_error($error_msg, $error_type = E_USER_ERROR, $file = null, $line = null)
{
if(isset($file) && isset($line))
{
$info = ' ('.basename($file).", line $line)";
}
else
{
$info = null;
}
trigger_error('TPL: [in ' . $this->_file . ' line ' . $this->_linenum . "]: syntax error: $error_msg$info", $error_type);
}
}
?>

View File

@@ -0,0 +1,74 @@
<?php
/**
* Template Lite compile config variables - template internal module
*
* Type: template
* Name: compile_config
*/
function compile_compile_config($variable, &$object)
{
$_result = "";
// remove the beginning and ending #
$variable = substr($variable, 1, -1);
// get [foo] and .foo and (...) pieces
preg_match_all('!(?:^\w+)|(?:' . $object->_var_bracket_regexp . ')|\.\$?\w+|\S+!', $variable, $_match);
$variable = $_match[0];
$var_name = array_shift($variable);
$_result = "\$this->_confs['$var_name']";
foreach ($variable as $var)
{
if ($var{0} == '[')
{
$var = substr($var, 1, -1);
if (is_numeric($var))
{
$_result .= "[$var]";
}
elseif ($var{0} == '$')
{
$_result .= "[" . $object->_compile_variable($var) . "]";
}
elseif ($var{0} == '#')
{
$_result .= "[" . $object->_compile_config($var) . "]";
}
else
{
$_result .= "['$var']";
}
}
else if ($var{0} == '.')
{
if ($var{1} == '$')
{
$_result .= "[\$this->_TPL['" . substr($var, 2) . "']]";
}
else
{
$_result .= "['" . substr($var, 1) . "']";
}
}
else if (substr($var,0,2) == '->')
{
if(substr($var,2,2) == '__')
{
$object->trigger_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__);
}
else if (substr($var, 2, 1) == '$')
{
$_output .= '->{(($var=$this->_TPL[\''.substr($var,3).'\']) && substr($var,0,2)!=\'__\') ? $_var : $this->trigger_error("cannot access property \\"$var\\"")}';
}
}
else
{
$object->trigger_error('#' . $var_name.implode('', $variable) . '# is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
}
}
return $_result;
}
?>

View File

@@ -0,0 +1,60 @@
<?php
/**
* Template Lite compile custom block - template internal module
*
* Type: template
* Name: compile_custom_block
*/
function compile_compile_custom_block($function, $modifiers, $arguments, &$_result, &$object)
{
if ($function{0} == '/')
{
$start_tag = false;
$function = substr($function, 1);
}
else
{
$start_tag = true;
}
if ($function = $object->_plugin_exists($function, "block"))
{
if ($start_tag)
{
$_args = $object->_parse_arguments($arguments);
foreach($_args as $key => $value)
{
if (is_bool($value))
{
$value = $value ? 'true' : 'false';
}
if (is_null($value))
{
$value = 'null';
}
$_args[$key] = "'$key' => $value";
}
$_result = "<?php \$this->_tag_stack[] = array('$function', array(".implode(',', (array)$_args).")); ";
$_result .= $function . '(array(' . implode(',', (array)$_args) .'), null, $this); ';
$_result .= 'ob_start(); ?>';
}
else
{
$_result .= '<?php $this->_block_content = ob_get_contents(); ob_end_clean(); ';
$_result .= '$this->_block_content = ' . $function . '($this->_tag_stack[count($this->_tag_stack) - 1][1], $this->_block_content, $this); ';
if (!empty($modifiers))
{
$_result .= '$this->_block_content = ' . $object->_parse_modifier('$this->_block_content', $modifiers) . '; ';
}
$_result .= 'echo $this->_block_content; array_pop($this->_tag_stack); ?>';
}
return true;
}
else
{
return false;
}
}
?>

View File

@@ -0,0 +1,44 @@
<?php
/**
* Template Lite compile custom function - template internal module
*
* Type: template
* Name: compile_custom_function
*/
function compile_compile_custom_function($function, $modifiers, $arguments, &$_result, &$object)
{
if ($function = $object->_plugin_exists($function, "function"))
{
$_args = $object->_parse_arguments($arguments);
foreach($_args as $key => $value)
{
if (is_bool($value))
{
$value = $value ? 'true' : 'false';
}
if (is_null($value))
{
$value = 'null';
}
$_args[$key] = "'$key' => $value";
}
$_result = '<?php echo ';
if (!empty($modifiers))
{
$_result .= $object->_parse_modifier($function . '(array(' . implode(',', (array)$_args) . '), $this)', $modifiers) . '; ';
}
else
{
$_result .= $function . '(array(' . implode(',', (array)$_args) . '), $this);';
}
$_result .= '?>';
return true;
}
else
{
return false;
}
}
?>

View File

@@ -0,0 +1,154 @@
<?php
/**
* Template Lite compile IF tag - template internal module
*
* Type: template
* Name: compile_parse_is_expr
*/
function compile_compile_if($arguments, $elseif, $while, &$object)
{
$_result = "";
$_match = array();
$_args = array();
$_is_arg_stack = array();
// extract arguments from the equation
preg_match_all('/(?>(' . $object->_var_regexp . '|\/?' . $object->_svar_regexp . '|\/?' . $object->_func_regexp . ')(?:' . $object->_mod_regexp . '*)?|\-?0[xX][0-9a-fA-F]+|\-?\d+(?:\.\d+)?|\.\d+|!==|===|==|!=|<>|<<|>>|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\%|\+|\-|\/|\*|\@|\b\w+\b|\S+)/x', $arguments, $_match);
$_args = $_match[0];
// make sure we have balanced parenthesis
$_args_count = array_count_values($_args);
if(isset($_args_count['(']) && $_args_count['('] != $_args_count[')'])
{
$object->trigger_error("unbalanced parenthesis in if statement", E_USER_ERROR, __FILE__, __LINE__);
}
$count_args = count($_args);
for ($i = 0, $for_max = $count_args; $i < $for_max; $i++)
{
$_arg = &$_args[$i];
switch (strtolower($_arg))
{
case '!':
case '%':
case '!==':
case '==':
case '===':
case '>':
case '<':
case '!=':
case '<>':
case '<<':
case '>>':
case '<=':
case '>=':
case '&&':
case '||':
case '^':
case '&':
case '~':
case ')':
case ',':
case '+':
case '-':
case '*':
case '/':
case '@':
break;
case 'eq':
$_arg = '==';
break;
case 'ne':
case 'neq':
$_arg = '!=';
break;
case 'lt':
$_arg = '<';
break;
case 'le':
case 'lte':
$_arg = '<=';
break;
case 'gt':
$_arg = '>';
break;
case 'ge':
case 'gte':
$_arg = '>=';
break;
case 'and':
$_arg = '&&';
break;
case 'or':
$_arg = '||';
break;
case 'not':
$_arg = '!';
break;
case 'mod':
$_arg = '%';
break;
case '(':
array_push($_is_arg_stack, $i);
break;
case 'is':
if ($_args[$i-1] == ')')
{
$is_arg_start = array_pop($is_arg_stack);
}
else
{
$_is_arg_count = count($_args);
$is_arg = implode(' ', array_slice($_args, $is_arg_start, $i - $is_arg_start));
$_arg_tokens = $object->_parse_is_expr($is_arg, array_slice($_args, $i+1));
array_splice($_args, $is_arg_start, count($_args), $_arg_tokens);
$i = $_is_arg_count - count($_args);
}
break;
default:
preg_match('/(?:(' . $object->_var_regexp . '|' . $object->_svar_regexp . '|' . $object->_func_regexp . ')(' . $object->_mod_regexp . '*)(?:\s*[,\.]\s*)?)(?:\s+(.*))?/xs', $_arg, $_match);
if (isset($_match[0]{0}) && ($_match[0]{0} == '$' || ($_match[0]{0} == '#' && $_match[0]{strlen($_match[0]) - 1} == '#') || $_match[0]{0} == "'" || $_match[0]{0} == '"' || $_match[0]{0} == '%'))
{
// process a variable
$_arg = $object->_parse_variables(array($_match[1]), array($_match[2]));
}
elseif (is_numeric($_arg))
{
// pass the number through
}
elseif (function_exists($_match[0]) || $_match[0] == "empty" || $_match[0] == "isset" || $_match[0] == "unset" || strtolower($_match[0]) == "true" || strtolower($_match[0]) == "false" || strtolower($_match[0]) == "null")
{
// pass the function through
}
elseif (empty($_arg))
{
// pass the empty argument through
}
else
{
$object->trigger_error("unidentified token '$_arg'", E_USER_ERROR, __FILE__, __LINE__);
}
break;
}
}
if($while)
{
return implode(' ', $_args);
}
else
{
if ($elseif)
{
return '<?php elseif ('.implode(' ', $_args).'): ?>';
}
else
{
return '<?php if ('.implode(' ', $_args).'): ?>';
}
}
return $_result;
}
?>

View File

@@ -0,0 +1,35 @@
<?php
/**
* Template Lite generate_debug_output template internal module
*
* Type: template
* Name: generate_debug_output
*/
function generate_compiler_debug_output(&$object)
{
$debug_output = "\$assigned_vars = \$this->_vars;\n";
$debug_output .= "ksort(\$assigned_vars);\n";
$debug_output .= "if (@is_array(\$this->_config[0])) {\n";
$debug_output .= " \$config_vars = \$this->_config[0];\n";
$debug_output .= " ksort(\$config_vars);\n";
$debug_output .= " \$this->assign('_debug_config_keys', array_keys(\$config_vars));\n";
$debug_output .= " \$this->assign('_debug_config_vals', array_values(\$config_vars));\n";
$debug_output .= "} \n";
$debug_output .= "\$included_templates = \$this->_templatelite_debug_info;\n";
$debug_output .= "\$this->assign('_debug_keys', array_keys(\$assigned_vars));\n";
$debug_output .= "\$this->assign('_debug_vals', array_values(\$assigned_vars));\n";
$debug_output .= "\$this->assign('_debug_tpls', \$included_templates);\n";
$debug_output .= "\$this->_templatelite_debug_loop = true;\n";
$debug_output .= "\$this->_templatelite_debug_dir = \$this->template_dir;\n";
$debug_output .= "\$this->template_dir = TEMPLATE_LITE_DIR . 'internal/';\n";
$debug_output .= "echo \$this->_fetch_compile('debug.tpl');\n";
$debug_output .= "\$this->template_dir = \$this->_templatelite_debug_dir;\n";
$debug_output .= "\$this->_templatelite_debug_loop = false; \n";
return $debug_output;
}
?>

View File

@@ -0,0 +1,56 @@
<?php
/**
* Template Lite
*
* Type: compile
* Name: section_start
*/
function compile_include($arguments, &$object)
{
$_args = $object->_parse_arguments($arguments);
$arg_list = array();
if (empty($_args['file']))
{
$object->trigger_error("missing 'file' attribute in include tag", E_USER_ERROR, __FILE__, __LINE__);
}
foreach ($_args as $arg_name => $arg_value)
{
if ($arg_name == 'file')
{
$include_file = $arg_value;
continue;
}
else if ($arg_name == 'assign')
{
$assign_var = $arg_value;
continue;
}
if (is_bool($arg_value))
{
$arg_value = $arg_value ? 'true' : 'false';
}
$arg_list[] = "'$arg_name' => $arg_value";
}
if (isset($assign_var))
{
$output = '<?php $_templatelite_tpl_vars = $this->_vars;' .
"\n\$this->assign(" . $assign_var . ", \$this->_fetch_compile_include(" . $include_file . ", array(".implode(',', (array)$arg_list).")));\n" .
"\$this->_vars = \$_templatelite_tpl_vars;\n" .
"unset(\$_templatelite_tpl_vars);\n" .
' ?>';
}
else
{
$output = '<?php $_templatelite_tpl_vars = $this->_vars;' .
"\necho \$this->_fetch_compile_include(" . $include_file . ", array(".implode(',', (array)$arg_list)."));\n" .
"\$this->_vars = \$_templatelite_tpl_vars;\n" .
"unset(\$_templatelite_tpl_vars);\n" .
' ?>';
}
return $output;
}
?>

View File

@@ -0,0 +1,77 @@
<?php
/**
* Template Lite compile IS exprenssion in IF tag - template internal module
*
* Type: template
* Name: compile_parse_is_expr
*/
function compile_parse_is_expr($is_arg, $_args, &$object)
{
$expr_end = 0;
$negate_expr = false;
if (($first_arg = array_shift($_args)) == 'not') {
$negate_expr = true;
$expr_type = array_shift($_args);
}
else
{
$expr_type = $first_arg;
}
switch ($expr_type) {
case 'even':
if (isset($_args[$expr_end]) && $_args[$expr_end] == 'by')
{
$expr_end++;
$expr_arg = $_args[$expr_end++];
$expr = "!(1 & ($is_arg / " . $object->_parse_variable($expr_arg) . "))";
}
else
{
$expr = "!(1 & $is_arg)";
}
break;
case 'odd':
if (isset($_args[$expr_end]) && $_args[$expr_end] == 'by')
{
$expr_end++;
$expr_arg = $_args[$expr_end++];
$expr = "(1 & ($is_arg / " . $object->_parse_variable($expr_arg) . "))";
}
else
{
$expr = "(1 & $is_arg)";
}
break;
case 'div':
if (@$_args[$expr_end] == 'by')
{
$expr_end++;
$expr_arg = $_args[$expr_end++];
$expr = "!($is_arg % " . $object->_parse_variable($expr_arg) . ")";
}
else
{
$object->trigger_error("expecting 'by' after 'div'", E_USER_ERROR, __FILE__, __LINE__);
}
break;
default:
$object->trigger_error("unknown 'is' expression - '$expr_type'", E_USER_ERROR, __FILE__, __LINE__);
break;
}
if ($negate_expr) {
$expr = "!($expr)";
}
array_splice($_args, 0, $expr_end, $expr);
return $_args;
}
?>

View File

@@ -0,0 +1,129 @@
<?php
/**
* Template Lite section_start compile plugin converted from Smarty
*
* Type: compile
* Name: section_start
*/
function compile_section_start($arguments, &$object)
{
$attrs = $object->_parse_arguments($arguments);
$arg_list = array();
$output = '<?php ';
$section_name = $attrs['name'];
if (empty($section_name))
{
$object->trigger_error("missing section name", E_USER_ERROR, __FILE__, __LINE__);
}
$output .= "if (isset(\$this->_sections['$section_name'])) unset(\$this->_sections['$section_name']);\n";
$section_props = "\$this->_sections['$section_name']";
foreach ($attrs as $attr_name => $attr_value)
{
switch ($attr_name)
{
case 'loop':
$output .= "{$section_props}['loop'] = is_array($attr_value) ? count($attr_value) : max(0, (int)$attr_value);\n";
break;
case 'show':
if (is_bool($attr_value))
{
$show_attr_value = $attr_value ? 'true' : 'false';
}
else
{
$show_attr_value = "(bool)$attr_value";
}
$output .= "{$section_props}['show'] = $show_attr_value;\n";
break;
case 'name':
$output .= "{$section_props}['$attr_name'] = '$attr_value';\n";
break;
case 'max':
case 'start':
$output .= "{$section_props}['$attr_name'] = (int)$attr_value;\n";
break;
case 'step':
$output .= "{$section_props}['$attr_name'] = ((int)$attr_value) == 0 ? 1 : (int)$attr_value;\n";
break;
default:
$object->trigger_error("unknown section attribute - '$attr_name'", E_USER_ERROR, __FILE__, __LINE__);
break;
}
}
if (!isset($attrs['show']))
{
$output .= "{$section_props}['show'] = true;\n";
}
if (!isset($attrs['loop']))
{
$output .= "{$section_props}['loop'] = 1;\n";
}
if (!isset($attrs['max']))
{
$output .= "{$section_props}['max'] = {$section_props}['loop'];\n";
}
else
{
$output .= "if ({$section_props}['max'] < 0)\n" .
" {$section_props}['max'] = {$section_props}['loop'];\n";
}
if (!isset($attrs['step']))
{
$output .= "{$section_props}['step'] = 1;\n";
}
if (!isset($attrs['start']))
{
$output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n";
}
else
{
$output .= "if ({$section_props}['start'] < 0)\n" .
" {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" .
"else\n" .
" {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n";
}
$output .= "if ({$section_props}['show']) {\n";
if (!isset($attrs['start']) && !isset($attrs['step']) && !isset($attrs['max']))
{
$output .= " {$section_props}['total'] = {$section_props}['loop'];\n";
}
else
{
$output .= " {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n";
}
$output .= " if ({$section_props}['total'] == 0)\n" .
" {$section_props}['show'] = false;\n" .
"} else\n" .
" {$section_props}['total'] = 0;\n";
$output .= "if ({$section_props}['show']):\n";
$output .= "
for ({$section_props}['index'] = {$section_props}['start'], {$section_props}['iteration'] = 1;
{$section_props}['iteration'] <= {$section_props}['total'];
{$section_props}['index'] += {$section_props}['step'], {$section_props}['iteration']++):\n";
$output .= "{$section_props}['rownum'] = {$section_props}['iteration'];\n";
$output .= "{$section_props}['index_prev'] = {$section_props}['index'] - {$section_props}['step'];\n";
$output .= "{$section_props}['index_next'] = {$section_props}['index'] + {$section_props}['step'];\n";
$output .= "{$section_props}['first'] = ({$section_props}['iteration'] == 1);\n";
$output .= "{$section_props}['last'] = ({$section_props}['iteration'] == {$section_props}['total']);\n";
$output .= "?>";
return $output;
}
?>

View File

@@ -0,0 +1,77 @@
{* templatelite debug console *}
{if isset($_templatelite_debug_output) and $_templatelite_debug_output eq "html"}
<table border=0 width=100%>
<tr bgcolor=#cccccc><th colspan=2>Template Lite Debug Console</th></tr>
<tr bgcolor=#cccccc><td colspan=2><b>Included templates & config files (load time in seconds):</b></td></tr>
{foreach key=key value=templates from=$_debug_tpls}
<tr bgcolor={if $key % 2}#eeeeee{else}#fafafa{/if}>
<td colspan=2><tt>{for start=0 stop=$_debug_tpls[$key].depth}&nbsp;&nbsp;&nbsp;{/for}
<font color={if $_debug_tpls[$key].type eq "template"}brown{elseif $_debug_tpls[$key].type eq "insert"}black{else}green{/if}>
{$_debug_tpls[$key].filename}</font>{if isset($_debug_tpls[$key].exec_time)}
<font size=-1><i>({$_debug_tpls[$key].exec_time|string_format:"%.5f"} seconds){if $key eq 0} (total){/if}
</i></font>{/if}</tt></td></tr>
{foreachelse}
<tr bgcolor=#eeeeee><td colspan=2><tt><i>No template assigned</i></tt></td></tr>
{/foreach}
<tr bgcolor=#cccccc><td colspan=2><b>Assigned template variables:</b></td></tr>
{foreach key=key value=vars from=$_debug_keys}
<tr bgcolor={if $key % 2}#eeeeee{else}#fafafa{/if}>
<td valign=top><tt><font color=blue>{ldelim}${$_debug_keys[$key]}{rdelim}</font></tt></td>
<td nowrap><tt><font color=green>{$_debug_vals[$key]|@debug_print_var}</font></tt></td></tr>
{foreachelse}
<tr bgcolor=#eeeeee><td colspan=2><tt><i>No template variables assigned</i></tt></td></tr>
{/foreach}
<tr bgcolor=#cccccc><td colspan=2><b>Assigned config file variables (outer template scope):</b></td></tr>
{foreach key=key value=config_vars from=$_debug_config_keys}
<tr bgcolor={if $key % 2}#eeeeee{else}#fafafa{/if}>
<td valign=top><tt><font color=maroon>{ldelim}#{$_debug_config_keys[$key]}#{rdelim}</font></tt></td>
<td><tt><font color=green>{$_debug_config_vals[$key]|@debug_print_var}</font></tt></td></tr>
{foreachelse}
<tr bgcolor=#eeeeee><td colspan=2><tt><i>No config vars assigned</i></tt></td></tr>
{/foreach}
</table>
{else}
<SCRIPT language=javascript>
if( self.name == '' ) {ldelim}
var title = 'Console';
{rdelim}
else {ldelim}
var title = 'Console_' + self.name;
{rdelim}
_templatelite_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes");
_templatelite_console.document.write("<HTML><TITLE>Template Lite Debug Console_"+self.name+"</TITLE><BODY bgcolor=#ffffff>");
_templatelite_console.document.write("<table border=0 width=100%>");
_templatelite_console.document.write("<tr bgcolor=#cccccc><th colspan=2>Template Lite Debug Console</th></tr>");
_templatelite_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>Included templates & config files (load time in seconds):</b></td></tr>");
{foreach key=key value=templates from=$_debug_tpls}
_templatelite_console.document.write("<tr bgcolor={if $key % 2}#eeeeee{else}#fafafa{/if}>");
_templatelite_console.document.write("<td colspan=2><tt>{for start=0 stop=$_debug_tpls[$key].depth}&nbsp;&nbsp;&nbsp;{/for}");
_templatelite_console.document.write("<font color={if $_debug_tpls[$key].type eq "template"}brown{elseif $_debug_tpls[$key].type eq "insert"}black{else}green{/if}>");
_templatelite_console.document.write("{$_debug_tpls[$key].filename}</font>{if isset($_debug_tpls[$key].exec_time)} ");
_templatelite_console.document.write("<font size=-1><i>({$_debug_tpls[$key].exec_time|string_format:"%.5f"} seconds){if $key eq 0} (total){/if}");
_templatelite_console.document.write("</i></font>{/if}</tt></td></tr>");
{foreachelse}
_templatelite_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>No template assigned</i></tt></td></tr> ");
{/foreach}
_templatelite_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>Assigned template variables:</b></td></tr>");
{foreach key=key value=vars from=$_debug_keys}
_templatelite_console.document.write("<tr bgcolor={if $key % 2}#eeeeee{else}#fafafa{/if}>");
_templatelite_console.document.write("<td valign=top><tt><font color=blue>{ldelim}${$_debug_keys[$key]}{rdelim}</font></tt></td>");
_templatelite_console.document.write("<td nowrap><tt><font color=green>{$_debug_vals[$key]|@debug_print_var}</font></tt></td></tr>");
{foreachelse}
_templatelite_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>No template variables assigned</i></tt></td></tr>");
{/foreach}
_templatelite_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>Assigned config file variables (outer template scope):</b></td></tr>");
{foreach key=key value=config_vars from=$_debug_config_keys}
_templatelite_console.document.write("<tr bgcolor={if $key % 2}#eeeeee{else}#fafafa{/if}>");
_templatelite_console.document.write("<td valign=top><tt><font color=maroon>{ldelim}#{$_debug_config_keys[$key]}#{rdelim}</font></tt></td>");
_templatelite_console.document.write("<td><tt><font color=green>{$_debug_config_vals[$key]|@debug_print_var}</font></tt></td></tr>");
{foreachelse}
_templatelite_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>No config vars assigned</i></tt></td></tr>");
{/foreach}
_templatelite_console.document.write("</table>");
_templatelite_console.document.write("</BODY></HTML>");
_templatelite_console.document.close();
</SCRIPT>
{/if}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Template Lite template_build_dir template internal module
*
* Type: template
* Name: template_build_dir
*/
function template_build_dir($dir, $id, &$object)
{
$_args = explode('|', $id);
if (count($_args) == 1 && empty($_args[0]))
{
return $object->_get_dir($dir);
}
$_result = $object->_get_dir($dir);
foreach($_args as $value)
{
$_result .= $value.DIRECTORY_SEPARATOR;
if (!is_dir($_result))
{
@mkdir($_result, 0777);
}
}
return $_result;
}
?>

View File

@@ -0,0 +1,76 @@
<?php
/**
* Template Lite config_load template internal module
*
* Type: template
* Name: config_load
*/
$this->_config_module_loaded = true;
$this->template_dir = $this->_get_dir($this->template_dir);
$this->config_dir = $this->_get_dir($this->config_dir);
$this->compile_dir = $this->_get_dir($this->compile_dir);
$name = ($this->encode_file_name) ? md5($this->template_dir . $file . $section_name . $var_name).'.php' : str_replace(".", "_", str_replace("/", "_", $file."_".$section_name."_".$var_name)).'.php';
if ($this->debugging)
{
$debug_start_time = array_sum(explode(' ', microtime()));
}
if ($this->cache)
{
array_push($this->_cache_info['config'], $file);
}
if (!$this->force_compile && file_exists($this->compile_dir.'c_'.$name) && (filemtime($this->compile_dir.'c_'.$name) > filemtime($this->config_dir.$file)))
{
include($this->compile_dir.'c_'.$name);
return true;
}
if (!is_object($this->_config_obj))
{
require_once(TEMPLATE_LITE_DIR . "class.config.php");
$this->_config_obj = new $this->config_class;
$this->_config_obj->overwrite = $this->config_overwrite;
$this->_config_obj->booleanize = $this->config_booleanize;
$this->_config_obj->fix_new_lines = $this->config_fix_new_lines;
$this->_config_obj->read_hidden = $this->config_read_hidden;
}
if (!($_result = $this->_config_obj->config_load($this->config_dir.$file, $section_name, $var_name)))
{
return false;
}
if (!empty($var_name) || !empty($section_name))
{
$output = "\$this->_confs = " . var_export($_result, true) . ";";
}
else
{
// must shift of the bottom level of the array to get rid of the section labels
$_temp = array();
foreach($_result as $value)
{
$_temp = array_merge($_temp, $value);
}
$output = "\$this->_confs = " . var_export($_temp, true) . ";";
}
$f = fopen($this->compile_dir.'c_'.$name, "w");
fwrite($f, '<?php ' . $output . ' ?>');
fclose($f);
eval($output);
if ($this->debugging)
{
$this->_templatelite_debug_info[] = array('type' => 'config',
'filename' => $file.' ['.$section_name.'] '.$var_name,
'depth' => 0,
'exec_time' => array_sum(explode(' ', microtime())) - $debug_start_time );
}
return true;
?>

View File

@@ -0,0 +1,68 @@
<?php
/**
* Template Lite template_destroy_dir template internal module
*
* Type: template
* Name: template_destroy_dir
*/
function template_destroy_dir($file, $id, $dir, &$object)
{
if ($file == null && $id == null)
{
if (is_dir($dir))
{
if($d = opendir($dir))
{
while(($f = readdir($d)) !== false)
{
if ($f != '.' && $f != '..')
{
template_rm_dir($dir.$f.DIRECTORY_SEPARATOR);
}
}
}
}
}
else
{
if ($id == null)
{
$object->template_dir = $object->_get_dir($object->template_dir);
$name = ($object->encode_file_name) ? md5($object->template_dir.$file).'.php' : str_replace(".", "_", str_replace("/", "_", $file)).'.php';
@unlink($dir.$name);
}
else
{
$_args = "";
foreach(explode('|', $id) as $value)
{
$_args .= $value.DIRECTORY_SEPARATOR;
}
template_rm_dir($dir.DIRECTORY_SEPARATOR.$_args);
}
}
}
function template_rm_dir($dir)
{
if (is_file(substr($dir, 0, -1)))
{
@unlink(substr($dir, 0, -1));
return;
}
if ($d = opendir($dir))
{
while(($f = readdir($d)) !== false)
{
if ($f != '.' && $f != '..')
{
template_rm_dir($dir.$f.DIRECTORY_SEPARATOR, $object);
}
}
@rmdir($dir.$f);
}
}
?>

View File

@@ -0,0 +1,42 @@
<?php
/**
* Template Lite template_fetch_compile_include template internal module
*
* Type: template
* Name: template_fetch_compile_include
*/
function template_fetch_compile_include($_templatelite_include_file, $_templatelite_include_vars, &$object)
{
if ($object->debugging)
{
$object->_templatelite_debug_info[] = array('type' => 'template',
'filename' => $_templatelite_include_file,
'depth' => ++$object->_inclusion_depth,
'exec_time' => array_sum(explode(' ', microtime())) );
$included_tpls_idx = count($object->_templatelite_debug_info) - 1;
}
$object->_vars = array_merge($object->_vars, $_templatelite_include_vars);
$_templatelite_include_file = $object->_get_resource($_templatelite_include_file);
if(isset($object->_confs[0]))
{
array_unshift($object->_confs, $object->_confs[0]);
$_compiled_output = $object->_fetch_compile($_templatelite_include_file);
array_shift($object->_confs);
}
else
{
$_compiled_output = $object->_fetch_compile($_templatelite_include_file);
}
$object->_inclusion_depth--;
if ($object->debugging)
{
$object->_templatelite_debug_info[$included_tpls_idx]['exec_time'] = array_sum(explode(' ', microtime())) - $object->_templatelite_debug_info[$included_tpls_idx]['exec_time'];
}
return $_compiled_output;
}
?>

View File

@@ -0,0 +1,37 @@
<?php
/**
* Template Lite template_generate_debug_output template internal module
*
* Type: template
* Name: template_generate_debug_output
*/
function template_generate_debug_output(&$object)
{
$assigned_vars = $object->_vars;
ksort($assigned_vars);
if (@is_array($object->_config[0]))
{
$config_vars = $object->_config[0];
ksort($config_vars);
$object->assign("_debug_config_keys", array_keys($config_vars));
$object->assign("_debug_config_vals", array_values($config_vars));
}
$included_templates = $object->_templatelite_debug_info;
$object->assign("_debug_keys", array_keys($assigned_vars));
$object->assign("_debug_vals", array_values($assigned_vars));
$object->assign("_debug_tpls", $included_templates);
$object->assign("_templatelite_debug_output", "");
$object->_templatelite_debug_loop = true;
$object->_templatelite_debug_dir = $object->template_dir;
$object->template_dir = TEMPLATE_LITE_DIR . "internal/";
$debug_output = $object->fetch("debug.tpl");
$object->template_dir = $object->_templatelite_debug_dir;
$object->_templatelite_debug_loop = false;
return $debug_output;
}
?>