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;
|
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: */
|
/* vim: set expandtab: */
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@@ -85,7 +85,8 @@ class Smarty
|
|||||||
|
|
||||||
|
|
||||||
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
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',
|
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);
|
preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_contents, $match);
|
||||||
$this->_literal_blocks = $match[1];
|
$this->_literal_blocks = $match[1];
|
||||||
$template_contents = preg_replace("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s",
|
$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. */
|
/* Gather all template tags. */
|
||||||
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_contents, $match);
|
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_contents, $match);
|
||||||
@@ -1350,6 +1351,14 @@ class Smarty
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*======================================================================*\
|
||||||
|
Function: quote_replace
|
||||||
|
Purpose: Quote subpattern references
|
||||||
|
\*======================================================================*/
|
||||||
|
function quote_replace($string)
|
||||||
|
{
|
||||||
|
return preg_replace('![\\$]\d!', '\\\\\\0', $string);
|
||||||
|
}
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _set_error_msg()
|
Function: _set_error_msg()
|
||||||
|
@@ -10,10 +10,10 @@ $smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
|
|||||||
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
|
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
|
||||||
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
|
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
|
||||||
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
|
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
|
||||||
array("I", "J", "K", "L"), array("M", "N", "O", "P")));
|
array("I", "J", "K", "L"), array("M", "N", "O", "P")));
|
||||||
|
|
||||||
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||||
|
|
||||||
$smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX"));
|
$smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX"));
|
||||||
$smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
|
$smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
|
||||||
|
37
docs.sgml
37
docs.sgml
@@ -694,7 +694,7 @@ $smarty->display("index.tpl");
|
|||||||
</example>
|
</example>
|
||||||
<para>
|
<para>
|
||||||
You can also pass a cache id as an an optional second parameter
|
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>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>is_cached with multiple-cache template</title>
|
<title>is_cached with multiple-cache template</title>
|
||||||
@@ -1566,7 +1566,7 @@ e-mail: jane@mydomain.com<p>
|
|||||||
<title>sectionelse</title>
|
<title>sectionelse</title>
|
||||||
<programlisting>
|
<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}
|
{section name=customer loop=$custid}
|
||||||
id: {$customer/custid}<br>
|
id: {$customer/custid}<br>
|
||||||
{sectionelse}
|
{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.
|
||||||
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>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect2>
|
</sect2>
|
||||||
@@ -2829,8 +2858,8 @@ function makeTimeStamp($year="",$month="",$day="")
|
|||||||
added other features too numerous to mention.
|
added other features too numerous to mention.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Anne Holz <anne@ispi.net>: Many of Smarty's formatting features were
|
Anne Holz <anne@ispi.net>: Provided creative input with respect
|
||||||
a direct result of needs from her department.
|
to web design.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Frank Kromann <fmk@php.net>: Idea of custom function ability.
|
Frank Kromann <fmk@php.net>: Idea of custom function ability.
|
||||||
|
@@ -10,10 +10,10 @@ $smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
|
|||||||
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
|
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
|
||||||
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
|
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
|
||||||
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
|
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
|
||||||
array("I", "J", "K", "L"), array("M", "N", "O", "P")));
|
array("I", "J", "K", "L"), array("M", "N", "O", "P")));
|
||||||
|
|
||||||
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||||
|
|
||||||
$smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX"));
|
$smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX"));
|
||||||
$smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
|
$smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
|
||||||
|
@@ -85,7 +85,8 @@ class Smarty
|
|||||||
|
|
||||||
|
|
||||||
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
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',
|
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);
|
preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_contents, $match);
|
||||||
$this->_literal_blocks = $match[1];
|
$this->_literal_blocks = $match[1];
|
||||||
$template_contents = preg_replace("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s",
|
$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. */
|
/* Gather all template tags. */
|
||||||
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_contents, $match);
|
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_contents, $match);
|
||||||
@@ -1350,6 +1351,14 @@ class Smarty
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*======================================================================*\
|
||||||
|
Function: quote_replace
|
||||||
|
Purpose: Quote subpattern references
|
||||||
|
\*======================================================================*/
|
||||||
|
function quote_replace($string)
|
||||||
|
{
|
||||||
|
return preg_replace('![\\$]\d!', '\\\\\\0', $string);
|
||||||
|
}
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _set_error_msg()
|
Function: _set_error_msg()
|
||||||
|
Reference in New Issue
Block a user