From 2ba280277456a4db257dd30b1e5021be6b10256c Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 24 Apr 2018 19:50:44 +0100 Subject: [PATCH] bump Smarty to v3.1.32 (possible security fix, numerous bugs listed at https://github.com/smarty-php/smarty/blob/master/change_log.txt --- smarty/libs/Autoloader.php | 6 +- smarty/libs/Smarty.class.php | 737 ++- smarty/libs/SmartyBC.class.php | 23 +- smarty/libs/bootstrap.php | 4 +- smarty/libs/plugins/block.textformat.php | 31 +- smarty/libs/plugins/function.counter.php | 6 +- smarty/libs/plugins/function.cycle.php | 22 +- smarty/libs/plugins/function.fetch.php | 48 +- .../libs/plugins/function.html_checkboxes.php | 75 +- smarty/libs/plugins/function.html_image.php | 37 +- smarty/libs/plugins/function.html_options.php | 67 +- smarty/libs/plugins/function.html_radios.php | 65 +- .../plugins/function.html_select_date.php | 65 +- .../plugins/function.html_select_time.php | 51 +- smarty/libs/plugins/function.html_table.php | 32 +- smarty/libs/plugins/function.mailto.php | 22 +- smarty/libs/plugins/function.math.php | 12 +- smarty/libs/plugins/modifier.capitalize.php | 29 +- smarty/libs/plugins/modifier.date_format.php | 38 +- .../libs/plugins/modifier.debug_print_var.php | 8 +- smarty/libs/plugins/modifier.escape.php | 60 +- smarty/libs/plugins/modifier.mb_wordwrap.php | 75 + smarty/libs/plugins/modifier.needle.php | 55 - .../libs/plugins/modifier.regex_replace.php | 4 +- smarty/libs/plugins/modifier.replace.php | 14 +- smarty/libs/plugins/modifier.spacify.php | 4 +- smarty/libs/plugins/modifier.truncate.php | 6 +- smarty/libs/plugins/modifiercompiler.cat.php | 10 +- .../modifiercompiler.count_characters.php | 6 +- .../modifiercompiler.count_paragraphs.php | 4 +- .../modifiercompiler.count_sentences.php | 2 +- .../plugins/modifiercompiler.count_words.php | 4 +- .../libs/plugins/modifiercompiler.default.php | 4 +- .../libs/plugins/modifiercompiler.escape.php | 26 +- .../plugins/modifiercompiler.from_charset.php | 4 +- .../libs/plugins/modifiercompiler.indent.php | 4 +- .../libs/plugins/modifiercompiler.lower.php | 4 +- .../libs/plugins/modifiercompiler.noprint.php | 4 +- .../modifiercompiler.string_format.php | 4 +- .../libs/plugins/modifiercompiler.strip.php | 8 +- .../plugins/modifiercompiler.strip_tags.php | 6 +- .../plugins/modifiercompiler.to_charset.php | 4 +- .../plugins/modifiercompiler.unescape.php | 6 +- .../libs/plugins/modifiercompiler.upper.php | 4 +- .../plugins/modifiercompiler.wordwrap.php | 26 +- .../plugins/outputfilter.trimwhitespace.php | 2 +- .../plugins/shared.escape_special_chars.php | 2 +- smarty/libs/plugins/shared.make_timestamp.php | 6 +- smarty/libs/plugins/shared.mb_str_replace.php | 14 +- smarty/libs/plugins/shared.mb_unicode.php | 10 +- smarty/libs/plugins/shared.mb_wordwrap.php | 75 - .../variablefilter.htmlspecialchars.php | 6 +- .../smarty_cacheresource_custom.php | 5 +- .../smarty_cacheresource_keyvaluestore.php | 11 +- smarty/libs/sysplugins/smarty_data.php | 4 +- .../libs/sysplugins/smarty_internal_block.php | 4 +- .../smarty_internal_cacheresource_file.php | 31 +- .../smarty_internal_compile_append.php | 1 + .../smarty_internal_compile_assign.php | 6 +- .../smarty_internal_compile_block.php | 56 +- .../smarty_internal_compile_block_child.php | 40 +- .../smarty_internal_compile_block_parent.php | 56 +- .../smarty_internal_compile_break.php | 35 +- .../smarty_internal_compile_call.php | 4 +- .../smarty_internal_compile_capture.php | 6 +- .../smarty_internal_compile_child.php | 77 + .../smarty_internal_compile_continue.php | 27 +- .../smarty_internal_compile_eval.php | 5 +- .../smarty_internal_compile_extends.php | 29 +- .../smarty_internal_compile_for.php | 14 +- .../smarty_internal_compile_foreach.php | 45 +- .../smarty_internal_compile_function.php | 49 +- .../sysplugins/smarty_internal_compile_if.php | 34 +- .../smarty_internal_compile_include.php | 69 +- .../smarty_internal_compile_include_php.php | 13 +- .../smarty_internal_compile_insert.php | 23 +- .../smarty_internal_compile_ldelim.php | 5 +- .../smarty_internal_compile_make_nocache.php | 12 +- .../smarty_internal_compile_parent.php | 32 + ..._internal_compile_private_block_plugin.php | 19 +- ...nternal_compile_private_foreachsection.php | 11 +- ...ternal_compile_private_function_plugin.php | 6 +- ...arty_internal_compile_private_modifier.php | 29 +- ...ternal_compile_private_object_function.php | 12 +- .../smarty_internal_compile_private_php.php | 40 +- ...ernal_compile_private_print_expression.php | 41 +- ...ernal_compile_private_registered_block.php | 2 +- ...al_compile_private_registered_function.php | 30 +- .../smarty_internal_compile_rdelim.php | 10 +- .../smarty_internal_compile_section.php | 74 +- ...ty_internal_compile_shared_inheritance.php | 26 +- .../smarty_internal_compile_while.php | 10 +- .../smarty_internal_compilebase.php | 17 +- .../smarty_internal_config_file_compiler.php | 25 +- .../smarty_internal_configfilelexer.php | 287 +- .../smarty_internal_configfileparser.php | 797 ++-- .../libs/sysplugins/smarty_internal_data.php | 7 +- .../libs/sysplugins/smarty_internal_debug.php | 31 +- .../smarty_internal_errorhandler.php | 112 + .../smarty_internal_extension_handler.php | 127 +- ...rty_internal_method_addautoloadfilters.php | 2 +- .../smarty_internal_method_append.php | 4 +- .../smarty_internal_method_appendbyref.php | 2 +- .../smarty_internal_method_assignbyref.php | 2 +- .../smarty_internal_method_assignglobal.php | 2 +- .../smarty_internal_method_clearallcache.php | 3 +- .../smarty_internal_method_clearcache.php | 3 +- ..._internal_method_clearcompiledtemplate.php | 42 +- ...ty_internal_method_compilealltemplates.php | 30 +- .../smarty_internal_method_configload.php | 7 +- ...rty_internal_method_getautoloadfilters.php | 4 +- .../smarty_internal_method_getglobal.php | 4 +- .../smarty_internal_method_gettags.php | 5 +- ...smarty_internal_method_gettemplatevars.php | 9 +- .../smarty_internal_method_literals.php | 98 + .../smarty_internal_method_loadfilter.php | 4 +- .../smarty_internal_method_loadplugin.php | 2 +- .../smarty_internal_method_mustcompile.php | 2 +- ...al_method_registerdefaultconfighandler.php | 2 +- ..._method_registerdefaulttemplatehandler.php | 4 +- .../smarty_internal_method_registerfilter.php | 4 +- .../smarty_internal_method_registerplugin.php | 4 +- ...rty_internal_method_setautoloadfilters.php | 3 +- .../smarty_internal_method_unloadfilter.php | 3 +- ...marty_internal_method_unregisterfilter.php | 1 + .../smarty_internal_nocache_insert.php | 9 +- .../sysplugins/smarty_internal_parsetree.php | 4 +- .../smarty_internal_parsetree_code.php | 2 +- .../smarty_internal_parsetree_dq.php | 4 +- .../smarty_internal_parsetree_tag.php | 2 +- .../smarty_internal_parsetree_template.php | 12 +- .../smarty_internal_resource_extends.php | 5 +- .../smarty_internal_resource_file.php | 20 +- .../smarty_internal_resource_php.php | 59 +- .../smarty_internal_resource_stream.php | 1 + .../smarty_internal_resource_string.php | 3 + .../smarty_internal_runtime_cachemodify.php | 3 + ...rty_internal_runtime_cacheresourcefile.php | 56 +- .../smarty_internal_runtime_capture.php | 26 +- .../smarty_internal_runtime_codeframe.php | 69 +- .../smarty_internal_runtime_filterhandler.php | 4 +- .../smarty_internal_runtime_foreach.php | 66 +- ...smarty_internal_runtime_getincludepath.php | 21 +- .../smarty_internal_runtime_inheritance.php | 69 +- .../smarty_internal_runtime_tplfunction.php | 6 +- .../smarty_internal_runtime_updatecache.php | 132 +- .../smarty_internal_runtime_updatescope.php | 2 +- .../smarty_internal_runtime_writefile.php | 24 +- ...smarty_internal_smartytemplatecompiler.php | 8 +- .../sysplugins/smarty_internal_template.php | 85 +- .../smarty_internal_templatebase.php | 46 +- .../smarty_internal_templatecompilerbase.php | 1346 +++--- .../smarty_internal_templatelexer.php | 723 ++- .../smarty_internal_templateparser.php | 4022 ++++++++++------- .../smarty_internal_testinstall.php | 417 +- smarty/libs/sysplugins/smarty_resource.php | 198 +- .../sysplugins/smarty_resource_custom.php | 4 +- .../sysplugins/smarty_resource_recompiled.php | 5 +- .../sysplugins/smarty_resource_uncompiled.php | 2 +- smarty/libs/sysplugins/smarty_security.php | 115 +- .../sysplugins/smarty_template_cached.php | 9 +- .../sysplugins/smarty_template_compiled.php | 143 +- .../smarty_template_resource_base.php | 13 +- .../sysplugins/smarty_template_source.php | 12 +- .../sysplugins/smarty_undefined_variable.php | 12 +- .../sysplugins/smartycompilerexception.php | 3 + smarty/libs/sysplugins/smartyexception.php | 3 + 167 files changed, 6672 insertions(+), 5586 deletions(-) create mode 100644 smarty/libs/plugins/modifier.mb_wordwrap.php delete mode 100644 smarty/libs/plugins/modifier.needle.php delete mode 100644 smarty/libs/plugins/shared.mb_wordwrap.php create mode 100644 smarty/libs/sysplugins/smarty_internal_compile_child.php create mode 100644 smarty/libs/sysplugins/smarty_internal_compile_parent.php create mode 100644 smarty/libs/sysplugins/smarty_internal_errorhandler.php create mode 100644 smarty/libs/sysplugins/smarty_internal_method_literals.php diff --git a/smarty/libs/Autoloader.php b/smarty/libs/Autoloader.php index d3b039ca..3a0da8fa 100644 --- a/smarty/libs/Autoloader.php +++ b/smarty/libs/Autoloader.php @@ -14,13 +14,13 @@ * require_once '...path/Autoloader.php'; * Smarty_Autoloader::register(); * or - * include '...path/bootstarp.php'; + * include '...path/bootstrap.php'; * * $smarty = new Smarty(); */ class Smarty_Autoloader { - /** + /** * Filepath to Smarty root * * @var string @@ -76,7 +76,7 @@ class Smarty_Autoloader self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR; self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR; - if (version_compare(phpversion(), '5.3.0', '>=')) { + if (version_compare(PHP_VERSION, '5.3.0', '>=')) { spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); } else { spl_autoload_register(array(__CLASS__, 'autoload')); diff --git a/smarty/libs/Smarty.class.php b/smarty/libs/Smarty.class.php index 57eedfb9..597fbbf0 100644 --- a/smarty/libs/Smarty.class.php +++ b/smarty/libs/Smarty.class.php @@ -21,34 +21,44 @@ * smarty-discussion-subscribe@googlegroups.com * * @link http://www.smarty.net/ - * @copyright 2016 New Digital Group, Inc. - * @copyright 2016 Uwe Tews + * @copyright 2018 New Digital Group, Inc. + * @copyright 2018 Uwe Tews * @author Monte Ohrt - * @author Uwe Tews + * @author Uwe Tews * @author Rodney Rehm * @package Smarty - * @version 3.1.31 + * @version 3.1.32 */ - /** * set SMARTY_DIR to absolute path to Smarty library files. * Sets SMARTY_DIR only if user application has not already defined it. */ if (!defined('SMARTY_DIR')) { + /** + * + */ define('SMARTY_DIR', dirname(__FILE__) . 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')); } if (!defined('SMARTY_RESOURCE_CHAR_SET')) { @@ -64,14 +74,12 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { */ define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y'); } - /** * Load Smarty_Autoloader */ if (!class_exists('Smarty_Autoloader')) { - include __DIR__ . '/bootstrap.php'; + include dirname(__FILE__) . '/bootstrap.php'; } - /** * Load always needed external class files */ @@ -95,337 +103,196 @@ require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php'; * * @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, int $max_errors = null) - * @method int compileAllConfig(string $extension = '.conf', bool $force_compile = false, int $time_limit = 0, int $max_errors = 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 { - /**#@+ - * constant definitions - */ - /** * smarty version */ - const SMARTY_VERSION = '3.1.31'; - + const SMARTY_VERSION = '3.1.32'; /** * define variable scopes */ - const SCOPE_LOCAL = 1; - - const SCOPE_PARENT = 2; - + 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; - + const SCOPE_ROOT = 8; + const SCOPE_SMARTY = 16; + const SCOPE_GLOBAL = 32; /** * define caching modes */ - const CACHING_OFF = 0; - + const CACHING_OFF = 0; const CACHING_LIFETIME_CURRENT = 1; - - const CACHING_LIFETIME_SAVED = 2; - + const CACHING_LIFETIME_SAVED = 2; /** * define constant for clearing cache files be saved expiration dates */ - const CLEAR_EXPIRED = - 1; - + const CLEAR_EXPIRED = -1; /** * define compile check modes */ - const COMPILECHECK_OFF = 0; - - const COMPILECHECK_ON = 1; - + 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_OFF = 0; + const DEBUG_ON = 1; const DEBUG_INDIVIDUAL = 2; - /** * modes for handling of "" tags in templates. */ const PHP_PASSTHRU = 0; //-> print tags as plain text - - const PHP_QUOTE = 1; //-> escape tags as entities - - const PHP_REMOVE = 2; //-> escape tags as entities - - const PHP_ALLOW = 3; //-> escape tags as entities - + const PHP_QUOTE = 1; //-> escape tags as entities + const PHP_REMOVE = 2; //-> escape tags as entities + const PHP_ALLOW = 3; //-> escape tags as entities /** * filter types */ - const FILTER_POST = 'post'; - - const FILTER_PRE = 'pre'; - - const FILTER_OUTPUT = 'output'; - + const FILTER_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_FUNCTION = 'function'; + const PLUGIN_BLOCK = 'block'; + const PLUGIN_COMPILER = 'compiler'; + const PLUGIN_MODIFIER = 'modifier'; const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler'; - - /** - * Resource caching modes - * (not used since 3.1.30) - */ - const RESOURCE_CACHE_OFF = 0; - - const RESOURCE_CACHE_AUTOMATIC = 1; // cache template objects by rules - - const RESOURCE_CACHE_TEMPLATE = 2; // cache all template objects - - const RESOURCE_CACHE_ON = 4; // cache source and compiled resources - - /**#@-*/ - /** * assigned global tpl vars */ public static $global_tpl_vars = array(); - - /** - * error handler returned by set_error_handler() in Smarty::muteExpectedErrors() - */ - public static $_previous_error_handler = null; - - /** - * contains directories outside of SMARTY_DIR that are to be muted by muteExpectedErrors() - */ - public static $_muted_directories = 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_RESOURCE_CHAR_SET; - /** * The date format to be used internally * (accepts date() and strftime()) */ public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT; - /** * 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; - - /**#@+ - * variables - */ - /** * 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; - - /** - * template directory - * - * @var array - */ - protected $template_dir = array('./templates/'); - - /** - * flags for normalized template directory entries - * - * @var array - */ - protected $_processedTemplateDir = array(); - /** * 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; - - /** - * config directory - * - * @var array - */ - protected $config_dir = array('./configs/'); - - /** - * flags for normalized template directory entries - * - * @var array - */ - protected $_processedConfigDir = array(); - /** * 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; - - /** - * compile directory - * - * @var string - */ - protected $compile_dir = './templates_c/'; - /** * flag if template_dir is normalized * * @var bool */ public $_compileDirNormalized = false; - - /** - * plugins directory - * - * @var array - */ - protected $plugins_dir = array(); - /** * flag if plugins_dir is normalized * * @var bool */ public $_pluginsDirNormalized = false; - - /** - * cache directory - * - * @var string - */ - protected $cache_dir = './cache/'; - /** * flag if template_dir is normalized * * @var bool */ public $_cacheDirNormalized = false; - /** * force template compiling? * * @var boolean */ public $force_compile = false; - - /** - * check template for modifications? - * - * @var boolean - */ - public $compile_check = true; - - /** + /** * use sub dirs for compiled/cached files? * * @var boolean */ public $use_sub_dirs = false; - /** * 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. @@ -434,31 +301,30 @@ class Smarty extends Smarty_Internal_TemplateBase * @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 = "}"; - - /**#@+ - * security + /** + * 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. @@ -467,29 +333,24 @@ class Smarty extends Smarty_Internal_TemplateBase * @see Smarty_Security */ public $security_class = 'Smarty_Security'; - /** * implementation of security class * * @var Smarty_Security */ public $security_policy = null; - /** * controls handling of PHP-blocks * * @var integer */ public $php_handling = self::PHP_PASSTHRU; - /** * controls if the php template file resource is allowed * * @var bool */ public $allow_php_templates = false; - - /**#@-*/ /** * debug mode * Setting this to true enables the debug-console. @@ -497,7 +358,6 @@ class Smarty extends Smarty_Internal_TemplateBase * @var boolean */ public $debugging = false; - /** * This determines if debugging is enable-able from the browser. *
    @@ -508,7 +368,6 @@ class Smarty extends Smarty_Internal_TemplateBase * @var string */ public $debugging_ctrl = 'NONE'; - /** * Name of debugging URL-param. * Only used when $debugging_ctrl is set to 'URL'. @@ -517,75 +376,54 @@ class Smarty extends Smarty_Internal_TemplateBase * @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; - - /**#@+ - * config var settings - */ - /** * Controls whether variables with the same name overwrite each other. * * @var boolean */ public $config_overwrite = true; - /** * Controls whether config values of on/true/yes and off/false/no get converted to boolean. * * @var boolean */ public $config_booleanize = true; - /** * Controls whether hidden config sections/vars are read from the file. * * @var boolean */ public $config_read_hidden = false; - - /**#@-*/ - - /**#@+ - * resource locking - */ - /** * locking concurrent compiles * * @var boolean */ public $compile_locking = true; - /** * Controls whether cache resources should 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. @@ -593,7 +431,6 @@ class Smarty extends Smarty_Internal_TemplateBase * @var string */ public $default_resource_type = 'file'; - /** * caching type * Must be an element of $cache_resource_types. @@ -601,145 +438,160 @@ class Smarty extends Smarty_Internal_TemplateBase * @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; - /** - * Directory separator + * 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 */ - public $ds = DIRECTORY_SEPARATOR; - + 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[] */ - private $obsoleteProperties = array('resource_caching', 'template_resource_caching', 'direct_access_security', - '_dir_perms', '_file_perms', 'plugin_search_order', - 'inheritance_merge_compiled_includes', 'resource_cache_mode',); - + 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[] */ - private $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir', - 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir', - 'cache_dir' => 'CacheDir',); - - /**#@-*/ + protected $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir', + 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir', + 'cache_dir' => 'CacheDir',); /** * Initialize new Smarty object @@ -752,11 +604,9 @@ class Smarty extends Smarty_Internal_TemplateBase 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 @@ -765,12 +615,34 @@ class Smarty extends Smarty_Internal_TemplateBase } } + /** + * Enable error handler to mute expected messages + * + * @return boolean + * @deprecated + */ + public static function muteExpectedErrors() + { + return Smarty_Internal_ErrorHandler::muteExpectedErrors(); + } + + /** + * Disable error handler muting expected messages + * + * @deprecated + */ + public static function unmuteExpectedErrors() + { + restore_error_handler(); + } + /** * Check if a template resource exists * * @param string $resource_name template name * - * @return boolean status + * @return bool status + * @throws \SmartyException */ public function templateExists($resource_name) { @@ -801,28 +673,6 @@ class Smarty extends Smarty_Internal_TemplateBase public function disableSecurity() { $this->security_policy = null; - - return $this; - } - - /** - * 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; } @@ -886,7 +736,7 @@ class Smarty extends Smarty_Internal_TemplateBase $dir = &$this->template_dir; } if ($isConfig ? !$this->_configDirNormalized : !$this->_templateDirNormalized) { - $this->_nomalizeTemplateConfig($isConfig); + $this->_normalizeTemplateConfig($isConfig); } if ($index !== null) { return isset($dir[ $index ]) ? $dir[ $index ] : null; @@ -895,15 +745,24 @@ class Smarty extends Smarty_Internal_TemplateBase } /** - * Set config directory + * Set template directory * - * @param $config_dir + * @param string|array $template_dir directory(s) of template sources + * @param bool $isConfig true for config_dir * - * @return Smarty current Smarty instance for chaining + * @return \Smarty current Smarty instance for chaining */ - public function setConfigDir($config_dir) + public function setTemplateDir($template_dir, $isConfig = false) { - return $this->setTemplateDir($config_dir, true); + 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; } /** @@ -932,23 +791,21 @@ class Smarty extends Smarty_Internal_TemplateBase } /** - * Set plugins directory + * Set config directory * - * @param string|array $plugins_dir directory(s) of plugins + * @param $config_dir * * @return Smarty current Smarty instance for chaining */ - public function setPluginsDir($plugins_dir) + public function setConfigDir($config_dir) { - $this->plugins_dir = (array) $plugins_dir; - $this->_pluginsDirNormalized = false; - return $this; + return $this->setTemplateDir($config_dir, true); } /** * Adds directory of plugin files * - * @param null|array $plugins_dir + * @param null|array|string $plugins_dir * * @return Smarty current Smarty instance for chaining */ @@ -957,7 +814,7 @@ class Smarty extends Smarty_Internal_TemplateBase if (empty($this->plugins_dir)) { $this->plugins_dir[] = SMARTY_PLUGINS_DIR; } - $this->plugins_dir = array_merge($this->plugins_dir, (array) $plugins_dir); + $this->plugins_dir = array_merge($this->plugins_dir, (array)$plugins_dir); $this->_pluginsDirNormalized = false; return $this; } @@ -975,10 +832,10 @@ class Smarty extends Smarty_Internal_TemplateBase } if (!$this->_pluginsDirNormalized) { if (!is_array($this->plugins_dir)) { - $this->plugins_dir = (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, "/\\") . $this->ds, true); + $this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true); } $this->_cache[ 'plugin_files' ] = array(); $this->_pluginsDirNormalized = true; @@ -987,15 +844,16 @@ class Smarty extends Smarty_Internal_TemplateBase } /** + * Set plugins directory * - * @param string $compile_dir directory to store compiled templates in + * @param string|array $plugins_dir directory(s) of plugins * - * @return Smarty current Smarty instance for chaining + * @return Smarty current Smarty instance for chaining */ - public function setCompileDir($compile_dir) + public function setPluginsDir($plugins_dir) { - $this->_normalizeDir('compile_dir', $compile_dir); - $this->_compileDirNormalized = true; + $this->plugins_dir = (array)$plugins_dir; + $this->_pluginsDirNormalized = false; return $this; } @@ -1014,16 +872,15 @@ class Smarty extends Smarty_Internal_TemplateBase } /** - * Set cache directory * - * @param string $cache_dir directory to store cached templates in + * @param string $compile_dir directory to store compiled templates in * * @return Smarty current Smarty instance for chaining */ - public function setCacheDir($cache_dir) + public function setCompileDir($compile_dir) { - $this->_normalizeDir('cache_dir', $cache_dir); - $this->_cacheDirNormalized = true; + $this->_normalizeDir('compile_dir', $compile_dir); + $this->_compileDirNormalized = true; return $this; } @@ -1042,46 +899,17 @@ class Smarty extends Smarty_Internal_TemplateBase } /** - * 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, "/\\") . $this->ds, true); - if (!isset(Smarty::$_muted_directories[ $this->{$dirName} ])) { - Smarty::$_muted_directories[ $this->{$dirName} ] = null; - } - } - - /** - * Normalize template_dir or config_dir + * Set cache directory * - * @param bool $isConfig true for config_dir + * @param string $cache_dir directory to store cached templates in * + * @return Smarty current Smarty instance for chaining */ - private function _nomalizeTemplateConfig($isConfig) + public function setCacheDir($cache_dir) { - 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, "/\\") . $this->ds, 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); + $this->_normalizeDir('cache_dir', $cache_dir); + $this->_cacheDirNormalized = true; + return $this; } /** @@ -1093,7 +921,8 @@ class Smarty extends Smarty_Internal_TemplateBase * @param object $parent next higher level of Smarty variables * @param boolean $do_clone flag is Smarty object shall be cloned * - * @return object template object + * @return \Smarty_Internal_Template template object + * @throws \SmartyException */ public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true) { @@ -1108,7 +937,7 @@ class Smarty extends Smarty_Internal_TemplateBase $data = null; } if (!$this->_templateDirNormalized) { - $this->_nomalizeTemplateConfig(false); + $this->_normalizeTemplateConfig(false); } $_templateId = $this->_getTemplateId($template, $cache_id, $compile_id); $tpl = null; @@ -1137,10 +966,10 @@ class Smarty extends Smarty_Internal_TemplateBase $tpl->tpl_vars[ $_key ] = new Smarty_Variable($_val); } } - if ($this->debugging || $this->debugging_ctrl == 'URL') { + 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') { + if (!$this->debugging && $this->debugging_ctrl === 'URL') { $tpl->smarty->_debug->debugUrl($tpl->smarty); } } @@ -1173,16 +1002,19 @@ class Smarty extends Smarty_Internal_TemplateBase * @param \Smarty_Internal_Template $template * * @return string + * @throws \SmartyException */ - public function _getTemplateId($template_name, $cache_id = null, $compile_id = null, $caching = null, + 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); - + $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) . @@ -1210,38 +1042,51 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function _realpath($path, $realpath = null) { - $nds = $this->ds == '/' ? '\\' : '/'; - // normalize $this->ds - $path = str_replace($nds, $this->ds, $path); - preg_match('%^(?(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?(?:[[:print:]]*))$%', - $path, $parts); + static $nds = null; + static $sepDotsep = null; + static $sepDot = null; + static $sepSep =null; + if (!isset($nds)) { + $nds = array('/' => '\\', '\\' => '/'); + $sepDotsep = DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR; + $sepDot = DIRECTORY_SEPARATOR . '.'; + $sepSep = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; + } + // normalize DIRECTORY_SEPARATOR + $path = str_replace(array($nds[DIRECTORY_SEPARATOR], $sepDotsep), DIRECTORY_SEPARATOR, $path); + if (strpos($path,$sepDot) === false && (($realpath === false && $path[0] === '.') || $realpath === null) && $path[0] !== '\\') { + return $path; + } + preg_match('%^(?(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?(.*))$%u', + $path, + $parts); $path = $parts[ 'path' ]; - if ($parts[ 'root' ] == '\\') { + if ($parts[ 'root' ] === '\\') { $parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ]; } else { if ($realpath !== null && !$parts[ 'root' ]) { - $path = getcwd() . $this->ds . $path; + $path = getcwd() . DIRECTORY_SEPARATOR . $path; } } - // remove noop 'DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR' and 'DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR' patterns - $path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#', $this->ds, $path); + // remove noop 'DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR' and 'DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR' patterns + $path = str_replace(array($sepDotsep,$sepSep), DIRECTORY_SEPARATOR, $path); // resolve '..DIRECTORY_SEPARATOR' pattern, smallest first - if (strpos($path, '..' . $this->ds) != false && - preg_match_all('#(([.]?[\\\\/])*([.][.])[\\\\/]([.]?[\\\\/])*)+#', $path, $match) + if (strpos($path, '..' . DIRECTORY_SEPARATOR) !== false && + preg_match_all('#[\\\\/]([.][.][\\\\/])+#u', $path, $match) ) { $counts = array(); foreach ($match[ 0 ] as $m) { - $counts[] = (int) ((strlen($m) - 1) / 3); + $counts[] = (int)((strlen($m) - 1) / 3); } sort($counts); foreach ($counts as $count) { - $path = preg_replace('#(([\\\\/]([.]?[\\\\/])*[^\\\\/.]+){' . $count . - '}[\\\\/]([.]?[\\\\/])*([.][.][\\\\/]([.]?[\\\\/])*){' . $count . '})(?=[^.])#', - $this->ds, $path); + $path = preg_replace('#([\\\\/]+[^\\\\/]+){' . $count . + '}[\\\\/]+([.][.][\\\\/]+){' . $count . '}#u', + DIRECTORY_SEPARATOR, + $path); } } - - return $parts[ 'root' ] . $path; + return $realpath !== false ? $parts[ 'root' ] . $path : str_ireplace(getcwd(), '.', $parts[ 'root' ] . $path); } /** @@ -1253,24 +1098,6 @@ class Smarty extends Smarty_Internal_TemplateBase Smarty_Internal_Template::$tplObjCache = array(); } - /** - * Get Smarty object - * - * @return Smarty - */ - public function _getSmartyObj() - { - return $this; - } - - /** - * @param boolean $compile_check - */ - public function setCompileCheck($compile_check) - { - $this->compile_check = $compile_check; - } - /** * @param boolean $use_sub_dirs */ @@ -1296,9 +1123,21 @@ class Smarty extends Smarty_Internal_TemplateBase } /** + * 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) + public function setAutoLiteral($auto_literal = true) { $this->auto_literal = $auto_literal; } @@ -1320,6 +1159,18 @@ class Smarty extends Smarty_Internal_TemplateBase } /** + * Get left delimiter + * + * @return string + */ + public function getLeftDelimiter() + { + return $this->left_delimiter; + } + + /** + * Set left delimiter + * * @param string $left_delimiter */ public function setLeftDelimiter($left_delimiter) @@ -1328,7 +1179,19 @@ class Smarty extends Smarty_Internal_TemplateBase } /** - * @param string $right_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) { @@ -1401,6 +1264,16 @@ class Smarty extends Smarty_Internal_TemplateBase Smarty_Internal_TestInstall::testInstall($this, $errors); } + /** + * Get Smarty object + * + * @return Smarty + */ + public function _getSmartyObj() + { + return $this; + } + /** * <> Generic getter. * Calls the appropriate getter function. @@ -1409,15 +1282,16 @@ class Smarty extends Smarty_Internal_TemplateBase * @param string $name property name * * @return mixed + * @throws \SmartyException */ public function __get($name) { if (isset($this->accessMap[ $name ])) { $method = 'get' . $this->accessMap[ $name ]; return $this->{$method}(); - } elseif (isset($this->_cache[ $name ])) { + } else if (isset($this->_cache[ $name ])) { return $this->_cache[ $name ]; - } elseif (in_array($name, $this->obsoleteProperties)) { + } else if (in_array($name, $this->obsoleteProperties)) { return null; } else { trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); @@ -1432,13 +1306,15 @@ class Smarty extends Smarty_Internal_TemplateBase * * @param string $name property name * @param mixed $value parameter passed to setter + * + * @throws \SmartyException */ public function __set($name, $value) { if (isset($this->accessMap[ $name ])) { $method = 'set' . $this->accessMap[ $name ]; $this->{$method}($value); - } elseif (in_array($name, $this->obsoleteProperties)) { + } else if (in_array($name, $this->obsoleteProperties)) { return; } else { if (is_object($value) && method_exists($value, $name)) { @@ -1450,100 +1326,47 @@ class Smarty extends Smarty_Internal_TemplateBase } /** - * Error Handler to mute expected messages - * - * @link http://php.net/set_error_handler - * - * @param integer $errno Error level - * @param $errstr - * @param $errfile - * @param $errline - * @param $errcontext + * Normalize and set directory string * - * @return bool|void + * @param string $dirName cache_dir or compile_dir + * @param string $dir filepath of folder */ - public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) + private function _normalizeDir($dirName, $dir) { - $_is_muted_directory = false; - - // add the SMARTY_DIR to the list of muted directories - if (!isset(Smarty::$_muted_directories[ SMARTY_DIR ])) { - $smarty_dir = realpath(SMARTY_DIR); - if ($smarty_dir !== false) { - Smarty::$_muted_directories[ SMARTY_DIR ] = - array('file' => $smarty_dir, 'length' => strlen($smarty_dir),); - } - } - - // walk the muted directories and test against $errfile - foreach (Smarty::$_muted_directories as $key => &$dir) { - if (!$dir) { - // resolve directory and length for speedy comparisons - $file = realpath($key); - if ($file === false) { - // this directory does not exist, remove and skip it - unset(Smarty::$_muted_directories[ $key ]); - continue; - } - $dir = array('file' => $file, 'length' => strlen($file),); - } - if (!strncmp($errfile, $dir[ 'file' ], $dir[ 'length' ])) { - $_is_muted_directory = true; - break; - } - } - // pass to next error handler if this error did not occur inside SMARTY_DIR - // or the error was within smarty but masked to be ignored - if (!$_is_muted_directory || ($errno && $errno & error_reporting())) { - if (Smarty::$_previous_error_handler) { - return call_user_func(Smarty::$_previous_error_handler, $errno, $errstr, $errfile, $errline, - $errcontext); - } else { - return false; + $this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . DIRECTORY_SEPARATOR, true); + if (class_exists('Smarty_Internal_ErrorHandler', false)) { + if (!isset(Smarty_Internal_ErrorHandler::$mutedDirectories[ $this->{$dirName} ])) { + Smarty_Internal_ErrorHandler::$mutedDirectories[ $this->{$dirName} ] = null; } } - return; } /** - * Enable error handler to mute expected messages + * Normalize template_dir or config_dir * - * @return void - */ - public static function muteExpectedErrors() - { - /* - error muting is done because some people implemented custom error_handlers using - http://php.net/set_error_handler and for some reason did not understand the following paragraph: - - It is important to remember that the standard PHP error handler is completely bypassed for the - error types specified by error_types unless the callback function returns FALSE. - error_reporting() settings will have no effect and your error handler will be called regardless - - however you are still able to read the current value of error_reporting and act appropriately. - Of particular note is that this value will be 0 if the statement that caused the error was - prepended by the @ error-control operator. - - Smarty deliberately uses @filemtime() over file_exists() and filemtime() in some places. Reasons include - - @filemtime() is almost twice as fast as using an additional file_exists() - - between file_exists() and filemtime() a possible race condition is opened, - which does not exist using the simple @filemtime() approach. - */ - $error_handler = array('Smarty', 'mutingErrorHandler'); - $previous = set_error_handler($error_handler); - - // avoid dead loops - if ($previous !== $error_handler) { - Smarty::$_previous_error_handler = $previous; - } - } - - /** - * Disable error handler muting expected messages + * @param bool $isConfig true for config_dir * - * @return void */ - public static function unmuteExpectedErrors() + private function _normalizeTemplateConfig($isConfig) { - restore_error_handler(); + 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); } } diff --git a/smarty/libs/SmartyBC.class.php b/smarty/libs/SmartyBC.class.php index 3955e4f2..f2230fc9 100644 --- a/smarty/libs/SmartyBC.class.php +++ b/smarty/libs/SmartyBC.class.php @@ -100,6 +100,8 @@ class SmartyBC extends Smarty * @param string $function_impl the name of the PHP function to register * @param bool $cacheable * @param mixed $cache_attrs + * + * @throws \SmartyException */ public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null) { @@ -153,6 +155,8 @@ class SmartyBC extends Smarty * @param string $block_impl PHP function to register * @param bool $cacheable * @param mixed $cache_attrs + * + * @throws \SmartyException */ public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null) { @@ -175,6 +179,8 @@ class SmartyBC extends Smarty * @param string $function name of template function * @param string $function_impl name of PHP function to register * @param bool $cacheable + * + * @throws \SmartyException */ public function register_compiler_function($function, $function_impl, $cacheable = true) { @@ -196,6 +202,8 @@ class SmartyBC extends Smarty * * @param string $modifier name of template modifier * @param string $modifier_impl name of PHP function to register + * + * @throws \SmartyException */ public function register_modifier($modifier, $modifier_impl) { @@ -238,6 +246,8 @@ class SmartyBC extends Smarty * to a template before compiling * * @param callable $function + * + * @throws \SmartyException */ public function register_prefilter($function) { @@ -259,6 +269,8 @@ class SmartyBC extends Smarty * to a compiled template after compilation * * @param callable $function + * + * @throws \SmartyException */ public function register_postfilter($function) { @@ -280,6 +292,8 @@ class SmartyBC extends Smarty * to a template output * * @param callable $function + * + * @throws \SmartyException */ public function register_outputfilter($function) { @@ -301,6 +315,8 @@ class SmartyBC extends Smarty * * @param string $type filter type * @param string $name filter name + * + * @throws \SmartyException */ public function load_filter($type, $name) { @@ -341,7 +357,9 @@ class SmartyBC extends Smarty * @param string $cache_id * @param string $compile_id * - * @return boolean + * @return bool + * @throws \Exception + * @throws \SmartyException */ public function is_cached($tpl_file, $cache_id = null, $compile_id = null) { @@ -377,7 +395,8 @@ class SmartyBC extends Smarty * * @param string $tpl_file * - * @return boolean + * @return bool + * @throws \SmartyException */ public function template_exists($tpl_file) { diff --git a/smarty/libs/bootstrap.php b/smarty/libs/bootstrap.php index 32096087..dad72fcb 100644 --- a/smarty/libs/bootstrap.php +++ b/smarty/libs/bootstrap.php @@ -12,6 +12,6 @@ * Load and register Smarty Autoloader */ if (!class_exists('Smarty_Autoloader')) { - require __DIR__ . '/Autoloader.php'; + require dirname(__FILE__) . '/Autoloader.php'; } -Smarty_Autoloader::register(); +Smarty_Autoloader::register(true); diff --git a/smarty/libs/plugins/block.textformat.php b/smarty/libs/plugins/block.textformat.php index e2c5e3de..310a420e 100644 --- a/smarty/libs/plugins/block.textformat.php +++ b/smarty/libs/plugins/block.textformat.php @@ -5,22 +5,21 @@ * @package Smarty * @subpackage PluginsBlock */ - /** * Smarty {textformat}{/textformat} block plugin - * Type: block function
    - * Name: textformat
    + * Type: block function + * Name: textformat * Purpose: format text a certain way with preset styles - * or custom wrap/indent settings
    + * or custom wrap/indent settings * Params: - *
    + *
      * - style         - string (email)
      * - indent        - integer (0)
      * - wrap          - integer (80)
      * - wrap_char     - string ("\n")
      * - indent_char   - string (" ")
      * - wrap_boundary - boolean (true)
    - * 
    + * * * @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat} * (Smarty online manual) @@ -32,14 +31,16 @@ * * @return string content re-formatted * @author Monte Ohrt + * @throws \SmartyException */ -function smarty_block_textformat($params, $content, $template, &$repeat) +function smarty_block_textformat($params, $content, Smarty_Internal_Template $template, &$repeat) { if (is_null($content)) { return; } - if (Smarty::$_MBSTRING && !is_callable('smarty_mb_wordwrap')) { - require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'); + if (Smarty::$_MBSTRING) { + $template->_checkPlugins(array(array('function' => 'smarty_modifier_mb_wordwrap', + 'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'))); } $style = null; @@ -71,11 +72,11 @@ function smarty_block_textformat($params, $content, $template, &$repeat) break; default: - trigger_error("textformat: unknown attribute '$_key'"); + trigger_error("textformat: unknown attribute '{$_key}'"); } } - if ($style == 'email') { + if ($style === 'email') { $wrap = 72; } // split into paragraphs @@ -87,15 +88,17 @@ function smarty_block_textformat($params, $content, $template, &$repeat) } // convert mult. spaces & special chars to single space $_paragraph = - preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), - array(' ', ''), $_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_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); + $_paragraph = smarty_modifier_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); } else { $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); } diff --git a/smarty/libs/plugins/function.counter.php b/smarty/libs/plugins/function.counter.php index bcc8f498..9610362d 100644 --- a/smarty/libs/plugins/function.counter.php +++ b/smarty/libs/plugins/function.counter.php @@ -8,8 +8,8 @@ /** * Smarty {counter} function plugin - * Type: function
    - * Name: counter
    + * Type: function + * Name: counter * Purpose: print out a counter value * * @author Monte Ohrt @@ -63,7 +63,7 @@ function smarty_function_counter($params, $template) $counter[ 'direction' ] = $params[ 'direction' ]; } - if ($counter[ 'direction' ] == "down") { + if ($counter[ 'direction' ] === 'down') { $counter[ 'count' ] -= $counter[ 'skip' ]; } else { $counter[ 'count' ] += $counter[ 'skip' ]; diff --git a/smarty/libs/plugins/function.cycle.php b/smarty/libs/plugins/function.cycle.php index a76d49ae..b871524f 100644 --- a/smarty/libs/plugins/function.cycle.php +++ b/smarty/libs/plugins/function.cycle.php @@ -8,12 +8,12 @@ /** * Smarty {cycle} function plugin - * Type: function
    - * Name: cycle
    - * Date: May 3, 2002
    - * Purpose: cycle through given values
    + * Type: function + * Name: cycle + * Date: May 3, 2002 + * Purpose: cycle through given values * Params: - *
    + *
      * - name      - name of cycle (optional)
      * - values    - comma separated list of values to cycle, or an array of values to cycle
      *               (this can be left out for subsequent calls)
    @@ -22,13 +22,13 @@
      * - advance   - boolean - whether or not to advance the cycle
      * - delimiter - the value delimiter, default is ","
      * - assign    - boolean, assigns to template var instead of printed.
    - * 
    - * Examples:
    - *
    + *
    + * Examples:
    + *
      * {cycle values="#eeeeee,#d0d0d0d"}
      * {cycle name=row values="one,two,three" reset=true}
      * {cycle name=row}
    - * 
    + * * * @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle} * (Smarty online manual) @@ -55,12 +55,12 @@ function smarty_function_cycle($params, $template) if (!isset($params[ 'values' ])) { if (!isset($cycle_vars[ $name ][ 'values' ])) { - trigger_error("cycle: missing 'values' parameter"); + trigger_error('cycle: missing \'values\' parameter'); return; } } else { - if (isset($cycle_vars[ $name ][ 'values' ]) && $cycle_vars[ $name ][ 'values' ] != $params[ 'values' ]) { + if (isset($cycle_vars[ $name ][ 'values' ]) && $cycle_vars[ $name ][ 'values' ] !== $params[ 'values' ]) { $cycle_vars[ $name ][ 'index' ] = 0; } $cycle_vars[ $name ][ 'values' ] = $params[ 'values' ]; diff --git a/smarty/libs/plugins/function.fetch.php b/smarty/libs/plugins/function.fetch.php index cb60dd91..9539e1fc 100644 --- a/smarty/libs/plugins/function.fetch.php +++ b/smarty/libs/plugins/function.fetch.php @@ -8,8 +8,8 @@ /** * Smarty {fetch} plugin - * Type: function
    - * Name: fetch
    + * Type: function + * Name: fetch * Purpose: fetch file, web or ftp data and display results * * @link http://www.smarty.net/manual/en/language.function.fetch.php {fetch} @@ -25,7 +25,7 @@ function smarty_function_fetch($params, $template) { if (empty($params[ 'file' ])) { - trigger_error("[plugin] fetch parameter 'file' cannot be empty", E_USER_NOTICE); + trigger_error('[plugin] fetch parameter \'file\' cannot be empty', E_USER_NOTICE); return; } @@ -55,15 +55,15 @@ function smarty_function_fetch($params, $template) } $content = ''; - if ($protocol == 'http') { + 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 = ""; + $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; @@ -81,29 +81,29 @@ function smarty_function_fetch($params, $template) // loop through parameters, setup headers foreach ($params as $param_key => $param_value) { switch ($param_key) { - case "file": - case "assign": - case "assign_headers": + case 'file': + case 'assign': + case 'assign_headers': break; - case "user": + case 'user': if (!empty($param_value)) { $user = $param_value; } break; - case "pass": + case 'pass': if (!empty($param_value)) { $pass = $param_value; } break; - case "accept": + case 'accept': if (!empty($param_value)) { $accept = $param_value; } break; - case "header": + case 'header': if (!empty($param_value)) { if (!preg_match('![\w\d-]+: .+!', $param_value)) { - trigger_error("[plugin] invalid header format '" . $param_value . "'", E_USER_NOTICE); + trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE); return; } else { @@ -111,41 +111,41 @@ function smarty_function_fetch($params, $template) } } break; - case "proxy_host": + case 'proxy_host': if (!empty($param_value)) { $proxy_host = $param_value; } break; - case "proxy_port": + 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); + trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE); return; } break; - case "agent": + case 'agent': if (!empty($param_value)) { $agent = $param_value; } break; - case "referer": + case 'referer': if (!empty($param_value)) { $referer = $param_value; } break; - case "timeout": + 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); + 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); + trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE); return; } @@ -185,7 +185,7 @@ function smarty_function_fetch($params, $template) } } if (!empty($user) && !empty($pass)) { - fputs($fp, "Authorization: BASIC " . base64_encode("$user:$pass") . "\r\n"); + fputs($fp, 'Authorization: BASIC ' . base64_encode("$user:$pass") . "\r\n"); } fputs($fp, "\r\n"); diff --git a/smarty/libs/plugins/function.html_checkboxes.php b/smarty/libs/plugins/function.html_checkboxes.php index 04ce4573..d654caba 100644 --- a/smarty/libs/plugins/function.html_checkboxes.php +++ b/smarty/libs/plugins/function.html_checkboxes.php @@ -5,22 +5,21 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {html_checkboxes} function plugin - * File: function.html_checkboxes.php
    - * Type: function
    - * Name: html_checkboxes
    - * Date: 24.Feb.2003
    - * Purpose: Prints out a list of checkbox input types
    + * File: function.html_checkboxes.php + * Type: function + * Name: html_checkboxes + * Date: 24.Feb.2003 + * Purpose: Prints out a list of checkbox input types * Examples: - *
    + *
      * {html_checkboxes values=$ids output=$names}
      * {html_checkboxes values=$ids name='box' separator='
    ' output=$names} * {html_checkboxes values=$ids checked=$checked separator='
    ' output=$names} - *
    + * * Params: - *
    + *
      * - name       (optional) - string default "checkbox"
      * - values     (required) - array
      * - options    (optional) - associative array
    @@ -29,7 +28,7 @@
      * - 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 http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} * (Smarty online manual) @@ -37,17 +36,17 @@ * @author credits to Monte Ohrt * @version 1.0 * - * @param array $params parameters - * @param object $template template object + * @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, $template) +function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template) { - if (!is_callable('smarty_function_escape_special_chars')) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - } + $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); $name = 'checkbox'; $values = null; @@ -89,11 +88,11 @@ function smarty_function_html_checkboxes($params, $template) $selected = array(); foreach ($_val as $_sel) { if (is_object($_sel)) { - if (method_exists($_sel, "__toString")) { + 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); + trigger_error('html_checkboxes: selected attribute contains an object of class \'' . + get_class($_sel) . '\' without __toString() method', E_USER_NOTICE); continue; } } else { @@ -102,11 +101,11 @@ function smarty_function_html_checkboxes($params, $template) $selected[ $_sel ] = true; } } elseif (is_object($_val)) { - if (method_exists($_val, "__toString")) { + 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); + 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); @@ -129,7 +128,7 @@ function smarty_function_html_checkboxes($params, $template) 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", + trigger_error("html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute", E_USER_NOTICE); } @@ -145,7 +144,7 @@ function smarty_function_html_checkboxes($params, $template) 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); + trigger_error("html_checkboxes: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); } break; } @@ -178,18 +177,30 @@ function smarty_function_html_checkboxes($params, $template) 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) + $label_ids, $escape = true) { $_output = ''; if (is_object($value)) { - if (method_exists($value, "__toString")) { + 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); + trigger_error('html_options: value is an object of class \'' . get_class($value) . + '\' without __toString() method', E_USER_NOTICE); return ''; } @@ -198,11 +209,11 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte } if (is_object($output)) { - if (method_exists($output, "__toString")) { + 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); + trigger_error('html_options: output is an object of class \'' . get_class($output) . + '\' without __toString() method', E_USER_NOTICE); return ''; } diff --git a/smarty/libs/plugins/function.html_image.php b/smarty/libs/plugins/function.html_image.php index 6da8fc54..4fda72ee 100644 --- a/smarty/libs/plugins/function.html_image.php +++ b/smarty/libs/plugins/function.html_image.php @@ -8,20 +8,20 @@ /** * Smarty {html_image} function plugin - * Type: function
    - * Name: html_image
    - * Date: Feb 24, 2003
    - * Purpose: format HTML tags for the image
    - * Examples: {html_image file="/images/masthead.gif"}
    - * Output:
    + * Type: function + * Name: html_image + * Date: Feb 24, 2003 + * Purpose: format HTML tags for the image + * Examples: {html_image file="/images/masthead.gif"} + * Output: * Params: - *
    + *
      * - file        - (required) - file (and path) of image
      * - height      - (optional) - image height (default actual height)
      * - width       - (optional) - image width (default actual width)
      * - basedir     - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT
      * - path_prefix - prefix for path output (optional, default empty)
    - * 
    + * * * @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image} * (Smarty online manual) @@ -36,11 +36,10 @@ * @return string * @uses smarty_function_escape_special_chars() */ -function smarty_function_html_image($params, $template) +function smarty_function_html_image($params, Smarty_Internal_Template $template) { - if (!is_callable('smarty_function_escape_special_chars')) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - } + $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); $alt = ''; $file = ''; @@ -66,7 +65,7 @@ function smarty_function_html_image($params, $template) if (!is_array($_val)) { $$_key = smarty_function_escape_special_chars($_val); } else { - throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + throw new SmartyException ("html_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); } break; @@ -80,19 +79,19 @@ function smarty_function_html_image($params, $template) if (!is_array($_val)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; } else { - throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + throw new SmartyException ("html_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); } break; } } if (empty($file)) { - trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE); + trigger_error('html_image: missing \'file\' parameter', E_USER_NOTICE); return; } - if ($file[ 0 ] == '/') { + if ($file[ 0 ] === '/') { $_image_path = $basedir . $file; } else { $_image_path = $file; @@ -126,15 +125,15 @@ function smarty_function_html_image($params, $template) // FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader! if (!$_image_data = @getimagesize($_image_path)) { if (!file_exists($_image_path)) { - trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE); + trigger_error("html_image: unable to find '{$_image_path}'", E_USER_NOTICE); return; } elseif (!is_readable($_image_path)) { - trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE); + trigger_error("html_image: unable to read '{$_image_path}'", E_USER_NOTICE); return; } else { - trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); + trigger_error("html_image: '{$_image_path}' is not a valid image file", E_USER_NOTICE); return; } diff --git a/smarty/libs/plugins/function.html_options.php b/smarty/libs/plugins/function.html_options.php index bc8f36e0..b8b98649 100644 --- a/smarty/libs/plugins/function.html_options.php +++ b/smarty/libs/plugins/function.html_options.php @@ -5,15 +5,14 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {html_options} function plugin - * Type: function
    - * Name: html_options
    + * Type: function + * Name: html_options * Purpose: Prints the list of