From eab8a101e7a3fcbb41e01a574985e06c5a3775de Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 18 Oct 2018 02:40:38 +0200 Subject: Updating Smarty --- lib/smarty3/Autoloader.php | 41 +- lib/smarty3/Smarty.class.php | 776 ++- lib/smarty3/SmartyBC.class.php | 68 +- lib/smarty3/bootstrap.php | 16 + lib/smarty3/debug.tpl | 6 +- lib/smarty3/plugins/block.textformat.php | 57 +- lib/smarty3/plugins/function.counter.php | 21 +- lib/smarty3/plugins/function.cycle.php | 53 +- lib/smarty3/plugins/function.fetch.php | 69 +- lib/smarty3/plugins/function.html_checkboxes.php | 213 +- lib/smarty3/plugins/function.html_image.php | 64 +- lib/smarty3/plugins/function.html_options.php | 142 +- lib/smarty3/plugins/function.html_radios.php | 186 +- lib/smarty3/plugins/function.html_select_date.php | 171 +- lib/smarty3/plugins/function.html_select_time.php | 168 +- lib/smarty3/plugins/function.html_table.php | 72 +- lib/smarty3/plugins/function.mailto.php | 62 +- lib/smarty3/plugins/function.math.php | 78 +- lib/smarty3/plugins/modifier.capitalize.php | 82 +- lib/smarty3/plugins/modifier.date_format.php | 46 +- lib/smarty3/plugins/modifier.debug_print_var.php | 51 +- lib/smarty3/plugins/modifier.escape.php | 145 +- lib/smarty3/plugins/modifier.mb_wordwrap.php | 71 + lib/smarty3/plugins/modifier.regex_replace.php | 15 +- lib/smarty3/plugins/modifier.replace.php | 15 +- lib/smarty3/plugins/modifier.spacify.php | 7 +- lib/smarty3/plugins/modifier.truncate.php | 24 +- lib/smarty3/plugins/modifiercompiler.cat.php | 15 +- .../plugins/modifiercompiler.count_characters.php | 10 +- .../plugins/modifiercompiler.count_paragraphs.php | 9 +- .../plugins/modifiercompiler.count_sentences.php | 7 +- .../plugins/modifiercompiler.count_words.php | 5 +- lib/smarty3/plugins/modifiercompiler.default.php | 7 +- lib/smarty3/plugins/modifiercompiler.escape.php | 53 +- .../plugins/modifiercompiler.from_charset.php | 7 +- lib/smarty3/plugins/modifiercompiler.indent.php | 7 +- lib/smarty3/plugins/modifiercompiler.lower.php | 6 +- lib/smarty3/plugins/modifiercompiler.noprint.php | 7 +- .../plugins/modifiercompiler.string_format.php | 5 +- lib/smarty3/plugins/modifiercompiler.strip.php | 11 +- .../plugins/modifiercompiler.strip_tags.php | 7 +- .../plugins/modifiercompiler.to_charset.php | 7 +- lib/smarty3/plugins/modifiercompiler.unescape.php | 12 +- lib/smarty3/plugins/modifiercompiler.upper.php | 5 +- lib/smarty3/plugins/modifiercompiler.wordwrap.php | 26 +- .../plugins/outputfilter.trimwhitespace.php | 48 +- .../plugins/shared.escape_special_chars.php | 8 +- .../plugins/shared.literal_compiler_param.php | 9 +- lib/smarty3/plugins/shared.make_timestamp.php | 28 +- lib/smarty3/plugins/shared.mb_str_replace.php | 12 +- lib/smarty3/plugins/shared.mb_unicode.php | 15 +- .../plugins/variablefilter.htmlspecialchars.php | 6 +- lib/smarty3/sysplugins/smarty_cacheresource.php | 19 +- .../sysplugins/smarty_cacheresource_custom.php | 128 +- .../smarty_cacheresource_keyvaluestore.php | 217 +- lib/smarty3/sysplugins/smarty_data.php | 8 +- lib/smarty3/sysplugins/smarty_internal_block.php | 6 +- .../smarty_internal_cacheresource_file.php | 51 +- .../sysplugins/smarty_internal_compile_append.php | 5 +- .../sysplugins/smarty_internal_compile_assign.php | 22 +- .../sysplugins/smarty_internal_compile_block.php | 146 +- .../smarty_internal_compile_block_child.php | 24 + .../smarty_internal_compile_block_parent.php | 31 + .../sysplugins/smarty_internal_compile_break.php | 70 +- .../sysplugins/smarty_internal_compile_call.php | 12 +- .../sysplugins/smarty_internal_compile_capture.php | 39 +- .../sysplugins/smarty_internal_compile_child.php | 79 + .../smarty_internal_compile_config_load.php | 16 +- .../smarty_internal_compile_continue.php | 60 +- .../sysplugins/smarty_internal_compile_debug.php | 6 +- .../sysplugins/smarty_internal_compile_eval.php | 12 +- .../sysplugins/smarty_internal_compile_extends.php | 64 +- .../sysplugins/smarty_internal_compile_for.php | 42 +- .../sysplugins/smarty_internal_compile_foreach.php | 89 +- .../smarty_internal_compile_function.php | 123 +- .../sysplugins/smarty_internal_compile_if.php | 91 +- .../sysplugins/smarty_internal_compile_include.php | 98 +- .../smarty_internal_compile_include_php.php | 19 +- .../sysplugins/smarty_internal_compile_insert.php | 33 +- .../sysplugins/smarty_internal_compile_ldelim.php | 5 +- .../smarty_internal_compile_make_nocache.php | 10 +- .../sysplugins/smarty_internal_compile_nocache.php | 6 +- .../sysplugins/smarty_internal_compile_parent.php | 31 + ...marty_internal_compile_private_block_plugin.php | 51 +- ...rty_internal_compile_private_foreachsection.php | 87 +- ...ty_internal_compile_private_function_plugin.php | 28 +- .../smarty_internal_compile_private_modifier.php | 69 +- ...ernal_compile_private_object_block_function.php | 6 +- ...ty_internal_compile_private_object_function.php | 27 +- .../smarty_internal_compile_private_php.php | 129 +- ...y_internal_compile_private_print_expression.php | 81 +- ...y_internal_compile_private_registered_block.php | 8 +- ...nternal_compile_private_registered_function.php | 45 +- ...y_internal_compile_private_special_variable.php | 36 +- .../sysplugins/smarty_internal_compile_rdelim.php | 12 +- .../sysplugins/smarty_internal_compile_section.php | 181 +- .../smarty_internal_compile_setfilter.php | 8 +- .../smarty_internal_compile_shared_inheritance.php | 29 +- .../sysplugins/smarty_internal_compile_while.php | 34 +- .../sysplugins/smarty_internal_compilebase.php | 47 +- .../smarty_internal_config_file_compiler.php | 54 +- .../sysplugins/smarty_internal_configfilelexer.php | 625 ++- .../smarty_internal_configfileparser.php | 1122 ++-- lib/smarty3/sysplugins/smarty_internal_data.php | 117 +- lib/smarty3/sysplugins/smarty_internal_debug.php | 73 +- .../sysplugins/smarty_internal_errorhandler.php | 113 + .../smarty_internal_extension_handler.php | 174 +- .../smarty_internal_method_addautoloadfilters.php | 27 +- .../smarty_internal_method_adddefaultmodifiers.php | 6 +- .../sysplugins/smarty_internal_method_append.php | 20 +- .../smarty_internal_method_appendbyref.php | 13 +- .../smarty_internal_method_assignbyref.php | 10 +- .../smarty_internal_method_assignglobal.php | 13 +- .../smarty_internal_method_clearallassign.php | 3 +- .../smarty_internal_method_clearallcache.php | 11 +- .../smarty_internal_method_clearassign.php | 5 +- .../smarty_internal_method_clearcache.php | 28 +- ...marty_internal_method_clearcompiledtemplate.php | 75 +- .../smarty_internal_method_clearconfig.php | 4 +- .../smarty_internal_method_compileallconfig.php | 23 +- .../smarty_internal_method_compilealltemplates.php | 69 +- .../smarty_internal_method_configload.php | 56 +- .../smarty_internal_method_createdata.php | 6 +- .../smarty_internal_method_getautoloadfilters.php | 10 +- .../smarty_internal_method_getconfigvariable.php | 34 + .../smarty_internal_method_getconfigvars.php | 6 +- .../smarty_internal_method_getdebugtemplate.php | 4 +- .../smarty_internal_method_getdefaultmodifiers.php | 4 +- .../smarty_internal_method_getglobal.php | 10 +- .../smarty_internal_method_getregisteredobject.php | 6 +- .../smarty_internal_method_getstreamvariable.php | 5 +- .../sysplugins/smarty_internal_method_gettags.php | 13 +- .../smarty_internal_method_gettemplatevars.php | 39 +- .../sysplugins/smarty_internal_method_literals.php | 100 + .../smarty_internal_method_loadfilter.php | 12 +- .../smarty_internal_method_loadplugin.php | 14 +- .../smarty_internal_method_mustcompile.php | 7 +- ...marty_internal_method_registercacheresource.php | 14 +- .../smarty_internal_method_registerclass.php | 8 +- ...nternal_method_registerdefaultconfighandler.php | 10 +- ...nternal_method_registerdefaultpluginhandler.php | 6 +- ...ernal_method_registerdefaulttemplatehandler.php | 30 +- .../smarty_internal_method_registerfilter.php | 17 +- .../smarty_internal_method_registerobject.php | 44 +- .../smarty_internal_method_registerplugin.php | 31 +- .../smarty_internal_method_registerresource.php | 16 +- .../smarty_internal_method_setautoloadfilters.php | 24 +- .../smarty_internal_method_setdebugtemplate.php | 6 +- .../smarty_internal_method_setdefaultmodifiers.php | 8 +- .../smarty_internal_method_unloadfilter.php | 13 +- ...rty_internal_method_unregistercacheresource.php | 8 +- .../smarty_internal_method_unregisterfilter.php | 9 +- .../smarty_internal_method_unregisterobject.php | 6 +- .../smarty_internal_method_unregisterplugin.php | 8 +- .../smarty_internal_method_unregisterresource.php | 6 +- .../sysplugins/smarty_internal_nocache_insert.php | 22 +- .../sysplugins/smarty_internal_parsetree.php | 8 +- .../sysplugins/smarty_internal_parsetree_code.php | 2 +- .../sysplugins/smarty_internal_parsetree_dq.php | 24 +- .../sysplugins/smarty_internal_parsetree_tag.php | 4 +- .../smarty_internal_parsetree_template.php | 33 +- .../sysplugins/smarty_internal_resource_eval.php | 17 +- .../smarty_internal_resource_extends.php | 12 +- .../sysplugins/smarty_internal_resource_file.php | 170 +- .../sysplugins/smarty_internal_resource_php.php | 81 +- .../smarty_internal_resource_registered.php | 28 +- .../sysplugins/smarty_internal_resource_stream.php | 8 +- .../sysplugins/smarty_internal_resource_string.php | 21 +- .../smarty_internal_runtime_cachemodify.php | 14 +- .../smarty_internal_runtime_cacheresourcefile.php | 139 + .../sysplugins/smarty_internal_runtime_capture.php | 39 +- .../smarty_internal_runtime_codeframe.php | 94 +- .../smarty_internal_runtime_filterhandler.php | 12 +- .../sysplugins/smarty_internal_runtime_foreach.php | 119 +- .../smarty_internal_runtime_getincludepath.php | 21 +- .../smarty_internal_runtime_inheritance.php | 81 +- .../smarty_internal_runtime_make_nocache.php | 14 +- .../smarty_internal_runtime_tplfunction.php | 86 +- .../smarty_internal_runtime_updatecache.php | 152 +- .../smarty_internal_runtime_updatescope.php | 36 +- .../smarty_internal_runtime_writefile.php | 29 +- .../smarty_internal_smartytemplatecompiler.php | 34 +- .../sysplugins/smarty_internal_template.php | 296 +- .../sysplugins/smarty_internal_templatebase.php | 164 +- .../smarty_internal_templatecompilerbase.php | 1357 +++-- .../sysplugins/smarty_internal_templatelexer.php | 1100 ++-- .../sysplugins/smarty_internal_templateparser.php | 5458 +++++++++++--------- .../sysplugins/smarty_internal_testinstall.php | 396 +- .../sysplugins/smarty_internal_undefined.php | 40 +- lib/smarty3/sysplugins/smarty_resource.php | 230 +- lib/smarty3/sysplugins/smarty_resource_custom.php | 12 +- .../sysplugins/smarty_resource_recompiled.php | 12 +- .../sysplugins/smarty_resource_uncompiled.php | 2 +- lib/smarty3/sysplugins/smarty_security.php | 293 +- lib/smarty3/sysplugins/smarty_template_cached.php | 25 +- .../sysplugins/smarty_template_compiled.php | 162 +- lib/smarty3/sysplugins/smarty_template_config.php | 19 +- .../sysplugins/smarty_template_resource_base.php | 16 +- lib/smarty3/sysplugins/smarty_template_source.php | 27 +- .../sysplugins/smarty_undefined_variable.php | 16 +- lib/smarty3/sysplugins/smarty_variable.php | 3 +- lib/smarty3/sysplugins/smartycompilerexception.php | 3 + lib/smarty3/sysplugins/smartyexception.php | 3 + 203 files changed, 10874 insertions(+), 8726 deletions(-) create mode 100644 lib/smarty3/bootstrap.php create mode 100644 lib/smarty3/plugins/modifier.mb_wordwrap.php create mode 100644 lib/smarty3/sysplugins/smarty_internal_compile_block_child.php create mode 100644 lib/smarty3/sysplugins/smarty_internal_compile_block_parent.php create mode 100644 lib/smarty3/sysplugins/smarty_internal_compile_child.php create mode 100644 lib/smarty3/sysplugins/smarty_internal_compile_parent.php create mode 100644 lib/smarty3/sysplugins/smarty_internal_errorhandler.php create mode 100644 lib/smarty3/sysplugins/smarty_internal_method_getconfigvariable.php create mode 100644 lib/smarty3/sysplugins/smarty_internal_method_literals.php create mode 100644 lib/smarty3/sysplugins/smarty_internal_runtime_cacheresourcefile.php (limited to 'lib') diff --git a/lib/smarty3/Autoloader.php b/lib/smarty3/Autoloader.php index e888553..e4dc450 100644 --- a/lib/smarty3/Autoloader.php +++ b/lib/smarty3/Autoloader.php @@ -2,20 +2,21 @@ /** * Smarty Autoloader * - * @package Smarty + * @package Smarty */ /** * Smarty Autoloader * - * @package Smarty - * @author Uwe Tews + * @package Smarty + * @author Uwe Tews * Usage: - * require_once '...path/Autoloader.php'; - * Smarty_Autoloader::register(); - * $smarty = new Smarty(); - * Note: This autoloader is not needed if you use Composer. - * Composer will automatically add the classes of the Smarty package to it common autoloader. + * require_once '...path/Autoloader.php'; + * Smarty_Autoloader::register(); + * or + * include '...path/bootstrap.php'; + * + * $smarty = new Smarty(); */ class Smarty_Autoloader { @@ -24,14 +25,14 @@ class Smarty_Autoloader * * @var string */ - public static $SMARTY_DIR = ''; + public static $SMARTY_DIR = null; /** * Filepath to Smarty internal plugins * * @var string */ - public static $SMARTY_SYSPLUGINS_DIR = ''; + public static $SMARTY_SYSPLUGINS_DIR = null; /** * Array with Smarty core classes and their filename @@ -53,8 +54,8 @@ class Smarty_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 + 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' ])) { @@ -75,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')); @@ -89,18 +90,20 @@ class Smarty_Autoloader */ public static function autoload($class) { - $_class = strtolower($class); - if (strpos($_class, 'smarty') !== 0) { + if ($class[ 0 ] !== 'S' && strpos($class, 'Smarty') !== 0) { return; } - $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; - if (is_file($file)) { - include $file; - } else if (isset(self::$rootClasses[ $_class ])) { + $_class = strtolower($class); + if (isset(self::$rootClasses[ $_class ])) { $file = self::$SMARTY_DIR . self::$rootClasses[ $_class ]; if (is_file($file)) { include $file; } + } else { + $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; + if (is_file($file)) { + include $file; + } } return; } diff --git a/lib/smarty3/Smarty.class.php b/lib/smarty3/Smarty.class.php index 8d18450..a896992 100644 --- a/lib/smarty3/Smarty.class.php +++ b/lib/smarty3/Smarty.class.php @@ -21,41 +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.30 + * @version 3.1.33 */ - -/** - * define shorthand directory separator constant - */ -if (!defined('DS')) { - define('DS', DIRECTORY_SEPARATOR); -} - /** * 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__) . DS); + /** + * + */ + 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' . DS); + /** + * + */ + define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR); } if (!defined('SMARTY_PLUGINS_DIR')) { - define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS); + /** + * + */ + 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')) { @@ -71,25 +74,16 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { */ define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y'); } - /** - * 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 + * Load Smarty_Autoloader */ -if (!class_exists('Smarty_Autoloader', false)) { - if (!class_exists('Smarty_Internal_Data', true)) { - require_once dirname(__FILE__) . '/Autoloader.php'; - Smarty_Autoloader::registerBC(); - } +if (!class_exists('Smarty_Autoloader')) { + include dirname(__FILE__) . '/bootstrap.php'; } - /** * Load always needed external class files */ -if (!class_exists('Smarty_Internal_Data', false)) { - require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php'; -} +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'; @@ -97,6 +91,7 @@ require_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_variable.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_source.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php'; +require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php'; /** * This is the main Smarty class @@ -108,132 +103,75 @@ require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.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.30'; - + const SMARTY_VERSION = '3.1.33'; /** * 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 */ @@ -260,10 +198,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public static $_IS_WINDOWS = false; - /**#@+ - * variables - */ - /** * auto literal on delimiters with whitespace * @@ -285,20 +219,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ 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 * @@ -313,20 +233,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ 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 * @@ -362,13 +268,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $default_plugin_handler_func = null; - /** - * compile directory - * - * @var string - */ - protected $compile_dir = './templates_c/'; - /** * flag if template_dir is normalized * @@ -376,13 +275,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $_compileDirNormalized = false; - /** - * plugins directory - * - * @var array - */ - protected $plugins_dir = array(); - /** * flag if plugins_dir is normalized * @@ -390,13 +282,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $_pluginsDirNormalized = false; - /** - * cache directory - * - * @var string - */ - protected $cache_dir = './cache/'; - /** * flag if template_dir is normalized * @@ -411,13 +296,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $force_compile = false; - /** - * check template for modifications? - * - * @var boolean - */ - public $compile_check = true; - /** * use sub dirs for compiled/cached files? * @@ -439,6 +317,15 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $merge_compiled_includes = false; + /* + * flag for behaviour when extends: resource and {extends} tag are used simultaneous + * if false disable execution of {extends} in templates called by extends resource. + * (behaviour as versions < 3.1.28) + * + * @var boolean + */ + public $extends_recursion = true; + /** * force cache file creation * @@ -460,9 +347,13 @@ class Smarty extends Smarty_Internal_TemplateBase */ 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. @@ -493,7 +384,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $allow_php_templates = false; - /**#@-*/ /** * debug mode * Setting this to true enables the debug-console. @@ -536,10 +426,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $error_reporting = null; - /**#@+ - * config var settings - */ - /** * Controls whether variables with the same name overwrite each other. * @@ -561,12 +447,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $config_read_hidden = false; - /**#@-*/ - - /**#@+ - * resource locking - */ - /** * locking concurrent compiles * @@ -588,8 +468,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $locking_timeout = 10; - /**#@-*/ - /** * resource type used if none given * Must be an valid key of $registered_resources. @@ -718,41 +596,91 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $_debug = null; + /** + * template directory + * + * @var array + */ + protected $template_dir = array('./templates/'); + + /** + * flags for normalized template directory entries + * + * @var array + */ + protected $_processedTemplateDir = array(); + + /** + * config directory + * + * @var array + */ + protected $config_dir = array('./configs/'); + + /** + * flags for normalized template directory entries + * + * @var array + */ + protected $_processedConfigDir = array(); + + /** + * compile directory + * + * @var string + */ + protected $compile_dir = './templates_c/'; + + /** + * plugins directory + * + * @var array + */ + protected $plugins_dir = array(); + + /** + * cache directory + * + * @var string + */ + protected $cache_dir = './cache/'; + /** * removed properties * * @var string[] */ - 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 */ public function __construct() { + $this->_clearTemplateCache(); parent::__construct(); if (is_callable('mb_internal_encoding')) { mb_internal_encoding(Smarty::$_CHARSET); } $this->start_time = microtime(true); - if (isset($_SERVER[ 'SCRIPT_NAME' ])) { Smarty::$global_tpl_vars[ 'SCRIPT_NAME' ] = new Smarty_Variable($_SERVER[ 'SCRIPT_NAME' ]); } - // Check if we're running on windows Smarty::$_IS_WINDOWS = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; // let PCRE (preg_*) treat strings as ISO-8859-1 if we're not dealing with UTF-8 @@ -761,12 +689,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 + * @param string $resource_name template name * - * @return boolean status + * @return bool status + * @throws \SmartyException */ public function templateExists($resource_name) { @@ -778,10 +728,10 @@ class Smarty extends Smarty_Internal_TemplateBase /** * Loads security class and enables security * - * @param string|Smarty_Security $security_class if a string is used, it must be class-name + * @param string|Smarty_Security $security_class if a string is used, it must be class-name * * @return Smarty current Smarty instance for chaining - * @throws SmartyException when an invalid class name is provided + * @throws \SmartyException */ public function enableSecurity($security_class = null) { @@ -797,37 +747,15 @@ 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; } /** * Add template directory(s) * - * @param string|array $template_dir directory(s) of template sources - * @param string $key of the array element to assign the template dir to - * @param bool $isConfig true for config_dir + * @param string|array $template_dir directory(s) of template sources + * @param string $key of the array element to assign the template dir to + * @param bool $isConfig true for config_dir * * @return Smarty current Smarty instance for chaining */ @@ -882,7 +810,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; @@ -891,15 +819,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; } /** @@ -928,23 +865,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 */ @@ -953,7 +888,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; } @@ -971,10 +906,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, "/\\") . DS, true); + $this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, '/\\') . DIRECTORY_SEPARATOR, true); } $this->_cache[ 'plugin_files' ] = array(); $this->_pluginsDirNormalized = true; @@ -983,15 +918,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; } @@ -1010,16 +946,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; } @@ -1038,58 +973,30 @@ 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, "/\\") . 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, "/\\") . 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; } /** * creates a template object * - * @param string $template the resource handle of the template file - * @param mixed $cache_id cache id to be used with this template - * @param mixed $compile_id compile id to be used with this template - * @param object $parent next higher level of Smarty variables - * @param boolean $do_clone flag is Smarty object shall be cloned + * @param string $template the resource handle of the template file + * @param mixed $cache_id cache id to be used with this template + * @param mixed $compile_id compile id to be used with this template + * @param object $parent next higher level of Smarty variables + * @param boolean $do_clone flag is Smarty object shall be cloned * - * @return 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) { @@ -1103,14 +1010,20 @@ class Smarty extends Smarty_Internal_TemplateBase } else { $data = null; } + if (!$this->_templateDirNormalized) { + $this->_normalizeTemplateConfig(false); + } $_templateId = $this->_getTemplateId($template, $cache_id, $compile_id); $tpl = null; - if ($this->caching && isset($this->_cache[ 'isCached' ][ $_templateId ])) { - $tpl = $do_clone ? clone $this->_cache[ 'isCached' ][ $_templateId ] : - $this->_cache[ 'isCached' ][ $_templateId ]; + if ($this->caching && isset(Smarty_Internal_Template::$isCacheTplObj[ $_templateId ])) { + $tpl = $do_clone ? clone Smarty_Internal_Template::$isCacheTplObj[ $_templateId ] : + Smarty_Internal_Template::$isCacheTplObj[ $_templateId ]; + $tpl->inheritance = null; + $tpl->tpl_vars = $tpl->config_vars = array(); + } elseif (!$do_clone && isset(Smarty_Internal_Template::$tplObjCache[ $_templateId ])) { + $tpl = clone Smarty_Internal_Template::$tplObjCache[ $_templateId ]; + $tpl->inheritance = null; $tpl->tpl_vars = $tpl->config_vars = array(); - } else if (!$do_clone && isset($this->_cache[ 'tplObjects' ][ $_templateId ])) { - $tpl = clone $this->_cache[ 'tplObjects' ][ $_templateId ]; } else { /* @var Smarty_Internal_Template $tpl */ $tpl = new $this->template_class($template, $this, null, $cache_id, $compile_id, null, null); @@ -1127,10 +1040,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); } } @@ -1142,11 +1055,11 @@ class Smarty extends Smarty_Internal_TemplateBase * class name format: Smarty_PluginType_PluginName * plugin filename format: plugintype.pluginname.php * - * @param string $plugin_name class plugin name to load - * @param bool $check check if already loaded + * @param string $plugin_name class plugin name to load + * @param bool $check check if already loaded * - * @throws SmartyException * @return string |boolean filepath of loaded file or false + * @throws \SmartyException */ public function loadPlugin($plugin_name, $check = true) { @@ -1163,16 +1076,20 @@ class Smarty extends Smarty_Internal_TemplateBase * @param \Smarty_Internal_Template $template * * @return string - */ - public function _getTemplateId($template_name, $cache_id = null, $compile_id = null, $caching = null, - Smarty_Internal_Template $template = null) - { + * @throws \SmartyException + */ + public function _getTemplateId( + $template_name, + $cache_id = null, + $compile_id = null, + $caching = null, + Smarty_Internal_Template $template = null + ) { $template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" : $template_name; $cache_id = $cache_id === null ? $this->cache_id : $cache_id; $compile_id = $compile_id === null ? $this->compile_id : $compile_id; - $caching = (int) ($caching === null ? $this->caching : $caching); - + $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) . @@ -1191,47 +1108,43 @@ class Smarty extends Smarty_Internal_TemplateBase * - remove /./ and /../ * - make it absolute if required * - * @param string $path file path - * @param bool $realpath if true - convert to absolute - * false - convert to relative - * null - keep as it is but remove /./ /../ + * @param string $path file path + * @param bool $realpath if true - convert to absolute + * false - convert to relative + * null - keep as it is but + * remove /./ /../ * * @return string */ public function _realpath($path, $realpath = null) { - $nds = DS == '/' ? '\\' : '/'; - // normalize DS - $path = str_replace($nds, DS, $path); - preg_match('%^(?(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?(?:[[:print:]]*))$%', - $path, $parts); + $nds = array('/' => '\\', '\\' => '/'); + 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() . DS . $path; + $path = getcwd() . DIRECTORY_SEPARATOR . $path; } } - // remove noop 'DS DS' and 'DS.DS' patterns - $path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#', DS, $path); - // resolve '..DS' pattern, smallest first - if (strpos($path, '..' . DS) != false && - preg_match_all('#(([.]?[\\\\/])*([.][.])[\\\\/]([.]?[\\\\/])*)+#', $path, $match) - ) { - $counts = array(); - foreach ($match[ 0 ] as $m) { - $counts[] = (int) ((strlen($m) - 1) / 3); - } - sort($counts); - foreach ($counts as $count) { - $path = preg_replace('#(([\\\\/]([.]?[\\\\/])*[^\\\\/.]+){' . $count . - '}[\\\\/]([.]?[\\\\/])*([.][.][\\\\/]([.]?[\\\\/])*){' . $count . '})(?=[^.])#', - DS, $path); - } - } - - return $parts[ 'root' ] . $path; + // normalize DIRECTORY_SEPARATOR + $path = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $path); + $parts[ 'root' ] = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $parts[ 'root' ]); + do { + $path = preg_replace( + array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'), + DIRECTORY_SEPARATOR, + $path, + -1, + $count + ); + } while ($count > 0); + return $realpath !== false ? $parts[ 'root' ] . $path : str_ireplace(getcwd(), '.', $parts[ 'root' ] . $path); } /** @@ -1239,16 +1152,8 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function _clearTemplateCache() { - $this->_cache[ 'isCached' ] = array(); - $this->_cache[ 'tplObjects' ] = array(); - } - - /** - * @param boolean $compile_check - */ - public function setCompileCheck($compile_check) - { - $this->compile_check = $compile_check; + Smarty_Internal_Template::$isCacheTplObj = array(); + Smarty_Internal_Template::$tplObjCache = array(); } /** @@ -1276,9 +1181,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; } @@ -1300,6 +1217,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) @@ -1308,7 +1237,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) { @@ -1381,12 +1322,22 @@ 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. * Issues an E_USER_NOTICE if no valid getter is found. * - * @param string $name property name + * @param string $name property name * * @return mixed */ @@ -1412,6 +1363,7 @@ class Smarty extends Smarty_Internal_TemplateBase * * @param string $name property name * @param mixed $value parameter passed to setter + * */ public function __set($name, $value) { @@ -1420,110 +1372,54 @@ class Smarty extends Smarty_Internal_TemplateBase $this->{$method}($value); } elseif (in_array($name, $this->obsoleteProperties)) { return; + } elseif (is_object($value) && method_exists($value, $name)) { + $this->$name = $value; } else { - if (is_object($value) && method_exists($value, $name)) { - $this->$name = $value; - } else { - trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); - } + trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); } } /** - * 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 + * @param bool $isConfig true for config_dir */ - public static function muteExpectedErrors() + private function _normalizeTemplateConfig($isConfig) { - /* - 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; + if ($isConfig) { + $processed = &$this->_processedConfigDir; + $dir = &$this->config_dir; + } else { + $processed = &$this->_processedTemplateDir; + $dir = &$this->template_dir; } - } - - /** - * Disable error handler muting expected messages - * - * @return void - */ - public static function unmuteExpectedErrors() - { - restore_error_handler(); + 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/lib/smarty3/SmartyBC.class.php b/lib/smarty3/SmartyBC.class.php index 3955e4f..836f981 100644 --- a/lib/smarty3/SmartyBC.class.php +++ b/lib/smarty3/SmartyBC.class.php @@ -28,7 +28,7 @@ /** * @ignore */ -require_once(dirname(__FILE__) . '/Smarty.class.php'); +require_once dirname(__FILE__) . '/Smarty.class.php'; /** * Smarty Backward Compatibility Wrapper Class @@ -53,7 +53,6 @@ class SmartyBC extends Smarty /** * Initialize new SmartyBC object - * */ public function __construct() { @@ -100,6 +99,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) { @@ -125,12 +126,16 @@ class SmartyBC extends Smarty * @param boolean $smarty_args smarty argument format, else traditional * @param array $block_methods list of methods that are block format * - * @throws SmartyException + * @throws SmartyException * @internal param array $block_functs list of methods that are block format */ - public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, - $block_methods = array()) - { + public function register_object( + $object, + $object_impl, + $allowed = array(), + $smarty_args = true, + $block_methods = array() + ) { settype($allowed, 'array'); settype($smarty_args, 'boolean'); $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods); @@ -153,6 +158,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 +182,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 +205,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 +249,8 @@ class SmartyBC extends Smarty * to a template before compiling * * @param callable $function + * + * @throws \SmartyException */ public function register_prefilter($function) { @@ -259,6 +272,8 @@ class SmartyBC extends Smarty * to a compiled template after compilation * * @param callable $function + * + * @throws \SmartyException */ public function register_postfilter($function) { @@ -280,6 +295,8 @@ class SmartyBC extends Smarty * to a template output * * @param callable $function + * + * @throws \SmartyException */ public function register_outputfilter($function) { @@ -301,6 +318,8 @@ class SmartyBC extends Smarty * * @param string $type filter type * @param string $name filter name + * + * @throws \SmartyException */ public function load_filter($type, $name) { @@ -310,10 +329,10 @@ class SmartyBC extends Smarty /** * clear cached content for the given template and cache id * - * @param string $tpl_file name of template file - * @param string $cache_id name of cache_id - * @param string $compile_id name of compile_id - * @param string $exp_time expiration time + * @param string $tpl_file name of template file + * @param string $cache_id name of cache_id + * @param string $compile_id name of compile_id + * @param string $exp_time expiration time * * @return boolean */ @@ -325,7 +344,7 @@ class SmartyBC extends Smarty /** * clear the entire contents of cache (all templates) * - * @param string $exp_time expire time + * @param string $exp_time expire time * * @return boolean */ @@ -337,11 +356,13 @@ class SmartyBC extends Smarty /** * test to see if valid cache exists for this template * - * @param string $tpl_file name of template file - * @param string $cache_id - * @param string $compile_id + * @param string $tpl_file name of template file + * @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) { @@ -361,9 +382,9 @@ class SmartyBC extends Smarty * or all compiled template files if one is not specified. * This function is for advanced use only, not normally needed. * - * @param string $tpl_file - * @param string $compile_id - * @param string $exp_time + * @param string $tpl_file + * @param string $compile_id + * @param string $exp_time * * @return boolean results of {@link smarty_core_rm_auto()} */ @@ -375,9 +396,10 @@ class SmartyBC extends Smarty /** * Checks whether requested template exists. * - * @param string $tpl_file + * @param string $tpl_file * - * @return boolean + * @return bool + * @throws \SmartyException */ public function template_exists($tpl_file) { @@ -387,7 +409,7 @@ class SmartyBC extends Smarty /** * Returns an array containing template variables * - * @param string $name + * @param string $name * * @return array */ @@ -399,7 +421,7 @@ class SmartyBC extends Smarty /** * Returns an array containing config variables * - * @param string $name + * @param string $name * * @return array */ @@ -423,7 +445,7 @@ class SmartyBC extends Smarty /** * return a reference to a registered object * - * @param string $name + * @param string $name * * @return object */ diff --git a/lib/smarty3/bootstrap.php b/lib/smarty3/bootstrap.php new file mode 100644 index 0000000..2c83046 --- /dev/null +++ b/lib/smarty3/bootstrap.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Load and register Smarty Autoloader + */ +if (!class_exists('Smarty_Autoloader')) { + include dirname(__FILE__) . '/Autoloader.php'; +} +Smarty_Autoloader::register(true); diff --git a/lib/smarty3/debug.tpl b/lib/smarty3/debug.tpl index 5526cbc..edc7bef 100644 --- a/lib/smarty3/debug.tpl +++ b/lib/smarty3/debug.tpl @@ -113,10 +113,10 @@
{foreach $template_data as $template} {$template.name} -
   +
   (compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"}) -
+
{/foreach}
{/if} @@ -127,7 +127,7 @@ {foreach $assigned_vars as $vars}

${$vars@key}

- {if isset($vars['nocache'])}Nocache
{/if} + {if isset($vars['nocache'])}Nocache
{/if} {if isset($vars['scope'])}Origin: {$vars['scope']|debug_print_var nofilter}{/if}

Value

{$vars['value']|debug_print_var:10:80 nofilter} diff --git a/lib/smarty3/plugins/block.textformat.php b/lib/smarty3/plugins/block.textformat.php index e9f5fe2..5e49463 100644 --- a/lib/smarty3/plugins/block.textformat.php +++ b/lib/smarty3/plugins/block.textformat.php @@ -5,22 +5,20 @@ * @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,13 +30,23 @@ * * @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) { + $template->_checkPlugins( + array( + array( + 'function' => 'smarty_modifier_mb_wordwrap', + 'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php' + ) + ) + ); + } $style = null; $indent = 0; $indent_first = 0; @@ -47,53 +55,55 @@ function smarty_block_textformat($params, $content, $template, &$repeat) $wrap_char = "\n"; $wrap_cut = false; $assign = null; - foreach ($params as $_key => $_val) { switch ($_key) { case 'style': case 'indent_char': case 'wrap_char': case 'assign': - $$_key = (string) $_val; + $$_key = (string)$_val; break; - case 'indent': case 'indent_first': case 'wrap': - $$_key = (int) $_val; + $$_key = (int)$_val; break; - case 'wrap_cut': - $$_key = (bool) $_val; + $$_key = (bool)$_val; 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 $_paragraphs = preg_split('![\r\n]{2}!', $content); - foreach ($_paragraphs as &$_paragraph) { if (!$_paragraph) { continue; } // convert mult. spaces & special chars to single space $_paragraph = - preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), - array(' ', ''), $_paragraph); + 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) { - require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'); - $_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); } @@ -103,7 +113,6 @@ function smarty_block_textformat($params, $content, $template, &$repeat) } } $_output = implode($wrap_char . $wrap_char, $_paragraphs); - if ($assign) { $template->assign($assign, $_output); } else { diff --git a/lib/smarty3/plugins/function.counter.php b/lib/smarty3/plugins/function.counter.php index bcc8f49..a4129e7 100644 --- a/lib/smarty3/plugins/function.counter.php +++ b/lib/smarty3/plugins/function.counter.php @@ -5,11 +5,10 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {counter} function plugin - * Type: function
- * Name: counter
+ * Type: function + * Name: counter * Purpose: print out a counter value * * @author Monte Ohrt @@ -24,50 +23,40 @@ function smarty_function_counter($params, $template) { static $counters = array(); - $name = (isset($params[ 'name' ])) ? $params[ 'name' ] : 'default'; if (!isset($counters[ $name ])) { $counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1); } $counter =& $counters[ $name ]; - if (isset($params[ 'start' ])) { - $counter[ 'start' ] = $counter[ 'count' ] = (int) $params[ 'start' ]; + $counter[ 'start' ] = $counter[ 'count' ] = (int)$params[ 'start' ]; } - if (!empty($params[ 'assign' ])) { $counter[ 'assign' ] = $params[ 'assign' ]; } - if (isset($counter[ 'assign' ])) { $template->assign($counter[ 'assign' ], $counter[ 'count' ]); } - if (isset($params[ 'print' ])) { - $print = (bool) $params[ 'print' ]; + $print = (bool)$params[ 'print' ]; } else { $print = empty($counter[ 'assign' ]); } - if ($print) { $retval = $counter[ 'count' ]; } else { $retval = null; } - if (isset($params[ 'skip' ])) { $counter[ 'skip' ] = $params[ 'skip' ]; } - if (isset($params[ 'direction' ])) { $counter[ 'direction' ] = $params[ 'direction' ]; } - - if ($counter[ 'direction' ] == "down") { + if ($counter[ 'direction' ] === 'down') { $counter[ 'count' ] -= $counter[ 'skip' ]; } else { $counter[ 'count' ] += $counter[ 'skip' ]; } - return $retval; } diff --git a/lib/smarty3/plugins/function.cycle.php b/lib/smarty3/plugins/function.cycle.php index a76d49a..07ffcc5 100644 --- a/lib/smarty3/plugins/function.cycle.php +++ b/lib/smarty3/plugins/function.cycle.php @@ -5,15 +5,14 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * 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,84 +21,72 @@
  * - 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} + * @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle} * (Smarty online manual) - * @author Monte Ohrt - * @author credit to Mark Priatel - * @author credit to Gerard - * @author credit to Jason Sweat - * @version 1.3 + * @author Monte Ohrt + * @author credit to Mark Priatel + * @author credit to Gerard + * @author credit to Jason Sweat + * @version 1.3 * * @param array $params parameters * @param Smarty_Internal_Template $template template object * * @return string|null */ - function smarty_function_cycle($params, $template) { static $cycle_vars; - $name = (empty($params[ 'name' ])) ? 'default' : $params[ 'name' ]; - $print = (isset($params[ 'print' ])) ? (bool) $params[ 'print' ] : true; - $advance = (isset($params[ 'advance' ])) ? (bool) $params[ 'advance' ] : true; - $reset = (isset($params[ 'reset' ])) ? (bool) $params[ 'reset' ] : false; - + $print = (isset($params[ 'print' ])) ? (bool)$params[ 'print' ] : true; + $advance = (isset($params[ 'advance' ])) ? (bool)$params[ 'advance' ] : true; + $reset = (isset($params[ 'reset' ])) ? (bool)$params[ 'reset' ] : false; if (!isset($params[ 'values' ])) { if (!isset($cycle_vars[ $name ][ 'values' ])) { - trigger_error("cycle: missing 'values' parameter"); - + 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' ]; } - if (isset($params[ 'delimiter' ])) { $cycle_vars[ $name ][ 'delimiter' ] = $params[ 'delimiter' ]; } elseif (!isset($cycle_vars[ $name ][ 'delimiter' ])) { $cycle_vars[ $name ][ 'delimiter' ] = ','; } - if (is_array($cycle_vars[ $name ][ 'values' ])) { $cycle_array = $cycle_vars[ $name ][ 'values' ]; } else { $cycle_array = explode($cycle_vars[ $name ][ 'delimiter' ], $cycle_vars[ $name ][ 'values' ]); } - if (!isset($cycle_vars[ $name ][ 'index' ]) || $reset) { $cycle_vars[ $name ][ 'index' ] = 0; } - if (isset($params[ 'assign' ])) { $print = false; $template->assign($params[ 'assign' ], $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]); } - if ($print) { $retval = $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]; } else { $retval = null; } - if ($advance) { if ($cycle_vars[ $name ][ 'index' ] >= count($cycle_array) - 1) { $cycle_vars[ $name ][ 'index' ] = 0; } else { - $cycle_vars[ $name ][ 'index' ] ++; + $cycle_vars[ $name ][ 'index' ]++; } } - return $retval; } diff --git a/lib/smarty3/plugins/function.fetch.php b/lib/smarty3/plugins/function.fetch.php index cb60dd9..768761b 100644 --- a/lib/smarty3/plugins/function.fetch.php +++ b/lib/smarty3/plugins/function.fetch.php @@ -5,11 +5,10 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * 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,21 +24,17 @@ 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; } - // strip file protocol if (stripos($params[ 'file' ], 'file://') === 0) { $params[ 'file' ] = substr($params[ 'file' ], 7); } - $protocol = strpos($params[ 'file' ], '://'); if ($protocol !== false) { $protocol = strtolower(substr($params[ 'file' ], 0, $protocol)); } - if (isset($template->smarty->security_policy)) { if ($protocol) { // remote resource (or php stream, …) @@ -53,17 +48,16 @@ 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,72 +75,68 @@ 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 { $extra_headers[] = $param_value; } } 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; + $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; + $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; } } @@ -156,10 +146,8 @@ function smarty_function_fetch($params, $template) } else { $fp = fsockopen($server_name, $port, $errno, $errstr, $timeout); } - if (!$fp) { trigger_error("[plugin] unable to fetch: $errstr ($errno)", E_USER_NOTICE); - return; } else { if ($_is_proxy) { @@ -185,25 +173,21 @@ 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"); while (!feof($fp)) { $content .= fgets($fp, 4096); } fclose($fp); $csplit = preg_split("!\r\n\r\n!", $content, 2); - $content = $csplit[ 1 ]; - if (!empty($params[ 'assign_headers' ])) { $template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ])); } } } else { trigger_error("[plugin fetch] unable to parse URL, check syntax", E_USER_NOTICE); - return; } } else { @@ -212,7 +196,6 @@ function smarty_function_fetch($params, $template) throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'"); } } - if (!empty($params[ 'assign' ])) { $template->assign($params[ 'assign' ], $content); } else { diff --git a/lib/smarty3/plugins/function.html_checkboxes.php b/lib/smarty3/plugins/function.html_checkboxes.php index 33f2efe..302358e 100644 --- a/lib/smarty3/plugins/function.html_checkboxes.php +++ b/lib/smarty3/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,24 +28,30 @@
  * - 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} + * @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} * (Smarty online manual) - * @author Christopher Kvarme - * @author credits to Monte Ohrt - * @version 1.0 + * @author Christopher Kvarme + * @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() + * @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) { - 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; $options = null; @@ -56,120 +61,132 @@ function smarty_function_html_checkboxes($params, $template) $labels = true; $label_ids = false; $output = null; - $extra = ''; - foreach ($params as $_key => $_val) { switch ($_key) { case 'name': case 'separator': - $$_key = (string) $_val; + $$_key = (string)$_val; break; - case 'escape': case 'labels': case 'label_ids': - $$_key = (bool) $_val; + $$_key = (bool)$_val; break; - case 'options': - $$_key = (array) $_val; + $$_key = (array)$_val; break; - case 'values': case 'output': - $$_key = array_values((array) $_val); + $$_key = array_values((array)$_val); break; - case 'checked': case 'selected': if (is_array($_val)) { $selected = array(); foreach ($_val as $_sel) { if (is_object($_sel)) { - if (method_exists($_sel, "__toString")) { - $_sel = smarty_function_escape_special_chars((string) $_sel->__toString()); + 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 { - $_sel = smarty_function_escape_special_chars((string) $_sel); + $_sel = smarty_function_escape_special_chars((string)$_sel); } $selected[ $_sel ] = true; } } elseif (is_object($_val)) { - if (method_exists($_val, "__toString")) { - $selected = smarty_function_escape_special_chars((string) $_val->__toString()); + 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); + $selected = smarty_function_escape_special_chars((string)$_val); } break; - case 'checkboxes': - trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', - E_USER_WARNING); - $options = (array) $_val; + trigger_error( + 'html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', + E_USER_WARNING + ); + $options = (array)$_val; break; - case 'assign': break; - case 'strict': break; - case 'disabled': case 'readonly': if (!empty($params[ 'strict' ])) { if (!is_scalar($_val)) { - trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", - E_USER_NOTICE); + trigger_error( + "html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute", + E_USER_NOTICE + ); } - if ($_val === true || $_val === $_key) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; } - break; } // omit break; to fall through! - + // no break default: if (!is_array($_val)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; } else { - trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + trigger_error("html_checkboxes: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); } break; } } - if (!isset($options) && !isset($values)) { return ''; } /* raise error here? */ - $_html_result = array(); - if (isset($options)) { foreach ($options as $_key => $_val) { $_html_result[] = - smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, - $label_ids, $escape); + smarty_function_html_checkboxes_output( + $name, + $_key, + $_val, + $selected, + $extra, + $separator, + $labels, + $label_ids, + $escape + ); } } else { foreach ($values as $_i => $_key) { $_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; $_html_result[] = - smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, - $label_ids, $escape); + smarty_function_html_checkboxes_output( + $name, + $_key, + $_val, + $selected, + $extra, + $separator, + $labels, + $label_ids, + $escape + ); } } - if (!empty($params[ 'assign' ])) { $template->assign($params[ 'assign' ], $_html_result); } else { @@ -177,59 +194,82 @@ function smarty_function_html_checkboxes($params, $template) } } -function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, - $label_ids, $escape = true) -{ +/** + * @param $name + * @param $value + * @param $output + * @param $selected + * @param $extra + * @param $separator + * @param $labels + * @param $label_ids + * @param bool $escape + * + * @return string + */ +function smarty_function_html_checkboxes_output( + $name, + $value, + $output, + $selected, + $extra, + $separator, + $labels, + $label_ids, + $escape = true +) { $_output = ''; - if (is_object($value)) { - if (method_exists($value, "__toString")) { - $value = (string) $value->__toString(); + 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 ''; } } else { - $value = (string) $value; + $value = (string)$value; } - if (is_object($output)) { - if (method_exists($output, "__toString")) { - $output = (string) $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 ''; } } else { - $output = (string) $output; + $output = (string)$output; } - if ($labels) { if ($label_ids) { - $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', - $name . '_' . $value)); + $_id = smarty_function_escape_special_chars( + preg_replace( + '![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, + '_', + $name . '_' . $value + ) + ); $_output .= '