mirror of
https://github.com/smarty-php/smarty.git
synced 2026-08-06 13:34:11 +02:00
Compare commits
122 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c201ccd3fd | |||
| 28377a26e9 | |||
| 8a2ed9446a | |||
| 39dad96601 | |||
| c47756b489 | |||
| 047b73d4a1 | |||
| cabcafc7ea | |||
| a72f83d989 | |||
| 9e2399b020 | |||
| 169cd924df | |||
| 46dfed3837 | |||
| 754db3b2e3 | |||
| 971c4d5158 | |||
| a8cf56e4f4 | |||
| 45de28107a | |||
| 79842c8baf | |||
| 0e380a1748 | |||
| f53eb27450 | |||
| a5a15b8b1e | |||
| 262221f0b7 | |||
| 344b3e3a31 | |||
| b798362871 | |||
| 1a8ee6ebda | |||
| 641678083b | |||
| ecfa4bfa16 | |||
| 9cc60f5e38 | |||
| 431d77505f | |||
| c5f555eed4 | |||
| 2cf658c9c3 | |||
| ecac24d073 | |||
| 34a0a2876b | |||
| 3922c1eb1e | |||
| 68c59e6627 | |||
| ad2703dd75 | |||
| f1c3ac4395 | |||
| 7c02bb9a63 | |||
| 4bbe94f4e0 | |||
| bdb379d8fb | |||
| 2d2d052557 | |||
| f1f3874780 | |||
| 4ea8838d3b | |||
| 03430c4f94 | |||
| 2fbf67b32e | |||
| 390f34318d | |||
| 27dd3e4c57 | |||
| 41c8bd3035 | |||
| 38cad9723e | |||
| 5988116c81 | |||
| f5b432dea4 | |||
| b02061878f | |||
| 73ff8fd3d0 | |||
| d900a0ef4a | |||
| 5c74dc4a83 | |||
| 3be63a3418 | |||
| cdf1ed2a50 | |||
| e0f2c36d4d | |||
| 541f0821f0 | |||
| 536721d457 | |||
| 577f910e49 | |||
| 1fe5050a04 | |||
| 22ce23b47b | |||
| ad245ccd0c | |||
| 51075e0421 | |||
| 3d10630510 | |||
| 5052ce0d88 | |||
| 9651dafbce | |||
| b424657fd9 | |||
| 9016dd9908 | |||
| e124f71dd8 | |||
| 34d5d6d024 | |||
| c5de83b09f | |||
| 861aafa92c | |||
| e1d395e140 | |||
| fd64cc688a | |||
| e595cd2a5d | |||
| b2e11ee2b8 | |||
| 1f87cebb93 | |||
| 608a400e66 | |||
| f07e342d61 | |||
| 576bd4cc01 | |||
| e89a3dda49 | |||
| 2b71415d1f | |||
| 3cc61133a3 | |||
| 216347b4ff | |||
| 14bbffd584 | |||
| 41054cfb05 | |||
| 16c7fe1d4f | |||
| 3fccb54093 | |||
| 32df4c6467 | |||
| 98ad1a13af | |||
| 9766aba66e | |||
| b9ecf115dd | |||
| 60a56969dd | |||
| 6b9e2fadd1 | |||
| ab5705a90d | |||
| 57cff64869 | |||
| 4d66910e7f | |||
| f1e7b2d46f | |||
| 0fc2b3726b | |||
| d88175de3e | |||
| cfd8c08d09 | |||
| b0db4705a0 | |||
| 5cac5e42f1 | |||
| 6ba059dea8 | |||
| 1524f11c8e | |||
| 164a89a1fd | |||
| d0319bdc87 | |||
| 9a0d46f1bc | |||
| 53fe73b9cc | |||
| e54a53332f | |||
| 8b5540f4f3 | |||
| 91b6fdeb4e | |||
| a34ee98e21 | |||
| 4d1cf61bb8 | |||
| c0a6b641bf | |||
| 044647bd71 | |||
| c02e9e135e | |||
| 67ab8f6879 | |||
| 773b3b4b7c | |||
| 613c5d691c | |||
| c016895166 | |||
| f81720941c |
@@ -25,12 +25,12 @@ jobs:
|
||||
- ubuntu-latest
|
||||
|
||||
php-version:
|
||||
- "7.1"
|
||||
- "7.2"
|
||||
- "7.3"
|
||||
- "7.4"
|
||||
- "8.0"
|
||||
- "8.1"
|
||||
- "8.2"
|
||||
|
||||
compiler:
|
||||
- default
|
||||
@@ -42,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'
|
||||
@@ -59,17 +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
|
||||
uses: php-actions/composer@v6
|
||||
|
||||
- name: Run make
|
||||
run: make -B
|
||||
|
||||
- name: Run tests with phpunit
|
||||
run: ./run-tests.sh
|
||||
run: php ./vendor/phpunit/phpunit/phpunit
|
||||
|
||||
+2
-8
@@ -1,13 +1,7 @@
|
||||
|
||||
.idea/
|
||||
|
||||
# Smarty
|
||||
lexer/*.php
|
||||
lexer/*.php.bak
|
||||
lexer/*.out
|
||||
|
||||
# Dev
|
||||
phpunit*
|
||||
.phpunit.result.cache
|
||||
vendor/*
|
||||
composer.lock
|
||||
/vendor/*
|
||||
/composer.lock
|
||||
|
||||
+65
-4
@@ -6,11 +6,72 @@ 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)
|
||||
|
||||
- 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)
|
||||
@@ -1764,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
|
||||
@@ -2099,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
|
||||
|
||||
@@ -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
|
||||
@@ -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/).
|
||||
|
||||
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
-7
@@ -3,16 +3,10 @@ services:
|
||||
base:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./utilities/testrunners/php71/Dockerfile
|
||||
dockerfile: ./utilities/testrunners/php72/Dockerfile
|
||||
volumes:
|
||||
- .:/app
|
||||
working_dir: /app
|
||||
entrypoint: sh ./run-tests.sh
|
||||
php71:
|
||||
extends:
|
||||
service: base
|
||||
build:
|
||||
dockerfile: ./utilities/testrunners/php71/Dockerfile
|
||||
php72:
|
||||
extends:
|
||||
service: base
|
||||
@@ -38,3 +32,8 @@ services:
|
||||
service: base
|
||||
build:
|
||||
dockerfile: ./utilities/testrunners/php81/Dockerfile
|
||||
php82:
|
||||
extends:
|
||||
service: base
|
||||
build:
|
||||
dockerfile: ./utilities/testrunners/php82/Dockerfile
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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,7 +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)
|
||||
- [{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,7 +135,6 @@ The following functions can also *optionally* assign template variables.
|
||||
|
||||
[`{capture}`](#language.function.capture),
|
||||
[`{include}`](#language.function.include),
|
||||
[`{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.
|
||||
|
||||
@@ -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,5 +188,5 @@ current template.
|
||||
|
||||
|
||||
|
||||
See also [`{insert}`](#language.function.insert), [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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,43 +1,41 @@
|
||||
# capitalize (modifier)
|
||||
capitalize {#language.modifier.capitalize}
|
||||
==========
|
||||
|
||||
This is used to capitalize the first letter of all words in a variable.
|
||||
This is similar to the PHP [`ucwords()`](&url.php-manual;ucwords)
|
||||
function.
|
||||
|
||||
## Parameters
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- --------- ---------- --------- -----------------------------------------------------------------------------------------------------------
|
||||
1 boolean No FALSE This determines whether or not words with digits will be uppercased
|
||||
2 boolean No FALSE This determines whether or not Capital letters within words should be lowercased, e.g. \"aAa\" to \"Aaa\"
|
||||
|
||||
| Position | Type | Required | Default | Description |
|
||||
|----------|---------|----------|---------|-------------------------------------------------------------------------------------------------------|
|
||||
| 1 | boolean | No | False | This determines whether or not words with digits will be uppercased. |
|
||||
| 2 | boolean | No | False | This determines whether or not Capital letters within words should be lowercased, e.g. "aAa" to "Aaa" |
|
||||
|
||||
## Example
|
||||
<?php
|
||||
|
||||
PHP-script:
|
||||
$smarty->assign('articleTitle', 'next x-men film, x3, delayed.');
|
||||
|
||||
?>
|
||||
|
||||
```php
|
||||
$smarty->assign('articleTitle', 'next x-men film, x3, delayed.');
|
||||
```
|
||||
|
||||
|
||||
Where the template is:
|
||||
|
||||
```smarty
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|capitalize}
|
||||
{$articleTitle|capitalize:true}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
```
|
||||
|
||||
next x-men film, x3, delayed.
|
||||
Next X-Men Film, x3, Delayed.
|
||||
Next X-Men Film, X3, Delayed.
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [lower (modifier)](./language-modifier-lower.md)
|
||||
- [upper (modifier)](./language-modifier-upper.md)
|
||||
|
||||
See also [`lower`](#language.modifier.lower) and
|
||||
[`upper`](#language.modifier.upper)
|
||||
|
||||
@@ -1,26 +1,31 @@
|
||||
# cat (modifier)
|
||||
cat {#language.modifier.cat}
|
||||
===
|
||||
|
||||
This value is concatenated to the given variable.
|
||||
|
||||
## Parameters
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- -------- ---------- --------- -----------------------------------------------
|
||||
1 string No *empty* This value to catenate to the given variable.
|
||||
|
||||
| Position | Type | Required | Default | Description |
|
||||
|----------|--------|----------|---------|-----------------------------------------------|
|
||||
| 1 | string | No | *empty* | This value to catenate to the given variable. |
|
||||
|
||||
## Example
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', "Psychics predict world didn't end");
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
PHP-script:
|
||||
```php
|
||||
$smarty->assign('articleTitle', "Psychics predict world didn't end");
|
||||
```
|
||||
|
||||
Where template is:
|
||||
```smarty
|
||||
{$articleTitle|cat:' yesterday.'}
|
||||
```
|
||||
|
||||
|
||||
{$articleTitle|cat:' yesterday.'}
|
||||
|
||||
|
||||
|
||||
Will output:
|
||||
```
|
||||
|
||||
|
||||
Psychics predict world didn't end yesterday.
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -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}
|
||||
------------------------------------
|
||||
|
||||
@@ -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');
|
||||
```
|
||||
|
||||
@@ -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,7 +2,7 @@ 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
|
||||
@@ -10,15 +10,9 @@ instance of the Smarty\_Security class. These are the possible settings:
|
||||
|
||||
- `$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
|
||||
[`{insert}`](#language.function.insert.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
|
||||
@@ -27,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`
|
||||
|
||||
@@ -53,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
|
||||
@@ -103,13 +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;
|
||||
// allow everthing as modifier
|
||||
public $php_modifiers = array();
|
||||
class My_Security_Policy extends \Smarty\Security {
|
||||
public $allow_constants = false;
|
||||
}
|
||||
$smarty = new Smarty();
|
||||
// enable security
|
||||
@@ -118,13 +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;
|
||||
// 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);
|
||||
?>
|
||||
@@ -140,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.
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,12 +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)
|
||||
- [$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,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
|
||||
[`{insert}`](#language.function.insert.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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -44,10 +44,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
|
||||
@@ -59,7 +59,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');
|
||||
@@ -105,7 +105,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");
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
Constants {#smarty.constants}
|
||||
=========
|
||||
|
||||
SMARTY\_DIR {#constant.smarty.dir}
|
||||
===========
|
||||
|
||||
This is the **full system path** to the location of the Smarty class
|
||||
files. If this is not defined in your script, then Smarty will attempt
|
||||
to determine the appropriate value automatically. If defined, the path
|
||||
**must end with a trailing slash/**.
|
||||
|
||||
|
||||
<?php
|
||||
// set path to Smarty directory *nix style
|
||||
define('SMARTY_DIR', '/usr/local/lib/php/Smarty-v.e.r/libs/');
|
||||
|
||||
// path to Smarty windows style
|
||||
define('SMARTY_DIR', 'c:/webroot/libs/Smarty-v.e.r/libs/');
|
||||
|
||||
// include the smarty class, note 'S' is upper case
|
||||
require_once(SMARTY_DIR . 'Smarty.class.php');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`$smarty.const`](../designers/language-variables/language-variables-smarty.md).
|
||||
@@ -1,111 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Autoloader
|
||||
*
|
||||
* @package Smarty
|
||||
*/
|
||||
|
||||
|
||||
if (!defined('SMARTY_HELPER_FUNCTIONS_LOADED')) {
|
||||
include __DIR__ . '/functions.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Autoloader
|
||||
*
|
||||
* @package Smarty
|
||||
* @author Uwe Tews
|
||||
* Usage:
|
||||
* require_once '...path/Autoloader.php';
|
||||
* Smarty_Autoloader::register();
|
||||
* or
|
||||
* include '...path/bootstrap.php';
|
||||
*
|
||||
* $smarty = new Smarty();
|
||||
*/
|
||||
class Smarty_Autoloader
|
||||
{
|
||||
/**
|
||||
* Filepath to Smarty root
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $SMARTY_DIR = null;
|
||||
|
||||
/**
|
||||
* Filepath to Smarty internal plugins
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $SMARTY_SYSPLUGINS_DIR = null;
|
||||
|
||||
/**
|
||||
* Array with Smarty core classes and their filename
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $rootClasses = array('smarty' => 'Smarty.class.php');
|
||||
|
||||
/**
|
||||
* Registers Smarty_Autoloader backward compatible to older installations.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not.
|
||||
*/
|
||||
public static function registerBC($prepend = false)
|
||||
{
|
||||
/**
|
||||
* register the class autoloader
|
||||
*/
|
||||
if (!defined('SMARTY_SPL_AUTOLOAD')) {
|
||||
define('SMARTY_SPL_AUTOLOAD', 0);
|
||||
}
|
||||
if (SMARTY_SPL_AUTOLOAD
|
||||
&& set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
|
||||
) {
|
||||
$registeredAutoLoadFunctions = spl_autoload_functions();
|
||||
if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {
|
||||
spl_autoload_register();
|
||||
}
|
||||
} else {
|
||||
self::register($prepend);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers Smarty_Autoloader as an SPL autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not.
|
||||
*/
|
||||
public static function register($prepend = false)
|
||||
{
|
||||
self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : __DIR__ . DIRECTORY_SEPARATOR;
|
||||
self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR :
|
||||
self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR;
|
||||
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles auto loading of classes.
|
||||
*
|
||||
* @param string $class A class name.
|
||||
*/
|
||||
public static function autoload($class)
|
||||
{
|
||||
if ($class[ 0 ] !== 'S' || strpos($class, 'Smarty') !== 0) {
|
||||
return;
|
||||
}
|
||||
$_class = smarty_strtolower_ascii($class);
|
||||
if (isset(self::$rootClasses[ $_class ])) {
|
||||
$file = self::$SMARTY_DIR . self::$rootClasses[ $_class ];
|
||||
if (is_file($file)) {
|
||||
include $file;
|
||||
}
|
||||
} else {
|
||||
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
|
||||
if (is_file($file)) {
|
||||
include $file;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user