Some reported bugfixes (#1275)

* Some reported bugfixes

* Updated

* Update common.php

* Update BBCode.php
This commit is contained in:
Roman Kelesidis 2023-12-27 12:15:43 +07:00 committed by GitHub
commit e8a90b025c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 31 deletions

View file

@ -190,11 +190,11 @@ function file_write($str, $file, $max_size = LOG_MAX_SIZE, $lock = true, $replac
$bytes_written = false; $bytes_written = false;
clearstatcache(); clearstatcache();
if (($max_size && file_exists($file) && is_file($file)) && filesize($file) >= $max_size) { if (is_file($file) && ($max_size && filesize($file) >= $max_size)) {
$file_parts = pathinfo($file); $file_parts = pathinfo($file);
$new_name = ($file_parts['dirname'] . '/' . $file_parts['filename'] . '_[old]_' . date('Y-m-d_H-i-s_') . getmypid() . '.' . $file_parts['extension']); $new_name = ($file_parts['dirname'] . '/' . $file_parts['filename'] . '_[old]_' . date('Y-m-d_H-i-s_') . getmypid() . '.' . $file_parts['extension']);
clearstatcache(); clearstatcache();
if (!file_exists($new_name) && !is_file($new_name)) { if (!is_file($new_name)) {
rename($file, $new_name); rename($file, $new_name);
} }
} }
@ -269,6 +269,7 @@ function str_compact($str)
* *
* @param int $length * @param int $length
* @return string * @return string
* @throws Exception
*/ */
function make_rand_str(int $length = 10): string function make_rand_str(int $length = 10): string
{ {

View file

@ -16,13 +16,13 @@ namespace TorrentPier\Legacy;
class BBCode class BBCode
{ {
/** @var array $tpl Replacements for some code elements */ /** @var array $tpl Replacements for some code elements */
public $tpl = []; public array $tpl = [];
/** @var array $smilies Replacements for smilies */ /** @var array $smilies Replacements for smilies */
public $smilies; public $smilies;
/** @var array $tidy_cfg Tidy preprocessor configuration */ /** @var array $tidy_cfg Tidy preprocessor configuration */
public $tidy_cfg = [ public array $tidy_cfg = [
'drop-empty-paras' => false, 'drop-empty-paras' => false,
'fix-uri' => false, 'fix-uri' => false,
'force-output' => true, 'force-output' => true,
@ -42,7 +42,7 @@ class BBCode
]; ];
/** @var array $block_tags Define some elements as block-processed */ /** @var array $block_tags Define some elements as block-processed */
public $block_tags = [ public array $block_tags = [
'align', 'align',
'br', 'br',
'clear', 'clear',
@ -142,7 +142,7 @@ class BBCode
* *
* @return string * @return string
*/ */
public function bbcode2html($text): string public function bbcode2html(string $text): string
{ {
global $bb_cfg; global $bb_cfg;
@ -166,7 +166,7 @@ class BBCode
* *
* @return string * @return string
*/ */
private function parse($text): string private function parse(string $text): string
{ {
// Tag parse // Tag parse
if (!str_contains($text, '[')) { if (!str_contains($text, '[')) {
@ -205,23 +205,22 @@ class BBCode
* *
* @return string * @return string
*/ */
public static function clean_up($text): string public static function clean_up(string $text): string
{ {
$text = trim($text); $text = trim($text);
$text = str_replace("\r", '', $text); $text = str_replace("\r", '', $text);
$text = preg_replace('#[ \t]+$#m', '', $text); $text = preg_replace('#[ \t]+$#m', '', $text);
$text = preg_replace('#\n{3,}#', "\n\n", $text); return preg_replace('#\n{3,}#', "\n\n", $text);
return $text;
} }
/** /**
* Callback to [code] * Callback to [code]
* *
* @param string $m * @param array $m
* *
* @return string * @return string
*/ */
private function code_callback($m): string private function code_callback(array $m): string
{ {
$code = trim($m[2]); $code = trim($m[2]);
$code = str_replace(' ', '  ', $code); $code = str_replace(' ', '  ', $code);
@ -234,11 +233,11 @@ class BBCode
/** /**
* Callback to [url] * Callback to [url]
* *
* @param string $m * @param array $m
* *
* @return string * @return string
*/ */
private function url_callback($m): string private function url_callback(array $m): string
{ {
global $bb_cfg; global $bb_cfg;
@ -261,11 +260,11 @@ class BBCode
/** /**
* Callback to escape titles in block elements * Callback to escape titles in block elements
* *
* @param string $m * @param array $m
* *
* @return string * @return string
*/ */
private function escape_titles_callback($m): string private function escape_titles_callback(array $m): string
{ {
$title = substr($m[3], 0, 250); $title = substr($m[3], 0, 250);
$title = str_replace(['[', ']', ':', ')', '"'], ['[', ']', ':', ')', '"'], $title); $title = str_replace(['[', ']', ':', ')', '"'], ['[', ']', ':', ')', '"'], $title);
@ -281,7 +280,7 @@ class BBCode
* *
* @return string * @return string
*/ */
private function make_clickable($text): string private function make_clickable(string $text): string
{ {
$url_regexp = "# $url_regexp = "#
(?<![\"'=]) (?<![\"'=])
@ -311,11 +310,11 @@ class BBCode
/** /**
* Callback to make URL clickable * Callback to make URL clickable
* *
* @param string $m * @param array $m
* *
* @return string * @return string
*/ */
private function make_url_clickable_callback($m): string private function make_url_clickable_callback(array $m): string
{ {
global $bb_cfg; global $bb_cfg;
@ -339,9 +338,9 @@ class BBCode
* *
* @return string * @return string
*/ */
private function smilies_pass($text): string private function smilies_pass(string $text): string
{ {
global $bb_cfg, $datastore; global $datastore;
if (null === $this->smilies) { if (null === $this->smilies) {
$this->smilies = $datastore->get('smile_replacements'); $this->smilies = $datastore->get('smile_replacements');
@ -364,11 +363,10 @@ class BBCode
* *
* @return string * @return string
*/ */
private function new_line2html($text): string private function new_line2html(string $text): string
{ {
$text = preg_replace('#\n{2,}#', '<span class="post-br"><br /></span>', $text); $text = preg_replace('#\n{2,}#', '<span class="post-br"><br /></span>', $text);
$text = str_replace("\n", '<br />', $text); return str_replace("\n", '<br />', $text);
return $text;
} }
/** /**
@ -378,9 +376,8 @@ class BBCode
* *
* @return string * @return string
*/ */
private function tidy($text): string private function tidy(string $text): string
{ {
$text = tidy_repair_string($text, $this->tidy_cfg, 'utf8'); return tidy_repair_string($text, $this->tidy_cfg, 'utf8');
return $text;
} }
} }

View file

@ -219,12 +219,12 @@ class User
// Initial ban check // Initial ban check
if ($banInfo = getBanInfo((int)$this->id)) { if ($banInfo = getBanInfo((int)$this->id)) {
$this->session_end();
if (!empty($banInfo['ban_reason'])) { if (!empty($banInfo['ban_reason'])) {
bb_die($lang['YOU_BEEN_BANNED'] . '<br><br>' . $banInfo['ban_reason']); bb_die($lang['YOU_BEEN_BANNED'] . '<br><br>' . $lang['REASON'] . ':&nbsp;' . '<b>' . $banInfo['ban_reason'] . '</b>');
} else { } else {
bb_die($lang['YOU_BEEN_BANNED']); bb_die($lang['YOU_BEEN_BANNED']);
} }
$this->session_end();
} }
return $this->data; return $this->data;

View file

@ -939,7 +939,7 @@ class SqlDb
$msg[] = 'PID : ' . sprintf('%05d', getmypid()); $msg[] = 'PID : ' . sprintf('%05d', getmypid());
$msg[] = 'Request : ' . trim(print_r($_REQUEST, true)) . str_repeat('_', 78) . LOG_LF; $msg[] = 'Request : ' . trim(print_r($_REQUEST, true)) . str_repeat('_', 78) . LOG_LF;
$msg[] = ''; $msg[] = '';
bb_log($msg, IN_TRACKER ? SQL_TR_LOG_NAME : SQL_BB_LOG_NAME); bb_log($msg, (defined('IN_TRACKER') ? SQL_TR_LOG_NAME : SQL_BB_LOG_NAME));
} }
/** /**

View file

@ -34,7 +34,7 @@
<td class="row2"><input type="text" size="3" maxlength="4" name="img_link_width" value="{IMAGE_LINK_WIDTH}" class="post" /> x <input type="text" size="3" maxlength="4" name="img_link_height" value="{IMAGE_LINK_HEIGHT}" class="post" /></td> <td class="row2"><input type="text" size="3" maxlength="4" name="img_link_width" value="{IMAGE_LINK_WIDTH}" class="post" /> x <input type="text" size="3" maxlength="4" name="img_link_height" value="{IMAGE_LINK_HEIGHT}" class="post" /></td>
</tr> </tr>
<tr> <tr>
<td class="catBottom" colspan="2">{S_HIDDEN_FIELDS}<input type="submit" name="submit" value="{L_SUBMIT}" class="mainoption" />&nbsp;&nbsp;<input type="reset" value="{L_RESET}" class="liteoption" />&nbsp;&nbsp;<input type="submit" name="search_imagick" value="{L_IMAGE_SEARCH_IMAGICK}" class="liteoption" />&nbsp;&nbsp;<input type="submit" name="cat_settings" value="{L_TEST_SETTINGS}" class="liteoption" /></td> <td class="catBottom" colspan="2">{S_HIDDEN_FIELDS}<input type="submit" name="submit" value="{L_SUBMIT}" class="mainoption" />&nbsp;&nbsp;<input type="reset" value="{L_RESET}" class="liteoption" />&nbsp;&nbsp;<input type="submit" name="cat_settings" value="{L_TEST_SETTINGS}" class="liteoption" /></td>
</tr> </tr>
</table> </table>
</form> </form>