summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authoruwetews <uwe.tews@googlemail.com>2017-05-19 22:35:55 +0200
committeruwetews <uwe.tews@googlemail.com>2017-05-21 02:24:48 +0200
commitda22c961bba60c9a01473a9763913904fda37222 (patch)
tree84536000746c9a25a702fc788dbc39604fdfc6ca /libs
parent2782e83a924c4daa71aa65e292ecc315bb1e66ec (diff)
downloadsmarty-da22c961bba60c9a01473a9763913904fda37222.tar.gz
smarty-da22c961bba60c9a01473a9763913904fda37222.tar.bz2
smarty-da22c961bba60c9a01473a9763913904fda37222.zip
- improvement check if ini_get() and ini_set() not disabled
https://github.com/smarty-php/smarty/pull/362
Diffstat (limited to 'libs')
-rw-r--r--libs/sysplugins/smarty_internal_cacheresource_file.php11
-rw-r--r--libs/sysplugins/smarty_internal_config_file_compiler.php22
-rw-r--r--libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php8
-rw-r--r--libs/sysplugins/smarty_internal_resource_php.php55
-rw-r--r--libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php6
-rw-r--r--libs/sysplugins/smarty_internal_smartytemplatecompiler.php8
-rw-r--r--libs/sysplugins/smarty_template_compiled.php117
7 files changed, 125 insertions, 102 deletions
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
@@ -19,25 +19,25 @@ 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
+ * Resource does implement populateCompiledFilepath() method
*
- * @var string
+ * @var bool
*/
- protected $short_open_tag;
+ public $hasCompiledHandler = true;
/**
- * Resource does implement populateCompiledFilepath() method
+ * container for short_open_tag directive's value before executing PHP templates
*
- * @var bool
+ * @var string
*/
- public $hasCompiledHandler = true;
+ 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;
}
/**
@@ -57,6 +57,23 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
}
/**
+ * 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)
*
* @param Smarty_Template_Source $source source object
@@ -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("<?php\n\$_smarty_tpl->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
@@ -81,64 +81,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
*
* @param Smarty_Internal_Template $_template
@@ -180,6 +122,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
*
* @param Smarty_Internal_Template $_template
@@ -239,6 +219,27 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
}
/**
+ * 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
*
* @param Smarty_Internal_Template $_template template object