From c23ce16cafb826c8bb4fe7aaf2a5525b29052b23 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 6 Dec 2015 20:12:05 +0100 Subject: update smarty library - seems to bring some performance improvement --- library/Smarty/libs/Autoloader.php | 158 + library/Smarty/libs/Smarty.class.php | 840 ++-- library/Smarty/libs/SmartyBC.class.php | 27 +- library/Smarty/libs/debug.tpl | 57 +- .../Smarty/libs/plugins/modifier.date_format.php | 2 +- .../libs/plugins/modifier.debug_print_var.php | 26 +- .../libs/plugins/outputfilter.trimwhitespace.php | 4 +- .../libs/sysplugins/smarty_cacheresource.php | 225 +- .../sysplugins/smarty_cacheresource_custom.php | 52 +- .../smarty_cacheresource_keyvaluestore.php | 35 +- .../libs/sysplugins/smarty_config_source.php | 94 - library/Smarty/libs/sysplugins/smarty_data.php | 66 + .../smarty_internal_cacheresource_file.php | 49 +- .../sysplugins/smarty_internal_compile_assign.php | 6 +- .../sysplugins/smarty_internal_compile_block.php | 23 +- .../sysplugins/smarty_internal_compile_call.php | 52 +- .../smarty_internal_compile_config_load.php | 3 +- .../sysplugins/smarty_internal_compile_for.php | 45 +- .../sysplugins/smarty_internal_compile_foreach.php | 151 +- .../smarty_internal_compile_function.php | 200 +- .../libs/sysplugins/smarty_internal_compile_if.php | 29 +- .../sysplugins/smarty_internal_compile_include.php | 217 +- .../sysplugins/smarty_internal_compile_insert.php | 20 +- .../sysplugins/smarty_internal_compile_nocache.php | 13 +- .../smarty_internal_compile_private_php.php | 197 + ...y_internal_compile_private_special_variable.php | 132 +- .../sysplugins/smarty_internal_compile_while.php | 9 +- .../libs/sysplugins/smarty_internal_config.php | 306 -- .../smarty_internal_config_file_compiler.php | 75 +- .../sysplugins/smarty_internal_configfilelexer.php | 399 +- .../smarty_internal_configfileparser.php | 710 ++- .../libs/sysplugins/smarty_internal_data.php | 242 +- .../libs/sysplugins/smarty_internal_debug.php | 314 +- .../smarty_internal_extension_codeframe.php | 127 + .../smarty_internal_extension_config.php | 160 + ...y_internal_extension_defaulttemplatehandler.php | 85 + .../smarty_internal_function_call_handler.php | 65 +- .../libs/sysplugins/smarty_internal_parsetree.php | 318 +- .../sysplugins/smarty_internal_parsetree_code.php | 42 + .../sysplugins/smarty_internal_parsetree_dq.php | 86 + .../smarty_internal_parsetree_dqcontent.php | 42 + .../sysplugins/smarty_internal_parsetree_tag.php | 66 + .../smarty_internal_parsetree_template.php | 98 + .../sysplugins/smarty_internal_parsetree_text.php | 40 + .../sysplugins/smarty_internal_resource_eval.php | 6 +- .../smarty_internal_resource_extends.php | 2 +- .../sysplugins/smarty_internal_resource_file.php | 149 +- .../sysplugins/smarty_internal_resource_php.php | 59 +- .../smarty_internal_resource_registered.php | 2 +- .../sysplugins/smarty_internal_resource_stream.php | 4 +- .../sysplugins/smarty_internal_resource_string.php | 6 +- .../smarty_internal_smartytemplatecompiler.php | 16 +- .../libs/sysplugins/smarty_internal_template.php | 736 +-- .../sysplugins/smarty_internal_templatebase.php | 1417 +++--- .../smarty_internal_templatecompilerbase.php | 331 +- .../sysplugins/smarty_internal_templatelexer.php | 1206 ++--- .../sysplugins/smarty_internal_templateparser.php | 5045 ++++++-------------- .../sysplugins/smarty_internal_testinstall.php | 571 +++ .../libs/sysplugins/smarty_internal_utility.php | 540 +-- .../libs/sysplugins/smarty_internal_write_file.php | 12 +- library/Smarty/libs/sysplugins/smarty_resource.php | 732 +-- .../libs/sysplugins/smarty_resource_custom.php | 2 +- .../libs/sysplugins/smarty_resource_recompiled.php | 7 + .../libs/sysplugins/smarty_resource_uncompiled.php | 31 + library/Smarty/libs/sysplugins/smarty_security.php | 170 +- .../libs/sysplugins/smarty_template_cached.php | 403 ++ .../libs/sysplugins/smarty_template_compiled.php | 288 ++ .../libs/sysplugins/smarty_template_config.php | 118 + .../libs/sysplugins/smarty_template_source.php | 285 ++ .../libs/sysplugins/smarty_undefined_variable.php | 37 + library/Smarty/libs/sysplugins/smarty_variable.php | 55 + .../libs/sysplugins/smartycompilerexception.php | 39 + library/Smarty/libs/sysplugins/smartyexception.php | 15 + 73 files changed, 8789 insertions(+), 9402 deletions(-) create mode 100644 library/Smarty/libs/Autoloader.php delete mode 100644 library/Smarty/libs/sysplugins/smarty_config_source.php create mode 100644 library/Smarty/libs/sysplugins/smarty_data.php create mode 100644 library/Smarty/libs/sysplugins/smarty_internal_compile_private_php.php delete mode 100644 library/Smarty/libs/sysplugins/smarty_internal_config.php create mode 100644 library/Smarty/libs/sysplugins/smarty_internal_extension_codeframe.php create mode 100644 library/Smarty/libs/sysplugins/smarty_internal_extension_config.php create mode 100644 library/Smarty/libs/sysplugins/smarty_internal_extension_defaulttemplatehandler.php create mode 100644 library/Smarty/libs/sysplugins/smarty_internal_parsetree_code.php create mode 100644 library/Smarty/libs/sysplugins/smarty_internal_parsetree_dq.php create mode 100644 library/Smarty/libs/sysplugins/smarty_internal_parsetree_dqcontent.php create mode 100644 library/Smarty/libs/sysplugins/smarty_internal_parsetree_tag.php create mode 100644 library/Smarty/libs/sysplugins/smarty_internal_parsetree_template.php create mode 100644 library/Smarty/libs/sysplugins/smarty_internal_parsetree_text.php create mode 100644 library/Smarty/libs/sysplugins/smarty_internal_testinstall.php create mode 100644 library/Smarty/libs/sysplugins/smarty_template_cached.php create mode 100644 library/Smarty/libs/sysplugins/smarty_template_compiled.php create mode 100644 library/Smarty/libs/sysplugins/smarty_template_config.php create mode 100644 library/Smarty/libs/sysplugins/smarty_template_source.php create mode 100644 library/Smarty/libs/sysplugins/smarty_undefined_variable.php create mode 100644 library/Smarty/libs/sysplugins/smarty_variable.php create mode 100644 library/Smarty/libs/sysplugins/smartycompilerexception.php create mode 100644 library/Smarty/libs/sysplugins/smartyexception.php (limited to 'library/Smarty/libs') diff --git a/library/Smarty/libs/Autoloader.php b/library/Smarty/libs/Autoloader.php new file mode 100644 index 000000000..a24cad6f7 --- /dev/null +++ b/library/Smarty/libs/Autoloader.php @@ -0,0 +1,158 @@ + 'Smarty.class.php', + 'SmartyBC' => 'SmartyBC.class.php', + ); + + private static $syspluginsClasses = array( + 'smarty_config_source' => true, + 'smarty_security' => true, + 'smarty_cacheresource' => true, + 'smarty_compiledresource' => true, + 'smarty_cacheresource_custom' => true, + 'smarty_cacheresource_keyvaluestore' => true, + 'smarty_resource' => true, + 'smarty_resource_custom' => true, + 'smarty_resource_uncompiled' => true, + 'smarty_resource_recompiled' => true, + 'smarty_template_source' => true, + 'smarty_template_compiled' => true, + 'smarty_template_cached' => true, + 'smarty_template_config' => true, + 'smarty_data' => true, + 'smarty_variable' => true, + 'smarty_undefined_variable' => true, + 'smartyexception' => true, + 'smartycompilerexception' => true, + 'smarty_internal_data' => true, + 'smarty_internal_template' => true, + 'smarty_internal_templatebase' => true, + 'smarty_internal_resource_file' => true, + 'smarty_internal_resource_extends' => true, + 'smarty_internal_resource_eval' => true, + 'smarty_internal_resource_string' => true, + 'smarty_internal_resource_registered' => true, + 'smarty_internal_extension_codeframe' => true, + 'smarty_internal_extension_config' => true, + 'smarty_internal_filter_handler' => true, + 'smarty_internal_function_call_handler' => true, + 'smarty_internal_cacheresource_file' => true, + 'smarty_internal_write_file' => true, + ); + + /** + * 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 : dirname(__FILE__) . '/'; + self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : self::$SMARTY_DIR . 'sysplugins/'; + if (version_compare(phpversion(), '5.3.0', '>=')) { + spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); + } else { + spl_autoload_register(array(__CLASS__, 'autoload')); + } + } + + /** + * Handles autoloading of classes. + * + * @param string $class A class name. + */ + public static function autoload($class) + { + // Request for Smarty or already unknown class + if (isset(self::$unknown[$class])) { + return; + } + $_class = strtolower($class); + if (isset(self::$syspluginsClasses[$_class])) { + $_class = (self::$syspluginsClasses[$_class] === true) ? $_class : self::$syspluginsClasses[$_class]; + $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; + require_once $file; + return; + } elseif (0 !== strpos($_class, 'smarty_internal_')) { + if (isset(self::$rootClasses[$class])) { + $file = self::$SMARTY_DIR . self::$rootClasses[$class]; + require_once $file; + return; + } + self::$unknown[$class] = true; + return; + } + $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; + if (is_file($file)) { + require_once $file; + return; + } + self::$unknown[$class] = true; + return; + } +} diff --git a/library/Smarty/libs/Smarty.class.php b/library/Smarty/libs/Smarty.class.php index 832b0d309..1f0f2634a 100644 --- a/library/Smarty/libs/Smarty.class.php +++ b/library/Smarty/libs/Smarty.class.php @@ -2,15 +2,17 @@ /** * Project: Smarty: the PHP compiling template engine * File: Smarty.class.php - * SVN: $Id: Smarty.class.php 4897 2014-10-14 22:29:58Z Uwe.Tews@googlemail.com $ + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -19,12 +21,13 @@ * smarty-discussion-subscribe@googlegroups.com * * @link http://www.smarty.net/ - * @copyright 2008 New Digital Group, Inc. + * @copyright 2015 New Digital Group, Inc. + * @copyright 2015 Uwe Tews * @author Monte Ohrt * @author Uwe Tews * @author Rodney Rehm * @package Smarty - * @version 3.1.21 + * @version 3.1.27 */ /** @@ -53,7 +56,7 @@ if (!defined('SMARTY_PLUGINS_DIR')) { define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS); } if (!defined('SMARTY_MBSTRING')) { - define('SMARTY_MBSTRING', function_exists('mb_split')); + define('SMARTY_MBSTRING', function_exists('mb_get_info')); } if (!defined('SMARTY_RESOURCE_CHAR_SET')) { // UTF-8 can only be done properly when mbstring is available! @@ -70,31 +73,29 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { } /** - * register the class autoloader + * Try loading the Smarty_Internal_Data class + * If we fail we must load Smarty's autoloader. + * Otherwise we may have a global autoloader like Composer */ -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(); +if (!class_exists('Smarty_Autoloader', false)) { + if (!class_exists('Smarty_Internal_Data', true)) { + require_once 'Autoloader.php'; + Smarty_Autoloader::registerBC(); } -} else { - spl_autoload_register('smartyAutoload'); } /** * Load always needed external class files */ -include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php'; -include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php'; -include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php'; -include_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php'; -include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php'; -include_once SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php'; -include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_cacheresource_file.php'; + +if (!class_exists('Smarty_Internal_Data', false)) { + require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.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'; /** * This is the main Smarty class @@ -110,21 +111,28 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = 'Smarty-3.1.21-dev'; + const SMARTY_VERSION = '3.1.27'; /** * define variable scopes */ const SCOPE_LOCAL = 0; + const SCOPE_PARENT = 1; + const SCOPE_ROOT = 2; + const SCOPE_GLOBAL = 3; + /** * 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 datees */ @@ -134,29 +142,53 @@ class Smarty extends Smarty_Internal_TemplateBase * 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; + /** * 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 + /** * 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'; /**#@-*/ @@ -170,23 +202,28 @@ class Smarty extends Smarty_Internal_TemplateBase * error handler returned by set_error_hanlder() 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(); + public static $_muted_directories = array('./templates_c/' => null, './cache/' => null); + /** * 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 */ @@ -207,158 +244,154 @@ class Smarty extends Smarty_Internal_TemplateBase * @var boolean */ public $auto_literal = true; + /** * display error on not assigned variables * * @var boolean */ public $error_unassigned = false; + /** * look up relative filepaths in include_path * * @var boolean */ public $use_include_path = false; + /** * template directory * * @var array */ - private $template_dir = array(); + private $template_dir = array('./templates/'); + /** * joined template directory string used in cache keys * * @var string */ - public $joined_template_dir = null; + public $joined_template_dir = './templates/'; + /** * joined config directory string used in cache keys * * @var string */ - public $joined_config_dir = null; + public $joined_config_dir = './configs/'; + /** * 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 */ - private $compile_dir = null; + private $compile_dir = './templates_c/'; + /** * plugins directory * * @var array */ - private $plugins_dir = array(); + private $plugins_dir = null; + /** * cache directory * * @var string */ - private $cache_dir = null; + private $cache_dir = './cache/'; + /** * config directory * * @var array */ - private $config_dir = array(); + private $config_dir = array('./configs/'); + /** * 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; - /** - * caching enabled - * - * @var boolean - */ - public $caching = false; + /** * merge compiled includes * * @var boolean */ public $merge_compiled_includes = false; + /** * template inheritance merge compiled includes * * @var boolean */ public $inheritance_merge_compiled_includes = true; - /** - * cache lifetime in seconds - * - * @var integer - */ - public $cache_lifetime = 3600; + /** * force cache file creation * * @var boolean */ public $force_cache = false; - /** - * Set this if you want different sets of cache files for the same - * templates. - * - * @var string - */ - public $cache_id = null; - /** - * Set this if you want different sets of compiled files for the same - * templates. - * - * @var string - */ - public $compile_id = null; + /** * template left-delimiter * * @var string */ public $left_delimiter = "{"; + /** * template right-delimiter * * @var string */ public $right_delimiter = "}"; + /**#@+ * security */ @@ -370,24 +403,28 @@ 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; + /** * Should compiled-templates be prevented from being called directly? * {@internal @@ -397,6 +434,7 @@ class Smarty extends Smarty_Internal_TemplateBase * @var boolean */ public $direct_access_security = true; + /**#@-*/ /** * debug mode @@ -405,6 +443,7 @@ class Smarty extends Smarty_Internal_TemplateBase * @var boolean */ public $debugging = false; + /** * This determines if debugging is enable-able from the browser. *