add default modifier logic, minor doc updates

This commit is contained in:
mohrt
2002-07-17 21:16:43 +00:00
parent a3cb1ccb16
commit 8fc32e427f
5 changed files with 31 additions and 9 deletions

View File

@@ -152,6 +152,9 @@ class Smarty
// sub directories are more efficient, but
// you can set this to false if your PHP environment
// does not allow the creation of them.
var $default_modifiers = '';
// modifier string to implicitly append to every var
// example: '|escape:"htmlall"'
/**************************************************************************/
/* END SMARTY CONFIGURATION SECTION */
@@ -1073,6 +1076,7 @@ function _generate_debug_output() {
$smarty_compiler->trusted_dir = $this->trusted_dir;
$smarty_compiler->_plugins = &$this->_plugins;
$smarty_compiler->_tpl_vars = &$this->_tpl_vars;
$smarty_compiler->default_modifiers = $this->default_modifiers;
if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled))
return true;

View File

@@ -1109,6 +1109,13 @@ class Smarty_Compiler extends Smarty {
$var_ref = $parts[0];
$modifiers = isset($parts[1]) ? $parts[1] : '';
if(!empty($this->default_modifiers) && !strstr($modifiers,'smarty:nodefaults')) {
$modifiers = empty($modifiers) ? $this->default_modifiers : $this->default_modifiers . '|' . $modifiers;
}
$modifiers = str_replace(array('smarty:nodefaults','||'),array('','|'),$modifiers);
preg_match_all('!\[(?:\$\w+|\w+(\.\w+)?)\]|(->|\.)\$?\w+|^\w+!', $var_ref, $match);
$indexes = $match[0];
$var_name = array_shift($indexes);

View File

@@ -670,7 +670,7 @@ no title</programlisting>
<entry>1</entry>
<entry>string</entry>
<entry>No</entry>
<entry>html,url,quotes,hex,hexentity</entry>
<entry>html,htmlall,url,quotes,hex,hexentity</entry>
<entry>html</entry>
<entry>This is the escape format to use.</entry>
</row>
@@ -678,12 +678,12 @@ no title</programlisting>
</tgroup>
</informaltable>
<para>
This is used to html (or htmlall) escape, url escape, escape single
quotes on a variable not already escaped, hex escape or hexentity
escape. hex and hexentity escape can be used in conjunction to hide
"mailto:" links on a page from web spiders (spam collectors) and
yet keep them readable and linkable. By default, the variable is
html escaped.
This is used to html escape, url escape, escape single quotes on a
variable not already escaped, hex escape or hexentity escape. hex
and hexentity escape can be used in conjunction to hide "mailto:"
links on a page from web spiders (spam collectors) and yet keep
them readable and linkable. By default, the variable is html
escaped.
</para>
<example>
<title>escape</title>
@@ -1195,8 +1195,8 @@ Blind woman gets new kidney&lt;br&gt;
from dad she hasn't seen in years.
Blind woman gets new kidney fr
om dad she hasn't seen in
years.</programlisting>
om dad she hasn't seen in year
s.</programlisting>
</example>
</sect1>

View File

@@ -152,6 +152,9 @@ class Smarty
// sub directories are more efficient, but
// you can set this to false if your PHP environment
// does not allow the creation of them.
var $default_modifiers = '';
// modifier string to implicitly append to every var
// example: '|escape:"htmlall"'
/**************************************************************************/
/* END SMARTY CONFIGURATION SECTION */
@@ -1073,6 +1076,7 @@ function _generate_debug_output() {
$smarty_compiler->trusted_dir = $this->trusted_dir;
$smarty_compiler->_plugins = &$this->_plugins;
$smarty_compiler->_tpl_vars = &$this->_tpl_vars;
$smarty_compiler->default_modifiers = $this->default_modifiers;
if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled))
return true;

View File

@@ -1109,6 +1109,13 @@ class Smarty_Compiler extends Smarty {
$var_ref = $parts[0];
$modifiers = isset($parts[1]) ? $parts[1] : '';
if(!empty($this->default_modifiers) && !strstr($modifiers,'smarty:nodefaults')) {
$modifiers = empty($modifiers) ? $this->default_modifiers : $this->default_modifiers . '|' . $modifiers;
}
$modifiers = str_replace(array('smarty:nodefaults','||'),array('','|'),$modifiers);
preg_match_all('!\[(?:\$\w+|\w+(\.\w+)?)\]|(->|\.)\$?\w+|^\w+!', $var_ref, $match);
$indexes = $match[0];
$var_name = array_shift($indexes);