*** empty log message ***

This commit is contained in:
andrey
2001-01-26 16:11:21 +00:00
parent e9b0c5adc9
commit f82729afa4
5 changed files with 77 additions and 39 deletions

6
NEWS
View File

@@ -1,3 +1,6 @@
Version 1.2.0
-------------
- added file and line number information to syntax error messages. (Andrei)
- added ability to index template vars by a key. (Andrei) - added ability to index template vars by a key. (Andrei)
Version 1.1.0 Version 1.1.0
@@ -6,7 +9,8 @@ Version 1.1.0
Version 1.0b Version 1.0b
------------ ------------
- fixed the bug that prevented using non-array values for 'loop' attribute (Andrei) - fixed the bug that prevented using non-array values for 'loop' attribute.
(Andrei)
- many misc documentation changes & additions (monte) - many misc documentation changes & additions (monte)
Version 1.0a Version 1.0a

View File

@@ -5,7 +5,7 @@
* Author: Monte Ohrt <monte@ispi.net> * Author: Monte Ohrt <monte@ispi.net>
* Andrei Zmievski <andrei@ispi.net> * Andrei Zmievski <andrei@ispi.net>
* *
* Version: 1.1.0 * Version: 1.2.0
* Copyright: 2001 ispi of Lincoln, Inc. * Copyright: 2001 ispi of Lincoln, Inc.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@@ -88,6 +88,8 @@ class Smarty
var $_tpl_vars = array(); var $_tpl_vars = array();
var $_sectionelse_stack = array(); // keeps track of whether section had 'else' part var $_sectionelse_stack = array(); // keeps track of whether section had 'else' part
var $_literal_blocks = array(); // keeps literal template blocks var $_literal_blocks = array(); // keeps literal template blocks
var $_current_file = null; // the current template being compiled
var $_current_current_line_no = 1; // line number for error messages
/*======================================================================*\ /*======================================================================*\
@@ -326,11 +328,13 @@ class Smarty
function _compile_file($filepath, $compilepath) function _compile_file($filepath, $compilepath)
{ {
if(!($template_contents = $this->_read_file($filepath))) if (!($template_contents = $this->_read_file($filepath)))
return false; return false;
$ldq = preg_quote($this->left_delimiter, "!"); $this->_current_file = str_replace($this->template_dir . "/", "", $filepath);
$rdq = preg_quote($this->right_delimiter, "!"); $this->_current_line_no = 1;
$ldq = preg_quote($this->left_delimiter, '!');
$rdq = preg_quote($this->right_delimiter, '!');
/* Pull out the literal blocks. */ /* Pull out the literal blocks. */
preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_contents, $match); preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_contents, $match);
@@ -350,11 +354,13 @@ class Smarty
/* Compile the template tags into PHP code. */ /* Compile the template tags into PHP code. */
$compiled_tags = array(); $compiled_tags = array();
foreach ($template_tags as $template_tag) for ($i = 0; $i < count($template_tags); $i++) {
$compiled_tags[] = $this->_compile_tag($template_tag); $this->_current_line_no += substr_count($text_blocks[$i], "\n");
$compiled_tags[] = $this->_compile_tag($template_tags[$i]);
$this->_current_line_no += substr_count($template_tags[$i], "\n");
}
/* Interleave the compiled contents and text blocks to get the final /* Interleave the compiled contents and text blocks to get the final result. */
result. */
for ($i = 0; $i < count($compiled_tags); $i++) { for ($i = 0; $i < count($compiled_tags); $i++) {
$compiled_contents .= $text_blocks[$i].$compiled_tags[$i]; $compiled_contents .= $text_blocks[$i].$compiled_tags[$i];
} }
@@ -445,6 +451,7 @@ class Smarty
case 'literal': case 'literal':
list (,$literal_block) = each($this->_literal_blocks); list (,$literal_block) = each($this->_literal_blocks);
$this->_current_line_no += substr_count($literal_block, "\n");
return $literal_block; return $literal_block;
case 'insert': case 'insert':
@@ -454,7 +461,7 @@ class Smarty
if (isset($this->custom_funcs[$tag_command])) { if (isset($this->custom_funcs[$tag_command])) {
return $this->_compile_custom_tag($tag_command, $tag_args); return $this->_compile_custom_tag($tag_command, $tag_args);
} else { } else {
trigger_error("Smarty: syntax error: unknown tag - '$tag_command'", E_USER_WARNING); $this->_syntax_error("unknown tag - '$tag_command'", E_USER_WARNING);
return ""; return "";
} }
} }
@@ -481,7 +488,7 @@ class Smarty
$name = substr($attrs['name'], 1, -1); $name = substr($attrs['name'], 1, -1);
if (empty($name)) { if (empty($name)) {
trigger_error("Smarty: syntax error: missing insert name", E_USER_ERROR); $this->_syntax_error("missing insert name");
} }
foreach ($attrs as $arg_name => $arg_value) { foreach ($attrs as $arg_name => $arg_value) {
@@ -500,7 +507,7 @@ class Smarty
$attrs = $this->_parse_attrs($tag_args); $attrs = $this->_parse_attrs($tag_args);
if (empty($attrs['file'])) { if (empty($attrs['file'])) {
trigger_error("Smarty: syntax error: missing 'file' attribute in config_load tag", E_USER_ERROR); $this->_syntax_error("missing 'file' attribute in config_load tag");
} }
$output = "<?php if (!class_exists('Config_File'))\n" . $output = "<?php if (!class_exists('Config_File'))\n" .
@@ -524,7 +531,7 @@ class Smarty
$attrs = $this->_parse_attrs($tag_args); $attrs = $this->_parse_attrs($tag_args);
if (empty($attrs['file'])) { if (empty($attrs['file'])) {
trigger_error("Smarty: syntax error: missing 'file' attribute in include tag", E_USER_ERROR); $this->_syntax_error("missing 'file' attribute in include tag");
} else } else
$attrs['file'] = $this->_dequote($attrs['file']); $attrs['file'] = $this->_dequote($attrs['file']);
@@ -558,7 +565,7 @@ class Smarty
$output = "<?php\n"; $output = "<?php\n";
$section_name = $attrs['name']; $section_name = $attrs['name'];
if (empty($section_name)) { if (empty($section_name)) {
trigger_error("Smarty: syntax error: missing section name", E_USER_ERROR); $this->_syntax_error("missing section name");
} }
$output .= "unset(\$_sections[$section_name]);\n"; $output .= "unset(\$_sections[$section_name]);\n";
@@ -744,12 +751,12 @@ class Smarty
$expr_arg = $tokens[$expr_end++]; $expr_arg = $tokens[$expr_end++];
$expr = "!($is_arg % $expr_arg)"; $expr = "!($is_arg % $expr_arg)";
} else { } else {
trigger_error("Smarty: syntax error: expecting 'by' after 'div'", E_USER_ERROR); $this->_syntax_error("expecting 'by' after 'div'");
} }
break; break;
default: default:
trigger_error("Smarty: syntax error: unknown 'is' expression - '$expr_type'", E_USER_ERROR); $this->_syntax_error("unknown 'is' expression - '$expr_type'");
break; break;
} }
@@ -789,7 +796,7 @@ class Smarty
$attr_name = $token; $attr_name = $token;
$state = 1; $state = 1;
} else } else
trigger_error("Smarty: syntax error: invalid attribute name - '$token'", E_USER_ERROR); $this->_syntax_error("invalid attribute name - '$token'");
break; break;
case 1: case 1:
@@ -802,7 +809,7 @@ class Smarty
if ($token == '=') { if ($token == '=') {
$state = 2; $state = 2;
} else } else
trigger_error("Smarty: syntax error: expecting '=' after attribute name", E_USER_ERROR); $this->_syntax_error("expecting '=' after attribute name");
break; break;
case 2: case 2:
@@ -826,7 +833,7 @@ class Smarty
$attrs[$attr_name] = $token; $attrs[$attr_name] = $token;
$state = 0; $state = 0;
} else } else
trigger_error("Smarty: syntax error: '=' cannot be an attribute value", E_USER_ERROR); $this->_syntax_error("'=' cannot be an attribute value");
break; break;
} }
} }
@@ -1024,6 +1031,15 @@ class Smarty
return true; return true;
} }
/*======================================================================*\
Function: _syntax_error
Purpose: display Smarty syntax error
\*======================================================================*/
function _syntax_error($error_msg, $error_type = E_USER_ERROR)
{
trigger_error("Smarty: [in " . $this->_current_file . " line " .
$this->_current_line_no . "]: syntax error: $error_msg", $error_type);
}
} }
?> ?>

View File

@@ -8,7 +8,6 @@
Title: {#title#|capitalize} Title: {#title#|capitalize}
{if #bold#}</b>{/if} {if #bold#}</b>{/if}
the value of $SCRIPT_NAME is {$SCRIPT_NAME} the value of $SCRIPT_NAME is {$SCRIPT_NAME}
{* A simple variable test. print $Name in uppercase *} {* A simple variable test. print $Name in uppercase *}
@@ -34,6 +33,8 @@ testing
<p> <p>
{%^^^}
testing strip tags testing strip tags
{strip} {strip}
<table border=0> <table border=0>

View File

@@ -5,7 +5,7 @@
* Author: Monte Ohrt <monte@ispi.net> * Author: Monte Ohrt <monte@ispi.net>
* Andrei Zmievski <andrei@ispi.net> * Andrei Zmievski <andrei@ispi.net>
* *
* Version: 1.1.0 * Version: 1.2.0
* Copyright: 2001 ispi of Lincoln, Inc. * Copyright: 2001 ispi of Lincoln, Inc.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@@ -88,6 +88,8 @@ class Smarty
var $_tpl_vars = array(); var $_tpl_vars = array();
var $_sectionelse_stack = array(); // keeps track of whether section had 'else' part var $_sectionelse_stack = array(); // keeps track of whether section had 'else' part
var $_literal_blocks = array(); // keeps literal template blocks var $_literal_blocks = array(); // keeps literal template blocks
var $_current_file = null; // the current template being compiled
var $_current_current_line_no = 1; // line number for error messages
/*======================================================================*\ /*======================================================================*\
@@ -326,11 +328,13 @@ class Smarty
function _compile_file($filepath, $compilepath) function _compile_file($filepath, $compilepath)
{ {
if(!($template_contents = $this->_read_file($filepath))) if (!($template_contents = $this->_read_file($filepath)))
return false; return false;
$ldq = preg_quote($this->left_delimiter, "!"); $this->_current_file = str_replace($this->template_dir . "/", "", $filepath);
$rdq = preg_quote($this->right_delimiter, "!"); $this->_current_line_no = 1;
$ldq = preg_quote($this->left_delimiter, '!');
$rdq = preg_quote($this->right_delimiter, '!');
/* Pull out the literal blocks. */ /* Pull out the literal blocks. */
preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_contents, $match); preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_contents, $match);
@@ -350,11 +354,13 @@ class Smarty
/* Compile the template tags into PHP code. */ /* Compile the template tags into PHP code. */
$compiled_tags = array(); $compiled_tags = array();
foreach ($template_tags as $template_tag) for ($i = 0; $i < count($template_tags); $i++) {
$compiled_tags[] = $this->_compile_tag($template_tag); $this->_current_line_no += substr_count($text_blocks[$i], "\n");
$compiled_tags[] = $this->_compile_tag($template_tags[$i]);
$this->_current_line_no += substr_count($template_tags[$i], "\n");
}
/* Interleave the compiled contents and text blocks to get the final /* Interleave the compiled contents and text blocks to get the final result. */
result. */
for ($i = 0; $i < count($compiled_tags); $i++) { for ($i = 0; $i < count($compiled_tags); $i++) {
$compiled_contents .= $text_blocks[$i].$compiled_tags[$i]; $compiled_contents .= $text_blocks[$i].$compiled_tags[$i];
} }
@@ -445,6 +451,7 @@ class Smarty
case 'literal': case 'literal':
list (,$literal_block) = each($this->_literal_blocks); list (,$literal_block) = each($this->_literal_blocks);
$this->_current_line_no += substr_count($literal_block, "\n");
return $literal_block; return $literal_block;
case 'insert': case 'insert':
@@ -454,7 +461,7 @@ class Smarty
if (isset($this->custom_funcs[$tag_command])) { if (isset($this->custom_funcs[$tag_command])) {
return $this->_compile_custom_tag($tag_command, $tag_args); return $this->_compile_custom_tag($tag_command, $tag_args);
} else { } else {
trigger_error("Smarty: syntax error: unknown tag - '$tag_command'", E_USER_WARNING); $this->_syntax_error("unknown tag - '$tag_command'", E_USER_WARNING);
return ""; return "";
} }
} }
@@ -481,7 +488,7 @@ class Smarty
$name = substr($attrs['name'], 1, -1); $name = substr($attrs['name'], 1, -1);
if (empty($name)) { if (empty($name)) {
trigger_error("Smarty: syntax error: missing insert name", E_USER_ERROR); $this->_syntax_error("missing insert name");
} }
foreach ($attrs as $arg_name => $arg_value) { foreach ($attrs as $arg_name => $arg_value) {
@@ -500,7 +507,7 @@ class Smarty
$attrs = $this->_parse_attrs($tag_args); $attrs = $this->_parse_attrs($tag_args);
if (empty($attrs['file'])) { if (empty($attrs['file'])) {
trigger_error("Smarty: syntax error: missing 'file' attribute in config_load tag", E_USER_ERROR); $this->_syntax_error("missing 'file' attribute in config_load tag");
} }
$output = "<?php if (!class_exists('Config_File'))\n" . $output = "<?php if (!class_exists('Config_File'))\n" .
@@ -524,7 +531,7 @@ class Smarty
$attrs = $this->_parse_attrs($tag_args); $attrs = $this->_parse_attrs($tag_args);
if (empty($attrs['file'])) { if (empty($attrs['file'])) {
trigger_error("Smarty: syntax error: missing 'file' attribute in include tag", E_USER_ERROR); $this->_syntax_error("missing 'file' attribute in include tag");
} else } else
$attrs['file'] = $this->_dequote($attrs['file']); $attrs['file'] = $this->_dequote($attrs['file']);
@@ -558,7 +565,7 @@ class Smarty
$output = "<?php\n"; $output = "<?php\n";
$section_name = $attrs['name']; $section_name = $attrs['name'];
if (empty($section_name)) { if (empty($section_name)) {
trigger_error("Smarty: syntax error: missing section name", E_USER_ERROR); $this->_syntax_error("missing section name");
} }
$output .= "unset(\$_sections[$section_name]);\n"; $output .= "unset(\$_sections[$section_name]);\n";
@@ -744,12 +751,12 @@ class Smarty
$expr_arg = $tokens[$expr_end++]; $expr_arg = $tokens[$expr_end++];
$expr = "!($is_arg % $expr_arg)"; $expr = "!($is_arg % $expr_arg)";
} else { } else {
trigger_error("Smarty: syntax error: expecting 'by' after 'div'", E_USER_ERROR); $this->_syntax_error("expecting 'by' after 'div'");
} }
break; break;
default: default:
trigger_error("Smarty: syntax error: unknown 'is' expression - '$expr_type'", E_USER_ERROR); $this->_syntax_error("unknown 'is' expression - '$expr_type'");
break; break;
} }
@@ -789,7 +796,7 @@ class Smarty
$attr_name = $token; $attr_name = $token;
$state = 1; $state = 1;
} else } else
trigger_error("Smarty: syntax error: invalid attribute name - '$token'", E_USER_ERROR); $this->_syntax_error("invalid attribute name - '$token'");
break; break;
case 1: case 1:
@@ -802,7 +809,7 @@ class Smarty
if ($token == '=') { if ($token == '=') {
$state = 2; $state = 2;
} else } else
trigger_error("Smarty: syntax error: expecting '=' after attribute name", E_USER_ERROR); $this->_syntax_error("expecting '=' after attribute name");
break; break;
case 2: case 2:
@@ -826,7 +833,7 @@ class Smarty
$attrs[$attr_name] = $token; $attrs[$attr_name] = $token;
$state = 0; $state = 0;
} else } else
trigger_error("Smarty: syntax error: '=' cannot be an attribute value", E_USER_ERROR); $this->_syntax_error("'=' cannot be an attribute value");
break; break;
} }
} }
@@ -1024,6 +1031,15 @@ class Smarty
return true; return true;
} }
/*======================================================================*\
Function: _syntax_error
Purpose: display Smarty syntax error
\*======================================================================*/
function _syntax_error($error_msg, $error_type = E_USER_ERROR)
{
trigger_error("Smarty: [in " . $this->_current_file . " line " .
$this->_current_line_no . "]: syntax error: $error_msg", $error_type);
}
} }
?> ?>

View File

@@ -8,7 +8,6 @@
Title: {#title#|capitalize} Title: {#title#|capitalize}
{if #bold#}</b>{/if} {if #bold#}</b>{/if}
the value of $SCRIPT_NAME is {$SCRIPT_NAME} the value of $SCRIPT_NAME is {$SCRIPT_NAME}
{* A simple variable test. print $Name in uppercase *} {* A simple variable test. print $Name in uppercase *}
@@ -34,6 +33,8 @@ testing
<p> <p>
{%^^^}
testing strip tags testing strip tags
{strip} {strip}
<table border=0> <table border=0>