diff --git a/smarty/libs/Autoloader.php b/smarty/libs/Autoloader.php index 7d0c388a..d3b039ca 100644 --- a/smarty/libs/Autoloader.php +++ b/smarty/libs/Autoloader.php @@ -11,11 +11,12 @@ * @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/bootstarp.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 @@ -57,7 +58,7 @@ class Smarty_Autoloader set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false ) { $registeredAutoLoadFunctions = spl_autoload_functions(); - if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { + if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) { spl_autoload_register(); } } else { @@ -89,35 +90,20 @@ class Smarty_Autoloader */ 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; + if ($class[ 0 ] !== 'S' && strpos($class, 'Smarty') !== 0) { 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; + $_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; } - } - 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 a029f942..57eedfb9 100644 --- a/smarty/libs/Smarty.class.php +++ b/smarty/libs/Smarty.class.php @@ -21,28 +21,21 @@ * smarty-discussion-subscribe@googlegroups.com * * @link http://www.smarty.net/ - * @copyright 2015 New Digital Group, Inc. - * @copyright 2015 Uwe Tews + * @copyright 2016 New Digital Group, Inc. + * @copyright 2016 Uwe Tews * @author Monte Ohrt * @author Uwe Tews * @author Rodney Rehm * @package Smarty - * @version 3.1.29 + * @version 3.1.31 */ -/** - * 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); } /** @@ -50,10 +43,10 @@ if (!defined('SMARTY_DIR')) { * 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')); @@ -73,23 +66,16 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { } /** - * 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 __DIR__ . '/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,17 +83,21 @@ 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 * * @package Smarty * + * The following methods will be dynamically loaded by the extension handler when they are called. + * They are located in a corresponding Smarty_Internal_Method_xxxx class + * * @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) - * + * @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 clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null) */ class Smarty extends Smarty_Internal_TemplateBase { @@ -118,12 +108,12 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.29'; + const SMARTY_VERSION = '3.1.31'; /** * define variable scopes */ - const SCOPE_LOCAL = 0; + const SCOPE_LOCAL = 1; const SCOPE_PARENT = 2; @@ -135,8 +125,6 @@ class Smarty extends Smarty_Internal_TemplateBase const SCOPE_GLOBAL = 32; - const SCOPE_BUBBLE_UP = 64; - /** * define caching modes */ @@ -206,6 +194,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * Resource caching modes + * (not used since 3.1.30) */ const RESOURCE_CACHE_OFF = 0; @@ -288,7 +277,21 @@ class Smarty extends Smarty_Internal_TemplateBase * * @var array */ - private $template_dir = array('./templates/'); + protected $template_dir = array('./templates/'); + + /** + * flags for normalized template directory entries + * + * @var array + */ + protected $_processedTemplateDir = array(); + + /** + * flag if template_dir is normalized + * + * @var bool + */ + public $_templateDirNormalized = false; /** * joined template directory string used in cache keys @@ -297,6 +300,27 @@ 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 + * + * @var bool + */ + public $_configDirNormalized = false; + /** * joined config directory string used in cache keys * @@ -330,28 +354,42 @@ class Smarty extends Smarty_Internal_TemplateBase * * @var string */ - private $compile_dir = './templates_c/'; + protected $compile_dir = './templates_c/'; + + /** + * flag if template_dir is normalized + * + * @var bool + */ + public $_compileDirNormalized = false; /** * plugins directory * * @var array */ - private $plugins_dir = null; + protected $plugins_dir = array(); + + /** + * flag if plugins_dir is normalized + * + * @var bool + */ + public $_pluginsDirNormalized = false; /** * cache directory * * @var string */ - private $cache_dir = './cache/'; + protected $cache_dir = './cache/'; /** - * config directory + * flag if template_dir is normalized * - * @var array + * @var bool */ - private $config_dir = array('./configs/'); + public $_cacheDirNormalized = false; /** * force template compiling? @@ -388,6 +426,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 * @@ -562,13 +609,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $default_config_type = 'file'; - /** - * enable resource caching - * - * @var bool - */ - public $resource_cache_mode = 1; - /** * check If-Modified-Since headers * @@ -674,23 +714,30 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $_debug = null; + /** + * Directory separator + * + * @var string + */ + public $ds = DIRECTORY_SEPARATOR; + /** * removed properties * * @var string[] */ - private static $obsoleteProperties = array('resource_caching', 'template_resource_caching', - 'direct_access_security', '_dir_perms', '_file_perms', - 'plugin_search_order', 'inheritance_merge_compiled_includes'); + 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',); /** - * List of private properties which will call getter/setter ona direct access + * List of private properties which will call getter/setter on a direct access * - * @var array + * @var string[] */ - private static $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir', - 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir', - 'cache_dir' => 'CacheDir',); + private $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir', + 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir', + 'cache_dir' => 'CacheDir',); /**#@-*/ @@ -699,19 +746,19 @@ class Smarty extends Smarty_Internal_TemplateBase */ 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']); + 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 if (Smarty::$_CHARSET !== 'UTF-8') { Smarty::$_UTF8_MODIFIER = ''; @@ -732,31 +779,6 @@ class Smarty extends Smarty_Internal_TemplateBase return $source->exists; } - /** - * Returns a single or all global variables - * - * @param string $varname variable name or null - * - * @return string variable value or or array of variables - */ - public function getGlobal($varname = null) - { - if (isset($varname)) { - if (isset(self::$global_tpl_vars[$varname])) { - return self::$global_tpl_vars[$varname]->value; - } else { - return ''; - } - } else { - $_result = array(); - foreach (self::$global_tpl_vars AS $key => $var) { - $_result[$key] = $var->value; - } - - return $_result; - } - } - /** * Loads security class and enables security * @@ -793,12 +815,14 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function setTemplateDir($template_dir, $isConfig = false) { - $type = $isConfig ? 'config_dir' : 'template_dir'; - $joined = '_joined_' . $type; - $this->{$type} = (array) $template_dir; - $this->{$joined} = join(' # ', $this->{$type}); - $this->_cache[$type . '_new'] = true; - $this->_cache[$type] = 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; } @@ -813,16 +837,36 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function addTemplateDir($template_dir, $key = null, $isConfig = false) { - $type = $isConfig ? 'config_dir' : 'template_dir'; - $joined = '_joined_' . $type; - if (!isset($this->_cache[$type])) { - $this->{$type} = (array) $this->{$type}; - $this->{$joined} = join(' # ', $this->{$type}); - $this->_cache[$type . '_new'] = true; - $this->_cache[$type] = false; + if ($isConfig) { + $processed = &$this->_processedConfigDir; + $dir = &$this->config_dir; + $this->_configDirNormalized = false; + } else { + $processed = &$this->_processedTemplateDir; + $dir = &$this->template_dir; + $this->_templateDirNormalized = false; + } + if (is_array($template_dir)) { + foreach ($template_dir as $k => $v) { + if (is_int($k)) { + // indexes are not merged but appended + $dir[] = $v; + } else { + // string indexes are overridden + $dir[ $k ] = $v; + unset($processed[ $key ]); + } + } + } else { + if ($key !== null) { + // override directory at specified index + $dir[ $key ] = $template_dir; + unset($processed[ $key ]); + } else { + // append new directory + $dir[] = $template_dir; + } } - $this->{$joined} .= ' # ' . join(' # ', (array) $template_dir); - $this->_addDir($type, $template_dir, $key); return $this; } @@ -836,24 +880,18 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function getTemplateDir($index = null, $isConfig = false) { - $type = $isConfig ? 'config_dir' : 'template_dir'; - if (!isset($this->_cache[$type])) { - $joined = '_joined_' . $type; - $this->{$type} = (array) $this->{$type}; - $this->{$joined} = join(' # ', $this->{$type}); - $this->_cache[$type] = false; + if ($isConfig) { + $dir = &$this->config_dir; + } else { + $dir = &$this->template_dir; } - if ($this->_cache[$type] == false) { - foreach ($this->{$type} as $k => $v) { - $this->{$type}[$k] = $this->_realpath($v . DS, true); - } - $this->_cache[$type . '_new'] = true; - $this->_cache[$type] = true; + if ($isConfig ? !$this->_configDirNormalized : !$this->_templateDirNormalized) { + $this->_nomalizeTemplateConfig($isConfig); } if ($index !== null) { - return isset($this->{$type}[$index]) ? $this->{$type}[$index] : null; + return isset($dir[ $index ]) ? $dir[ $index ] : null; } - return $this->{$type}; + return $dir; } /** @@ -903,28 +941,24 @@ class Smarty extends Smarty_Internal_TemplateBase public function setPluginsDir($plugins_dir) { $this->plugins_dir = (array) $plugins_dir; - if (isset($this->_cache['plugins_dir'])) { - unset($this->_cache['plugins_dir']); - } + $this->_pluginsDirNormalized = false; return $this; } /** * Adds directory of plugin files * - * @param $plugins_dir + * @param null|array $plugins_dir * * @return Smarty current Smarty instance for chaining */ public function addPluginsDir($plugins_dir) { - if (!isset($this->plugins_dir)) { - $this->plugins_dir = array(SMARTY_PLUGINS_DIR); - } - $this->plugins_dir = array_merge((array) $this->plugins_dir, (array) $plugins_dir); - if (isset($this->_cache['plugins_dir'])) { - unset($this->_cache['plugins_dir']); + if (empty($this->plugins_dir)) { + $this->plugins_dir[] = SMARTY_PLUGINS_DIR; } + $this->plugins_dir = array_merge($this->plugins_dir, (array) $plugins_dir); + $this->_pluginsDirNormalized = false; return $this; } @@ -935,25 +969,24 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function getPluginsDir() { - if (!isset($this->_cache['plugins_dir'])) { - if (!isset($this->plugins_dir)) { - $this->plugins_dir = array(SMARTY_PLUGINS_DIR); - } else { - $plugins_dir = (array) $this->plugins_dir; - $this->plugins_dir = array(); - foreach ($plugins_dir as $v) { - $this->plugins_dir[] = $this->_realpath($v . DS, true); - } - $this->plugins_dir = array_unique($this->plugins_dir); + if (empty($this->plugins_dir)) { + $this->plugins_dir[] = SMARTY_PLUGINS_DIR; + $this->_pluginsDirNormalized = false; + } + if (!$this->_pluginsDirNormalized) { + if (!is_array($this->plugins_dir)) { + $this->plugins_dir = (array) $this->plugins_dir; } - $this->_cache['plugin_files'] = array(); - $this->_cache['plugins_dir'] = true; + foreach ($this->plugins_dir as $k => $v) { + $this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . $this->ds, true); + } + $this->_cache[ 'plugin_files' ] = array(); + $this->_pluginsDirNormalized = true; } return $this->plugins_dir; } /** - * Set compile directory * * @param string $compile_dir directory to store compiled templates in * @@ -961,11 +994,8 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function setCompileDir($compile_dir) { - $this->compile_dir = $this->_realpath($compile_dir . DS, true); - if (!isset(Smarty::$_muted_directories[$this->compile_dir])) { - Smarty::$_muted_directories[$this->compile_dir] = null; - } - $this->_cache['compile_dir'] = true; + $this->_normalizeDir('compile_dir', $compile_dir); + $this->_compileDirNormalized = true; return $this; } @@ -976,12 +1006,9 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function getCompileDir() { - if (!isset($this->_cache['compile_dir'])) { - $this->compile_dir = $this->_realpath($this->compile_dir . DS, true); - if (!isset(Smarty::$_muted_directories[$this->compile_dir])) { - Smarty::$_muted_directories[$this->compile_dir] = null; - } - $this->_cache['compile_dir'] = true; + if (!$this->_compileDirNormalized) { + $this->_normalizeDir('compile_dir', $this->compile_dir); + $this->_compileDirNormalized = true; } return $this->compile_dir; } @@ -995,11 +1022,8 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function setCacheDir($cache_dir) { - $this->cache_dir = $this->_realpath($cache_dir . DS, true); - if (!isset(Smarty::$_muted_directories[$this->cache_dir])) { - Smarty::$_muted_directories[$this->cache_dir] = null; - } - $this->_cache['cache_dir'] = true; + $this->_normalizeDir('cache_dir', $cache_dir); + $this->_cacheDirNormalized = true; return $this; } @@ -1010,47 +1034,54 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function getCacheDir() { - if (!isset($this->_cache['cache_dir'])) { - $this->cache_dir = $this->_realpath($this->cache_dir . DS, true); - if (!isset(Smarty::$_muted_directories[$this->cache_dir])) { - Smarty::$_muted_directories[$this->cache_dir] = null; - } - $this->_cache['cache_dir'] = true; + if (!$this->_cacheDirNormalized) { + $this->_normalizeDir('cache_dir', $this->cache_dir); + $this->_cacheDirNormalized = true; } return $this->cache_dir; } /** - * add directories to given property name + * Normalize and set directory string * - * @param string $dirName directory property name - * @param string|array $dir directory string or array of strings - * @param mixed $key optional key + * @param string $dirName cache_dir or compile_dir + * @param string $dir filepath of folder */ - private function _addDir($dirName, $dir, $key = null) + private function _normalizeDir($dirName, $dir) { - $rp = $this->_cache[$dirName]; - if (is_array($dir)) { - foreach ($dir as $k => $v) { - $path = $rp ? $this->_realpath($v . DS, true) : $v; - if (is_int($k)) { - // indexes are not merged but appended - $this->{$dirName}[] = $path; - } else { - // string indexes are overridden - $this->{$dirName}[$k] = $path; - } - } + $this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . $this->ds, true); + if (!isset(Smarty::$_muted_directories[ $this->{$dirName} ])) { + Smarty::$_muted_directories[ $this->{$dirName} ] = null; + } + } + + /** + * Normalize template_dir or config_dir + * + * @param bool $isConfig true for config_dir + * + */ + private function _nomalizeTemplateConfig($isConfig) + { + if ($isConfig) { + $processed = &$this->_processedConfigDir; + $dir = &$this->config_dir; } else { - $path = $rp ? $this->_realpath($dir . DS, true) : $dir; - if ($key !== null) { - // override directory at specified index - $this->{$dirName}[$key] = $path; - } else { - // append new directory - $this->{$dirName}[] = $path; + $processed = &$this->_processedTemplateDir; + $dir = &$this->template_dir; + } + if (!is_array($dir)) { + $dir = (array) $dir; + } + foreach ($dir as $k => $v) { + if (!isset($processed[ $k ])) { + $dir[ $k ] = $v = $this->_realpath(rtrim($v, "/\\") . $this->ds, true); + $processed[ $k ] = true; } } + $isConfig ? $this->_configDirNormalized = true : $this->_templateDirNormalized = true; + $isConfig ? $this->_joined_config_dir = join('#', $this->config_dir) : + $this->_joined_template_dir = join('#', $this->template_dir); } /** @@ -1076,27 +1107,34 @@ class Smarty extends Smarty_Internal_TemplateBase } else { $data = null; } - if ($this->caching && - isset($this->_cache['isCached'][$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id)]) - ) { - $tpl = $do_clone ? clone $this->_cache['isCached'][$_templateId] : $this->_cache['isCached'][$_templateId]; - $tpl->parent = $parent; - $tpl->tpl_vars = array(); - $tpl->config_vars = array(); + if (!$this->_templateDirNormalized) { + $this->_nomalizeTemplateConfig(false); + } + $_templateId = $this->_getTemplateId($template, $cache_id, $compile_id); + $tpl = null; + 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(); + } else if (!$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 { /* @var Smarty_Internal_Template $tpl */ - $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id, null, null); + $tpl = new $this->template_class($template, $this, null, $cache_id, $compile_id, null, null); + $tpl->templateId = $_templateId; } if ($do_clone) { $tpl->smarty = clone $tpl->smarty; - } elseif ($parent === null) { - $tpl->parent = $this; } + $tpl->parent = $parent ? $parent : $this; // fill data if present if (!empty($data) && is_array($data)) { // set up variable values foreach ($data as $_key => $_val) { - $tpl->tpl_vars[$_key] = new Smarty_Variable($_val); + $tpl->tpl_vars[ $_key ] = new Smarty_Variable($_val); } } if ($this->debugging || $this->debugging_ctrl == 'URL') { @@ -1128,26 +1166,31 @@ class Smarty extends Smarty_Internal_TemplateBase /** * Get unique template id * - * @param string $template_name - * @param null|mixed $cache_id - * @param null|mixed $compile_id - * @param null $caching + * @param string $template_name + * @param null|mixed $cache_id + * @param null|mixed $compile_id + * @param null $caching + * @param \Smarty_Internal_Template $template * * @return string */ - public function _getTemplateId($template_name, $cache_id = null, $compile_id = null, $caching = null) + public function _getTemplateId($template_name, $cache_id = null, $compile_id = null, $caching = null, + Smarty_Internal_Template $template = null) { + $template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" : + $template_name; $cache_id = $cache_id === null ? $this->cache_id : $cache_id; $compile_id = $compile_id === null ? $this->compile_id : $compile_id; $caching = (int) ($caching === null ? $this->caching : $caching); - if ($this->allow_ambiguous_resources) { + if ((isset($template) && strpos($template_name, ':.') !== false) || $this->allow_ambiguous_resources) { $_templateId = - Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}#{$caching}"; + Smarty_Resource::getUniqueTemplateName((isset($template) ? $template : $this), $template_name) . + "#{$cache_id}#{$compile_id}#{$caching}"; } else { $_templateId = $this->_joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}#{$caching}"; } - if (isset($_templateId[150])) { + if (isset($_templateId[ 150 ])) { $_templateId = sha1($_templateId); } return $_templateId; @@ -1158,36 +1201,66 @@ class Smarty extends Smarty_Internal_TemplateBase * - remove /./ and /../ * - make it absolute if required * - * @param string $path file path - * @param bool $realpath leave $path relative + * @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) { - static $pattern = null; - static $nds = null; - if ($pattern == null) { - $nds = DS == '/' ? '\\' : '/'; - $ds = '\\' . DS; - $pattern = - "#([{$ds}]+[^{$ds}]+[{$ds}]+[.]([{$ds}]+[.])*[.][{$ds}]+([.][{$ds}]+)*)|([{$ds}]+([.][{$ds}]+)+)|[{$ds}]{2,}#"; + $nds = $this->ds == '/' ? '\\' : '/'; + // normalize $this->ds + $path = str_replace($nds, $this->ds, $path); + preg_match('%^(?(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?(?:[[:print:]]*))$%', + $path, $parts); + $path = $parts[ 'path' ]; + if ($parts[ 'root' ] == '\\') { + $parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ]; + } else { + if ($realpath !== null && !$parts[ 'root' ]) { + $path = getcwd() . $this->ds . $path; + } } - // normalize DS - if (strpos($path, $nds) !== false) { - $path = str_replace($nds, DS, $path); + // remove noop 'DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR' and 'DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR' patterns + $path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#', $this->ds, $path); + // resolve '..DIRECTORY_SEPARATOR' pattern, smallest first + if (strpos($path, '..' . $this->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 . '})(?=[^.])#', + $this->ds, $path); + } } - if ($realpath === true && (($path[0] !== '/' && DS == '/') || ($path[1] !== ':' && DS != '/'))) { - $path = getcwd() . DS . $path; - } - while ((strpos($path, '.' . DS) !== false) || (strpos($path, DS . DS) !== false)) { - $path = preg_replace($pattern, DS, $path); - } - if ($realpath === false && ($path[0] == '/' || $path[1] == ':')) { - $path = str_ireplace(getcwd(), '.', $path); - } - return $path; + return $parts[ 'root' ] . $path; + } + + /** + * Empty template objects cache + */ + public function _clearTemplateCache() + { + Smarty_Internal_Template::$isCacheTplObj = array(); + Smarty_Internal_Template::$tplObjCache = array(); + } + + /** + * Get Smarty object + * + * @return Smarty + */ + public function _getSmartyObj() + { + return $this; } /** @@ -1328,14 +1401,6 @@ class Smarty extends Smarty_Internal_TemplateBase Smarty_Internal_TestInstall::testInstall($this, $errors); } - /** - * Class destructor - */ - public function __destruct() - { - $i = 0;// intentionally left blank - } - /** * <> Generic getter. * Calls the appropriate getter function. @@ -1347,15 +1412,17 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function __get($name) { - - if (isset(self::$accessMap[$name])) { - $method = 'get' . self::$accessMap[$name]; + if (isset($this->accessMap[ $name ])) { + $method = 'get' . $this->accessMap[ $name ]; return $this->{$method}(); - } elseif (in_array($name, self::$obsoleteProperties)) { + } elseif (isset($this->_cache[ $name ])) { + return $this->_cache[ $name ]; + } elseif (in_array($name, $this->obsoleteProperties)) { return null; } else { trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); } + return null; } /** @@ -1368,10 +1435,10 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function __set($name, $value) { - if (isset(self::$accessMap[$name])) { - $method = 'set' . self::$accessMap[$name]; + if (isset($this->accessMap[ $name ])) { + $method = 'set' . $this->accessMap[ $name ]; $this->{$method}($value); - } elseif (in_array($name, self::$obsoleteProperties)) { + } elseif (in_array($name, $this->obsoleteProperties)) { return; } else { if (is_object($value) && method_exists($value, $name)) { @@ -1393,17 +1460,17 @@ class Smarty extends Smarty_Internal_TemplateBase * @param $errline * @param $errcontext * - * @return boolean + * @return bool|void */ public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) { $_is_muted_directory = false; // add the SMARTY_DIR to the list of muted directories - if (!isset(Smarty::$_muted_directories[SMARTY_DIR])) { + if (!isset(Smarty::$_muted_directories[ SMARTY_DIR ])) { $smarty_dir = realpath(SMARTY_DIR); if ($smarty_dir !== false) { - Smarty::$_muted_directories[SMARTY_DIR] = + Smarty::$_muted_directories[ SMARTY_DIR ] = array('file' => $smarty_dir, 'length' => strlen($smarty_dir),); } } @@ -1415,17 +1482,16 @@ class Smarty extends Smarty_Internal_TemplateBase $file = realpath($key); if ($file === false) { // this directory does not exist, remove and skip it - unset(Smarty::$_muted_directories[$key]); + unset(Smarty::$_muted_directories[ $key ]); continue; } $dir = array('file' => $file, 'length' => strlen($file),); } - if (!strncmp($errfile, $dir['file'], $dir['length'])) { + 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())) { @@ -1436,6 +1502,7 @@ class Smarty extends Smarty_Internal_TemplateBase return false; } } + return; } /** diff --git a/smarty/libs/SmartyBC.class.php b/smarty/libs/SmartyBC.class.php index 0e06d819..3955e4f2 100644 --- a/smarty/libs/SmartyBC.class.php +++ b/smarty/libs/SmartyBC.class.php @@ -2,7 +2,7 @@ /** * Project: Smarty: the PHP compiling template engine * File: SmartyBC.class.php - * SVN: $Id$ + * SVN: $Id: $ * 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 @@ -31,7 +31,7 @@ require_once(dirname(__FILE__) . '/Smarty.class.php'); /** - * Smarty Backward Compatability Wrapper Class + * Smarty Backward Compatibility Wrapper Class * * @package Smarty */ @@ -54,11 +54,10 @@ class SmartyBC extends Smarty /** * Initialize new SmartyBC object * - * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false ) */ - public function __construct(array $options = array()) + public function __construct() { - parent::__construct($options); + parent::__construct(); } /** @@ -108,7 +107,7 @@ class SmartyBC extends Smarty } /** - * Unregisters custom function + * Unregister custom function * * @param string $function name of template function */ @@ -129,7 +128,8 @@ class SmartyBC extends Smarty * @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'); @@ -137,7 +137,7 @@ class SmartyBC extends Smarty } /** - * Unregisters object + * Unregister object * * @param string $object name of template object */ @@ -160,7 +160,7 @@ class SmartyBC extends Smarty } /** - * Unregisters block function + * Unregister block function * * @param string $block name of template function */ @@ -182,7 +182,7 @@ class SmartyBC extends Smarty } /** - * Unregisters compiler function + * Unregister compiler function * * @param string $function name of template function */ @@ -203,7 +203,7 @@ class SmartyBC extends Smarty } /** - * Unregisters modifier + * Unregister modifier * * @param string $modifier name of template modifier */ @@ -224,7 +224,7 @@ class SmartyBC extends Smarty } /** - * Unregisters a resource + * Unregister a resource * * @param string $type name of resource */ @@ -245,7 +245,7 @@ class SmartyBC extends Smarty } /** - * Unregisters a prefilter function + * Unregister a prefilter function * * @param callable $function */ @@ -266,7 +266,7 @@ class SmartyBC extends Smarty } /** - * Unregisters a postfilter function + * Unregister a postfilter function * * @param callable $function */ @@ -287,7 +287,7 @@ class SmartyBC extends Smarty } /** - * Unregisters an outputfilter function + * Unregister an outputfilter function * * @param callable $function */ diff --git a/smarty/libs/bootstrap.php b/smarty/libs/bootstrap.php new file mode 100644 index 00000000..32096087 --- /dev/null +++ b/smarty/libs/bootstrap.php @@ -0,0 +1,17 @@ + + * + * 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')) { + require __DIR__ . '/Autoloader.php'; +} +Smarty_Autoloader::register(); diff --git a/smarty/libs/plugins/block.textformat.php b/smarty/libs/plugins/block.textformat.php index abf54493..e2c5e3de 100644 --- a/smarty/libs/plugins/block.textformat.php +++ b/smarty/libs/plugins/block.textformat.php @@ -38,6 +38,9 @@ function smarty_block_textformat($params, $content, $template, &$repeat) if (is_null($content)) { return; } + if (Smarty::$_MBSTRING && !is_callable('smarty_mb_wordwrap')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'); + } $style = null; $indent = 0; @@ -83,14 +86,15 @@ function smarty_block_textformat($params, $content, $template, &$repeat) continue; } // convert mult. spaces & special chars to single space - $_paragraph = preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), array(' ', ''), $_paragraph); + $_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); } else { $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); diff --git a/smarty/libs/plugins/function.counter.php b/smarty/libs/plugins/function.counter.php index 4da85a14..bcc8f498 100644 --- a/smarty/libs/plugins/function.counter.php +++ b/smarty/libs/plugins/function.counter.php @@ -25,53 +25,48 @@ 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 - ); + $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]; + $counter =& $counters[ $name ]; - if (isset($params['start'])) { - $counter['start'] = $counter['count'] = (int) $params['start']; + if (isset($params[ 'start' ])) { + $counter[ 'start' ] = $counter[ 'count' ] = (int) $params[ 'start' ]; } - if (!empty($params['assign'])) { - $counter['assign'] = $params['assign']; + if (!empty($params[ 'assign' ])) { + $counter[ 'assign' ] = $params[ 'assign' ]; } - if (isset($counter['assign'])) { - $template->assign($counter['assign'], $counter['count']); + if (isset($counter[ 'assign' ])) { + $template->assign($counter[ 'assign' ], $counter[ 'count' ]); } - if (isset($params['print'])) { - $print = (bool) $params['print']; + if (isset($params[ 'print' ])) { + $print = (bool) $params[ 'print' ]; } else { - $print = empty($counter['assign']); + $print = empty($counter[ 'assign' ]); } if ($print) { - $retval = $counter['count']; + $retval = $counter[ 'count' ]; } else { $retval = null; } - if (isset($params['skip'])) { - $counter['skip'] = $params['skip']; + if (isset($params[ 'skip' ])) { + $counter[ 'skip' ] = $params[ 'skip' ]; } - if (isset($params['direction'])) { - $counter['direction'] = $params['direction']; + if (isset($params[ 'direction' ])) { + $counter[ 'direction' ] = $params[ 'direction' ]; } - if ($counter['direction'] == "down") { - $counter['count'] -= $counter['skip']; + if ($counter[ 'direction' ] == "down") { + $counter[ 'count' ] -= $counter[ 'skip' ]; } else { - $counter['count'] += $counter['skip']; + $counter[ 'count' ] += $counter[ 'skip' ]; } return $retval; diff --git a/smarty/libs/plugins/function.cycle.php b/smarty/libs/plugins/function.cycle.php index 8dc5cd9d..a76d49ae 100644 --- a/smarty/libs/plugins/function.cycle.php +++ b/smarty/libs/plugins/function.cycle.php @@ -48,58 +48,56 @@ 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; + $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; - if (!isset($params['values'])) { - if (!isset($cycle_vars[$name]['values'])) { + if (!isset($params[ 'values' ])) { + if (!isset($cycle_vars[ $name ][ 'values' ])) { trigger_error("cycle: missing 'values' parameter"); return; } } else { - if (isset($cycle_vars[$name]['values']) - && $cycle_vars[$name]['values'] != $params['values'] - ) { - $cycle_vars[$name]['index'] = 0; + if (isset($cycle_vars[ $name ][ 'values' ]) && $cycle_vars[ $name ][ 'values' ] != $params[ 'values' ]) { + $cycle_vars[ $name ][ 'index' ] = 0; } - $cycle_vars[$name]['values'] = $params['values']; + $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 (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']; + 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']); + $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($cycle_vars[ $name ][ 'index' ]) || $reset) { + $cycle_vars[ $name ][ 'index' ] = 0; } - if (isset($params['assign'])) { + if (isset($params[ 'assign' ])) { $print = false; - $template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]); + $template->assign($params[ 'assign' ], $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]); } if ($print) { - $retval = $cycle_array[$cycle_vars[$name]['index']]; + $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; + if ($cycle_vars[ $name ][ 'index' ] >= count($cycle_array) - 1) { + $cycle_vars[ $name ][ 'index' ] = 0; } else { - $cycle_vars[$name]['index'] ++; + $cycle_vars[ $name ][ 'index' ] ++; } } diff --git a/smarty/libs/plugins/function.fetch.php b/smarty/libs/plugins/function.fetch.php index 3506d4a8..cb60dd91 100644 --- a/smarty/libs/plugins/function.fetch.php +++ b/smarty/libs/plugins/function.fetch.php @@ -24,31 +24,31 @@ */ function smarty_function_fetch($params, $template) { - if (empty($params['file'])) { + if (empty($params[ 'file' ])) { 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); + if (stripos($params[ 'file' ], 'file://') === 0) { + $params[ 'file' ] = substr($params[ 'file' ], 7); } - $protocol = strpos($params['file'], '://'); + $protocol = strpos($params[ 'file' ], '://'); if ($protocol !== false) { - $protocol = strtolower(substr($params['file'], 0, $protocol)); + $protocol = strtolower(substr($params[ 'file' ], 0, $protocol)); } if (isset($template->smarty->security_policy)) { if ($protocol) { // remote resource (or php stream, …) - if (!$template->smarty->security_policy->isTrustedUri($params['file'])) { + if (!$template->smarty->security_policy->isTrustedUri($params[ 'file' ])) { return; } } else { // local file - if (!$template->smarty->security_policy->isTrustedResourceDir($params['file'])) { + if (!$template->smarty->security_policy->isTrustedResourceDir($params[ 'file' ])) { return; } } @@ -57,26 +57,26 @@ function smarty_function_fetch($params, $template) $content = ''; if ($protocol == 'http') { // http fetch - if ($uri_parts = parse_url($params['file'])) { + if ($uri_parts = parse_url($params[ 'file' ])) { // set defaults - $host = $server_name = $uri_parts['host']; + $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 = ""; - $uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/'; - $uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : ''; + $uri = !empty($uri_parts[ 'path' ]) ? $uri_parts[ 'path' ] : '/'; + $uri .= !empty($uri_parts[ 'query' ]) ? '?' . $uri_parts[ 'query' ] : ''; $_is_proxy = false; - if (empty($uri_parts['port'])) { + if (empty($uri_parts[ 'port' ])) { $port = 80; } else { - $port = $uri_parts['port']; + $port = $uri_parts[ 'port' ]; } - if (!empty($uri_parts['user'])) { - $user = $uri_parts['user']; + if (!empty($uri_parts[ 'user' ])) { + $user = $uri_parts[ 'user' ]; } - if (!empty($uri_parts['pass'])) { - $pass = $uri_parts['pass']; + if (!empty($uri_parts[ 'pass' ])) { + $pass = $uri_parts[ 'pass' ]; } // loop through parameters, setup headers foreach ($params as $param_key => $param_value) { @@ -163,7 +163,7 @@ function smarty_function_fetch($params, $template) return; } else { if ($_is_proxy) { - fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n"); + fputs($fp, 'GET ' . $params[ 'file' ] . " HTTP/1.0\r\n"); } else { fputs($fp, "GET $uri HTTP/1.0\r\n"); } @@ -195,10 +195,10 @@ function smarty_function_fetch($params, $template) fclose($fp); $csplit = preg_split("!\r\n\r\n!", $content, 2); - $content = $csplit[1]; + $content = $csplit[ 1 ]; - if (!empty($params['assign_headers'])) { - $template->assign($params['assign_headers'], preg_split("!\r\n!", $csplit[0])); + if (!empty($params[ 'assign_headers' ])) { + $template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ])); } } } else { @@ -207,14 +207,14 @@ function smarty_function_fetch($params, $template) return; } } else { - $content = @file_get_contents($params['file']); + $content = @file_get_contents($params[ 'file' ]); if ($content === false) { - throw new SmartyException("{fetch} cannot read resource '" . $params['file'] . "'"); + throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'"); } } - if (!empty($params['assign'])) { - $template->assign($params['assign'], $content); + if (!empty($params[ 'assign' ])) { + $template->assign($params[ 'assign' ], $content); } else { return $content; } diff --git a/smarty/libs/plugins/function.html_checkboxes.php b/smarty/libs/plugins/function.html_checkboxes.php index d7868036..04ce4573 100644 --- a/smarty/libs/plugins/function.html_checkboxes.php +++ b/smarty/libs/plugins/function.html_checkboxes.php @@ -45,7 +45,9 @@ */ function smarty_function_html_checkboxes($params, $template) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + if (!is_callable('smarty_function_escape_special_chars')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + } $name = 'checkbox'; $values = null; @@ -90,19 +92,21 @@ function smarty_function_html_checkboxes($params, $template) 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); } - $selected[$_sel] = true; + $selected[ $_sel ] = true; } } elseif (is_object($_val)) { 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); @@ -110,7 +114,8 @@ function smarty_function_html_checkboxes($params, $template) break; case 'checkboxes': - trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING); + trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', + E_USER_WARNING); $options = (array) $_val; break; @@ -122,9 +127,10 @@ function smarty_function_html_checkboxes($params, $template) case 'disabled': case 'readonly': - if (!empty($params['strict'])) { + 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) { @@ -153,23 +159,28 @@ function smarty_function_html_checkboxes($params, $template) 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); + $_html_result[] = + 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); + $_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; + $_html_result[] = + 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); + if (!empty($params[ 'assign' ])) { + $template->assign($params[ 'assign' ], $_html_result); } else { return implode("\n", $_html_result); } } -function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape = true) +function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, + $label_ids, $escape = true) { $_output = ''; @@ -177,7 +188,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte 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 ''; } @@ -189,7 +201,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte 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 ''; } @@ -199,7 +212,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte 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 .= '