diff --git a/change_log.txt b/change_log.txt index f5e7c950..5e220ac1 100644 --- a/change_log.txt +++ b/change_log.txt @@ -2,9 +2,11 @@ 19.5.2017 - change properties $accessMap and $obsoleteProperties from private to protected https://github.com/smarty-php/smarty/issues/351 - - improvement The named capture buffers can now be accessed also as array + - new feature The named capture buffers can now be accessed also as array See NEWS_FEATURES.txt https://github.com/smarty-php/smarty/issues/366 - + - improvement check if ini_get() and ini_set() not disabled + https://github.com/smarty-php/smarty/pull/362 + 24.4.2017 - fix spelling https://github.com/smarty-php/smarty/commit/e3eda8a5f5653d8abb960eb1bc47e3eca679b1b4#commitcomment-21803095 diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index 7df4ddff..5eb99fb1 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -33,7 +33,9 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource $_filepath = sha1($source->uid . $smarty->_joined_template_dir); $cached->filepath = $smarty->getCacheDir(); if (isset($_template->cache_id)) { - $cached->filepath .= preg_replace(array('![^\w|]+!', '![|]+!'), array('_', $_compile_dir_sep), + $cached->filepath .= preg_replace(array('![^\w|]+!', + '![|]+!'), array('_', + $_compile_dir_sep), $_template->cache_id) . $_compile_dir_sep; } if (isset($_template->compile_id)) { @@ -41,7 +43,8 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource } // if use_sub_dirs, break file into directories if ($smarty->use_sub_dirs) { - $cached->filepath .= $_filepath[ 0 ] . $_filepath[ 1 ] . $smarty->ds . $_filepath[ 2 ] . $_filepath[ 3 ] . $smarty->ds . + $cached->filepath .= $_filepath[ 0 ] . $_filepath[ 1 ] . $smarty->ds . $_filepath[ 2 ] . $_filepath[ 3 ] . + $smarty->ds . $_filepath[ 4 ] . $_filepath[ 5 ] . $smarty->ds; } $cached->filepath .= $_filepath; @@ -108,7 +111,9 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content, $_template->smarty) === true ) { - if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) { + if (function_exists('opcache_invalidate') && + (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api"))) < 1 + ) { opcache_invalidate($_template->cached->filepath, true); } elseif (function_exists('apc_compile_file')) { apc_compile_file($_template->cached->filepath); diff --git a/libs/sysplugins/smarty_internal_config_file_compiler.php b/libs/sysplugins/smarty_internal_config_file_compiler.php index b1ef958c..ec1cb2be 100644 --- a/libs/sysplugins/smarty_internal_config_file_compiler.php +++ b/libs/sysplugins/smarty_internal_config_file_compiler.php @@ -102,28 +102,32 @@ class Smarty_Internal_Config_File_Compiler { $this->template = $template; $this->template->compiled->file_dependency[ $this->template->source->uid ] = - array($this->template->source->filepath, $this->template->source->getTimeStamp(), + array($this->template->source->filepath, + $this->template->source->getTimeStamp(), $this->template->source->type); if ($this->smarty->debugging) { - if (!isset( $this->smarty->_debug)) { - $this->smarty->_debug = new Smarty_Internal_Debug(); + if (!isset($this->smarty->_debug)) { + $this->smarty->_debug = new Smarty_Internal_Debug(); } $this->smarty->_debug->start_compile($this->template); } // init the lexer/parser to compile the config file - /* @var Smarty_Internal_ConfigFileLexer $this->lex */ - $this->lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->getContent()) . "\n", - $this); - /* @var Smarty_Internal_ConfigFileParser $this->parser */ + /* @var Smarty_Internal_ConfigFileLexer $this ->lex */ + $this->lex = new $this->lexer_class(str_replace(array("\r\n", + "\r"), "\n", $template->source->getContent()) . "\n", + $this); + /* @var Smarty_Internal_ConfigFileParser $this ->parser */ $this->parser = new $this->parser_class($this->lex, $this); - if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { + if (function_exists('mb_internal_encoding') + && function_exists('ini_get') + && ((int) ini_get('mbstring.func_overload')) & 2 + ) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); } else { $mbEncoding = null; } - if ($this->smarty->_parserdebug) { $this->parser->PrintTrace(); } diff --git a/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php b/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php index a1f1a80b..54c3a36b 100644 --- a/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php +++ b/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php @@ -75,7 +75,7 @@ class Smarty_Internal_Method_ClearCompiledTemplate } $_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST); foreach ($_compile as $_file) { - if (substr(basename($_file->getPathname()), 0, 1) == '.') { + if (substr(basename($_file->getPathname()), 0, 1) == '.') { continue; } $_filepath = (string) $_file; @@ -86,7 +86,7 @@ class Smarty_Internal_Method_ClearCompiledTemplate } } else { // delete only php files - if (substr($_filepath, -4) !== '.php') { + if (substr($_filepath, - 4) !== '.php') { continue; } $unlink = false; @@ -111,7 +111,9 @@ class Smarty_Internal_Method_ClearCompiledTemplate if ($unlink && @unlink($_filepath)) { $_count ++; - if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) { + if (function_exists('opcache_invalidate') + && (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1) + ) { opcache_invalidate($_filepath, true); } } diff --git a/libs/sysplugins/smarty_internal_resource_php.php b/libs/sysplugins/smarty_internal_resource_php.php index 52e7096b..6e9351d9 100644 --- a/libs/sysplugins/smarty_internal_resource_php.php +++ b/libs/sysplugins/smarty_internal_resource_php.php @@ -18,13 +18,6 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File */ public $uncompiled = true; - /** - * container for short_open_tag directive's value before executing PHP templates - * - * @var string - */ - protected $short_open_tag; - /** * Resource does implement populateCompiledFilepath() method * @@ -32,12 +25,19 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File */ public $hasCompiledHandler = true; + /** + * container for short_open_tag directive's value before executing PHP templates + * + * @var string + */ + protected $short_open_tag; + /** * Create a new PHP Resource */ public function __construct() { - $this->short_open_tag = ini_get('short_open_tag'); + $this->short_open_tag = function_exists('ini_get') ? ini_get('short_open_tag') : 1; } /** @@ -56,6 +56,23 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); } + /** + * populate compiled object with compiled filepath + * + * @param Smarty_Template_Compiled $compiled compiled object + * @param Smarty_Internal_Template $_template template object (is ignored) + */ + public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) + { + $compiled->filepath = $_template->source->filepath; + $compiled->timestamp = $_template->source->timestamp; + $compiled->exists = $_template->source->exists; + $compiled->file_dependency[ $_template->source->uid ] = + array($compiled->filepath, + $compiled->timestamp, + $_template->source->type,); + } + /** * Render and output the template (without using the compiler) * @@ -79,28 +96,16 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File extract($_template->getTemplateVars()); // include PHP template with short open tags enabled - ini_set('short_open_tag', '1'); + if (function_exists('ini_set')) { + ini_set('short_open_tag', '1'); + } /** @var Smarty_Internal_Template $_smarty_template * used in included file */ $_smarty_template = $_template; include($source->filepath); - ini_set('short_open_tag', $this->short_open_tag); - } - - /** - * populate compiled object with compiled filepath - * - * @param Smarty_Template_Compiled $compiled compiled object - * @param Smarty_Internal_Template $_template template object (is ignored) - */ - public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) - { - $compiled->filepath = $_template->source->filepath; - $compiled->timestamp = $_template->source->timestamp; - $compiled->exists = $_template->source->exists; - $compiled->file_dependency[ $_template->source->uid ] = - array($compiled->filepath, $compiled->timestamp, - $_template->source->type,); + if (function_exists('ini_set')) { + ini_set('short_open_tag', $this->short_open_tag); + } } } diff --git a/libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php b/libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php index 7b7a9f68..523b7560 100644 --- a/libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php +++ b/libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php @@ -80,7 +80,7 @@ class Smarty_Internal_Runtime_CacheResourceFile } } else { // delete only php files - if (substr($_filepath, -4) !== '.php') { + if (substr($_filepath, - 4) !== '.php') { continue; } $_parts = explode($_dir_sep, str_replace('\\', '/', substr($_filepath, $_dir_length))); @@ -125,7 +125,9 @@ class Smarty_Internal_Runtime_CacheResourceFile } } $_count += @unlink($_filepath) ? 1 : 0; - if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) { + if (function_exists('opcache_invalidate') + && (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1) + ) { opcache_invalidate($_filepath, true); } } diff --git a/libs/sysplugins/smarty_internal_smartytemplatecompiler.php b/libs/sysplugins/smarty_internal_smartytemplatecompiler.php index 8cd37dd5..bdf74065 100644 --- a/libs/sysplugins/smarty_internal_smartytemplatecompiler.php +++ b/libs/sysplugins/smarty_internal_smartytemplatecompiler.php @@ -89,12 +89,16 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom then written to compiled files. */ // init the lexer/parser to compile the template $this->parser = - new $this->parser_class(new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $_content), $this), + new $this->parser_class(new $this->lexer_class(str_replace(array("\r\n", + "\r"), "\n", $_content), $this), $this); if ($isTemplateSource && $this->template->caching) { $this->parser->insertPhpCode("compiled->nocache_hash = '{$this->nocache_hash}';\n?>\n"); } - if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { + if (function_exists('mb_internal_encoding') + && function_exists('ini_get') + && ((int) ini_get('mbstring.func_overload')) & 2 + ) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); } else { diff --git a/libs/sysplugins/smarty_template_compiled.php b/libs/sysplugins/smarty_template_compiled.php index 18f9d562..803fd260 100644 --- a/libs/sysplugins/smarty_template_compiled.php +++ b/libs/sysplugins/smarty_template_compiled.php @@ -80,64 +80,6 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base } } - /** - * load compiled template or compile from source - * - * @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template - * - * @throws Exception - */ - public function process(Smarty_Internal_Template $_smarty_tpl) - { - $source = &$_smarty_tpl->source; - $smarty = &$_smarty_tpl->smarty; - if ($source->handler->recompiled) { - $source->handler->process($_smarty_tpl); - } elseif (!$source->handler->uncompiled) { - if (!$this->exists || $smarty->force_compile || - ($smarty->compile_check && $source->getTimeStamp() > $this->getTimeStamp()) - ) { - $this->compileTemplateSource($_smarty_tpl); - $compileCheck = $smarty->compile_check; - $smarty->compile_check = false; - $this->loadCompiledTemplate($_smarty_tpl); - $smarty->compile_check = $compileCheck; - } else { - $_smarty_tpl->mustCompile = true; - @include($this->filepath); - if ($_smarty_tpl->mustCompile) { - $this->compileTemplateSource($_smarty_tpl); - $compileCheck = $smarty->compile_check; - $smarty->compile_check = false; - $this->loadCompiledTemplate($_smarty_tpl); - $smarty->compile_check = $compileCheck; - } - } - $_smarty_tpl->_subTemplateRegister(); - $this->processed = true; - } - } - - /** - * Load fresh compiled template by including the PHP file - * HHVM requires a work around because of a PHP incompatibility - * - * @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template - */ - private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl) - { - if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) { - opcache_invalidate($this->filepath, true); - } elseif (function_exists('apc_compile_file')) { - apc_compile_file($this->filepath); - } - if (defined('HHVM_VERSION')) { - eval("?>" . file_get_contents($this->filepath)); - } else { - include($this->filepath); - } - } - /** * render compiled template code * @@ -179,6 +121,44 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base } } + /** + * load compiled template or compile from source + * + * @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template + * + * @throws Exception + */ + public function process(Smarty_Internal_Template $_smarty_tpl) + { + $source = &$_smarty_tpl->source; + $smarty = &$_smarty_tpl->smarty; + if ($source->handler->recompiled) { + $source->handler->process($_smarty_tpl); + } elseif (!$source->handler->uncompiled) { + if (!$this->exists || $smarty->force_compile || + ($smarty->compile_check && $source->getTimeStamp() > $this->getTimeStamp()) + ) { + $this->compileTemplateSource($_smarty_tpl); + $compileCheck = $smarty->compile_check; + $smarty->compile_check = false; + $this->loadCompiledTemplate($_smarty_tpl); + $smarty->compile_check = $compileCheck; + } else { + $_smarty_tpl->mustCompile = true; + @include($this->filepath); + if ($_smarty_tpl->mustCompile) { + $this->compileTemplateSource($_smarty_tpl); + $compileCheck = $smarty->compile_check; + $smarty->compile_check = false; + $this->loadCompiledTemplate($_smarty_tpl); + $smarty->compile_check = $compileCheck; + } + } + $_smarty_tpl->_subTemplateRegister(); + $this->processed = true; + } + } + /** * compile template from source * @@ -238,6 +218,27 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base return true; } + /** + * Load fresh compiled template by including the PHP file + * HHVM requires a work around because of a PHP incompatibility + * + * @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template + */ + private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl) + { + if (function_exists('opcache_invalidate') + && (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1) + ) { + } elseif (function_exists('apc_compile_file')) { + apc_compile_file($this->filepath); + } + if (defined('HHVM_VERSION')) { + eval("?>" . file_get_contents($this->filepath)); + } else { + include($this->filepath); + } + } + /** * Read compiled content from handler *