See changelog.

This commit is contained in:
andrey
2001-02-02 16:55:55 +00:00
parent fa325b0a0d
commit 2a90f7392a
5 changed files with 83 additions and 20 deletions

5
NEWS
View File

@@ -1,3 +1,8 @@
- made Smarty catch unimplemented modifiers and custom functions and output
error messages during compilation instead of failing during run time.
(Andrei)
- added register_custom_function() and register_modifier() API calls
to make registering stuff easier. (Andrei)
- added template results caching capability. (Monte, Andrei)
- added optional 'options' attribute to html_options custom function
that allows passing associative arrays for values/output. (Andrei)

View File

@@ -69,7 +69,7 @@ class Smarty
// 0 = never expires. default is one hour (3600)
var $tpl_file_ext = ".tpl"; // template file extentions
var $tpl_file_ext = ".tpl"; // template files extention
var $allow_php = false; // whether or not to allow embedded php
// in the templates. By default, php tags
@@ -170,6 +170,27 @@ class Smarty
unset($this->_tpl_vars[$tpl_var]);
}
/*======================================================================*\
Function: register_custom_function
Purpose: Registers custom function to be used in templates
\*======================================================================*/
function register_custom_function($function, $function_impl)
{
$this->custom_funcs[$function] = $function_impl;
}
/*======================================================================*\
Function: register_modifier
Purpose: Registers modifier to be used in templates
\*======================================================================*/
function register_modifier($modifier, $modifier_impl)
{
$this->custom_mods[$modifier] = $modifier_impl;
}
/*======================================================================*\
Function: clear_cache()
Purpose: clear all cached template files for given template
@@ -491,7 +512,7 @@ class Smarty
\*======================================================================*/
function _process_cached_inserts($results)
{
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'\n??!Uis',
$results, $match);
list($cached_inserts, $insert_args) = $match;
@@ -499,10 +520,6 @@ class Smarty
$attrs = $this->_parse_attrs($insert_args[$i], false);
$name = $this->_dequote($attrs['name']);
if (empty($name)) {
$this->_syntax_error("missing insert name");
}
$arg_list = array();
foreach ($attrs as $arg_name => $arg_value) {
if ($arg_name == 'name') continue;
@@ -600,15 +617,21 @@ class Smarty
return $this->_compile_custom_tag($tag_command, $tag_args);
} else {
$this->_syntax_error("unknown tag - '$tag_command'", E_USER_WARNING);
return "";
return;
}
}
}
function _compile_custom_tag($tag_command, $tag_args)
{
$attrs = $this->_parse_attrs($tag_args);
$function = $this->custom_funcs[$tag_command];
if (!function_exists($function)) {
$this->_syntax_error("custom function '$tag_command' is not implemented", E_USER_WARNING);
return;
}
$attrs = $this->_parse_attrs($tag_args);
foreach ($attrs as $arg_name => $arg_value) {
if (is_bool($arg_value))
$arg_value = $arg_value ? 'true' : 'false';
@@ -1104,6 +1127,11 @@ class Smarty
if (!isset($mod_func_name))
$mod_func_name = $modifier_name;
if (!function_exists($mod_func_name)) {
$this->_syntax_error("modifier '$modifier_name' is not implemented", E_USER_WARNING);
continue;
}
$this->_parse_vars_props($modifier_args);
if (count($modifier_args) > 0)

View File

@@ -47,7 +47,8 @@ testing strip tags
</PRE>
{insert name = foo
arg1=5}
test: {$now|date_format:"%I:%M %p"}
{insert name = foo arg1=5}

View File

@@ -69,7 +69,7 @@ class Smarty
// 0 = never expires. default is one hour (3600)
var $tpl_file_ext = ".tpl"; // template file extentions
var $tpl_file_ext = ".tpl"; // template files extention
var $allow_php = false; // whether or not to allow embedded php
// in the templates. By default, php tags
@@ -170,6 +170,27 @@ class Smarty
unset($this->_tpl_vars[$tpl_var]);
}
/*======================================================================*\
Function: register_custom_function
Purpose: Registers custom function to be used in templates
\*======================================================================*/
function register_custom_function($function, $function_impl)
{
$this->custom_funcs[$function] = $function_impl;
}
/*======================================================================*\
Function: register_modifier
Purpose: Registers modifier to be used in templates
\*======================================================================*/
function register_modifier($modifier, $modifier_impl)
{
$this->custom_mods[$modifier] = $modifier_impl;
}
/*======================================================================*\
Function: clear_cache()
Purpose: clear all cached template files for given template
@@ -491,7 +512,7 @@ class Smarty
\*======================================================================*/
function _process_cached_inserts($results)
{
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'\n??!Uis',
$results, $match);
list($cached_inserts, $insert_args) = $match;
@@ -499,10 +520,6 @@ class Smarty
$attrs = $this->_parse_attrs($insert_args[$i], false);
$name = $this->_dequote($attrs['name']);
if (empty($name)) {
$this->_syntax_error("missing insert name");
}
$arg_list = array();
foreach ($attrs as $arg_name => $arg_value) {
if ($arg_name == 'name') continue;
@@ -600,15 +617,21 @@ class Smarty
return $this->_compile_custom_tag($tag_command, $tag_args);
} else {
$this->_syntax_error("unknown tag - '$tag_command'", E_USER_WARNING);
return "";
return;
}
}
}
function _compile_custom_tag($tag_command, $tag_args)
{
$attrs = $this->_parse_attrs($tag_args);
$function = $this->custom_funcs[$tag_command];
if (!function_exists($function)) {
$this->_syntax_error("custom function '$tag_command' is not implemented", E_USER_WARNING);
return;
}
$attrs = $this->_parse_attrs($tag_args);
foreach ($attrs as $arg_name => $arg_value) {
if (is_bool($arg_value))
$arg_value = $arg_value ? 'true' : 'false';
@@ -1104,6 +1127,11 @@ class Smarty
if (!isset($mod_func_name))
$mod_func_name = $modifier_name;
if (!function_exists($mod_func_name)) {
$this->_syntax_error("modifier '$modifier_name' is not implemented", E_USER_WARNING);
continue;
}
$this->_parse_vars_props($modifier_args);
if (count($modifier_args) > 0)

View File

@@ -47,7 +47,8 @@ testing strip tags
</PRE>
{insert name = foo
arg1=5}
test: {$now|date_format:"%I:%M %p"}
{insert name = foo arg1=5}