- bugfix allow array definitions as modifier parameter

- bugfix observe compile_check property when loading config files
- added the template object as third filter parameter
This commit is contained in:
Uwe.Tews
2010-03-29 15:41:01 +00:00
parent 76f1bd5428
commit 24d5ad78f3
9 changed files with 1068 additions and 953 deletions

View File

@@ -1,7 +1,12 @@
29/03/2010
- bugfix allow array definitions as modifier parameter
- bugfix observe compile_check property when loading config files
- added the template object as third filter parameter
25/03/2010
- change of utility->compileAllTemplates() log messages
- bugfix on nocache code in {function} tags
- new methode utility->compileAllConfig() to compile all config files
- new method utility->compileAllConfig() to compile all config files
24/03/2010
- bugfix on register->modifier() error messages

View File

@@ -329,7 +329,7 @@ class Smarty extends Smarty_Internal_Data {
}
// return redered template
if (isset($this->autoload_filters['output']) || isset($this->registered_filters['output'])) {
$_output = Smarty_Internal_Filter_Handler::runFilter('output', $_template->getRenderedTemplate(), $this);
$_output = Smarty_Internal_Filter_Handler::runFilter('output', $_template->getRenderedTemplate(), $this, $_template);
} else {
$_output = $_template->getRenderedTemplate();
}

View File

@@ -49,7 +49,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
// display value
$this->compiler->has_output = true;
if (isset($this->compiler->smarty->registered_filters['variable'])) {
$output = '<?php echo Smarty_Internal_Filter_Handler::runFilter(\'variable\', ' . $_attr['value'] . ',$this->smarty, ' . $_attr['filter'] . ');?>';
$output = '<?php echo Smarty_Internal_Filter_Handler::runFilter(\'variable\', ' . $_attr['value'] . ',$_smarty_tpl->smarty, $_smarty_tpl, ' . $_attr['filter'] . ');?>';
} else {
$output = '<?php echo ' . $_attr['value'] . ';?>';
}
@@ -58,4 +58,4 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
}
?>
?>

View File

@@ -1,14 +1,14 @@
<?php
/**
* Smarty Internal Plugin Config
*
* Main class for config variables
*
* @ignore
* @package Smarty
* @subpackage Config
* @author Uwe Tews
*/
* Smarty Internal Plugin Config
*
* Main class for config variables
*
* @ignore
* @package Smarty
* @subpackage Config
* @author Uwe Tews
*/
class Smarty_Internal_Config {
static $config_objects = array();
@@ -85,23 +85,23 @@ class Smarty_Internal_Config {
}
// check for absolute path
if (file_exists($this->config_resource_name))
return $this->config_resource_name;
return $this->config_resource_name;
// no tpl file found
throw new Exception("Unable to load config file \"{$this->config_resource_name}\"");
return false;
}
/**
* Read config file source
*
* @return string content of source file
*/
* Read config file source
*
* @return string content of source file
*/
/**
* Returns the template source code
*
* The template source is being read by the actual resource handler
*
* @return string the template source
*/
* Returns the template source code
*
* The template source is being read by the actual resource handler
*
* @return string the template source
*/
public function getConfigSource ()
{
if ($this->config_source === null) {
@@ -123,10 +123,10 @@ class Smarty_Internal_Config {
}
/**
* Returns the compiled filepath
*
* @return string the compiled filepath
*/
* Returns the compiled filepath
*
* @return string the compiled filepath
*/
public function getCompiledFilepath ()
{
return $this->compiled_filepath === null ?
@@ -152,10 +152,10 @@ class Smarty_Internal_Config {
return $_compile_dir . $_filepath . '.' . basename($this->config_resource_name) . '.config' . '.php';
}
/**
* Returns the timpestamp of the compiled file
*
* @return integer the file timestamp
*/
* Returns the timpestamp of the compiled file
*
* @return integer the file timestamp
*/
public function getCompiledTimestamp ()
{
return $this->compiled_timestamp === null ?
@@ -163,98 +163,98 @@ class Smarty_Internal_Config {
$this->compiled_timestamp;
}
/**
* Returns if the current config file must be compiled
*
* It does compare the timestamps of config source and the compiled config and checks the force compile configuration
*
* @return boolean true if the file must be compiled
*/
* Returns if the current config file must be compiled
*
* It does compare the timestamps of config source and the compiled config and checks the force compile configuration
*
* @return boolean true if the file must be compiled
*/
public function mustCompile ()
{
return $this->mustCompile === null ?
$this->mustCompile = ($this->smarty->force_compile || $this->getCompiledTimestamp () !== $this->getTimestamp ()):
$this->mustCompile;
}
/**
* Returns the compiled config file
*
* It checks if the config file must be compiled or just read the compiled version
*
* @return string the compiled config file
*/
public function getCompiledConfig ()
{
if ($this->compiled_config === null) {
// see if template needs compiling.
if ($this->mustCompile()) {
$this->compileConfigSource();
$this->mustCompile = ($this->smarty->force_compile || $this->smarty->compile_check && $this->getCompiledTimestamp () !== $this->getTimestamp ()):
$this->mustCompile;
}
/**
* Returns the compiled config file
*
* It checks if the config file must be compiled or just read the compiled version
*
* @return string the compiled config file
*/
public function getCompiledConfig ()
{
if ($this->compiled_config === null) {
// see if template needs compiling.
if ($this->mustCompile()) {
$this->compileConfigSource();
} else {
$this->compiled_config = file_get_contents($this->getCompiledFilepath());
}
}
return $this->compiled_config;
}
/**
* Compiles the config files
*/
public function compileConfigSource ()
{
// compile template
if (!is_object($this->compiler_object)) {
// load compiler
$this->compiler_object = new Smarty_Internal_Config_File_Compiler($this->smarty);
}
// call compiler
if ($this->compiler_object->compileSource($this)) {
// compiling succeded
// write compiled template
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->getCompiledConfig(), $this->smarty);
// make template and compiled file timestamp match
touch($this->getCompiledFilepath(), $this->getTimestamp());
} else {
$this->compiled_config = file_get_contents($this->getCompiledFilepath());
// error compiling template
throw new Exception("Error compiling template {$this->getConfigFilepath ()}");
return false;
}
}
return $this->compiled_config;
}
/**
* Compiles the config files
*/
public function compileConfigSource ()
{
// compile template
if (!is_object($this->compiler_object)) {
// load compiler
$this->compiler_object = new Smarty_Internal_Config_File_Compiler($this->smarty);
}
// call compiler
if ($this->compiler_object->compileSource($this)) {
// compiling succeded
// write compiled template
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->getCompiledConfig(), $this->smarty);
// make template and compiled file timestamp match
touch($this->getCompiledFilepath(), $this->getTimestamp());
} else {
// error compiling template
throw new Exception("Error compiling template {$this->getConfigFilepath ()}");
return false;
}
}
/*
/*
* load config variables
*
* @param mixed $sections array of section names, single section or null
* @param object $scope global,parent or local
*/
public function loadConfigVars ($sections = null, $scope)
{
if (isset($this->template)) {
$this->template->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp());
} else {
$this->smarty->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp());
}
$config_data = unserialize($this->getCompiledConfig());
// var_dump($config_data);
// copy global config vars
foreach ($config_data['vars'] as $variable => $value) {
if ($this->smarty->config_overwrite || !isset($scope->config_vars[$variable])) {
$scope->config_vars[$variable] = $value;
public function loadConfigVars ($sections = null, $scope)
{
if (isset($this->template)) {
$this->template->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp());
} else {
$scope->config_vars[$variable] = array_merge((array)$scope->config_vars[$variable], (array)$value);
$this->smarty->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp());
}
}
// scan sections
foreach ($config_data['sections'] as $this_section => $dummy) {
if ($sections == null || in_array($this_section, (array)$sections)) {
foreach ($config_data['sections'][$this_section]['vars'] as $variable => $value) {
if ($this->smarty->config_overwrite || !isset($scope->config_vars[$variable])) {
$scope->config_vars[$variable] = $value;
} else {
$scope->config_vars[$variable] = array_merge((array)$scope->config_vars[$variable], (array)$value);
$config_data = unserialize($this->getCompiledConfig());
// var_dump($config_data);
// copy global config vars
foreach ($config_data['vars'] as $variable => $value) {
if ($this->smarty->config_overwrite || !isset($scope->config_vars[$variable])) {
$scope->config_vars[$variable] = $value;
} else {
$scope->config_vars[$variable] = array_merge((array)$scope->config_vars[$variable], (array)$value);
}
}
// scan sections
foreach ($config_data['sections'] as $this_section => $dummy) {
if ($sections == null || in_array($this_section, (array)$sections)) {
foreach ($config_data['sections'][$this_section]['vars'] as $variable => $value) {
if ($this->smarty->config_overwrite || !isset($scope->config_vars[$variable])) {
$scope->config_vars[$variable] = $value;
} else {
$scope->config_vars[$variable] = array_merge((array)$scope->config_vars[$variable], (array)$value);
}
}
}
}
}
}
}
?>
?>

View File

@@ -1,23 +1,23 @@
<?php
/**
* Smarty Internal Plugin Config File Compiler
*
* This is the config file compiler class. It calls the lexer and parser to
* perform the compiling.
*
* @package Smarty
* @subpackage Config
* @author Uwe Tews
*/
* Smarty Internal Plugin Config File Compiler
*
* This is the config file compiler class. It calls the lexer and parser to
* perform the compiling.
*
* @package Smarty
* @subpackage Config
* @author Uwe Tews
*/
/**
* Main config file compiler class
*/
* Main config file compiler class
*/
class Smarty_Internal_Config_File_Compiler {
public $compile_error= false;
/**
* Initialize compiler
*/
public $compile_error = false;
/**
* Initialize compiler
*/
public function __construct($smarty)
{
$this->smarty = $smarty;
@@ -29,19 +29,19 @@ class Smarty_Internal_Config_File_Compiler {
}
/**
* Methode to compile a Smarty template
*
* @param $template template object to compile
* @return bool true if compiling succeeded, false if it failed
*/
* Methode to compile a Smarty template
*
* @param $template template object to compile
* @return bool true if compiling succeeded, false if it failed
*/
public function compileSource($config)
{
/* here is where the compiling takes place. Smarty
tags in the templates are replaces with PHP code,
then written to compiled files. */
$this->config = $config;
// get config file source
$_content = $config->getConfigSource()."\n";
then written to compiled files. */
$this->config = $config;
// get config file source
$_content = $config->getConfigSource() . "\n";
// on empty template just return
if ($_content == '') {
return true;
@@ -49,10 +49,10 @@ class Smarty_Internal_Config_File_Compiler {
// init the lexer/parser to compile the config file
$lex = new Smarty_Internal_Configfilelexer($_content, $this->smarty);
$parser = new Smarty_Internal_Configfileparser($lex, $this);
// $parser->PrintTrace();
if (isset($this->smarty->_parserdebug)) $parser->PrintTrace();
// get tokens from lexer and parse them
while ($lex->yylex()) {
// echo "<br>Parsing {$parser->yyTokenName[$lex->token]} Token {$lex->value} Line {$lex->line} \n";
if (isset($this->smarty->_parserdebug)) echo "<br>Parsing {$parser->yyTokenName[$lex->token]} Token {$lex->value} Line {$lex->line} \n";
$parser->doParse($lex->token, $lex->value);
}
// finish parsing process
@@ -67,16 +67,16 @@ class Smarty_Internal_Config_File_Compiler {
}
}
/**
* display compiler error messages without dying
*
* If parameter $args is empty it is a parser detected syntax error.
* In this case the parser is called to obtain information about exspected tokens.
*
* If parameter $args contains a string this is used as error message
*
* @todo output exact position of parse error in source line
* @param $args string individual error message or null
*/
* display compiler error messages without dying
*
* If parameter $args is empty it is a parser detected syntax error.
* In this case the parser is called to obtain information about exspected tokens.
*
* If parameter $args contains a string this is used as error message
*
* @todo output exact position of parse error in source line
* @param $args string individual error message or null
*/
public function trigger_config_file_error($args = null)
{
$this->lex = Smarty_Internal_Configfilelexer::instance();
@@ -84,7 +84,7 @@ class Smarty_Internal_Config_File_Compiler {
// get template source line which has error
$line = $this->lex->line;
if (isset($args)) {
// $line--;
// $line--;
}
$match = preg_split("/\n/", $this->lex->data);
$error_text = "Syntax error in config file '{$this->config->getConfigFilepath()}' on line {$line} '{$match[$line-1]}' ";
@@ -106,11 +106,10 @@ class Smarty_Internal_Config_File_Compiler {
// output parser error message
$error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect);
}
throw new Exception($error_text);
throw new Exception($error_text);
// set error flag
$this->compile_error = true;
}
}
?>
?>

View File

@@ -26,7 +26,7 @@ class Smarty_Internal_Filter_Handler {
* @param string $content the content which shall be processed by the filters
* @return string the filtered content
*/
static function runFilter($type, $content, $smarty, $flag = null)
static function runFilter($type, $content, $smarty, $template, $flag = null)
{
$output = $content;
if ($type != 'variable' || ($smarty->variable_filter && $flag !== false) || $flag === true) {
@@ -40,7 +40,7 @@ class Smarty_Internal_Filter_Handler {
$output = $plugin_name($output, $smarty);
} elseif (class_exists($plugin_name, false)) {
// loaded class of filter plugin
$output = call_user_func(array($plugin_name, 'execute'), $output, $smarty);
$output = call_user_func(array($plugin_name, 'execute'), $output, $smarty, $template);
}
} else {
// nothing found, throw exception
@@ -52,9 +52,9 @@ class Smarty_Internal_Filter_Handler {
if (!empty($smarty->registered_filters[$type])) {
foreach ($smarty->registered_filters[$type] as $key => $name) {
if (is_array($smarty->registered_filters[$type][$key])) {
$output = call_user_func($smarty->registered_filters[$type][$key], $output, $smarty);
$output = call_user_func($smarty->registered_filters[$type][$key], $output, $smarty, $template);
} else {
$output = $smarty->registered_filters[$type][$key]($output, $smarty);
$output = $smarty->registered_filters[$type][$key]($output, $smarty, $template);
}
}
}

View File

@@ -69,7 +69,7 @@ class Smarty_Internal_TemplateCompilerBase {
$_content = $template->getTemplateSource();
// run prefilter if required
if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) {
$_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $this->smarty);
$_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $this->smarty, $template);
}
// on empty template just return header
if ($_content == '') {
@@ -92,7 +92,7 @@ class Smarty_Internal_TemplateCompilerBase {
}
// run postfilter if required
if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) {
$template->compiled_template = Smarty_Internal_Filter_Handler::runFilter('post', $template->compiled_template, $this->smarty);
$template->compiled_template = Smarty_Internal_Filter_Handler::runFilter('post', $template->compiled_template, $this->smarty, $template);
}
return true;
} else {

File diff suppressed because it is too large Load Diff

View File

@@ -50,13 +50,7 @@ class Smarty_Internal_Utility {
* @return integer number of template files recompiled
*/
function compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
{
function _get_time()
{
$_mtime = microtime();
$_mtime = explode(" ", $_mtime);
return (double)($_mtime[1]) + (double)($_mtime[0]);
}
{
// switch off time limit
if (function_exists('set_time_limit')) {
@set_time_limit($time_limit);
@@ -79,12 +73,12 @@ class Smarty_Internal_Utility {
}
echo '<br>', $_dir, '---', $_template_file;
flush();
$_start_time = _get_time();
$_start_time = $this->_get_time();
try {
$_tpl = $this->smarty->createTemplate($_template_file);
if ($_tpl->mustCompile()) {
$_tpl->compileTemplateSource();
echo ' compiled in ', _get_time() - $_start_time, ' seconds';
echo ' compiled in ', $this->_get_time() - $_start_time, ' seconds';
flush();
} else {
echo ' is up to date';
@@ -114,8 +108,8 @@ class Smarty_Internal_Utility {
* @return integer number of template files recompiled
*/
function compileAllConfig($extention = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null)
{
// switch off time limit
{
// switch off time limit
if (function_exists('set_time_limit')) {
@set_time_limit($time_limit);
}
@@ -137,12 +131,12 @@ class Smarty_Internal_Utility {
}
echo '<br>', $_dir, '---', $_config_file;
flush();
$_start_time = _get_time();
$_start_time = $this->_get_time();
try {
$_config = new Smarty_Internal_Config($_config_file, $this->smarty);
if ($_config->mustCompile()) {
$_config->compileConfigSource();
echo ' compiled in ', _get_time() - $_start_time, ' seconds';
echo ' compiled in ', $this->_get_time() - $_start_time, ' seconds';
flush();
} else {
echo ' is up to date';
@@ -279,4 +273,15 @@ class Smarty_Internal_Utility {
return true;
}
/**
* Get Micro Time
*
* @return double micro time
*/
function _get_time()
{
$_mtime = microtime();
$_mtime = explode(" ", $_mtime);
return (double)($_mtime[1]) + (double)($_mtime[0]);
}
}