diff --git a/SMARTY2_BC_NOTES b/SMARTY2_BC_NOTES index cde8629c..79a2cb1b 100644 --- a/SMARTY2_BC_NOTES +++ b/SMARTY2_BC_NOTES @@ -1,23 +1,19 @@ -Smarty 2 and Smarty 3 are quite similar in implementation, but do have a few -differences you need to be aware of when upgrading from Smarty 2 to Smarty 3. - = Known incompatibilities with Smarty 2 = == Syntax == -The Smarty 3 API has been updated in various places. Some Smarty 2 API calls -need to be updated to comply with Smarty 3. You will get a deprecation notice -with old Smarty 2 API calls, and informed what the new one is. See the README that -comes with Smarty 3 for more information. +Smarty 3 API has a new syntax. Much of the Smarty 2 syntax is supported +by a wrapper but deprecated. See the README that comes with Smarty 3 for more +information. The {$array|@mod} syntax has always been a bit confusing, where an "@" is required -to apply a modifier to an array instead of the individual array elements. Normally you +to apply a modifier to an array instead of the individual elements. Normally you always want the modifier to apply to the variable regardless of its type. In Smarty 3, {$array|mod} and {$array|@mod} behave identical. It is safe to drop the "@" and the modifier will still apply to the array. If you really want the modifier to apply to each array element, you must loop the array in-template, or use a custom modifier that -supports array iteration. Most smarty functions already escape array elements where -necessary such as {html_options} +supports array iteration. Most smarty functions already escape values where necessary +such as {html_options} == PHP Version == Smarty 3 is PHP 5 only. It will not work with PHP 4. @@ -26,31 +22,30 @@ Smarty 3 is PHP 5 only. It will not work with PHP 4. The {php} tag is disabled by default. The use of {php} tags is deprecated. It can be enabled with $smarty->allow_php_tag=true. -Variables inside {php} blocks no longer share scope with other -{php} blocks on the page, so be aware of this change if you use them. +But if you scatter PHP code which belongs together into several +{php} tags it may not work any longer. == Delimiters and whitespace == -Smarty delimiters {} surrounded by whitespace are no longer treated as Smarty tags. -Therefore, { foo } will be ignored by Smarty, but {foo} is recognized. This change -makes Javascript/CSS easier to work with, eliminating the need for {literal}. -This feature can be disabled by setting $smarty->auto_literal = false; +Delimiters surrounded by whitespace are no longer treated as Smarty tags. +Therefore, { foo } will not compile as a tag, you must use {foo}. This change +Makes Javascript/CSS easier to work with, eliminating the need for {literal}. +This can be disabled by setting $smarty->auto_literal = false; == Unquoted Strings == Smarty 2 was a bit more forgiving (and ambiguous) when it comes to unquoted strings in parameters. Smarty3 is more restrictive. You can still pass strings without quotes so long as they contain no special characters. (anything outside of A-Za-z0-9_) -For example filename strings must be quoted: - +For example filename strings must be quoted -{assign var=foo value=baz} <-- works ok -{include file="path/foo.tpl"} <-- needs quotes! +{include file='path/foo.tpl'} == Extending the Smarty class == -Smarty 3 follows standard PHP5 constructor rules. When extending the Smarty class, -use __construct() as the class constructor name. If you implement your own constructor, -be certain to call parent::__construct() first. +Smarty 3 makes use of the __construct method for initialization. If you are extending +the Smarty class, its constructor is not called implicitly if the your child class defines +its own constructor. In order to run Smarty's constructor, a call to parent::__construct() +within your child constructor is required. class MySmarty extends Smarty { @@ -64,35 +59,41 @@ class MySmarty extends Smarty { == Autoloader == -Smarty implements its own autoloader with spl_autoload_register. If you -use an autoloader in your own application, you MUST register yours as well. Using -__autoload() WILL FAIL. This is standard PHP5 autoloader procedure for shared libraries. -See http://us3.php.net/manual/en/function.spl-autoload-register.php +Smarty 3 does register its own autoloader with spl_autoload_register. If your code has +an existing __autoload function then this function must be explicitly registered on +the __autoload stack. See http://us3.php.net/manual/en/function.spl-autoload-register.php +for further details. == Plugin Filenames == -Since Smarty 3 uses the default spl_autoloader, the plugin filenames are now required to be -lower case. Smarty 2 allowed mixed case plugin names, you must rename them for Smarty 3. +Smarty 3 optionally supports the PHP spl_autoloader. The autoloader requires filenames +to be lower case. Because of this, Smarty plugin file names must also be lowercase. +In Smarty 2, mixed case file names did work. == Scope of Special Smarty Variables == -In Smarty 2 the special Smarty variables $smarty.section.* and $smarty.foreach.* -had global scope. If you had loops with the same name in subtemplates, you could accidentally -overwrite values of a parent template. - -In Smarty 3 these special Smarty variables now have local scope in the template which -is defining the loop. In the rare case you need these values in a subtemplate, you have to -pass them as parameters. +In Smarty 2 the special Smarty variables $smarty.section... and $smarty.foreach... +had global scope. If you had loops with the same name in subtemplates you could accidentally +overwrite values of parent template. +In Smarty 3 these special Smarty variable have only local scope in the template which +is defining the loop. If you need their value in a subtemplate you have to pass them +as parameter. -{include file="path/foo.tpl" index=$smarty.section.foo.index} +{include file='path/foo.tpl' index=$smarty.section.foo.index} == SMARTY_RESOURCE_CHAR_SET == -Smarty 3 sets the constant SMARTY_RESOURCE_CHAR_SET to utf-8 as the default template charset. -This is now used with modifiers like escape as the default charset. If your templates use -another charset, make sure that you define the constant accordingly. +Smarty 3 sets the constant SMARTY_RESOURCE_CHAR_SET to utf-8 as default template charset. +This is now used also on modifiers like escape as default charset. If your templates use +other charsets make sure that you define the constant accordingly. Otherwise you may not +get any output. + +== newline at {if} tags == +A \n was added to the compiled code of the {if},{else},{elseif},{/if} tags to get output of newlines as expected by the template source. +If one of the {if} tags is at the line end you will now get a newline in the HTML output. == trigger_error() == -The API function trigger_error() has been removed. It is still included in the Smarty2 API wrapper. +The API function trigger_error() has been removed because it did just map to PHP trigger_error. +However it's still included in the Smarty2 API wrapper. == Smarty constants == The constants diff --git a/SMARTY3.0_BC_NOTES.txt b/SMARTY3.0_BC_NOTES.txt new file mode 100644 index 00000000..fd8b540c --- /dev/null +++ b/SMARTY3.0_BC_NOTES.txt @@ -0,0 +1,24 @@ +== Smarty2 backward compatibility == +All Smarty2 specific API functions and deprecated functionallity has been moved +to the SmartyBC class. + +== {php} Tag == +The {php} tag is no longer available in the standard Smarty calls. +The use of {php} tags is deprecated and only available in the SmartyBC class. + +== {include_php} Tag == +The {include_php} tag is no longer available in the standard Smarty calls. +The use of {include_php} tags is deprecated and only available in the SmartyBC class. + +== php template resource == +The support of the php template resource is removed. + +== $cache_dir, $compile_dir, $config_dir, $template_dir access == +The mentioned properties can't be accessed directly any longer. You must use +corresponding getter/setters like addConfigDir(), setConfigDir(), getConfigDir() + +== obsolete Smarty class properties == +The following no longer used properties are removed: +$allow_php_tag +$allow_php_template +$deprecation_notices \ No newline at end of file diff --git a/SMARTY_3.1_NOTES.txt b/SMARTY_3.1_NOTES.txt new file mode 100644 index 00000000..6da478de --- /dev/null +++ b/SMARTY_3.1_NOTES.txt @@ -0,0 +1,306 @@ +Smarty 3.1 Notes +================ + +Smarty 3.1 is a departure from 2.0 compatibility. Most notably, all +backward compatibility has been moved to a separate class file named +SmartyBC.class.php. If you require compatibility with 2.0, you will +need to use this class. + +Some differences from 3.0 are also present. 3.1 begins the journey of +requiring setters/getters for property access. So far this is only +implemented on the five directory properties: template_dir, +plugins_dir, configs_dir, compile_dir and cache_dir. These properties +are now protected, it is required to use the setters/getters instead. +That said, direct property access will still work, however slightly +slower since they will now fall through __set() and __get() and in +turn passed through the setter/getter methods. 3.2 will exhibit a full +list of setter/getter methods for all (currently) public properties, +so code-completion in your IDE will work as expected. + +There is absolutely no PHP allowed in templates any more. All +deprecated features of Smarty 2.0 are gone. Again, use the SmartyBC +class if you need any backward compatibility. + +Internal Changes + + Full UTF-8 Compatibility + +The plugins shipped with Smarty 3.1 have been rewritten to fully +support UTF-8 strings if Multibyte String is available. Without +MBString UTF-8 cannot be handled properly. For those rare cases where +templates themselves have to juggle encodings, the new modifiers +to_charset and from_charset may come in handy. + + Plugin API and Performance + +All Plugins (modifiers, functions, blocks, resources, +default_template_handlers, etc) are now receiving the +Smarty_Internal_Template instance, where they were supplied with the +Smarty instance in Smarty 3.0. *. As The Smarty_Internal_Template +mimics the behavior of Smarty, this API simplification should not +require any changes to custom plugins. + +The plugins shipped with Smarty 3.1 have been rewritten for better +performance. Most notably {html_select_date} and {html_select_time} +have been improved vastly. Performance aside, plugins have also been +reviewed and generalized in their API. {html_select_date} and +{html_select_time} now share almost all available options. + +The escape modifier now knows the $double_encode option, which will +prevent entities from being encoded again. + +The capitalize modifier now know the $lc_rest option, which makes sure +all letters following a captial letter are lower-cased. + +The count_sentences modifier now accepts ».?!« as +legitimate endings of a sentence - previously only ».« was +accepted + +The new unescape modifier is there to reverse the effects of the +escape modifier. This applies to the escape formats html, htmlall and +entity. + + default_template_handler_func + +The invocation of $smarty->$default_template_handler_func had to be +altered. Instead of a Smarty_Internal_Template, the fifth argument is +now provided with the Smarty instance. New footprint: + + +/** + * Default Template Handler + * + * called when Smarty's file: resource is unable to load a requested file + * + * @param string $type resource type (e.g. "file", "string", "eval", "resource") + * @param string $name resource name (e.g. "foo/bar.tpl") + * @param string &$content template's content + * @param integer &$modified template's modification time + * @param Smarty $smarty Smarty instance + * @return string|boolean path to file or boolean true if $content and $modified + * have been filled, boolean false if no default template + * could be loaded + */ +function default_template_handler_func($type, $name, &$content, &$modified, Smarty $smarty) { + if (false) { + // return corrected filepath + return "/tmp/some/foobar.tpl"; + } elseif (false) { + // return a template directly + $content = "the template source"; + $modified = time(); + return true; + } else { + // tell smarty that we failed + return false; + } +} + + Stuff done to the compiler + +@todo uwe.tews + +Many performance improvements have happened internally. One notable +improvement is that all compiled templates are now handled as PHP +functions. This speeds up repeated templates tremendously, as each one +calls an (in-memory) PHP function instead of performing another file +include/scan. + +New Features + + Template syntax + + {block}..{/block} + +The {block} tag has a new hide option flag. It does suppress the block +content if no corresponding child block exists. +EXAMPLE: +parent.tpl +{block name=body hide} child content "{$smarty.block.child}" was +inserted {block} +In the above example the whole block will be suppressed if no child +block "body" is existing. + + {setfilter}..{/setfilter} + +The new {setfilter} block tag allows the definition of filters which +run on variable output. +SYNTAX: +{setfilter filter1|filter2|filter3....} +Smarty3 will lookup up matching filters in the following search order: +1. varibale filter plugin in plugins_dir. +2. a valid modifier. A modifier specification will also accept +additional parameter like filter2:'foo' +3. a PHP function +{/setfilter} will turn previous filter setting off again. +{setfilter} tags can be nested. +EXAMPLE: +{setfilter filter1} + {$foo} + {setfilter filter2} + {$bar} + {/setfilter} + {$buh} +{/setfilter} +{$blar} +In the above example filter1 will run on the output of $foo, filter2 +on $bar, filter1 again on $buh and no filter on $blar. +NOTES: +- {$foo nofilter} will suppress the filters +- These filters will run in addition to filters defined by +registerFilter('variable',...), autoLoadFilter('variable',...) and +defined default modifier. +- {setfilter} will effect only the current template, not included +subtemplates. + + Resource API + +Smarty 3.1 features a new approach to resource management. The +Smarty_Resource API allows simple, yet powerful integration of custom +resources for templates and configuration files. It offers simple +functions for loading data from a custom resource (e.g. database) as +well as define new template types adhering to the special +non-compiling (e,g, plain php) and non-compile-caching (e.g. eval: +resource type) resources. + +See demo/plugins/resource.mysql.php for an example custom database +resource. + +Note that old-fashioned registration of callbacks for resource +management has been deprecated but is still possible with SmartyBC. + + CacheResource API + +In line with the Resource API, the CacheResource API offers a more +comfortable handling of output-cache data. With the +Smarty_CacheResource_Custom accessing databases is made simple. With +the introduction of Smarty_CacheResource_KeyValueStore the +implementation of resources like memcache or APC became a no-brainer; +simple hash-based storage systems are now supporting hierarchical +output-caches. + +See demo/plugins/cacheresource.mysql.php for an example custom +database CacheResource. +See demo/plugins/cacheresource.memcache.php for an example custom +memcache CacheResource using the KeyValueStore helper. + +Note that old-fashioned registration of $cache_handler is not possible +anymore. As the functionality had not been ported to Smarty 3.0.x +properly, it has been dropped from 3.1 completely. + +Locking facilities have been implemented to avoid concurrent cache +generation. Enable cache locking by setting +$smarty->cache_locking = true; + + Relative Paths in Templates (File-Resource) + +As of Smarty 3.1 {include file="../foo.tpl"} and {include +file="./foo.tpl"} will resolve relative to the template they're in. +Relative paths are available with {include file="..."} and +{extends file="..."}. As $smarty->fetch('../foo.tpl') and +$smarty->fetch('./foo.tpl') cannot be relative to a template, an +exception is thrown. + + Adressing a specific $template_dir + +Smarty 3.1 introduces the $template_dir index notation. +$smarty->fetch('[foo]bar.tpl') and {include file="[foo]bar.tpl"} +require the template bar.tpl to be loaded from $template_dir['foo']; +Smarty::setTemplateDir() and Smarty::addTemplateDir() offer ways to +define indexes along with the actual directories. + + Mixing Resources in extends-Resource + +Taking the php extends: template resource one step further, it is now +possible to mix resources within an extends: call like +$smarty->fetch("extends:file:foo.tpl|db:bar.tpl"); + +To make eval: and string: resources available to the inheritance +chain, eval:base64:TPL_STRING and eval:urlencode:TPL_STRING have been +introduced. Supplying the base64 or urlencode flags will trigger +decoding the TPL_STRING in with either base64_decode() or urldecode(). + + extends-Resource in template inheritance + +Template based inheritance may now inherit from php's extends: +resource like {extends file="extends:foo.tpl|db:bar.tpl"}. + + New Smarty property escape_html + +$smarty->escape_html = true will autoescape all template variable +output by calling htmlspecialchars({$output}, ENT_QUOTES, +SMARTY_RESOURCE_CHAR_SET). +NOTE: +This is a compile time option. If you change the setting you must make +sure that the templates get recompiled. + + New option at Smarty property compile_check + +The automatic recompilation of modified templates can now be +controlled by the following settings: +$smarty->compile_check = COMPILECHECK_OFF (false) - template files +will not be checked +$smarty->compile_check = COMPILECHECK_ON (true) - template files will +always be checked +$smarty->compile_check = COMPILECHECK_CACHEMISS - template files will +be checked if caching is enabled and there is no existing cache file +or it has expired + + Automatic recompilation on Smarty version change + +Templates will now be automatically recompiled on Smarty version +changes to avoide incompatibillities in the compiled code. Compiled +template checked against the current setting of the SMARTY_VERSION +constant. + + default_config_handler_func() + +Analogous to the default_template_handler_func() +default_config_handler_func() has been introduced. + + default_plugin_handler_func() + +@todo uwe.tews + +New getters/setters + +The following setters/getters will be part of the official +documentation, and will be strongly recommended. Direct property +access will still work for the foreseeable future... it will be +transparently routed through the setters/getters, and consequently a +bit slower. + +array|string getTemplateDir( [string $index] ) +replaces $smarty->template_dir; and $smarty->template_dir[$index]; +Smarty setTemplateDir( array|string $path ) +replaces $smarty->template_dir = "foo"; and $smarty->template_dir = +array("foo", "bar"); +Smarty addTemplateDir( array|string $path, [string $index]) +replaces $smarty->template_dir[] = "bar"; and +$smarty->template_dir[$index] = "bar"; + +array|string getConfigDir( [string $index] ) +replaces $smarty->config_dir; and $smarty->config_dir[$index]; +Smarty setConfigDir( array|string $path ) +replaces $smarty->config_dir = "foo"; and $smarty->config_dir = +array("foo", "bar"); +Smarty addConfigDir( array|string $path, [string $index]) +replaces $smarty->config_dir[] = "bar"; and +$smarty->config_dir[$index] = "bar"; + +array getPluginsDir() +replaces $smarty->plugins_dir; +Smarty setPluginsDir( array|string $path ) +replaces $smarty->plugins_dir = "foo"; +Smarty addPluginsDir( array|string $path ) +replaces $smarty->plugins_dir[] = "bar"; + +string getCompileDir() +replaces $smarty->compile_dir; +Smarty setCompileDir( string $path ) +replaces $smarty->compile_dir = "foo"; + +string getCacheDir() +replaces $smarty->cache_dir; +Smarty setCacheDir( string $path ) +replaces $smarty->cache_dir; diff --git a/change_log.txt b/change_log.txt index d01dcbb8..2864cb06 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,32 +1,298 @@ -===== SVN trunk ===== -27/07/2011 -- bugfix subtemplate could use wrong varibale scope when it was recalled from different templates +===== Smarty 3.1-DEV ===== +15/09/2011 +- optimization of {foreach}; call internal _count() method only when "total" or "last" {foreach} properties are used + +11/09/2011 +- added unregisterObject() methode + +06/09/2011 +- bugfix isset() did not work in templates on config variables + +03/09/2011 +- bugfix createTemplate() must default to cache_id and compile_id of Smarty object +- bugfix Smarty_CacheResource_KeyValueStore must include $source->uid in cache filepath to keep templates with same + name but different folders seperated +- added cacheresource.apc.php example in demo folder + +02/09/2011 +- bugfix cache lock file must use absolute filepath + +01/09/2011 +- update of cache locking + +30/08/2011 +- added locking mechanism to CacheResource API (implemented with File and KeyValueStores) + +28/08/2011 +- bugfix clearCompileTemplate() did not work for specific template subfolder or resource + +27/08/2011 +- bugfix {$foo|bar+1} did create syntax error + +26/08/2011 +- bugfix when generating nocache code which contains double \ +- bugfix handle race condition if cache file was deleted between filemtime and include + +17/08/2011 +- bugfix CacheResource_Custom bad internal fetch() call + +15/08/2011 +- bugfix CacheResource would load content twice for KeyValueStore and Custom handlers + +06/08/2011 +- bugfix {include} with scope attribute could execute in wrong scope +- optimization of compile_check processing + +03/08/2011 +- allow comment tags to comment {block} tags out in child templates 26/07/2011 - bugfix experimental getTags() method did not work +24/07/2011 +- sure opened output buffers are closed on exception +- bugfix {foreach} did not work on IteratorAggregate + +22/07/2011 +- clear internal caches on clearAllCache(), clearCache(), clearCompiledTemplate() + +21/07/2011 +- bugfix value changes of variable values assigned to Smarty object could not be seen on repeated $smarty->fetch() calls + +17/07/2011 +- bugfix {$smarty.block.child} did drop a notice at undefined child + 15/07/2011 - bugfix individual cache_lifetime of {include} did not work correctly inside {block} tags +- added caches for Smarty_Template_Source and Smarty_Template_Compiled to reduce I/O for multiple cache_id rendering -12/07/2011 +14/07/2011 +- made Smarty::loadPlugin() respect the include_path if required + +13/07/2011 +- optimized internal file write functionality - bugfix PHP did eat line break on nocache sections +- fixed typo of Smarty_Security properties $allowed_modifiers and $disabled_modifiers + +06/07/2011 +- bugfix variable modifier must run befor gereral filtering/escaping + +04/07/2011 +- bugfix use (?P) syntax at preg_match as some pcre libraries failed on (?) +- some performance improvement when using generic getter/setter on template objects + +30/06/2011 +- bugfix generic getter/setter of Smarty properties used on template objects did throw exception +- removed is_dir and is_readable checks from directory setters for better performance + +28/06/2011 +- added back support of php template resource as undocumented feature +- bugfix automatic recompilation on version change could drop undefined index notice on old 3.0 cache and compiled files +- update of README_3_1_DEV.txt and moved into the distribution folder +- improvement show first characters of eval and string templates instead sha1 Uid in debug window + +===== Smarty 3.1-RC1 ===== +25/06/2011 +- revert change of 17/06/2011. $_smarty varibale removed. call loadPlugin() from inside plugin code if required +- code cleanup, remove no longer used properties and methods +- update of PHPdoc comments + +23/06/2011 +- bugfix {html_select_date} would not respect current time zone 19/06/2011 -- bugfix clear_config Smarty2 BC wrapper function was missing +- added $errors argument to testInstall() functions to suppress output. +- added plugin-file checks to testInstall() + +18/06/2011 +- bugfix mixed use of same subtemplate inline and not inline in same script could cause a warning during compilation + +17/06/2011 +- bugfix/change use $_smarty->loadPlugin() when loading nested depending plugins via loadPlugin +- bugfix {include ... inline} within {block}...{/block} did fail 16/06/2011 -- bugfix do not overwrite 'smarty' template variable when {include ... scope=parent} exits +- bugfix do not overwrite '$smarty' template variable when {include ... scope=parent} is called +- bugfix complete empty inline subtemplates did fail + +15/06/2011 +- bugfix template variables where not accessable within inline subtemplates + +12/06/2011 +- bugfix removed unneeded merging of template variable when fetching includled subtemplates + +10/06/2011 +- made protected properties $template_dir, $plugins_dir, $cache_dir, $compile_dir, $config_dir accessible via magic methods 09/06/2011 -- bugfix smarty security_policy issue in plugins {html_image} and {fetch} +- fix smarty security_policy issue in plugins {html_image} and {fetch} -07/06/2011 -- bugfix registerFilter() or registerPlugin() on template objects did register to the main Smarty object if the register methods had been used on the main Smarty object before. +05/06/2011 +- update of SMARTY_VERSION +- bugfix made getTags() working again -===== Smarty 3.0.8 ===== -29/05/2011 -- bugfix in templates did break "cache modified check" +04/06/2011 +- allow extends resource in file attribute of {extends} tag +03/06/2011 +- added {setfilter} tag to set filters for variable output +- added escape_html property to control autoescaping of variable output + +27/05/2011 +- added allowed/disabled tags and modifiers in security for sandboxing + +23/05/2011 +- added base64: and urlencode: arguments to eval and string resource types + +22/05/2011 +- made time-attribute of {html_select_date} and {html_select_time} accept arrays as defined by attributes prefix and field_array + +13/05/2011 +- remove setOption / getOption calls from SamrtyBC class + +02/05/2011 +- removed experimental setOption() getOption() methods +- output returned content also on opening tag calls of block plugins +- rewrite of default plugin handler +- compile code of variable filters for better performance + +20/04/2011 +- allow {php} {include_php} tags and PHP_ALLOW handling only with the SmartyBC class +- removed support of php template resource + +20/04/2011 +- added extendsall resource example +- optimization of template variable access +- optimization of subtemplate handling {include} +- optimization of template class + +01/04/2011 +- bugfix quote handling in capitalize modifier + +28/03/2011 +- bugfix stripslashes() requried when using PCRE e-modifier + +04/03/2011 +- upgrade to new PHP_LexerGenerator version 0.4.0 for better performance + +27/02/2011 +- ignore .svn folders when clearing cache and compiled files +- string resources do not need a modify check + +26/02/2011 +- replaced smarty_internal_wrapper by SmartyBC class +- load utility functions as static methods instead through __call() +- bugfix in extends resource when subresources are used +- optimization of modify checks + +25/02/2011 +- use $smarty->error_unassigned to control NOTICE handling on unassigned variables + +21/02/2011 +- added new new compile_check mode COMPILECHECK_CACHEMISS +- corrected new cloning behaviour of createTemplate() +- do no longer store the compiler object as property in the compile_tag classes to avoid possible memory leaks + during compilation + +19/02/2011 +- optimizations on merge_compiled_includes handling +- a couple of optimizations and bugfixes related to new resource structure + +17/02/2011 +- changed ./ and ../ behaviour + +14/02/2011 +- added {block ... hide} option to supress block if no child is defined + +13/02/2011 +- update handling of recursive subtemplate calls +- bugfix replace $smarty->triggerError() by exception in smarty_internal_resource_extends.php + +12/02/2011 +- new class Smarty_Internal_TemplateBase with shared methods of Smarty and Template objects +- optimizations of template processing +- made register... methods permanet +- code for default_plugin_handler +- add automatic recompilation at version change + +04/02/2011 +- change in Smarty_CacheResource_Custom +- bugfix cache_lifetime did not compile correctly at {include} after last update +- moved isCached processing into CacheResource class +- bugfix new CacheResource API did not work with disabled compile_check + +03/02/2011 +- handle template content as function to improve speed on multiple calls of same subtemplate and isCached()/display() calls +- bugfixes and improvents in the new resource API +- optimizations of template class code + +25/01/2011 +- optimized function html_select_time + +22/01/2011 +- added Smarty::$use_include_path configuration directive for Resource API + +21/01/2011 +- optimized function html_select_date + +19/01/2011 +- optimized outputfilter trimwhitespace + +18/01/2011 +- bugfix Config to use Smarty_Resource to fetch sources +- optimized Smarty_Security's isTrustedDir() and isTrustedPHPDir() + +17/01/2011 +- bugfix HTTP headers for CGI SAPIs + +16/01/2011 +- optimized internals of Smarty_Resource and Smarty_CacheResource + +14/01/2011 +- added modifiercompiler escape to improve performance of escaping html, htmlall, url, urlpathinfo, quotes, javascript +- added support to choose template_dir to load from: [index]filename.tpl + +12/01/2011 +- added unencode modifier to revert results of encode modifier +- added to_charset and from_charset modifier for character encoding + +11/01/2011 +- added SMARTY_MBSTRING to generalize MBString detection +- added argument $lc_rest to modifier.capitalize to lower-case anything but the first character of a word +- changed strip modifier to consider unicode white-space, too +- changed wordwrap modifier to accept UTF-8 strings +- changed count_sentences modifier to consider unicode characters and treat sequences delimited by ? and ! as sentences, too +- added argument $double_encode to modifier.escape (applies to html and htmlall only) +- changed escape modifier to be UTF-8 compliant +- changed textformat block to be UTF-8 compliant +- optimized performance of mailto function +- fixed spacify modifier so characters are not prepended and appended, made it unicode compatible +- fixed truncate modifier to properly use mb_string if possible +- removed UTF-8 frenzy from count_characters modifier +- fixed count_words modifier to treat "hello-world" as a single word like str_count_words() does +- removed UTF-8 frenzy from upper modifier +- removed UTF-8 frenzy from lower modifier + +01/01/2011 +- optimize smarty_modified_escape for hex, hexentity, decentity. + +28/12/2010 +- changed $tpl_vars, $config_vars and $parent to belong to Smarty_Internal_Data +- added Smarty::registerCacheResource() for dynamic cache resource object registration + +27/12/2010 +- added Smarty_CacheResource API and refactored existing cache resources accordingly +- added Smarty_CacheResource_Custom and Smarty_CacheResource_Mysql + +26/12/2010 +- added Smarty_Resource API and refactored existing resources accordingly +- added Smarty_Resource_Custom and Smarty_Resource_Mysql +- bugfix Smarty::createTemplate() to return properly cloned template instances + +24/12/2010 +- optimize smarty_function_escape_special_chars() for PHP >= 5.2.3 + +===== SVN 3.0 trunk ===== 14/05/2011 - bugfix error handling at stream resources @@ -35,7 +301,6 @@ 22/04/2011 - bugfix allow only fixed string as file attribute at {extends} tag -- workaround for PHP 5.2.13 bug in method_exists() 01/04/2011 - bugfix do not run filters and default modifier when displaying the debug template @@ -73,7 +338,7 @@ 18/02/2011 - bugfix removed possible race condition when isCached() was called for an individually cached subtemplate -- bugfix force default debug.tpl to be loaded by the file resource when default_resource_type was modified +- bugfix force default debug.tpl to be loaded by the file resource 17/02/2011 -improvement not to delete files starting with '.' from cache and template_c folders on clearCompiledTemplate() and clearCache() @@ -83,8 +348,9 @@ -improvement allow leading spaces on } tag closing if auto_literal is enabled 13/02/2011 -- bugfix replace $smarty->triggerError() by exception in smarty_internal_resource_extends.php +- bufix replace $smarty->triggerError() by exception - removed obsolete {popup_init..} plugin from demo templates +- bugfix replace $smarty->triggerError() by exception in smarty_internal_resource_extends.php ===== Smarty 3.0.7 ===== 09/02/2011 @@ -615,7 +881,7 @@ request_use_auto_globals - added $smarty->_tag_stack for tracing block tag hierarchy 08/02/2010 -- bugfix use template fullpath at §smarty->cache->clear(...), $smarty->clear_cache(....) +- bugfix use template fullpath at §smarty->cache->clear(...), $smarty->clear_cache(....) - bugfix of cache filename on extended templates when force_compile=true 07/02/2010 diff --git a/demo/index.php b/demo/index.php index b9ec74ae..74c8e897 100644 --- a/demo/index.php +++ b/demo/index.php @@ -1,4 +1,10 @@ -* @package SmartyTestScripts -*/ -require('../libs/Smarty.class.php'); - - class Person -{ - private $m_szName; - private $m_iAge; - - public function setName($szName) - { - $this->m_szName = $szName; - return $this; // We now return $this (the Person) - } - - public function setAge($iAge) - { - $this->m_iAge = $iAge; - return $this; // Again, return our Person - } - - public function introduce() - { - return 'Hello my name is '.$this->m_szName.' and I am '.$this->m_iAge.' years old.'; - } -} - -$smarty = new Smarty(); -$smarty->allow_php_templates= true; -$smarty->force_compile = false; -$smarty->caching = true; -$smarty->cache_lifetime = 100; -//$smarty->debugging = true; - -$smarty->assign('foo',"'bar'"); - -$person = new Person; - -$smarty->assign('person',$person); - -$smarty->assign('array',array('a'=>array('aa'=>'This is a long string'),'b'=>2)); - -$smarty->display('php:index_view.php'); - -?> diff --git a/demo/plugins/cacheresource.apc.php b/demo/plugins/cacheresource.apc.php new file mode 100644 index 00000000..40369e3a --- /dev/null +++ b/demo/plugins/cacheresource.apc.php @@ -0,0 +1,76 @@ + $v) { + $_res[$k] = $v; + } + return $_res; + } + + /** + * Save values for a set of keys to cache + * + * @param array $keys list of values to save + * @param int $expire expiration time + * @return boolean true on success, false on failure + */ + protected function write(array $keys, $expire=null) + { + foreach ($keys as $k => $v) { + apc_store($k, $v, $expire); + } + return true; + } + + /** + * Remove values from cache + * + * @param array $keys list of keys to delete + * @return boolean true on success, false on failure + */ + protected function delete(array $keys) + { + foreach ($keys as $k) { + apc_delete($k); + } + return true; + } + + /** + * Remove *all* values from cache + * + * @return boolean true on success, false on failure + */ + protected function purge() + { + return apc_clear_cache('user'); + } +} diff --git a/demo/plugins/cacheresource.memcache.php b/demo/plugins/cacheresource.memcache.php new file mode 100644 index 00000000..230607d6 --- /dev/null +++ b/demo/plugins/cacheresource.memcache.php @@ -0,0 +1,91 @@ +memcache = new Memcache(); + $this->memcache->addServer( '127.0.0.1', 11211 ); + } + + /** + * Read values for a set of keys from cache + * + * @param array $keys list of keys to fetch + * @return array list of values with the given keys used as indexes + * @return boolean true on success, false on failure + */ + protected function read(array $keys) + { + $_keys = $lookup = array(); + foreach ($keys as $k) { + $_k = sha1($k); + $_keys[] = $_k; + $lookup[$_k] = $k; + } + $_res = array(); + $res = $this->memcache->get($_keys); + foreach ($res as $k => $v) { + $_res[$lookup[$k]] = $v; + } + return $_res; + } + + /** + * Save values for a set of keys to cache + * + * @param array $keys list of values to save + * @param int $expire expiration time + * @return boolean true on success, false on failure + */ + protected function write(array $keys, $expire=null) + { + foreach ($keys as $k => $v) { + $k = sha1($k); + $this->memcache->set($k, $v, 0, $expire); + } + return true; + } + + /** + * Remove values from cache + * + * @param array $keys list of keys to delete + * @return boolean true on success, false on failure + */ + protected function delete(array $keys) + { + foreach ($keys as $k) { + $k = sha1($k); + $this->memcache->delete($k); + } + return true; + } + + /** + * Remove *all* values from cache + * + * @return boolean true on success, false on failure + */ + protected function purge() + { + return $this->memcache->flush(); + } +} diff --git a/demo/plugins/cacheresource.mysql.php b/demo/plugins/cacheresource.mysql.php new file mode 100644 index 00000000..03455c80 --- /dev/null +++ b/demo/plugins/cacheresource.mysql.php @@ -0,0 +1,152 @@ +CREATE TABLE IF NOT EXISTS `output_cache` ( + * `id` CHAR(40) NOT NULL COMMENT 'sha1 hash', + * `name` VARCHAR(250) NOT NULL, + * `cache_id` VARCHAR(250) NULL DEFAULT NULL, + * `compile_id` VARCHAR(250) NULL DEFAULT NULL, + * `modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + * `content` LONGTEXT NOT NULL, + * PRIMARY KEY (`id`), + * INDEX(`name`), + * INDEX(`cache_id`), + * INDEX(`compile_id`), + * INDEX(`modified`) + * ) ENGINE = InnoDB; + * + * @package CacheResource-examples + * @author Rodney Rehm + */ +class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom { + // PDO instance + protected $db; + protected $fetch; + protected $fetchTimestamp; + protected $save; + + public function __construct() { + try { + $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty"); + } catch (PDOException $e) { + throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); + } + $this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id'); + $this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id'); + $this->save = $this->db->prepare('REPLACE INTO output_cache (id, name, cache_id, compile_id, content) + VALUES (:id, :name, :cache_id, :compile_id, :content)'); + } + + /** + * fetch cached content and its modification time from data source + * + * @param string $id unique cache content identifier + * @param string $name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * @param string $content cached content + * @param integer $mtime cache modification timestamp (epoch) + * @return void + */ + protected function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime) + { + $this->fetch->execute(array('id' => $id)); + $row = $this->fetch->fetch(); + $this->fetch->closeCursor(); + if ($row) { + $content = $row['content']; + $mtime = $row['modified']; + } else { + $content = null; + $mtime = null; + } + } + + /** + * Fetch cached content's modification timestamp from data source + * + * @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the complete cached content. + * @param string $id unique cache content identifier + * @param string $name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * @return integer|boolean timestamp (epoch) the template was modified, or false if not found + */ + protected function fetchTimestamp($id, $name, $cache_id, $compile_id) + { + $this->fetchTimestamp->execute(array('id' => $id)); + $mtime = $this->fetchTimestamp->fetchColumn(); + $this->fetchTimestamp->closeCursor(); + return $mtime; + } + + /** + * Save content to cache + * + * @param string $id unique cache content identifier + * @param string $name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * @param integer|null $exp_time seconds till expiration time in seconds or null + * @param string $content content to cache + * @return boolean success + */ + protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content) + { + $this->save->execute(array( + 'id' => $id, + 'name' => $name, + 'cache_id' => $cache_id, + 'compile_id' => $compile_id, + 'content' => $content, + )); + return !!$this->save->rowCount(); + } + + /** + * Delete content from cache + * + * @param string $name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * @param integer|null $exp_time seconds till expiration or null + * @return integer number of deleted caches + */ + protected function delete($name, $cache_id, $compile_id, $exp_time) + { + // delete the whole cache + if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) { + // returning the number of deleted caches would require a second query to count them + $query = $this->db->query('TRUNCATE TABLE output_cache'); + return -1; + } + // build the filter + $where = array(); + // equal test name + if ($name !== null) { + $where[] = 'name = ' . $this->db->quote($name); + } + // equal test compile_id + if ($compile_id !== null) { + $where[] = 'compile_id = ' . $this->db->quote($compile_id); + } + // range test expiration time + if ($exp_time !== null) { + $where[] = 'modified < DATE_SUB(NOW(), INTERVAL ' . intval($exp_time) . ' SECOND)'; + } + // equal test cache_id and match sub-groups + if ($cache_id !== null) { + $where[] = '(cache_id = '. $this->db->quote($cache_id) + . ' OR cache_id LIKE '. $this->db->quote($cache_id .'|%') .')'; + } + // run delete query + $query = $this->db->query('DELETE FROM output_cache WHERE ' . join(' AND ', $where)); + return $query->rowCount(); + } +} diff --git a/demo/plugins/resource.extendsall.php b/demo/plugins/resource.extendsall.php new file mode 100644 index 00000000..d8c40b5b --- /dev/null +++ b/demo/plugins/resource.extendsall.php @@ -0,0 +1,60 @@ +smarty->getTemplateDir() as $key => $directory) { + try { + $s = Smarty_Resource::source(null, $source->smarty, '[' . $key . ']' . $source->name ); + if (!$s->exists) { + continue; + } + $sources[$s->uid] = $s; + $uid .= $s->filepath; + } + catch (SmartyException $e) {} + } + + if (!$sources) { + $source->exists = false; + $source->template = $_template; + return; + } + + $sources = array_reverse($sources, true); + reset($sources); + $s = current($sources); + + $source->components = $sources; + $source->filepath = $s->filepath; + $source->uid = sha1($uid); + $source->exists = $exists; + if ($_template && $_template->smarty->compile_check) { + $source->timestamp = $s->timestamp; + } + // need the template at getContent() + $source->template = $_template; + } +} + +?> \ No newline at end of file diff --git a/demo/plugins/resource.mysql.php b/demo/plugins/resource.mysql.php new file mode 100644 index 00000000..312f3fc7 --- /dev/null +++ b/demo/plugins/resource.mysql.php @@ -0,0 +1,76 @@ +CREATE TABLE IF NOT EXISTS `templates` ( + * `name` varchar(100) NOT NULL, + * `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + * `source` text, + * PRIMARY KEY (`name`) + * ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + * + * Demo data: + *
INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');
+ * + * @package Resource-examples + * @author Rodney Rehm + */ +class Smarty_Resource_Mysql extends Smarty_Resource_Custom { + // PDO instance + protected $db; + // prepared fetch() statement + protected $fetch; + // prepared fetchTimestamp() statement + protected $mtime; + + public function __construct() { + try { + $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty"); + } catch (PDOException $e) { + throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); + } + $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); + $this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name'); + } + + /** + * Fetch a template and its modification time from database + * + * @param string $name template name + * @param string $source template source + * @param integer $mtime template modification timestamp (epoch) + * @return void + */ + protected function fetch($name, &$source, &$mtime) + { + $this->fetch->execute(array('name' => $name)); + $row = $this->fetch->fetch(); + $this->fetch->closeCursor(); + if ($row) { + $source = $row['source']; + $mtime = strtotime($row['modified']); + } else { + $source = null; + $mtime = null; + } + } + + /** + * Fetch a template's modification time from database + * + * @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source. + * @param string $name template name + * @return integer timestamp (epoch) the template was modified + */ + protected function fetchTimestamp($name) { + $this->mtime->execute(array('name' => $name)); + $mtime = $this->mtime->fetchColumn(); + $this->mtime->closeCursor(); + return strtotime($mtime); + } +} diff --git a/demo/plugins/resource.mysqls.php b/demo/plugins/resource.mysqls.php new file mode 100644 index 00000000..f9fe1c2f --- /dev/null +++ b/demo/plugins/resource.mysqls.php @@ -0,0 +1,62 @@ +CREATE TABLE IF NOT EXISTS `templates` ( + * `name` varchar(100) NOT NULL, + * `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + * `source` text, + * PRIMARY KEY (`name`) + * ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + * + * Demo data: + *
INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');
+ * + * @package Resource-examples + * @author Rodney Rehm + */ +class Smarty_Resource_Mysqls extends Smarty_Resource_Custom { + // PDO instance + protected $db; + // prepared fetch() statement + protected $fetch; + + public function __construct() { + try { + $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty"); + } catch (PDOException $e) { + throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); + } + $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); + } + + /** + * Fetch a template and its modification time from database + * + * @param string $name template name + * @param string $source template source + * @param integer $mtime template modification timestamp (epoch) + * @return void + */ + protected function fetch($name, &$source, &$mtime) + { + $this->fetch->execute(array('name' => $name)); + $row = $this->fetch->fetch(); + $this->fetch->closeCursor(); + if ($row) { + $source = $row['source']; + $mtime = strtotime($row['modified']); + } else { + $source = null; + $mtime = null; + } + } +} diff --git a/demo/templates/index_view.php b/demo/templates/index_view.php deleted file mode 100644 index 833fe961..00000000 --- a/demo/templates/index_view.php +++ /dev/null @@ -1,13 +0,0 @@ -PHP file test -$foo is -
Test functions - -
Test objects -setName('Paul')->setAge(39)->introduce()?> -
Test Arrays - -
function time - -
nocache function time -';?> -
DONE diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 6c9b7489..3e3492a9 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -1,71 +1,75 @@ +* @author Uwe Tews +* @author Rodney Rehm +* @package Smarty +* @version 3.1-DEV +*/ /** - * Project: Smarty: the PHP compiling template engine - * File: Smarty.class.php - * SVN: $Id$ - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For questions, help, comments, discussion, etc., please join the - * Smarty mailing list. Send a blank e-mail to - * smarty-discussion-subscribe@googlegroups.com - * - * @link http://www.smarty.net/ - * @copyright 2008 New Digital Group, Inc. - * @author Monte Ohrt - * @author Uwe Tews - * @package Smarty - * @version 3-SVN$Rev: 3286 $ - */ - -/** - * define shorthand directory separator constant - */ +* define shorthand directory separator constant +*/ if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } /** - * set SMARTY_DIR to absolute path to Smarty library files. - * Sets SMARTY_DIR only if user application has not already defined it. - */ +* set SMARTY_DIR to absolute path to Smarty library files. +* Sets SMARTY_DIR only if user application has not already defined it. +*/ if (!defined('SMARTY_DIR')) { define('SMARTY_DIR', dirname(__FILE__) . DS); } /** - * set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins. - * Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it. - */ +* set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins. +* Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it. +*/ if (!defined('SMARTY_SYSPLUGINS_DIR')) { define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS); } if (!defined('SMARTY_PLUGINS_DIR')) { define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS); } +if (!defined('SMARTY_MBSTRING')) { + define('SMARTY_MBSTRING', function_exists('mb_strlen')); +} if (!defined('SMARTY_RESOURCE_CHAR_SET')) { - define('SMARTY_RESOURCE_CHAR_SET', 'UTF-8'); + // UTF-8 can only be done properly when mbstring is available! + define('SMARTY_RESOURCE_CHAR_SET', SMARTY_MBSTRING ? 'UTF-8' : 'ISO-8859-1'); } if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y'); } /** - * register the class autoloader - */ +* register the class autoloader +*/ if (!defined('SMARTY_SPL_AUTOLOAD')) { define('SMARTY_SPL_AUTOLOAD', 0); } @@ -80,176 +84,465 @@ if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR } /** - * This is the main Smarty class - */ -class Smarty extends Smarty_Internal_Data { - /** - * constant definitions - */ - // smarty version - const SMARTY_VERSION = 'Smarty3-SVN$Rev: 3286 $'; - //define variable scopes - const SCOPE_LOCAL = 0; - const SCOPE_PARENT = 1; - const SCOPE_ROOT = 2; - const SCOPE_GLOBAL = 3; - // define caching modes - const CACHING_OFF = 0; - const CACHING_LIFETIME_CURRENT = 1; - const CACHING_LIFETIME_SAVED = 2; - /** modes for handling of "" tags in templates. **/ - const PHP_PASSTHRU = 0; //-> print tags as plain text - const PHP_QUOTE = 1; //-> escape tags as entities - const PHP_REMOVE = 2; //-> escape tags as entities - const PHP_ALLOW = 3; //-> escape tags as entities - // filter types - const FILTER_POST = 'post'; - const FILTER_PRE = 'pre'; - const FILTER_OUTPUT = 'output'; - const FILTER_VARIABLE = 'variable'; - // plugin types - const PLUGIN_FUNCTION = 'function'; - const PLUGIN_BLOCK = 'block'; - const PLUGIN_COMPILER = 'compiler'; - const PLUGIN_MODIFIER = 'modifier'; +* Load always needed external class files +*/ +include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_data.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_templatebase.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_template.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_resource.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_resource_file.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_cacheresource.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_cacheresource_file.php'; - /** - * static variables - */ - // assigned global tpl vars - static $global_tpl_vars = array(); +/** +* This is the main Smarty class +* @package Smarty +*/ +class Smarty extends Smarty_Internal_TemplateBase { - /** - * variables - */ - // auto literal on delimiters with whitspace - public $auto_literal = true; - // display error on not assigned variables - public $error_unassigned = false; - // template directory - public $template_dir = null; - // default template handler - public $default_template_handler_func = null; - // compile directory - public $compile_dir = null; - // plugins directory - public $plugins_dir = null; - // cache directory - public $cache_dir = null; - // config directory - public $config_dir = null; - // force template compiling? - public $force_compile = false; - // check template for modifications? - public $compile_check = true; - // locking concurrent compiles - public $compile_locking = true; - // use sub dirs for compiled/cached files? - public $use_sub_dirs = false; - // compile_error? - public $compile_error = false; - // caching enabled - public $caching = false; - // merge compiled includes - public $merge_compiled_includes = false; - // cache lifetime - public $cache_lifetime = 3600; - // force cache file creation - public $force_cache = false; - // cache_id - public $cache_id = null; - // compile_id - public $compile_id = null; - // template delimiters - public $left_delimiter = "{"; - public $right_delimiter = "}"; - // security - public $security_class = 'Smarty_Security'; - public $security_policy = null; - public $php_handling = self::PHP_PASSTHRU; - public $allow_php_tag = false; - public $allow_php_templates = false; - public $direct_access_security = true; - public $trusted_dir = array(); - // debug mode - public $debugging = false; - public $debugging_ctrl = 'NONE'; - public $smarty_debug_id = 'SMARTY_DEBUG'; - public $debug_tpl = null; - // When set, smarty does uses this value as error_reporting-level. - public $error_reporting = null; - // config var settings - public $config_overwrite = true; //Controls whether variables with the same name overwrite each other. - public $config_booleanize = true; //Controls whether config values of on/true/yes and off/false/no get converted to boolean - public $config_read_hidden = false; //Controls whether hidden config sections/vars are read from the file. - // config vars - public $config_vars = array(); - // assigned tpl vars - public $tpl_vars = array(); - // dummy parent object - public $parent = null; - // global template functions - public $template_functions = array(); - // resource type used if none given - public $default_resource_type = 'file'; - // caching type - public $caching_type = 'file'; - // internal cache resource types - public $cache_resource_types = array('file'); - // internal config properties - public $properties = array(); - // config type - public $default_config_type = 'file'; - // cached template objects - public $template_objects = null; - // check If-Modified-Since headers - public $cache_modified_check = false; - // registered plugins - public $registered_plugins = array(); - // plugin search order - public $plugin_search_order = array('function', 'block', 'compiler', 'class'); - // registered objects - public $registered_objects = array(); - // registered classes - public $registered_classes = array(); - // registered filters - public $registered_filters = array(); - // registered resources - public $registered_resources = array(); - // autoload filter - public $autoload_filters = array(); - // status of filter on variable output - public $variable_filter = true; - // default modifier - public $default_modifiers = array(); - // global internal smarty vars - static $_smarty_vars = array(); - // start time for execution time calculation - public $start_time = 0; - // default file permissions - public $_file_perms = 0644; - // default dir permissions - public $_dir_perms = 0771; - // block tag hierarchy - public $_tag_stack = array(); - // flag if {block} tag is compiled for template inheritance - public $inheritance = false; - // generate deprecated function call notices? - public $deprecation_notices = true; - // internal flag for getTags() - public $get_used_tags = false; - // Smarty 2 BC - public $_version = self::SMARTY_VERSION; - // self pointer to Smarty object - public $smarty; + /**#@+ + * constant definitions + */ /** - * Class constructor, initializes basic smarty properties + * smarty version + */ + const SMARTY_VERSION = 'Smarty 3.1-DEV'; + + /** + * define variable scopes + */ + const SCOPE_LOCAL = 0; + const SCOPE_PARENT = 1; + const SCOPE_ROOT = 2; + const SCOPE_GLOBAL = 3; + /** + * define caching modes + */ + const CACHING_OFF = 0; + const CACHING_LIFETIME_CURRENT = 1; + const CACHING_LIFETIME_SAVED = 2; + /** + * define compile check modes + */ + const COMPILECHECK_OFF = 0; + const COMPILECHECK_ON = 1; + const COMPILECHECK_CACHEMISS = 2; + /** + * modes for handling of "" tags in templates. + */ + const PHP_PASSTHRU = 0; //-> print tags as plain text + const PHP_QUOTE = 1; //-> escape tags as entities + const PHP_REMOVE = 2; //-> escape tags as entities + const PHP_ALLOW = 3; //-> escape tags as entities + /** + * filter types + */ + const FILTER_POST = 'post'; + const FILTER_PRE = 'pre'; + const FILTER_OUTPUT = 'output'; + const FILTER_VARIABLE = 'variable'; + /** + * plugin types + */ + const PLUGIN_FUNCTION = 'function'; + const PLUGIN_BLOCK = 'block'; + const PLUGIN_COMPILER = 'compiler'; + const PLUGIN_MODIFIER = 'modifier'; + const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler'; + + /**#@-*/ + + /** + * assigned global tpl vars + */ + public static $global_tpl_vars = array(); + + /**#@+ + * variables + */ + + /** + * auto literal on delimiters with whitspace + * @var boolean + */ + public $auto_literal = true; + /** + * display error on not assigned variables + * @var boolean + */ + public $error_unassigned = false; + /** + * look up relative filepaths in include_path + * @var boolean + */ + public $use_include_path = false; + /** + * template directory + * @var string + */ + protected $template_dir = null; + /** + * default template handler + * @var callable + */ + public $default_template_handler_func = null; + /** + * default config handler + * @var callable + */ + public $default_config_handler_func = null; + /** + * default plugin handler + * @var callable + */ + public $default_plugin_handler_func = null; + /** + * compile directory + * @var string + */ + protected $compile_dir = null; + /** + * plugins directory + * @var string + */ + protected $plugins_dir = null; + /** + * cache directory + * @var string + */ + protected $cache_dir = null; + /** + * config directory + * @var string + */ + protected $config_dir = null; + /** + * force template compiling? + * @var boolean + */ + public $force_compile = false; + /** + * check template for modifications? + * @var boolean + */ + public $compile_check = true; + /** + * use sub dirs for compiled/cached files? + * @var boolean + */ + public $use_sub_dirs = false; + /** + * caching enabled + * @var boolean + */ + public $caching = false; + /** + * merge compiled includes + * @var boolean + */ + public $merge_compiled_includes = false; + /** + * cache lifetime in seconds + * @var integer + */ + public $cache_lifetime = 3600; + /** + * force cache file creation + * @var boolean + */ + public $force_cache = false; + /** + * Set this if you want different sets of cache files for the same + * templates. + * + * @var string */ + public $cache_id = null; + /** + * Set this if you want different sets of compiled files for the same + * templates. + * + * @var string + */ + public $compile_id = null; + /** + * template left-delimiter + * @var string + */ + public $left_delimiter = "{"; + /** + * template right-delimiter + * @var string + */ + public $right_delimiter = "}"; + /**#@+ + * security + */ + /** + * class name + * + * This should be instance of Smarty_Security. + * + * @var string + * @see Smarty_Security + */ + public $security_class = 'Smarty_Security'; + /** + * implementation of security class + * + * @var Smarty_Security + */ + public $security_policy = null; + /** + * controls handling of PHP-blocks + * + * @var integer + */ + public $php_handling = self::PHP_PASSTHRU; + /** + * controls if the php template file resource is allowed + * + * @var bool + */ + public $allow_php_templates = false; + /** + * Should compiled-templates be prevented from being called directly? + * + * {@internal + * Currently used by Smarty_Internal_Template only. + * }} + * + * @var boolean + */ + public $direct_access_security = true; + /**#@-*/ + /** + * debug mode + * + * Setting this to true enables the debug-console. + * + * @var boolean + */ + public $debugging = false; + /** + * This determines if debugging is enable-able from the browser. + *
    + *
  • NONE => no debugging control allowed
  • + *
  • URL => enable debugging when SMARTY_DEBUG is found in the URL.
  • + *
+ * @var string + */ + public $debugging_ctrl = 'NONE'; + /** + * Name of debugging URL-param. + * + * Only used when $debugging_ctrl is set to 'URL'. + * The name of the URL-parameter that activates debugging. + * + * @var type + */ + public $smarty_debug_id = 'SMARTY_DEBUG'; + /** + * Path of debug template. + * @var string + */ + public $debug_tpl = null; + /** + * When set, smarty uses this value as error_reporting-level. + * @var int + */ + public $error_reporting = null; + /** + * Internal flag for getTags() + * @var boolean + */ + public $get_used_tags = false; + + /**#@+ + * config var settings + */ + + /** + * Controls whether variables with the same name overwrite each other. + * @var boolean + */ + public $config_overwrite = true; + /** + * Controls whether config values of on/true/yes and off/false/no get converted to boolean. + * @var boolean + */ + public $config_booleanize = true; + /** + * Controls whether hidden config sections/vars are read from the file. + * @var boolean + */ + public $config_read_hidden = false; + + /**#@-*/ + + /**#@+ + * resource locking + */ + + /** + * locking concurrent compiles + * @var boolean + */ + public $compile_locking = true; + /** + * Controls whether cache resources should emply locking mechanism + * @var boolean + */ + public $cache_locking = false; + /** + * seconds to wait for acquiring a lock before ignoring the write lock + * @var float + */ + public $locking_timeout = 10; + + /**#@-*/ + + /** + * global template functions + * @var array + */ + public $template_functions = array(); + /** + * resource type used if none given + * + * Must be an valid key of $registered_resources. + * @var string + */ + public $default_resource_type = 'file'; + /** + * caching type + * + * Must be an element of $cache_resource_types. + * + * @var string + */ + public $caching_type = 'file'; + /** + * internal config properties + * @var array + */ + public $properties = array(); + /** + * config type + * @var string + */ + public $default_config_type = 'file'; + /** + * cached template objects + * @var array + */ + public $template_objects = array(); + /** + * check If-Modified-Since headers + * @var boolean + */ + public $cache_modified_check = false; + /** + * registered plugins + * @var array + */ + public $registered_plugins = array(); + /** + * plugin search order + * @var array + */ + public $plugin_search_order = array('function', 'block', 'compiler', 'class'); + /** + * registered objects + * @var array + */ + public $registered_objects = array(); + /** + * registered classes + * @var array + */ + public $registered_classes = array(); + /** + * registered filters + * @var array + */ + public $registered_filters = array(); + /** + * registered resources + * @var array + */ + public $registered_resources = array(); + /** + * registered cache resources + * @var array + */ + public $registered_cache_resources = array(); + /** + * autoload filter + * @var array + */ + public $autoload_filters = array(); + /** + * default modifier + * @var array + */ + public $default_modifiers = array(); + /** + * autoescape variable output + * @var boolean + */ + public $escape_html = false; + /** + * global internal smarty vars + * @var array + */ + public static $_smarty_vars = array(); + /** + * start time for execution time calculation + * @var int + */ + public $start_time = 0; + /** + * default file permissions + * @var int + */ + public $_file_perms = 0644; + /** + * default dir permissions + * @var int + */ + public $_dir_perms = 0771; + /** + * block tag hierarchy + * @var array + */ + public $_tag_stack = array(); + /** + * self pointer to Smarty object + * @var Smarty + */ + public $smarty; + /** + * required by the compiler for BC + * @var string + */ + public $_current_file = null; + /** + * internal flag to enable parser debugging + * @var bool + */ + public $_parserdebug = false; + /**#@-*/ + + /** + * Initialize new Smarty object + * + */ public function __construct() { - // selfpointer need by some other class methods - $this->smarty = $this; + // selfpointer needed by some other class methods + $this->smarty = $this; if (is_callable('mb_internal_encoding')) { mb_internal_encoding(SMARTY_RESOURCE_CHAR_SET); } @@ -259,241 +552,107 @@ class Smarty extends Smarty_Internal_Data { $this->compile_dir = '.' . DS . 'templates_c' . DS; $this->plugins_dir = array(SMARTY_PLUGINS_DIR); $this->cache_dir = '.' . DS . 'cache' . DS; - $this->config_dir = '.' . DS . 'configs' . DS; - $this->debug_tpl = 'file:' . SMARTY_DIR . 'debug.tpl'; + $this->config_dir = array('.' . DS . 'configs' . DS); + $this->debug_tpl = 'file:' . dirname(__FILE__) . '/debug.tpl'; if (isset($_SERVER['SCRIPT_NAME'])) { $this->assignGlobal('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']); } } /** - * Class destructor - */ + * Class destructor + */ public function __destruct() { + // intentionally left blank } /** - * fetches a rendered Smarty template - * - * @param string $template the resource handle of the template file or template object - * @param mixed $cache_id cache id to be used with this template - * @param mixed $compile_id compile id to be used with this template - * @param object $ |null $parent next higher level of Smarty variables - * @return string rendered template output - */ - public function fetch($template, $cache_id = null, $compile_id = null, $parent = null, $display = false) + * <> set selfpointer on cloned object + */ + public function __clone() { - if (!empty($cache_id) && is_object($cache_id)) { - $parent = $cache_id; - $cache_id = null; - } - if ($parent === null) { - // get default Smarty data object - $parent = $this; - } - // create template object if necessary - ($template instanceof $this->template_class)? $_template = $template : - $_template = $this->createTemplate ($template, $cache_id, $compile_id, $parent, false); - if (isset($this->error_reporting)) { - $_smarty_old_error_level = error_reporting($this->error_reporting); - } - // check URL debugging control - if (!$this->debugging && $this->debugging_ctrl == 'URL') { - if (isset($_SERVER['QUERY_STRING'])) { - $_query_string = $_SERVER['QUERY_STRING']; - } else { - $_query_string = ''; - } - if (false !== strpos($_query_string, $this->smarty_debug_id)) { - if (false !== strpos($_query_string, $this->smarty_debug_id . '=on')) { - // enable debugging for this browser session - setcookie('SMARTY_DEBUG', true); - $this->debugging = true; - } elseif (false !== strpos($_query_string, $this->smarty_debug_id . '=off')) { - // disable debugging for this browser session - setcookie('SMARTY_DEBUG', false); - $this->debugging = false; - } else { - // enable debugging for this page - $this->debugging = true; - } - } else { - if (isset($_COOKIE['SMARTY_DEBUG'])) { - $this->debugging = true; - } - } - } - // obtain data for cache modified check - if ($this->cache_modified_check && $this->caching && $display) { - $_isCached = $_template->isCached() && !$_template->has_nocache_code; - if ($_isCached) { - $_gmt_mtime = gmdate('D, d M Y H:i:s', $_template->getCachedTimestamp()) . ' GMT'; - } else { - $_gmt_mtime = ''; - } - } - // return rendered template - if ((!$this->caching || $_template->resource_object->isEvaluated) && (isset($this->autoload_filters['output']) || isset($this->registered_filters['output']))) { - $_output = Smarty_Internal_Filter_Handler::runFilter('output', $_template->getRenderedTemplate(), $_template); + $this->smarty = $this; + } + + + /** + * <> Generic getter. + * + * Calls the appropriate getter function. + * Issues an E_USER_NOTICE if no valid getter is found. + * + * @param string $name property name + * @return mixed + */ + public function __get($name) + { + $allowed = array( + 'template_dir' => 'getTemplateDir', + 'config_dir' => 'getConfigDir', + 'plugins_dir' => 'getPluginsDir', + 'compile_dir' => 'getCompileDir', + 'cache_dir' => 'getCacheDir', + ); + + if (isset($allowed[$name])) { + return $this->{$allowed[$name]}(); } else { - $_output = $_template->getRenderedTemplate(); + trigger_error('Undefined property: '. get_class($this) .'::$'. $name, E_USER_NOTICE); } - $_template->rendered_content = null; - if (isset($this->error_reporting)) { - error_reporting($_smarty_old_error_level); - } - // display or fetch - if ($display) { - if ($this->caching && $this->cache_modified_check) { - $_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); - if ($_isCached && $_gmt_mtime == $_last_modified_date) { - if (php_sapi_name() == 'cgi') - header('Status: 304 Not Modified'); - else - header('HTTP/1.1 304 Not Modified'); - } else { - header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->getCachedTimestamp()) . ' GMT'); - echo $_output; - } - } else { - echo $_output; - } - // debug output - if ($this->debugging) { - Smarty_Internal_Debug::display_debug($this); - } - return; + } + + /** + * <> Generic setter. + * + * Calls the appropriate setter function. + * Issues an E_USER_NOTICE if no valid setter is found. + * + * @param string $name property name + * @param mixed $value parameter passed to setter + */ + public function __set($name, $value) + { + $allowed = array( + 'template_dir' => 'setTemplateDir', + 'config_dir' => 'setConfigDir', + 'plugins_dir' => 'setPluginsDir', + 'compile_dir' => 'setCompileDir', + 'cache_dir' => 'setCacheDir', + ); + + if (isset($allowed[$name])) { + $this->{$allowed[$name]}($value); } else { - // return fetched content - return $_output; + trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); } } /** - * displays a Smarty template - * - * @param string $ |object $template the resource handle of the template file or template object - * @param mixed $cache_id cache id to be used with this template - * @param mixed $compile_id compile id to be used with this template - * @param object $parent next higher level of Smarty variables - */ - public function display($template, $cache_id = null, $compile_id = null, $parent = null) - { - // display template - $this->fetch ($template, $cache_id, $compile_id, $parent, true); - } - - /** - * test if cache i valid - * - * @param string $ |object $template the resource handle of the template file or template object - * @param mixed $cache_id cache id to be used with this template - * @param mixed $compile_id compile id to be used with this template - * @param object $parent next higher level of Smarty variables - * @return boolean cache status - */ - public function isCached($template, $cache_id = null, $compile_id = null, $parent = null) - { - if ($parent === null) { - $parent = $this; - } - if (!($template instanceof $this->template_class)) { - $template = $this->createTemplate ($template, $cache_id, $compile_id, $parent, false); - } - // return cache status of template - return $template->isCached(); - } - - /** - * creates a data object - * - * @param object $parent next higher level of Smarty variables - * @returns object data object - */ - public function createData($parent = null) - { - return new Smarty_Data($parent, $this); - } - - /** - * creates a template object - * - * @param string $template the resource handle of the template file - * @param mixed $cache_id cache id to be used with this template - * @param mixed $compile_id compile id to be used with this template - * @param object $parent next higher level of Smarty variables - * @param boolean $do_clone flag is Smarty object shall be cloned - * @returns object template object - */ - public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true) - { - if (!empty($cache_id) && (is_object($cache_id) || is_array($cache_id))) { - $parent = $cache_id; - $cache_id = null; - } - if (!empty($parent) && is_array($parent)) { - $data = $parent; - $parent = null; - } else { - $data = null; - } - if (!is_object($template)) { - // we got a template resource - // already in template cache? - $_templateId = sha1($template . $cache_id . $compile_id); - if (isset($this->template_objects[$_templateId]) && $this->caching) { - // return cached template object - $tpl = $this->template_objects[$_templateId]; - } else { - // create new template object - if ($do_clone) { - $tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id); - } else { - $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id); - } - } - } else { - // just return a copy of template class - $tpl = $template; - } - // fill data if present - if (!empty($data) && is_array($data)) { - // set up variable values - foreach ($data as $_key => $_val) { - $tpl->tpl_vars[$_key] = new Smarty_variable($_val); - } - } - return $tpl; - } - - - - /** - * Check if a template resource exists - * - * @param string $resource_name template name - * @return boolean status - */ - function templateExists($resource_name) + * Check if a template resource exists + * + * @param string $resource_name template name + * @return boolean status + */ + public function templateExists($resource_name) { // create template object $save = $this->template_objects; $tpl = new $this->template_class($resource_name, $this); // check if it does exists - $result = $tpl->isExisting(); + $result = $tpl->source->exists; $this->template_objects = $save; return $result; } /** - * Returns a single or all global variables - * - * @param object $smarty - * @param string $varname variable name or null - * @return string variable value or or array of variables - */ - function getGlobal($varname = null) + * Returns a single or all global variables + * + * @param object $smarty + * @param string $varname variable name or null + * @return string variable value or or array of variables + */ + public function getGlobal($varname = null) { if (isset($varname)) { if (isset(self::$global_tpl_vars[$varname])) { @@ -514,168 +673,497 @@ class Smarty extends Smarty_Internal_Data { * Empty cache folder * * @param integer $exp_time expiration time - * @param string $type resource type + * @param string $type resource type * @return integer number of cache files deleted */ function clearAllCache($exp_time = null, $type = null) { - // load cache resource and call clearAll - return $this->loadCacheResource($type)->clearAll($exp_time); + // load cache resource and call clearAll + $_cache_resource = Smarty_CacheResource::load($this, $type); + Smarty_CacheResource::invalidLoadedCache($this); + return $_cache_resource->clearAll($this, $exp_time); } /** * Empty cache for a specific template * - * @param string $template_name template name - * @param string $cache_id cache id - * @param string $compile_id compile id - * @param integer $exp_time expiration time - * @param string $type resource type + * @param string $template_name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * @param integer $exp_time expiration time + * @param string $type resource type * @return integer number of cache files deleted */ - function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null) + public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null) { - // load cache resource and call clear - return $this->loadCacheResource($type)->clear($template_name, $cache_id, $compile_id, $exp_time); + // load cache resource and call clear + $_cache_resource = Smarty_CacheResource::load($this, $type); + Smarty_CacheResource::invalidLoadedCache($this); + return $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time); } /** - * Loads security class and enables security - */ + * Loads security class and enables security + * + * @param string|Smarty_Security $security_class if a string is used, it must be class-name + * @return Smarty current Smarty instance for chaining + * @throws SmartyException when an invalid class name is provided + */ public function enableSecurity($security_class = null) { - if ($security_class instanceof Smarty_Security) { - $this->security_policy = $security_class; - return; - } - if ($security_class == null) { - $security_class = $this->security_class; - } - if (class_exists($security_class)) { - $this->security_policy = new $security_class($this); - } else { - throw new SmartyException("Security class '$security_class' is not defined"); + if ($security_class instanceof Smarty_Security) { + $this->security_policy = $security_class; + return $this; + } elseif (is_object($security_class)) { + throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security."); } + if ($security_class == null) { + $security_class = $this->security_class; + } + if (!class_exists($security_class)) { + throw new SmartyException("Security class '$security_class' is not defined"); + } elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) { + throw new SmartyException("Class '$security_class' must extend Smarty_Security."); + } else { + $this->security_policy = new $security_class($this); + } + + return $this; } /** - * Disable security - */ + * Disable security + * @return Smarty current Smarty instance for chaining + */ public function disableSecurity() { - $this->security_policy = null; + $this->security_policy = null; + + return $this; } /** - * Loads cache resource. + * Set template directory * - * @param string $type cache resource type - * @return object of cache resource + * @param string|array $template_dir directory(s) of template sources + * @return Smarty current Smarty instance for chaining */ - public function loadCacheResource($type = null) { - if (!isset($type)) { - $type = $this->caching_type; - } - if (in_array($type, $this->cache_resource_types)) { - $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type); - return new $cache_resource_class($this); - } - else { - // try plugins dir - $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type); - if ($this->loadPlugin($cache_resource_class)) { - return new $cache_resource_class($this); - } - else { - throw new SmartyException("Unable to load cache resource '{$type}'"); - } - } - } - - - /** - * Set template directory - * - * @param string $ |array $template_dir folder(s) of template sorces - */ public function setTemplateDir($template_dir) { - $this->template_dir = (array)$template_dir; - return; + $this->template_dir = array(); + foreach ((array) $template_dir as $k => $v) { + $this->template_dir[$k] = rtrim($v, '/\\') . DS; + } + + return $this; } /** - * Adds template directory(s) to existing ones - * - * @param string $ |array $template_dir folder(s) of template sources - */ - public function addTemplateDir($template_dir) + * Add template directory(s) + * + * @param string|array $template_dir directory(s) of template sources + * @param string $key of the array element to assign the template dir to + * @return Smarty current Smarty instance for chaining + * @throws SmartyException when the given template directory is not valid + */ + public function addTemplateDir($template_dir, $key=null) { - $this->template_dir = array_unique(array_merge((array)$this->template_dir, (array)$template_dir)); - return; + // make sure we're dealing with an array + $this->template_dir = (array) $this->template_dir; + + if (is_array($template_dir)) { + foreach ($template_dir as $k => $v) { + if (is_int($k)) { + // indexes are not merged but appended + $this->template_dir[] = rtrim($v, '/\\') . DS; + } else { + // string indexes are overridden + $this->template_dir[$k] = rtrim($v, '/\\') . DS; + } + } + } elseif ($key !== null) { + // override directory at specified index + $this->template_dir[$key] = rtrim($template_dir, '/\\') . DS; + } else { + // append new directory + $this->template_dir[] = rtrim($template_dir, '/\\') . DS; + } + + return $this; } /** - * Adds directory of plugin files - * - * @param object $smarty - * @param string $ |array $ plugins folder - * @return - */ - function addPluginsDir($plugins_dir) + * Get template directories + * + * @param mixed index of directory to get, null to get all + * @return array|string list of template directories, or directory of $index + */ + public function getTemplateDir($index=null) { - $this->plugins_dir = array_unique(array_merge((array)$this->plugins_dir, (array)$plugins_dir)); - return; + if ($index !== null) { + return isset($this->template_dir[$index]) ? $this->template_dir[$index] : null; + } + + return $this->template_dir; } - /** - * return a reference to a registered object - * - * @param string $name object name - * @return object - */ - function getRegisteredObject($name) + * Set config directory + * + * @param string|array $template_dir directory(s) of configuration sources + * @return Smarty current Smarty instance for chaining + */ + public function setConfigDir($config_dir) { - if (!isset($this->registered_objects[$name])) - throw new SmartyException("'$name' is not a registered object"); + $this->config_dir = array(); + foreach ((array) $config_dir as $k => $v) { + $this->config_dir[$k] = rtrim($v, '/\\') . DS; + } - if (!is_object($this->registered_objects[$name][0])) - throw new SmartyException("registered '$name' is not an object"); + return $this; + } - return $this->registered_objects[$name][0]; + /** + * Add config directory(s) + * + * @param string|array $config_dir directory(s) of config sources + * @param string key of the array element to assign the config dir to + * @return Smarty current Smarty instance for chaining + */ + public function addConfigDir($config_dir, $key=null) + { + // make sure we're dealing with an array + $this->config_dir = (array) $this->config_dir; + + if (is_array($config_dir)) { + foreach ($config_dir as $k => $v) { + if (is_int($k)) { + // indexes are not merged but appended + $this->config_dir[] = rtrim($v, '/\\') . DS; + } else { + // string indexes are overridden + $this->config_dir[$k] = rtrim($v, '/\\') . DS; + } + } + } elseif( $key !== null ) { + // override directory at specified index + $this->config_dir[$key] = rtrim($config_dir, '/\\') . DS; + } else { + // append new directory + $this->config_dir[] = rtrim($config_dir, '/\\') . DS; + } + + return $this; + } + + /** + * Get config directory + * + * @param mixed index of directory to get, null to get all + * @return array|string configuration directory + */ + public function getConfigDir($index=null) + { + if ($index !== null) { + return isset($this->config_dir[$index]) ? $this->config_dir[$index] : null; + } + + return $this->config_dir; + } + + /** + * Set plugins directory + * + * @param string|array $plugins_dir directory(s) of plugins + * @return Smarty current Smarty instance for chaining + */ + public function setPluginsDir($plugins_dir) + { + $this->plugins_dir = array(); + foreach ((array)$plugins_dir as $k => $v) { + $this->plugins_dir[$k] = rtrim($v, '/\\') . DS; + } + + return $this; + } + + /** + * Adds directory of plugin files + * + * @param object $smarty + * @param string $ |array $ plugins folder + * @return Smarty current Smarty instance for chaining + */ + public function addPluginsDir($plugins_dir) + { + // make sure we're dealing with an array + $this->plugins_dir = (array) $this->plugins_dir; + + if (is_array($plugins_dir)) { + foreach ($plugins_dir as $k => $v) { + if (is_int($k)) { + // indexes are not merged but appended + $this->plugins_dir[] = rtrim($v, '/\\') . DS; + } else { + // string indexes are overridden + $this->plugins_dir[$k] = rtrim($v, '/\\') . DS; + } + } + } else { + // append new directory + $this->plugins_dir[] = rtrim($plugins_dir, '/\\') . DS; + } + + $this->plugins_dir = array_unique($this->plugins_dir); + return $this; + } + + /** + * Get plugin directories + * + * @return array list of plugin directories + */ + public function getPluginsDir() + { + return $this->plugins_dir; + } + + /** + * Set compile directory + * + * @param string $compile_dir directory to store compiled templates in + * @return Smarty current Smarty instance for chaining + */ + public function setCompileDir($compile_dir) + { + $this->compile_dir = rtrim($compile_dir, '/\\') . DS; + return $this; + } + + /** + * Get compiled directory + * + * @return string path to compiled templates + */ + public function getCompileDir() + { + return $this->compile_dir; + } + + /** + * Set cache directory + * + * @param string $cache_dir directory to store cached templates in + * @return Smarty current Smarty instance for chaining + */ + public function setCacheDir($cache_dir) + { + $this->cache_dir = rtrim($cache_dir, '/\\') . DS; + return $this; + } + + /** + * Get cache directory + * + * @return string path of cache directory + */ + public function getCacheDir() + { + return $this->cache_dir; + } + + /** + * Set default modifiers + * + * @param array|string $modifiers modifier or list of modifiers to set + * @return Smarty current Smarty instance for chaining + */ + public function setDefaultModifiers($modifiers) + { + $this->default_modifiers = (array) $modifiers; + return $this; + } + + /** + * Add default modifiers + * + * @param array|string $modifiers modifier or list of modifiers to add + * @return Smarty current Smarty instance for chaining + */ + public function addDefaultModifiers($modifiers) + { + if (is_array($modifiers)) { + $this->default_modifiers = array_merge($this->default_modifiers, $modifiers); + } else { + $this->default_modifiers[] = $modifiers; + } + + return $this; + } + + /** + * Get default modifiers + * + * @return array list of default modifiers + */ + public function getDefaultModifiers() + { + return $this->default_modifiers; } /** - * return name of debugging template - * - * @return string - */ - function getDebugTemplate() + * Set autoload filters + * + * @param array $filters filters to load automatically + * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types + * @return Smarty current Smarty instance for chaining + */ + public function setAutoloadFilters($filters, $type=null) + { + if ($type !== null) { + $this->autoload_filters[$type] = (array) $filters; + } else { + $this->autoload_filters = (array) $filters; + } + + return $this; + } + + /** + * Add autoload filters + * + * @param array $filters filters to load automatically + * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types + * @return Smarty current Smarty instance for chaining + */ + public function addAutoloadFilters($filters, $type=null) + { + if ($type !== null) { + if (!empty($this->autoload_filters[$type])) { + $this->autoload_filters[$type] = array_merge($this->autoload_filters[$type], (array) $filters); + } else { + $this->autoload_filters[$type] = (array) $filters; + } + } else { + foreach ((array) $filters as $key => $value) { + if (!empty($this->autoload_filters[$key])) { + $this->autoload_filters[$key] = array_merge($this->autoload_filters[$key], (array) $value); + } else { + $this->autoload_filters[$key] = (array) $value; + } + } + } + + return $this; + } + + /** + * Get autoload filters + * + * @param string $type type of filter to get autoloads for. Defaults to all autoload filters + * @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type was specified + */ + public function getAutoloadFilters($type=null) + { + if ($type !== null) { + return isset($this->autoload_filters[$type]) ? $this->autoload_filters[$type] : array(); + } + + return $this->autoload_filters; + } + + /** + * return name of debugging template + * + * @return string + */ + public function getDebugTemplate() { return $this->debug_tpl; } /** - * set the debug template - * - * @param string $tpl_name - * @return bool - */ - function setDebugTemplate($tpl_name) + * set the debug template + * + * @param string $tpl_name + * @return Smarty current Smarty instance for chaining + * @throws SmartyException if file is not readable + */ + public function setDebugTemplate($tpl_name) { - return $this->debug_tpl = $tpl_name; + if (!is_readable($tpl_name)) { + throw new SmartyException("Unknown file '{$tpl_name}'"); + } + $this->debug_tpl = $tpl_name; + + return $this; } /** - * Takes unknown classes and loads plugin files for them - * class name format: Smarty_PluginType_PluginName - * plugin filename format: plugintype.pluginname.php - * - * @param string $plugin_name class plugin name to load - * @return string |boolean filepath of loaded file or false - */ + * creates a template object + * + * @param string $template the resource handle of the template file + * @param mixed $cache_id cache id to be used with this template + * @param mixed $compile_id compile id to be used with this template + * @param object $parent next higher level of Smarty variables + * @param boolean $do_clone flag is Smarty object shall be cloned + * @return object template object + */ + public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true) + { + if (!empty($cache_id) && (is_object($cache_id) || is_array($cache_id))) { + $parent = $cache_id; + $cache_id = null; + } + if (!empty($parent) && is_array($parent)) { + $data = $parent; + $parent = null; + } else { + $data = null; + } + // default to cache_id and compile_id of Smarty object + $cache_id = $cache_id === null ? $this->cache_id : $cache_id; + $compile_id = $compile_id === null ? $this->compile_id : $compile_id; + // already in template cache? + $_templateId = sha1($template . $cache_id . $compile_id); + if ($do_clone) { + if (isset($this->template_objects[$_templateId])) { + // return cached template object + $tpl = clone $this->template_objects[$_templateId]; + $tpl->smarty = clone $tpl->smarty; + $tpl->parent = $parent; + } else { + $tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id); + } + } else { + if (isset($this->template_objects[$_templateId])) { + // return cached template object + $tpl = $this->template_objects[$_templateId]; + } else { + $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id); + } + } + // fill data if present + if (!empty($data) && is_array($data)) { + // set up variable values + foreach ($data as $_key => $_val) { + $tpl->tpl_vars[$_key] = new Smarty_variable($_val); + } + } + return $tpl; + } + + + /** + * Takes unknown classes and loads plugin files for them + * class name format: Smarty_PluginType_PluginName + * plugin filename format: plugintype.pluginname.php + * + * @param string $plugin_name class plugin name to load + * @param bool $check check if already loaded + * @return string |boolean filepath of loaded file or false + */ public function loadPlugin($plugin_name, $check = true) { // if function or class exists, exit silently (already loaded) @@ -702,20 +1190,66 @@ class Smarty extends Smarty_Internal_Data { // plugin filename is expected to be: [type].[name].php $_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php"; // loop through plugin dirs and find the plugin - foreach((array)$this->plugins_dir as $_plugin_dir) { - if (strpos('/\\', substr($_plugin_dir, -1)) === false) { - $_plugin_dir .= DS; - } + foreach($this->getPluginsDir() as $_plugin_dir) { $file = $_plugin_dir . $_plugin_filename; if (file_exists($file)) { require_once($file); return $file; } + if ($this->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) { + // try PHP include_path + if (($file = Smarty_Internal_Get_Include_Path::getIncludePath($file)) !== false) { + require_once($file); + return $file; + } + } } // no plugin loaded return false; } + /** + * Compile all template files + * + * @param string $extension file extension + * @param bool $force_compile force all to recompile + * @param int $time_limit + * @param int $max_errors + * @return integer number of template files recompiled + */ + public function compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null) + { + return Smarty_Internal_Utility::compileAllTemplates($extention, $force_compile, $time_limit, $max_errors, $this); + } + + /** + * Compile all config files + * + * @param string $extension file extension + * @param bool $force_compile force all to recompile + * @param int $time_limit + * @param int $max_errors + * @return integer number of template files recompiled + */ + public function compileAllConfig($extention = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null) + { + return Smarty_Internal_Utility::compileAllConfig($extention, $force_compile, $time_limit, $max_errors, $this); + } + + /** + * Delete compiled template file + * + * @param string $resource_name template name + * @param string $compile_id compile id + * @param integer $exp_time expiration time + * @return integer number of template files deleted + */ + public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null) + { + return Smarty_Internal_Utility::clearCompiledTemplate($resource_name, $compile_id, $exp_time, $this); + } + + /** * Return array of tag/attributes of all tags used by an template * @@ -728,101 +1262,53 @@ class Smarty extends Smarty_Internal_Data { } /** - * clean up properties on cloned object + * Run installation test + * + * @param array $errors Array to write errors into, rather than outputting them + * @return boolean true if setup is fine, false if something is wrong */ - public function __clone() + public function testInstall(&$errors=null) { - // clear config vars - $this->config_vars = array(); - // clear assigned tpl vars - $this->tpl_vars = array(); - // clear objects for external methods - unset($this->Register); - unset($this->Filter); - } + return Smarty_Internal_Utility::testInstall($this, $errors); + } - - /** - * Handle unknown class methods - * - * @param string $name unknown methode name - * @param array $args aurgument array - */ - public function __call($name, $args) - { - static $camel_func; - if (!isset($camel_func)) - $camel_func = create_function('$c', 'return "_" . strtolower($c[1]);'); - // see if this is a set/get for a property - $first3 = strtolower(substr($name, 0, 3)); - if (in_array($first3, array('set', 'get')) && substr($name, 3, 1) !== '_') { - // try to keep case correct for future PHP 6.0 case-sensitive class methods - // lcfirst() not available < PHP 5.3.0, so improvise - $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4); - // convert camel case to underscored name - $property_name = preg_replace_callback('/([A-Z])/', $camel_func, $property_name); - if (!property_exists($this, $property_name)) { - throw new SmartyException("property '$property_name' does not exist."); - return false; - } - if ($first3 == 'get') - return $this->$property_name; - else - return $this->$property_name = $args[0]; - } - // Smarty Backward Compatible wrapper - if (strpos($name,'_') !== false) { - if (!isset($this->wrapper)) { - $this->wrapper = new Smarty_Internal_Wrapper($this); - } - return $this->wrapper->convert($name, $args); - } - // external Smarty methods ? - foreach(array('Filter','Register') as $external) { - if (class_exists("Smarty_Internal_{$external}") && method_exists("Smarty_Internal_{$external}",$name)) { - if (!isset($this->$external)) { - $class = "Smarty_Internal_{$external}"; - $this->$external = new $class($this); - } - return call_user_func_array(array($this->$external,$name), $args); - } - } - if (in_array($name,array('clearCompiledTemplate','compileAllTemplates','compileAllConfig','testInstall','getTags'))) { - if (!isset($this->utility)) { - $this->utility = new Smarty_Internal_Utility($this); - } - return call_user_func_array(array($this->utility,$name), $args); - } - // PHP4 call to constructor? - if (strtolower($name) == 'smarty') { - throw new SmartyException('Please use parent::__construct() to call parent constuctor'); - return false; - } - throw new SmartyException("Call of unknown function '$name'."); - } } /** - * Autoloader - */ +* Smarty exception class +* @package Smarty +*/ +class SmartyException extends Exception { +} + +/** +* Smarty compiler exception class +* @package Smarty +*/ +class SmartyCompilerException extends SmartyException { +} + +/** +* Autoloader +*/ function smartyAutoload($class) { $_class = strtolower($class); - if (substr($_class, 0, 16) === 'smarty_internal_' || $_class == 'smarty_security') { + if (substr($_class, 0, 16) == 'smarty_internal_' + || in_array( $_class, array( + 'smarty_config_source', + 'smarty_config_compiled', + 'smarty_security', + 'smarty_cacheresource', + 'smarty_cacheresource_custom', + 'smarty_cacheresource_keyvaluestore', + 'smarty_resource', + 'smarty_resource_custom', + 'smarty_resource_uncompiled', + 'smarty_resource_recompiled', + ))) { include SMARTY_SYSPLUGINS_DIR . $_class . '.php'; } } -/** - * Smarty exception class - */ -Class SmartyException extends Exception { -} - -/** - * Smarty compiler exception class - */ -Class SmartyCompilerException extends SmartyException { -} - -?> +?> \ No newline at end of file diff --git a/libs/SmartyBC.class.php b/libs/SmartyBC.class.php new file mode 100644 index 00000000..f8f0a138 --- /dev/null +++ b/libs/SmartyBC.class.php @@ -0,0 +1,460 @@ + + * @author Uwe Tews + * @author Rodney Rehm + * @package Smarty + */ +/** + * @ignore + */ +require(dirname(__FILE__) . '/Smarty.class.php'); + +/** + * Smarty Backward Compatability Wrapper Class + * + * @package Smarty + */ +class SmartyBC extends Smarty { + + /** + * Smarty 2 BC + * @var string + */ + public $_version = self::SMARTY_VERSION; + + /** + * Initialize new SmartyBC object + * + * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false ) + */ + public function __construct(array $options=array()) + { + parent::__construct($options); + // register {php} tag + $this->registerPlugin('block', 'php', 'smarty_php_tag'); + } + + /** + * wrapper for assign_by_ref + * + * @param string $tpl_var the template variable name + * @param mixed &$value the referenced value to assign + */ + public function assign_by_ref($tpl_var, &$value) + { + $this->assignByRef($tpl_var, $value); + } + + /** + * wrapper for append_by_ref + * + * @param string $tpl_var the template variable name + * @param mixed &$value the referenced value to append + * @param boolean $merge flag if array elements shall be merged + */ + public function append_by_ref($tpl_var, &$value, $merge = false) + { + $this->appendByRef($tpl_var, $value, $merge); + } + + /** + * clear the given assigned template variable. + * + * @param string $tpl_var the template variable to clear + */ + public function clear_assign($tpl_var) + { + $this->clearAssign($tpl_var); + } + + /** + * Registers custom function to be used in templates + * + * @param string $function the name of the template function + * @param string $function_impl the name of the PHP function to register + * @param bool $cacheable + * @param mixed $cache_attrs + */ + public function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null) + { + $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs); + } + + /** + * Unregisters custom function + * + * @param string $function name of template function + */ + public function unregister_function($function) + { + $this->unregisterPlugin('function', $function); + } + + /** + * Registers object to be used in templates + * + * @param string $object name of template object + * @param object $object_impl the referenced PHP object to register + * @param array $allowed list of allowed methods (empty = all) + * @param boolean $smarty_args smarty argument format, else traditional + * @param array $block_functs list of methods that are block format + */ + public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) + { + settype($allowed, 'array'); + settype($smarty_args, 'boolean'); + $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods); + } + + /** + * Unregisters object + * + * @param string $object name of template object + */ + public function unregister_object($object) + { + $this->unregisterObject($object); + } + + /** + * Registers block function to be used in templates + * + * @param string $block name of template block + * @param string $block_impl PHP function to register + * @param bool $cacheable + * @param mixed $cache_attrs + */ + public function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null) + { + $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs); + } + + /** + * Unregisters block function + * + * @param string $block name of template function + */ + public function unregister_block($block) + { + $this->unregisterPlugin('block', $block); + } + + /** + * Registers compiler function + * + * @param string $function name of template function + * @param string $function_impl name of PHP function to register + * @param bool $cacheable + */ + public function register_compiler_function($function, $function_impl, $cacheable=true) + { + $this->registerPlugin('compiler', $function, $function_impl, $cacheable); + } + + /** + * Unregisters compiler function + * + * @param string $function name of template function + */ + public function unregister_compiler_function($function) + { + $this->unregisterPlugin('compiler', $function); + } + + /** + * Registers modifier to be used in templates + * + * @param string $modifier name of template modifier + * @param string $modifier_impl name of PHP function to register + */ + public function register_modifier($modifier, $modifier_impl) + { + $this->registerPlugin('modifier', $modifier, $modifier_impl); + } + + /** + * Unregisters modifier + * + * @param string $modifier name of template modifier + */ + public function unregister_modifier($modifier) + { + $this->unregisterPlugin('modifier', $modifier); + } + + /** + * Registers a resource to fetch a template + * + * @param string $type name of resource + * @param array $functions array of functions to handle resource + */ + public function register_resource($type, $functions) + { + $this->registerResource($type, $functions); + } + + /** + * Unregisters a resource + * + * @param string $type name of resource + */ + public function unregister_resource($type) + { + $this->unregisterResource($type); + } + + /** + * Registers a prefilter function to apply + * to a template before compiling + * + * @param callable $function + */ + public function register_prefilter($function) + { + $this->registerFilter('pre', $function); + } + + /** + * Unregisters a prefilter function + * + * @param callable $function + */ + public function unregister_prefilter($function) + { + $this->unregisterFilter('pre', $function); + } + + /** + * Registers a postfilter function to apply + * to a compiled template after compilation + * + * @param callable $function + */ + public function register_postfilter($function) + { + $this->registerFilter('post', $function); + } + + /** + * Unregisters a postfilter function + * + * @param callable $function + */ + public function unregister_postfilter($function) + { + $this->unregisterFilter('post', $function); + } + + /** + * Registers an output filter function to apply + * to a template output + * + * @param callable $function + */ + public function register_outputfilter($function) + { + $this->registerFilter('output', $function); + } + + /** + * Unregisters an outputfilter function + * + * @param callable $function + */ + public function unregister_outputfilter($function) + { + $this->unregisterFilter('output', $function); + } + + /** + * load a filter of specified type and name + * + * @param string $type filter type + * @param string $name filter name + */ + public function load_filter($type, $name) + { + $this->loadFilter($type, $name); + } + + /** + * clear cached content for the given template and cache id + * + * @param string $tpl_file name of template file + * @param string $cache_id name of cache_id + * @param string $compile_id name of compile_id + * @param string $exp_time expiration time + * @return boolean + */ + public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) + { + return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time); + } + + /** + * clear the entire contents of cache (all templates) + * + * @param string $exp_time expire time + * @return boolean + */ + public function clear_all_cache($exp_time = null) + { + return $this->clearCache(null, null, null, $exp_time); + } + + /** + * test to see if valid cache exists for this template + * + * @param string $tpl_file name of template file + * @param string $cache_id + * @param string $compile_id + * @return boolean + */ + public function is_cached($tpl_file, $cache_id = null, $compile_id = null) + { + return $this->isCached($tpl_file, $cache_id, $compile_id); + } + + /** + * clear all the assigned template variables. + */ + public function clear_all_assign() + { + $this->clearAllAssign(); + } + + /** + * clears compiled version of specified template resource, + * or all compiled template files if one is not specified. + * This function is for advanced use only, not normally needed. + * + * @param string $tpl_file + * @param string $compile_id + * @param string $exp_time + * @return boolean results of {@link smarty_core_rm_auto()} + */ + public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) + { + return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time); + } + + /** + * Checks whether requested template exists. + * + * @param string $tpl_file + * @return boolean + */ + public function template_exists($tpl_file) + { + return $this->templateExists($tpl_file); + } + + /** + * Returns an array containing template variables + * + * @param string $name + * @return array + */ + public function get_template_vars($name=null) + { + return $this->getTemplateVars($name); + } + + /** + * Returns an array containing config variables + * + * @param string $name + * @return array + */ + public function get_config_vars($name=null) + { + return $this->getConfigVars($name); + } + + /** + * load configuration values + * + * @param string $file + * @param string $section + * @param string $scope + */ + public function config_load($file, $section = null, $scope = 'global') + { + $this->ConfigLoad($file, $section, $scope); + } + + /** + * return a reference to a registered object + * + * @param string $name + * @return object + */ + public function get_registered_object($name) + { + return $this->getRegisteredObject($name); + } + + /** + * clear configuration values + * + * @param string $var + */ + public function clear_config($var = null) + { + $this->clearConfig($var); + } + + /** + * trigger Smarty error + * + * @param string $error_msg + * @param integer $error_type + */ + public function trigger_error($error_msg, $error_type = E_USER_WARNING) + { + trigger_error("Smarty error: $error_msg", $error_type); + } + +} + +/** + * Smarty {php}{/php} block function + * + * @param array $params parameter list + * @param string $content contents of the block + * @param object $template template object + * @param boolean &$repeat repeat flag + * @return string content re-formatted + */ +function smarty_php_tag($params, $content, $template, &$repeat) +{ + eval($content); + return ''; +} + +?> \ No newline at end of file diff --git a/libs/plugins/block.php.php b/libs/plugins/block.php.php deleted file mode 100644 index 8fedd8b4..00000000 --- a/libs/plugins/block.php.php +++ /dev/null @@ -1,27 +0,0 @@ -allow_php_tag) { - throw new SmartyException("{php} is deprecated, set allow_php_tag = true to enable"); - } - eval($content); - return ''; -} - -?> \ No newline at end of file diff --git a/libs/plugins/block.textformat.php b/libs/plugins/block.textformat.php index 517fd62d..dc465ac9 100644 --- a/libs/plugins/block.textformat.php +++ b/libs/plugins/block.textformat.php @@ -8,34 +8,35 @@ /** * Smarty {textformat}{/textformat} block plugin - * + * * Type: block function
* Name: textformat
* Purpose: format text a certain way with preset styles - * or custom wrap/indent settings
- * - * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat} - * (Smarty online manual) - * @param array $params parameters + * or custom wrap/indent settings
+ * Params: *
- * Params:   style: string (email)
- *            indent: integer (0)
- *            wrap: integer (80)
- *            wrap_char string ("\n")
- *            indent_char: string (" ")
- *            wrap_boundary: boolean (true)
+ * - style         - string (email)
+ * - indent        - integer (0)
+ * - wrap          - integer (80)
+ * - wrap_char     - string ("\n")
+ * - indent_char   - string (" ")
+ * - wrap_boundary - boolean (true)
  * 
- * @author Monte Ohrt - * @param string $content contents of the block - * @param object $template template object - * @param boolean &$repeat repeat flag + * + * @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat} + * (Smarty online manual) + * @param array $params parameters + * @param string $content contents of the block + * @param Smarty_Internal_Template $template template object + * @param boolean &$repeat repeat flag * @return string content re-formatted + * @author Monte Ohrt */ function smarty_block_textformat($params, $content, $template, &$repeat) { if (is_null($content)) { return; - } + } $style = null; $indent = 0; @@ -67,36 +68,41 @@ function smarty_block_textformat($params, $content, $template, &$repeat) default: trigger_error("textformat: unknown attribute '$_key'"); - } - } + } + } if ($style == 'email') { $wrap = 72; - } + } // split into paragraphs - $_paragraphs = preg_split('![\r\n][\r\n]!', $content); + $_paragraphs = preg_split('![\r\n]{2}!', $content); $_output = ''; for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) { if ($_paragraphs[$_x] == '') { continue; - } + } // convert mult. spaces & special chars to single space - $_paragraphs[$_x] = preg_replace(array('!\s+!', '!(^\s+)|(\s+$)!'), array(' ', ''), $_paragraphs[$_x]); + $_paragraphs[$_x] = preg_replace(array('!\s+!u', '!(^\s+)|(\s+$)!u'), array(' ', ''), $_paragraphs[$_x]); // indent first line if ($indent_first > 0) { $_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x]; - } + } // wordwrap sentences - $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut); + if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'); + $_paragraphs[$_x] = smarty_mb_wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut); + } else { + $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut); + } // indent lines if ($indent > 0) { $_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]); - } - } + } + } $_output = implode($wrap_char . $wrap_char, $_paragraphs); - + return $assign ? $template->assign($assign, $_output) : $_output; -} +} ?> \ No newline at end of file diff --git a/libs/plugins/function.counter.php b/libs/plugins/function.counter.php index 7c50bd44..3906badf 100644 --- a/libs/plugins/function.counter.php +++ b/libs/plugins/function.counter.php @@ -11,12 +11,12 @@ * Type: function
* Name: counter
* Purpose: print out a counter value + * * @author Monte Ohrt - * @link http://smarty.php.net/manual/en/language.function.counter.php {counter} + * @link http://www.smarty.net/manual/en/language.function.counter.php {counter} * (Smarty online manual) - * @param array parameters - * @param Smarty - * @param object $template template object + * @param array $params parameters + * @param Smarty_Internal_Template $template template object * @return string|null */ function smarty_function_counter($params, $template) diff --git a/libs/plugins/function.cycle.php b/libs/plugins/function.cycle.php index 98e3e287..d456ee54 100644 --- a/libs/plugins/function.cycle.php +++ b/libs/plugins/function.cycle.php @@ -13,45 +13,45 @@ * Name: cycle
* Date: May 3, 2002
* Purpose: cycle through given values
- * Input: - * - name = name of cycle (optional) - * - values = comma separated list of values to cycle, - * or an array of values to cycle - * (this can be left out for subsequent calls) - * - reset = boolean - resets given var to true - * - print = boolean - print var or not. default is true - * - advance = boolean - whether or not to advance the cycle - * - delimiter = the value delimiter, default is "," - * - assign = boolean, assigns to template var instead of - * printed. - * + * Params: + *
+ * - name      - name of cycle (optional)
+ * - values    - comma separated list of values to cycle, or an array of values to cycle
+ *               (this can be left out for subsequent calls)
+ * - reset     - boolean - resets given var to true
+ * - print     - boolean - print var or not. default is true
+ * - advance   - boolean - whether or not to advance the cycle
+ * - delimiter - the value delimiter, default is ","
+ * - assign    - boolean, assigns to template var instead of printed.
+ * 
* Examples:
*
  * {cycle values="#eeeeee,#d0d0d0d"}
  * {cycle name=row values="one,two,three" reset=true}
  * {cycle name=row}
  * 
- * @link http://smarty.php.net/manual/en/language.function.cycle.php {cycle} + * + * @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle} * (Smarty online manual) * @author Monte Ohrt * @author credit to Mark Priatel * @author credit to Gerard * @author credit to Jason Sweat * @version 1.3 - * @param array - * @param object $template template object + * @param array $params parameters + * @param Smarty_Internal_Template $template template object * @return string|null */ function smarty_function_cycle($params, $template) { static $cycle_vars; - + $name = (empty($params['name'])) ? 'default' : $params['name']; $print = (isset($params['print'])) ? (bool)$params['print'] : true; $advance = (isset($params['advance'])) ? (bool)$params['advance'] : true; $reset = (isset($params['reset'])) ? (bool)$params['reset'] : false; - + if (!in_array('values', array_keys($params))) { if(!isset($cycle_vars[$name]['values'])) { trigger_error("cycle: missing 'values' parameter"); @@ -68,24 +68,24 @@ function smarty_function_cycle($params, $template) if (isset($params['delimiter'])) { $cycle_vars[$name]['delimiter'] = $params['delimiter']; } elseif (!isset($cycle_vars[$name]['delimiter'])) { - $cycle_vars[$name]['delimiter'] = ','; + $cycle_vars[$name]['delimiter'] = ','; } - + if(is_array($cycle_vars[$name]['values'])) { $cycle_array = $cycle_vars[$name]['values']; } else { $cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']); } - + if(!isset($cycle_vars[$name]['index']) || $reset ) { $cycle_vars[$name]['index'] = 0; } - + if (isset($params['assign'])) { $print = false; $template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]); } - + if($print) { $retval = $cycle_array[$cycle_vars[$name]['index']]; } else { @@ -99,7 +99,7 @@ function smarty_function_cycle($params, $template) $cycle_vars[$name]['index']++; } } - + return $retval; } diff --git a/libs/plugins/function.fetch.php b/libs/plugins/function.fetch.php index a800350b..cde98d2e 100644 --- a/libs/plugins/function.fetch.php +++ b/libs/plugins/function.fetch.php @@ -12,13 +12,13 @@ * Type: function
* Name: fetch
* Purpose: fetch file, web or ftp data and display results - * @link http://smarty.php.net/manual/en/language.function.fetch.php {fetch} + * + * @link http://www.smarty.net/manual/en/language.function.fetch.php {fetch} * (Smarty online manual) * @author Monte Ohrt - * @param array $params parameters - * @param object $template template object - * @return string|null if the assign parameter is passed, Smarty assigns the - * result to a template variable + * @param array $params parameters + * @param Smarty_Internal_Template $template template object + * @return string|null if the assign parameter is passed, Smarty assigns the result to a template variable */ function smarty_function_fetch($params, $template) { @@ -32,7 +32,7 @@ function smarty_function_fetch($params, $template) if(!$template->smarty->security_policy->isTrustedResourceDir($params['file'])) { return; } - + // fetch the file if($fp = @fopen($params['file'],'r')) { while(!feof($fp)) { @@ -52,7 +52,7 @@ function smarty_function_fetch($params, $template) $host = $server_name = $uri_parts['host']; $timeout = 30; $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; - $agent = "Smarty Template Engine ".$template->_version; + $agent = "Smarty Template Engine ". Smarty::SMARTY_VERSION; $referer = ""; $uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/'; $uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : ''; diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php index 6a1a3ffd..40e4a8fc 100644 --- a/libs/plugins/function.html_checkboxes.php +++ b/libs/plugins/function.html_checkboxes.php @@ -20,20 +20,23 @@ * {html_checkboxes values=$ids name='box' separator='
' output=$names} * {html_checkboxes values=$ids checked=$checked separator='
' output=$names} * - * @link http://smarty.php.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} + * Params: + *
+ * - name       (optional) - string default "checkbox"
+ * - values     (required) - array
+ * - options    (optional) - associative array
+ * - checked    (optional) - array default not set
+ * - separator  (optional) - ie 
or   + * - output (optional) - the output next to each checkbox + * - assign (optional) - assign the output as an array to this variable + *
+ * + * @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} * (Smarty online manual) * @author Christopher Kvarme * @author credits to Monte Ohrt * @version 1.0 * @param array $params parameters - * Input:
- * - name (optional) - string default "checkbox" - * - values (required) - array - * - options (optional) - associative array - * - checked (optional) - array default not set - * - separator (optional) - ie
or   - * - output (optional) - the output next to each checkbox - * - assign (optional) - assign the output as an array to this variable * @param object $template template object * @return string * @uses smarty_function_escape_special_chars() diff --git a/libs/plugins/function.html_image.php b/libs/plugins/function.html_image.php index f148f1c3..2f1ef641 100644 --- a/libs/plugins/function.html_image.php +++ b/libs/plugins/function.html_image.php @@ -13,23 +13,24 @@ * Name: html_image
* Date: Feb 24, 2003
* Purpose: format HTML tags for the image
- * Examples: {html_image file="/images/masthead.gif"} - * Output: + * Examples: {html_image file="/images/masthead.gif"}
+ * Output:
+ * Params: + *
+ * - file        - (required) - file (and path) of image
+ * - height      - (optional) - image height (default actual height)
+ * - width       - (optional) - image width (default actual width)
+ * - basedir     - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT
+ * - path_prefix - prefix for path output (optional, default empty)
+ * 
* - * @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image} + * @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image} * (Smarty online manual) * @author Monte Ohrt * @author credits to Duda * @version 1.0 - * @param array $params parameters - * Input:
- * - file = file (and path) of image (required) - * - height = image height (optional, default actual height) - * - width = image width (optional, default actual width) - * - basedir = base directory for absolute paths, default - * is environment variable DOCUMENT_ROOT - * - path_prefix = prefix for path output (optional, default empty) - * @param object $template template object + * @param array $params parameters + * @param Smarty_Internal_Template $template template object * @return string * @uses smarty_function_escape_special_chars() */ diff --git a/libs/plugins/function.html_options.php b/libs/plugins/function.html_options.php index 7ac03902..269601a5 100644 --- a/libs/plugins/function.html_options.php +++ b/libs/plugins/function.html_options.php @@ -12,19 +12,24 @@ * Type: function
* Name: html_options
* Purpose: Prints the list of