mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
- added $error_muting to suppress error messages even for badly implemented error_handlers
- reverted r4301
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
===== Smarty 3.1 trunk =====
|
===== Smarty 3.1 trunk =====
|
||||||
21.09.2011
|
21.09.2011
|
||||||
- bugfix look for mixed case plugin file names as in 3.0 if not found try all lowercase
|
- bugfix look for mixed case plugin file names as in 3.0 if not found try all lowercase
|
||||||
- bugfix use 3.0 version of smarty_internal_write_file.php because of problems with custom error handlers
|
- added $error_muting to suppress error messages even for badly implemented error_handlers
|
||||||
|
|
||||||
20.09.2011
|
20.09.2011
|
||||||
- bugfix removed debug echo output while compiling template inheritance
|
- bugfix removed debug echo output while compiling template inheritance
|
||||||
|
@@ -157,6 +157,11 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
* assigned global tpl vars
|
* assigned global tpl vars
|
||||||
*/
|
*/
|
||||||
public static $global_tpl_vars = array();
|
public static $global_tpl_vars = array();
|
||||||
|
/**
|
||||||
|
* Enable error_handler suppression to outsmart badly implemented external error_handlers
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
public static $error_muting = true;
|
||||||
|
|
||||||
/**#@+
|
/**#@+
|
||||||
* variables
|
* variables
|
||||||
@@ -684,10 +689,13 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
*/
|
*/
|
||||||
function clearAllCache($exp_time = null, $type = null)
|
function clearAllCache($exp_time = null, $type = null)
|
||||||
{
|
{
|
||||||
|
Smarty::muteExpectedErrors();
|
||||||
// load cache resource and call clearAll
|
// load cache resource and call clearAll
|
||||||
$_cache_resource = Smarty_CacheResource::load($this, $type);
|
$_cache_resource = Smarty_CacheResource::load($this, $type);
|
||||||
Smarty_CacheResource::invalidLoadedCache($this);
|
Smarty_CacheResource::invalidLoadedCache($this);
|
||||||
return $_cache_resource->clearAll($this, $exp_time);
|
$t = $_cache_resource->clearAll($this, $exp_time);
|
||||||
|
Smarty::unmuteExpectedErrors();
|
||||||
|
return $t;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -702,10 +710,13 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
*/
|
*/
|
||||||
public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
|
public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
|
||||||
{
|
{
|
||||||
|
Smarty::muteExpectedErrors();
|
||||||
// load cache resource and call clear
|
// load cache resource and call clear
|
||||||
$_cache_resource = Smarty_CacheResource::load($this, $type);
|
$_cache_resource = Smarty_CacheResource::load($this, $type);
|
||||||
Smarty_CacheResource::invalidLoadedCache($this);
|
Smarty_CacheResource::invalidLoadedCache($this);
|
||||||
return $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time);
|
$t = $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time);
|
||||||
|
Smarty::unmuteExpectedErrors();
|
||||||
|
return $t;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1178,7 +1189,8 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
// Plugin name is expected to be: Smarty_[Type]_[Name]
|
// Plugin name is expected to be: Smarty_[Type]_[Name]
|
||||||
$_name_parts = explode('_', $plugin_name, 3);
|
$_name_parts = explode('_', $plugin_name, 3);
|
||||||
// class name must have three parts to be valid plugin
|
// class name must have three parts to be valid plugin
|
||||||
if (count($_name_parts) < 3 || strtolower($_name_parts[0]) !== 'smarty') {
|
// count($_name_parts) < 3 === !isset($_name_parts[2])
|
||||||
|
if (!isset($_name_parts[2]) || strtolower($_name_parts[0]) !== 'smarty') {
|
||||||
throw new SmartyException("plugin {$plugin_name} is not a valid name format");
|
throw new SmartyException("plugin {$plugin_name} is not a valid name format");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1196,9 +1208,10 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
$_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php";
|
$_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php";
|
||||||
// loop through plugin dirs and find the plugin
|
// loop through plugin dirs and find the plugin
|
||||||
foreach($this->getPluginsDir() as $_plugin_dir) {
|
foreach($this->getPluginsDir() as $_plugin_dir) {
|
||||||
$names = array();
|
$names = array(
|
||||||
$names[] = $_plugin_dir . $_plugin_filename;
|
// $_plugin_dir . $_plugin_filename,
|
||||||
$names[] = $_plugin_dir . strtolower($_plugin_filename);
|
$_plugin_dir . strtolower($_plugin_filename),
|
||||||
|
);
|
||||||
foreach ($names as $file) {
|
foreach ($names as $file) {
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
require_once($file);
|
require_once($file);
|
||||||
@@ -1280,7 +1293,43 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
{
|
{
|
||||||
return Smarty_Internal_Utility::testInstall($this, $errors);
|
return Smarty_Internal_Utility::testInstall($this, $errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error Handler to mute expected messages
|
||||||
|
*
|
||||||
|
* @link http://php.net/set_error_handler
|
||||||
|
* @param integer $errno Error level
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function mutingErrorHandler($errno)
|
||||||
|
{
|
||||||
|
// return false if $errno is not 0 and included in current error level
|
||||||
|
return (bool)($errno && $errno & error_reporting());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable error handler to mute expected messages
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function muteExpectedErrors()
|
||||||
|
{
|
||||||
|
if (self::$error_muting) {
|
||||||
|
set_error_handler(array('Smarty', 'mutingErrorHandler'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable error handler muting expected messages
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function unmuteExpectedErrors()
|
||||||
|
{
|
||||||
|
if (self::$error_muting) {
|
||||||
|
restore_error_handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -61,7 +61,9 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
|
|||||||
$cached->lock_id = $_lock_dir.sha1($_cache_id.$_compile_id.$_template->source->uid).'.lock';
|
$cached->lock_id = $_lock_dir.sha1($_cache_id.$_compile_id.$_template->source->uid).'.lock';
|
||||||
}
|
}
|
||||||
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
|
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
|
||||||
|
Smarty::muteExpectedErrors();
|
||||||
$cached->timestamp = @filemtime($cached->filepath);
|
$cached->timestamp = @filemtime($cached->filepath);
|
||||||
|
Smarty::unmuteExpectedErrors();
|
||||||
$cached->exists = !!$cached->timestamp;
|
$cached->exists = !!$cached->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +75,9 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
|
|||||||
*/
|
*/
|
||||||
public function populateTimestamp(Smarty_Template_Cached $cached)
|
public function populateTimestamp(Smarty_Template_Cached $cached)
|
||||||
{
|
{
|
||||||
|
Smarty::muteExpectedErrors();
|
||||||
$cached->timestamp = @filemtime($cached->filepath);
|
$cached->timestamp = @filemtime($cached->filepath);
|
||||||
|
Smarty::unmuteExpectedErrors();
|
||||||
$cached->exists = !!$cached->timestamp;
|
$cached->exists = !!$cached->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -174,6 +174,7 @@ class Smarty_Internal_Data {
|
|||||||
if (!isset($this->tpl_vars[$tpl_var])) {
|
if (!isset($this->tpl_vars[$tpl_var])) {
|
||||||
$this->tpl_vars[$tpl_var] = new Smarty_variable();
|
$this->tpl_vars[$tpl_var] = new Smarty_variable();
|
||||||
}
|
}
|
||||||
|
// FIXME u.tews what's this @silence doing here?
|
||||||
if (!@is_array($this->tpl_vars[$tpl_var]->value)) {
|
if (!@is_array($this->tpl_vars[$tpl_var]->value)) {
|
||||||
settype($this->tpl_vars[$tpl_var]->value, 'array');
|
settype($this->tpl_vars[$tpl_var]->value, 'array');
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource {
|
|||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
|
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
|
||||||
{
|
{
|
||||||
|
Smarty::muteExpectedErrors();
|
||||||
$source->filepath = $this->buildFilepath($source, $_template);
|
$source->filepath = $this->buildFilepath($source, $_template);
|
||||||
|
|
||||||
if ($source->filepath !== false) {
|
if ($source->filepath !== false) {
|
||||||
@@ -39,6 +40,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource {
|
|||||||
$source->exists = !!$source->timestamp;
|
$source->exists = !!$source->timestamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Smarty::unmuteExpectedErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,7 +50,9 @@ class Smarty_Internal_Resource_File extends Smarty_Resource {
|
|||||||
*/
|
*/
|
||||||
public function populateTimestamp(Smarty_Template_Source $source)
|
public function populateTimestamp(Smarty_Template_Source $source)
|
||||||
{
|
{
|
||||||
|
Smarty::muteExpectedErrors();
|
||||||
$source->timestamp = @filemtime($source->filepath);
|
$source->timestamp = @filemtime($source->filepath);
|
||||||
|
Smarty::unmuteExpectedErrors();
|
||||||
$source->exists = !!$source->timestamp;
|
$source->exists = !!$source->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled {
|
|||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
|
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
|
||||||
{
|
{
|
||||||
|
Smarty::muteExpectedErrors();
|
||||||
$source->filepath = $this->buildFilepath($source, $_template);
|
$source->filepath = $this->buildFilepath($source, $_template);
|
||||||
|
|
||||||
if ($source->filepath !== false) {
|
if ($source->filepath !== false) {
|
||||||
@@ -48,6 +49,7 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled {
|
|||||||
$source->exists = !!$source->timestamp;
|
$source->exists = !!$source->timestamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Smarty::unmuteExpectedErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,7 +60,9 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled {
|
|||||||
*/
|
*/
|
||||||
public function populateTimestamp(Smarty_Template_Source $source)
|
public function populateTimestamp(Smarty_Template_Source $source)
|
||||||
{
|
{
|
||||||
|
Smarty::muteExpectedErrors();
|
||||||
$source->timestamp = @filemtime($source->filepath);
|
$source->timestamp = @filemtime($source->filepath);
|
||||||
|
Smarty::unmuteExpectedErrors();
|
||||||
$source->exists = !!$source->timestamp;
|
$source->exists = !!$source->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,56 +1,74 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty write file plugin
|
* Smarty write file plugin
|
||||||
*
|
*
|
||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsInternal
|
* @subpackage PluginsInternal
|
||||||
* @author Monte Ohrt
|
* @author Monte Ohrt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Write File Class
|
* Smarty Internal Write File Class
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage PluginsInternal
|
||||||
*/
|
*/
|
||||||
class Smarty_Internal_Write_File {
|
class Smarty_Internal_Write_File {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes file in a save way to disk
|
* Writes file in a safe way to disk
|
||||||
*
|
*
|
||||||
* @param string $_filepath complete filepath
|
* @param string $_filepath complete filepath
|
||||||
* @param string $_contents file content
|
* @param string $_contents file content
|
||||||
|
* @param Smarty $smarty smarty instance
|
||||||
* @return boolean true
|
* @return boolean true
|
||||||
*/
|
*/
|
||||||
public static function writeFile($_filepath, $_contents, $smarty)
|
public static function writeFile($_filepath, $_contents, Smarty $smarty)
|
||||||
{
|
{
|
||||||
$old_umask = umask(0);
|
Smarty::muteExpectedErrors();
|
||||||
$_dirpath = dirname($_filepath);
|
$_error_reporting = error_reporting();
|
||||||
|
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
|
||||||
|
if ($smarty->_file_perms !== null) {
|
||||||
|
$old_umask = umask(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$_dirpath = dirname($_filepath);
|
||||||
// if subdirs, create dir structure
|
// if subdirs, create dir structure
|
||||||
if ($_dirpath !== '.' && !file_exists($_dirpath)) {
|
if ($_dirpath !== '.' && !file_exists($_dirpath)) {
|
||||||
mkdir($_dirpath, $smarty->_dir_perms, true);
|
mkdir($_dirpath, $smarty->_dir_perms === null ? 0777 : $smarty->_dir_perms, true);
|
||||||
}
|
}
|
||||||
// write to tmp file, then move to overt file lock race condition
|
|
||||||
$_tmp_file = tempnam($_dirpath, 'wrt');
|
|
||||||
|
|
||||||
if (!($fd = @fopen($_tmp_file, 'wb'))) {
|
// write to tmp file, then move to overt file lock race condition
|
||||||
$_tmp_file = $_dirpath . DS . uniqid('wrt');
|
$_tmp_file = $_dirpath . DS . uniqid('wrt');
|
||||||
if (!($fd = @fopen($_tmp_file, 'wb'))) {
|
if (!file_put_contents($_tmp_file, $_contents)) {
|
||||||
|
error_reporting($_error_reporting);
|
||||||
|
Smarty::unmuteExpectedErrors();
|
||||||
throw new SmartyException("unable to write file {$_tmp_file}");
|
throw new SmartyException("unable to write file {$_tmp_file}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fwrite($fd, $_contents);
|
|
||||||
fclose($fd);
|
|
||||||
|
|
||||||
// remove original file
|
// remove original file
|
||||||
if (file_exists($_filepath))
|
unlink($_filepath);
|
||||||
@unlink($_filepath);
|
|
||||||
// rename tmp file
|
// rename tmp file
|
||||||
rename($_tmp_file, $_filepath);
|
$success = rename($_tmp_file, $_filepath);
|
||||||
// set file permissions
|
if (!$success) {
|
||||||
chmod($_filepath, $smarty->_file_perms);
|
error_reporting($_error_reporting);
|
||||||
umask($old_umask);
|
Smarty::unmuteExpectedErrors();
|
||||||
|
throw new SmartyException("unable to write file {$_filepath}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($smarty->_file_perms !== null) {
|
||||||
|
// set file permissions
|
||||||
|
chmod($_filepath, $smarty->_file_perms);
|
||||||
|
umask($old_umask);
|
||||||
|
}
|
||||||
|
error_reporting($_error_reporting);
|
||||||
|
Smarty::unmuteExpectedErrors();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@@ -422,7 +422,7 @@ abstract class Smarty_Resource {
|
|||||||
$resource_name = $template_resource;
|
$resource_name = $template_resource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$resource = Smarty_Resource::load($smarty, $resource_type);
|
$resource = Smarty_Resource::load($smarty, $resource_type);
|
||||||
$source = new Smarty_Template_Source($resource, $smarty, $template_resource, $resource_type, $resource_name);
|
$source = new Smarty_Template_Source($resource, $smarty, $template_resource, $resource_type, $resource_name);
|
||||||
$resource->populate($source, $_template);
|
$resource->populate($source, $_template);
|
||||||
@@ -609,7 +609,9 @@ class Smarty_Template_Source {
|
|||||||
|
|
||||||
$compiled = new Smarty_Template_Compiled($this);
|
$compiled = new Smarty_Template_Compiled($this);
|
||||||
$this->handler->populateCompiledFilepath($compiled, $_template);
|
$this->handler->populateCompiledFilepath($compiled, $_template);
|
||||||
|
Smarty::muteExpectedErrors();
|
||||||
$compiled->timestamp = @filemtime($compiled->filepath);
|
$compiled->timestamp = @filemtime($compiled->filepath);
|
||||||
|
Smarty::unmuteExpectedErrors();
|
||||||
$compiled->exists = !!$compiled->timestamp;
|
$compiled->exists = !!$compiled->timestamp;
|
||||||
|
|
||||||
// runtime cache
|
// runtime cache
|
||||||
|
Reference in New Issue
Block a user