mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
fixed literal tags and other optional delimiters
This commit is contained in:
@@ -273,6 +273,53 @@ function smarty_func_html_select_date()
|
||||
print $html_result;
|
||||
}
|
||||
|
||||
function smarty_func_math() {
|
||||
$args=func_get_arg(0);
|
||||
|
||||
// be sure equation parameter is present
|
||||
if(empty($args["equation"])) {
|
||||
trigger_error("math: missing equation parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
$equation = $args["equation"];
|
||||
|
||||
// make sure parenthesis are balanced
|
||||
if(substr_count($equation,"(") != substr_count($equation,")")) {
|
||||
trigger_error("math: unbalanced parenthesis");
|
||||
return;
|
||||
}
|
||||
|
||||
// match all vars in equation, make sure all are passed
|
||||
preg_match_all("![a-zA-Z][a-zA-Z0-9]*!",$equation,$match);
|
||||
|
||||
foreach($match[0] as $curr_var) {
|
||||
if(!in_array($curr_var,array_keys($args)) &&
|
||||
!in_array($curr_var,array('abs','ceil','cos','exp','floor','log','log10',
|
||||
'max','min','pi','pow','rand','round','sin','sqrt','srand','tan')) ) {
|
||||
trigger_error("math: parameter $curr_var not passed as argument");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($args as $key => $val) {
|
||||
if($key != "equation") {
|
||||
// make sure value is not empty
|
||||
if(strlen($val)==0) {
|
||||
trigger_error("math: parameter $key is empty");
|
||||
return;
|
||||
}
|
||||
if(!is_numeric($val)) {
|
||||
trigger_error("math: parameter $key: is not numeric");
|
||||
return;
|
||||
}
|
||||
$equation = preg_replace("/\b$key\b/",$val,$equation);
|
||||
}
|
||||
}
|
||||
|
||||
eval("echo ".$equation.";");
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
||||
?>
|
||||
|
@@ -85,7 +85,8 @@ class Smarty
|
||||
|
||||
|
||||
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
||||
'html_select_date' => 'smarty_func_html_select_date'
|
||||
'html_select_date' => 'smarty_func_html_select_date',
|
||||
'math' => 'smarty_func_math'
|
||||
);
|
||||
|
||||
var $custom_mods = array( 'lower' => 'strtolower',
|
||||
@@ -510,7 +511,7 @@ class Smarty
|
||||
preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_contents, $match);
|
||||
$this->_literal_blocks = $match[1];
|
||||
$template_contents = preg_replace("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s",
|
||||
'{literal}', $template_contents);
|
||||
$this->quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $template_contents);
|
||||
|
||||
/* Gather all template tags. */
|
||||
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_contents, $match);
|
||||
@@ -1350,6 +1351,14 @@ class Smarty
|
||||
return true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: quote_replace
|
||||
Purpose: Quote subpattern references
|
||||
\*======================================================================*/
|
||||
function quote_replace($string)
|
||||
{
|
||||
return preg_replace('![\\$]\d!', '\\\\\\0', $string);
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _set_error_msg()
|
||||
|
37
docs.sgml
37
docs.sgml
@@ -694,7 +694,7 @@ $smarty->display("index.tpl");
|
||||
</example>
|
||||
<para>
|
||||
You can also pass a cache id as an an optional second parameter
|
||||
in the case you want multiple caches for the given template.
|
||||
in case you want multiple caches for the given template.
|
||||
</para>
|
||||
<example>
|
||||
<title>is_cached with multiple-cache template</title>
|
||||
@@ -1566,7 +1566,7 @@ e-mail: jane@mydomain.com<p>
|
||||
<title>sectionelse</title>
|
||||
<programlisting>
|
||||
|
||||
{* sectionelse will execute in the case there are no $custid values *}
|
||||
{* sectionelse will execute if there are no $custid values *}
|
||||
{section name=customer loop=$custid}
|
||||
id: {$customer/custid}<br>
|
||||
{sectionelse}
|
||||
@@ -2639,6 +2639,35 @@ OUTPUT:
|
||||
If Strike isn't Settled Quickly it may Last a While.
|
||||
IF STRIKE ISN'T SETTLED QUICKLY IT MAY LAST A WHILE.
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>Combining Modifiers</title>
|
||||
<para>
|
||||
You can combine as many modifiers as you like on a single variable.
|
||||
This allows the ability to combine the application of different
|
||||
modifiers to a single variable. The modifiers will be applied to
|
||||
the variable in the order they are combined, from left to right.
|
||||
</para>
|
||||
<example>
|
||||
<title>combining modifiers</title>
|
||||
<programlisting>
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|upper|spacify}
|
||||
{$articleTitle|lower|spacify|truncate}
|
||||
{$articleTitle|lower|truncate:30|spacify}
|
||||
{$articleTitle|lower|spacify|truncate:30:". . ."}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
Smokers are Productive, but Death Cuts Efficiency.
|
||||
S M O K E R S A R E P R O D U C T I V E , B U T D E A T H C U T S E F F I C I E N C Y .
|
||||
s m o k e r s a r e p r o d u c t i v e , b u t d e a t h c u t s...
|
||||
s m o k e r s a r e p r o d u c t i v e , b u t . . .
|
||||
s m o k e r s a r e p. . .
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect2>
|
||||
@@ -2829,8 +2858,8 @@ function makeTimeStamp($year="",$month="",$day="")
|
||||
added other features too numerous to mention.
|
||||
</para>
|
||||
<para>
|
||||
Anne Holz <anne@ispi.net>: Many of Smarty's formatting features were
|
||||
a direct result of needs from her department.
|
||||
Anne Holz <anne@ispi.net>: Provided creative input with respect
|
||||
to web design.
|
||||
</para>
|
||||
<para>
|
||||
Frank Kromann <fmk@php.net>: Idea of custom function ability.
|
||||
|
@@ -85,7 +85,8 @@ class Smarty
|
||||
|
||||
|
||||
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
||||
'html_select_date' => 'smarty_func_html_select_date'
|
||||
'html_select_date' => 'smarty_func_html_select_date',
|
||||
'math' => 'smarty_func_math'
|
||||
);
|
||||
|
||||
var $custom_mods = array( 'lower' => 'strtolower',
|
||||
@@ -510,7 +511,7 @@ class Smarty
|
||||
preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_contents, $match);
|
||||
$this->_literal_blocks = $match[1];
|
||||
$template_contents = preg_replace("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s",
|
||||
'{literal}', $template_contents);
|
||||
$this->quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $template_contents);
|
||||
|
||||
/* Gather all template tags. */
|
||||
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_contents, $match);
|
||||
@@ -1350,6 +1351,14 @@ class Smarty
|
||||
return true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: quote_replace
|
||||
Purpose: Quote subpattern references
|
||||
\*======================================================================*/
|
||||
function quote_replace($string)
|
||||
{
|
||||
return preg_replace('![\\$]\d!', '\\\\\\0', $string);
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _set_error_msg()
|
||||
|
Reference in New Issue
Block a user