diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00072c8c7..681c45acd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,6 @@ jobs: - ubuntu-latest php-version: - - "7.1" - "7.2" - "7.3" - "7.4" @@ -63,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@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 diff --git a/.gitignore b/.gitignore index cf81ad040..d0d6b422a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,8 @@ .idea/ -# Smarty -lexer/*.php -lexer/*.php.bak -lexer/*.out - /site -# Dev phpunit* .phpunit.result.cache vendor/* diff --git a/CHANGELOG.md b/CHANGELOG.md index 20c5b00ed..ddbae7a46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,63 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Added support for PHP8.2 +- Added a new way to extend Smarty functionality using `Smarty::addExtension()` or `Smarty::setExtensions()`. Please see the docs for more information. +- Custom tags can accept positional parameters, so you can write a block compiler that support this: `{trans "Jack" "dull boy"}All work and no play makes %s a %s.{/trans}` [#164](https://github.com/smarty-php/smarty/issues/164) +- Full support for ternary operator: `{$test ? $a : $b}` and `{$var ?: $value_if_falsy}` [#881](https://github.com/smarty-php/smarty/issues/881) +- Full support for null coalescing operator: `{$var ?? $value_if_null}` [#882](https://github.com/smarty-php/smarty/issues/882) + +### 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 reliably generated from sources (.y and .plex) using the make file +- Smarty now always runs in multibyte mode, using `symfony/polyfill-mbstring` if required. Please use the + multibyte extension for optimal performance. +- Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive [#480](https://github.com/smarty-php/smarty/issues/480) +- Generated ` +{/block} +``` + +mypage.tpl (grandchild) + +```smarty +{extends file='myproject.tpl'} +{block name=title}My Page Title{/block} +{block name=head} + + +{/block} +{block name=body}My HTML Page Body goes here{/block} +``` + + +To render the above, you would use: + +```php +display('mypage.tpl'); +``` + +The resulting output is: + +```html + + + My Page Title + + + + + My HTML Page Body goes here + + +``` + +> **Note** +> +> When [compile-check](./configuring.md#disabling-compile-check) is enabled, all files +> in the inheritance tree +> are checked for modifications upon each invocation. You may want to +> disable compile-check on production servers for this reason. + +> **Note** +> +> If you have a subtemplate which is included with +> [`{include}`](../designers/language-builtin-functions/language-function-include.md) and it contains +> [`{block}`](../designers/language-builtin-functions/language-function-block.md) areas it works only if the +> [`{include}`](../designers/language-builtin-functions/language-function-include.md) itself is called from within +> a surrounding [`{block}`](../designers/language-builtin-functions/language-function-block.md). In the final +> parent template you may need a dummy +> [`{block}`](../designers/language-builtin-functions/language-function-block.md) for it. + + +## Using append and prepend +The content of [`{block}`](../designers/language-builtin-functions/language-function-block.md) tags from child +and parent templates can be merged by the `append` or `prepend` +[`{block}`](../designers/language-builtin-functions/language-function-block.md) tag option flags and +`{$smarty.block.parent}` or `{$smarty.block.child}` placeholders. + +## Extends resource type +Instead of using [`{extends}`](../designers/language-builtin-functions/language-function-extends.md) tags in the +template files you can define the inheritance tree in your PHP script by +using the [`extends:` resource](resources.md#the-extends-resource) type. + +The code below will return same result as the example above. + +```php +display('extends:layout.tpl|myproject.tpl|mypage.tpl'); +``` diff --git a/docs/api/rendering.md b/docs/api/rendering.md new file mode 100644 index 000000000..a66b61269 --- /dev/null +++ b/docs/api/rendering.md @@ -0,0 +1,86 @@ +# Rendering templates + +## Fetching or rendering templates directly +As explained in [basics](basics.md), you can use `$smarty->fetch()` or `$smarty->display()` +to render a template directly. + +```php +display('homepage.tpl'); + +// or + +$output = $smarty->fetch('homepage.tpl'); +``` + +When you use `display()`, Smarty renders the template to the standard output stream. +`fetch()` returns the output instead of echoing it. + +The example above uses simple filenames to load the template. Smarty also supports +[loading templates from resources](resources.md). + +## Creating a template object +You can also create a template object which later can be prepared first, +and rendered later. This can be useful, for example if you plan to re-use several +templates. + +```php +createTemplate('index.tpl'); + +// assign a variable (available only to this template) +$tpl->assign('title', 'My Homepage!'); + +// display the template +$tpl->display(); +``` + +More on assigning variables in [using data in templates](variables/assigning.md). + + +## Testing if a template exists +You can use `templateExists()` to check whether a template exists before you attempt to use it. + +It accepts either a path to the template on the filesystem or a +resource string specifying the template. + +This example uses `$_GET['page']` to +[`{include}`](../designers/language-builtin-functions/language-function-include.md) a content template. If the +template does not exist then an error page is displayed instead. First, +the `page_container.tpl` + +```smarty + + + {$title|escape} + + + {* include middle content page *} + {include file=$content_template} + + +``` + +And the php script: + +```php +templateExists($mid_template)){ + $mid_template = 'page_not_found.tpl'; +} +$smarty->assign('content_template', $mid_template); + +$smarty->display('page_container.tpl'); +``` diff --git a/docs/api/resources.md b/docs/api/resources.md new file mode 100644 index 000000000..5ca52b12d --- /dev/null +++ b/docs/api/resources.md @@ -0,0 +1,322 @@ +# Template resources + +## The filesystem resource + +So far in our examples, we have used simple filenames or paths when loading a template. + +For example, to load a template file called `homepage.tpl`, from the filesystem, you could write: +```php +display('homepage.tpl'); +``` + +The filesystem is the default resource. Templates, however, may come +from a variety of sources. When you render a template, or +when you include a template from within another template, you supply a +resource type, followed by `:` and the appropriate path and template name. + +If a resource is not explicitly given, the default resource type is assumed. +The resource type for the filesystem is `file`, which means that the previous example +can be rewritten as follows: +```php +display('file:homepage.tpl'); +``` + +The file resource pulls templates source files from the directories +specified using `Smarty::setTemplateDir()` (see [Configuring Smarty](configuring.md)). + +`setTemplateDir` accepts a single path, but can also ben called with an array of paths. +In that case, the list of directories is traversed in the order they appear in the array. The +first template found is the one to process. + +### Templates from a specific directory + +Smarty 3.1 introduced the bracket-syntax for specifying an element from +`Smarty::setTemplateDir()`. This allows websites +employing multiple sets of templates better control over which template +to access. + +The bracket-syntax can be used as follows: +```php +setTemplateDir([ + './templates', // element: 0, index: 0 + './templates_2', // element: 1, index: 1 + '10' => 'templates_10', // element: 2, index: '10' + 'foo' => 'templates_foo', // element: 3, index: 'foo' +]); + +/* + assume the template structure + ./templates/foo.tpl + ./templates_2/foo.tpl + ./templates_2/bar.tpl + ./templates_10/foo.tpl + ./templates_10/bar.tpl + ./templates_foo/foo.tpl +*/ + +// regular access +$smarty->display('file:foo.tpl'); +// will load ./templates/foo.tpl + +// using numeric index +$smarty->display('file:[1]foo.tpl'); +// will load ./templates_2/foo.tpl + +// using numeric string index +$smarty->display('file:[10]foo.tpl'); +// will load ./templates_10/foo.tpl + +// using string index +$smarty->display('file:[foo]foo.tpl'); +// will load ./templates_foo/foo.tpl + +// using "unknown" numeric index (using element number) +$smarty->display('file:[2]foo.tpl'); +// will load ./templates_10/foo.tpl +``` + +And, from within a Smarty template: + +```smarty +{include file="file:foo.tpl"} +{* will load ./templates/foo.tpl *} + +{include file="file:[1]foo.tpl"} +{* will load ./templates_2/foo.tpl *} + +{include file="file:[foo]foo.tpl"} +{* will load ./templates_foo/foo.tpl *} +``` + +### Using absolute paths + +Templates outside the specified template directories +require the `file:` template resource type, followed by the absolute +path to the template (with leading slash). + +```php +display('file:/export/templates/index.tpl'); +$smarty->display('file:/path/to/my/templates/menu.tpl'); +```` + +And from within a Smarty template: +```smarty +{include file='file:/usr/local/share/templates/navigation.tpl'} +``` + +> **Note** +> +> With [`Security`](security.md) enabled, access to +> templates outside of the specified templates directories is +> not allowed unless you whitelist those directories. + +### Windows file paths +If you are running on Windows, file paths usually include a drive +letter (such as `C:`) at the beginning of the pathname. Be sure to use `file:` in +the path to avoid namespace conflicts and get the desired results. +```php +display('file:C:/export/templates/index.tpl'); +$smarty->display('file:F:/path/to/my/templates/menu.tpl'); +``` + +And from within Smarty template: +```smarty +{include file='file:D:/usr/local/share/templates/navigation.tpl'} +``` + +### Handling missing templates +If the file resource cannot find the requested template, it will check if there is +a default template handler to call. By default, there is none, and Smarty will return an error, +but you can register a default template handler calling `Smarty::registerDefaultTemplateHandler` +with any [callable](https://www.php.net/manual/en/language.types.callable.php). + +```php +registerDefaultTemplateHandler([$this, 'handleMissingTemplate']); + +// ... + +public function handleMissingTemplate($type, $name, &$content, &$modified, Smarty $smarty) { + if (/* ... */) { + // return corrected filepath + return "/tmp/some/foobar.tpl"; + } elseif (/* ... */) { + // return a template directly + $content = "the template source"; + $modified = time(); + return true; + } else { + // tell smarty that we failed + return false; + } +} + +``` + +## The string and eval resources + +Smarty can render templates from a string by using the `string:` or +`eval:` resource. + +- The `string:` resource behaves much the same as a template file. The + template source is compiled from a string and stores the compiled + template code for later reuse. Each unique template string will + create a new compiled template file. If your template strings are + accessed frequently, this is a good choice. If you have frequently + changing template strings (or strings with low reuse value), the + `eval:` resource may be a better choice, as it doesn\'t save + compiled templates to disk. + +- The `eval:` resource evaluates the template source every time a page + is rendered. This is a good choice for strings with low reuse value. + If the same string is accessed frequently, the `string:` resource + may be a better choice. + +> **Note** +> +> With a `string:` resource type, each unique string generates a +> compiled file. Smarty cannot detect a string that has changed, and +> therefore will generate a new compiled file for each unique string. It +> is important to choose the correct resource so that you do not fill +> your disk space with wasted compiled strings. + +```php +assign('foo', 'value'); +$template_string = 'display {$foo} here'; +$smarty->display('string:' . $template_string); // compiles for later reuse +$smarty->display('eval:' . $template_string); // compiles every time +``` +From within a Smarty template: +```smarty +{include file="string:$template_string"} {* compiles for later reuse *} +{include file="eval:$template_string"} {* compiles every time *} +``` + +Both `string:` and `eval:` resources may be encoded with +[`urlencode()`](https://www.php.net/urlencode) or +[`base64_encode()`](https://www.php.net/urlencode). This is not necessary +for the usual use of `string:` and `eval:`, but is required when using +either of them in conjunction with the [`extends resource`](#the-extends-resource). + +```php + assign('foo','value'); + $template_string_urlencode = urlencode('display {$foo} here'); + $template_string_base64 = base64_encode('display {$foo} here'); + $smarty->display('eval:urlencode:' . $template_string_urlencode); // will decode string using urldecode() + $smarty->display('eval:base64:' . $template_string_base64); // will decode string using base64_decode() +``` + +From within a Smarty template: +```smarty + {include file="string:urlencode:$template_string_urlencode"} {* will decode string using urldecode() *} + {include file="eval:base64:$template_string_base64"} {* will decode string using base64_decode() *} +``` + +## The extends resource + +The `extends:` resource is used to define child/parent relationships. For details see section of +[Template inheritance](inheritance.md). + +> **Note** +> +> Using the extends resource is usually not necessary. If you have a choice, it is normally more flexible and +> intuitive to handle inheritance chains from within the templates using the [{extends} tag](inheritance.md). + +When `string:` and `eval:` templates are used, make sure they are properly url or base64 encoded. + +The templates within an inheritance chain are not compiled separately. Only a single compiled template will be generated. +(If an `eval:` resource is found within an inheritance chain, its "don't save a compile file" property is superseded by +the `extends:` resource.) + +Example: +```php +display('extends:parent.tpl|child.tpl|grandchild.tpl'); + +// inheritance from multiple template sources +$smarty->display('extends:db:parent.tpl|file:child.tpl|grandchild.tpl|eval:{block name="fooBazVar_"}hello world{/block}'); +``` + +## The stream resource + +Smarty allow you to use [PHP streams](https://www.php.net/manual/en/function.stream-wrapper-register.php) +as a template resource. Smarty will first look for a registered template resource. If nothing is +found, it will check if a PHP stream is available. If a stream is available, Smarty will use it +to fetch the template. + +For example, +```php +display('myresource:bar.tpl'); +``` + +Or, from within a template: +```smarty + {include file="myresource:bar.tpl"} +``` + +## Adding your own resource type +You can create a class that extends `Smarty\Resource\CustomPlugin` to add your own resource type, +for example to load template from a database. + +For example: +```php +registerResource('helloworld', new HelloWorldResource()); +``` + +If a Resource's templates should not be run through the Smarty +compiler, the Custom Resource may extend `\Smarty\Resource\UncompiledPlugin`. +The Resource Handler must then implement the function +`renderUncompiled(\Smarty\Template $_template)`. `$_template` is +a reference to the current template and contains all assigned variables +which the implementor can access via +`$_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 +`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\RecompiledPlugin`. These Resources +are compiled every time they are accessed. This may be an expensive +overhead. See `src/Resource/StringEval.php` for an +example. + +## Changing the default resource type +The default resource type is `file`. If you want to change it, use `Smarty::setDefaultResourceType`. + +The following example will change the default resource type to `mysql`: +```php +setDefaultResourceType('mysql'); +``` diff --git a/docs/api/security.md b/docs/api/security.md new file mode 100644 index 000000000..07120afdb --- /dev/null +++ b/docs/api/security.md @@ -0,0 +1,119 @@ +# Security + +Security is good for situations when you have untrusted parties editing +the templates, and you want to reduce the risk of system +security compromises through the template language. + +The settings of the security policy are defined by overriding public properties of an +instance of the \Smarty\Security class. These are the possible settings: + +- `$secure_dir` is an array of template directories that are + considered secure. A directory configured using `$smarty->setTemplateDir()` is + 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 is used by + [`{fetch}`](../designers/language-custom-functions/language-function-fetch.md) and + [`{html_image}`](../designers/language-custom-functions/language-function-html-image.md). URIs passed to + these functions are reduced to `{$PROTOCOL}://{$HOSTNAME}` to allow + simple regular expressions (without having to deal with edge cases + like authentication-tokens). + + The expression `'#https?://.*smarty.net$#i'` would allow accessing + the following URIs: + + - `http://smarty.net/foo` + - `http://smarty.net/foo` + - `http://www.smarty.net/foo` + - `http://smarty.net/foo` + - `https://foo.bar.www.smarty.net/foo/bla?blubb=1` + + but deny access to these URIs: + + - `http://smarty.com/foo` (not matching top-level domain \"com\") + - `ftp://www.smarty.net/foo` (not matching protocol \"ftp\") + - `http://www.smarty.net.otherdomain.com/foo` (not matching end of + domain \"smarty.net\") + +- `$static_classes` is an array of classes that are considered + trusted. The default is an empty array which allows access to all + static classes. To disable access to all static classes set + $static_classes = null. + +- `$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 = [] ) will + allow all streams. The default is array('file'). + +- `$allowed_modifiers` is an array of (registered / autoloaded) + modifiers that should be accessible to the template. If this array + is non-empty, only the herein listed modifiers may be used. This is + a whitelist. + +- `$disabled_modifiers` is an array of (registered / autoloaded) + modifiers that may not be accessible to the template. + +- `$allowed_tags` is a boolean flag which controls if constants can + function-, block and filter plugins that should be accessible to the + template. If this array is non-empty, only the herein listed + modifiers may be used. This is a whitelist. + +- `$disabled_tags` is an array of (registered / autoloaded) function-, + block and filter plugins that may not be accessible to the template. + +- `$allow_constants` is a boolean flag which controls if constants can + be accessed by the template. The default is "true". + +- `$allow_super_globals` is a boolean flag which controls if the PHP + super globals can be accessed by the template. The default is + "true". + +If security is enabled, no private methods, functions or properties of +static classes or assigned objects can be accessed (beginning with +'_') by the template. + +To customize the security policy settings you can extend the +\Smarty\Security class or create an instance of it. + +```php +enableSecurity('My_Security_Policy'); +``` + +```php +allow_constants = false; + +$smarty->enableSecurity($my_security_policy); +``` + +```php +enableSecurity(); +``` + +> **Note** +> +> Most security policy settings are only checked when the template gets +> compiled. For that reason you should delete all cached and compiled +> template files when you change your security settings. diff --git a/docs/api/variables/assigning.md b/docs/api/variables/assigning.md new file mode 100644 index 000000000..3aa606b69 --- /dev/null +++ b/docs/api/variables/assigning.md @@ -0,0 +1,139 @@ +# Assigning variables + +Templates start to become really useful once you know how to use variables. + +## Basic assigning +Let's revisit the example from the [basics section](../basics.md). The following script assigns a value to +the 'companyName' variable and renders the template: + +```php +assign('companyName', 'AC & ME Corp.'); + +$smarty->display('footer.tpl'); +``` + +footer.tpl: +```smarty +Copyright {$companyName|escape} +``` + +Smarty will apply the [escape modifier](../designers/language-modifiers/language-modifier-escape.md) +to the value assigned to the variable +`companyName` and replace `{$companyName|escape}` with the result. + +```html +Copyright AC & ME Corp. +``` + +Using `$smarty->assign()` is the most common way of assigning data to templates, but there are several other methods. + +## Appending data to an existing variable +Using `append()`, you can add data to an existing variable, usually an array. + +If you append to a string value, it is converted to an array value and +then appended to. You can explicitly pass name/value pairs, or +associative arrays containing the name/value pairs. If you pass the +optional third parameter of TRUE, the value will be merged with the +current array instead of appended. + +Examples: + +```php +append('foo', 'Fred'); +// After this line, foo will now be seen as an array in the template +$smarty->append('foo', 'Albert'); + +$array = [1 => 'one', 2 => 'two']; +$smarty->append('X', $array); +$array2 = [3 => 'three', 4 => 'four']; +// The following line will add a second element to the X array +$smarty->append('X', $array2); + +// passing an associative array +$smarty->append(['city' => 'Lincoln', 'state' => 'Nebraska']); +``` + +## Assigning to template objects +When you use a template objects, as explained in [rendering a template](../rendering.md#creating-a-template-object), +you can assign data to the template objects directly instead of assigning it to Smarty. This way, you can use different +sets of data for different templates. + +For example: +```php +createTemplate('blue.tpl'); +$tplBlue->assign('name', 'The one'); +$tplBlue->display(); + +$tplRed = $smarty->createTemplate('red.tpl'); +$tplRed->assign('name', 'Neo'); +$tplRed->display(); +``` + +## Using data objects +For more complex use cases, Smarty supports the concept of data objects. +Data objects are containers to hold data. Data objects can be attached to templates when creating them. +This allows for fine-grained re-use of data. + +For example: +```php +createData(); + +// assign variable to the data object +$data->assign('name', 'Neo'); + +// create template object which will use variables from the data object +$tpl = $smarty->createTemplate('index.tpl', $data); + +// display the template +$tpl->display(); +``` + +## Clearing assigned data +When re-using templates, you may need to clear data assigned in a previous run. Use `clearAllAssign()` to +clear the values of all assigned variables on data objects, template objects or the Smarty object. + +Examples: +```php +assign('Name', 'Fred'); +// ... +$smarty->clearAllAssign(); + +// using a data object +$data = $smarty->createData(); +$data->assign('name', 'Neo'); +// ... +$data->clearAllAssign(); + +// using a template +$tplBlue = $smarty->createTemplate('blue.tpl'); +$tplBlue->assign('name', 'The one'); +// ... +$tplBlue->clearAllAssign(); +``` + +Note that there it's only useful to clear assigned data if you: + +1. repeatedly re-use templates, and +2. the variables used may change on each repetition + +If your script simply runs once and then ends, or you always assign the same variables, clearing assigned data +is of no use. \ No newline at end of file diff --git a/docs/api/variables/config-files.md b/docs/api/variables/config-files.md new file mode 100644 index 000000000..181733ea2 --- /dev/null +++ b/docs/api/variables/config-files.md @@ -0,0 +1,89 @@ +# Loading data from config files + +Instead of [assigning data to templates from PHP](assigning.md), you can also +use a config file. + +## Example config file +Config files are best suited to manage template settings +from one file. One example is a multi-language application. +Instead of writing multiple templates to support different languages, +you can write a single template file and load your language dependent strings +from config files. + +Example `lang.en.ini`: +```ini +# global variables +pageTitle = "Main Menu" + +[Customer] +pageTitle = "Customer Info" + +[Login] +pageTitle = "Login" +focus = "username" +Intro = """This is a value that spans more + than one line. you must enclose + it in triple quotes.""" + +``` + +Values of [config file variables](./language-variables/language-config-variables.md) can be in +quotes, but not necessary. You can use either single or double quotes. +If you have a value that spans more than one line, enclose the entire +value with triple quotes \("""\). You can put comments into config +files by any syntax that is not a valid config file syntax. We recommend +using a `#` (hash) at the beginning of the line. + +The example config file above has two sections. Section names are +enclosed in \[brackets\]. Section names can be arbitrary strings not +containing `[` or `]` symbols. The variable at the top is a global +variable. Global variables are always +loaded from the config file. If a particular section is loaded, then the +global variables and the variables from that section are also loaded. If +a variable exists both as a global and in a section, the section +variable is used. + +## Loading a config file + +Config files are loaded into templates with the built-in template +function [`{config_load}`](../../designers/language-builtin-functions/language-function-config-load.md) or by calling +`configLoad()` from PHP: + +```php +configLoad('lang.en.ini'); +``` + +Load a specific section with: + +```php +configLoad('lang.en.ini', 'Customer'); +``` + +Note that the global section will always be loaded. + +## Retrieving config variables in PHP + + +## Loading from a resource +Config files (or resources) are loaded by the same resource facilities +as templates. That means that a config file can also be loaded from a db. See [resources](../resources.md) +for more information. + +## Config overwrite +If you name two variables the same within a section, +the last one will be used unless you call: +```php +setConfigOverwrite(false); +``` +When config overwrite is disabled, Smarty will create arrays of config file variables when it encounters +multiple entries with the same name. + +See also [`{config_load}`](./language-builtin-functions/language-function-config-load.md), +[`$config_overwrite`](../programmers/api-variables/variable-config-overwrite.md), +[`$default_config_handler_func`](../programmers/api-variables/variable-default-config-handler-func.md), +[`getConfigVars()`](../programmers/api-functions/api-get-config-vars.md), +[`clearConfig()`](../programmers/api-functions/api-clear-config.md) and +[`configLoad()`](../programmers/api-functions/api-config-load.md) diff --git a/docs/api/variables/objects.md b/docs/api/variables/objects.md new file mode 100644 index 000000000..1d0d7e335 --- /dev/null +++ b/docs/api/variables/objects.md @@ -0,0 +1,106 @@ +# Objects + +Smarty allows access to PHP [objects](https://www.php.net/object) through +the templates. + +> **Note** +> +> When you assign/register objects to templates, be sure that all +> properties and methods accessed from the template are for presentation +> purposes only. It is very easy to inject application logic through +> objects, and this leads to poor designs that are difficult to manage. +> See the Best Practices section of the Smarty website. + +There are two ways to access them. + +## Assign the object +You can assign objects to a template and access them much like any other assigned variable. + +Example: +```php +assign('myobj', new My_Object()); + +$smarty->display('index.tpl'); +``` + +And here's how to access your object in `index.tpl`: + +```smarty +{$myobj->meth1('foo',$bar)} +``` + + + +## Register the object +Registerd objects use a different template syntax. Also, a registered object +can be restricted to certain methods or +properties. However, **a registered object cannot be looped over or +assigned in arrays of objects**, etc. + +If security is enabled, no private methods or functions can be accessed +(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 +listing them in an array as the third registration parameter. + +By default, parameters passed to objects through the templates are +passed the same way [custom functions](../../designers/language-custom-functions/index.md) get +them. An associative array is passed as the first parameter, and the +smarty object as the second. If you want the parameters passed one at a +time for each argument like traditional object parameter passing, set +the fourth registration parameter to FALSE. + +The optional fifth parameter has only effect with `format` being TRUE +and contains a list of methods that should be treated as blocks. That +means these methods have a closing tag in the template +(`{foobar->meth2}...{/foobar->meth2}`) and the parameters to the methods +have the same synopsis as the parameters for +[`block tags`](../extending/block-tags.md): They get the four +parameters `$params`, `$content`, `$smarty` and `&$repeat` and they also +behave like block tags. + +```php +registerObject('foobar', $myobj); + +// if we want to restrict access to certain methods or properties, list them +$smarty->registerObject('foobar', $myobj, array('meth1','meth2','prop1')); + +// if you want to use the traditional object parameter format, pass a boolean of false +$smarty->registerObject('foobar', $myobj, null, false); + +$smarty->display('index.tpl'); +``` + +And here's how to access your objects in `index.tpl`: + +```smarty +{* access our registered object *} +{foobar->meth1 p1='foo' p2=$bar} + +{* you can also assign the output *} +{foobar->meth1 p1='foo' p2=$bar assign='output'} +the output was {$output} +``` diff --git a/docs/api/variables/static-class-methods.md b/docs/api/variables/static-class-methods.md new file mode 100644 index 000000000..fd3fea4c8 --- /dev/null +++ b/docs/api/variables/static-class-methods.md @@ -0,0 +1,39 @@ +# Static Classes + +You can directly access static classes. The syntax is roughly the same as in +PHP. + +> **Note** +> +> Direct access to PHP classes is not recommended. This ties the +> underlying application code structure directly to the presentation, +> and also complicates template syntax. It is recommended to register +> plugins which insulate templates from PHP classes/objects. Use at your +> own discretion. + +## Examples + +**class constant BAR** +```smarty +{assign var=foo value=myclass::BAR} +``` + +**method result** +```smarty +{assign var=foo value=myclass::method()} +``` + +**method chaining** +```smarty +{assign var=foo value=myclass::method1()->method2} +``` + +**property bar of class myclass** +```smarty +{assign var=foo value=myclass::$bar} +``` + +**using Smarty variable bar as class name** +```smarty +{assign var=foo value=$bar::method} +``` diff --git a/docs/api/variables/streams.md b/docs/api/variables/streams.md new file mode 100644 index 000000000..93d5c15e1 --- /dev/null +++ b/docs/api/variables/streams.md @@ -0,0 +1,13 @@ +# Streams + +You can also use streams to call variables. *{$foo:bar}* will use the +*foo://bar* stream to get the template variable. + +Using a PHP stream for a template variable resource from within a +template. + +```smarty +{$foo:bar} +``` + +See also [`Template Resources`](../resources.md) diff --git a/docs/appendixes/tips.md b/docs/appendixes/tips.md index 3c6e6b96f..e4e38d4be 100644 --- a/docs/appendixes/tips.md +++ b/docs/appendixes/tips.md @@ -209,8 +209,7 @@ fetching the data up front? You can do this by writing a custom plugin for fetching the content and assigning it to a template variable. -`function.load_ticker.php` - drop file in -[`$plugins directory`](../programmers/api-variables/variable-plugins-dir.md) +`function.load_ticker.php` ```php diff --git a/docs/designers/chapter-debugging-console.md b/docs/designers/chapter-debugging-console.md index 6704fce2f..50acd1950 100644 --- a/docs/designers/chapter-debugging-console.md +++ b/docs/designers/chapter-debugging-console.md @@ -10,8 +10,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. diff --git a/docs/designers/language-basic-syntax/index.md b/docs/designers/language-basic-syntax/index.md index c0a12a9be..05c0ba699 100644 --- a/docs/designers/language-basic-syntax/index.md +++ b/docs/designers/language-basic-syntax/index.md @@ -26,8 +26,8 @@ The basis components of the Smarty syntax are: - [Comments](language-syntax-comments.md) - [Variables](language-syntax-variables.md) +- [Operators](language-syntax-operators.md) - [Functions](language-syntax-functions.md) - [Attributes](language-syntax-attributes.md) - [Quotes](language-syntax-quotes.md) -- [Math](language-math.md) - [Escaping](language-escaping.md) diff --git a/docs/designers/language-basic-syntax/language-escaping.md b/docs/designers/language-basic-syntax/language-escaping.md index 4c75e09e6..58e75d581 100644 --- a/docs/designers/language-basic-syntax/language-escaping.md +++ b/docs/designers/language-basic-syntax/language-escaping.md @@ -69,7 +69,7 @@ Where the template is: ```smarty Welcome to Smarty - @@ -51,7 +51,7 @@ spiders to lift email addresses off of a site. me@example.com {mailto address="me@example.com" encode="javascript_charcode"} - ``` diff --git a/docs/designers/language-modifiers/index.md b/docs/designers/language-modifiers/index.md index c9aeef887..a384c95c2 100644 --- a/docs/designers/language-modifiers/index.md +++ b/docs/designers/language-modifiers/index.md @@ -69,7 +69,7 @@ These parameters follow the modifier name and are separated by a `:` -``` +``` - Modifiers can be applied to any type of variables, including arrays and objects. @@ -96,26 +96,9 @@ These parameters follow the modifier name and are separated by a `:` > gives 9. To get the old result use parentheses like > `{(8+2)|count_characters}`. -- Modifiers are autoloaded from the - [`$plugins_dir`](../../programmers/api-variables/variable-plugins-dir.md) or can be registered - explicitly with the [`registerPlugin()`](../../programmers/api-functions/api-register-plugin.md) - function. The later is useful for sharing a function between php - scripts and smarty templates. - -- All php-functions can be used as modifiers implicitly, as - demonstrated in the example above. However, using php-functions as - modifiers has two little pitfalls: - - - First - sometimes the order of the function-parameters is not - the desirable one. Formatting `$foo` with - `{"%2.f"|sprintf:$foo}` actually works, but asks for the more - intuitive, like `{$foo|string_format:"%2.f"}` that is provided - by the Smarty distribution. - - - 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 security policy. See the - [Security](../../programmers/advanced-features/advanced-features-security.md) section for details. +- Custom modifiers can be registered + with the [`registerPlugin()`](../../programmers/api-functions/api-register-plugin.md) + function. See also [`registerPlugin()`](../../programmers/api-functions/api-register-plugin.md), [combining modifiers](../language-combining-modifiers.md). and [extending smarty with diff --git a/docs/designers/language-modifiers/language-modifier-from-charset.md b/docs/designers/language-modifiers/language-modifier-from-charset.md index bf4b4769e..25c4d2d9e 100644 --- a/docs/designers/language-modifiers/language-modifier-from-charset.md +++ b/docs/designers/language-modifiers/language-modifier-from-charset.md @@ -16,5 +16,5 @@ modifier](language-modifier-to-charset.md). > modifier should only be used in cases where the application cannot > anticipate that a certain string is required in another encoding. -See also [Charset Encoding](../../programmers/charset.md), [to_charset +See also [Configuring Smarty](../../api/configuring.md), [to_charset modifier](language-modifier-to-charset.md). diff --git a/docs/designers/language-modifiers/language-modifier-to-charset.md b/docs/designers/language-modifiers/language-modifier-to-charset.md index c0b003842..aa8cfd53f 100644 --- a/docs/designers/language-modifiers/language-modifier-to-charset.md +++ b/docs/designers/language-modifiers/language-modifier-to-charset.md @@ -16,5 +16,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 Encoding](../../programmers/charset.md), [from_charset +See also [Configuring Smarty](../../api/configuring.md), [from_charset modifier](language-modifier-from-charset.md). diff --git a/docs/designers/language-variables/language-assigned-variables.md b/docs/designers/language-variables/language-assigned-variables.md index bd356a2b0..a358008f1 100644 --- a/docs/designers/language-variables/language-assigned-variables.md +++ b/docs/designers/language-variables/language-assigned-variables.md @@ -7,7 +7,7 @@ Variables assigned from PHP are referenced by preceding them with a dollar ```php assign('firstname', 'Doug'); diff --git a/docs/designers/language-variables/language-variables-smarty.md b/docs/designers/language-variables/language-variables-smarty.md index da543fb62..b6dff73a2 100644 --- a/docs/designers/language-variables/language-variables-smarty.md +++ b/docs/designers/language-variables/language-variables-smarty.md @@ -66,8 +66,7 @@ difference. ## {$smarty.const} -You can access PHP constant values directly. See also [smarty -constants](../../programmers/smarty-constants.md). +You can access PHP constant values directly. ```php setTemplateDir('/some/template/dir'); $smarty->setConfigDir('/some/config/dir'); @@ -70,6 +69,8 @@ You can verify if your system has the correct access rights for these directories with [`testInstall()`](./programmers/api-functions/api-test-install.md): ```php +setTemplateDir('/some/template/dir'); $smarty->setConfigDir('/some/config/dir'); @@ -103,6 +104,7 @@ Now lets edit our php file. We'll create an instance of Smarty, require 'vendor/autoload.php'; +use Smarty\Smarty; $smarty = new Smarty(); $smarty->setTemplateDir('/web/www.example.com/guestbook/templates/'); @@ -140,7 +142,9 @@ the same vars, etc., we can do that in one place. ```php {$title|escape}

@@ -20,31 +20,11 @@ and 480 for $height, the result is:

``` -## Introduction +## Getting Started +- [Getting Started](./getting-started.md) - [Philosophy](./philosophy.md) - or "Why do I need a template engine?" - [Features](./features.md) - or "Why do I want Smarty?" -- [Getting Started](./getting-started.md) - -## Smarty for template designers -- [Basic Syntax](designers/language-basic-syntax/index.md) -- [Variables](designers/language-variables/index.md) -- [Variable Modifiers](designers/language-modifiers/index.md) -- [Combining Modifiers](./designers/language-combining-modifiers.md) -- [Built-in Functions](designers/language-builtin-functions/index.md) -- [Custom Functions](designers/language-custom-functions/index.md) -- [Config Files](./designers/config-files.md) -- [Debugging Console](./designers/chapter-debugging-console.md) - -## 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) -- [Resources](./programmers/resources.md) -- [Advanced Features](./programmers/advanced-features.md) -- [Extending Smarty With Plugins](./programmers/plugins.md) -## Other +## Help - [Some random tips & tricks](./appendixes/tips.md) - [Troubleshooting](./appendixes/troubleshooting.md) diff --git a/docs/philosophy.md b/docs/philosophy.md index 34555c288..41bcfc8b2 100644 --- a/docs/philosophy.md +++ b/docs/philosophy.md @@ -8,7 +8,7 @@ presentation. This is best described in a situation where the application programmer and the template designer play different roles, or in most cases are not the same person. -For example, let\'s say you are creating a web page that is displaying a +For example, let's say you are creating a web page that is displaying a newspaper article. - The article `$headline`, `$tagline`, `$author` and `$body` are diff --git a/docs/programmers/advanced-features.md b/docs/programmers/advanced-features.md deleted file mode 100644 index 60d4416b5..000000000 --- a/docs/programmers/advanced-features.md +++ /dev/null @@ -1,14 +0,0 @@ -Advanced Features {#advanced.features} -================= - -## Table of contents - -- [Security](./advanced-features/advanced-features-security.md) -- [Changing settings by template](./advanced-features/advanced-features-template-settings.md) -- [Template Inheritance](./advanced-features/advanced-features-template-inheritance.md) -- [Streams](./advanced-features/advanced-features-streams.md) -- [Objects](./advanced-features/advanced-features-objects.md) -- [Static Classes](./advanced-features/advanced-features-static-classes.md) -- [Prefilters](./advanced-features/advanced-features-prefilters.md) -- [Postfilters](./advanced-features/advanced-features-postfilters.md) -- [Output Filters](./advanced-features/advanced-features-outputfilters.md) diff --git a/docs/programmers/advanced-features/advanced-features-objects.md b/docs/programmers/advanced-features/advanced-features-objects.md deleted file mode 100644 index b681945e1..000000000 --- a/docs/programmers/advanced-features/advanced-features-objects.md +++ /dev/null @@ -1,99 +0,0 @@ -Objects {#advanced.features.objects} -======= - -Smarty allows access to PHP [objects](https://www.php.net/object) through -the templates. - -> **Note** -> -> When you assign/register objects to templates, be sure that all -> properties and methods accessed from the template are for presentation -> purposes only. It is very easy to inject application logic through -> objects, and this leads to poor designs that are difficult to manage. -> See the Best Practices section of the Smarty website. - -There are two ways to access them. - -- One way is to [register objects](#api.register.object) to the - template, then use access them via syntax similar to [custom - functions](#language.custom.functions). - -- The other way is to [`assign()`](#api.assign) objects to the - templates and access them much like any other assigned variable. - -The first method has a much nicer template syntax. It is also more -secure, as a registered object can be restricted to certain methods or -properties. However, **a registered object cannot be looped over or -assigned in arrays of objects**, etc. The method you choose will be -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 -(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 -listing them in an array as the third registration parameter. - -By default, parameters passed to objects through the templates are -passed the same way [custom functions](#language.custom.functions) get -them. An associative array is passed as the first parameter, and the -smarty object as the second. If you want the parameters passed one at a -time for each argument like traditional object parameter passing, set -the fourth registration parameter to FALSE. - -The optional fifth parameter has only effect with `format` being TRUE -and contains a list of methods that should be treated as blocks. That -means these methods have a closing tag in the template -(`{foobar->meth2}...{/foobar->meth2}`) and the parameters to the methods -have the same synopsis as the parameters for -[`block-function-plugins`](#plugins.block.functions): They get the four -parameters `$params`, `$content`, `$smarty` and `&$repeat` and they also -behave like block-function-plugins. - - - registerObject('foobar',$myobj); - - // if we want to restrict access to certain methods or properties, list them - $smarty->registerObject('foobar',$myobj,array('meth1','meth2','prop1')); - - // if you want to use the traditional object parameter format, pass a boolean of false - $smarty->registerObject('foobar',$myobj,null,false); - - // We can also assign objects. assign_by_ref when possible. - $smarty->assign_by_ref('myobj', $myobj); - - $smarty->display('index.tpl'); - ?> - - - -And here\'s how to access your objects in `index.tpl`: - - - {* access our registered object *} - {foobar->meth1 p1='foo' p2=$bar} - - {* you can also assign the output *} - {foobar->meth1 p1='foo' p2=$bar assign='output'} - the output was {$output} - - {* access our assigned object *} - {$myobj->meth1('foo',$bar)} - - - -See also [`registerObject()`](#api.register.object) and -[`assign()`](#api.assign). diff --git a/docs/programmers/advanced-features/advanced-features-outputfilters.md b/docs/programmers/advanced-features/advanced-features-outputfilters.md deleted file mode 100644 index 393d7da23..000000000 --- a/docs/programmers/advanced-features/advanced-features-outputfilters.md +++ /dev/null @@ -1,43 +0,0 @@ -Output Filters {#advanced.features.outputfilters} -============== - -When the template is invoked via [`display()`](#api.display) or -[`fetch()`](#api.fetch), its output can be sent through one or more -output filters. This differs from -[`postfilters`](#advanced.features.postfilters) because postfilters -operate on compiled templates before they are saved to the disk, whereas -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 -pass the template output as the first argument, and expect the function -to return the result of the processing. - - - registerFilter("output","protect_email"); - $smarty->display("index.tpl'); - - // now any occurrence of an email address in the template output will have - // a simple protection against spambots - ?> - - - -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). diff --git a/docs/programmers/advanced-features/advanced-features-postfilters.md b/docs/programmers/advanced-features/advanced-features-postfilters.md deleted file mode 100644 index d3bad546a..000000000 --- a/docs/programmers/advanced-features/advanced-features-postfilters.md +++ /dev/null @@ -1,40 +0,0 @@ -Postfilters {#advanced.features.postfilters} -=========== - -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 -pass the compiled template code as the first argument, and expect the -function to return the result of the processing. - - - \n\"; ?>\n".$tpl_source; - } - - // register the postfilter - $smarty->registerFilter('post','add_header_comment'); - $smarty->display('index.tpl'); - ?> - - - -The postfilter above will make the compiled Smarty template `index.tpl` -look like: - - - - {* rest of template content... *} - - - -See also [`registerFilter()`](#api.register.filter), -[prefilters](#advanced.features.prefilters), -[outputfilters](#advanced.features.outputfilters), and -[`loadFilter()`](#api.load.filter). diff --git a/docs/programmers/advanced-features/advanced-features-prefilters.md b/docs/programmers/advanced-features/advanced-features-prefilters.md deleted file mode 100644 index 76229e633..000000000 --- a/docs/programmers/advanced-features/advanced-features-prefilters.md +++ /dev/null @@ -1,36 +0,0 @@ -Prefilters {#advanced.features.prefilters} -========== - -Template prefilters are PHP functions that your templates are ran -through *before they are compiled*. This is good for preprocessing your -templates to remove unwanted comments, keeping an eye on what people are -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. - -Smarty will pass the template source code as the first argument, and -expect the function to return the resulting template source code. - -This will remove all the html comments in the template source. - - - /U",'',$tpl_source); - } - - // register the prefilter - $smarty->registerFilter('pre','remove_dw_comments'); - $smarty->display('index.tpl'); - ?> - - - -See also [`registerFilter()`](#api.register.filter), -[postfilters](#advanced.features.postfilters) and -[`loadFilter()`](#api.load.filter). diff --git a/docs/programmers/advanced-features/advanced-features-security.md b/docs/programmers/advanced-features/advanced-features-security.md deleted file mode 100644 index 730915f14..000000000 --- a/docs/programmers/advanced-features/advanced-features-security.md +++ /dev/null @@ -1,144 +0,0 @@ -Security {#advanced.features.security} -======== - -Security is good for situations when you have untrusted parties editing -the templates e.g. via ftp, and you want to reduce the risk of system -security compromises through the template language. - -The settings of the security policy are defined by properties of an -instance of the Smarty\_Security class. These are the possible settings: - -- `$secure_dir` is an array of template directories that are - considered secure. [`$template_dir`](#variable.template.dir) - considered 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 - are considered trusted. This security directive used by - [`{fetch}`](#language.function.fetch) and - [`{html_image}`](#language.function.html.image). URIs passed to - these functions are reduced to `{$PROTOCOL}://{$HOSTNAME}` to allow - simple regular expressions (without having to deal with edge cases - like authentication-tokens). - - The expression `'#https?://.*smarty.net$#i'` would allow accessing - the following URIs: - - - `http://smarty.net/foo` - - - `http://smarty.net/foo` - - - `http://www.smarty.net/foo` - - - `http://smarty.net/foo` - - - `https://foo.bar.www.smarty.net/foo/bla?blubb=1` - - but deny access to these URIs: - - - `http://smarty.com/foo` (not matching top-level domain \"com\") - - - `ftp://www.smarty.net/foo` (not matching protocol \"ftp\") - - - `http://www.smarty.net.otherdomain.com/foo` (not matching end of - domain \"smarty.net\") - -- `$static_classes` is an array of classes that are considered - trusted. The default is an empty array which allows access to all - 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 - allow all streams. The default is array(\'file\'). - -- `$allowed_modifiers` is an array of (registered / autoloaded) - modifiers that should be accessible to the template. If this array - is non-empty, only the herein listed modifiers may be used. This is - a whitelist. - -- `$disabled_modifiers` is an array of (registered / autoloaded) - modifiers that may not be accessible to the template. - -- `$allowed_tags` is a boolean flag which controls if constants can - function-, block and filter plugins that should be accessible to the - template. If this array is non-empty, only the herein listed - modifiers may be used. This is a whitelist. - -- `$disabled_tags` is an array of (registered / autoloaded) function-, - block and filter plugins that may not be accessible to the template. - -- `$allow_constants` is a boolean flag which controls if constants can - be accessed by the template. The default is \"true\". - -- `$allow_super_globals` is a boolean flag which controls if the PHP - super globals can be accessed by the template. The default is - \"true\". - -If security is enabled, no private methods, functions or properties of -static classes or assigned objects can be accessed (beginning with -\'\_\') by the template. - -To customize the security policy settings you can extend the -Smarty\_Security class or create an instance of it. - - - enableSecurity('My_Security_Policy'); - ?> - - - php_functions = null; - // allow everthing as modifier - $my_security_policy->php_modifiers = array(); - // enable security - $smarty->enableSecurity($my_security_policy); - ?> - - - enableSecurity(); - ?> - -> **Note** -> -> Most security policy settings are only checked when the template gets -> compiled. For that reason you should delete all cached and compiled -> template files when you change your security settings. diff --git a/docs/programmers/advanced-features/advanced-features-static-classes.md b/docs/programmers/advanced-features/advanced-features-static-classes.md deleted file mode 100644 index 8ef79113c..000000000 --- a/docs/programmers/advanced-features/advanced-features-static-classes.md +++ /dev/null @@ -1,27 +0,0 @@ -Static Classes {#advanced.features.static.classes} -============== - -You can directly access static classes. The syntax is the same as in -PHP. - -> **Note** -> -> Direct access to PHP classes is not recommended. This ties the -> underlying application code structure directly to the presentation, -> and also complicates template syntax. It is recommended to register -> plugins which insulate templates from PHP classes/objects. Use at your -> own discretion. See the Best Practices section of the Smarty website. - - - {assign var=foo value=myclass::BAR} <--- class constant BAR - - {assign var=foo value=myclass::method()} <--- method result - - {assign var=foo value=myclass::method1()->method2} <--- method chaining - - {assign var=foo value=myclass::$bar} <--- property bar of class myclass - - {assign var=foo value=$bar::method} <--- using Smarty variable bar as class name - - - diff --git a/docs/programmers/advanced-features/advanced-features-streams.md b/docs/programmers/advanced-features/advanced-features-streams.md deleted file mode 100644 index d6f7a0de5..000000000 --- a/docs/programmers/advanced-features/advanced-features-streams.md +++ /dev/null @@ -1,15 +0,0 @@ -Streams {#advanced.features.streams} -======= - -You can also use streams to call variables. *{\$foo:bar}* will use the -*foo://bar* stream to get the template variable. - -Using a PHP stream for a template variable resource from within a -template. - - - {$foo:bar} - - - -See also [`Template Resources`](#resources) diff --git a/docs/programmers/advanced-features/advanced-features-template-inheritance.md b/docs/programmers/advanced-features/advanced-features-template-inheritance.md deleted file mode 100644 index ce47310ca..000000000 --- a/docs/programmers/advanced-features/advanced-features-template-inheritance.md +++ /dev/null @@ -1,128 +0,0 @@ -Template Inheritance {#advanced.features.template.inheritance} -==================== - -Inheritance brings the concept of Object Oriented Programming to -templates, allowing you to define one (or more) base templates that can -be extended by child templates. Extending means that the child template -can override all or some of the parent named block areas. - -- The inheritance tree can be as deep as you want, meaning you can - extend a file that extends another one that extends another one and - so on. - -- The child templates can not define any content besides what\'s - inside [`{block}`](#language.function.block) tags they override. - Anything outside of [`{block}`](#language.function.block) tags will - be removed. - -- The content of [`{block}`](#language.function.block) tags from child - and parent templates can be merged by the `append` or `prepend` - [`{block}`](#language.function.block) tag option flags and - `{$smarty.block.parent}` or `{$smarty.block.child}` placeholders. - -- Template inheritance is a compile time process which creates a - single compiled template file. Compared to corresponding solutions - based on subtemplates included with the - [`{include}`](#language.function.include) tag it does have much - better performance when rendering. - -- The child template extends its parent defined with the - [`{extends}`](#language.function.extends) tag, which must be the - first line in the child template. Instead of using the - [`{extends}`](#language.function.extends) tags in the template files - 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 flexibility. - -> **Note** -> -> When `$compile_check` is enabled, all files in the inheritance tree -> are checked for modifications upon each invocation. You may want to -> disable `$compile_check` on production servers for this reason. - -> **Note** -> -> If you have a subtemplate which is included with -> [`{include}`](#language.function.include) and it contains -> [`{block}`](#language.function.block) areas it works only if the -> [`{include}`](#language.function.include) itself is called from within -> a surrounding [`{block}`](#language.function.block). In the final -> parent template you may need a dummy -> [`{block}`](#language.function.block) for it. - -layout.tpl (parent) - - - - - {block name=title}Default Page Title{/block} - {block name=head}{/block} - - - {block name=body}{/block} - - - - - -myproject.tpl (child) - - - {extends file='layout.tpl'} - {block name=head} - - - {/block} - - - - -mypage.tpl (grandchild) - - - {extends file='myproject.tpl'} - {block name=title}My Page Title{/block} - {block name=head} - - - {/block} - {block name=body}My HTML Page Body goes here{/block} - - - -To render the above use - - - $smarty->display('mypage.tpl'); - -The resulting output is - - - - - My Page Title - - - - - My HTML Page Body goes here - - - -Instead of using [`{extends}`](#language.function.extends) tags in the -template files you can define the inheritance tree in your PHP script by -using the [`extends:` resource](#resources.extends) type. - -The code below will return same result as the example above. - - - display('extends:layout.tpl|myproject.tpl|mypage.tpl'); - ?> - - - -See also [`{block}`](#language.function.block), -[`{extends}`](#language.function.extends) and [`extends:` -resource](#resources.extends) diff --git a/docs/programmers/advanced-features/advanced-features-template-settings.md b/docs/programmers/advanced-features/advanced-features-template-settings.md deleted file mode 100644 index b06430ff0..000000000 --- a/docs/programmers/advanced-features/advanced-features-template-settings.md +++ /dev/null @@ -1,32 +0,0 @@ -Changing settings by template {#advanced.features.template.settings} -============================= - -Normally you configure the Smarty settings by modifying the -[`Smarty class variables`](#api.variables). Furthermore you can register -plugins, filters etc. with [`Smarty functions`](#api.functions). -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 individual template objects. Modification done to a template -object will apply only for that template and its included subtemplates. - - - createTemplate('index.tpl); - $tpl->cache_lifetime = 600; - //or - $tpl->setCacheLifetime(600); - $smarty->display($tpl); - ?> - - - - - createTemplate('index.tpl); - $tpl->registerPlugin('modifier','mymodifier'); - $smarty->display($tpl); - ?> - - diff --git a/docs/programmers/api-functions.md b/docs/programmers/api-functions.md deleted file mode 100644 index 6f120fa9a..000000000 --- a/docs/programmers/api-functions.md +++ /dev/null @@ -1,64 +0,0 @@ -Smarty Class Methods {#api.functions} -==================== - -## Table of contents - -- [addConfigDir()](./api-functions/api-add-config-dir.md) — add a directory to the list of directories where config files are stored -- [addPluginsDir()](./api-functions/api-add-plugins-dir.md) — add a directory to the list of directories where plugins are stored -- [addTemplateDir()](./api-functions/api-add-template-dir.md) — add a directory to the list of directories where templates are stored -- [append()](./api-functions/api-append.md) — append an element to an assigned array -- [appendByRef()](./api-functions/api-append-by-ref.md) — append values by reference -- [assign()](./api-functions/api-assign.md) — assign variables/objects to the templates -- [assignByRef()](./api-functions/api-assign-by-ref.md) — assign values by reference -- [clearAllAssign()](./api-functions/api-clear-all-assign.md) — clears the values of all assigned variables -- [clearAllCache()](./api-functions/api-clear-all-cache.md) — clears the entire template cache -- [clearAssign()](./api-functions/api-clear-assign.md) — clears the value of an assigned variable -- [clearCache()](./api-functions/api-clear-cache.md) — clears the cache for a specific template -- [clearCompiledTemplate()](./api-functions/api-clear-compiled-tpl.md) — clears the compiled version of the specified template resource -- [clearConfig()](./api-functions/api-clear-config.md) — clears assigned config variables -- [compileAllConfig()](./api-functions/api-compile-all-config.md) — compiles all known config files -- [compileAllTemplates()](./api-functions/api-compile-all-templates.md) — compiles all known templates -- [configLoad()](./api-functions/api-config-load.md) — loads config file data and assigns it to the template -- [createData()](./api-functions/api-create-data.md) — creates a data object -- [createTemplate()](./api-functions/api-create-template.md) — returns a template object -- [disableSecurity()](./api-functions/api-disable-security.md) — disables template security -- [display()](./api-functions/api-display.md) — displays the template -- [enableSecurity()](./api-functions/api-enable-security.md) — enables template security -- [fetch()](./api-functions/api-fetch.md) — returns the template output -- [getCacheDir()](./api-functions/api-get-cache-dir.md) — return the directory where the rendered template's output is stored -- [getCompileDir()](./api-functions/api-get-compile-dir.md) — returns the directory where compiled templates are stored -- [getConfigDir()](./api-functions/api-get-config-dir.md) — return the directory where config files are stored -- [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 -- [loadFilter()](./api-functions/api-load-filter.md) — load a filter plugin -- [muteExpectedErrors()](./api-functions/api-mute-expected-errors.md) — mutes expected warnings and notices deliberately generated by Smarty -- [registerCacheResource()](./api-functions/api-register-cacheresource.md) — dynamically register CacheResources -- [registerClass()](./api-functions/api-register-class.md) — register a class for use in the templates -- [registerDefaultPluginHandler()](./api-functions/api-register-default-plugin-handler.md) — register a function which gets called on undefined tags -- [registerFilter()](./api-functions/api-register-filter.md) — dynamically register filters -- [registerPlugin()](./api-functions/api-register-plugin.md) — dynamically register plugins -- [registerObject()](./api-functions/api-register-object.md) — register an object for use in the templates -- [registerResource()](./api-functions/api-register-resource.md) — dynamically register resources -- [setCacheDir()](./api-functions/api-set-cache-dir.md) — set the directory where the rendered template's output is stored -- [setCompileDir()](./api-functions/api-set-compile-dir.md) — set the directory where compiled templates are stored -- [setConfigDir()](./api-functions/api-set-config-dir.md) — set the directories where config files are stored -- [setPluginsDir()](./api-functions/api-set-plugins-dir.md) — set the directories where plugins are stored -- [setTemplateDir()](./api-functions/api-set-template-dir.md) — set the directories where templates are stored -- [templateExists()](./api-functions/api-template-exists.md) — checks whether the specified template exists -- [unregisterCacheResource()](./api-functions/api-unregister-cacheresource.md) — dynamically unregister a CacheResource plugin -- [unregisterFilter()](./api-functions/api-unregister-filter.md) — dynamically unregister a filter -- [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** -> -> See -> [`Changing settings by template`](./advanced-features/advanced-features-template-settings.md) -> section for how to use the functions for individual templates. diff --git a/docs/programmers/api-functions/add-extension.md b/docs/programmers/api-functions/add-extension.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/programmers/api-functions/api-add-config-dir.md b/docs/programmers/api-functions/api-add-config-dir.md deleted file mode 100644 index c3a052289..000000000 --- a/docs/programmers/api-functions/api-add-config-dir.md +++ /dev/null @@ -1,49 +0,0 @@ -addConfigDir() - -add a directory to the list of directories where config files are stored - -Description -=========== - -Smarty - -addConfigDir - -string\|array - -config\_dir - -string - -key - - - addConfigDir('./config_1'); - - // add directory where config files are stored and specify array-key - $smarty->addConfigDir('./config_1', 'one'); - - // add multiple directories where config files are stored and specify array-keys - $smarty->addTemplateDir(array( - 'two' => './config_2', - 'three' => './config_3', - )); - - // view the template dir chain - var_dump($smarty->getConfigDir()); - - // chaining of method calls - $smarty->setConfigDir('./config') - ->addConfigDir('./config_1', 'one') - ->addConfigDir('./config_2', 'two'); - - ?> - - - -See also [`getConfigDir()`](#api.get.config.dir), -[`setConfigDir()`](#api.set.config.dir) and -[`$config_dir`](#variable.config.dir). diff --git a/docs/programmers/api-functions/api-add-template-dir.md b/docs/programmers/api-functions/api-add-template-dir.md deleted file mode 100644 index e0d24564c..000000000 --- a/docs/programmers/api-functions/api-add-template-dir.md +++ /dev/null @@ -1,49 +0,0 @@ -addTemplateDir() - -add a directory to the list of directories where templates are stored - -Description -=========== - -Smarty - -addTemplateDir - -string\|array - -template\_dir - -string - -key - - - addTemplateDir('./templates_1'); - - // add directory where templates are stored and specify array-key - $smarty->addTemplateDir('./templates_1', 'one'); - - // add multiple directories where templates are stored and specify array-keys - $smarty->addTemplateDir(array( - 'two' => './templates_2', - 'three' => './templates_3', - )); - - // view the template dir chain - var_dump($smarty->getTemplateDir()); - - // chaining of method calls - $smarty->setTemplateDir('./templates') - ->addTemplateDir('./templates_1', 'one') - ->addTemplateDir('./templates_2', 'two'); - - ?> - - - -See also [`getTemplateDir()`](#api.get.template.dir), -[`setTemplateDir()`](#api.set.template.dir) and -[`$template_dir`](#variable.template.dir). diff --git a/docs/programmers/api-functions/api-append-by-ref.md b/docs/programmers/api-functions/api-append-by-ref.md deleted file mode 100644 index cd396d9cc..000000000 --- a/docs/programmers/api-functions/api-append-by-ref.md +++ /dev/null @@ -1,46 +0,0 @@ -appendByRef() - -append values by reference - -Description -=========== - -void - -appendByRef - -string - -varname - -mixed - -var - -bool - -merge - -This is used to [`append()`](#api.append) values to the templates by -reference. - -> **Note** -> -> With the introduction of PHP5, `appendByRef()` is not necessary for -> most intents and purposes. `appendByRef()` is useful if you want a PHP -> array index value to be affected by its reassignment from a template. -> Assigned object properties behave this way by default. - -NOTE.PARAMETER.MERGE - - - appendByRef('Name', $myname); - $smarty->appendByRef('Address', $address); - ?> - - - -See also [`append()`](#api.append), [`assign()`](#api.assign) and -[`getTemplateVars()`](#api.get.template.vars). diff --git a/docs/programmers/api-functions/api-append.md b/docs/programmers/api-functions/api-append.md index b94586417..d9acff84a 100644 --- a/docs/programmers/api-functions/api-append.md +++ b/docs/programmers/api-functions/api-append.md @@ -56,6 +56,5 @@ NOTE.PARAMETER.MERGE -See also [`appendByRef()`](#api.append.by.ref), -[`assign()`](#api.assign) and +See also [`assign()`](#api.assign) and [`getTemplateVars()`](#api.get.template.vars) diff --git a/docs/programmers/api-functions/api-assign-by-ref.md b/docs/programmers/api-functions/api-assign-by-ref.md deleted file mode 100644 index 7c42b4836..000000000 --- a/docs/programmers/api-functions/api-assign-by-ref.md +++ /dev/null @@ -1,42 +0,0 @@ -assignByRef() - -assign values by reference - -Description -=========== - -void - -assignByRef - -string - -varname - -mixed - -var - -This is used to [`assign()`](#api.assign) values to the templates by -reference. - -> **Note** -> -> With the introduction of PHP5, `assignByRef()` is not necessary for -> most intents and purposes. `assignByRef()` is useful if you want a PHP -> array index value to be affected by its reassignment from a template. -> Assigned object properties behave this way by default. - - - assignByRef('Name', $myname); - $smarty->assignByRef('Address', $address); - ?> - - - -See also [`assign()`](#api.assign), -[`clearAllAssign()`](#api.clear.all.assign), [`append()`](#api.append), -[`{assign}`](#language.function.assign) and -[`getTemplateVars()`](#api.get.template.vars). diff --git a/docs/programmers/api-functions/api-assign.md b/docs/programmers/api-functions/api-assign.md index c3b9985d4..31f6a1508 100644 --- a/docs/programmers/api-functions/api-assign.md +++ b/docs/programmers/api-functions/api-assign.md @@ -78,7 +78,6 @@ To access more complex array assignments see [`{foreach}`](#language.function.foreach) and [`{section}`](#language.function.section) -See also [`assignByRef()`](#api.assign.by.ref), -[`getTemplateVars()`](#api.get.template.vars), +See also [`getTemplateVars()`](#api.get.template.vars), [`clearAssign()`](#api.clear.assign), [`append()`](#api.append) and [`{assign}`](#language.function.assign) diff --git a/docs/programmers/api-functions/api-compile-all-config.md b/docs/programmers/api-functions/api-compile-all-config.md index a102fc97e..35497d9ad 100644 --- a/docs/programmers/api-functions/api-compile-all-config.md +++ b/docs/programmers/api-functions/api-compile-all-config.md @@ -50,7 +50,7 @@ parameters: setCaching(true); diff --git a/docs/programmers/api-functions/api-fetch.md b/docs/programmers/api-functions/api-fetch.md index 6da05bd0e..491c28d4d 100644 --- a/docs/programmers/api-functions/api-fetch.md +++ b/docs/programmers/api-functions/api-fetch.md @@ -30,7 +30,7 @@ PARAMETER.COMPILEID setCaching(true); diff --git a/docs/programmers/api-functions/api-get-cache-dir.md b/docs/programmers/api-functions/api-get-cache-dir.md deleted file mode 100644 index 9e55d8d0b..000000000 --- a/docs/programmers/api-functions/api-get-cache-dir.md +++ /dev/null @@ -1,23 +0,0 @@ -getCacheDir() - -return the directory where the rendered template\'s output is stored - -Description -=========== - -string - -getCacheDir - - - getCacheDir(); - - ?> - - - -See also [`setCacheDir()`](#api.set.cache.dir) and -[`$cache_dir`](#variable.cache.dir). diff --git a/docs/programmers/api-functions/api-get-compile-dir.md b/docs/programmers/api-functions/api-get-compile-dir.md deleted file mode 100644 index 3bfae7306..000000000 --- a/docs/programmers/api-functions/api-get-compile-dir.md +++ /dev/null @@ -1,23 +0,0 @@ -getCompileDir() - -returns the directory where compiled templates are stored - -Description -=========== - -string - -getCompileDir - - - getCompileDir(); - - ?> - - - -See also [`setCompileDir()`](#api.set.compile.dir) and -[`$compile_dir`](#variable.compile.dir). diff --git a/docs/programmers/api-functions/api-get-tags.md b/docs/programmers/api-functions/api-get-tags.md deleted file mode 100644 index 7729b468b..000000000 --- a/docs/programmers/api-functions/api-get-tags.md +++ /dev/null @@ -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. - - - createTemplate('index.tpl'); - - // get tags - $tags = $smarty->getTags($tpl); - - print_r($tags); - - ?> - - diff --git a/docs/programmers/api-functions/api-get-template-dir.md b/docs/programmers/api-functions/api-get-template-dir.md deleted file mode 100644 index 42c75908b..000000000 --- a/docs/programmers/api-functions/api-get-template-dir.md +++ /dev/null @@ -1,40 +0,0 @@ -getTemplateDir() - -return the directory where templates are stored - -Description -=========== - -string\|array - -getTemplateDir - -string - -key - - - setTemplateDir(array( - 'one' => './templates', - 'two' => './templates_2', - 'three' => './templates_3', - )); - - // get all directories where templates are stored - $template_dir = $smarty->getTemplateDir(); - var_dump($template_dir); // array - - // get directory identified by key - $template_dir = $smarty->getTemplateDir('one'); - var_dump($template_dir); // string - - ?> - - - -See also [`setTemplateDir()`](#api.set.template.dir), -[`addTemplateDir()`](#api.add.template.dir) and -[`$template_dir`](#variable.template.dir). diff --git a/docs/programmers/api-functions/api-is-cached.md b/docs/programmers/api-functions/api-is-cached.md index 0c41bf04a..d9d3057fb 100644 --- a/docs/programmers/api-functions/api-is-cached.md +++ b/docs/programmers/api-functions/api-is-cached.md @@ -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 diff --git a/docs/programmers/api-functions/api-load-filter.md b/docs/programmers/api-functions/api-load-filter.md index 19286ee33..e2738b0c8 100644 --- a/docs/programmers/api-functions/api-load-filter.md +++ b/docs/programmers/api-functions/api-load-filter.md @@ -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). diff --git a/docs/programmers/api-functions/api-mute-expected-errors.md b/docs/programmers/api-functions/api-mute-expected-errors.md index 626288ea6..ac84a6435 100644 --- a/docs/programmers/api-functions/api-mute-expected-errors.md +++ b/docs/programmers/api-functions/api-mute-expected-errors.md @@ -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. +`\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. diff --git a/docs/programmers/api-functions/api-register-cacheresource.md b/docs/programmers/api-functions/api-register-cacheresource.md index 60ae60308..626091496 100644 --- a/docs/programmers/api-functions/api-register-cacheresource.md +++ b/docs/programmers/api-functions/api-register-cacheresource.md @@ -31,7 +31,7 @@ how to create custom CacheResources. registerCacheResource('mysql', new Smarty_CacheResource_Mysql()); + $smarty->registerCacheResource('mysql', new My_CacheResource_Mysql()); ?> diff --git a/docs/programmers/api-functions/api-register-class.md b/docs/programmers/api-functions/api-register-class.md index ee339cadb..d0156d512 100644 --- a/docs/programmers/api-functions/api-register-class.md +++ b/docs/programmers/api-functions/api-register-class.md @@ -24,6 +24,7 @@ otherwise. If security is enabled, classes registered with registerClass("Foo", "\my\php\application\Bar"); diff --git a/docs/programmers/api-functions/api-register-default-plugin-handler.md b/docs/programmers/api-functions/api-register-default-plugin-handler.md index 03547df71..61ac47612 100644 --- a/docs/programmers/api-functions/api-register-default-plugin-handler.md +++ b/docs/programmers/api-functions/api-register-default-plugin-handler.md @@ -25,7 +25,7 @@ plugin types. registerDefaultPluginHandler('my_plugin_handler'); @@ -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) diff --git a/docs/programmers/api-functions/api-register-filter.md b/docs/programmers/api-functions/api-register-filter.md index fd91d2661..4a2aa4b02 100644 --- a/docs/programmers/api-functions/api-register-filter.md +++ b/docs/programmers/api-functions/api-register-filter.md @@ -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. diff --git a/docs/programmers/api-functions/api-register-plugin.md b/docs/programmers/api-functions/api-register-plugin.md index 6eb433810..51342b8e1 100644 --- a/docs/programmers/api-functions/api-register-plugin.md +++ b/docs/programmers/api-functions/api-register-plugin.md @@ -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. diff --git a/docs/programmers/api-functions/api-register-resource.md b/docs/programmers/api-functions/api-register-resource.md index ca4005460..774452bff 100644 --- a/docs/programmers/api-functions/api-register-resource.md +++ b/docs/programmers/api-functions/api-register-resource.md @@ -37,7 +37,7 @@ information on how to setup a function for fetching templates. registerResource('mysql', new Smarty_Resource_Mysql()); + $smarty->registerResource('mysql', new My_Resource_Mysql()); ?> diff --git a/docs/programmers/api-functions/api-set-cache-dir.md b/docs/programmers/api-functions/api-set-cache-dir.md deleted file mode 100644 index 7f7c4b60d..000000000 --- a/docs/programmers/api-functions/api-set-cache-dir.md +++ /dev/null @@ -1,32 +0,0 @@ -setCacheDir() - -set the directory where the rendered template\'s output is stored - -Description -=========== - -Smarty - -setCacheDir - -string - -cache\_dir - - - setCacheDir('./cache'); - - // chaining of method calls - $smarty->setTemplateDir('./templates') - ->setCompileDir('./templates_c') - ->setCacheDir('./cache'); - - ?> - - - -See also [`getCacheDir()`](#api.get.cache.dir) and -[`$cache_dir`](#variable.cache.dir). diff --git a/docs/programmers/api-functions/api-set-compile-dir.md b/docs/programmers/api-functions/api-set-compile-dir.md deleted file mode 100644 index bfeb55a53..000000000 --- a/docs/programmers/api-functions/api-set-compile-dir.md +++ /dev/null @@ -1,32 +0,0 @@ -setCompileDir() - -set the directory where compiled templates are stored - -Description -=========== - -Smarty - -setCompileDir - -string - -compile\_dir - - - setCompileDir('./templates_c'); - - // chaining of method calls - $smarty->setTemplateDir('./templates') - ->setCompileDir('./templates_c') - ->setCacheDir('./cache'); - - ?> - - - -See also [`getCompileDir()`](#api.get.compile.dir) and -[`$compile_dir`](#variable.compile.dir). diff --git a/docs/programmers/api-functions/api-set-config-dir.md b/docs/programmers/api-functions/api-set-config-dir.md deleted file mode 100644 index 97a6ae977..000000000 --- a/docs/programmers/api-functions/api-set-config-dir.md +++ /dev/null @@ -1,47 +0,0 @@ -setConfigDir() - -set the directories where config files are stored - -Description -=========== - -Smarty - -setConfigDir - -string\|array - -config\_dir - - - setConfigDir('./config'); - - // view the config dir chain - var_dump($smarty->getConfigDir()); - - // set multiple directoríes where config files are stored - $smarty->setConfigDir(array( - 'one' => './config', - 'two' => './config_2', - 'three' => './config_3', - )); - - // view the config dir chain - var_dump($smarty->getConfigDir()); - - // chaining of method calls - $smarty->setTemplateDir('./templates') - ->setConfigDir('./config') - ->setCompileDir('./templates_c') - ->setCacheDir('./cache'); - - ?> - - - -See also [`getConfigDir()`](#api.get.config.dir), -[`addConfigDir()`](#api.add.config.dir) and -[`$config_dir`](#variable.config.dir). diff --git a/docs/programmers/api-functions/api-set-template-dir.md b/docs/programmers/api-functions/api-set-template-dir.md deleted file mode 100644 index 2de23309b..000000000 --- a/docs/programmers/api-functions/api-set-template-dir.md +++ /dev/null @@ -1,46 +0,0 @@ -setTemplateDir() - -set the directories where templates are stored - -Description -=========== - -Smarty - -setTemplateDir - -string\|array - -template\_dir - - - setTemplateDir('./cache'); - - // view the template dir chain - var_dump($smarty->getTemplateDir()); - - // set multiple directoríes where templates are stored - $smarty->setTemplateDir(array( - 'one' => './templates', - 'two' => './templates_2', - 'three' => './templates_3', - )); - - // view the template dir chain - var_dump($smarty->getTemplateDir()); - - // chaining of method calls - $smarty->setTemplateDir('./templates') - ->setCompileDir('./templates_c') - ->setCacheDir('./cache'); - - ?> - - - -See also [`getTemplateDir()`](#api.get.template.dir), -[`addTemplateDir()`](#api.add.template.dir) and -[`$template_dir`](#variable.template.dir). diff --git a/docs/programmers/api-functions/api-template-exists.md b/docs/programmers/api-functions/api-template-exists.md deleted file mode 100644 index 07f61b12e..000000000 --- a/docs/programmers/api-functions/api-template-exists.md +++ /dev/null @@ -1,59 +0,0 @@ -templateExists() - -checks whether the specified template exists - -Description -=========== - -bool - -templateExists - -string - -template - -It can accept either a path to the template on the filesystem or a -resource string specifying the template. - -This example uses `$_GET['page']` to -[`{include}`](#language.function.include) a content template. If the -template does not exist then an error page is displayed instead. First -the `page_container.tpl` - - - - {$title} - - {include file='page_top.tpl'} - - {* include middle content page *} - {include file=$content_template} - - {include file='page_footer.tpl'} - - - - -And the php script - - - templateExists($mid_template) ){ - $mid_template = 'page_not_found.tpl'; - } - $smarty->assign('content_template', $mid_template); - - $smarty->display('page_container.tpl'); - - ?> - - - -See also [`display()`](#api.display), [`fetch()`](#api.fetch), -[`{include}`](#language.function.include) and -[`{insert}`](#language.function.insert) diff --git a/docs/programmers/api-functions/api-test-install.md b/docs/programmers/api-functions/api-test-install.md index 918bd220a..bba64a19c 100644 --- a/docs/programmers/api-functions/api-test-install.md +++ b/docs/programmers/api-functions/api-test-install.md @@ -14,7 +14,7 @@ installation can be accessed. It does output a corresponding protocol. testInstall(); ?> diff --git a/docs/programmers/api-variables.md b/docs/programmers/api-variables.md deleted file mode 100644 index ee9c07611..000000000 --- a/docs/programmers/api-variables.md +++ /dev/null @@ -1,63 +0,0 @@ -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) -- [$cache_locking](./api-variables/variable-cache-locking.md) -- [$cache_modified_check](./api-variables/variable-cache-modified-check.md) -- [$caching](./api-variables/variable-caching.md) -- [$caching_type](./api-variables/variable-caching-type.md) -- [$compile_check](./api-variables/variable-compile-check.md) -- [$compile_dir](./api-variables/variable-compile-dir.md) -- [$compile_id](./api-variables/variable-compile-id.md) -- [$compile_locking](./api-variables/variable-compile-locking.md) -- [$compiler_class](./api-variables/variable-compiler-class.md) -- [$config_booleanize](./api-variables/variable-config-booleanize.md) -- [$config_dir](./api-variables/variable-config-dir.md) -- [$config_overwrite](./api-variables/variable-config-overwrite.md) -- [$config_read_hidden](./api-variables/variable-config-read-hidden.md) -- [$debug_tpl](./api-variables/variable-debug-template.md) -- [$debugging](./api-variables/variable-debugging.md) -- [$debugging_ctrl](./api-variables/variable-debugging-ctrl.md) -- [$default_config_type](./api-variables/variable-default-config-type.md) -- [$default_modifiers](./api-variables/variable-default-modifiers.md) -- [$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) -- [$force_compile](./api-variables/variable-force-compile.md) -- [$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** -> -> All class variables have magic setter/getter methods available. -> setter/getter methods are camelCaseFormat, unlike the variable itself. -> So for example, you can set and get the \$smarty-\>template\_dir -> variable with \$smarty-\>setTemplateDir(\$dir) and \$dir = -> \$smarty-\>getTemplateDir() respectively. - -> **Note** -> -> See -> [`Changing settings by template`](./advanced-features/advanced-features-template-settings.md) -> section for how to change Smarty class variables for individual -> templates. diff --git a/docs/programmers/api-variables/variable-allow-php-templates.md b/docs/programmers/api-variables/variable-allow-php-templates.md deleted file mode 100644 index e15520e2d..000000000 --- a/docs/programmers/api-variables/variable-allow-php-templates.md +++ /dev/null @@ -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} - - allow_php_templates = true; - ?> - - -::: - -> **Note** -> -> The PHP template file resource is an undocumented deprecated feature. diff --git a/docs/programmers/api-variables/variable-autoload-filters.md b/docs/programmers/api-variables/variable-autoload-filters.md deleted file mode 100644 index 8a300b065..000000000 --- a/docs/programmers/api-variables/variable-autoload-filters.md +++ /dev/null @@ -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} - - autoload_filters = array('pre' => array('trim', 'stamp'), - 'output' => array('convert')); - ?> - - -::: - -See also [`registerFilter()`](#api.register.filter) and -[`loadFilter()`](#api.load.filter) diff --git a/docs/programmers/api-variables/variable-cache-lifetime.md b/docs/programmers/api-variables/variable-cache-lifetime.md index c9624b556..481fbee8e 100644 --- a/docs/programmers/api-variables/variable-cache-lifetime.md +++ b/docs/programmers/api-variables/variable-cache-lifetime.md @@ -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). diff --git a/docs/programmers/api-variables/variable-cache-modified-check.md b/docs/programmers/api-variables/variable-cache-modified-check.md index 05e00bb91..815be2556 100644 --- a/docs/programmers/api-variables/variable-cache-modified-check.md +++ b/docs/programmers/api-variables/variable-cache-modified-check.md @@ -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 diff --git a/docs/programmers/api-variables/variable-caching.md b/docs/programmers/api-variables/variable-caching.md index 9377e3b6d..7304e41d6 100644 --- a/docs/programmers/api-variables/variable-caching.md +++ b/docs/programmers/api-variables/variable-caching.md @@ -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 diff --git a/docs/programmers/api-variables/variable-compile-check.md b/docs/programmers/api-variables/variable-compile-check.md deleted file mode 100644 index 075e7f17a..000000000 --- a/docs/programmers/api-variables/variable-compile-check.md +++ /dev/null @@ -1,30 +0,0 @@ -\$compile\_check {#variable.compile.check} -================ - -Upon each invocation of the PHP application, Smarty tests to see if the -current template has changed (different timestamp) since the last time -it was compiled. If it has changed, it recompiles that template. If the -template has yet not been compiled at all, it will compile regardless of -this setting. By default this variable is set to TRUE. - -Once an application is put into production (ie the templates won\'t be -changing), the compile check step is no longer needed. Be sure to set -`$compile_check` to FALSE for maximum performance. Note that if you -change this to FALSE and a template file is changed, you will \*not\* -see the change since the template will not get recompiled. - -Note that up to Smarty 4.x, Smarty will check for the existence of -the source template even if `$compile_check` is disabled. - -If [`$caching`](#variable.caching) is enabled and `$compile_check` is -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 -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. - -See [`$force_compile`](#variable.force.compile) and -[`clearCompiledTemplate()`](#api.clear.compiled.tpl). diff --git a/docs/programmers/api-variables/variable-debug-template.md b/docs/programmers/api-variables/variable-debug-template.md index faec0e171..11a805292 100644 --- a/docs/programmers/api-variables/variable-debug-template.md +++ b/docs/programmers/api-variables/variable-debug-template.md @@ -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. diff --git a/docs/programmers/api-variables/variable-default-config-handler-func.md b/docs/programmers/api-variables/variable-default-config-handler-func.md index 0d6ec5e0d..50eb65bb5 100644 --- a/docs/programmers/api-variables/variable-default-config-handler-func.md +++ b/docs/programmers/api-variables/variable-default-config-handler-func.md @@ -8,11 +8,11 @@ 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. default_config_handler_func = 'my_default_config_handler_func'; diff --git a/docs/programmers/api-variables/variable-default-template-handler-func.md b/docs/programmers/api-variables/variable-default-template-handler-func.md index d8fcbb1ad..96c8190d7 100644 --- a/docs/programmers/api-variables/variable-default-template-handler-func.md +++ b/docs/programmers/api-variables/variable-default-template-handler-func.md @@ -8,11 +8,11 @@ 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. default_template_handler_func = 'my_default_template_handler_func'; diff --git a/docs/programmers/api-variables/variable-direct-access-security.md b/docs/programmers/api-variables/variable-direct-access-security.md deleted file mode 100644 index f471f5de0..000000000 --- a/docs/programmers/api-variables/variable-direct-access-security.md +++ /dev/null @@ -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. diff --git a/docs/programmers/api-variables/variable-error-reporting.md b/docs/programmers/api-variables/variable-error-reporting.md index c0aa9cedb..ee28d47ab 100644 --- a/docs/programmers/api-variables/variable-error-reporting.md +++ b/docs/programmers/api-variables/variable-error-reporting.md @@ -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()` diff --git a/docs/programmers/api-variables/variable-plugins-dir.md b/docs/programmers/api-variables/variable-plugins-dir.md deleted file mode 100644 index 8a7cfcdb2..000000000 --- a/docs/programmers/api-variables/variable-plugins-dir.md +++ /dev/null @@ -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). diff --git a/docs/programmers/api-variables/variable-template-dir.md b/docs/programmers/api-variables/variable-template-dir.md index 1db9c4139..eb91d2c24 100644 --- a/docs/programmers/api-variables/variable-template-dir.md +++ b/docs/programmers/api-variables/variable-template-dir.md @@ -15,22 +15,12 @@ found. > document root. > **Note** -> -> If the directories known to `$template_dir` are relative to -> directories known to the -> [include\_path](https://www.php.net/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). diff --git a/docs/programmers/api-variables/variable-trusted-dir.md b/docs/programmers/api-variables/variable-trusted-dir.md deleted file mode 100644 index 9720ae8a6..000000000 --- a/docs/programmers/api-variables/variable-trusted-dir.md +++ /dev/null @@ -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). diff --git a/docs/programmers/api-variables/variable-use-include-path.md b/docs/programmers/api-variables/variable-use-include-path.md index 90f55f073..e69de29bb 100644 --- a/docs/programmers/api-variables/variable-use-include-path.md +++ b/docs/programmers/api-variables/variable-use-include-path.md @@ -1,49 +0,0 @@ -\$use\_include\_path {#variable.use.include.path} -==================== - -This tells smarty to respect the -[include\_path](https://www.php.net/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](https://www.php.net/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](https://www.php.net/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) diff --git a/docs/programmers/caching.md b/docs/programmers/caching.md deleted file mode 100644 index 5656b71b5..000000000 --- a/docs/programmers/caching.md +++ /dev/null @@ -1,24 +0,0 @@ -Caching -======= - -Caching is used to speed up a call to [`display()`](./api-functions/api-display.md) or -[`fetch()`](./api-functions/api-fetch.md) by saving its output to a file. If a cached -version of the call is available, that is displayed instead of -regenerating the output. Caching can speed things up tremendously, -especially templates with longer computation times. Since the output of -[`display()`](./api-functions/api-display.md) or [`fetch()`](./api-functions/api-fetch.md) is cached, one -cache file could conceivably be made up of several template files, -config files, etc. - -Since templates are dynamic, it is important to be careful what you are -caching and for how long. For instance, if you are displaying the front -page of your website that does not change its content very often, it -might work well to cache this page for an hour or more. On the other -hand, if you are displaying a page with a timetable containing new -information by the minute, it would not make sense to cache this page. - -## Table of contents -- [Setting Up Caching](./caching/caching-setting-up.md) -- [Multiple Caches Per Page](./caching/caching-multiple-caches.md) -- [Controlling Cacheability of Output](./caching/caching-groups.md) -- [Custom Cache Implementation](./caching/caching-custom.md) diff --git a/docs/programmers/caching/caching-cacheable.md b/docs/programmers/caching/caching-cacheable.md deleted file mode 100644 index ee9b60090..000000000 --- a/docs/programmers/caching/caching-cacheable.md +++ /dev/null @@ -1,176 +0,0 @@ -Controlling Cacheability of Output {#caching.cacheable} -================================== - -If caching is enabled normally the whole final output of the page gets -cached. However Smarty3 offers several options how to exclude sections -of your output from caching. - -> **Note** -> -> Be sure any variables used within a non-cached section are also -> assigned from PHP when the page is loaded from the cache. - -Cacheability of Template Section {#cacheability.sections} --------------------------------- - -A larger section of your template can easily excluded from caching by -using the [`{nocache}`](#language.function.nocache) and -[`{/nocache}`](#language.function.nocache) tags. - - - - Today's date is - {nocache} - {$smarty.now|date_format} - {/nocache} - - - -The above code will output the current date on a cached page. - -Cacheability of Tags {#cacheability.tags} --------------------- - -Caching for an individual tag can be disabled by adding the \"nocache\" -option flag to the tag. - - - Today's date is - {$smarty.now|date_format nocache} - - - -Cacheability of Variables {#cacheability.variables} -------------------------- - -You can [`assign()`](#api.assign) variables as not cachable. Any tag -which uses such variable will be automatically executed in nocache mode. - -> **Note** -> -> If a tag is executed in nocache mode you must make sure that all other -> variables used by that tag are also assigned from PHP when the page is -> loaded from the cache. - -> **Note** -> -> The nocache status of an assigned variable will effect the compiled -> template code. If you change the status you must manually delete -> existing compiled and cached template files to force a recompile. - - - // assign $foo as nocahe variable - $smarty->assign('foo',time(),true); - - - Dynamic time value is {$foo} - - - -Cacheability of Plugins {#cacheability.plugins} ------------------------ - -The cacheability of plugins can be declared when registering them. The -third parameter to [`registerPlugin()`](#api.register.plugin) is called -`$cacheable` and defaults to TRUE. - -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 -> 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. - - - 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: - - setCaching(Smarty::CACHING_LIFETIME_CURRENT); - - function smarty_block_dynamic($param, $content, $smarty) { - return $content; - } - $smarty->registerPlugin('block','dynamic', 'smarty_block_dynamic', false); - - $smarty->display('index.tpl'); - ?> - - - -where `index.tpl` is: - - - Page created: {'0'|date_format:'%D %H:%M:%S'} - - {dynamic} - - Now is: {'0'|date_format:'%D %H:%M:%S'} - - ... do other stuff ... - - {/dynamic} - - - -When reloading the page you will notice that both dates differ. One is -"dynamic" one is "static". You can do everything between -`{dynamic}...{/dynamic}` and be sure it will not be cached like the rest -of the page. - -> **Note** -> -> The above example shall just demonstrate how a dynamic block plugins -> works. See -> [`Cacheability of Template Section`](#cacheability.sections) on how to -> disable caching of a template section by the built-in -> [`{nocache}`](#language.function.nocache) and -> [`{/nocache}`](#language.function.nocache) tags. diff --git a/docs/programmers/caching/caching-custom.md b/docs/programmers/caching/caching-custom.md deleted file mode 100644 index 77d2ce7b3..000000000 --- a/docs/programmers/caching/caching-custom.md +++ /dev/null @@ -1,296 +0,0 @@ -Custom Cache Implementation {#caching.custom} -=========================== - -As an alternative to using the default file-based caching mechanism, you -can specify a custom cache implementation that will be used to read, -write and clear cached files. - -> **Note** -> -> In Smarty2 this used to be a callback function called -> `$cache_handler_func`. Smarty3 replaced this callback by the -> `Smarty_CacheResource` module. - -With a custom cache implementation you\'re likely trying to achieve at -least one of the following goals: replace the slow filesystem by a -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, -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\" -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 -allows clearing the cache-group \"a\" and all nested groups are cleared -as well - even though KeyValue-Stores don\'t allow this kind of -hierarchy by nature. - -Custom CacheResources may be put in a file `cacheresource.foobarxyz.php` -within your [`$plugins_dir`](#variable.plugins.dir), or registered on -runtime with [`registerCacheResource()`](#api.register.cacheresource). -In either case you need to set [`$caching_type`](#variable.caching.type) -to invoke your custom CacheResource implementation. - - - caching_type = 'mysql'; - - /** - * MySQL CacheResource - * - * CacheResource Implementation based on the Custom API to use - * MySQL as the storage resource for Smarty's output caching. - * - * Table definition: - *
CREATE TABLE IF NOT EXISTS `output_cache` (
-     *   `id` CHAR(40) NOT NULL COMMENT 'sha1 hash',
-     *   `name` VARCHAR(250) NOT NULL,
-     *   `cache_id` VARCHAR(250) NULL DEFAULT NULL,
-     *   `compile_id` VARCHAR(250) NULL DEFAULT NULL,
-     *   `modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-     *   `content` LONGTEXT NOT NULL,
-     *   PRIMARY KEY (`id`),
-     *   INDEX(`name`),
-     *   INDEX(`cache_id`),
-     *   INDEX(`compile_id`),
-     *   INDEX(`modified`)
-     * ) ENGINE = InnoDB;
- * - * @package CacheResource-examples - * @author Rodney Rehm - */ - class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom { - // PDO instance - protected $db; - protected $fetch; - protected $fetchTimestamp; - protected $save; - - public function __construct() { - try { - $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty"); - } catch (PDOException $e) { - throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); - } - $this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id'); - $this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id'); - $this->save = $this->db->prepare('REPLACE INTO output_cache (id, name, cache_id, compile_id, content) - VALUES (:id, :name, :cache_id, :compile_id, :content)'); - } - - /** - * fetch cached content and its modification time from data source - * - * @param string $id unique cache content identifier - * @param string $name template name - * @param string $cache_id cache id - * @param string $compile_id compile id - * @param string $content cached content - * @param integer $mtime cache modification timestamp (epoch) - * @return void - */ - protected function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime) - { - $this->fetch->execute(array('id' => $id)); - $row = $this->fetch->fetch(); - $this->fetch->closeCursor(); - if ($row) { - $content = $row['content']; - $mtime = strtotime($row['modified']); - } else { - $content = null; - $mtime = null; - } - } - - /** - * Fetch cached content's modification timestamp from data source - * - * @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the complete cached content. - * @param string $id unique cache content identifier - * @param string $name template name - * @param string $cache_id cache id - * @param string $compile_id compile id - * @return integer|boolean timestamp (epoch) the template was modified, or false if not found - */ - protected function fetchTimestamp($id, $name, $cache_id, $compile_id) - { - $this->fetchTimestamp->execute(array('id' => $id)); - $mtime = strtotime($this->fetchTimestamp->fetchColumn()); - $this->fetchTimestamp->closeCursor(); - return $mtime; - } - - /** - * Save content to cache - * - * @param string $id unique cache content identifier - * @param string $name template name - * @param string $cache_id cache id - * @param string $compile_id compile id - * @param integer|null $exp_time seconds till expiration time in seconds or null - * @param string $content content to cache - * @return boolean success - */ - protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content) - { - $this->save->execute(array( - 'id' => $id, - 'name' => $name, - 'cache_id' => $cache_id, - 'compile_id' => $compile_id, - 'content' => $content, - )); - return !!$this->save->rowCount(); - } - - /** - * Delete content from cache - * - * @param string $name template name - * @param string $cache_id cache id - * @param string $compile_id compile id - * @param integer|null $exp_time seconds till expiration or null - * @return integer number of deleted caches - */ - protected function delete($name, $cache_id, $compile_id, $exp_time) - { - // delete the whole cache - if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) { - // returning the number of deleted caches would require a second query to count them - $query = $this->db->query('TRUNCATE TABLE output_cache'); - return -1; - } - // build the filter - $where = array(); - // equal test name - if ($name !== null) { - $where[] = 'name = ' . $this->db->quote($name); - } - // equal test compile_id - if ($compile_id !== null) { - $where[] = 'compile_id = ' . $this->db->quote($compile_id); - } - // range test expiration time - if ($exp_time !== null) { - $where[] = 'modified < DATE_SUB(NOW(), INTERVAL ' . intval($exp_time) . ' SECOND)'; - } - // equal test cache_id and match sub-groups - if ($cache_id !== null) { - $where[] = '(cache_id = '. $this->db->quote($cache_id) - . ' OR cache_id LIKE '. $this->db->quote($cache_id .'|%') .')'; - } - // run delete query - $query = $this->db->query('DELETE FROM output_cache WHERE ' . join(' AND ', $where)); - return $query->rowCount(); - } - } - - - - - caching_type = 'memcache'; - - /** - * Memcache CacheResource - * - * CacheResource Implementation based on the KeyValueStore API to use - * memcache as the storage resource for Smarty's output caching. - * - * 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 { - /** - * memcache instance - * @var Memcache - */ - protected $memcache = null; - - public function __construct() - { - $this->memcache = new Memcache(); - $this->memcache->addServer( '127.0.0.1', 11211 ); - } - - /** - * Read values for a set of keys from cache - * - * @param array $keys list of keys to fetch - * @return array list of values with the given keys used as indexes - * @return boolean true on success, false on failure - */ - protected function read(array $keys) - { - $_keys = $lookup = array(); - foreach ($keys as $k) { - $_k = sha1($k); - $_keys[] = $_k; - $lookup[$_k] = $k; - } - $_res = array(); - $res = $this->memcache->get($_keys); - foreach ($res as $k => $v) { - $_res[$lookup[$k]] = $v; - } - return $_res; - } - - /** - * Save values for a set of keys to cache - * - * @param array $keys list of values to save - * @param int $expire expiration time - * @return boolean true on success, false on failure - */ - protected function write(array $keys, $expire=null) - { - foreach ($keys as $k => $v) { - $k = sha1($k); - $this->memcache->set($k, $v, 0, $expire); - } - return true; - } - - /** - * Remove values from cache - * - * @param array $keys list of keys to delete - * @return boolean true on success, false on failure - */ - protected function delete(array $keys) - { - foreach ($keys as $k) { - $k = sha1($k); - $this->memcache->delete($k); - } - return true; - } - - /** - * Remove *all* values from cache - * - * @return boolean true on success, false on failure - */ - protected function purge() - { - return $this->memcache->flush(); - } - } - - - diff --git a/docs/programmers/caching/caching-groups.md b/docs/programmers/caching/caching-groups.md deleted file mode 100644 index 7e248b2f3..000000000 --- a/docs/programmers/caching/caching-groups.md +++ /dev/null @@ -1,60 +0,0 @@ -Cache Groups {#caching.groups} -============ - -You can do more elaborate grouping by setting up `$cache_id` groups. -This is accomplished by separating each sub-group with a vertical bar -`|` in the `$cache_id` value. You can have as many sub-groups as you -like. - -- You can think of cache groups like a directory hierarchy. For - instance, a cache group of `'a|b|c'` could be thought of as the - directory structure `'/a/b/c/'`. - -- `clearCache(null,'a|b|c')` would be like removing the files - `'/a/b/c/*'`. `clearCache(null,'a|b')` would be like removing the - files `'/a/b/*'`. - -- If you specify a [`$compile_id`](#variable.compile.id) such as - `clearCache(null,'a|b','foo')` it is treated as an appended cache - group `'/a/b/c/foo/'`. - -- If you specify a template name such as - `clearCache('foo.tpl','a|b|c')` then Smarty will attempt to remove - `'/a/b/c/foo.tpl'`. - -- 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 hierarchy to be able to clear them as a group. - -Cache grouping should not be confused with your template directory -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 -structure that mimics your template file structure, such as -`display('themes/blue/index.tpl','themes|blue')`, then clear them with -`clearCache(null,'themes|blue')`. - - - setCaching(Smarty::CACHING_LIFETIME_CURRENT); - - // clear all caches with 'sports|basketball' as the first two cache_id groups - $smarty->clearCache(null,'sports|basketball'); - - // clear all caches with "sports" as the first cache_id group. This would - // include "sports|basketball", or "sports|(anything)|(anything)|(anything)|..." - $smarty->clearCache(null,'sports'); - - // clear the foo.tpl cache file with "sports|basketball" as the cache_id - $smarty->clearCache('foo.tpl','sports|basketball'); - - - $smarty->display('index.tpl','sports|basketball'); - ?> - - diff --git a/docs/programmers/caching/caching-multiple-caches.md b/docs/programmers/caching/caching-multiple-caches.md deleted file mode 100644 index 40fffc3d7..000000000 --- a/docs/programmers/caching/caching-multiple-caches.md +++ /dev/null @@ -1,87 +0,0 @@ -Multiple Caches Per Page {#caching.multiple.caches} -======================== - -You can have multiple cache files for a single call to -[`display()`](#api.display) or [`fetch()`](#api.fetch). Let\'s say that -a call to `display('index.tpl')` may have several different output -contents depending on some condition, and you want separate caches for -each one. You can do this by passing a `$cache_id` as the second -parameter to the function call. - - - setCaching(Smarty::CACHING_LIFETIME_CURRENT); - - $my_cache_id = $_GET['article_id']; - - $smarty->display('index.tpl', $my_cache_id); - ?> - - - -Above, we are passing the variable `$my_cache_id` to -[`display()`](#api.display) as the `$cache_id`. For each unique value of -`$my_cache_id`, a separate cache will be generated for `index.tpl`. In -this example, `article_id` was passed in the URL and is used as the -`$cache_id`. - -> **Note** -> -> Be very cautious when passing values from a client (web browser) into -> Smarty or any PHP application. Although the above example of using the -> article\_id from the URL looks handy, it could have bad consequences. -> The `$cache_id` is used to create a directory on the file system, so -> if the user decided to pass an extremely large value for article\_id, -> or write a script that sends random article\_id\'s at a rapid pace, -> this could possibly cause problems at the server level. Be sure to -> sanitize any data passed in before using it. In this instance, maybe -> you know the article\_id has a length of ten characters and is made up -> of alpha-numerics only, and must be a valid article\_id in the -> database. Check for this! - -Be sure to pass the same `$cache_id` as the second parameter to -[`isCached()`](#api.is.cached) and [`clearCache()`](#api.clear.cache). - - - setCaching(Smarty::CACHING_LIFETIME_CURRENT); - - $my_cache_id = $_GET['article_id']; - - if(!$smarty->isCached('index.tpl',$my_cache_id)) { - // No cache available, do variable assignments here. - $contents = get_database_contents(); - $smarty->assign($contents); - } - - $smarty->display('index.tpl',$my_cache_id); - ?> - - - -You can clear all caches for a particular `$cache_id` by passing NULL as -the first parameter to [`clearCache()`](#api.clear.cache). - - - setCaching(Smarty::CACHING_LIFETIME_CURRENT); - - // clear all caches with "sports" as the $cache_id - $smarty->clearCache(null,'sports'); - - $smarty->display('index.tpl','sports'); - ?> - - - -In this manner, you can "group" your caches together by giving them the -same `$cache_id`. diff --git a/docs/programmers/caching/caching-setting-up.md b/docs/programmers/caching/caching-setting-up.md deleted file mode 100644 index bc9d2ad9e..000000000 --- a/docs/programmers/caching/caching-setting-up.md +++ /dev/null @@ -1,153 +0,0 @@ -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`. - - - cacheLifetime() to determine - // the number of seconds a cache is good for - $smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT); - - $smarty->display('index.tpl'); - ?> - - - -With caching enabled, the function call to `display('index.tpl')` will -render the template as usual, but also saves a copy of its output to a -file (a cached copy) in the [`$cache_dir`](#variable.cache.dir). On the -next call to `display('index.tpl')`, the cached copy will be used -instead of rendering the template again. - -> **Note** -> -> The files in the [`$cache_dir`](#variable.cache.dir) are named similar -> to the template name. Although they end in the `.php` extension, they -> are not intended to be directly executable. Do not edit these files! - -Each cached page has a limited lifetime determined by -[`$cache_lifetime`](#variable.cache.lifetime). The default value is 3600 -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 -[`$cache_lifetime`](#variable.cache.lifetime) for more details. - - - setCaching(Smarty::CACHING_LIFETIME_SAVED); - - // set the cache_lifetime for index.tpl to 5 minutes - $smarty->setCacheLifetime(300); - $smarty->display('index.tpl'); - - // set the cache_lifetime for home.tpl to 1 hour - $smarty->setCacheLifetime(3600); - $smarty->display('home.tpl'); - - // NOTE: the following $cache_lifetime setting will not work when $caching - // is set to Smarty::CACHING_LIFETIME_SAVED. - // The cache lifetime for home.tpl has already been set - // to 1 hour, and will no longer respect the value of $cache_lifetime. - // The home.tpl cache will still expire after 1 hour. - $smarty->setCacheLifetime(30); // 30 seconds - $smarty->display('home.tpl'); - ?> - - - -If [`$compile_check`](#variable.compile.check) is enabled (default), -every template file and config file that is involved with the cache file -is checked for modification. If any of the files have been modified -since the cache was generated, the cache is immediately regenerated. -This is a computational overhead, so for optimum performance set -[`$compile_check`](#variable.compile.check) to FALSE. - - - setCaching(Smarty::CACHING_LIFETIME_CURRENT); - $smarty->setCompileCheck(false); - - $smarty->display('index.tpl'); - ?> - - - -If [`$force_compile`](#variable.force.compile) is enabled, the cache -files will always be regenerated. This effectively disables caching, -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. - -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 -requires something like a database fetch, you can use this to skip that -process. - - - setCaching(Smarty::CACHING_LIFETIME_CURRENT); - - if(!$smarty->isCached('index.tpl')) { - // No cache available, do variable assignments here. - $contents = get_database_contents(); - $smarty->assign($contents); - } - - $smarty->display('index.tpl'); - ?> - - - -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` 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. - -You can clear all the cache files with the -[`clearAllCache()`](#api.clear.all.cache) function, or individual cache -files [and groups](#caching.groups) with the -[`clearCache()`](#api.clear.cache) function. - - - setCaching(Smarty::CACHING_LIFETIME_CURRENT); - - // clear only cache for index.tpl - $smarty->clearCache('index.tpl'); - - // clear out all cache files - $smarty->clearAllCache(); - - $smarty->display('index.tpl'); - ?> - - diff --git a/docs/programmers/charset.md b/docs/programmers/charset.md deleted file mode 100644 index 9dedf4dcd..000000000 --- a/docs/programmers/charset.md +++ /dev/null @@ -1,44 +0,0 @@ -Charset Encoding {#charset} -================ - -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. - -> **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 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. -> -> Since unicode and UTF-8 are very wide spread nowadays, their use is -> strongly encouraged. - -> **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. - - - // use japanese character encoding - if (function_exists('mb_internal_charset')) { - mb_internal_charset('EUC-JP'); - } - - require_once 'libs/Smarty.class.php'; - Smarty::$_CHARSET = 'EUC-JP'; - $smarty = new Smarty(); - - diff --git a/docs/programmers/plugins.md b/docs/programmers/plugins.md deleted file mode 100644 index 41a7ea0c4..000000000 --- a/docs/programmers/plugins.md +++ /dev/null @@ -1,44 +0,0 @@ -Extending Smarty With Plugins {#plugins} -============================= - -## Table of contents - -- [How Plugins Work](./plugins/plugins-howto.md) -- [Naming Conventions](./plugins/plugins-naming-conventions.md) -- [Writing Plugins](./plugins/plugins-writing.md) -- [Template Functions](./plugins/plugins-functions.md) -- [Modifiers](./plugins/plugins-modifiers.md) -- [Block Functions](./plugins/plugins-block-functions.md) -- [Compiler Functions](./plugins/plugins-compiler-functions.md) -- [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: - -- functions - -- modifiers - -- block functions - -- compiler functions - -- prefilters - -- postfilters - -- outputfilters - -- resources - -- inserts - -With the exception of resources, backwards compatibility with the old -way of registering handler functions via register\_\* API is preserved. -If you did not use the API but instead modified the class variables -`$custom_funcs`, `$custom_mods`, and other ones directly, then you will -need to adjust your scripts to either use the API or convert your custom -functionality into plugins. diff --git a/docs/programmers/plugins/plugins-block-functions.md b/docs/programmers/plugins/plugins-block-functions.md deleted file mode 100644 index 0e11c0782..000000000 --- a/docs/programmers/plugins/plugins-block-functions.md +++ /dev/null @@ -1,95 +0,0 @@ -Block Functions {#plugins.block.functions} -=============== - -void - -smarty\_block\_ - -name - -array - -\$params - -mixed - -\$content - -object - -\$template - -boolean - -&\$repeat - -Block functions are functions of the form: `{func} .. {/func}`. In other -words, they enclose a template block and operate on the contents of this -block. Block functions take precedence over [custom -functions](#language.custom.functions) of the same name, that is, you -cannot have both custom function `{func}` and block function -`{func}..{/func}`. - -- By default your function implementation is called twice by Smarty: - once for the opening tag, and once for the closing tag. (See - `$repeat` below on how to change this.) - -- Starting with Smarty 3.1 the returned value of the opening tag call - is displayed as well. - -- Only the opening tag of the block function may have - [attributes](#language.syntax.attributes). All attributes passed to - template functions from the template are contained in the `$params` - variable as an associative array. The opening tag attributes are - also accessible to your function when processing the closing tag. - -- The value of the `$content` variable depends on whether your - function is called for the opening or closing tag. In case of the - opening tag, it will be NULL, and in case of the closing tag it will - be the contents of the template block. Note that the template block - will have already been processed by Smarty, so all you will receive - is the template output, not the template source. - -- The parameter `$repeat` is passed by reference to the function - implementation and provides a possibility for it to control how many - times the block is displayed. By default `$repeat` is TRUE at the - first call of the block-function (the opening tag) and FALSE on all - subsequent calls to the block function (the block\'s closing tag). - Each time the function implementation returns with `$repeat` being - TRUE, the contents between `{func}...{/func}` are evaluated and the - 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()`](https://www.php.net/var_dump) on it and the -structure should be apparent. - - - - - - -See also: [`registerPlugin()`](#api.register.plugin), -[`unregisterPlugin()`](#api.unregister.plugin). diff --git a/docs/programmers/plugins/plugins-compiler-functions.md b/docs/programmers/plugins/plugins-compiler-functions.md deleted file mode 100644 index ef2454e8a..000000000 --- a/docs/programmers/plugins/plugins-compiler-functions.md +++ /dev/null @@ -1,66 +0,0 @@ -Compiler Functions {#plugins.compiler.functions} -================== - -Compiler functions are called only during compilation of the template. -They are useful for injecting PHP code or time-sensitive static content -into the template. If there is both a compiler function and a [custom -function](#language.custom.functions) registered under the same name, -the compiler function has precedence. - -mixed - -smarty\_compiler\_ - -name - -array - -\$params - -object - -\$smarty - -The compiler function is passed two parameters: the params array which -contains precompiled strings for the attribute values and the Smarty -object. It\'s supposed to return the code to be injected into the -compiled template including the surrounding PHP tags. - - - _current_file . " compiled at " . date('Y-m-d H:M'). "';\n?>"; - } - ?> - -This function can be called from the template as: - - - {* this function gets executed at compile time only *} - {tplheader} - - - -The resulting PHP code in the compiled template would be something like -this: - - - - - - -See also [`registerPlugin()`](#api.register.plugin), -[`unregisterPlugin()`](#api.unregister.plugin). diff --git a/docs/programmers/plugins/plugins-functions.md b/docs/programmers/plugins/plugins-functions.md deleted file mode 100644 index 067b93826..000000000 --- a/docs/programmers/plugins/plugins-functions.md +++ /dev/null @@ -1,94 +0,0 @@ -Template Functions {#plugins.functions} -================== - -void - -smarty\_function\_ - -name - -array - -\$params - -object - -\$template - -All [attributes](#language.syntax.attributes) passed to template -functions from the template are contained in the `$params` as an -associative array. - -The output (return value) of the function will be substituted in place -of the function tag in the template, eg the -[`{fetch}`](#language.function.fetch) function. Alternatively, the -function can simply perform some other task without any output, eg the -[`{assign}`](#language.function.assign) function. - -If the function needs to assign some variables to the template or use -some other Smarty-provided functionality, it can use the supplied -`$template` object to do so eg `$template->foo()`. - - - - -which can be used in the template as: - - Question: Will we ever have time travel? - Answer: {eightball}. - - - - assign($params['var'], $params['value']); - - } - ?> - - - -See also: [`registerPlugin()`](#api.register.plugin), -[`unregisterPlugin()`](#api.unregister.plugin). diff --git a/docs/programmers/plugins/plugins-howto.md b/docs/programmers/plugins/plugins-howto.md deleted file mode 100644 index 5738c3fcb..000000000 --- a/docs/programmers/plugins/plugins-howto.md +++ /dev/null @@ -1,18 +0,0 @@ -How Plugins Work {#plugins.howto} -================ - -Plugins are always loaded on demand. Only the specific modifiers, -functions, resources, etc invoked in the templates scripts will be -loaded. Moreover, each plugin is loaded only once, even if you have -several different instances of Smarty running within the same request. - -Pre/postfilters and output filters are a bit of a special case. Since -they are not mentioned in the templates, they must be registered or -loaded explicitly via API functions before the template is processed. -The order in which multiple filters of the same type are executed -depends on the order in which they are registered or loaded. - -The [plugins directory](#variable.plugins.dir) can be a string -containing a path or an array containing multiple paths. To install a -plugin, simply place it in one of the directories and Smarty will use it -automatically. diff --git a/docs/programmers/plugins/plugins-inserts.md b/docs/programmers/plugins/plugins-inserts.md deleted file mode 100644 index 370a97bd0..000000000 --- a/docs/programmers/plugins/plugins-inserts.md +++ /dev/null @@ -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. - - - - - diff --git a/docs/programmers/plugins/plugins-modifiers.md b/docs/programmers/plugins/plugins-modifiers.md deleted file mode 100644 index a4e99daa3..000000000 --- a/docs/programmers/plugins/plugins-modifiers.md +++ /dev/null @@ -1,86 +0,0 @@ -Modifiers {#plugins.modifiers} -========= - -[Modifiers](#language.modifiers) are little functions that are applied -to a variable in the template before it is displayed or used in some -other context. Modifiers can be chained together. - -mixed - -smarty\_modifier\_ - -name - -mixed - -\$value - -\[mixed - -\$param1 - -, \...\] - -The first parameter to the modifier plugin is the value on which the -modifier is to operate. The rest of the parameters are optional, -depending on what kind of operation is to be performed. - -The modifier has to [return](https://www.php.net/return) the result of its -processing. - -This plugin basically aliases one of the built-in PHP functions. It does -not have any additional parameters. - - - - - - $length) { - $length -= strlen($etc); - $fragment = substr($string, 0, $length+1); - if ($break_words) - $fragment = substr($fragment, 0, -1); - else - $fragment = preg_replace('/\s+(\S+)?$/', '', $fragment); - return $fragment.$etc; - } else - return $string; - } - ?> - - - -See also [`registerPlugin()`](#api.register.plugin), -[`unregisterPlugin()`](#api.unregister.plugin). diff --git a/docs/programmers/plugins/plugins-naming-conventions.md b/docs/programmers/plugins/plugins-naming-conventions.md deleted file mode 100644 index 15bc26015..000000000 --- a/docs/programmers/plugins/plugins-naming-conventions.md +++ /dev/null @@ -1,51 +0,0 @@ -Naming Conventions {#plugins.naming.conventions} -================== - -Plugin files and functions must follow a very specific naming convention -in order to be located by Smarty. - -**plugin files** must be named as follows: - -> ` -> type.name.php -> ` - -- Where `type` is one of these plugin types: - - - function - - - modifier - - - block - - - compiler - - - prefilter - - - postfilter - - - outputfilter - - - resource - - - insert - -- And `name` should be a valid identifier; letters, numbers, and - underscores only, see [php - variables](https://www.php.net/language.variables). - -- Some examples: `function.html_select_date.php`, `resource.db.php`, - `modifier.spacify.php`. - -**plugin functions** inside the PHP files must be named as follows: - -> `smarty_type_name` - -- The meanings of `type` and `name` are the same as above. - -- An example modifier name `foo` would be - `function smarty_modifier_foo()`. - -Smarty will output appropriate error messages if the plugin file it -needs is not found, or if the file or the plugin function are named -improperly. diff --git a/docs/programmers/plugins/plugins-outputfilters.md b/docs/programmers/plugins/plugins-outputfilters.md deleted file mode 100644 index 4e34ab7eb..000000000 --- a/docs/programmers/plugins/plugins-outputfilters.md +++ /dev/null @@ -1,48 +0,0 @@ -Output Filters {#plugins.outputfilters} -============== - -Output filter plugins operate on a template\'s output, after the -template is loaded and executed, but before the output is displayed. - -string - -smarty\_outputfilter\_ - -name - -string - -\$template\_output - -object - -\$template - -The first parameter to the output filter function is the template output -that needs to be processed, and the second parameter is the instance of -Smarty invoking the plugin. The plugin is supposed to do the processing -and return the results. - - - - - - -See also [`registerFilter()`](#api.register.filter), -[`unregisterFilter()`](#api.unregister.filter). diff --git a/docs/programmers/plugins/plugins-prefilters-postfilters.md b/docs/programmers/plugins/plugins-prefilters-postfilters.md deleted file mode 100644 index 39467cbcb..000000000 --- a/docs/programmers/plugins/plugins-prefilters-postfilters.md +++ /dev/null @@ -1,89 +0,0 @@ -Prefilters/Postfilters {#plugins.prefilters.postfilters} -====================== - -Prefilter and postfilter plugins are very similar in concept; where they -differ is in the execution \-- more precisely the time of their -execution. - -string - -smarty\_prefilter\_ - -name - -string - -\$source - -object - -\$template - -Prefilters are used to process the source of the template immediately -before compilation. The first parameter to the prefilter function is the -template source, possibly modified by some other prefilters. The plugin -is supposed to return the modified source. Note that this source is not -saved anywhere, it is only used for compilation. - -string - -smarty\_postfilter\_ - -name - -string - -\$compiled - -object - -\$template - -Postfilters are used to process the compiled output of the template (the -PHP code) immediately after the compilation is done but before the -compiled template is saved to the filesystem. The first parameter to the -postfilter function is the compiled template code, possibly modified by -other postfilters. The plugin is supposed to return the modified version -of this code. - - - ]+>!e', 'strtolower("$1")', $source); - } - ?> - - - - - \ngetTemplateVars()); ?>\n" . $compiled; - return $compiled; - } - ?> - - - -See also [`registerFilter()`](#api.register.filter) and -[`unregisterFilter()`](#api.unregister.filter). diff --git a/docs/programmers/plugins/plugins-resources.md b/docs/programmers/plugins/plugins-resources.md deleted file mode 100644 index 1b1fdf0ab..000000000 --- a/docs/programmers/plugins/plugins-resources.md +++ /dev/null @@ -1,128 +0,0 @@ -Resources {#plugins.resources} -========= - -Resource plugins are meant as a generic way of providing template -sources or PHP script components to Smarty. Some examples of resources: -databases, LDAP, shared memory, sockets, and so on. - -Custom Resources may be put in a file `resource.foobarxyz.php` within -your [`$plugins_dir`](#variable.plugins.dir), or registered on runtime -with [`registerResource()`](#api.register.resource). In either case you -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`. -The Resource Handler must then implement the function -`renderUncompiled(Smarty_Internal_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 -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. - -If the Resource\'s compiled templates should not be cached on disk, the -Custom Resource may extend `Smarty_Resource_Recompiled`. 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 -example. - - - CREATE TABLE IF NOT EXISTS `templates` ( - * `name` varchar(100) NOT NULL, - * `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - * `source` text, - * PRIMARY KEY (`name`) - * ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - * - * Demo data: - *
INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');
- * - * @package Resource-examples - * @author Rodney Rehm - */ - class Smarty_Resource_Mysql extends Smarty_Resource_Custom { - // PDO instance - protected $db; - // prepared fetch() statement - protected $fetch; - // prepared fetchTimestamp() statement - protected $mtime; - - public function __construct() { - try { - $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty"); - } catch (PDOException $e) { - throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); - } - $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); - $this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name'); - } - - /** - * Fetch a template and its modification time from database - * - * @param string $name template name - * @param string $source template source - * @param integer $mtime template modification timestamp (epoch) - * @return void - */ - protected function fetch($name, &$source, &$mtime) - { - $this->fetch->execute(array('name' => $name)); - $row = $this->fetch->fetch(); - $this->fetch->closeCursor(); - if ($row) { - $source = $row['source']; - $mtime = strtotime($row['modified']); - } else { - $source = null; - $mtime = null; - } - } - - /** - * Fetch a template's modification time from database - * - * @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source. - * @param string $name template name - * @return integer timestamp (epoch) the template was modified - */ - protected function fetchTimestamp($name) { - $this->mtime->execute(array('name' => $name)); - $mtime = $this->mtime->fetchColumn(); - $this->mtime->closeCursor(); - return strtotime($mtime); - } - } - - - require_once 'libs/Smarty.class.php'; - $smarty = new Smarty(); - $smarty->registerResource('mysql', new Smarty_Resource_Mysql()); - - // using resource from php script - $smarty->display("mysql:index.tpl"); - ?> - - - -And from within Smarty template: - - - {include file='mysql:extras/navigation.tpl'} - - - -See also [`registerResource()`](#api.register.resource), -[`unregisterResource()`](#api.unregister.resource). diff --git a/docs/programmers/plugins/plugins-writing.md b/docs/programmers/plugins/plugins-writing.md deleted file mode 100644 index 972911d97..000000000 --- a/docs/programmers/plugins/plugins-writing.md +++ /dev/null @@ -1,36 +0,0 @@ -Writing Plugins {#plugins.writing} -=============== - -Plugins can be either loaded by Smarty automatically from the filesystem -or they can be registered at runtime via one of the register\_\* API -functions. They can also be unregistered by using unregister\_\* API -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: - - - 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: - -- modifiers do not get passed the Smarty\_Internal\_Template object at - all - -- blocks get passed `$repeat` after the Smarty\_Internal\_Template - object to keep backwards compatibility to older versions of Smarty. diff --git a/docs/programmers/resources.md b/docs/programmers/resources.md deleted file mode 100644 index 239690061..000000000 --- a/docs/programmers/resources.md +++ /dev/null @@ -1,19 +0,0 @@ -Resources -========= - -The templates may come from a variety of sources. When you -[`display()`](./api-functions/api-display.md) or [`fetch()`](./api-functions/api-fetch.md) a template, or -when you include a template from within another template, you supply a -resource type, followed by the appropriate path and template name. If a -resource is not explicitly given, the value of -[`$default_resource_type`](./api-variables/variable-default-resource-type.md) (default: -\"file\") is assumed. - -## Table of contents - -- [File Template Resources](./resources/resources-file.md) -- [String Template Resources](./resources/resources-string.md) -- [Stream Template Resources](./resources/resources-streams.md) -- [Extends Template Resources](./resources/resources-extends.md) -- [Custom Template Resources](./resources/resources-custom.md) - diff --git a/docs/programmers/resources/resources-custom.md b/docs/programmers/resources/resources-custom.md deleted file mode 100644 index d679afcb1..000000000 --- a/docs/programmers/resources/resources-custom.md +++ /dev/null @@ -1,111 +0,0 @@ -Custom Template Resources {#resources.custom} -========================= - -You can retrieve templates using whatever possible source you can access -with PHP: databases, sockets, files, etc. You do this by writing -resource plugin functions and registering them with Smarty. - -See [resource plugins](#plugins.resources) section for more information -on the functions you are supposed to provide. - -> **Note** -> -> Note that you cannot override the built-in `file:` resource, but you -> can provide a resource that fetches templates from the file system in -> some other way by registering under another resource name. - - - CREATE TABLE IF NOT EXISTS `templates` ( - * `name` varchar(100) NOT NULL, - * `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - * `source` text, - * PRIMARY KEY (`name`) - * ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - * - * Demo data: - *
INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');
- * - * @package Resource-examples - * @author Rodney Rehm - */ - class Smarty_Resource_Mysql extends Smarty_Resource_Custom { - // PDO instance - protected $db; - // prepared fetch() statement - protected $fetch; - // prepared fetchTimestamp() statement - protected $mtime; - - public function __construct() { - try { - $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty"); - } catch (PDOException $e) { - throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); - } - $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); - $this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name'); - } - - /** - * Fetch a template and its modification time from database - * - * @param string $name template name - * @param string $source template source - * @param integer $mtime template modification timestamp (epoch) - * @return void - */ - protected function fetch($name, &$source, &$mtime) - { - $this->fetch->execute(array('name' => $name)); - $row = $this->fetch->fetch(); - $this->fetch->closeCursor(); - if ($row) { - $source = $row['source']; - $mtime = strtotime($row['modified']); - } else { - $source = null; - $mtime = null; - } - } - - /** - * Fetch a template's modification time from database - * - * @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source. - * @param string $name template name - * @return integer timestamp (epoch) the template was modified - */ - protected function fetchTimestamp($name) { - $this->mtime->execute(array('name' => $name)); - $mtime = $this->mtime->fetchColumn(); - $this->mtime->closeCursor(); - return strtotime($mtime); - } - } - - - require_once 'libs/Smarty.class.php'; - $smarty = new Smarty(); - $smarty->registerResource('mysql', new Smarty_Resource_Mysql()); - - // using resource from php script - $smarty->display("mysql:index.tpl"); - ?> - - - -And from within Smarty template: - - - {include file='mysql:extras/navigation.tpl'} - - diff --git a/docs/programmers/resources/resources-extends.md b/docs/programmers/resources/resources-extends.md deleted file mode 100644 index d7213d894..000000000 --- a/docs/programmers/resources/resources-extends.md +++ /dev/null @@ -1,36 +0,0 @@ -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 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 -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 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. - - - display('extends:parent.tpl|child.tpl|grandchild.tpl'); - - // inheritance from multiple template sources - $smarty->display('extends:db:parent.tpl|file:child.tpl|grandchild.tpl|eval:{block name="fooBazVar_"}hello world{/block}'); - ?> - - - -See also [Template Inheritance](#advanced.features.template.inheritance) -[`{block}`](#language.function.block) and -[`{extends}`](#language.function.extends). diff --git a/docs/programmers/resources/resources-file.md b/docs/programmers/resources/resources-file.md deleted file mode 100644 index 9a89af183..000000000 --- a/docs/programmers/resources/resources-file.md +++ /dev/null @@ -1,160 +0,0 @@ -File Template Resources {#resources.file} -======================= - -Smarty ships with a built-in template resource for the filesystem. The -`file:` is the default resource. The resource key `file:` must only be -specified, if the -[`$default_resource_type`](#variable.default.resource.type) has been -changed. - -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](https://www.php.net/ini.core.php#ini.include-path) unless -> [`$use_include_path` is activated](#variable.use.include.path) - -Templates from \$template\_dir {#templates.from.template.dir} ------------------------------- - -The file resource pulls templates source files from the directories -specified in [`$template_dir`](#variable.template.dir). The list of -directories is traversed in the order they appear in the array. The -first template found is the one to process. - - - display('index.tpl'); - $smarty->display('file:index.tpl'); // same as above - ?> - - - -From within a Smarty template - - - {include file='index.tpl'} - {include file='file:index.tpl'} {* same as above *} - - - -Templates from a specific \$template\_dir {#templates.from.specified.template.dir} ------------------------------------------ - -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 access. - -The bracket-syntax can be used from anywhere you can specify the `file:` -resource type. - - - setTemplateDir(array( - './templates', // element: 0, index: 0 - './templates_2', // element: 1, index: 1 - '10' => 'templates_10', // element: 2, index: '10' - 'foo' => 'templates_foo', // element: 3, index: 'foo' - )); - - /* - assume the template structure - ./templates/foo.tpl - ./templates_2/foo.tpl - ./templates_2/bar.tpl - ./templates_10/foo.tpl - ./templates_10/bar.tpl - ./templates_foo/foo.tpl - */ - - // regular access - $smarty->display('file:foo.tpl'); - // will load ./templates/foo.tpl - - // using numeric index - $smarty->display('file:[1]foo.tpl'); - // will load ./templates_2/foo.tpl - - // using numeric string index - $smarty->display('file:[10]foo.tpl'); - // will load ./templates_10/foo.tpl - - // using string index - $smarty->display('file:[foo]foo.tpl'); - // will load ./templates_foo/foo.tpl - - // using "unknown" numeric index (using element number) - $smarty->display('file:[2]foo.tpl'); - // will load ./templates_10/foo.tpl - - ?> - - - -From within a Smarty template - - - {include file="file:foo.tpl"} - {* will load ./templates/foo.tpl *} - - {include file="file:[1]foo.tpl"} - {* will load ./templates_2/foo.tpl *} - - {include file="file:[foo]foo.tpl"} - {* will load ./templates_foo/foo.tpl *} - - - -Templates from any directory {#templates.from.any.dir} ----------------------------- - -Templates outside of the [`$template_dir`](#variable.template.dir) -require the `file:` template resource type, followed by the absolute -path to the template (with leading slash.) - -> **Note** -> -> With [`Security`](#advanced.features.security) enabled, access to -> templates outside of the [`$template_dir`](#variable.template.dir) is -> not allowed unless you list those directories in `$secure_dir`. - - - display('file:/export/templates/index.tpl'); - $smarty->display('file:/path/to/my/templates/menu.tpl'); - ?> - - - -And from within a Smarty template: - - - {include file='file:/usr/local/share/templates/navigation.tpl'} - - - -Windows Filepaths {#templates.windows.filepath} ------------------ - -If you are using a Windows machine, filepaths usually include a drive -letter (C:) at the beginning of the pathname. Be sure to use `file:` in -the path to avoid namespace conflicts and get the desired results. - - - display('file:C:/export/templates/index.tpl'); - $smarty->display('file:F:/path/to/my/templates/menu.tpl'); - ?> - - - -And from within Smarty template: - - - {include file='file:D:/usr/local/share/templates/navigation.tpl'} diff --git a/docs/programmers/resources/resources-streams.md b/docs/programmers/resources/resources-streams.md deleted file mode 100644 index e0596f591..000000000 --- a/docs/programmers/resources/resources-streams.md +++ /dev/null @@ -1,27 +0,0 @@ -Stream Template Resources {#resources.streams} -========================= - -Streams allow you to use PHP streams as a template resource. The syntax -is much the same a traditional template resource names. - -Smarty will first look for a registered template resource. If nothing is -found, it will check if a PHP stream is available. If a stream is -available, Smarty will use it to fetch the template. - -> **Note** -> -> You can further define allowed streams with security enabled. - -Using a PHP stream for a template resource from the display() function. - - - $smarty->display('foo:bar.tpl'); - - - -Using a PHP stream for a template resource from within a template. - - - {include file="foo:bar.tpl"} - - diff --git a/docs/programmers/resources/resources-string.md b/docs/programmers/resources/resources-string.md deleted file mode 100644 index d3f6d4155..000000000 --- a/docs/programmers/resources/resources-string.md +++ /dev/null @@ -1,73 +0,0 @@ -String Template Resources {#resources.string} -========================= - -Smarty can render templates from a string by using the `string:` or -`eval:` resource. - -- The `string:` resource behaves much the same as a template file. The - template source is compiled from a string and stores the compiled - template code for later reuse. Each unique template string will - create a new compiled template file. If your template strings are - accessed frequently, this is a good choice. If you have frequently - changing template strings (or strings with low reuse value), the - `eval:` resource may be a better choice, as it doesn\'t save - compiled templates to disk. - -- The `eval:` resource evaluates the template source every time a page - is rendered. This is a good choice for strings with low reuse value. - If the same string is accessed frequently, the `string:` resource - may be a better choice. - -> **Note** -> -> With a `string:` resource type, each unique string generates a -> compiled file. Smarty cannot detect a string that has changed, and -> therefore will generate a new compiled file for each unique string. It -> is important to choose the correct resource so that you do not fill -> your disk space with wasted compiled strings. - - - assign('foo','value'); - $template_string = 'display {$foo} here'; - $smarty->display('string:'.$template_string); // compiles for later reuse - $smarty->display('eval:'.$template_string); // compiles every time - ?> - - - -From within a Smarty template - - - {include file="string:$template_string"} {* compiles for later reuse *} - {include file="eval:$template_string"} {* compiles every time *} - - - - -Both `string:` and `eval:` resources may be encoded with -[`urlencode()`](https://www.php.net/urlencode) or -[`base64_encode()`](https://www.php.net/urlencode). This is not necessary -for the usual use of `string:` and `eval:`, but is required when using -either of them in conjunction with -[`Extends Template Resource`](#resources.extends) - - - assign('foo','value'); - $template_string_urlencode = urlencode('display {$foo} here'); - $template_string_base64 = base64_encode('display {$foo} here'); - $smarty->display('eval:urlencode:'.$template_string_urlencode); // will decode string using urldecode() - $smarty->display('eval:base64:'.$template_string_base64); // will decode string using base64_decode() - ?> - - - -From within a Smarty template - - - {include file="string:urlencode:$template_string_urlencode"} {* will decode string using urldecode() *} - {include file="eval:base64:$template_string_base64"} {* will decode string using base64_decode() *} - - - diff --git a/docs/programmers/resources/template-resources.md b/docs/programmers/resources/template-resources.md deleted file mode 100644 index 7bb5d752e..000000000 --- a/docs/programmers/resources/template-resources.md +++ /dev/null @@ -1,130 +0,0 @@ -Resources {#resasdources} -========= - -The templates may come from a variety of sources. When you -[`display()`](#api.display) or [`fetch()`](#api.fetch) a template, or -when you include a template from within another template, you supply a -resource type, followed by the appropriate path and template name. If a -resource is not explicitly given, the value of -[`$default_resource_type`](#variable.default.resource.type) is assumed. - -Templates from other sources {#templates.from.elsewhere} ----------------------------- - -You can retrieve templates using whatever possible source you can access -with PHP: databases, sockets, files, etc. You do this by writing -resource plugin functions and registering them with Smarty. - -See [resource plugins](#plugins.resources) section for more information -on the functions you are supposed to provide. - -> **Note** -> -> Note that you cannot override the built-in `file:` resource, but you -> can provide a resource that fetches templates from the file system in -> some other way by registering under another resource name. - - - CREATE TABLE IF NOT EXISTS `templates` ( - * `name` varchar(100) NOT NULL, - * `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - * `source` text, - * PRIMARY KEY (`name`) - * ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - * - * Demo data: - *
INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');
- * - * @package Resource-examples - * @author Rodney Rehm - */ - class Smarty_Resource_Mysql extends Smarty_Resource_Custom { - // PDO instance - protected $db; - // prepared fetch() statement - protected $fetch; - // prepared fetchTimestamp() statement - protected $mtime; - - public function __construct() { - try { - $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty"); - } catch (PDOException $e) { - throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); - } - $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); - $this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name'); - } - - /** - * Fetch a template and its modification time from database - * - * @param string $name template name - * @param string $source template source - * @param integer $mtime template modification timestamp (epoch) - * @return void - */ - protected function fetch($name, &$source, &$mtime) - { - $this->fetch->execute(array('name' => $name)); - $row = $this->fetch->fetch(); - $this->fetch->closeCursor(); - if ($row) { - $source = $row['source']; - $mtime = strtotime($row['modified']); - } else { - $source = null; - $mtime = null; - } - } - - /** - * Fetch a template's modification time from database - * - * @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source. - * @param string $name template name - * @return integer timestamp (epoch) the template was modified - */ - protected function fetchTimestamp($name) { - $this->mtime->execute(array('name' => $name)); - $mtime = $this->mtime->fetchColumn(); - $this->mtime->closeCursor(); - return strtotime($mtime); - } - } - - - require_once 'libs/Smarty.class.php'; - $smarty = new Smarty(); - $smarty->registerResource('mysql', new Smarty_Resource_Mysql()); - - // using resource from php script - $smarty->display("mysql:index.tpl"); - ?> - - - -And from within Smarty template: - - - {include file='mysql:extras/navigation.tpl'} - - - -Default template handler function {#default.template.handler.function} ---------------------------------- - -You can specify a function that is used to retrieve template contents in -the event the template cannot be retrieved from its resource. One use of -this is to create templates that do not exist on-the-fly. - -See also [`Streams`](#advanced.features.streams) diff --git a/docs/programmers/smarty-constants.md b/docs/programmers/smarty-constants.md deleted file mode 100644 index de04e1b59..000000000 --- a/docs/programmers/smarty-constants.md +++ /dev/null @@ -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/**. - - - - - - -See also [`$smarty.const`](../designers/language-variables/language-variables-smarty.md). diff --git a/libs/Autoloader.php b/libs/Autoloader.php deleted file mode 100644 index da7e32abf..000000000 --- a/libs/Autoloader.php +++ /dev/null @@ -1,111 +0,0 @@ - '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; - } -} diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php deleted file mode 100644 index 71734274f..000000000 --- a/libs/Smarty.class.php +++ /dev/null @@ -1,1405 +0,0 @@ - - * @author Uwe Tews - * @author Rodney Rehm - * @package Smarty - */ -/** - * set SMARTY_DIR to absolute path to Smarty library files. - * Sets SMARTY_DIR only if user application has not already defined it. - */ -if (!defined('SMARTY_DIR')) { - /** - * - */ - define('SMARTY_DIR', __DIR__ . DIRECTORY_SEPARATOR); -} -/** - * set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins. - * Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it. - */ -if (!defined('SMARTY_SYSPLUGINS_DIR')) { - /** - * - */ - define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR); -} -if (!defined('SMARTY_PLUGINS_DIR')) { - /** - * - */ - define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DIRECTORY_SEPARATOR); -} -if (!defined('SMARTY_MBSTRING')) { - /** - * - */ - define('SMARTY_MBSTRING', function_exists('mb_get_info')); -} - -/** - * Load helper functions - */ -if (!defined('SMARTY_HELPER_FUNCTIONS_LOADED')) { - include __DIR__ . '/functions.php'; -} - -/** - * Load Smarty_Autoloader - */ -if (!class_exists('Smarty_Autoloader')) { - include __DIR__ . '/bootstrap.php'; -} - -/** - * Load always needed external class files - */ -require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php'; -require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_extension_handler.php'; -require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php'; -require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php'; -require_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php'; -require_once SMARTY_SYSPLUGINS_DIR . 'smarty_variable.php'; -require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_source.php'; -require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php'; -require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php'; - -/** - * This is the main Smarty class - * - * @package Smarty - * - * The following methods will be dynamically loaded by the extension handler when they are called. - * They are located in a corresponding Smarty_Internal_Method_xxxx class - * - * @method int clearAllCache(int $exp_time = null, string $type = null) - * @method int clearCache(string $template_name, string $cache_id = null, string $compile_id = null, int $exp_time = null, string $type = null) - * @method int compileAllTemplates(string $extension = '.tpl', bool $force_compile = false, int $time_limit = 0, $max_errors = null) - * @method int compileAllConfig(string $extension = '.conf', bool $force_compile = false, int $time_limit = 0, $max_errors = null) - * @method int clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null) - */ -class Smarty extends Smarty_Internal_TemplateBase -{ - /** - * smarty version - */ - const SMARTY_VERSION = '4.3.2'; - /** - * define variable scopes - */ - const SCOPE_LOCAL = 1; - const SCOPE_PARENT = 2; - const SCOPE_TPL_ROOT = 4; - const SCOPE_ROOT = 8; - const SCOPE_SMARTY = 16; - const SCOPE_GLOBAL = 32; - /** - * define caching modes - */ - const CACHING_OFF = 0; - const CACHING_LIFETIME_CURRENT = 1; - const CACHING_LIFETIME_SAVED = 2; - /** - * define constant for clearing cache files be saved expiration dates - */ - const CLEAR_EXPIRED = -1; - /** - * define compile check modes - */ - const COMPILECHECK_OFF = 0; - const COMPILECHECK_ON = 1; - const COMPILECHECK_CACHEMISS = 2; - /** - * define debug modes - */ - const DEBUG_OFF = 0; - const DEBUG_ON = 1; - const DEBUG_INDIVIDUAL = 2; - - /** - * filter types - */ - const FILTER_POST = 'post'; - const FILTER_PRE = 'pre'; - const FILTER_OUTPUT = 'output'; - const FILTER_VARIABLE = 'variable'; - /** - * plugin types - */ - const PLUGIN_FUNCTION = 'function'; - const PLUGIN_BLOCK = 'block'; - const PLUGIN_COMPILER = 'compiler'; - const PLUGIN_MODIFIER = 'modifier'; - const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler'; - - /** - * assigned global tpl vars - */ - public static $global_tpl_vars = array(); - - /** - * Flag denoting if Multibyte String functions are available - */ - public static $_MBSTRING = SMARTY_MBSTRING; - - /** - * The character set to adhere to (e.g. "UTF-8") - */ - public static $_CHARSET = SMARTY_MBSTRING ? 'UTF-8' : 'ISO-8859-1'; - - /** - * The date format to be used internally - * (accepts date() and strftime()) - */ - public static $_DATE_FORMAT = '%b %e, %Y'; - - /** - * Flag denoting if PCRE should run in UTF-8 mode - */ - public static $_UTF8_MODIFIER = 'u'; - - /** - * Flag denoting if operating system is windows - */ - public static $_IS_WINDOWS = false; - - /** - * auto literal on delimiters with whitespace - * - * @var boolean - */ - public $auto_literal = true; - - /** - * display error on not assigned variables - * - * @var boolean - */ - public $error_unassigned = false; - - /** - * look up relative file path in include_path - * - * @var boolean - */ - public $use_include_path = false; - - /** - * flag if template_dir is normalized - * - * @var bool - */ - public $_templateDirNormalized = false; - - /** - * joined template directory string used in cache keys - * - * @var string - */ - public $_joined_template_dir = null; - - /** - * flag if config_dir is normalized - * - * @var bool - */ - public $_configDirNormalized = false; - - /** - * joined config directory string used in cache keys - * - * @var string - */ - public $_joined_config_dir = null; - - /** - * default template handler - * - * @var callable - */ - public $default_template_handler_func = null; - - /** - * default config handler - * - * @var callable - */ - public $default_config_handler_func = null; - - /** - * default plugin handler - * - * @var callable - */ - public $default_plugin_handler_func = null; - - /** - * flag if template_dir is normalized - * - * @var bool - */ - public $_compileDirNormalized = false; - - /** - * flag if plugins_dir is normalized - * - * @var bool - */ - public $_pluginsDirNormalized = false; - - /** - * flag if template_dir is normalized - * - * @var bool - */ - public $_cacheDirNormalized = false; - - /** - * force template compiling? - * - * @var boolean - */ - public $force_compile = false; - - /** - * use sub dirs for compiled/cached files? - * - * @var boolean - */ - public $use_sub_dirs = false; - - /** - * allow ambiguous resources (that are made unique by the resource handler) - * - * @var boolean - */ - public $allow_ambiguous_resources = false; - - /** - * merge compiled includes - * - * @var boolean - */ - public $merge_compiled_includes = false; - - /* - * flag for behaviour when extends: resource and {extends} tag are used simultaneous - * if false disable execution of {extends} in templates called by extends resource. - * (behaviour as versions < 3.1.28) - * - * @var boolean - */ - public $extends_recursion = true; - - /** - * force cache file creation - * - * @var boolean - */ - public $force_cache = false; - - /** - * template left-delimiter - * - * @var string - */ - public $left_delimiter = "{"; - - /** - * template right-delimiter - * - * @var string - */ - public $right_delimiter = "}"; - - /** - * array of strings which shall be treated as literal by compiler - * - * @var array string - */ - public $literals = array(); - - /** - * class name - * This should be instance of Smarty_Security. - * - * @var string - * @see Smarty_Security - */ - public $security_class = 'Smarty_Security'; - - /** - * implementation of security class - * - * @var Smarty_Security - */ - public $security_policy = null; - - /** - * controls if the php template file resource is allowed - * - * @var bool - */ - public $allow_php_templates = false; - - /** - * debug mode - * Setting this to true enables the debug-console. - * - * @var boolean - */ - public $debugging = false; - - /** - * This determines if debugging is enable-able from the browser. - * - * - * @var string - */ - public $debugging_ctrl = 'NONE'; - - /** - * Name of debugging URL-param. - * Only used when $debugging_ctrl is set to 'URL'. - * The name of the URL-parameter that activates debugging. - * - * @var string - */ - public $smarty_debug_id = 'SMARTY_DEBUG'; - - /** - * Path of debug template. - * - * @var string - */ - public $debug_tpl = null; - - /** - * When set, smarty uses this value as error_reporting-level. - * - * @var int - */ - public $error_reporting = null; - - /** - * Controls whether variables with the same name overwrite each other. - * - * @var boolean - */ - public $config_overwrite = true; - - /** - * Controls whether config values of on/true/yes and off/false/no get converted to boolean. - * - * @var boolean - */ - public $config_booleanize = true; - - /** - * Controls whether hidden config sections/vars are read from the file. - * - * @var boolean - */ - public $config_read_hidden = false; - - /** - * locking concurrent compiles - * - * @var boolean - */ - public $compile_locking = true; - - /** - * Controls whether cache resources should use locking mechanism - * - * @var boolean - */ - public $cache_locking = false; - - /** - * seconds to wait for acquiring a lock before ignoring the write lock - * - * @var float - */ - public $locking_timeout = 10; - - /** - * resource type used if none given - * Must be an valid key of $registered_resources. - * - * @var string - */ - public $default_resource_type = 'file'; - - /** - * caching type - * Must be an element of $cache_resource_types. - * - * @var string - */ - public $caching_type = 'file'; - - /** - * config type - * - * @var string - */ - public $default_config_type = 'file'; - - /** - * check If-Modified-Since headers - * - * @var boolean - */ - public $cache_modified_check = false; - - /** - * registered plugins - * - * @var array - */ - public $registered_plugins = array(); - - /** - * registered objects - * - * @var array - */ - public $registered_objects = array(); - - /** - * registered classes - * - * @var array - */ - public $registered_classes = array(); - - /** - * registered filters - * - * @var array - */ - public $registered_filters = array(); - - /** - * registered resources - * - * @var array - */ - public $registered_resources = array(); - - /** - * registered cache resources - * - * @var array - */ - public $registered_cache_resources = array(); - - /** - * autoload filter - * - * @var array - */ - public $autoload_filters = array(); - - /** - * default modifier - * - * @var array - */ - public $default_modifiers = array(); - - /** - * autoescape variable output - * - * @var boolean - */ - public $escape_html = false; - - /** - * start time for execution time calculation - * - * @var int - */ - public $start_time = 0; - - /** - * required by the compiler for BC - * - * @var string - */ - public $_current_file = null; - - /** - * internal flag to enable parser debugging - * - * @var bool - */ - public $_parserdebug = false; - - /** - * This object type (Smarty = 1, template = 2, data = 4) - * - * @var int - */ - public $_objType = 1; - - /** - * Debug object - * - * @var Smarty_Internal_Debug - */ - public $_debug = null; - - /** - * template directory - * - * @var array - */ - protected $template_dir = array('./templates/'); - - /** - * flags for normalized template directory entries - * - * @var array - */ - protected $_processedTemplateDir = array(); - - /** - * config directory - * - * @var array - */ - protected $config_dir = array('./configs/'); - - /** - * flags for normalized template directory entries - * - * @var array - */ - protected $_processedConfigDir = array(); - - /** - * compile directory - * - * @var string - */ - protected $compile_dir = './templates_c/'; - - /** - * plugins directory - * - * @var array - */ - protected $plugins_dir = array(); - - /** - * cache directory - * - * @var string - */ - protected $cache_dir = './cache/'; - - /** - * removed properties - * - * @var string[] - */ - protected $obsoleteProperties = array( - 'resource_caching', 'template_resource_caching', 'direct_access_security', - '_dir_perms', '_file_perms', 'plugin_search_order', - 'inheritance_merge_compiled_includes', 'resource_cache_mode', - ); - - /** - * List of private properties which will call getter/setter on a direct access - * - * @var string[] - */ - protected $accessMap = array( - 'template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir', - 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir', - 'cache_dir' => 'CacheDir', - ); - - /** - * PHP7 Compatibility mode - * @var bool - */ - private $isMutingUndefinedOrNullWarnings = false; - - /** - * Initialize new Smarty object - */ - public function __construct() - { - $this->_clearTemplateCache(); - parent::__construct(); - if (is_callable('mb_internal_encoding')) { - mb_internal_encoding(Smarty::$_CHARSET); - } - $this->start_time = microtime(true); - if (isset($_SERVER[ 'SCRIPT_NAME' ])) { - Smarty::$global_tpl_vars[ 'SCRIPT_NAME' ] = new Smarty_Variable($_SERVER[ 'SCRIPT_NAME' ]); - } - // Check if we're running on windows - Smarty::$_IS_WINDOWS = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; - // let PCRE (preg_*) treat strings as ISO-8859-1 if we're not dealing with UTF-8 - if (Smarty::$_CHARSET !== 'UTF-8') { - Smarty::$_UTF8_MODIFIER = ''; - } - } - - /** - * Check if a template resource exists - * - * @param string $resource_name template name - * - * @return bool status - * @throws \SmartyException - */ - public function templateExists($resource_name) - { - // create source object - $source = Smarty_Template_Source::load(null, $this, $resource_name); - return $source->exists; - } - - /** - * Loads security class and enables security - * - * @param string|Smarty_Security $security_class if a string is used, it must be class-name - * - * @return Smarty current Smarty instance for chaining - * @throws \SmartyException - */ - public function enableSecurity($security_class = null) - { - Smarty_Security::enableSecurity($this, $security_class); - return $this; - } - - /** - * Disable security - * - * @return Smarty current Smarty instance for chaining - */ - public function disableSecurity() - { - $this->security_policy = null; - return $this; - } - - /** - * Add template directory(s) - * - * @param string|array $template_dir directory(s) of template sources - * @param string $key of the array element to assign the template dir to - * @param bool $isConfig true for config_dir - * - * @return Smarty current Smarty instance for chaining - */ - public function addTemplateDir($template_dir, $key = null, $isConfig = false) - { - if ($isConfig) { - $processed = &$this->_processedConfigDir; - $dir = &$this->config_dir; - $this->_configDirNormalized = false; - } else { - $processed = &$this->_processedTemplateDir; - $dir = &$this->template_dir; - $this->_templateDirNormalized = false; - } - if (is_array($template_dir)) { - foreach ($template_dir as $k => $v) { - if (is_int($k)) { - // indexes are not merged but appended - $dir[] = $v; - } else { - // string indexes are overridden - $dir[ $k ] = $v; - unset($processed[ $key ]); - } - } - } else { - if ($key !== null) { - // override directory at specified index - $dir[ $key ] = $template_dir; - unset($processed[ $key ]); - } else { - // append new directory - $dir[] = $template_dir; - } - } - return $this; - } - - /** - * Get template directories - * - * @param mixed $index index of directory to get, null to get all - * @param bool $isConfig true for config_dir - * - * @return array|string list of template directories, or directory of $index - */ - public function getTemplateDir($index = null, $isConfig = false) - { - if ($isConfig) { - $dir = &$this->config_dir; - } else { - $dir = &$this->template_dir; - } - if ($isConfig ? !$this->_configDirNormalized : !$this->_templateDirNormalized) { - $this->_normalizeTemplateConfig($isConfig); - } - if ($index !== null) { - return isset($dir[ $index ]) ? $dir[ $index ] : null; - } - return $dir; - } - - /** - * Set template directory - * - * @param string|array $template_dir directory(s) of template sources - * @param bool $isConfig true for config_dir - * - * @return \Smarty current Smarty instance for chaining - */ - public function setTemplateDir($template_dir, $isConfig = false) - { - if ($isConfig) { - $this->config_dir = array(); - $this->_processedConfigDir = array(); - } else { - $this->template_dir = array(); - $this->_processedTemplateDir = array(); - } - $this->addTemplateDir($template_dir, null, $isConfig); - return $this; - } - - /** - * Add config directory(s) - * - * @param string|array $config_dir directory(s) of config sources - * @param mixed $key key of the array element to assign the config dir to - * - * @return Smarty current Smarty instance for chaining - */ - public function addConfigDir($config_dir, $key = null) - { - return $this->addTemplateDir($config_dir, $key, true); - } - - /** - * Get config directory - * - * @param mixed $index index of directory to get, null to get all - * - * @return array configuration directory - */ - public function getConfigDir($index = null) - { - return $this->getTemplateDir($index, true); - } - - /** - * Set config directory - * - * @param $config_dir - * - * @return Smarty current Smarty instance for chaining - */ - public function setConfigDir($config_dir) - { - return $this->setTemplateDir($config_dir, true); - } - - /** - * Adds directory of plugin files - * - * @param null|array|string $plugins_dir - * - * @return Smarty current Smarty instance for chaining - */ - public function addPluginsDir($plugins_dir) - { - if (empty($this->plugins_dir)) { - $this->plugins_dir[] = SMARTY_PLUGINS_DIR; - } - $this->plugins_dir = array_merge($this->plugins_dir, (array)$plugins_dir); - $this->_pluginsDirNormalized = false; - return $this; - } - - /** - * Get plugin directories - * - * @return array list of plugin directories - */ - public function getPluginsDir() - { - if (empty($this->plugins_dir)) { - $this->plugins_dir[] = SMARTY_PLUGINS_DIR; - $this->_pluginsDirNormalized = false; - } - if (!$this->_pluginsDirNormalized) { - if (!is_array($this->plugins_dir)) { - $this->plugins_dir = (array)$this->plugins_dir; - } - foreach ($this->plugins_dir as $k => $v) { - $this->plugins_dir[ $k ] = $this->_realpath(rtrim($v ?? '', '/\\') . DIRECTORY_SEPARATOR, true); - } - $this->_cache[ 'plugin_files' ] = array(); - $this->_pluginsDirNormalized = true; - } - return $this->plugins_dir; - } - - /** - * Set plugins directory - * - * @param string|array $plugins_dir directory(s) of plugins - * - * @return Smarty current Smarty instance for chaining - */ - public function setPluginsDir($plugins_dir) - { - $this->plugins_dir = (array)$plugins_dir; - $this->_pluginsDirNormalized = false; - return $this; - } - - /** - * Get compiled directory - * - * @return string path to compiled templates - */ - public function getCompileDir() - { - if (!$this->_compileDirNormalized) { - $this->_normalizeDir('compile_dir', $this->compile_dir); - $this->_compileDirNormalized = true; - } - return $this->compile_dir; - } - - /** - * - * @param string $compile_dir directory to store compiled templates in - * - * @return Smarty current Smarty instance for chaining - */ - public function setCompileDir($compile_dir) - { - $this->_normalizeDir('compile_dir', $compile_dir); - $this->_compileDirNormalized = true; - return $this; - } - - /** - * Get cache directory - * - * @return string path of cache directory - */ - public function getCacheDir() - { - if (!$this->_cacheDirNormalized) { - $this->_normalizeDir('cache_dir', $this->cache_dir); - $this->_cacheDirNormalized = true; - } - return $this->cache_dir; - } - - /** - * Set cache directory - * - * @param string $cache_dir directory to store cached templates in - * - * @return Smarty current Smarty instance for chaining - */ - public function setCacheDir($cache_dir) - { - $this->_normalizeDir('cache_dir', $cache_dir); - $this->_cacheDirNormalized = true; - return $this; - } - - /** - * creates a template object - * - * @param string $template the resource handle of the template file - * @param mixed $cache_id cache id to be used with this template - * @param mixed $compile_id compile id to be used with this template - * @param object $parent next higher level of Smarty variables - * @param boolean $do_clone flag is Smarty object shall be cloned - * - * @return \Smarty_Internal_Template template object - * @throws \SmartyException - */ - public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true) - { - if ($cache_id !== null && (is_object($cache_id) || is_array($cache_id))) { - $parent = $cache_id; - $cache_id = null; - } - if ($parent !== null && is_array($parent)) { - $data = $parent; - $parent = null; - } else { - $data = null; - } - if (!$this->_templateDirNormalized) { - $this->_normalizeTemplateConfig(false); - } - $_templateId = $this->_getTemplateId($template, $cache_id, $compile_id); - $tpl = null; - if ($this->caching && isset(Smarty_Internal_Template::$isCacheTplObj[ $_templateId ])) { - $tpl = $do_clone ? clone Smarty_Internal_Template::$isCacheTplObj[ $_templateId ] : - Smarty_Internal_Template::$isCacheTplObj[ $_templateId ]; - $tpl->inheritance = null; - $tpl->tpl_vars = $tpl->config_vars = array(); - } elseif (!$do_clone && isset(Smarty_Internal_Template::$tplObjCache[ $_templateId ])) { - $tpl = clone Smarty_Internal_Template::$tplObjCache[ $_templateId ]; - $tpl->inheritance = null; - $tpl->tpl_vars = $tpl->config_vars = array(); - } else { - /* @var Smarty_Internal_Template $tpl */ - $tpl = new $this->template_class($template, $this, null, $cache_id, $compile_id, null, null); - $tpl->templateId = $_templateId; - } - if ($do_clone) { - $tpl->smarty = clone $tpl->smarty; - } - $tpl->parent = $parent ? $parent : $this; - // fill data if present - if (!empty($data) && is_array($data)) { - // set up variable values - foreach ($data as $_key => $_val) { - $tpl->tpl_vars[ $_key ] = new Smarty_Variable($_val); - } - } - if ($this->debugging || $this->debugging_ctrl === 'URL') { - $tpl->smarty->_debug = new Smarty_Internal_Debug(); - // check URL debugging control - if (!$this->debugging && $this->debugging_ctrl === 'URL') { - $tpl->smarty->_debug->debugUrl($tpl->smarty); - } - } - return $tpl; - } - - /** - * Takes unknown classes and loads plugin files for them - * class name format: Smarty_PluginType_PluginName - * plugin filename format: plugintype.pluginname.php - * - * @param string $plugin_name class plugin name to load - * @param bool $check check if already loaded - * - * @return string |boolean filepath of loaded file or false - * @throws \SmartyException - */ - public function loadPlugin($plugin_name, $check = true) - { - return $this->ext->loadPlugin->loadPlugin($this, $plugin_name, $check); - } - - /** - * Get unique template id - * - * @param string $template_name - * @param null|mixed $cache_id - * @param null|mixed $compile_id - * @param null $caching - * @param \Smarty_Internal_Template $template - * - * @return string - * @throws \SmartyException - */ - public function _getTemplateId( - $template_name, - $cache_id = null, - $compile_id = null, - $caching = null, - Smarty_Internal_Template $template = null - ) { - $template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" : - $template_name; - $cache_id = $cache_id === null ? $this->cache_id : $cache_id; - $compile_id = $compile_id === null ? $this->compile_id : $compile_id; - $caching = (int)($caching === null ? $this->caching : $caching); - if ((isset($template) && strpos($template_name, ':.') !== false) || $this->allow_ambiguous_resources) { - $_templateId = - Smarty_Resource::getUniqueTemplateName((isset($template) ? $template : $this), $template_name) . - "#{$cache_id}#{$compile_id}#{$caching}"; - } else { - $_templateId = $this->_joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}#{$caching}"; - } - if (isset($_templateId[ 150 ])) { - $_templateId = sha1($_templateId); - } - return $_templateId; - } - - /** - * Normalize path - * - remove /./ and /../ - * - make it absolute if required - * - * @param string $path file path - * @param bool $realpath if true - convert to absolute - * false - convert to relative - * null - keep as it is but - * remove /./ /../ - * - * @return string - */ - public function _realpath($path, $realpath = null) - { - $nds = array('/' => '\\', '\\' => '/'); - preg_match( - '%^(?(?:[[:alpha:]]:[\\\\/]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?(.*))$%u', - $path, - $parts - ); - $path = $parts[ 'path' ]; - if ($parts[ 'root' ] === '\\') { - $parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ]; - } else { - if ($realpath !== null && !$parts[ 'root' ]) { - $path = getcwd() . DIRECTORY_SEPARATOR . $path; - } - } - // normalize DIRECTORY_SEPARATOR - $path = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $path); - $parts[ 'root' ] = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $parts[ 'root' ]); - do { - $path = preg_replace( - array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'), - DIRECTORY_SEPARATOR, - $path, - -1, - $count - ); - } while ($count > 0); - return $realpath !== false ? $parts[ 'root' ] . $path : str_ireplace(getcwd(), '.', $parts[ 'root' ] . $path); - } - - /** - * Empty template objects cache - */ - public function _clearTemplateCache() - { - Smarty_Internal_Template::$isCacheTplObj = array(); - Smarty_Internal_Template::$tplObjCache = array(); - } - - /** - * @param boolean $use_sub_dirs - */ - public function setUseSubDirs($use_sub_dirs) - { - $this->use_sub_dirs = $use_sub_dirs; - } - - /** - * @param int $error_reporting - */ - public function setErrorReporting($error_reporting) - { - $this->error_reporting = $error_reporting; - } - - /** - * @param boolean $escape_html - */ - public function setEscapeHtml($escape_html) - { - $this->escape_html = $escape_html; - } - - /** - * Return auto_literal flag - * - * @return boolean - */ - public function getAutoLiteral() - { - return $this->auto_literal; - } - - /** - * Set auto_literal flag - * - * @param boolean $auto_literal - */ - public function setAutoLiteral($auto_literal = true) - { - $this->auto_literal = $auto_literal; - } - - /** - * @param boolean $force_compile - */ - public function setForceCompile($force_compile) - { - $this->force_compile = $force_compile; - } - - /** - * @param boolean $merge_compiled_includes - */ - public function setMergeCompiledIncludes($merge_compiled_includes) - { - $this->merge_compiled_includes = $merge_compiled_includes; - } - - /** - * Get left delimiter - * - * @return string - */ - public function getLeftDelimiter() - { - return $this->left_delimiter; - } - - /** - * Set left delimiter - * - * @param string $left_delimiter - */ - public function setLeftDelimiter($left_delimiter) - { - $this->left_delimiter = $left_delimiter; - } - - /** - * Get right delimiter - * - * @return string $right_delimiter - */ - public function getRightDelimiter() - { - return $this->right_delimiter; - } - - /** - * Set right delimiter - * - * @param string - */ - public function setRightDelimiter($right_delimiter) - { - $this->right_delimiter = $right_delimiter; - } - - /** - * @param boolean $debugging - */ - public function setDebugging($debugging) - { - $this->debugging = $debugging; - } - - /** - * @param boolean $config_overwrite - */ - public function setConfigOverwrite($config_overwrite) - { - $this->config_overwrite = $config_overwrite; - } - - /** - * @param boolean $config_booleanize - */ - public function setConfigBooleanize($config_booleanize) - { - $this->config_booleanize = $config_booleanize; - } - - /** - * @param boolean $config_read_hidden - */ - public function setConfigReadHidden($config_read_hidden) - { - $this->config_read_hidden = $config_read_hidden; - } - - /** - * @param boolean $compile_locking - */ - public function setCompileLocking($compile_locking) - { - $this->compile_locking = $compile_locking; - } - - /** - * @param string $default_resource_type - */ - public function setDefaultResourceType($default_resource_type) - { - $this->default_resource_type = $default_resource_type; - } - - /** - * @param string $caching_type - */ - public function setCachingType($caching_type) - { - $this->caching_type = $caching_type; - } - - /** - * Test install - * - * @param null $errors - */ - public function testInstall(&$errors = null) - { - Smarty_Internal_TestInstall::testInstall($this, $errors); - } - - /** - * Get Smarty object - * - * @return Smarty - */ - public function _getSmartyObj() - { - return $this; - } - - /** - * <> Generic getter. - * Calls the appropriate getter function. - * Issues an E_USER_NOTICE if no valid getter is found. - * - * @param string $name property name - * - * @return mixed - */ - public function __get($name) - { - if (isset($this->accessMap[ $name ])) { - $method = 'get' . $this->accessMap[ $name ]; - return $this->{$method}(); - } elseif (isset($this->_cache[ $name ])) { - return $this->_cache[ $name ]; - } elseif (in_array($name, $this->obsoleteProperties)) { - return null; - } else { - trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); - } - return null; - } - - /** - * <> Generic setter. - * Calls the appropriate setter function. - * Issues an E_USER_NOTICE if no valid setter is found. - * - * @param string $name property name - * @param mixed $value parameter passed to setter - * - */ - public function __set($name, $value) - { - if (isset($this->accessMap[ $name ])) { - $method = 'set' . $this->accessMap[ $name ]; - $this->{$method}($value); - } elseif (in_array($name, $this->obsoleteProperties)) { - return; - } elseif (is_object($value) && method_exists($value, $name)) { - $this->$name = $value; - } else { - trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); - } - } - - /** - * Normalize and set directory string - * - * @param string $dirName cache_dir or compile_dir - * @param string $dir filepath of folder - */ - private function _normalizeDir($dirName, $dir) - { - $this->{$dirName} = $this->_realpath(rtrim($dir ?? '', "/\\") . DIRECTORY_SEPARATOR, true); - } - - /** - * Normalize template_dir or config_dir - * - * @param bool $isConfig true for config_dir - */ - private function _normalizeTemplateConfig($isConfig) - { - if ($isConfig) { - $processed = &$this->_processedConfigDir; - $dir = &$this->config_dir; - } else { - $processed = &$this->_processedTemplateDir; - $dir = &$this->template_dir; - } - if (!is_array($dir)) { - $dir = (array)$dir; - } - foreach ($dir as $k => $v) { - if (!isset($processed[ $k ])) { - $dir[ $k ] = $v = $this->_realpath(rtrim($v ?? '', "/\\") . DIRECTORY_SEPARATOR, true); - $processed[ $k ] = true; - } - } - $isConfig ? $this->_configDirNormalized = true : $this->_templateDirNormalized = true; - $isConfig ? $this->_joined_config_dir = join('#', $this->config_dir) : - $this->_joined_template_dir = join('#', $this->template_dir); - } - - /** - * Mutes errors for "undefined index", "undefined array key" and "trying to read property of null". - * - * @void - */ - public function muteUndefinedOrNullWarnings(): void { - $this->isMutingUndefinedOrNullWarnings = true; - } - - /** - * Indicates if Smarty will mute errors for "undefined index", "undefined array key" and "trying to read property of null". - * @bool - */ - public function isMutingUndefinedOrNullWarnings(): bool { - return $this->isMutingUndefinedOrNullWarnings; - } - -} diff --git a/libs/bootstrap.php b/libs/bootstrap.php deleted file mode 100644 index a226ac04e..000000000 --- a/libs/bootstrap.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -/** - * Load and register Smarty Autoloader - */ -if (!class_exists('Smarty_Autoloader')) { - include __DIR__ . '/Autoloader.php'; -} -Smarty_Autoloader::register(true); diff --git a/libs/functions.php b/libs/functions.php deleted file mode 100644 index bac00e521..000000000 --- a/libs/functions.php +++ /dev/null @@ -1,51 +0,0 @@ - - * @throws \SmartyException - */ -function smarty_block_textformat($params, $content, Smarty_Internal_Template $template, &$repeat) -{ - if (is_null($content)) { - return; - } - if (Smarty::$_MBSTRING) { - $template->_checkPlugins( - array( - array( - 'function' => 'smarty_modifier_mb_wordwrap', - 'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php' - ) - ) - ); - } - $style = null; - $indent = 0; - $indent_first = 0; - $indent_char = ' '; - $wrap = 80; - $wrap_char = "\n"; - $wrap_cut = false; - $assign = null; - foreach ($params as $_key => $_val) { - switch ($_key) { - case 'style': - case 'indent_char': - case 'wrap_char': - case 'assign': - $$_key = (string)$_val; - break; - case 'indent': - case 'indent_first': - case 'wrap': - $$_key = (int)$_val; - break; - case 'wrap_cut': - $$_key = (bool)$_val; - break; - default: - trigger_error("textformat: unknown attribute '{$_key}'"); - } - } - if ($style === 'email') { - $wrap = 72; - } - // split into paragraphs - $_paragraphs = preg_split('![\r\n]{2}!', $content); - foreach ($_paragraphs as &$_paragraph) { - if (!$_paragraph) { - continue; - } - // convert mult. spaces & special chars to single space - $_paragraph = - preg_replace( - array( - '!\s+!' . Smarty::$_UTF8_MODIFIER, - '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER - ), - array( - ' ', - '' - ), - $_paragraph - ); - // indent first line - if ($indent_first > 0) { - $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph; - } - // wordwrap sentences - if (Smarty::$_MBSTRING) { - $_paragraph = smarty_modifier_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); - } else { - $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); - } - // indent lines - if ($indent > 0) { - $_paragraph = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraph); - } - } - $_output = implode($wrap_char . $wrap_char, $_paragraphs); - if ($assign) { - $template->assign($assign, $_output); - } else { - return $_output; - } -} diff --git a/libs/plugins/function.counter.php b/libs/plugins/function.counter.php deleted file mode 100644 index 54795459c..000000000 --- a/libs/plugins/function.counter.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @link https://www.smarty.net/manual/en/language.function.counter.php {counter} - * (Smarty online manual) - * - * @param array $params parameters - * @param Smarty_Internal_Template $template template object - * - * @return string|null - */ -function smarty_function_counter($params, $template) -{ - static $counters = array(); - $name = (isset($params[ 'name' ])) ? $params[ 'name' ] : 'default'; - if (!isset($counters[ $name ])) { - $counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1); - } - $counter =& $counters[ $name ]; - if (isset($params[ 'start' ])) { - $counter[ 'start' ] = $counter[ 'count' ] = (int)$params[ 'start' ]; - } - if (!empty($params[ 'assign' ])) { - $counter[ 'assign' ] = $params[ 'assign' ]; - } - if (isset($counter[ 'assign' ])) { - $template->assign($counter[ 'assign' ], $counter[ 'count' ]); - } - if (isset($params[ 'print' ])) { - $print = (bool)$params[ 'print' ]; - } else { - $print = empty($counter[ 'assign' ]); - } - if ($print) { - $retval = $counter[ 'count' ]; - } else { - $retval = null; - } - if (isset($params[ 'skip' ])) { - $counter[ 'skip' ] = $params[ 'skip' ]; - } - if (isset($params[ 'direction' ])) { - $counter[ 'direction' ] = $params[ 'direction' ]; - } - if ($counter[ 'direction' ] === 'down') { - $counter[ 'count' ] -= $counter[ 'skip' ]; - } else { - $counter[ 'count' ] += $counter[ 'skip' ]; - } - return $retval; -} diff --git a/libs/plugins/function.cycle.php b/libs/plugins/function.cycle.php deleted file mode 100644 index 793569991..000000000 --- a/libs/plugins/function.cycle.php +++ /dev/null @@ -1,92 +0,0 @@ - - * @author credit to Mark Priatel - * @author credit to Gerard - * @author credit to Jason Sweat - * @version 1.3 - * - * @param array $params parameters - * @param Smarty_Internal_Template $template template object - * - * @return string|null - */ -function smarty_function_cycle($params, $template) -{ - static $cycle_vars; - $name = (empty($params[ 'name' ])) ? 'default' : $params[ 'name' ]; - $print = (isset($params[ 'print' ])) ? (bool)$params[ 'print' ] : true; - $advance = (isset($params[ 'advance' ])) ? (bool)$params[ 'advance' ] : true; - $reset = (isset($params[ 'reset' ])) ? (bool)$params[ 'reset' ] : false; - if (!isset($params[ 'values' ])) { - if (!isset($cycle_vars[ $name ][ 'values' ])) { - trigger_error('cycle: missing \'values\' parameter'); - return; - } - } else { - if (isset($cycle_vars[ $name ][ 'values' ]) && $cycle_vars[ $name ][ 'values' ] !== $params[ 'values' ]) { - $cycle_vars[ $name ][ 'index' ] = 0; - } - $cycle_vars[ $name ][ 'values' ] = $params[ 'values' ]; - } - if (isset($params[ 'delimiter' ])) { - $cycle_vars[ $name ][ 'delimiter' ] = $params[ 'delimiter' ]; - } elseif (!isset($cycle_vars[ $name ][ 'delimiter' ])) { - $cycle_vars[ $name ][ 'delimiter' ] = ','; - } - if (is_array($cycle_vars[ $name ][ 'values' ])) { - $cycle_array = $cycle_vars[ $name ][ 'values' ]; - } else { - $cycle_array = explode($cycle_vars[ $name ][ 'delimiter' ], $cycle_vars[ $name ][ 'values' ]); - } - if (!isset($cycle_vars[ $name ][ 'index' ]) || $reset) { - $cycle_vars[ $name ][ 'index' ] = 0; - } - if (isset($params[ 'assign' ])) { - $print = false; - $template->assign($params[ 'assign' ], $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]); - } - if ($print) { - $retval = $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]; - } else { - $retval = null; - } - if ($advance) { - if ($cycle_vars[ $name ][ 'index' ] >= count($cycle_array) - 1) { - $cycle_vars[ $name ][ 'index' ] = 0; - } else { - $cycle_vars[ $name ][ 'index' ]++; - } - } - return $retval; -} diff --git a/libs/plugins/function.fetch.php b/libs/plugins/function.fetch.php deleted file mode 100644 index 4a3e88196..000000000 --- a/libs/plugins/function.fetch.php +++ /dev/null @@ -1,204 +0,0 @@ - - * - * @param array $params parameters - * @param Smarty_Internal_Template $template template object - * - * @throws SmartyException - * @return string|null if the assign parameter is passed, Smarty assigns the result to a template variable - */ -function smarty_function_fetch($params, $template) -{ - if (empty($params[ 'file' ])) { - trigger_error('[plugin] fetch parameter \'file\' cannot be empty', E_USER_NOTICE); - return; - } - // strip file protocol - if (stripos($params[ 'file' ], 'file://') === 0) { - $params[ 'file' ] = substr($params[ 'file' ], 7); - } - $protocol = strpos($params[ 'file' ], '://'); - if ($protocol !== false) { - $protocol = strtolower(substr($params[ 'file' ], 0, $protocol)); - } - if (isset($template->smarty->security_policy)) { - if ($protocol) { - // remote resource (or php stream, …) - if (!$template->smarty->security_policy->isTrustedUri($params[ 'file' ])) { - return; - } - } else { - // local file - if (!$template->smarty->security_policy->isTrustedResourceDir($params[ 'file' ])) { - return; - } - } - } - $content = ''; - if ($protocol === 'http') { - // http fetch - if ($uri_parts = parse_url($params[ 'file' ])) { - // set defaults - $host = $server_name = $uri_parts[ 'host' ]; - $timeout = 30; - $accept = 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*'; - $agent = 'Smarty Template Engine ' . Smarty::SMARTY_VERSION; - $referer = ''; - $uri = !empty($uri_parts[ 'path' ]) ? $uri_parts[ 'path' ] : '/'; - $uri .= !empty($uri_parts[ 'query' ]) ? '?' . $uri_parts[ 'query' ] : ''; - $_is_proxy = false; - if (empty($uri_parts[ 'port' ])) { - $port = 80; - } else { - $port = $uri_parts[ 'port' ]; - } - if (!empty($uri_parts[ 'user' ])) { - $user = $uri_parts[ 'user' ]; - } - if (!empty($uri_parts[ 'pass' ])) { - $pass = $uri_parts[ 'pass' ]; - } - // loop through parameters, setup headers - foreach ($params as $param_key => $param_value) { - switch ($param_key) { - case 'file': - case 'assign': - case 'assign_headers': - break; - case 'user': - if (!empty($param_value)) { - $user = $param_value; - } - break; - case 'pass': - if (!empty($param_value)) { - $pass = $param_value; - } - break; - case 'accept': - if (!empty($param_value)) { - $accept = $param_value; - } - break; - case 'header': - if (!empty($param_value)) { - if (!preg_match('![\w\d-]+: .+!', $param_value)) { - trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE); - return; - } else { - $extra_headers[] = $param_value; - } - } - break; - case 'proxy_host': - if (!empty($param_value)) { - $proxy_host = $param_value; - } - break; - case 'proxy_port': - if (!preg_match('!\D!', $param_value)) { - $proxy_port = (int)$param_value; - } else { - trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE); - return; - } - break; - case 'agent': - if (!empty($param_value)) { - $agent = $param_value; - } - break; - case 'referer': - if (!empty($param_value)) { - $referer = $param_value; - } - break; - case 'timeout': - if (!preg_match('!\D!', $param_value)) { - $timeout = (int)$param_value; - } else { - trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE); - return; - } - break; - default: - trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE); - return; - } - } - if (!empty($proxy_host) && !empty($proxy_port)) { - $_is_proxy = true; - $fp = fsockopen($proxy_host, $proxy_port, $errno, $errstr, $timeout); - } else { - $fp = fsockopen($server_name, $port, $errno, $errstr, $timeout); - } - if (!$fp) { - trigger_error("[plugin] unable to fetch: $errstr ($errno)", E_USER_NOTICE); - return; - } else { - if ($_is_proxy) { - fputs($fp, 'GET ' . $params[ 'file' ] . " HTTP/1.0\r\n"); - } else { - fputs($fp, "GET $uri HTTP/1.0\r\n"); - } - if (!empty($host)) { - fputs($fp, "Host: $host\r\n"); - } - if (!empty($accept)) { - fputs($fp, "Accept: $accept\r\n"); - } - if (!empty($agent)) { - fputs($fp, "User-Agent: $agent\r\n"); - } - if (!empty($referer)) { - fputs($fp, "Referer: $referer\r\n"); - } - if (isset($extra_headers) && is_array($extra_headers)) { - foreach ($extra_headers as $curr_header) { - fputs($fp, $curr_header . "\r\n"); - } - } - if (!empty($user) && !empty($pass)) { - fputs($fp, 'Authorization: BASIC ' . base64_encode("$user:$pass") . "\r\n"); - } - fputs($fp, "\r\n"); - while (!feof($fp)) { - $content .= fgets($fp, 4096); - } - fclose($fp); - $csplit = preg_split("!\r\n\r\n!", $content, 2); - $content = $csplit[ 1 ]; - if (!empty($params[ 'assign_headers' ])) { - $template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ])); - } - } - } else { - trigger_error("[plugin fetch] unable to parse URL, check syntax", E_USER_NOTICE); - return; - } - } else { - $content = @file_get_contents($params[ 'file' ]); - if ($content === false) { - throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'"); - } - } - if (!empty($params[ 'assign' ])) { - $template->assign($params[ 'assign' ], $content); - } else { - return $content; - } -} diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php deleted file mode 100644 index a8e7a07d8..000000000 --- a/libs/plugins/function.html_checkboxes.php +++ /dev/null @@ -1,286 +0,0 @@ -' output=$names} - * {html_checkboxes values=$ids checked=$checked separator='
' output=$names} - * - * Params: - * - * - name (optional) - string default "checkbox" - * - values (required) - array - * - options (optional) - associative array - * - checked (optional) - array default not set - * - separator (optional) - ie
or   - * - output (optional) - the output next to each checkbox - * - assign (optional) - assign the output as an array to this variable - * - escape (optional) - escape the content (not value), defaults to true - * - * @link https://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} - * (Smarty online manual) - * @author Christopher Kvarme - * @author credits to Monte Ohrt - * @version 1.0 - * - * @param array $params parameters - * @param Smarty_Internal_Template $template template object - * - * @return string - * @uses smarty_function_escape_special_chars() - * @throws \SmartyException - */ -function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template) -{ - $template->_checkPlugins( - array( - array( - 'function' => 'smarty_function_escape_special_chars', - 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php' - ) - ) - ); - $name = 'checkbox'; - $values = null; - $options = null; - $selected = array(); - $separator = ''; - $escape = true; - $labels = true; - $label_ids = false; - $output = null; - $extra = ''; - foreach ($params as $_key => $_val) { - switch ($_key) { - case 'name': - case 'separator': - $$_key = (string)$_val; - break; - case 'escape': - case 'labels': - case 'label_ids': - $$_key = (bool)$_val; - break; - case 'options': - $$_key = (array)$_val; - break; - case 'values': - case 'output': - $$_key = array_values((array)$_val); - break; - case 'checked': - case 'selected': - if (is_array($_val)) { - $selected = array(); - foreach ($_val as $_sel) { - if (is_object($_sel)) { - if (method_exists($_sel, '__toString')) { - $_sel = smarty_function_escape_special_chars((string)$_sel->__toString()); - } else { - trigger_error( - 'html_checkboxes: selected attribute contains an object of class \'' . - get_class($_sel) . '\' without __toString() method', - E_USER_NOTICE - ); - continue; - } - } else { - $_sel = smarty_function_escape_special_chars((string)$_sel); - } - $selected[ $_sel ] = true; - } - } elseif (is_object($_val)) { - if (method_exists($_val, '__toString')) { - $selected = smarty_function_escape_special_chars((string)$_val->__toString()); - } else { - trigger_error( - 'html_checkboxes: selected attribute is an object of class \'' . get_class($_val) . - '\' without __toString() method', - E_USER_NOTICE - ); - } - } else { - $selected = smarty_function_escape_special_chars((string)$_val); - } - break; - case 'checkboxes': - trigger_error( - 'html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', - E_USER_WARNING - ); - $options = (array)$_val; - break; - case 'assign': - break; - case 'strict': - break; - case 'disabled': - case 'readonly': - if (!empty($params[ 'strict' ])) { - if (!is_scalar($_val)) { - trigger_error( - "html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute", - E_USER_NOTICE - ); - } - if ($_val === true || $_val === $_key) { - $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; - } - break; - } - // omit break; to fall through! - // no break - default: - if (!is_array($_val)) { - $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; - } else { - trigger_error("html_checkboxes: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); - } - break; - } - } - if (!isset($options) && !isset($values)) { - return ''; - } /* raise error here? */ - $_html_result = array(); - if (isset($options)) { - foreach ($options as $_key => $_val) { - $_html_result[] = - smarty_function_html_checkboxes_output( - $name, - $_key, - $_val, - $selected, - $extra, - $separator, - $labels, - $label_ids, - $escape - ); - } - } else { - foreach ($values as $_i => $_key) { - $_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; - $_html_result[] = - smarty_function_html_checkboxes_output( - $name, - $_key, - $_val, - $selected, - $extra, - $separator, - $labels, - $label_ids, - $escape - ); - } - } - if (!empty($params[ 'assign' ])) { - $template->assign($params[ 'assign' ], $_html_result); - } else { - return implode("\n", $_html_result); - } -} - -/** - * @param $name - * @param $value - * @param $output - * @param $selected - * @param $extra - * @param $separator - * @param $labels - * @param $label_ids - * @param bool $escape - * - * @return string - */ -function smarty_function_html_checkboxes_output( - $name, - $value, - $output, - $selected, - $extra, - $separator, - $labels, - $label_ids, - $escape = true -) { - $_output = ''; - if (is_object($value)) { - if (method_exists($value, '__toString')) { - $value = (string)$value->__toString(); - } else { - trigger_error( - 'html_options: value is an object of class \'' . get_class($value) . - '\' without __toString() method', - E_USER_NOTICE - ); - return ''; - } - } else { - $value = (string)$value; - } - if (is_object($output)) { - if (method_exists($output, '__toString')) { - $output = (string)$output->__toString(); - } else { - trigger_error( - 'html_options: output is an object of class \'' . get_class($output) . - '\' without __toString() method', - E_USER_NOTICE - ); - return ''; - } - } else { - $output = (string)$output; - } - if ($labels) { - if ($label_ids) { - $_id = smarty_function_escape_special_chars( - preg_replace( - '![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, - '_', - $name . '_' . $value - ) - ); - $_output .= '