Added index_prev, index_next section properties and ability to

index by them.
This commit is contained in:
andrey
2001-02-26 16:50:04 +00:00
parent b557a5c100
commit ea1f3ded5a
3 changed files with 24 additions and 11 deletions

5
NEWS
View File

@@ -1,4 +1,7 @@
- fixed issue with php executing in literal blocks (Monte) - added ability to index looped variables by section properties, e.g.
$foo.index_prev/bar. (Andrei)
- added index_prev and index_next section properties. (Andrei)
- fixed issue with php executing in literal blocks. (Monte)
Version 1.3.0 Version 1.3.0
------------- -------------

View File

@@ -628,7 +628,7 @@ class Smarty
/* If the tag name matches a variable or section property definition, /* If the tag name matches a variable or section property definition,
we simply process it. */ we simply process it. */
if (preg_match('!^\$(\w+/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // if a variable if (preg_match('!^\$(\w+(\.\w+)?/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // if a variable
preg_match('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // or a configuration variable preg_match('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // or a configuration variable
preg_match('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command)) { // or a section property preg_match('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command)) { // or a section property
settype($tag_command, 'array'); settype($tag_command, 'array');
@@ -861,6 +861,8 @@ class Smarty
{$section_props}['index'] < {$section_props}['loop']; {$section_props}['index'] < {$section_props}['loop'];
{$section_props}['index']++):\n"; {$section_props}['index']++):\n";
$output .= "{$section_props}['rownum'] = {$section_props}['index'] + 1;\n"; $output .= "{$section_props}['rownum'] = {$section_props}['index'] + 1;\n";
$output .= "{$section_props}['index_prev'] = {$section_props}['index'] - 1;\n";
$output .= "{$section_props}['index_next'] = {$section_props}['index'] + 1;\n";
$output .= "?>"; $output .= "?>";
@@ -1126,11 +1128,11 @@ class Smarty
allow people to use older versions of PHP we emulate preg_grep() and allow people to use older versions of PHP we emulate preg_grep() and
use the version check to see what function to call. */ use the version check to see what function to call. */
if (strnatcmp(PHP_VERSION, '4.0.4') >= 0) { if (strnatcmp(PHP_VERSION, '4.0.4') >= 0) {
$var_exprs = preg_grep('!^\$(\w+/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $var_exprs = preg_grep('!^\$(\w+(\.\w+)?/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
$conf_var_exprs = preg_grep('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $conf_var_exprs = preg_grep('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
$sect_prop_exprs = preg_grep('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $sect_prop_exprs = preg_grep('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
} else { } else {
$var_exprs = $this->_preg_grep('!^\$(\w+/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $var_exprs = $this->_preg_grep('!^\$(\w+(\.\w+)?/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
$conf_var_exprs = $this->_preg_grep('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $conf_var_exprs = $this->_preg_grep('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
$sect_prop_exprs = $this->_preg_grep('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $sect_prop_exprs = $this->_preg_grep('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
} }
@@ -1164,8 +1166,11 @@ class Smarty
$output = "\$$var_name"; $output = "\$$var_name";
foreach ($sections as $section) { foreach ($sections as $section_ref) {
$output .= "[\$_sections['$section']['properties']['index']]"; list($section, $section_prop) = explode('.', $section_ref);
if (!isset($section_prop))
$section_prop = 'index';
$output .= "[\$_sections['$section']['properties']['$section_prop']]";
} }
foreach ($props as $prop) { foreach ($props as $prop) {
$output .= "['$prop']"; $output .= "['$prop']";

View File

@@ -628,7 +628,7 @@ class Smarty
/* If the tag name matches a variable or section property definition, /* If the tag name matches a variable or section property definition,
we simply process it. */ we simply process it. */
if (preg_match('!^\$(\w+/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // if a variable if (preg_match('!^\$(\w+(\.\w+)?/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // if a variable
preg_match('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // or a configuration variable preg_match('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // or a configuration variable
preg_match('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command)) { // or a section property preg_match('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command)) { // or a section property
settype($tag_command, 'array'); settype($tag_command, 'array');
@@ -861,6 +861,8 @@ class Smarty
{$section_props}['index'] < {$section_props}['loop']; {$section_props}['index'] < {$section_props}['loop'];
{$section_props}['index']++):\n"; {$section_props}['index']++):\n";
$output .= "{$section_props}['rownum'] = {$section_props}['index'] + 1;\n"; $output .= "{$section_props}['rownum'] = {$section_props}['index'] + 1;\n";
$output .= "{$section_props}['index_prev'] = {$section_props}['index'] - 1;\n";
$output .= "{$section_props}['index_next'] = {$section_props}['index'] + 1;\n";
$output .= "?>"; $output .= "?>";
@@ -1126,11 +1128,11 @@ class Smarty
allow people to use older versions of PHP we emulate preg_grep() and allow people to use older versions of PHP we emulate preg_grep() and
use the version check to see what function to call. */ use the version check to see what function to call. */
if (strnatcmp(PHP_VERSION, '4.0.4') >= 0) { if (strnatcmp(PHP_VERSION, '4.0.4') >= 0) {
$var_exprs = preg_grep('!^\$(\w+/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $var_exprs = preg_grep('!^\$(\w+(\.\w+)?/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
$conf_var_exprs = preg_grep('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $conf_var_exprs = preg_grep('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
$sect_prop_exprs = preg_grep('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $sect_prop_exprs = preg_grep('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
} else { } else {
$var_exprs = $this->_preg_grep('!^\$(\w+/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $var_exprs = $this->_preg_grep('!^\$(\w+(\.\w+)?/)*\w+(?>\.\w+)*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
$conf_var_exprs = $this->_preg_grep('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $conf_var_exprs = $this->_preg_grep('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
$sect_prop_exprs = $this->_preg_grep('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); $sect_prop_exprs = $this->_preg_grep('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
} }
@@ -1164,8 +1166,11 @@ class Smarty
$output = "\$$var_name"; $output = "\$$var_name";
foreach ($sections as $section) { foreach ($sections as $section_ref) {
$output .= "[\$_sections['$section']['properties']['index']]"; list($section, $section_prop) = explode('.', $section_ref);
if (!isset($section_prop))
$section_prop = 'index';
$output .= "[\$_sections['$section']['properties']['$section_prop']]";
} }
foreach ($props as $prop) { foreach ($props as $prop) {
$output .= "['$prop']"; $output .= "['$prop']";