From f051537982cb1419a8548172b7296a3a42b806ec Mon Sep 17 00:00:00 2001 From: mohrt Date: Wed, 9 May 2001 14:06:59 +0000 Subject: [PATCH] update dates versions --- NEWS | 7 ++- RELEASE_NOTES | 37 +++++++++---- Smarty.addons.php | 48 ++++++++++++++++ Smarty.class.php | 12 ++-- docs.sgml | 126 +++++++++++++++++++++++++++++++++++++++++- libs/Smarty.class.php | 12 ++-- 6 files changed, 220 insertions(+), 22 deletions(-) diff --git a/NEWS b/NEWS index 9f7de4f0..97ea29db 100644 --- a/NEWS +++ b/NEWS @@ -1,8 +1,11 @@ - - updated Smarty to use absolute paths when requiring/including Smarty - components. (Andrei, John Lim) + - fix LOCK_EX logic once and for all (not used under windows) (Monte) + - updated Smarty to use absolute paths when requiring/including Smarty + components. (Andrei, John Lim) Version 1.4.0 ------------- + - added {capture}{/capture} function, documented (Monte) + - added {counter} function, documented (Monte) - fixed indexing by section properties with the new syntax. (Andrei) Version 1.4.0b2 diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 6884bd85..5021bc77 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -5,15 +5,29 @@ IMPORTANT NOTICE Smarty now has a new syntax for accessing elements within section loops. The new syntax is easier to use and nicely handles data structures of any -complexity. Consequently, this breaks the old syntax. To fix your current -templates, we have provided a script that will adjust the syntax for you. -Located in misc/fix_vars.php, run this script from the the command line, giving -each template as an argument. Be sure to use absolute pathnames, or pathnames -relative to the executing script. Probably the easiest way to do this is to -copy the fix_vars.php script into your template directory and run 'php -q -fix_vars.php *.tpl' Be sure you have proper write permission, and backup your -scripts first to be safe! The examples in the 1.4.0 documentation have been -updated to reflect the changes. +complexity. Consequently, this breaks the old syntax. + +Here is an example of the syntax change: + +old syntax: +{$sec1/sec2/sec3/customer.phone} + +new syntax: +{$customer[$sec1][$sec2][$sec3].phone} + +The section names used to come first, followed by the variable name. Now the +variable name always comes first, followed by the section names in brackets. +You can access variable indexes anywhere, depending on how you passed the +variables in. + +To fix your current templates, we have provided a script that will adjust the +syntax for you. Located in misc/fix_vars.php, run this script from the the +command line, giving each template as an argument. Be sure to use absolute +pathnames, or pathnames relative to the executing script. Probably the easiest +way to do this is to copy the fix_vars.php script into your template directory +and run 'php -q fix_vars.php *.tpl' Be sure you have proper write permission, +and backup your scripts first to be safe! The examples in the 1.4.0 +documentation have been updated to reflect the changes. cd /path/to/templates cp /path/to/fix_vars.php . @@ -81,7 +95,10 @@ symbol and specifying the property name after it, e.g. $foo->bar. {php}{/php} tags were added to embed php into the templates. Not normally needed, but some circumstances may call for it. Check out the "componentized -templates" tip in the documentation for an example of needed usage. +templates" tip in the documentation for an example. + +{capture}{/capture} and {counter} functions were added. See the documentation +for a complete description and examples. UPGRADE NOTES diff --git a/Smarty.addons.php b/Smarty.addons.php index b1370eb3..e2b2f539 100644 --- a/Smarty.addons.php +++ b/Smarty.addons.php @@ -514,6 +514,54 @@ function smarty_mod_count_paragraphs($string,$include_spaces=false) { return count( preg_split("/[\r\n]+/",$string) ); } +/*======================================================================*\ + Function: smarty_func_counter + Purpose: print out a counter value +\*======================================================================*/ +function smarty_func_counter() { + + static $count = array(); + static $skipval = array(); + static $dir = array(); + static $id = "default"; + static $printval = array(); + + extract(func_get_arg(0)); + + if(!isset($id)) + $id = "default"; + + if(isset($start)) + $count[$id] = $start; + elseif(!isset($count[$id])) + $count[$id]=1; + + if(!isset($print)) + $printval[$id]=true; + else + $printval[$id]=$print; + + if($printval[$id]) + echo $count[$id]; + + if(isset($skip)) + $skipval[$id] = $skip; + elseif(!isset($skipval)) + $skipval[$id] = 1; + + if(isset($direction)) + $dir[$id] = $direction; + elseif(!isset($dir[$id])) + $dir[$id] = "up"; + + if($dir[$id] == "down") + $count[$id] -= $skipval[$id]; + else + $count[$id] += $skipval[$id]; + + return true; +} + /* vim: set expandtab: */ ?> diff --git a/Smarty.class.php b/Smarty.class.php index 9c5885ed..94823326 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -109,7 +109,8 @@ class Smarty 'html_select_date' => 'smarty_func_html_select_date', 'html_select_time' => 'smarty_func_html_select_time', 'math' => 'smarty_func_math', - 'fetch' => 'smarty_func_fetch' + 'fetch' => 'smarty_func_fetch', + 'counter' => 'smarty_func_counter' ); var $custom_mods = array( 'lower' => 'strtolower', @@ -645,7 +646,7 @@ class Smarty $funcname($resource_name, $template_source, $template_timestamp); return true; } else { - $this->_trigger_error_msg("function: resource function \"$funcname\" does not exist for resource type: \"$resource_type\"."); + $this->_trigger_error_msg("resource function: \"$funcname\" does not exist for resource type: \"$resource_type\"."); return false; } } else { @@ -776,7 +777,11 @@ class Smarty $this->_trigger_error_msg("problem writing '$filename.'"); return false; } - if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) { + + // flock doesn't seem to work on several windows platforms (98, NT4, NT5, ?), + // so we'll not use it at all in windows. + + if ( strtoupper(substr(PHP_OS,0,3)) == 'WIN' || (flock($fd, LOCK_EX)) ) { fwrite( $fd, $contents ); fclose($fd); chmod($filename,0644); @@ -785,7 +790,6 @@ class Smarty return true; } - /*======================================================================*\ Function: _clear_tpl_cache_dir Purpose: Clear the specified template cache diff --git a/docs.sgml b/docs.sgml index bbd206ab..8c30813d 100644 --- a/docs.sgml +++ b/docs.sgml @@ -1225,7 +1225,7 @@ $smarty->display("db:index.tpl"); - Template Preilters + Template Prefilters Template prefilters are PHP functions that your templates are ran through before they are compiled. This is good for preprocessing your templates @@ -1558,6 +1558,41 @@ Intro = """This is a value that spans more are integral to the template language. You cannot create custom functions with the same names, nor can you modify built-in functions. + + capture + + capture is used to collect the output of the template into a + variable instead of displaying it. Any content between {capture} and + {/capture} is collected into the special $return variable, which can + be used in the template from that point on. All {capture} commands + must be paired with {/capture}. You can nest capture commands, but + be aware that each iteration will overwrite the last value of + $return. capture was added to Smarty 1.4.0. + + + TECHNICAL NOTE: Be careful when capturing {insert} output. If you + have caching turned on and you have {insert} commands that you + expect to run within cached content, do not capture this content. + + +capturing template content + + +{* we don't want to print a table row unless content is displayed *} +{capture} +{include file="get_banner.tpl"} +{/capture} +{if $return ne ""} + <tr> + <td> + {$return} + </td> + </tr> +{/if} + + + + config_load @@ -1922,7 +1957,7 @@ OUTPUT: - + literal Literal tags allow a block of data to be taken literally, @@ -2497,6 +2532,93 @@ OUTPUT: Custom functions in Smarty work much the same as the built-in functions syntactically. + + counter + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + id + string + No + default + The id of the counter + + + start + number + No + 1 + The initial number to start counting from + + + skip + number + No + 1 + The interval to count by + + + direction + string + No + up + the direction to count (up/down) + + + print + boolean + No + false + Whether or not to print the value + + + + + + counter is used to print out a count. counter will remember the + count on each iteration. You can adjust the number, the interval + and the direction of the count, as well as determine whether or not + to print the value. You can run multiple counters concurrently by + supplying a unique id for each one. If you do not supply an id, the + default id will be used. counter was added to Smarty 1.4.0. + + +counter + + +{* initialize the count *} +{counter start=0 skip=2 print=false} + +{counter}<br> +{counter}<br> +{counter}<br> +{counter}<br> + +OUTPUT: + +2<br> +4<br> +6<br> +8<br> + + + + fetch diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 9c5885ed..94823326 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -109,7 +109,8 @@ class Smarty 'html_select_date' => 'smarty_func_html_select_date', 'html_select_time' => 'smarty_func_html_select_time', 'math' => 'smarty_func_math', - 'fetch' => 'smarty_func_fetch' + 'fetch' => 'smarty_func_fetch', + 'counter' => 'smarty_func_counter' ); var $custom_mods = array( 'lower' => 'strtolower', @@ -645,7 +646,7 @@ class Smarty $funcname($resource_name, $template_source, $template_timestamp); return true; } else { - $this->_trigger_error_msg("function: resource function \"$funcname\" does not exist for resource type: \"$resource_type\"."); + $this->_trigger_error_msg("resource function: \"$funcname\" does not exist for resource type: \"$resource_type\"."); return false; } } else { @@ -776,7 +777,11 @@ class Smarty $this->_trigger_error_msg("problem writing '$filename.'"); return false; } - if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) { + + // flock doesn't seem to work on several windows platforms (98, NT4, NT5, ?), + // so we'll not use it at all in windows. + + if ( strtoupper(substr(PHP_OS,0,3)) == 'WIN' || (flock($fd, LOCK_EX)) ) { fwrite( $fd, $contents ); fclose($fd); chmod($filename,0644); @@ -785,7 +790,6 @@ class Smarty return true; } - /*======================================================================*\ Function: _clear_tpl_cache_dir Purpose: Clear the specified template cache