diff --git a/change_log.txt b/change_log.txt index e4d3a08e..f5a5c4b5 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,9 @@ 11/23/2009 +- suppress warnings on unlink caused by race conditions +- correct line number on unknown tag error message + +------- beta 5 +11/23/2009 - fixed configfile parser for text starting with a numeric char - the default_template_handler_func may now return a filepath to a template source diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index 269207f5..aee72653 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -130,10 +130,10 @@ class Smarty_Internal_CacheResource_File { (isset($resource_name) && (string)$_file == $_dir . $_resource_part)) { if (isset($exp_time)) { if (time() - @filemtime($_file) >= $exp_time) { - $_count += unlink((string) $_file) ? 1 : 0; + $_count += @unlink((string) $_file) ? 1 : 0; } } else { - $_count += unlink((string) $_file) ? 1 : 0; + $_count += @unlink((string) $_file) ? 1 : 0; } } } diff --git a/libs/sysplugins/smarty_internal_smartytemplatecompiler.php b/libs/sysplugins/smarty_internal_smartytemplatecompiler.php index 3d7dc697..4ee8aec6 100644 --- a/libs/sysplugins/smarty_internal_smartytemplatecompiler.php +++ b/libs/sysplugins/smarty_internal_smartytemplatecompiler.php @@ -37,13 +37,13 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom tags in the templates are replaces with PHP code, then written to compiled files. */ // init the lexer/parser to compile the template - $lex = new $this->lexer_class($_content,$this->smarty); - $parser = new $this->parser_class($lex, $this); - // $parser->PrintTrace(); + $this->lex = new $this->lexer_class($_content,$this->smarty); + $this->parser = new $this->parser_class($this->lex, $this); + // $this->parser->PrintTrace(); // get tokens from lexer and parse them - while ($lex->yylex() && !$this->abort_and_recompile) { - // echo "Line {$lex->line} Parsing {$parser->yyTokenName[$lex->token]} Token
".htmlentities($lex->value)."
"; - $parser->doParse($lex->token, $lex->value); + while ($this->lex->yylex() && !$this->abort_and_recompile) { + // echo "Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token
".htmlentities($this->lex->value)."
"; + $this->parser->doParse($this->lex->token, $this->lex->value); } if ($this->abort_and_recompile) { @@ -51,7 +51,7 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom return false; } // finish parsing process - $parser->doParse(0, 0); + $this->parser->doParse(0, 0); // check for unclosed tags if (count($this->_tag_stack) > 0) { // get stacked info @@ -61,7 +61,7 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom if (!$this->compile_error) { // return compiled code - return str_replace(array("?>\nretvalue); + return str_replace(array("?>\nparser->retvalue); } else { // compilation error return false; diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index e501fb31..6f9ce3ce 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -149,7 +149,7 @@ class Smarty_Internal_TemplateCompilerBase { } elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) { return $this->generateCode('object_block_function',$args, $tag, $methode); } else { - return $this->trigger_template_error ('unallowed methode "' . $methode . '" in registered object "' . $tag . '"'); + return $this->trigger_template_error ('unallowed methode "' . $methode . '" in registered object "' . $tag . '"', $this->lex->taglineno); } } // check if tag is registered or is Smarty plugin @@ -176,7 +176,7 @@ class Smarty_Internal_TemplateCompilerBase { if (in_array($methode, $this->smarty->registered_objects[$base_tag][3])) { return $this->generateCode('object_block_function', $args, $tag, $methode); } else { - return $this->trigger_template_error ('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"'); + return $this->trigger_template_error ('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"', $this->lex->taglineno); } } // plugin ? @@ -184,7 +184,7 @@ class Smarty_Internal_TemplateCompilerBase { return $this->generateCode('block_plugin',$args, $tag); } } - $this->trigger_template_error ("unknown tag \"" . $tag . "\""); + $this->trigger_template_error ("unknown tag \"" . $tag . "\"", $this->lex->taglineno); } } @@ -231,14 +231,11 @@ class Smarty_Internal_TemplateCompilerBase { * @todo output exact position of parse error in source line * @param $args string individual error message or null */ - public function trigger_template_error($args = null) + public function trigger_template_error($args = null, $line= null) { - $this->lex = Smarty_Internal_Templatelexer::instance(); - $this->parser = Smarty_Internal_Templateparser::instance(); // get template source line which has error + if (!isset($line)) { $line = $this->lex->line; - if (isset($args)) { - // $line--; } $match = preg_split("/\n/", $this->lex->data); $error_text = 'Syntax Error in template "' . $this->template->getTemplateFilepath() . '" on line ' . $line . ' "' . $match[$line-1] . '" '; diff --git a/libs/sysplugins/smarty_internal_templatelexer.php b/libs/sysplugins/smarty_internal_templatelexer.php index 0d59003c..1a405d06 100644 --- a/libs/sysplugins/smarty_internal_templatelexer.php +++ b/libs/sysplugins/smarty_internal_templatelexer.php @@ -18,6 +18,7 @@ class Smarty_Internal_Templatelexer public $value; public $node; public $line; + public $taglineno; public $state = 1; public $smarty_token_names = array ( // Text for parser error messages 'IDENTITY' => '===', @@ -296,6 +297,7 @@ class Smarty_Internal_Templatelexer } else { $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } } function yy_r1_10($yy_subpatterns) @@ -306,6 +308,7 @@ class Smarty_Internal_Templatelexer } else { $this->token = Smarty_Internal_Templateparser::TP_LDEL; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } } function yy_r1_11($yy_subpatterns) @@ -313,12 +316,14 @@ class Smarty_Internal_Templatelexer $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } function yy_r1_12($yy_subpatterns) { $this->token = Smarty_Internal_Templateparser::TP_LDEL; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } function yy_r1_13($yy_subpatterns) { @@ -604,6 +609,7 @@ class Smarty_Internal_Templatelexer } else { $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } } function yy_r2_8($yy_subpatterns) @@ -614,6 +620,7 @@ class Smarty_Internal_Templatelexer } else { $this->token = Smarty_Internal_Templateparser::TP_LDEL; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } } function yy_r2_9($yy_subpatterns) @@ -631,12 +638,14 @@ class Smarty_Internal_Templatelexer $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } function yy_r2_11($yy_subpatterns) { $this->token = Smarty_Internal_Templateparser::TP_LDEL; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } function yy_r2_12($yy_subpatterns) { @@ -1328,6 +1337,7 @@ class Smarty_Internal_Templatelexer } else { $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } } function yy_r5_2($yy_subpatterns) @@ -1338,6 +1348,7 @@ class Smarty_Internal_Templatelexer } else { $this->token = Smarty_Internal_Templateparser::TP_LDEL; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } } function yy_r5_3($yy_subpatterns) @@ -1345,12 +1356,14 @@ class Smarty_Internal_Templatelexer $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } function yy_r5_4($yy_subpatterns) { $this->token = Smarty_Internal_Templateparser::TP_LDEL; $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } function yy_r5_5($yy_subpatterns) { @@ -1364,6 +1377,7 @@ class Smarty_Internal_Templatelexer $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; $this->value = substr($this->value,0,-1); $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; } function yy_r5_7($yy_subpatterns) { diff --git a/libs/sysplugins/smarty_internal_write_file.php b/libs/sysplugins/smarty_internal_write_file.php index 437053bf..5c756f1b 100644 --- a/libs/sysplugins/smarty_internal_write_file.php +++ b/libs/sysplugins/smarty_internal_write_file.php @@ -36,7 +36,7 @@ class Smarty_Internal_Write_File { } // remove original file if (file_exists($_filepath)) - unlink($_filepath); + @unlink($_filepath); // rename tmp file rename($_tmp_file, $_filepath); // set file permissions diff --git a/libs/sysplugins/smarty_method_clear_compiled_tpl.php b/libs/sysplugins/smarty_method_clear_compiled_tpl.php index 4f53d61c..260f042b 100644 --- a/libs/sysplugins/smarty_method_clear_compiled_tpl.php +++ b/libs/sysplugins/smarty_method_clear_compiled_tpl.php @@ -51,10 +51,10 @@ function Smarty_Method_Clear_Compiled_Tpl($smarty, $resource_name = null, $comp substr_compare((string)$_file, $_resource_part_2, - strlen($_resource_part_2), strlen($_resource_part_2)) == 0)) { if (isset($exp_time)) { if (time() - @filemtime($_file) >= $exp_time) { - $_count += unlink((string) $_file) ? 1 : 0; + $_count += @unlink((string) $_file) ? 1 : 0; } } else { - $_count += unlink((string) $_file) ? 1 : 0; + $_count += @unlink((string) $_file) ? 1 : 0; } } }