Skip to content

class Smarty

Oliver edited this page Apr 25, 2020 · 1 revision

www/smartylib/Smarty.class.php


Smarty

Package

Smarty

Overview

Public Properties

_cache_include() | _cache_including() | _cache_info() | _cache_serials() | _compile_id() | _conf_obj() | _config() | _dir_perms() | _file_perms() | _foreach() | _inclusion_depth() | _plugins() | _reg_objects() | _sections() | _smarty_debug_id() | _smarty_debug_info() | _smarty_md5() | _smarty_vars() | _tag_stack() | _tpl_vars() | _version() | autoload_filters() | cache_dir() | cache_handler_func() | cache_lifetime() | cache_modified_check() | caching() | compile_check() | compile_dir() | compile_id() | compiler_class() | compiler_file() | config_booleanize() | config_class() | config_dir() | config_fix_newlines() | config_overwrite() | config_read_hidden() | debug_tpl() | debugging() | debugging_ctrl() | default_modifiers() | default_resource_type() | default_template_handler_func() | error_reporting() | force_compile() | left_delimiter() | php_handling() | plugins_dir() | request_use_auto_globals() | request_vars_order() | right_delimiter() | secure_dir() | security() | security_settings() | template_dir() | trusted_dir() | use_sub_dirs() |

Constants

No constants found

Public Methods

__construct() | _compile_resource() | _compile_source() | _dequote() | _eval() | _fetch_resource_info() | _get_auto_filename() | _get_auto_id() | _get_compile_path() | _get_filter_name() | _get_plugin_filepath() | _include() | _is_compiled() | _parse_resource_name() | _process_compiled_include_callback() | _read_file() | _run_mod_handler() | _smarty_cache_attrs() | _smarty_include() | _trigger_fatal_error() | _unlink() | append() | append_by_ref() | assign() | assign_by_ref() | clear_all_assign() | clear_all_cache() | clear_assign() | clear_cache() | clear_compiled_tpl() | clear_config() | config_load() | display() | fetch() | get_config_vars() | get_registered_object() | get_template_vars() | is_cached() | load_filter() | register_block() | register_compiler_function() | register_function() | register_modifier() | register_object() | register_outputfilter() | register_postfilter() | register_prefilter() | register_resource() | template_exists() | trigger_error() | unregister_block() | unregister_compiler_function() | unregister_function() | unregister_modifier() | unregister_object() | unregister_outputfilter() | unregister_postfilter() | unregister_prefilter() | unregister_resource() |

Properties

_cache_include

name of optional cache include file

public $_cache_include : string

Array

_cache_including

indicate if the current code is used in a compiled include

public $_cache_including : string

Array

_cache_info

info that makes up a cache file

public $_cache_info : array

Array

_cache_serials

cache serials

public $_cache_serials : array

Array

_compile_id

for different compiled templates

public $_compile_id : string

Array

_conf_obj

configuration object

public $_conf_obj : \Config_file

Array

_config

loaded configuration settings

public $_config : array

Array

_dir_perms

default dir permissions

public $_dir_perms : int

Array

_file_perms

default file permissions

public $_file_perms : int

Array

_foreach

keeps track of foreach blocks

public $_foreach : array

Array

_inclusion_depth

current template inclusion depth

public $_inclusion_depth : int

Array

_plugins

table keeping track of plugins

public $_plugins : array

Array

_reg_objects

registered objects

public $_reg_objects : array

Array

_sections

keeps track of sections

public $_sections : array

Array

_smarty_debug_id

text in URL to enable debug mode

public $_smarty_debug_id : string

Array

_smarty_debug_info

debugging information for debug console

public $_smarty_debug_info : array

Array

_smarty_md5

md5 checksum of the string 'Smarty'

public $_smarty_md5 : string

Array

_smarty_vars

stores run-time $smarty.* vars

public $_smarty_vars : null|array

Array

_tag_stack

keeps track of tag hierarchy

public $_tag_stack : array

Array

_tpl_vars

where assigned template vars are kept

public $_tpl_vars : array

Array

_version

Smarty version number

public $_version : string

Array

autoload_filters

This indicates which filters are automatically loaded into Smarty.

public $autoload_filters : array

Array: array of filter names

cache_dir

The name of the directory for cache files.

public $cache_dir : string

Array

cache_handler_func

The function used for cache file handling. If not set, built-in caching is used.

public $cache_handler_func : null|string

Array: function name

cache_lifetime

This is the number of seconds cached content will persist.

  • 0 = always regenerate cache
  • -1 = never expires
  • `public` `$cache_lifetime : int`

    Array

    cache_modified_check

    Only used when $caching is enabled. If true, then If-Modified-Since headers are respected with cached content, and appropriate HTTP headers are sent.

    This way repeated hits to a cached page do not send the entire page to the client every time. public $cache_modified_check : bool

    Array

    caching

    This enables template caching.

  • 0 = no caching
  • 1 = use class cache_lifetime value
  • 2 = use cache_lifetime in cache file
  • `public` `$caching : int`

    Array

    compile_check

    This tells Smarty whether to check for recompiling or not. Recompiling does not need to happen unless a template or config file is changed.

    Typically you enable this during development, and disable for production. public $compile_check : bool

    Array

    compile_dir

    The directory where compiled templates are located.

    public $compile_dir : string

    Array

    compile_id

    Set this if you want different sets of compiled files for the same templates. This is useful for things like different languages.

    Instead of creating separate sets of templates per language, you set different compile_ids like 'en' and 'de'. public $compile_id : string

    Array

    compiler_class

    The class used for compiling templates.

    public $compiler_class : string

    Array

    compiler_file

    The file that contains the compiler class. This can a full pathname, or relative to the php_include path.

    public $compiler_file : string

    Array

    config_booleanize

    This tells whether or not to automatically booleanize config file variables.

    If enabled, then the strings "on", "true", and "yes" are treated as boolean true, and "off", "false" and "no" are treated as boolean false. public $config_booleanize

    config_class

    The class used to load config vars.

    public $config_class : string

    Array

    config_dir

    The directory where config files are located.

    public $config_dir : string

    Array

    config_fix_newlines

    This tells whether or not automatically fix newlines in config files.

    It basically converts \r (mac) or \r\n (dos) to \n public $config_fix_newlines

    config_overwrite

    This tells if config file vars of the same name overwrite each other or not.

    if disabled, same name variables are accumulated in an array. public $config_overwrite

    config_read_hidden

    This tells whether hidden sections [.foobar] are readable from the tempalates or not. Normally you would never allow this since that is the point behind hidden sections: the application can access them, but the templates cannot.

    public $config_read_hidden

    debug_tpl

    This is the path to the debug console template. If not set, the default one will be used.

    public $debug_tpl : string

    Array

    debugging

    If debugging is enabled, a debug console window will display when the page loads (make sure your browser allows unrequested popup windows)

    public $debugging : bool

    Array

    debugging_ctrl

    This determines if debugging is enable-able from the browser.

  • NONE => no debugging control allowed
  • URL => enable debugging when SMARTY_DEBUG is found in the URL.
  • `public` `$debugging_ctrl : string`

    Array See also

    default_modifiers

    This is a list of the modifiers to apply to all template variables.

    Put each modifier in a separate array element in the order you want them applied. example: array('escape:"htmlall"'); public $default_modifiers : array

    Array

    default_resource_type

    This is the resource type to be used when not specified at the beginning of the resource path. examples: $smarty->display('file:index.tpl'); $smarty->display('db:index.tpl'); $smarty->display('index.tpl'); // will use default resource type {include file="file:index.tpl"} {include file="db:index.tpl"} {include file="index.tpl"} {* will use default resource type *}

    public $default_resource_type : array

    Array

    default_template_handler_func

    If a template cannot be found, this PHP function will be executed.

    Useful for creating templates on-the-fly or other special action. public $default_template_handler_func : string

    Array: function name

    error_reporting

    When set, smarty does uses this value as error_reporting-level.

    public $error_reporting : int

    Array

    force_compile

    This forces templates to compile every time. Useful for development or debugging.

    public $force_compile : bool

    Array

    left_delimiter

    The left delimiter used for the template tags.

    public $left_delimiter : string

    Array

    php_handling

    This determines how Smarty handles "<?php ... ?>" tags in templates.

    possible values:

    • SMARTY_PHP_PASSTHRU -> print tags as plain text
    • SMARTY_PHP_QUOTE -> escape tags as entities
    • SMARTY_PHP_REMOVE -> remove php tags
    • SMARTY_PHP_ALLOW -> execute php tags
    `public` `$php_handling : int`

    Array

    plugins_dir

    An array of directories searched for plugins.

    public $plugins_dir : array

    Array

    request_use_auto_globals

    Indicates wether $HTTP_VARS[] (request_use_auto_globals=false) are uses as request-vars or $[]-vars. note: if request_use_auto_globals is true, then $request_vars_order has no effect, but the php-ini-value "gpc_order"

    public $request_use_auto_globals : bool

    Array

    request_vars_order

    The order in which request variables are registered, similar to variables_order in php.ini E = Environment, G = GET, P = POST, C = Cookies, S = Server

    public $request_vars_order : string

    Array

    right_delimiter

    The right delimiter used for the template tags.

    public $right_delimiter : string

    Array

    secure_dir

    This is the list of template directories that are considered secure. This is used only if {@link $security} is enabled. One directory per array element. {@link $template_dir} is in this list implicitly.

    public $secure_dir : array

    Array

    security

    This enables template security. When enabled, many things are restricted in the templates that normally would go unchecked. This is useful when untrusted parties are editing templates and you want a reasonable level of security. (no direct execution of PHP in templates for example)

    public $security : bool

    Array

    security_settings

    These are the security settings for Smarty. They are used only when {@link $security} is enabled.

    public $security_settings : array

    Array

    template_dir

    The name of the directory where templates are located.

    public $template_dir : string

    Array

    trusted_dir

    This is an array of directories where trusted php scripts reside.

    $security is disabled during their inclusion/execution. public $trusted_dir : array

    Array

    use_sub_dirs

    This tells Smarty whether or not to use sub dirs in the cache/ and templates_c/ directories. sub directories better organized, but may not work well with PHP safe mode enabled.

    public $use_sub_dirs : bool

    Array

    Methods

    __construct()

    The class constructor.

    public __construct() : mixed

    _compile_resource()

    compile the template

    public _compile_resource(string $resource_name, string $compile_path) : bool

    _compile_source()

    compile the given source

    public _compile_source(string $resource_name, string $source_content, string $compiled_content, mixed $cache_include_path = null) : bool

    _dequote()

    Remove starting and ending quotes from the string

    public _dequote(string $string) : string

    _eval()

    wrapper for eval() retaining $this

    public _eval(mixed $code, mixed $params = null) : mixed

    _fetch_resource_info()

    fetch the template info. Gets timestamp, and source if get_source is true

    sets $source_content to the source of the template, and $resource_timestamp to its time stamp

    public _fetch_resource_info(mixed $params) : bool

    _get_auto_filename()

    get a concrete filename for automagically created content

    public _get_auto_filename(string $auto_base, string $auto_source = null, string $auto_id = null) : string

    Tags
    • staticvar: string|null
    • staticvar: string|null

    _get_auto_id()

    returns an auto_id for auto-file-functions

    public _get_auto_id(string $cache_id = null, string $compile_id = null) : string|null

    _get_compile_path()

    Get the compile path for this resource

    public _get_compile_path(string $resource_name) : string

    _get_filter_name()

    Extracts the filter name from the given callback

    public _get_filter_name(callable $function) : string

    _get_plugin_filepath()

    get filepath of requested plugin

    public _get_plugin_filepath(string $type, string $name) : string|bool

    _include()

    wrapper for include() retaining $this

    public _include(mixed $filename, mixed $once = false, mixed $params = null) : mixed

    _is_compiled()

    test if resource needs compiling

    public _is_compiled(string $resource_name, string $compile_path) : bool

    _parse_resource_name()

    parse out the type and name from the resource

    public _parse_resource_name(mixed $params) : bool

    _process_compiled_include_callback()

    callback function for preg_replace, to call a non-cacheable block

    public _process_compiled_include_callback(mixed $match) : string

    _read_file()

    read in a file

    public _read_file(string $filename) : string

    _run_mod_handler()

    Handle modifiers

    public _run_mod_handler() : string

    _smarty_cache_attrs()

    get or set an array of cached attributes for function that is not cacheable

    public _smarty_cache_attrs(mixed $cache_serial, mixed $count) : array

    _smarty_include()

    public _smarty_include(mixed $params) : mixed

    _trigger_fatal_error()

    trigger Smarty plugin error

    public _trigger_fatal_error(string $error_msg, string $tpl_file = null, int $tpl_line = null, string $file = null, int $line = null, int $error_type = E_USER_ERROR) : mixed

    _unlink()

    unlink a file, possibly using expiration time

    public _unlink(string $resource, int $exp_time = null) : mixed

    append()

    appends values to template variables

    public append(array|string $tpl_var, mixed $value = null, mixed $merge = false) : mixed

    append_by_ref()

    appends values to template variables by reference

    public append_by_ref(string $tpl_var, mixed $value, mixed $merge = false) : mixed

    assign()

    assigns values to template variables

    public assign(array|string $tpl_var, mixed $value = null) : mixed

    assign_by_ref()

    assigns values to template variables by reference

    public assign_by_ref(string $tpl_var, mixed $value) : mixed

    clear_all_assign()

    clear all the assigned template variables.

    public clear_all_assign() : mixed

    clear_all_cache()

    clear the entire contents of cache (all templates)

    public clear_all_cache(string $exp_time = null) : bool

    clear_assign()

    clear the given assigned template variable.

    public clear_assign(string $tpl_var) : mixed

    clear_cache()

    clear cached content for the given template and cache id

    public clear_cache(string $tpl_file = null, string $cache_id = null, string $compile_id = null, string $exp_time = null) : bool

    clear_compiled_tpl()

    clears compiled version of specified template resource, or all compiled template files if one is not specified.

    This function is for advanced use only, not normally needed.

    public clear_compiled_tpl(string $tpl_file = null, string $compile_id = null, string $exp_time = null) : bool

    clear_config()

    clear configuration values

    public clear_config(string $var = null) : mixed

    config_load()

    load configuration values

    public config_load(string $file, string $section = null, string $scope = &#039;global&#039;) : mixed

    display()

    executes & displays the template results

    public display(string $resource_name, string $cache_id = null, string $compile_id = null) : mixed

    fetch()

    executes & returns or displays the template results

    public fetch(string $resource_name, string $cache_id = null, string $compile_id = null, bool $display = false) : mixed

    get_config_vars()

    Returns an array containing config variables

    public get_config_vars(string $name = null) : array

    get_registered_object()

    return a reference to a registered object

    public get_registered_object(string $name) : object

    get_template_vars()

    Returns an array containing template variables

    public get_template_vars(string $name = null) : array

    is_cached()

    test to see if valid cache exists for this template

    public is_cached(string $tpl_file, string $cache_id = null, string $compile_id = null) : string|bool

    load_filter()

    load a filter of specified type and name

    public load_filter(string $type, string $name) : mixed

    register_block()

    Registers block function to be used in templates

    public register_block(string $block, string $block_impl, mixed $cacheable = true, mixed $cache_attrs = null) : mixed

    register_compiler_function()

    Registers compiler function

    public register_compiler_function(string $function, string $function_impl, mixed $cacheable = true) : mixed

    register_function()

    Registers custom function to be used in templates

    public register_function(string $function, string $function_impl, mixed $cacheable = true, mixed $cache_attrs = null) : mixed

    register_modifier()

    Registers modifier to be used in templates

    public register_modifier(string $modifier, string $modifier_impl) : mixed

    register_object()

    Registers object to be used in templates

    public register_object(string $object, mixed $object_impl, null|array $allowed = array(), bool $smarty_args = true, mixed $block_methods = array()) : mixed

    register_outputfilter()

    Registers an output filter function to apply to a template output

    public register_outputfilter(callable $function) : mixed

    register_postfilter()

    Registers a postfilter function to apply to a compiled template after compilation

    public register_postfilter(callable $function) : mixed

    register_prefilter()

    Registers a prefilter function to apply to a template before compiling

    public register_prefilter(callable $function) : mixed

    register_resource()

    Registers a resource to fetch a template

    public register_resource(string $type, array $functions) : mixed

    template_exists()

    Checks whether requested template exists.

    public template_exists(string $tpl_file) : bool

    trigger_error()

    trigger Smarty error

    public trigger_error(string $error_msg, int $error_type = E_USER_WARNING) : mixed

    unregister_block()

    Unregisters block function

    public unregister_block(string $block) : mixed

    unregister_compiler_function()

    Unregisters compiler function

    public unregister_compiler_function(string $function) : mixed

    unregister_function()

    Unregisters custom function

    public unregister_function(string $function) : mixed

    unregister_modifier()

    Unregisters modifier

    public unregister_modifier(string $modifier) : mixed

    unregister_object()

    Unregisters object

    public unregister_object(string $object) : mixed

    unregister_outputfilter()

    Unregisters an outputfilter function

    public unregister_outputfilter(callable $function) : mixed

    unregister_postfilter()

    Unregisters a postfilter function

    public unregister_postfilter(callable $function) : mixed

    unregister_prefilter()

    Unregisters a prefilter function

    public unregister_prefilter(callable $function) : mixed

    unregister_resource()

    Unregisters a resource

    public unregister_resource(string $type) : mixed


    \ » Classes » Smarty

    Clone this wiki locally