Compare commits

...

158 Commits

Author SHA1 Message Date
Simon Wisselink c201ccd3fd WIP 2023-01-29 22:02:44 +01:00
Simon Wisselink 28377a26e9 WIP on creating new CodeFrames using nette 2023-01-28 10:45:59 +01:00
Simon Wisselink 8a2ed9446a Update composer packages cache key
Update composer packages cache key to trigger refresh on lexer
2023-01-28 10:44:01 +01:00
Simon Wisselink 39dad96601 Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. 2023-01-26 13:03:04 +01:00
Simon Wisselink c47756b489 Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. 2023-01-26 12:58:15 +01:00
Simon Wisselink 047b73d4a1 Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer 2023-01-26 12:57:46 +01:00
Simon Wisselink cabcafc7ea Fix smarty-lexer dependency for the time being (remove direct ref to github) 2023-01-25 21:58:46 +01:00
Simon Wisselink a72f83d989 Fix smarty-lexer dependency for the time being 2023-01-25 21:58:04 +01:00
Simon Wisselink 9e2399b020 updated todo 2023-01-25 17:00:12 +01:00
Simon Wisselink 169cd924df Re-organized rendering (read source / compile / cache) process to avoid circular dependencies.
Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll
have to check back.
2023-01-25 16:59:10 +01:00
Simon Wisselink 46dfed3837 Updated the changelog 2023-01-24 22:45:35 +01:00
Simon Wisselink 754db3b2e3 correct type of repository 2023-01-24 16:31:46 +01:00
Simon Wisselink 971c4d5158 Shouldnt need Github token now 2023-01-24 16:18:36 +01:00
Simon Wisselink a8cf56e4f4 attempt to load smarty-lexer directly from zip file 2023-01-24 16:18:09 +01:00
Simon Wisselink 45de28107a Update ci.yml 2023-01-24 16:12:53 +01:00
Simon Wisselink 79842c8baf Update ci.yml 2023-01-24 16:08:16 +01:00
Simon Wisselink 0e380a1748 fixes in source files 2023-01-24 16:05:38 +01:00
Simon Wisselink f53eb27450 Update ci.yml 2023-01-24 15:56:26 +01:00
Simon Wisselink a5a15b8b1e Update ci.yml 2023-01-24 15:54:15 +01:00
Simon Wisselink 262221f0b7 revise CI/CD workflows, bypass packagist for lexer 2023-01-24 15:49:44 +01:00
Simon Wisselink 344b3e3a31 Attempt to fix CI 2023-01-24 13:59:17 +01:00
Simon Wisselink b798362871 Run composer install before online test run 2023-01-24 12:57:01 +01:00
Simon Wisselink 1a8ee6ebda Merge branch 'master' into smarty5 2023-01-24 12:53:58 +01:00
Simon Wisselink 641678083b Add TODO list 2023-01-24 12:14:55 +01:00
Simon Wisselink ecfa4bfa16 Fixed getCachedContent 2023-01-24 12:09:47 +01:00
Simon Wisselink 9cc60f5e38 Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. 2023-01-24 12:01:20 +01:00
Simon Wisselink 431d77505f Fixed all scope assignment bugs 2023-01-24 10:16:00 +01:00
Simon Wisselink c5f555eed4 Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() 2023-01-23 16:59:52 +01:00
Simon Wisselink 2cf658c9c3 Fix function call compilation using {functionname} syntax for in-template defined functions. 2023-01-23 16:56:42 +01:00
Simon Wisselink ecac24d073 Fixed bug in {include} variable assignment and removed some unused/unrequired code 2023-01-23 16:40:27 +01:00
Simon Wisselink 34a0a2876b Fix major {include} bug 2023-01-23 15:56:26 +01:00
Simon Wisselink 3922c1eb1e Fixed the {if} failures. 2023-01-23 15:34:29 +01:00
Simon Wisselink 68c59e6627 Fix all foreach unit tests 2023-01-23 15:16:45 +01:00
Simon Wisselink ad2703dd75 Handle BC registered compilers and missed parameters for openTag and closeTag. 2023-01-23 12:08:36 +01:00
Simon Wisselink f1c3ac4395 Fixed all inheritance issues 2023-01-23 11:45:29 +01:00
Simon Wisselink 7c02bb9a63 Fix inhertiance implementation for $smarty.block.child 2023-01-23 08:47:49 +01:00
Simon Wisselink 4bbe94f4e0 Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent}
and {block_child} and {child} alternatives to {$smarty.block.child}
2023-01-22 23:01:05 +01:00
Simon Wisselink bdb379d8fb Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. 2023-01-22 22:44:45 +01:00
Simon Wisselink 2d2d052557 Fix default plugin handler 2023-01-21 00:03:08 +01:00
Simon Wisselink f1f3874780 Made exception msgs exactly the same again, fixing some unit tests 2023-01-20 23:45:27 +01:00
Simon Wisselink 4ea8838d3b Fix testRegisterCompilerFunction by parsing argument correctly. 2023-01-20 23:42:08 +01:00
Simon Wisselink 03430c4f94 Fixed block append/prepend functionality 2023-01-20 23:16:41 +01:00
Simon Wisselink 2fbf67b32e Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. 2023-01-20 17:22:00 +01:00
Simon Wisselink 390f34318d Fixed cacheability of block plugins. 2023-01-19 23:29:10 +01:00
Simon Wisselink 27dd3e4c57 Fix function caching function name 2023-01-19 22:35:03 +01:00
Simon Wisselink 41c8bd3035 @var integer > @var int for vsCode 2023-01-19 22:32:06 +01:00
Simon Wisselink 38cad9723e Fix searchParents parameter, fixing GetTemplateVarsTest 2023-01-19 22:30:16 +01:00
Adrien Poupa 5988116c81 PHP 8.1 deprecation warnings on null strings in modifiers (#834) 2023-01-17 00:24:23 +01:00
Simon Wisselink f5b432dea4 Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. 2023-01-13 23:29:05 +01:00
Simon Wisselink b02061878f Update test runners: no longer support PHP7.1, add PHP8.2 2023-01-13 23:28:18 +01:00
Simon Wisselink 73ff8fd3d0 Fix unit tests that broke because now is now in 2023 2023-01-13 22:19:17 +01:00
Simon Wisselink d900a0ef4a Added variable scope test for multi-level extends resource 2023-01-13 19:23:12 +01:00
Simon Wisselink 5c74dc4a83 Replaced a bunch of direct property access with getters/setters. 2023-01-13 16:55:15 +01:00
Simon Wisselink 3be63a3418 Removed unneeded magic setters/getters/destructors and the like. 2023-01-13 15:56:25 +01:00
Simon Wisselink cdf1ed2a50 Simplified the (no)caching architecture by:
- removing support for $cache_attrs for registered plugins,
- removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code
- removing support for a compile_id property on include tags.

Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement.
2023-01-13 15:47:57 +01:00
Simon Wisselink e0f2c36d4d converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. 2023-01-13 00:04:08 +01:00
Simon Wisselink 541f0821f0 Replace direct access to inheritance property on Template object by proper getter. 2023-01-12 10:11:10 +01:00
Simon Wisselink 536721d457 Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. 2023-01-12 09:59:10 +01:00
Simon Wisselink 577f910e49 removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. 2023-01-11 23:33:12 +01:00
Simon Wisselink 1fe5050a04 Fix configfile tests 2023-01-11 13:05:42 +01:00
Simon Wisselink 22ce23b47b Made variable scoping more sensible 2023-01-11 11:22:24 +01:00
Simon Wisselink ad245ccd0c Fixed minor unit tests 2023-01-11 00:00:07 +01:00
Simon Wisselink 51075e0421 WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( 2023-01-10 23:49:33 +01:00
Simon Wisselink 3d10630510 WIP rewriting variable scopes 2023-01-10 17:35:34 +01:00
Simon Wisselink 5052ce0d88 WIP 2023-01-10 14:54:21 +01:00
Simon Wisselink 9651dafbce WIP replacing direct access tpl_vars with proper getter/setters. 2023-01-10 14:46:33 +01:00
Simon Wisselink b424657fd9 Fix bug in calling BC function handlers. 2023-01-10 14:45:58 +01:00
Simon Wisselink 9016dd9908 Added strlen function, fixing some unit tests 2023-01-09 11:54:13 +01:00
Simon Wisselink e124f71dd8 Fixed issue related to scoping of left/right delimiter overrides 2023-01-09 11:25:09 +01:00
Simon Wisselink 34d5d6d024 Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. 2023-01-09 09:55:22 +01:00
Simon Wisselink c5de83b09f Fixed modifiercompiler handling multiple/chained modifiers 2023-01-09 09:53:15 +01:00
Simon Wisselink 861aafa92c 2 small fixes for unit tests 2023-01-07 23:45:59 +01:00
Simon Wisselink e1d395e140 Fixed stream resources 2023-01-07 23:22:58 +01:00
Simon Wisselink fd64cc688a Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. 2023-01-07 23:06:47 +01:00
Simon Wisselink e595cd2a5d Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests 2023-01-06 21:53:37 +01:00
Simon Wisselink b2e11ee2b8 Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. 2023-01-06 21:43:48 +01:00
Simon Wisselink 1f87cebb93 Make DefaultExtension lazy load again. 2023-01-06 21:41:23 +01:00
Simon Wisselink 608a400e66 Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. 2023-01-05 23:07:45 +01:00
Simon Wisselink f07e342d61 Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. 2023-01-05 23:06:02 +01:00
Simon Wisselink 576bd4cc01 Removed support for PHP include path, and removed the ::loadPlugin method. 2023-01-05 21:58:29 +01:00
Simon Wisselink e89a3dda49 Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests 2023-01-05 11:18:42 +01:00
Simon Wisselink 2b71415d1f minor fixes 2023-01-04 23:48:45 +01:00
Simon Wisselink 3cc61133a3 Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. 2023-01-04 23:45:57 +01:00
Simon Wisselink 216347b4ff Introduce formatParamsArray method for recurring code fragment 2023-01-04 14:42:30 +01:00
Simon Wisselink 14bbffd584 move runPluginFromDefaultHandler to new Runtime class 2023-01-04 13:19:25 +01:00
Simon Wisselink 41054cfb05 Fixed DefaultPluginHandlerTest for function plugins (blocks still break) 2023-01-04 12:16:10 +01:00
Simon Wisselink 16c7fe1d4f Fixed setfilter 2023-01-03 22:03:43 +01:00
Simon Wisselink 3fccb54093 Fixed CacheResource implementation and tests 2023-01-03 17:10:02 +01:00
Simon Wisselink 32df4c6467 Fix CustomResourceAmbiguousTest 2023-01-03 15:02:58 +01:00
Simon Wisselink 98ad1a13af Fixed TemplateObject test 2023-01-03 14:20:40 +01:00
Simon Wisselink 9766aba66e filter tests passing 2023-01-03 14:12:36 +01:00
Simon Wisselink b9ecf115dd fixed pre/post/output filters and removed some old todo-comments 2023-01-02 23:26:36 +01:00
Simon Wisselink 60a56969dd WIP moving Smarty to PSR-4. 2023-01-02 00:49:38 +01:00
Simon Wisselink 6b9e2fadd1 Rewrote remaining plugins to PSR-4, plugins dir is now gone. 2022-12-25 14:02:15 +01:00
Simon Wisselink ab5705a90d Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes 2022-12-24 23:38:13 +01:00
Simon Wisselink 57cff64869 Add makefile, PSR-4 ModifierCompilers 2022-12-23 14:03:05 +01:00
Simon Wisselink 4d66910e7f Entire src dir now PSR-4 compatible 2022-12-22 22:38:37 +01:00
Simon Wisselink f1e7b2d46f src/sysplugins/* to PSR-4 2022-12-22 21:50:01 +01:00
Simon Wisselink 0fc2b3726b src/Template/* to PSR-4 2022-12-22 21:23:22 +01:00
Simon Wisselink d88175de3e Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. 2022-12-22 15:43:20 +01:00
Simon Wisselink cfd8c08d09 smarty_internal_resource_* to PSR-4 2022-12-21 16:33:26 +01:00
Simon Wisselink b0db4705a0 Finished moving smarty_internal_method_* 2022-12-21 14:47:33 +01:00
Simon Wisselink 5cac5e42f1 WIP rewriting smarty_internal_method_* 2022-12-21 14:01:18 +01:00
Simon Wisselink 6ba059dea8 Rewrote all Compile and Compiler classes to PSR-4 2022-12-20 23:47:18 +01:00
Simon Wisselink 1524f11c8e finished rewriting all compile classes into PSR-4 2022-12-20 23:05:36 +01:00
Simon Wisselink 164a89a1fd WIP making compile classes PSR-4 2022-12-01 23:44:58 +01:00
Simon Wisselink d0319bdc87 Replace Smarty:: with symfony/polyfill-mbstring 2022-12-01 21:56:12 +01:00
Simon Wisselink 9a0d46f1bc WIP making compile classes PSR-4 2022-12-01 21:54:23 +01:00
Simon Wisselink 53fe73b9cc WIP making compile classes PSR-4 2022-12-01 21:53:05 +01:00
Simon Wisselink e54a53332f Removed autoload filters 2022-11-30 10:06:09 +01:00
Simon Wisselink 8b5540f4f3 More PSR4 rewriting 2022-11-30 00:25:27 +01:00
Simon Wisselink 91b6fdeb4e WIP converting code to PSR-4 2022-11-28 12:30:07 +01:00
Simon Wisselink a34ee98e21 Allow dereferencing of non-objects accross all supported PHP versions (#832)
Fixes #831
2022-11-24 18:44:19 +01:00
Simon Wisselink 4d1cf61bb8 Simplify test running to support all phpunit cmdline options 2022-11-24 18:24:17 +01:00
Simon Wisselink c0a6b641bf Treat undefined vars and array access of a null or false variables equivalent across all supported PHP versions (#830)
* Added test to see what changed exactly

* Treat undefined vars and array access of a null or false variables
  equivalent across all supported PHP versions

* Removed 2 tests that produce inconsistent results between PHP7.x versions.

* Fix regex matching for slightly different error message for php7.1
2022-11-24 09:43:51 +01:00
Simon Wisselink 044647bd71 Also mute php7 notices for undefined array indexes when muteUndefinedOrNullWarnings is activated. (#829)
Fixes #736
2022-11-23 23:26:24 +01:00
Simon Wisselink c02e9e135e Merge branch 'release/4.3.0' 2022-11-22 22:47:32 +01:00
Simon Wisselink 67ab8f6879 version bump 2022-11-22 22:47:30 +01:00
Simon Wisselink 773b3b4b7c Change file permissions for directories and respect umask for written files. (#828)
Fixes #548
Fixes #819
2022-11-22 22:31:54 +01:00
Hunman 613c5d691c Make SmartyCompilerException play nicer with error handler libraries (#782)
* Make SmartyCompilerException play nicer with error handler libraries

Added a new constructor, which accepts a filename and a line number too
(similar to ErrorException, except no severity parameter)
This way error handlers will display the correct file's correct line as
the source of the exception, instead of the template's line in the
core of the parser (php file)

Kept the __toString() method, but removed $source, $desc, and $template

* Revert the breaking changes
2022-11-22 21:58:13 +01:00
Progi1984 c016895166 PHP8.2 compatibility (#775)
* PHP8.2 compatibility

* PHP8.2 compatibility : Fixed unit tests

* PHP8.2 compatibility : Replace ENT_COMPAT by ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401

* PHP8.2 compatibility : Remove deprecated utf8_decode

* PHP8.2 compatibility : Remove HTML-ENTITIES parameter

* Removed some unused code for clarity, updated the changelog.

* More concise escape implementation and unit test to cover both modifierplugin and modifiercompiler.

* Fix htmlall unescape of quotes without mbstring too

Co-authored-by: Simon Wisselink <s.wisselink@iwink.nl>
2022-11-22 21:22:57 +01:00
Andrew Dawes f81720941c Fixed several typos and grammar errors (#821) 2022-10-22 22:08:38 +02:00
Simon Wisselink 1ff79c6c38 Update changelog
Closes #816
2022-09-27 12:24:08 +02:00
Simon Wisselink 254b5cabee Dropped remaining references to removed PHP-support in Smarty 4 from docs, lexer and security class. 2022-09-27 12:21:01 +02:00
Raimondas Rimkevičius 1b556c7077 Use __DIR__ instead of dirname(__FILE__) (#817) 2022-09-27 12:03:34 +02:00
Simon Wisselink 4550fc0339 Using PHP functions as modifiers now triggers a deprecation notice (#814)
Fixes #813
2022-09-23 00:09:00 +02:00
Scott Newton 4fc39d59a5 Bug fix for underscore in template name (#581)
* Corrected bug #578, where underscore characters were being stripped from template names when using a custom resource
* Increased the maximum template name length to 127 characters when using a custom resource
2022-09-22 23:56:18 +02:00
Alec Smecher 0fb29024e7 #155 Adapt Smarty upper/lower functions to be codesafe (e.g. for Turkish locale) (#586)
* Implemented locale safe strotoupper, strolower and ucfirst functions for translating user string to filenames etc.

Fixes #155

Co-Authored-By: Alexkurd <7689609+Alexkurd@users.noreply.github.com>
2022-09-22 23:32:55 +02:00
Simon Wisselink 612bd3f657 Fixed PHP8.1 deprecation errors in strip_tags (#803) 2022-09-22 14:55:20 +02:00
Simon Wisselink 9eea30ec1e Removed now superfluous phpunit.sh 2022-09-22 14:44:45 +02:00
Simon Wisselink ea95e8b047 Re-organize all testrunners to use the same script(s). (#812) 2022-09-22 14:31:49 +02:00
Simon Wisselink 474138fd7e Updated changelog 2022-09-22 14:31:01 +02:00
Mathias b91c04bfcf Fixed PHP8.1 deprecation errors passing null to parameter in trim (#807)
Fixed a PHP 8.1 deprecation error:  trim(): Passing null to parameter #1 ($string) of type string is deprecated in cacheresource_keyvaluestore.php on line 247 and in cacheresource_keyvaluestore.php on line 431
2022-09-22 14:29:51 +02:00
Simon Wisselink c53342c9fc Silence deprecation errors for strtime in PHP8.1 or higher
Fixes #672 (#811)
2022-09-22 14:11:36 +02:00
Simon Wisselink f8a958cd53 Update changelog 2022-09-21 21:56:39 +02:00
Jonathan Stoll 45345e75ec Fix Variable Usage (#808)
Fix Variable Usage in Exception message when unable to load subtemplate
2022-09-21 21:54:41 +02:00
Simon Wisselink bf7d6b8bd8 Include docs en demo in the releases.
Fixes #799
2022-09-20 22:45:16 +02:00
Simon Wisselink 32a11b34ea Added changelog 2022-09-18 17:18:32 +02:00
Storyxx db80246b58 fix compilation for caching templates (#801) 2022-09-18 17:15:56 +02:00
Hypolite Petovan d683641f90 Fix wrong indentation in libs/plugins/modifier.capitalize.php (#802) 2022-09-18 11:14:59 +02:00
Simon Wisselink e2e68b3622 clean output buffer for Throwable instead of just Exception (#797)
Fixes #514
2022-09-14 13:47:36 +02:00
Simon Wisselink ffa2b81a8e Merge branch 'release/4.2.1' 2022-09-14 12:59:01 +02:00
Simon Wisselink c693d81370 version bump 2022-09-14 12:58:59 +02:00
Simon Wisselink 813c83f7a3 Fixed unselected year/month/day not working in html_select_date
Fixes #395
2022-09-14 12:44:37 +02:00
Simon Wisselink 55ea25d1f5 Applied appropriate javascript and html escaping in mailto plugin to counter injection attacks
Fixes #454
2022-09-14 11:38:18 +02:00
Simon Wisselink d304d349b4 Fixed PHP8.1 deprecation errors in capitalize modifier
Fixes #789
2022-09-13 12:19:44 +02:00
Simon Wisselink 7494818434 prevent double CI workflows in PRs 2022-09-12 16:02:42 +02:00
Simon Wisselink 50d5890eac Exclude unit test files from git export 2022-09-12 15:52:32 +02:00
Simon Wisselink 6872e78238 Utility script for running unit tests on all PHP versions locally 2022-09-12 15:50:09 +02:00
Simon Wisselink 5479e3362c Fixed use of rand() without a parameter in math function (#795)
* Fixed use of `rand()` without a parameter in math function
Fixes #794
2022-09-12 12:13:42 +02:00
Simon Wisselink f8f97b4e2d Fixed PHP8.1 deprecation errors in upper modifier #788 2022-09-10 12:34:20 +02:00
Mark Fettig 1bc7c722a3 address PHP 8.1 'explode', 'number_format', and 'replace' deprecations (#755) 2022-09-09 22:39:24 +02:00
Simon Wisselink 02968a82b5 Update SECURITY.md
Removed comment that still indicated v4 wasn’t released yet.
2022-08-16 22:43:47 +02:00
Simon Wisselink 97aeb14c6f Merge branch 'release/4.2.0' 2022-08-01 23:57:38 +02:00
Simon Wisselink ed454551a3 version bump 2022-08-01 23:57:36 +02:00
Simon Wisselink f4b26a3cbf Fixed second param of unescape modifier (#778)
Fixes #777
2022-08-01 23:49:19 +02:00
Simon Wisselink 20a8026ccd Merge branch 'fix-issue-549-v3' of github.com:AnrDaemon/smarty into AnrDaemon-fix-issue-549-v3 (#771) 2022-07-19 22:55:07 +02:00
Simon Wisselink 27910bf2c1 git push origin masterMerge branch 'JonisoftGermany-master' 2022-07-17 00:54:29 +02:00
733 changed files with 25312 additions and 33020 deletions
+1 -2
View File
@@ -7,11 +7,10 @@
# exclude from git export
/tests export-ignore
/demo export-ignore
/docs export-ignore
/utilities export-ignore
/docker-compose.yml export-ignore
/.github export-ignore
/run_tests_for_all_php_versions.sh export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/make-release.sh export-ignore
+17 -13
View File
@@ -1,8 +1,10 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
on:
- pull_request
- push
pull_request:
push:
branches:
- 'master'
name: CI
@@ -23,12 +25,12 @@ jobs:
- ubuntu-latest
php-version:
- "7.1"
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
compiler:
- default
@@ -40,10 +42,13 @@ jobs:
- os: ubuntu-latest
php-version: "8.1"
compiler: jit
- os: ubuntu-latest
php-version: "8.2"
compiler: jit
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Override PHP ini values for JIT compiler
if: matrix.compiler == 'jit'
@@ -57,21 +62,20 @@ jobs:
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: ${{ env.PHP_INI_VALUES }}
- name: Validate composer.json and composer.lock
run: composer validate
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
key: v5r2-${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php-version }}-
v5r1-${{ runner.os }}-php-${{ matrix.php-version }}-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest
uses: php-actions/composer@v6
- name: Run make
run: make -B
- name: Run tests with phpunit
run: ./phpunit.sh
run: php ./vendor/phpunit/phpunit/phpunit
+2 -8
View File
@@ -1,13 +1,7 @@
.idea/
# Smarty
lexer/*.php
lexer/*.php.bak
lexer/*.out
# Dev
phpunit*
.phpunit.result.cache
vendor/*
composer.lock
/vendor/*
/composer.lock
+95 -2
View File
@@ -6,6 +6,99 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Added support for PHP8.2
### Changed
- All Smarty code is now in the \Smarty namespace. For simple use-cases, you only need to add
`use \Smarty\Smarty;` to your script and everything will work. If you extend Smarty or use
Smarty plug-ins, please review your code to see if they assume specific class or method names.
E.g.: `Smarty_Internal_Template` is now `\Smarty\Template\`, `SmartyException` is now `\Smarty\Exception`.
- Template variable scope bubbling has been simplified and made more consistent.
The global scope now equals the Smarty scope in order to avoid global state side effects. Please read
the documentation for more details.
- Lexers and Parsers PHP files are no longer under version control, but generated from sources (.y and .plex)
- Smarty now always runs in multibyte mode, using `symfony/polyfill-mbstring` if required. Please use the
multibyte extension for optimal performance.
### Deprecated
- `$smarty->getPluginsDir()`
- `$smarty->loadFilter()`
- `$smarty->setPluginsDir()`
- `$smarty->assignGlobal()`
- Using `$smarty->registerFilter()` for registering variable filters will trigger a notice.
-
### Removed
- Dropped support for PHP7.1
- Removed `$smarty->left_delimiter` and `$smarty->right_delimiter`, use `$smarty->getLeftDelimiter()`/`$smarty->setLeftDelimiter()` and `$smarty->getRightDelimiter()`/`$smarty->setRightDelimiter()`
- Removed support for the `$cache_attrs` parameter for registered plugins
- Removed support for undocumented `{make_nocache}` tag
- Removed support for deprecated `{insert}` tag, the 'insert' plugin type and the associated $smarty->trusted_dir variable
- Removed the undocumented `{block_parent}` and `{parent}` alternatives to `{$smarty.block.parent}`
- Removed the undocumented `{block_child}` and `{child}` alternatives to `{$smarty.block.child}`
- Removed support for loading config files into a non-local scope using `{config_load}` from a template
- Removed `$smarty->autoload_filters` in favor of `$smarty->registerFilter()`
- Removed `$smarty->trusted_dir` and `$smarty->allow_php_templates` since support for executing php scripts from templates has been dropped
- Removed `$smarty->php_functions` and `$smarty->php_modifiers`. If you need a PHP-function in your templates,
register it as a modifier.
- Removed support for `$smarty->getTags()`
- Removed the abandoned `$smarty->direct_access_security` setting
- Dropped support for `$smarty->plugins_dir` and `$smarty->use_include_path`. If you must, use `$smarty->addPluginsDir()` instead,
but it's better to use Smarty::addExtension() to add an extension or Smarty::registerPlugin to
quickly register a plugin using a callback function.
- Removed constants such as SMARTY_DIR to prevent global side effects.
- Removed direct access to `$smarty->template_dir`. Use `$smarty->setTemplateDir()`.
- Removed direct access to `$smarty->cache_dir`. Use `$smarty->setCacheDir()`.
- Removed `$smarty->loadPlugin()`, use `$smarty->registerPlugin()` instead.
- Removed `$smarty->appendByRef()` and `$smarty->assignByRef()`.
- Removed `$smarty->use_sub_dirs`. Cached files are now automatically stored in subdirs for maximum performance.
### Fixed
- `$smarty->muteUndefinedOrNullWarnings()` now also mutes PHP7 notices for undefined array indexes [#736](https://github.com/smarty-php/smarty/issues/736)
- `$smarty->muteUndefinedOrNullWarnings()` now treats undefined vars and array access of a null or false variables
equivalent across all supported PHP versions
- `$smarty->muteUndefinedOrNullWarnings()` now allows dereferencing of non-objects across all supported PHP versions [#831](https://github.com/smarty-php/smarty/issues/831)
- PHP 8.1 deprecation warnings on null strings in modifiers [#834](https://github.com/smarty-php/smarty/pull/834)
## [4.3.0] - 2022-11-22
### Added
- PHP8.2 compatibility [#775](https://github.com/smarty-php/smarty/pull/775)
### Changed
- Include docs and demo in the releases [#799](https://github.com/smarty-php/smarty/issues/799)
- Using PHP functions as modifiers now triggers a deprecation notice because we will drop support for this in the next major release [#813](https://github.com/smarty-php/smarty/issues/813)
- Dropped remaining references to removed PHP-support in Smarty 4 from docs, lexer and security class. [#816](https://github.com/smarty-php/smarty/issues/816)
- Support umask when writing (template) files and set dir permissions to 777 [#548](https://github.com/smarty-php/smarty/issues/548) [#819](https://github.com/smarty-php/smarty/issues/819)
### Fixed
- Output buffer is now cleaned for internal PHP errors as well, not just for Exceptions [#514](https://github.com/smarty-php/smarty/issues/514)
- Fixed recursion and out of memory errors when caching in complicated template set-ups using inheritance and includes [#801](https://github.com/smarty-php/smarty/pull/801)
- Fixed PHP8.1 deprecation errors in strip_tags
- Fix Variable Usage in Exception message when unable to load subtemplate [#808](https://github.com/smarty-php/smarty/pull/808)
- Fixed PHP8.1 deprecation notices for strftime [#672](https://github.com/smarty-php/smarty/issues/672)
- Fixed PHP8.1 deprecation errors passing null to parameter in trim [#807](https://github.com/smarty-php/smarty/pull/807)
- Adapt Smarty upper/lower functions to be codesafe (e.g. for Turkish locale) [#586](https://github.com/smarty-php/smarty/pull/586)
- Bug fix for underscore and limited length in template name in custom resources [#581](https://github.com/smarty-php/smarty/pull/581)
## [4.2.1] - 2022-09-14
### Security
- Applied appropriate javascript and html escaping in mailto plugin to counter injection attacks [#454](https://github.com/smarty-php/smarty/issues/454)
### Fixed
- Fixed PHP8.1 deprecation notices in modifiers (upper, explode, number_format and replace) [#755](https://github.com/smarty-php/smarty/pull/755) and [#788](https://github.com/smarty-php/smarty/pull/788)
- Fixed PHP8.1 deprecation notices in capitalize modifier [#789](https://github.com/smarty-php/smarty/issues/789)
- Fixed use of `rand()` without a parameter in math function [#794](https://github.com/smarty-php/smarty/issues/794)
- Fixed unselected year/month/day not working in html_select_date [#395](https://github.com/smarty-php/smarty/issues/395)
## [4.2.0] - 2022-08-01
### Fixed
- Fixed problems with smarty_mb_str_replace [#549](https://github.com/smarty-php/smarty/issues/549)
- Fixed second parameter of unescape modifier not working [#777](https://github.com/smarty-php/smarty/issues/777)
### Changed
- Updated HTML of the debug template [#599](https://github.com/smarty-php/smarty/pull/599)
@@ -1732,7 +1825,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
27.09.2011
- bugfix possible warning "attempt to modify property of non-object" in {section} (issue #34)
- added chaining to Smarty_Internal_Data so $smarty->assign('a',1)->assign('b',2); is possible now
- added chaining to \Smarty\Data so $smarty->assign('a',1)->assign('b',2); is possible now
- bugfix remove race condition when a custom resource did change timestamp during compilation
- bugfix variable property did not work on objects variable in template
- bugfix smarty_make_timestamp() failed to process DateTime objects properly
@@ -2067,7 +2160,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- optimize smarty_modified_escape for hex, hexentity, decentity.
28/12/2010
- changed $tpl_vars, $config_vars and $parent to belong to Smarty_Internal_Data
- changed $tpl_vars, $config_vars and $parent to belong to \Smarty\Data
- added Smarty::registerCacheResource() for dynamic cache resource object registration
27/12/2010
+19
View File
@@ -0,0 +1,19 @@
all: lexers parsers
lexers: src/Lexer/ConfigfileLexer.php src/Lexer/TemplateLexer.php
parsers: src/Parser/ConfigfileParser.php src/Parser/TemplateParser.php
src/Lexer/ConfigfileLexer.php: src/Lexer/ConfigfileLexer.plex
php ./utilities/make-lexer.php src/Lexer/ConfigfileLexer.plex src/Lexer/ConfigfileLexer.php
src/Lexer/TemplateLexer.php: src/Lexer/TemplateLexer.plex
php ./utilities/make-lexer.php src/Lexer/TemplateLexer.plex src/Lexer/TemplateLexer.php
src/Parser/ConfigfileParser.php: src/Parser/ConfigfileParser.y
php ./utilities/make-parser.php src/Parser/ConfigfileParser.y src/Parser/ConfigfileParser.php
src/Parser/TemplateParser.php: src/Parser/TemplateParser.y
php ./utilities/make-parser.php src/Parser/TemplateParser.y src/Parser/TemplateParser.php
clean:
rm -f src/Lexer/ConfigfileLexer.php src/Lexer/TemplateLexer.php src/Parser/ConfigfileParser.php src/Parser/TemplateParser.php
+1 -1
View File
@@ -7,7 +7,7 @@ Smarty is a template engine for PHP, facilitating the separation of presentation
Read the [documentation](https://smarty-php.github.io/smarty/) to find out how to use it.
## Requirements
Smarty can be run with PHP 7.1 to PHP 8.1.
Smarty v5 can be run with PHP 7.2 to PHP 8.2.
## Installation
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).
+1 -1
View File
@@ -2,7 +2,7 @@
## Supported Versions
Smarty currently supports the latest minor version of Smarty 3 and Smarty 4. (Smarty 4 has not been released yet.)
Smarty currently supports the latest minor version of Smarty 3 and Smarty 4.
| Version | Supported |
| ------- | ------------------ |
+48
View File
@@ -0,0 +1,48 @@
# @TODO
## Review direct variable property access
- review ->value{$index} in ForTag
- review ->(step|total|first|last|do_else|key|show|iteration|index)
- review ->tpl_vars, ->config_vars, ->value
- Re-introduce merge_compiled_includes and the {include inline} attribute?
## Beatify output
- strip <?php and ?> tags from generated output
## Review public static vars
- such as _CHARSET and _IS_WINDOWS
## Build
- add compiled lexers and parsers to Release assets automatically
## Benchmark
- benchmark to see that performance hasn't degraded
## Block / inheritance
- Consider phasing out $smarty.block.child as this reverses the inheritance hierarchy and might cause infinite loops
when combined with $smarty.block.parent
## Plugin system
- fix template security checks in one place in compiler
## Documentation
- beautify and review docs, possibly using [
Material for MkDocs ](https://squidfunk.github.io/mkdocs-material/publishing-your-site/)
## Resources
- Fix circular deps between resources and sources
```
$smarty = $this->_getSmartyObj();
[$name, $type] = \Smarty\Resource\BasePlugin::parseResourceName($config_file, $smarty->default_config_type);
$source = new Config($smarty, $config_file, $type, $name);
$source->handler->getContent($source);
```
## Unrelated / other
- review (and avoid) use of 'clone' keyword
- compiler->has_code seems silly. Why not have proper return values?
- what is 'user literal support', why are unit tests skipped?
+10 -5
View File
@@ -30,20 +30,25 @@
"forum": "https://github.com/smarty-php/smarty/discussions"
},
"require": {
"php": "^7.1 || ^8.0"
"php": "^7.2 || ^8.0",
"symfony/polyfill-mbstring": "^1.27",
"nette/php-generator": "^3.6"
},
"autoload": {
"classmap": [
"libs/"
"psr-4" : {
"Smarty\\" : "src/"
},
"files": [
"src/functions.php"
]
},
"extra": {
"branch-alias": {
"dev-master": "4.0.x-dev"
"dev-master": "5.0.x-dev"
}
},
"require-dev": {
"phpunit/phpunit": "^8.5 || ^7.5",
"smarty/smarty-lexer": "^3.1"
"smarty/smarty-lexer": "dev-master"
}
}
+4 -4
View File
@@ -2,11 +2,11 @@
/**
* Example Application
*
* @package Example-application
*/
require '../libs/Smarty.class.php';
$smarty = new Smarty;
//$smarty->force_compile = true;
$smarty = new \Smarty\Smarty;
$smarty->debugging = true;
$smarty->caching = true;
$smarty->cache_lifetime = 120;
-101
View File
@@ -1,101 +0,0 @@
<?php
/**
* MySQL Resource
* Resource Implementation based on the Custom API to use
* MySQL as the storage resource for Smarty's templates and configs.
* Table definition:
* <pre>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;</pre>
* Demo data:
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello
* world"}{$x}');</pre>
*
*
* @package Resource-examples
* @author Rodney Rehm
*/
class Smarty_Resource_Mysql extends Smarty_Resource_Custom
{
/**
* PDO instance
*
* @var \PDO
*/
protected $db;
/**
* prepared fetch() statement
*
* @var \PDOStatement
*/
protected $fetch;
/**
* prepared fetchTimestamp() statement
*
* @var \PDOStatement
*/
protected $mtime;
/**
* Smarty_Resource_Mysql constructor.
*
* @throws \SmartyException
*/
public function __construct()
{
try {
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "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);
}
}
-77
View File
@@ -1,77 +0,0 @@
<?php
/**
* MySQL Resource
* Resource Implementation based on the Custom API to use
* MySQL as the storage resource for Smarty's templates and configs.
* Note that this MySQL implementation fetches the source and timestamps in
* a single database query, instead of two separate like resource.mysql.php does.
* Table definition:
* <pre>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;</pre>
* Demo data:
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello
* world"}{$x}');</pre>
*
*
* @package Resource-examples
* @author Rodney Rehm
*/
class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
{
/**
* PDO instance
*
* @var \PDO
*/
protected $db;
/**
* prepared fetch() statement
*
* @var \PDOStatement
*/
protected $fetch;
/**
* Smarty_Resource_Mysqls constructor.
*
* @throws \SmartyException
*/
public function __construct()
{
try {
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "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;
}
}
}
-2
View File
@@ -11,8 +11,6 @@
The current date and time is {$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}
The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME}
Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME}
The value of {ldelim}$Name{rdelim} is <b>{$Name}</b>
+6 -6
View File
@@ -3,15 +3,10 @@ services:
base:
build:
context: .
dockerfile: ./utilities/testrunners/php72/Dockerfile
volumes:
- .:/app
working_dir: /app
entrypoint: sh ./utilities/testrunners/run-test.sh
php71:
extends:
service: base
build:
dockerfile: ./utilities/testrunners/php71/Dockerfile
php72:
extends:
service: base
@@ -37,3 +32,8 @@ services:
service: base
build:
dockerfile: ./utilities/testrunners/php81/Dockerfile
php82:
extends:
service: base
build:
dockerfile: ./utilities/testrunners/php82/Dockerfile
+2 -65
View File
@@ -188,67 +188,6 @@ See also [`{html_select_date}`](#language.function.html.select.date),
[`date_format`](#language.modifier.date.format) and
[`$smarty.now`](#language.variables.smarty.now),
WAP/WML {#tips.wap}
=======
WAP/WML templates require a php [Content-Type
header](&url.php-manual;header) to be passed along with the template.
The easist way to do this would be to write a custom function that
prints the header. If you are using [caching](#caching), that won\'t
work so we\'ll do it using the [`{insert}`](#language.function.insert)
tag; remember `{insert}` tags are not cached! Be sure that there is
nothing output to the browser before the template, or else the header
may fail.
<?php
// be sure apache is configure for the .wml extensions!
// put this function somewhere in your application, or in Smarty.addons.php
function insert_header($params)
{
// this function expects $content argument
if (empty($params['content'])) {
return;
}
header($params['content']);
return;
}
?>
your Smarty template *must* begin with the insert tag :
{insert name=header content="Content-Type: text/vnd.wap.wml"}
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<!-- begin new wml deck -->
<wml>
<!-- begin first card -->
<card>
<do type="accept">
<go href="#two"/>
</do>
<p>
Welcome to WAP with Smarty!
Press OK to continue...
</p>
</card>
<!-- begin second card -->
<card id="two">
<p>
Pretty easy isn't it?
</p>
</card>
</wml>
Componentized Templates {#tips.componentized.templates}
=======================
@@ -259,7 +198,7 @@ Smarty object, [`assign()`](#api.assign) the variables and
[`display()`](#api.display) the template. So lets say for example we
have a stock ticker on our template. We would collect the stock data in
our application, then assign these variables in the template and display
it. Now wouldn\'t it be nice if you could add this stock ticker to any
it. Now wouldn't it be nice if you could add this stock ticker to any
application by merely including the template, and not worry about
fetching the data up front?
@@ -301,9 +240,7 @@ assigning it to a template variable.
See also [`{include_php}`](#language.function.include.php),
[`{include}`](#language.function.include) and
[`{php}`](#language.function.php).
See also: [`{include}`](#language.function.include).
Obfuscating E-mail Addresses {#tips.obfuscating.email}
============================
+1 -1
View File
@@ -109,7 +109,7 @@ the corresponding error is in the template.
- This means that your application registered a custom error hander
- This means that your application registered a custom error handler
(using [set\_error\_handler()](&url.php-manual;set_error_handler))
which is not respecting the given `$errno` as it should. If, for
whatever reason, this is the desired behaviour of your custom error
+1 -2
View File
@@ -11,8 +11,7 @@ of the console.
Set [`$debugging`](../programmers/api-variables/variable-debugging.md) to TRUE in Smarty, and if needed
set [`$debug_tpl`](../programmers/api-variables/variable-debug-template.md) to the template resource
path to `debug.tpl` (this is in [`SMARTY_DIR`](../programmers/smarty-constants.md) by
default). When you load the page, a Javascript console window will pop
path to `debug.tpl`. When you load the page, a Javascript console window will pop
up and give you the names of all the included templates and assigned
variables for the current page.
@@ -3,7 +3,7 @@ Attributes {#language.syntax.attributes}
Most of the [functions](#language.syntax.functions) take attributes that
specify or modify their behavior. Attributes to Smarty functions are
much like HTML attributes. Static values don\'t have to be enclosed in
much like HTML attributes. Static values don't have to be enclosed in
quotes, but it is required for literal strings. Variables with or
without modifiers may also be used, and should not be in quotes. You can
even use PHP function results, plugin results and complex expressions.
@@ -10,7 +10,6 @@ within delimiters like so: `{funcname attr1="val1" attr2="val2"}`.
{config_load file="colors.conf"}
{include file="header.tpl"}
{insert file="banner_ads.tpl" title="My Site"}
{if $logged_in}
Welcome, <span style="color:{#fontColor#}">{$name}!</span>
@@ -16,8 +16,6 @@ Built-in Functions {#language.builtin.functions}
- [{function}](./language-builtin-functions/language-function-function.md)
- [{if},{elseif},{else}](./language-builtin-functions/language-function-if.md)
- [{include}](./language-builtin-functions/language-function-include.md)
- [{include_php}](./language-builtin-functions/language-function-include.php)
- [{insert}](./language-builtin-functions/language-function-insert.md)
- [{ldelim},{rdelim}](./language-builtin-functions/language-function-ldelim.md)
- [{literal}](./language-builtin-functions/language-function-literal.md)
- [{nocache}](./language-builtin-functions/language-function-nocache.md)
@@ -17,7 +17,7 @@
var string Yes *n/a* The name of the variable being assigned
value string Yes *n/a* The value being assigned
index string No *n/a* The index for the new array element. If not specified the value is append to the end of the array.
scope string No *n/a* The scope of the assigned variable: \'parent\',\'root\' or \'global\'
scope string No *n/a* The scope of the assigned variable: \'parent\',\'root\' or \'smarty\'
**Option Flags:**
@@ -21,7 +21,7 @@ execution of a template**.
---------------- -------- ---------- --------- -----------------------------------------------------------------------
var string Yes *n/a* The name of the variable being assigned
value string Yes *n/a* The value being assigned
scope string No *n/a* The scope of the assigned variable: \'parent\',\'root\' or \'global\'
scope string No *n/a* The scope of the assigned variable: \'parent\',\'root\' or \'smarty\'
**Option Flags:**
@@ -135,8 +135,6 @@ The following functions can also *optionally* assign template variables.
[`{capture}`](#language.function.capture),
[`{include}`](#language.function.include),
[`{include_php}`](#language.function.include.php),
[`{insert}`](#language.function.insert),
[`{counter}`](#language.function.counter),
[`{cycle}`](#language.function.cycle),
[`{eval}`](#language.function.eval),
@@ -3,14 +3,14 @@
`{block}` is used to define a named area of template source for template
inheritance. For details see section of [Template
Interitance](#advanced.features.template.inheritance).
Inheritance](#advanced.features.template.inheritance).
The `{block}` template source area of a child template will replace the
correponding areas in the parent template(s).
corresponding areas in the parent template(s).
Optionally `{block}` areas of child and parent templates can be merged
into each other. You can append or prepend the parent `{block}` content
by using the `append` or `prepend` option flag with the childs `{block}`
by using the `append` or `prepend` option flag with the child's `{block}`
definition. With the {\$smarty.block.parent} the `{block}` content of
the parent template can be inserted at any location of the child
`{block}` content. {\$smarty.block.child} inserts the `{block}` content
@@ -28,13 +28,6 @@ is the value passed in the `name` attribute. If you do not supply the
--------- -----------------------------------------
nocache Disables caching of this captured block
> **Note**
>
> Be careful when capturing [`{insert}`](#language.function.insert)
> output. If you have [`$caching`](#caching) enabled and you have
> [`{insert}`](#language.function.insert) commands that you expect to
> run within cached content, do not capture this content.
{* we don't want to print a div tag unless content is displayed *}
{capture name="banner"}
@@ -3,7 +3,7 @@
`{extends}` tags are used in child templates in template inheritance for
extending parent templates. For details see section of [Template
Interitance](#advanced.features.template.inheritance).
Inheritance](#advanced.features.template.inheritance).
- The `{extends}` tag must be on the first line of the template.
@@ -33,5 +33,5 @@ Interitance](#advanced.features.template.inheritance).
See also [Template Interitance](#advanced.features.template.inheritance)
See also [Template Inheritance](#advanced.features.template.inheritance)
and [`{block}`](#language.function.block).
@@ -2,7 +2,7 @@
=====
The `{for}{forelse}` tag is used to create simple loops. The following
different formarts are supported:
different formats are supported:
- `{for $var=$start to $end}` simple loop with step size of 1.
@@ -8,10 +8,6 @@ template engine. Every `{if}` must be paired with a matching `{/if}`.
functions are recognized, such as *\|\|*, *or*, *&&*, *and*,
*is\_array()*, etc.
If securty is enabled, only PHP functions from `$php_functions` property
of the securty policy are allowed. See the
[Security](#advanced.features.security) section for details.
The following is a list of recognized qualifiers, which must be
separated from surrounding elements by spaces. Note that items listed in
\[brackets\] are optional. PHP equivalents are shown where applicable.
@@ -1,74 +0,0 @@
{include\_php} {#language.function.include.php}
==============
> **Note**
>
> `{include_php}` is deprecated from Smarty, use registered plugins to
> properly insulate presentation from the application code. As of Smarty
> 3.1 the `{include_php}` tags are only available from [SmartyBC](#bc).
Attribute Name Type Required Default Description
---------------- --------- ---------- --------- ----------------------------------------------------------------------------------
file string Yes *n/a* The name of the php file to include as absolute path
once boolean No *TRUE* whether or not to include the php file more than once if included multiple times
assign string No *n/a* The name of the variable that the output of include\_php will be assigned to
**Option Flags:**
Name Description
--------- ----------------------------------------
nocache Disables caching of inluded PHP script
`{include_php}` tags are used to include a php script in your template.
The path of the attribute `file` can be either absolute, or relative to
[`$trusted_dir`](#variable.trusted.dir). If security is enabled, then
the script must be located in the `$trusted_dir` path of the securty
policy. See the [Security](#advanced.features.security) section for
details.
By default, php files are only included once even if called multiple
times in the template. You can specify that it should be included every
time with the `once` attribute. Setting once to FALSE will include the
php script each time it is included in the template.
You can optionally pass the `assign` attribute, which will specify a
template variable name that the output of `{include_php}` will be
assigned to instead of displayed.
The smarty object is available as `$_smarty_tpl->smarty` within the PHP
script that you include.
The `load_nav.php` file:
<?php
// load in variables from a mysql db and assign them to the template
require_once('database.class.php');
$db = new Db();
$db->query('select url, name from navigation order by name');
$this->assign('navigation', $db->getRows());
?>
where the template is:
{* absolute path, or relative to $trusted_dir *}
{include_php file='/path/to/load_nav.php'}
{include_php '/path/to/load_nav.php'} {* short-hand *}
{foreach item='nav' from=$navigation}
<a href="{$nav.url}">{$nav.name}</a><br />
{/foreach}
See also [`{include}`](#language.function.include),
[`$trusted_dir`](#variable.trusted.dir),
[`{php}`](#language.function.php),
[`{capture}`](#language.function.capture), [template
resources](#resources) and [componentized
templates](#tips.componentized.templates)
@@ -131,7 +131,7 @@ cache lifetime of 500 seconds.
In this example included template will be cached independent of the
global cahing setting.
global caching setting.
{include 'sub_template.tpl' caching}
@@ -188,7 +188,5 @@ current template.
See also [`{include_php}`](#language.function.include.php),
[`{insert}`](#language.function.insert),
[`{php}`](#language.function.php), [template resources](#resources) and
See also [template resources](#resources) and
[componentized templates](#tips.componentized.templates).
@@ -1,86 +0,0 @@
{insert} {#language.function.insert}
========
> **Note**
>
> `{insert}` tags are deprecated from Smarty, and should not be used.
> Put your PHP logic in PHP scripts or plugin functions instead.
> **Note**
>
> As of Smarty 3.1 the `{insert}` tags are only available from
> [SmartyBC](#bc).
`{insert}` tags work much like [`{include}`](#language.function.include)
tags, except that `{insert}` tags are NOT cached when template
[caching](#caching) is enabled. They will be executed on every
invocation of the template.
Attribute Name Type Required Default Description
---------------- -------------- ---------- --------- ----------------------------------------------------------------------------------
name string Yes *n/a* The name of the insert function (insert\_`name`) or insert plugin
assign string No *n/a* The name of the template variable the output will be assigned to
script string No *n/a* The name of the php script that is included before the insert function is called
\[var \...\] \[var type\] No *n/a* variable to pass to insert function
Let\'s say you have a template with a banner slot at the top of the
page. The banner can contain any mixture of HTML, images, flash, etc. so
we can\'t just use a static link here, and we don\'t want this contents
cached with the page. In comes the {insert} tag: the template knows
\#banner\_location\_id\# and \#site\_id\# values (gathered from a
[config file](#config.files)), and needs to call a function to get the
banner contents.
{* example of fetching a banner *}
{insert name="getBanner" lid=#banner_location_id# sid=#site_id#}
{insert "getBanner" lid=#banner_location_id# sid=#site_id#} {* short-hand *}
In this example, we are using the name "getBanner" and passing the
parameters \#banner\_location\_id\# and \#site\_id\#. Smarty will look
for a function named insert\_getBanner() in your PHP application,
passing the values of \#banner\_location\_id\# and \#site\_id\# as the
first argument in an associative array. All {insert} function names in
your application must be prepended with \"insert\_\" to remedy possible
function name-space conflicts. Your insert\_getBanner() function should
do something with the passed values and return the results. These
results are then displayed in the template in place of the {insert} tag.
In this example, Smarty would call this function:
insert\_getBanner(array(\"lid\" =\> \"12345\",\"sid\" =\> \"67890\"));
and display the returned results in place of the {insert} tag.
- If you supply the `assign` attribute, the output of the `{insert}`
tag will be assigned to this template variable instead of being
output to the template.
> **Note**
>
> Assigning the output to a template variable isn\'t too useful with
> [caching](#variable.caching) enabled.
- If you supply the `script` attribute, this php script will be
included (only once) before the `{insert}` function is executed.
This is the case where the insert function may not exist yet, and a
php script must be included first to make it work.
The path can be either absolute, or relative to
[`$trusted_dir`](#variable.trusted.dir). If security is enabled,
then the script must be located in the `$trusted_dir` path of the
securty policy. See the [Security](#advanced.features.security)
section for details.
The Smarty object is passed as the second argument. This way you can
reference and modify information in the Smarty object from within the
`{insert}` function.
If no PHP script can be found Smarty is looking for a corresponding
insert plugin.
> **Note**
>
> It is possible to have portions of the template not cached. If you
> have [caching](#caching) turned on, `{insert}` tags will not be
> cached. They will run dynamically every time the page is created, even
> within cached pages. This works good for things like banners, polls,
> live weather, search results, user feedback areas, etc.
See also [`{include}`](#language.function.include)
@@ -251,8 +251,8 @@ The above example will output:
{section}\'s can be nested as deep as you like. With nested
{section}\'s, you can access complex data structures, such as
multi-dimensional arrays. This is an example `.php` script thats
assign\'s the arrays.
multi-dimensional arrays. This is an example `.php` script that
assigns the arrays.
<?php
@@ -10,7 +10,7 @@ The filter can be:
- A variable filter plugin specified by it\'s name.
- A modidier specified by it\'s name and optional additional
- A modifier specified by it\'s name and optional additional
parameter.
`{setfilter}...{/setfilter}` blocks can be nested. The filter definition
@@ -22,7 +22,7 @@ ftp and display the contents.
>
> If security is enabled and you are fetching a file from the local
> file system, `{fetch}` will only allow files from within the
> `$secure_dir` path of the securty policy. See the
> `$secure_dir` path of the security policy. See the
> [Security](#advanced.features.security) section for details.
- If the `assign` attribute is set, the output of the `{fetch}`
@@ -19,7 +19,7 @@ automatically calculated from the image file if they are not supplied.
from. If not given, the web server\'s document root
`$_ENV['DOCUMENT_ROOT']` is used as the base. If security is
enabled, then the image must be located in the `$secure_dir` path of
the securty policy. See the [Security](#advanced.features.security)
the security policy. See the [Security](#advanced.features.security)
section for details.
- `href` is the href value to link the image to. If link is supplied,
+1 -1
View File
@@ -115,7 +115,7 @@ These parameters follow the modifier name and are separated by a `:`
- Secondly - if security is enabled, all php-functions that are to
be used as modifiers have to be declared trusted in the
`$modifiers` property of the securty policy. See the
`$modifiers` property of the security policy. See the
[Security](../programmers/advanced-features/advanced-features-security.md) section for details.
See also [`registerPlugin()`](../programmers/api-functions/api-register-plugin.md), [combining
@@ -15,5 +15,5 @@ modifier](#language.modifier.to_charset).
> modifier should only be used in cases where the application cannot
> anticipate that a certain string is required in another encoding.
See also [Charset Enconding](#charset), [from\_charset
See also [Charset Encoding](#charset), [from\_charset
modifier](#language.modifier.from_charset).
@@ -15,5 +15,5 @@ modifier](#language.modifier.from_charset).
> modifier should only be used in cases where the application cannot
> anticipate that a certain string is required in another encoding.
See also [Charset Enconding](#charset), [from\_charset
See also [Charset Encoding](#charset), [from\_charset
modifier](#language.modifier.from_charset).
@@ -157,13 +157,13 @@ Returns the version of Smarty the template was compiled with.
----------------------
Returns block text from child template. See [Template
interitance](#advanced.features.template.inheritance).
inheritance](#advanced.features.template.inheritance).
{\$smarty.block.parent} {#language.variables.smarty.block.parent}
-----------------------
Returns block text from parent template. See [Template
interitance](#advanced.features.template.inheritance)
inheritance](#advanced.features.template.inheritance)
{\$smarty.ldelim}, {\$smarty.rdelim} {#language.variables.smarty.ldelim}
------------------------------------
+6 -4
View File
@@ -2,7 +2,7 @@ What is Smarty?
==============
## Requirements
Smarty can be run with PHP 7.1 to PHP 8.1.
Smarty can be run with PHP 7.1 to PHP 8.2.
## Installation
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).
@@ -143,7 +143,9 @@ the same vars, etc., we can do that in one place.
```php
<?php
class Smarty_GuestBook extends Smarty {
use Smarty\Smarty;
class My_GuestBook extends Smarty {
public function __construct()
{
@@ -161,9 +163,9 @@ class Smarty_GuestBook extends Smarty {
}
```
Now, we can use `Smarty_GuestBook` instead of `Smarty` in our scripts:
Now, we can use `My_GuestBook` instead of `Smarty` in our scripts:
```php
$smarty = new Smarty_GuestBook();
$smarty = new My_GuestBook();
$smarty->assign('name','Ned');
$smarty->display('index.tpl');
```
-1
View File
@@ -37,7 +37,6 @@ and 480 for $height, the result is:
## Smarty for php developers
- [Charset Encoding](./programmers/charset.md)
- [Constants](./programmers/smarty-constants.md)
- [Smarty Class Variables](./programmers/api-variables.md)
- [Smarty Class Methods](./programmers/api-functions.md)
- [Caching](./programmers/caching.md)
@@ -29,7 +29,7 @@ determined by your needs, but use the first method whenever possible to
keep template syntax to a minimum.
If security is enabled, no private methods or functions can be accessed
(beginningwith \'\_\'). If a method and property of the same name exist,
(beginning with \'\_\'). If a method and property of the same name exist,
the method will be used.
You can restrict the methods and properties that can be accessed by
@@ -10,15 +10,14 @@ output filters operate on the template output when it is executed.
Output filters can be either [registered](#api.register.filter) or
loaded from the [plugins directory](#variable.plugins.dir) by using the
[`loadFilter()`](#api.load.filter) method or by setting the
[`$autoload_filters`](#variable.autoload.filters) variable. Smarty will
[`loadFilter()`](#api.load.filter) method. Smarty will
pass the template output as the first argument, and expect the function
to return the result of the processing.
<?php
// put this in your application
function protect_email($tpl_output, Smarty_Internal_Template $template)
function protect_email($tpl_output, \Smarty\Template\ $template)
{
$tpl_output =
preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
@@ -38,6 +37,5 @@ to return the result of the processing.
See also [`registerFilter()`](#api.register.filter),
[`loadFilter()`](#api.load.filter),
[`$autoload_filters`](#variable.autoload.filters),
[postfilters](#advanced.features.postfilters) and
[`$plugins_dir`](#variable.plugins.dir).
@@ -5,15 +5,14 @@ Template postfilters are PHP functions that your templates are ran
through *after they are compiled*. Postfilters can be either
[registered](#api.register.filter) or loaded from the [plugins
directory](#variable.plugins.dir) by using the
[`loadFilter()`](#api.load.filter) function or by setting the
[`$autoload_filters`](#variable.autoload.filters) variable. Smarty will
[`loadFilter()`](#api.load.filter) function. Smarty will
pass the compiled template code as the first argument, and expect the
function to return the result of the processing.
<?php
// put this in your application
function add_header_comment($tpl_source, Smarty_Internal_Template $template)
function add_header_comment($tpl_source, \Smarty\Template\ $template)
{
return "<?php echo \"<!-- Created by Smarty! -->\n\"; ?>\n".$tpl_source;
}
@@ -8,8 +8,7 @@ putting in their templates, etc.
Prefilters can be either [registered](#api.register.filter) or loaded
from the [plugins directory](#variable.plugins.dir) by using
[`loadFilter()`](#api.load.filter) function or by setting the
[`$autoload_filters`](#variable.autoload.filters) variable.
[`loadFilter()`](#api.load.filter) function.
Smarty will pass the template source code as the first argument, and
expect the function to return the resulting template source code.
@@ -19,7 +18,7 @@ This will remove all the html comments in the template source.
<?php
// put this in your application
function remove_dw_comments($tpl_source, Smarty_Internal_Template $template)
function remove_dw_comments($tpl_source, \Smarty\Template\ $template)
{
return preg_replace("/<!--#.*-->/U",'',$tpl_source);
}
@@ -2,39 +2,17 @@ Security {#advanced.features.security}
========
Security is good for situations when you have untrusted parties editing
the templates eg via ftp, and you want to reduce the risk of system
the templates e.g. via ftp, and you want to reduce the risk of system
security compromises through the template language.
The settings of the security policy are defined by properties of an
instance of the Smarty\_Security class. These are the possible settings:
- `$php_handling` determines how Smarty to handle PHP code embedded in
templates. Possible values are:
- Smarty::PHP\_PASSTHRU -\> echo PHP tags as they are
- Smarty::PHP\_QUOTE -\> escape tags as entities
- Smarty::PHP\_REMOVE -\> remove php tags
- Smarty::PHP\_ALLOW -\> execute php tags
The default value is Smarty::PHP\_PASSTHRU.
If security is enabled the [`$php_handling`](#variable.php.handling)
setting of the Smarty object is not checked for security.
- `$secure_dir` is an array of template directories that are
considered secure. [`$template_dir`](#variable.template.dir)
concidered secure implicitly. The default is an empty array.
- `$trusted_dir` is an array of all directories that are considered
trusted. Trusted directories are where you keep php scripts that are
executed directly from the templates with
[`{include_php}`](#language.function.include.php). The default is an
empty array.
- `$trusted_uri` is an array of regular expressions matching URIs that
considered secure implicitly. The default is an empty array.
- `$trusted_uri` is an array of regular expressions matching URIs that
are considered trusted. This security directive used by
[`{fetch}`](#language.function.fetch) and
[`{html_image}`](#language.function.html.image). URIs passed to
@@ -43,7 +21,7 @@ instance of the Smarty\_Security class. These are the possible settings:
like authentication-tokens).
The expression `'#https?://.*smarty.net$#i'` would allow accessing
the follwing URIs:
the following URIs:
- `http://smarty.net/foo`
@@ -69,19 +47,6 @@ instance of the Smarty\_Security class. These are the possible settings:
static classes. To disable access to all static classes set
\$static\_classes = null.
- `$php_functions` is an array of PHP functions that are considered
trusted and can be used from within template. To disable access to
all PHP functions set \$php\_functions = null. An empty array (
\$php\_functions = array() ) will allow all PHP functions. The
default is array(\'isset\', \'empty\', \'count\', \'sizeof\',
\'in\_array\', \'is\_array\',\'time\',\'nl2br\').
- `$php_modifiers` is an array of PHP functions that are considered
trusted and can be used from within template as modifier. To disable
access to all PHP modifier set \$php\_modifier = null. An empty
array ( \$php\_modifier = array() ) will allow all PHP functions.
The default is array(\'escape\',\'count\').
- `$streams` is an array of streams that are considered trusted and
can be used from within template. To disable access to all streams
set \$streams = null. An empty array ( \$streams = array() ) will
@@ -110,12 +75,8 @@ instance of the Smarty\_Security class. These are the possible settings:
super globals can be accessed by the template. The default is
\"true\".
- `$allow_php_tag` is a boolean flag which controls if {php} and
{include\_php} tags can be used by the template. The default is
\"false\".
If security is enabled, no private methods, functions or properties of
static classes or assigned objects can be accessed (beginningwith
static classes or assigned objects can be accessed (beginning with
\'\_\') by the template.
To customize the security policy settings you can extend the
@@ -123,15 +84,9 @@ Smarty\_Security class or create an instance of it.
<?php
require 'Smarty.class.php';
class My_Security_Policy extends Smarty_Security {
// disable all PHP functions
public $php_functions = null;
// remove PHP tags
public $php_handling = Smarty::PHP_REMOVE;
// allow everthing as modifier
public $php_modifiers = array();
class My_Security_Policy extends \Smarty\Security {
public $allow_constants = false;
}
$smarty = new Smarty();
// enable security
@@ -140,15 +95,9 @@ Smarty\_Security class or create an instance of it.
<?php
require 'Smarty.class.php';
$smarty = new Smarty();
$my_security_policy = new Smarty_Security($smarty);
// disable all PHP functions
$my_security_policy->php_functions = null;
// remove PHP tags
$my_security_policy->php_handling = Smarty::PHP_REMOVE;
// allow everthing as modifier
$my_security_policy->php_modifiers = array();
$my_security_policy = new \Smarty\Security($smarty);
$my_security_policy->allow_constants = false;
// enable security
$smarty->enableSecurity($my_security_policy);
?>
@@ -164,5 +113,5 @@ Smarty\_Security class or create an instance of it.
> **Note**
>
> Most security policy settings are only checked when the template gets
> compiled. For that reasion you should delete all cached and compiled
> compiled. For that reason you should delete all cached and compiled
> template files when you change your security settings.
@@ -33,7 +33,7 @@ can override all or some of the parent named block areas.
you can define the whole template inheritance tree in the PHP script
when you are calling [`fetch()`](#api.fetch) or
[`display()`](#api.display) with the `extends:` template resource
type. The later provides even more flexibillity.
type. The later provides even more flexibility.
> **Note**
>
@@ -8,7 +8,7 @@ Modifications done to the Smarty object will be global for all
templates.
However the Smarty class variables and functions can be accessed or
called by induvidual template objects. Modification done to a template
called by individual template objects. Modification done to a template
object will apply only for that template and its included subtemplates.
-2
View File
@@ -31,7 +31,6 @@ Smarty Class Methods {#api.functions}
- [getConfigVars()](./api-functions/api-get-config-vars.md) — returns the given loaded config variable value
- [getPluginsDir()](./api-functions/api-get-plugins-dir.md) — return the directory where plugins are stored
- [getRegisteredObject()](./api-functions/api-get-registered-object.md) — returns a reference to a registered object
- [getTags()](./api-functions/api-get-tags.md) — return tags used by template
- [getTemplateDir()](./api-functions/api-get-template-dir.md) — return the directory where templates are stored
- [getTemplateVars()](./api-functions/api-get-template-vars.md) — returns assigned variable value(s)
- [isCached()](./api-functions/api-is-cached.md) — returns true if there is a valid cache for this template
@@ -55,7 +54,6 @@ Smarty Class Methods {#api.functions}
- [unregisterPlugin()](./api-functions/api-unregister-plugin.md) — dynamically unregister plugins
- [unregisterObject()](./api-functions/api-unregister-object.md) — dynamically unregister an object
- [unregisterResource()](./api-functions/api-unregister-resource.md) — dynamically unregister a resource plugin
- [testInstall()](./api-functions/api-test-install.md) — checks Smarty installation
> **Note**
>
@@ -26,7 +26,7 @@ the following parameters:
variables assigned to any of the objects in it\'s parent chain.
Data objects are used to create scopes for assigned variables. They can
be used to have controll which variables are seen by which templates.
be used to control which variables are seen by which templates.
<?php
@@ -9,7 +9,7 @@ string
disableSecurity
This disables securty checking on templates.
This disables security checking on templates.
See also [`enableSecurity()`](#api.enable.security), and
[Security](#advanced.features.security).
@@ -31,7 +31,9 @@ PARAMETER.COMPILEID
<?php
include(SMARTY_DIR.'Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->setCaching(true);
@@ -25,7 +25,7 @@ string
enableSecurity
This enables securty checking on templates. It uses the following
This enables security checking on templates. It uses the following
parameters:
- `securityclass` is an optional parameter. It\'s the name of the
@@ -1,40 +0,0 @@
getTags()
return tags used by template
Description
===========
string
getTags
object
template
This function returns an array of tagname/attribute pairs for all tags
used by the template. It uses the following parameters:
- `template` is the template object.
> **Note**
>
> This function is experimental.
<?php
include('Smarty.class.php');
$smarty = new Smarty;
// create template object
$tpl = $smarty->createTemplate('index.tpl');
// get tags
$tags = $smarty->getTags($tpl);
print_r($tags);
?>
@@ -22,8 +22,8 @@ string
compile\_id
- This only works if [`$caching`](#variable.caching) is set to one of
`Smarty::CACHING_LIFETIME_CURRENT` or
`Smarty::CACHING_LIFETIME_SAVED` to enable caching. See the [caching
`\Smarty\Smarty::CACHING_LIFETIME_CURRENT` or
`\Smarty\Smarty::CACHING_LIFETIME_SAVED` to enable caching. See the [caching
section](#caching) for more info.
- You can also pass a `$cache_id` as an optional second parameter in
@@ -18,7 +18,7 @@ string
name
The first argument specifies the type of the filter to load and can be
one of the following: `pre`, `post` or `output`. The second argument
one of the following: `variable`, `pre`, `post` or `output`. The second argument
specifies the `name` of the filter plugin.
@@ -37,6 +37,5 @@ specifies the `name` of the filter plugin.
See also [`registerFilter()`](#api.register.filter),
[`$autoload_filters`](#variable.autoload.filters) and [advanced
See also [`registerFilter()`](#api.register.filter) and [advanced
features](#advanced.features).
@@ -15,7 +15,7 @@ handler merely inspects `$errno` and `$errfile` to determine if the
given error was produced deliberately and must be ignored, or should be
passed on to the next error handler.
`Smarty::unmuteExpectedErrors()` removes the current error handler.
Please note, that if you\'ve registerd any custom error handlers after
`\Smarty\Smarty::unmuteExpectedErrors()` removes the current error handler.
Please note, that if you\'ve registered any custom error handlers after
the muteExpectedErrors() call, the unmute will not remove Smarty\'s
muting error handler, but the one registered last.
@@ -31,7 +31,7 @@ how to create custom CacheResources.
<?php
$smarty->registerCacheResource('mysql', new Smarty_CacheResource_Mysql());
$smarty->registerCacheResource('mysql', new My_CacheResource_Mysql());
?>
@@ -18,7 +18,7 @@ not find a definition for a tag otherwise. It uses the following
parameters:
If during compilation Smarty encounters tag which is not defined
internal, registered or loacted in the plugins folder it tries to
internal, registered or located in the plugins folder it tries to
resolve it by calling the registered default plugin handler. The handler
may be called several times for same undefined tag looping over valid
plugin types.
@@ -37,7 +37,7 @@ plugin types.
* @param string $name name of the undefined tag
* @param string $type tag type (e.g. Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK,
Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_MODIFIER, Smarty::PLUGIN_MODIFIERCOMPILER)
* @param Smarty_Internal_Template $template template object
* @param \Smarty\Template\ $template template object
* @param string &$callback returned function name
* @param string &$script optional returned script filepath if function is external
* @param bool &$cacheable true by default, set to false if plugin is not cachable (Smarty >= 3.1.8)
@@ -38,8 +38,7 @@ filters](#advanced.features.outputfilters) for more information on how
to set up an output filter function.
See also [`unregisterFilter()`](#api.unregister.filter),
[`loadFilter()`](#api.load.filter),
[`$autoload_filters`](#variable.autoload.filters), [template pre
[`loadFilter()`](#api.load.filter), [template pre
filters](#advanced.features.prefilters) [template post
filters](#advanced.features.postfilters) [template output
filters](#advanced.features.outputfilters) section.
@@ -32,9 +32,9 @@ cache\_attrs
This method registers functions or methods defined in your script as
plugin. It uses the following parameters:
- `cacheable` and `cache_attrs` can be omitted in most cases. See
- `cacheable` can be omitted in most cases. See
[controlling cacheability of plugins output](#caching.cacheable) on
how to use them properly.
how to use this properly.
<!-- -->
@@ -37,7 +37,7 @@ information on how to setup a function for fetching templates.
<?php
$smarty->registerResource('mysql', new Smarty_Resource_Mysql());
$smarty->registerResource('mysql', new My_Resource_Mysql());
?>
@@ -55,5 +55,4 @@ And the php script
See also [`display()`](#api.display), [`fetch()`](#api.fetch),
[`{include}`](#language.function.include) and
[`{insert}`](#language.function.insert)
and [`{include}`](#language.function.include)
@@ -10,7 +10,7 @@ void
testInstall
This function verifies that all required working folders of the Smarty
installation can be accessed. It does output a corresponding protocoll.
installation can be accessed. It does output a corresponding protocol.
<?php
-7
View File
@@ -4,9 +4,7 @@ Smarty Class Variables {#api.variables}
These are all of the available Smarty class variables. You can access
them directly, or use the corresponding setter/getter methods.
- [$allow_php_templates](./api-variables/variable-allow-php-templates.md)
- [$auto_literal](./api-variables/variable-auto-literal.md)
- [$autoload_filters](./api-variables/variable-autoload-filters.md)
- [$cache_dir](./api-variables/variable-cache-dir.md)
- [$cache_id](./api-variables/variable-cache-id.md)
- [$cache_lifetime](./api-variables/variable-cache-lifetime.md)
@@ -31,7 +29,6 @@ them directly, or use the corresponding setter/getter methods.
- [$default_resource_type](./api-variables/variable-default-resource-type.md)
- [$default_config_handler_func](./api-variables/variable-default-config-handler-func.md)
- [$default_template_handler_func](./api-variables/variable-default-template-handler-func.md)
- [$direct_access_security](./api-variables/variable-direct-access-security.md)
- [$error_reporting](./api-variables/variable-error-reporting.md)
- [$escape_html](./api-variables/variable-escape-html.md)
- [$force_cache](./api-variables/variable-force-cache.md)
@@ -39,13 +36,9 @@ them directly, or use the corresponding setter/getter methods.
- [$left_delimiter](./api-variables/variable-left-delimiter.md)
- [$locking_timeout](./api-variables/variable-locking-timeout.md)
- [$merge_compiled_includes](./api-variables/variable-merge-compiled-includes.md)
- [$php_handling](./api-variables/variable-php-handling.md)
- [$plugins_dir](./api-variables/variable-plugins-dir.md)
- [$right_delimiter](./api-variables/variable-right-delimiter.md)
- [$smarty_debug_id](./api-variables/variable-smarty-debug-id.md)
- [$template_dir](./api-variables/variable-template-dir.md)
- [$trusted_dir](./api-variables/variable-trusted-dir.md)
- [$use_include_path](./api-variables/variable-use-include-path.md)
- [$use_sub_dirs](./api-variables/variable-use-sub-dirs.md)
> **Note**
@@ -1,18 +0,0 @@
\$allow\_php\_templates {#variable.allow.php.templates}
=======================
By default the PHP template file resource is disabled. Setting
`$allow_php_templates` to TRUE will enable PHP template files.
::: {.informalexample}
<?php
$smarty->allow_php_templates = true;
?>
:::
> **Note**
>
> The PHP template file resource is an undocumented deprecated feature.
@@ -1,21 +0,0 @@
\$autoload\_filters {#variable.autoload.filters}
===================
If there are some filters that you wish to load on every template
invocation, you can specify them using this variable and Smarty will
automatically load them for you. The variable is an associative array
where keys are filter types and values are arrays of the filter names.
For example:
::: {.informalexample}
<?php
$smarty->autoload_filters = array('pre' => array('trim', 'stamp'),
'output' => array('convert'));
?>
:::
See also [`registerFilter()`](#api.register.filter) and
[`loadFilter()`](#api.load.filter)
@@ -5,8 +5,8 @@ This is the length of time in seconds that a template cache is valid.
Once this time has expired, the cache will be regenerated.
- `$caching` must be turned on (either
Smarty::CACHING\_LIFETIME\_CURRENT or
Smarty::CACHING\_LIFETIME\_SAVED) for `$cache_lifetime` to have any
\Smarty\Smarty::CACHING\_LIFETIME\_CURRENT or
\Smarty\Smarty::CACHING\_LIFETIME\_SAVED) for `$cache_lifetime` to have any
purpose.
- A `$cache_lifetime` value of -1 will force the cache to never
@@ -14,11 +14,11 @@ Once this time has expired, the cache will be regenerated.
- A value of 0 will cause the cache to always regenerate (good for
testing only, to disable caching a more efficient method is to set
[`$caching`](#variable.caching) = Smarty::CACHING\_OFF).
[`$caching`](#variable.caching) = \Smarty\Smarty::CACHING\_OFF).
- If you want to give certain templates their own cache lifetime, you
could do this by setting [`$caching`](#variable.caching) =
Smarty::CACHING\_LIFETIME\_SAVED, then set `$cache_lifetime` to a
\Smarty\Smarty::CACHING\_LIFETIME\_SAVED, then set `$cache_lifetime` to a
unique value just before calling [`display()`](#api.display) or
[`fetch()`](#api.fetch).
@@ -4,8 +4,7 @@
If set to TRUE, Smarty will respect the If-Modified-Since header sent
from the client. If the cached file timestamp has not changed since the
last visit, then a `'304: Not Modified'` header will be sent instead of
the content. This works only on cached content without
[`{insert}`](#language.function.insert) tags.
the content.
See also [`$caching`](#variable.caching),
[`$cache_lifetime`](#variable.cache.lifetime), and the [caching
@@ -3,21 +3,21 @@
This tells Smarty whether or not to cache the output of the templates to
the [`$cache_dir`](#variable.cache.dir). By default this is set to the
constant Smarty::CACHING\_OFF. If your templates consistently generate
constant \Smarty\Smarty::CACHING\_OFF. If your templates consistently generate
the same content, it is advisable to turn on `$caching`, as this may
result in significant performance gains.
You can also have [multiple](#caching.multiple.caches) caches for the
same template.
- A constant value of Smarty::CACHING\_LIFETIME\_CURRENT or
Smarty::CACHING\_LIFETIME\_SAVED enables caching.
- A constant value of \Smarty\Smarty::CACHING\_LIFETIME\_CURRENT or
\Smarty\Smarty ::CACHING\_LIFETIME\_SAVED enables caching.
- A value of Smarty::CACHING\_LIFETIME\_CURRENT tells Smarty to use
- A value of \Smarty\Smarty::CACHING\_LIFETIME\_CURRENT tells Smarty to use
the current [`$cache_lifetime`](#variable.cache.lifetime) variable
to determine if the cache has expired.
- A value of Smarty::CACHING\_LIFETIME\_SAVED tells Smarty to use the
- A value of \Smarty\Smarty::CACHING\_LIFETIME\_SAVED tells Smarty to use the
[`$cache_lifetime`](#variable.cache.lifetime) value at the time the
cache was generated. This way you can set the
[`$cache_lifetime`](#variable.cache.lifetime) just before
@@ -18,7 +18,7 @@ enabled, then the cache files will get regenerated if an involved
template file or config file was updated.
As of Smarty 3.1 `$compile_check` can be set to the value
`Smarty::COMPILECHECK_CACHEMISS`. This enables Smarty to revalidate the
`\Smarty\Smarty::COMPILECHECK_CACHEMISS`. This enables Smarty to revalidate the
compiled template, once a cache file is regenerated. So if there was a
cached template, but it\'s expired, Smarty will run a single
compile\_check before regenerating the cache.
@@ -1,7 +1,7 @@
\$compile\_id {#variable.compile.id}
=============
Persistant compile identifier. As an alternative to passing the same
Persistent compile identifier. As an alternative to passing the same
`$compile_id` to each and every function call, you can set this
`$compile_id` and it will be used implicitly thereafter.
@@ -10,7 +10,7 @@ post-filters](#plugins.prefilters.postfilters) you must use a unique
`$compile_id` to keep the compiled template files separated.
For example a [prefilter](#plugins.prefilters.postfilters) that
localizes your templates (that is: translates language dependend parts)
localizes your templates (that is: translates language dependent parts)
at compile time, then you could use the current language as
`$compile_id` and you will get a set of compiled templates for each
language you use.
@@ -2,8 +2,7 @@
============
This is the name of the template file used for the debugging console. By
default, it is named `debug.tpl` and is located in the
[`SMARTY_DIR`](#constant.smarty.dir).
default, it is named `debug.tpl` and is located in `src/debug.tpl`.
See also [`$debugging`](#variable.debugging) and the [debugging
console](#chapter.debugging.console) section.
@@ -8,7 +8,7 @@ resource.
>
> The default handler is currently only invoked for file resources. It
> is not triggered when the resource itself cannot be found, in which
> case a SmartyException is thrown.
> case a \Smarty\Exception is thrown.
<?php
@@ -8,7 +8,7 @@ resource.
>
> The default handler is currently only invoked for file resources. It
> is not triggered when the resource itself cannot be found, in which
> case a SmartyException is thrown.
> case a \Smarty\Exception is thrown.
<?php
@@ -1,13 +0,0 @@
\$direct\_access\_security {#variable.direct.access.security}
==========================
Direct access security inhibits direct browser access to compiled or
cached template files.
Direct access security is enabled by default. To disable it set
`$direct_access_security` to FALSE.
> **Note**
>
> This is a compile time option. If you change the setting you must make
> sure that the templates get recompiled.
@@ -7,7 +7,7 @@ When this value is set to a non-null-value it\'s value is used as php\'s
Smarty 3.1.2 introduced the
[`muteExpectedErrors()`](#api.mute.expected.errors) function. Calling
`Smarty::muteExpectedErrors();` after setting up custom error handling
`\Smarty\Smarty::muteExpectedErrors();` after setting up custom error handling
will ensure that warnings and notices (deliberately) produced by Smarty
will not be passed to other custom error handlers. If your error logs
are filling up with warnings regarding `filemtime()` or `unlink()`
@@ -2,6 +2,6 @@
==================
This is maximum time in seconds a cache lock is valid to avoid dead
locks. The deafult value is 10 seconds.
locks. The default value is 10 seconds.
See also [`$cache_locking`](#variable.cache.locking)
@@ -1,21 +0,0 @@
\$php\_handling {#variable.php.handling}
===============
This tells Smarty how to handle PHP code embedded in the templates.
There are four possible settings, the default being
`Smarty::PHP_PASSTHRU`. Note that this does NOT affect php code within
[`{php}{/php}`](#language.function.php) tags in the template.
- `Smarty::PHP_PASSTHRU` - Smarty echos tags as-is.
- `Smarty::PHP_QUOTE` - Smarty quotes the tags as html entities.
- `Smarty::PHP_REMOVE` - Smarty removes the tags from the templates.
- `Smarty::PHP_ALLOW` - Smarty will execute the tags as PHP code.
> **Note**
>
> Embedding PHP code into templates is highly discouraged. Use [custom
> functions](#plugins.functions) or [modifiers](#plugins.modifiers)
> instead.
@@ -1,28 +0,0 @@
\$plugins\_dir {#variable.plugins.dir}
==============
This is the directory or directories where Smarty will look for the
plugins that it needs. Default is `plugins/` under the
[`SMARTY_DIR`](#constant.smarty.dir). If you supply a relative path,
Smarty will first look under the [`SMARTY_DIR`](#constant.smarty.dir),
then relative to the current working directory, then relative to the PHP
include\_path. If `$plugins_dir` is an array of directories, Smarty will
search for your plugin in each plugin directory **in the order they are
given**.
> **Note**
>
> For best performance, do not setup your `$plugins_dir` to have to use
> the PHP include path. Use an absolute pathname, or a path relative to
> `SMARTY_DIR` or the current working directory.
> **Note**
>
> As of Smarty 3.1 the attribute \$plugins\_dir is no longer accessible
> directly. Use [`getPluginsDir()`](#api.get.plugins.dir),
> [`setPluginsDir()`](#api.set.plugins.dir) and
> [`addPluginsDir()`](#api.add.plugins.dir) instead.
See also [`getPluginsDir()`](#api.get.plugins.dir),
[`setPluginsDir()`](#api.set.plugins.dir) and
[`addPluginsDir()`](#api.add.plugins.dir).
@@ -15,22 +15,12 @@ found.
> document root.
> **Note**
>
> If the directories known to `$template_dir` are relative to
> directories known to the
> [include\_path](&url.php-manual;ini.core.php#ini.include-path) you
> need to activate the [`$use_include_path`](#variable.use.include.path)
> option.
> **Note**
>
> As of Smarty 3.1 the attribute \$template\_dir is no longer accessible
> directly. Use [`getTemplateDir()`](#api.get.template.dir),
> [`setTemplateDir()`](#api.set.template.dir) and
> [`addTemplateDir()`](#api.add.template.dir) instead.
See also [`Template Resources`](#resources),
[`$use_include_path`](#variable.use.include.path),
[`getTemplateDir()`](#api.get.template.dir),
[`setTemplateDir()`](#api.set.template.dir) and
[`addTemplateDir()`](#api.add.template.dir).
@@ -1,8 +0,0 @@
\$trusted\_dir {#variable.trusted.dir}
==============
`$trusted_dir` is only for use when security is enabled. This is an
array of all directories that are considered trusted. Trusted
directories are where you keep php scripts that are executed directly
from the templates with
[`{include_php}`](#language.function.include.php).
@@ -1,49 +0,0 @@
\$use\_include\_path {#variable.use.include.path}
====================
This tells smarty to respect the
[include\_path](&url.php-manual;ini.core.php#ini.include-path) within
the [`File Template Resource`](#resources.file) handler and the plugin
loader to resolve the directories known to
[`$template_dir`](#variable.template.dir). The flag also makes the
plugin loader check the include\_path for
[`$plugins_dir`](#variable.plugins.dir).
> **Note**
>
> You should not design your applications to rely on the include\_path,
> as this may - depending on your implementation - slow down your system
> (and Smarty) considerably.
If use\_include\_path is enabled, file discovery for
[`$template_dir`](#variable.template.dir) and
[`$plugins_dir`](#variable.plugins.dir) work as follows.
- For each element `$directory` in array (\$template\_dir or
\$plugins\_dir) do
- Test if requested file is in `$directory` relative to the [current
working directory](&url.php-manual;function.getcwd.php). If file
found, return it.
- For each `$path` in include\_path do
- Test if requested file is in `$directory` relative to the `$path`
(possibly relative to the [current working
directory](&url.php-manual;function.getcwd.php)). If file found,
return it.
- Try default\_handler or fail.
This means that whenever a directory/file relative to the current
working directory is encountered, it is preferred over anything
potentially accessible through the include\_path.
> **Note**
>
> Smarty does not filter elements of the include\_path. That means a
> \".:\" within your include path will trigger the current working
> directory lookup twice.
See also [`Template Resources`](#resources) and
[`$template_dir`](#variable.template.dir)
@@ -10,7 +10,7 @@ environments do not allow PHP processes to create directories, so this
must be disabled which is the default.
Sub directories are more efficient, so use them if you can.
Theoretically you get much better perfomance on a filesystem with 10
Theoretically you get much better performance on a filesystem with 10
directories each having 100 files, than with 1 directory having 1000
files. This was certainly the case with Solaris 7 (UFS)\... with newer
filesystems such as ext3 and especially reiserfs, the difference is
+2 -50
View File
@@ -76,62 +76,14 @@ third parameter to [`registerPlugin()`](#api.register.plugin) is called
When registering a plugin with `$cacheable=false` the plugin is called
everytime the page is displayed, even if the page comes from the cache.
The plugin function behaves a little like an
[`{insert}`](#plugins.inserts) function.
> **Note**
>
> The `$cacheable` status will effect the compiled template code. If you
> The `$cacheable` status will affect the compiled template code. If you
> change the status you must manually delete existing compiled and
> cached template files to force a recompile.
In contrast to [`{insert}`](#plugins.inserts) the attributes to the
plugins are not cached by default. They can be declared to be cached
with the fourth parameter `$cache_attrs`. `$cache_attrs` is an array of
attribute-names that should be cached, so the plugin-function get value
as it was the time the page was written to cache everytime it is fetched
from the cache.
<?php
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
function remaining_seconds($params, $smarty) {
$remain = $params['endtime'] - time();
if($remain >= 0){
return $remain . ' second(s)';
}else{
return 'done';
}
}
$smarty->registerPlugin('function','remaining', 'remaining_seconds', false, array('endtime'));
if (!$smarty->isCached('index.tpl')) {
// fetch $obj from db and assign...
$smarty->assignByRef('obj', $obj);
}
$smarty->display('index.tpl');
?>
where `index.tpl` is:
Time Remaining: {remaining endtime=$obj->endtime}
The number of seconds till the endtime of `$obj` is reached changes on
each display of the page, even if the page is cached. Since the endtime
attribute is cached the object only has to be pulled from the database
when page is written to the cache but not on subsequent requests of the
page.
index.php:
Example `index.php`:
<?php
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
+8 -8
View File
@@ -17,11 +17,11 @@ faster storage engine, centralize the cache to be accessible to multiple
servers.
Smarty allows CacheResource implementations to use one of the APIs
`Smarty_CacheResource_Custom` or `Smarty_CacheResource_KeyValueStore`.
`Smarty_CacheResource_Custom` is a simple API directing all read, write,
`\Smarty\Cacheresource\Custom` or `\Smarty\Cacheresource\KeyValueStore`.
`\Smarty\Cacheresource\Custom` is a simple API directing all read, write,
clear calls to your implementation. This API allows you to store
wherever and however you deem fit. The
`Smarty_CacheResource_KeyValueStore` API allows you to turn any \"dumb\"
`\Smarty\Cacheresource\KeyValueStore` API allows you to turn any \"dumb\"
KeyValue-Store (like APC, Memcache, ...) into a full-featured
CacheResource implementation. That is, everything around deep
cache-groups like \"a\|b\|c\" is being handled for you in way that
@@ -63,10 +63,10 @@ to invoke your custom CacheResource implementation.
* INDEX(`modified`)
* ) ENGINE = InnoDB;</pre>
*
* @package CacheResource-examples
* @author Rodney Rehm
*/
class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom {
class My_CacheResource_Mysql extends \Smarty\Cacheresource\Custom {
// PDO instance
protected $db;
protected $fetch;
@@ -77,7 +77,7 @@ to invoke your custom CacheResource implementation.
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());
throw new \Smarty\Exception('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');
@@ -211,10 +211,10 @@ to invoke your custom CacheResource implementation.
* Note that memcache has a limitation of 256 characters per cache-key.
* To avoid complications all cache-keys are translated to a sha1 hash.
*
* @package CacheResource-examples
* @author Rodney Rehm
*/
class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore {
class My_CacheResource_Memcache extends \Smarty\Cacheresource\KeyValueStore {
/**
* memcache instance
* @var Memcache
+2 -2
View File
@@ -25,10 +25,10 @@ like.
- You CANNOT remove a specified template name under multiple cache
groups such as `'/a/b/*/foo.tpl'`, the cache grouping works
left-to-right ONLY. You will need to group your templates under a
single cache group heirarchy to be able to clear them as a group.
single cache group hierarchy to be able to clear them as a group.
Cache grouping should not be confused with your template directory
heirarchy, the cache grouping has no knowledge of how your templates are
hierarchy, the cache grouping has no knowledge of how your templates are
structured. So for example, if you have a template structure like
`themes/blue/index.tpl` and you want to be able to clear all the cache
files for the "blue" theme, you will need to create a cache group
+7 -10
View File
@@ -3,7 +3,7 @@ Setting Up Caching {#caching.setting.up}
The first thing to do is enable caching by setting
[`$caching`](#variable.caching) to one of
`Smarty::CACHING_LIFETIME_CURRENT` or `Smarty::CACHING_LIFETIME_SAVED`.
`\Smarty\Smarty::CACHING_LIFETIME_CURRENT` or `Smarty::CACHING_LIFETIME_SAVED`.
<?php
@@ -36,7 +36,7 @@ Each cached page has a limited lifetime determined by
seconds, or one hour. After that time expires, the cache is regenerated.
It is possible to give individual caches their own expiration time by
setting [`$caching`](#variable.caching) to
`Smarty::CACHING_LIFETIME_SAVED`. See
`\Smarty\Smarty::CACHING_LIFETIME_SAVED`. See
[`$cache_lifetime`](#variable.cache.lifetime) for more details.
@@ -92,7 +92,7 @@ however this also seriously degrades performance.
[`$force_compile`](#variable.force.compile) is meant to be used for
[debugging](#chapter.debugging.console) purposes. The appropriate way to
disable caching is to set [`$caching`](#variable.caching) to
Smarty::CACHING\_OFF.
\Smarty\Smarty::CACHING\_OFF.
The [`isCached()`](#api.is.cached) function can be used to test if a
template has a valid cache or not. If you have a cached template that
@@ -118,16 +118,13 @@ process.
You can keep parts of a page dynamic (disable caching) with the
[`{nocache}{/nocache}`](#language.function.nocache) block function, the
[`{insert}`](#language.function.insert) function, or by using the
[`{nocache}{/nocache}`](#language.function.nocache) block function, or by using the
`nocache` parameter for most template functions.
Let\'s say the whole page can be cached except for a banner that is
displayed down the side of the page. By using the
[`{insert}`](#language.function.insert) function for the banner, you can
keep this element dynamic within the cached content. See the
documentation on [`{insert}`](#language.function.insert) for more
details and examples.
displayed down the side of the page. By using a [`{nocache}{/nocache}`](#language.function.nocache)
block for the banner, you can
keep this element dynamic within the cached content.
You can clear all the cache files with the
[`clearAllCache()`](#api.clear.all.cache) function, or individual cache
+4 -9
View File
@@ -5,17 +5,15 @@ Charset Encoding {#charset.encoding}
================
There are a variety of encodings for textual data, ISO-8859-1 (Latin1)
and UTF-8 being the most popular. Unless you change `Smarty::$_CHARSET`,
Smarty recognizes `UTF-8` as the internal charset if
[Multibyte String](https://www.php.net/mbstring) is available,
`ISO-8859-1` if not.
and UTF-8 being the most popular. Unless you change `\Smarty\Smarty::$_CHARSET`,
Smarty recognizes `UTF-8` as the internal charset.
> **Note**
>
> `ISO-8859-1` has been PHP\'s default internal charset since the
> beginning. Unicode has been evolving since 1991. Since then it has
> become the one charset to conquer them all, as it is capable of
> encoding most of the known characters even accross different character
> encoding most of the known characters even across different character
> systems (latin, cyrillic, japanese, ...). `UTF-8` is unicode\'s most
> used encoding, as it allows referencing the thousands of character
> with the smallest size overhead possible.
@@ -26,10 +24,7 @@ Smarty recognizes `UTF-8` as the internal charset if
> **Note**
>
> Smarty\'s internals and core plugins are truly UTF-8 compatible since
> Smarty 3.1. To achieve unicode compatibility, the [Multibyte
> String](https://www.php.net/mbstring) PECL is required. Unless your PHP
> environment offers this package, Smarty will not be able to offer
> full-scale UTF-8 compatibility.
> Smarty 3.1.
// use japanese character encoding
-1
View File
@@ -13,7 +13,6 @@ Extending Smarty With Plugins {#plugins}
- [Prefilters/Postfilters](./plugins/plugins-prefilters-postfilters.md)
- [Output Filters](./plugins/plugins-outputfilters.md)
- [Resources](./plugins/plugins-resources.md)
- [Inserts](./plugins/plugins-inserts.md)
Version 2.0 introduced the plugin architecture that is used for almost
all the customizable functionality of Smarty. This includes:
@@ -60,12 +60,6 @@ cannot have both custom function `{func}` and block function
function implementation is called again with the new block contents
in the parameter `$content`.
If you have nested block functions, it\'s possible to find out what the
parent block function is by accessing `$smarty->_tag_stack` variable.
Just do a [`var_dump()`](&url.php-manual;var_dump) on it and the
structure should be apparent.
<?php
/*
* Smarty plugin
@@ -76,7 +70,7 @@ structure should be apparent.
* Purpose: translate a block of text
* -------------------------------------------------------------
*/
function smarty_block_translate($params, $content, Smarty_Internal_Template $template, &$repeat)
function smarty_block_translate($params, $content, \Smarty\Template $template, &$repeat)
{
// only output on the closing tag
if(!$repeat){
@@ -40,7 +40,7 @@ some other Smarty-provided functionality, it can use the supplied
* Purpose: outputs a random magic answer
* -------------------------------------------------------------
*/
function smarty_function_eightball($params, Smarty_Internal_Template $template)
function smarty_function_eightball($params, \Smarty\Template\ $template)
{
$answers = array('Yes',
'No',
@@ -71,7 +71,7 @@ which can be used in the template as:
* Purpose: assign a value to a template variable
* -------------------------------------------------------------
*/
function smarty_function_assign($params, Smarty_Internal_Template $template)
function smarty_function_assign($params, \Smarty\Template\ $template)
{
if (empty($params['var'])) {
trigger_error("assign: missing 'var' parameter");
@@ -1,48 +0,0 @@
Inserts {#plugins.inserts}
=======
Insert plugins are used to implement functions that are invoked by
[`{insert}`](#language.function.insert) tags in the template.
string
smarty\_insert\_
name
array
\$params
object
\$template
The first parameter to the function is an associative array of
attributes passed to the insert.
The insert function is supposed to return the result which will be
substituted in place of the `{insert}` tag in the template.
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: insert.time.php
* Type: time
* Name: time
* Purpose: Inserts current date/time according to format
* -------------------------------------------------------------
*/
function smarty_insert_time($params, Smarty_Internal_Template $template)
{
if (empty($params['format'])) {
trigger_error("insert time: missing 'format' parameter");
return;
}
return strftime($params['format']);
}
?>
@@ -28,8 +28,6 @@ in order to be located by Smarty.
- resource
- insert
- And `name` should be a valid identifier; letters, numbers, and
underscores only, see [php
variables](&url.php-manual;language.variables).
@@ -35,7 +35,7 @@ and return the results.
* a simple protection against spambots
* -------------------------------------------------------------
*/
function smarty_outputfilter_protect_email($output, Smarty_Internal_Template $template)
function smarty_outputfilter_protect_email($output, \Smarty\Template\ $template)
{
return preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
'$1%40$2', $output);
@@ -57,7 +57,7 @@ of this code.
* Purpose: Convert html tags to be lowercase.
* -------------------------------------------------------------
*/
function smarty_prefilter_pre01($source, Smarty_Internal_Template $template)
function smarty_prefilter_pre01($source, \Smarty\Template\ $template)
{
return preg_replace('!<(\w+)[^>]+>!e', 'strtolower("$1")', $source);
}
@@ -76,7 +76,7 @@ of this code.
* Purpose: Output code that lists all current template vars.
* -------------------------------------------------------------
*/
function smarty_postfilter_post01($compiled, Smarty_Internal_Template $template)
function smarty_postfilter_post01($compiled, \Smarty\Template\ $template)
{
$compiled = "<pre>\n<?php print_r(\$template->getTemplateVars()); ?>\n</pre>" . $compiled;
return $compiled;
+10 -10
View File
@@ -12,20 +12,20 @@ will be able to access that resource by prepending its name to the
template you\'re addressing: `foobarxyz:yourtemplate.tpl`.
If a Resource\'s templates should not be run through the Smarty
compiler, the Custom Resource may extend `Smarty_Resource_Uncompiled`.
compiler, the Custom Resource may extend `\Smarty\Resource\UncompiledPlugin`.
The Resource Handler must then implement the function
`renderUncompiled(Smarty_Internal_Template $_template)`. `$_template` is
`renderUncompiled(\Smarty\Template $_template)`. `$_template` is
a reference to the current template and contains all assigned variables
which the implementor can access via
`$_template->smarty->getTemplateVars()`. These Resources simply echo
`$_template->getSmarty()->getTemplateVars()`. These Resources simply echo
their rendered content to the output stream. The rendered output will be
output-cached if the Smarty instance was configured accordingly. See
`libs/sysplugins/smarty_internal_resource_php.php` for an example.
`src/Resource/PhpPlugin.php` for an example.
If the Resource\'s compiled templates should not be cached on disk, the
Custom Resource may extend `Smarty_Resource_Recompiled`. These Resources
Custom Resource may extend `\Smarty\Resource\RecompiledPlugin`. These Resources
are compiled every time they are accessed. This may be an expensive
overhead. See `libs/sysplugins/smarty_internal_resource_eval.php` for an
overhead. See `src/Resource/StringEval.php` for an
example.
@@ -48,10 +48,10 @@ example.
* Demo data:
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');</pre>
*
* @package Resource-examples
* @author Rodney Rehm
*/
class Smarty_Resource_Mysql extends Smarty_Resource_Custom {
class My_Resource_Mysql extends \Smarty\Resource\CustomPlugin {
// PDO instance
protected $db;
// prepared fetch() statement
@@ -63,7 +63,7 @@ example.
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());
throw new \Smarty\Exception('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');
@@ -109,7 +109,7 @@ example.
require_once 'libs/Smarty.class.php';
$smarty = new Smarty();
$smarty->registerResource('mysql', new Smarty_Resource_Mysql());
$smarty->registerResource('mysql', new My_Resource_Mysql());
// using resource from php script
$smarty->display("mysql:index.tpl");
+1 -17
View File
@@ -8,23 +8,7 @@ functions.
For the plugins that are registered at runtime, the name of the plugin
function(s) does not have to follow the naming convention.
If a plugin depends on some functionality provided by another plugin (as
is the case with some plugins bundled with Smarty), then the proper way
to load the needed plugin is this:
<?php
function smarty_function_yourPlugin(array $params, Smarty_Internal_Template $template)
{
// load plugin depended upon
$template->smarty->loadPlugin('smarty_shared_make_timestamp');
// plugin code
}
?>
As a general rule, the currently evaluated template\'s
Smarty\_Internal\_Template object is always passed to the plugins as the
last parameter with two exceptions:
@@ -34,10 +34,10 @@ on the functions you are supposed to provide.
* Demo data:
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');</pre>
*
* @package Resource-examples
* @author Rodney Rehm
*/
class Smarty_Resource_Mysql extends Smarty_Resource_Custom {
class My_Resource_Mysql extends \Smarty\Resource\Custom {
// PDO instance
protected $db;
// prepared fetch() statement
@@ -49,7 +49,7 @@ on the functions you are supposed to provide.
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());
throw new \Smarty\Exception('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');
@@ -95,7 +95,7 @@ on the functions you are supposed to provide.
require_once 'libs/Smarty.class.php';
$smarty = new Smarty();
$smarty->registerResource('mysql', new Smarty_Resource_Mysql());
$smarty->registerResource('mysql', new My_Resource_Mysql());
// using resource from php script
$smarty->display("mysql:index.tpl");
@@ -3,20 +3,20 @@ Extends Template Resources {#resources.extends}
The `extends:` resource is used to define child/parent relationships for
template inheritance from the PHP script. For details see section of
[Template Interitance](#advanced.features.template.inheritance).
[Template Inheritance](#advanced.features.template.inheritance).
As of Smarty 3.1 the `extends:` resource may use any available [template
resource](#resources), including `string:` and `eval:`. When [templates
from strings](#resources.string) are used, make sure they are properly
(url or base64) encoded. Is an `eval:` resource found within an
inheritance chain, its \"don\'t save a compile file\" property is
superseeded by the `extends:` resource. The templates within an
superseded by the `extends:` resource. The templates within an
inheritance chain are not compiled separately, though. Only a single
compiled template will be generated.
> **Note**
>
> Use this when inheritance is required programatically. When inheriting
> Use this when inheritance is required programmatically. When inheriting
> within PHP, it is not obvious from the child template what inheritance
> took place. If you have a choice, it is normally more flexible and
> intuitive to handle inheritance chains from within the templates.
+1 -7
View File
@@ -11,12 +11,6 @@ If the file resource cannot find the requested template, the
[`$default_template_handler_func`](#variable.default.template.handler.func)
is invoked.
> **Note**
>
> As of Smarty 3.1 the file resource no longer walks through the
> [include\_path](&url.php-manual;ini.core.php#ini.include-path) unless
> [`$use_include_path` is activated](#variable.use.include.path)
Templates from \$template\_dir {#templates.from.template.dir}
------------------------------
@@ -47,7 +41,7 @@ Templates from a specific \$template\_dir {#templates.from.specified.template.di
Smarty 3.1 introduced the bracket-syntax for specifying an element from
[`$template_dir`](#variable.template.dir). This allows websites
employing multiple sets of templates better control over which template
to acces.
to access.
The bracket-syntax can be used from anywhere you can specify the `file:`
resource type.

Some files were not shown because too many files have changed in this diff Show More