diff --git a/CHANGELOG.md b/CHANGELOG.md index 43cc3968..6ebbb64b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ - Corrected translations [\#183](https://github.com/torrentpier/torrentpier-lts/pull/183) ([belomaxorka](https://github.com/belomaxorka)) - Fixed $bb_cfg['pm_days_keep'] [\#180](https://github.com/torrentpier/torrentpier-lts/pull/180) ([belomaxorka](https://github.com/belomaxorka)) - IP storage bugfix [\#177](https://github.com/torrentpier/torrentpier-lts/pull/177) ([belomaxorka](https://github.com/belomaxorka)) -- Minor improvements [\#172](https://github.com/torrentpier/torrentpier-lts/pull/172), [\#175](https://github.com/torrentpier/torrentpier-lts/pull/175), [\#176](https://github.com/torrentpier/torrentpier-lts/pull/176), [\#178](https://github.com/torrentpier/torrentpier-lts/pull/178), [\#179](https://github.com/torrentpier/torrentpier-lts/pull/179), [\#181](https://github.com/torrentpier/torrentpier-lts/pull/181), [\#187](https://github.com/torrentpier/torrentpier-lts/pull/187), [\#192](https://github.com/torrentpier/torrentpier-lts/pull/192), [\#194](https://github.com/torrentpier/torrentpier-lts/pull/194) ([belomaxorka](https://github.com/belomaxorka)) +- Minor improvements [\#172](https://github.com/torrentpier/torrentpier-lts/pull/172), [\#175](https://github.com/torrentpier/torrentpier-lts/pull/175), [\#176](https://github.com/torrentpier/torrentpier-lts/pull/176), [\#178](https://github.com/torrentpier/torrentpier-lts/pull/178), [\#179](https://github.com/torrentpier/torrentpier-lts/pull/179), [\#181](https://github.com/torrentpier/torrentpier-lts/pull/181), [\#187](https://github.com/torrentpier/torrentpier-lts/pull/187), [\#192](https://github.com/torrentpier/torrentpier-lts/pull/192), [\#194](https://github.com/torrentpier/torrentpier-lts/pull/194), [\#195](https://github.com/torrentpier/torrentpier-lts/pull/195) ([belomaxorka](https://github.com/belomaxorka)) - Fixed empty user search box [\#171](https://github.com/torrentpier/torrentpier-lts/pull/171) ([belomaxorka](https://github.com/belomaxorka)) - Added some placeholders for input fields [\#173](https://github.com/torrentpier/torrentpier-lts/pull/173) ([belomaxorka](https://github.com/belomaxorka)) diff --git a/common.php b/common.php index fe1b44c3..d43e41b6 100644 --- a/common.php +++ b/common.php @@ -199,47 +199,36 @@ function bb_log ($msg, $file_name) function file_write ($str, $file, $max_size = LOG_MAX_SIZE, $lock = true, $replace_content = false) { $bytes_written = false; + clearstatcache(); - clearstatcache(); - - if ($max_size && @file_exists($file) && !is_dir($file) && (@filesize($file) >= $max_size)) + if (($max_size && file_exists($file) && is_file($file)) && filesize($file) >= $max_size) { - $old_name = $file; $ext = ''; - if (preg_match('#^(.+)(\.[^\\\/]+)$#', $file, $matches)) - { - $old_name = $matches[1]; $ext = $matches[2]; - } - $new_name = $old_name .'_[old]_'. date('Y-m-d_H-i-s_') . getmypid() . $ext; + $file_parts = pathinfo($file); + $new_name = ($file_parts['dirname'] . '/' . $file_parts['filename'] . '_[old]_' . date('Y-m-d_H-i-s_') . getmypid() . '.' . $file_parts['extension']); clearstatcache(); - if (@file_exists($file) && !is_dir($file) && (@filesize($file) >= $max_size) && !@file_exists($new_name)) + if (!file_exists($new_name) && !is_file($new_name)) { - @rename($file, $new_name); + rename($file, $new_name); } } - - clearstatcache(); - - if (!$fp = @fopen($file, 'ab')) + clearstatcache(); + if (bb_mkdir(dirname($file))) { - if ($dir_created = bb_mkdir(dirname($file))) + if ($fp = fopen($file, 'ab+')) { - $fp = @fopen($file, 'ab'); + if ($lock) + { + flock($fp, LOCK_EX); + } + if ($replace_content) + { + ftruncate($fp, 0); + fseek($fp, 0, SEEK_SET); + } + $bytes_written = fwrite($fp, $str); + fclose($fp); } } - if ($fp) - { - if ($lock) - { - @flock($fp, LOCK_EX); - } - if ($replace_content) - { - @ftruncate($fp, 0); - @fseek($fp, 0, SEEK_SET); - } - $bytes_written = @fwrite($fp, $str); - @fclose($fp); - } return $bytes_written; }