diff --git a/smarty.inc.php b/smarty.inc.php index 3dcbf80d..f840e0e7 100644 --- a/smarty.inc.php +++ b/smarty.inc.php @@ -1,5 +1,7 @@ template->debugging = true; $incpath = dirname(__FILE__); - $this->template->template_dir = $incpath.'/templates'; - $this->template->compile_dir = $incpath.'/templates_c'; - $this->template->config_dir = $incpath.'/'.$this->template->config_dir[0]; + $this->template->setTemplateDir(dirname(__FILE__) . '/templates'); + $this->template->setCompileDir(dirname(__FILE__) . '/templates_c'); + $this->template->setConfigDir(dirname(__FILE__) . '/configs'); } public function assign($key, $value, $sanitise = true) { diff --git a/smarty/libs/Autoloader.php b/smarty/libs/Autoloader.php new file mode 100644 index 00000000..7d0c388a --- /dev/null +++ b/smarty/libs/Autoloader.php @@ -0,0 +1,124 @@ + 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',); + + /** + * Registers Smarty_Autoloader backward compatible to older installations. + * + * @param bool $prepend Whether to prepend the autoloader or not. + */ + public static function registerBC($prepend = false) + { + /** + * register the class autoloader + */ + if (!defined('SMARTY_SPL_AUTOLOAD')) { + define('SMARTY_SPL_AUTOLOAD', 0); + } + if (SMARTY_SPL_AUTOLOAD && + set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false + ) { + $registeredAutoLoadFunctions = spl_autoload_functions(); + if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { + spl_autoload_register(); + } + } else { + self::register($prepend); + } + } + + /** + * Registers Smarty_Autoloader as an SPL autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not. + */ + public static function register($prepend = false) + { + self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : 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', '>=')) { + spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); + } else { + spl_autoload_register(array(__CLASS__, 'autoload')); + } + } + + /** + * Handles auto loading of classes. + * + * @param string $class A class name. + */ + public static function autoload($class) + { + $_class = strtolower($class); + $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; + if (strpos($_class, 'smarty_internal_') === 0) { + if (strpos($_class, 'smarty_internal_compile_') === 0) { + if (is_file($file)) { + require $file; + } + return; + } + @include $file; + return; + } + if (preg_match('/^(smarty_(((template_(source|config|cache|compiled|resource_base))|((cached|compiled)?resource)|(variable|security)))|(smarty(bc)?)$)/', + $_class, $match)) { + if (!empty($match[3])) { + @include $file; + return; + } elseif (!empty($match[9]) && isset(self::$rootClasses[$_class])) { + $file = self::$rootClasses[$_class]; + require $file; + return; + } + } + if (0 !== strpos($_class, 'smarty')) { + return; + } + if (is_file($file)) { + require $file; + return; + } + return; + } +} diff --git a/smarty/libs/Smarty.class.php b/smarty/libs/Smarty.class.php index 832b0d30..a029f942 100644 --- a/smarty/libs/Smarty.class.php +++ b/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.29 */ /** @@ -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,36 +73,41 @@ 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 dirname(__FILE__) . '/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_extension_handler.php'; +require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php'; +require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php'; +require_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php'; +require_once SMARTY_SYSPLUGINS_DIR . 'smarty_variable.php'; +require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_source.php'; +require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php'; /** * This is the main Smarty class * * @package Smarty + * + * @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(Smarty $smarty, string $extension = '.tpl', bool $force_compile = false, int $time_limit = 0, int $max_errors = null) + * @method int compileAllConfig(Smarty $smarty, string $extension = '.conf', bool $force_compile = false, int $time_limit = 0, int $max_errors = null) + * */ class Smarty extends Smarty_Internal_TemplateBase { @@ -110,23 +118,36 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = 'Smarty-3.1.21-dev'; + const SMARTY_VERSION = '3.1.29'; /** * define variable scopes */ const SCOPE_LOCAL = 0; - const SCOPE_PARENT = 1; - const SCOPE_ROOT = 2; - const SCOPE_GLOBAL = 3; + + const SCOPE_PARENT = 2; + + const SCOPE_TPL_ROOT = 4; + + const SCOPE_ROOT = 8; + + const SCOPE_SMARTY = 16; + + const SCOPE_GLOBAL = 32; + + const SCOPE_BUBBLE_UP = 64; + /** * 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 + * define constant for clearing cache files be saved expiration dates */ const CLEAR_EXPIRED = - 1; @@ -134,31 +155,66 @@ 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'; + /** + * Resource caching modes + */ + 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 + /**#@-*/ /** @@ -167,26 +223,31 @@ class Smarty extends Smarty_Internal_TemplateBase public static $global_tpl_vars = array(); /** - * error handler returned by set_error_hanlder() in Smarty::muteExpectedErrors() + * 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 */ @@ -202,163 +263,152 @@ class Smarty extends Smarty_Internal_TemplateBase */ /** - * auto literal on delimiters with whitspace + * 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 filepaths in include_path + * look up relative file path 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 = null; + /** * joined config directory string used in cache keys * * @var string */ - public $joined_config_dir = null; + 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 */ - 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,33 +420,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 - * Currently used by Smarty_Internal_Template only. - * }} - * - * @var boolean - */ - public $direct_access_security = true; + /**#@-*/ /** * debug mode @@ -405,6 +450,7 @@ class Smarty extends Smarty_Internal_TemplateBase * @var boolean */ public $debugging = false; + /** * This determines if debugging is enable-able from the browser. *