mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
- suppress warnings on unlink caused by race conditions
- correct line number on unknown tag error message
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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 <pre>".htmlentities($lex->value)."</pre>";
|
||||
$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 <pre>".htmlentities($this->lex->value)."</pre>";
|
||||
$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("?>\n<?php","?><?php"), array('',''), $parser->retvalue);
|
||||
return str_replace(array("?>\n<?php","?><?php"), array('',''), $this->parser->retvalue);
|
||||
} else {
|
||||
// compilation error
|
||||
return false;
|
||||
|
@@ -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] . '" ';
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user