diff --git a/Config_File.class.php b/Config_File.class.php index 35b4eb9f..ade62e9f 100644 --- a/Config_File.class.php +++ b/Config_File.class.php @@ -5,7 +5,7 @@ require_once "PEAR.php"; /** * Config_File class. * - * @version 1.5.1 + * @version 1.5.2 * @author Andrei Zmievski * @access public * diff --git a/NEWS b/NEWS index 490c0b0a..3ce02be5 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +Version 1.5.2 +------------- + - added Smarty object as fifth argument for template resource functions + (Monte) - fixed a bug with incorrectly combined cache and compile id in clear_cache(). (Andrei) - fixed bug in smarty_make_timestamp introduced in PHP 4.1.0. (Monte) diff --git a/README b/README index 511b5ad7..c3bae83c 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ NAME: Smarty - the PHP compiling template engine -VERSION: 1.5.1 +VERSION: 1.5.2 AUTHORS: diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 1bd4388c..085caa58 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,3 +1,8 @@ +1.5.2 +----- + +Mostly bug fixes, added a default template resource handler. + 1.5.1 ----- diff --git a/Smarty.addons.php b/Smarty.addons.php index 790090d3..63117a59 100644 --- a/Smarty.addons.php +++ b/Smarty.addons.php @@ -4,7 +4,7 @@ * File: Smarty.addons.php * Author: Monte Ohrt * Andrei Zmievski - * Version: 1.5.1 + * Version: 1.5.2 * Copyright: 2001 ispi of Lincoln, Inc. * * This library is free software; you can redistribute it and/or diff --git a/Smarty.class.php b/Smarty.class.php index ddccb0a2..066dc41c 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -6,7 +6,7 @@ * Author: Monte Ohrt * Andrei Zmievski * - * Version: 1.5.1 + * Version: 1.5.2 * Copyright: 2001 ispi of Lincoln, Inc. * * This library is free software; you can redistribute it and/or @@ -204,7 +204,7 @@ class Smarty var $_conf_obj = null; // configuration object var $_config = array(); // loaded configuration settings var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' - var $_version = '1.5.1'; // Smarty version number + var $_version = '1.5.2'; // Smarty version number var $_extract = false; // flag for custom functions var $_inclusion_depth = 0; // current template inclusion depth var $_compile_id = null; // for different compiled templates @@ -927,6 +927,7 @@ function _is_trusted($resource_type, $resource_name) break; } } + if(!$_return) { // see if we can get a template with the default template handler if(!empty($this->default_template_handler_func)) { diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 1547792b..0e1ce11b 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -6,7 +6,7 @@ * Author: Monte Ohrt * Andrei Zmievski * - * Version: 1.5.1 + * Version: 1.5.2 * Copyright: 2001 ispi of Lincoln, Inc. * * This library is free software; you can redistribute it and/or diff --git a/docs.sgml b/docs.sgml index 6b11e3cc..6bdcea92 100644 --- a/docs.sgml +++ b/docs.sgml @@ -14,7 +14,7 @@
andrei@php.net
- Version 1.5.0 + Version 1.5.2 2001ispi of Lincoln, Inc. @@ -435,18 +435,18 @@ require_once(SMARTY_DIR."Smarty.class.php"); If $compile_check is enabled, the cached content will be regenerated if any of the involved templates are changed. (new to 1.4.6). If $force_compile is enabled, the cached content - will always be regenerated (new to 1.4.7). + will always be regenerated. (added to Smarty 1.4.7) $cache_dir - This is the name of the directory where template caches are - stored. By default this is "./cache", meaning that it will - look for the cache directory in the same directory as the - executing php script. This was added to Smarty version 1.3.0. - You can also use your own custom cache handler function to - control cache files, which will ignore this setting. + This is the name of the directory where template caches are + stored. By default this is "./cache", meaning that it will look + for the cache directory in the same directory as the executing + php script. You can also use your own custom cache handler + function to control cache files, which will ignore this + setting. (added to Smarty 1.3.0) TECHNICAL NOTE: This setting must be either a relative or @@ -464,8 +464,8 @@ require_once(SMARTY_DIR."Smarty.class.php"); valid. Once this time has expired, the cache will be regenerated. $caching must be set to "true" for this setting to work. You can also force the cache to expire with clear_all_cache. This was - added to Smarty 1.3.0. + linkend="api.clear.all.cache">clear_all_cache. (added to + Smarty 1.3.0) @@ -485,6 +485,13 @@ require_once(SMARTY_DIR."Smarty.class.php"); custom cache handler function section for details. + + $default_template_handler_func + + This function is called when a template cannot be obtained from + its resource. (added to Smarty 1.5.2) + + $tpl_file_ext @@ -1472,7 +1479,7 @@ $smarty->display("file:/path/to/my/templates/menu.tpl"); // put this function somewhere in your application function get_db_template ($tpl_name, &$tpl_source, &$tpl_timestamp, - $get_source=true) { + $get_source=true, &$smarty_obj) { if($get_source) { // do database calls (or whatever) here to fetch your template, populating @@ -1496,6 +1503,47 @@ $smarty->display("db:index.tpl"); {* using resource from within Smarty template *} {include file="db:/extras/navigation.tpl"} + + + + + Default Template Handler Function + + You can specify a function that is used to retrieve template + contents in the event the template cannot be retrieved from its + resource. One use of this is to create templates that do not exist + on-the-fly. This was added to Smarty 1.5.2. + + + +using the default template handler function call + + +// from PHP script + +// put this function somewhere in your application + +function make_template ($resource_type, $resource_name, &$template_source, + &$template_timestamp, &$smarty_obj) { + + if( $resource_type == 'file' ) { + if ( ! is_readable ( $resource_name )) { + // create the template file, return contents. + $template_source = "This is a new template."; + $template_timestamp = time(); + $smarty_obj->_write_file($resource_name,$template_source); + return true; + } + else { + // not a file + return false; + } +} + +// set the default handler +$smarty->default_template_handler_func = 'make_template'; + + @@ -1601,8 +1649,8 @@ $smarty->display("index.tpl"); variable. Smarty will now use this to handle cached data. The first argument is the action, which will be one of 'read', 'write' and 'clear'. The second parameter is the smarty object. The third - parameter is the cached content. Upon a write, Smarty passed th - cached content in this parameters. Upon a 'read', Smarty expects + parameter is the cached content. Upon a write, Smarty passes the + cached content in these parameters. Upon a 'read', Smarty expects your function to pass this by reference and populate it with the cached data. Upon a 'clear', pass a dummy variable here since it is not used. The fourth parameter is the name of the template file @@ -2481,6 +2529,14 @@ index.tpl The name of the template variable the output will be assigned to + + script + string + No + n/a + The name of the php script that is included before + the insert function is called + [var ...] [var type] @@ -2492,22 +2548,19 @@ index.tpl - The insert tag in Smarty serves a special purpose. You may - run into the situation where it is impossible to pass data to a template - before the template is executed because there is info in the template - needed to aquire the data, kind of a catch 22. The insert tag is a way - to callback a function in PHP during runtime of the template. The - difference between insert tags and custom functions is that insert - tags are not cached when you have template caching enabled. They - will be executed on every invocation of the template. + Insert tags work much like include tags, except that insert tags + are not cached when you have template caching enabled. They will be + executed on every invocation of the template. - Let's say you have a template with a banner slot at the top of the page. The - banner can contain any mixture of HTML, images, flash, etc. so we can't just - use a static link here. In comes the insert tag: the template - knows #banner_location_id# and #site_id# values (gathered from a config file), - and needs to call a function to get the banner's contents. + Let's say you have a template with a banner slot at the top of the + page. The banner can contain any mixture of HTML, images, flash, + etc. so we can't just use a static link here, and we don't want + this contents cached with the page. In comes the insert tag: the + template knows #banner_location_id# and #site_id# values (gathered + from a config file), and needs to call a function to get the banner + contents. function insert @@ -2533,11 +2586,19 @@ index.tpl and display the returned results in place of the insert tag. - If you supply the special "assign" attribute, the output of the - insert tag will be assigned to this template variable instead of - being output to the template. NOTE: assiging the output to a template - variable isn't too useful with caching enabled. (added to Smarty - 1.5.0) + If you supply the "assign" attribute, the output of the insert tag + will be assigned to this template variable instead of being output + to the template. NOTE: assiging the output to a template variable + isn't too useful with caching enabled. (added to Smarty 1.5.0) + + + If you supply the "script" attribute, this php script will be + included (only once) before the insert function is executed. This + is the case where the insert function may not exist yet, and a php + script must be included first to make it work. The path can be + either absolute, or relative to $trusted_dir. When security is + enabled, the script must reside in $trusted_dir. (added to Smarty + 1.5.2) The Smarty object is passed as the second argument. This way you diff --git a/libs/Config_File.class.php b/libs/Config_File.class.php index 35b4eb9f..ade62e9f 100644 --- a/libs/Config_File.class.php +++ b/libs/Config_File.class.php @@ -5,7 +5,7 @@ require_once "PEAR.php"; /** * Config_File class. * - * @version 1.5.1 + * @version 1.5.2 * @author Andrei Zmievski * @access public * diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index ddccb0a2..066dc41c 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -6,7 +6,7 @@ * Author: Monte Ohrt * Andrei Zmievski * - * Version: 1.5.1 + * Version: 1.5.2 * Copyright: 2001 ispi of Lincoln, Inc. * * This library is free software; you can redistribute it and/or @@ -204,7 +204,7 @@ class Smarty var $_conf_obj = null; // configuration object var $_config = array(); // loaded configuration settings var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' - var $_version = '1.5.1'; // Smarty version number + var $_version = '1.5.2'; // Smarty version number var $_extract = false; // flag for custom functions var $_inclusion_depth = 0; // current template inclusion depth var $_compile_id = null; // for different compiled templates @@ -927,6 +927,7 @@ function _is_trusted($resource_type, $resource_name) break; } } + if(!$_return) { // see if we can get a template with the default template handler if(!empty($this->default_template_handler_func)) { diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 1547792b..0e1ce11b 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -6,7 +6,7 @@ * Author: Monte Ohrt * Andrei Zmievski * - * Version: 1.5.1 + * Version: 1.5.2 * Copyright: 2001 ispi of Lincoln, Inc. * * This library is free software; you can redistribute it and/or