Minor improvements (#1306)

* Minor improvements

* Update functions.php

* Updated

* Updated

* Update edit_user_profile.php

* Update index_data.php

* Update

* Update sitemap.php
This commit is contained in:
Roman Kelesidis 2024-01-02 21:18:54 +07:00 committed by GitHub
commit 36e52d5d3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 67 additions and 64 deletions

View file

@ -190,7 +190,7 @@ function file_write($str, $file, $max_size = LOG_MAX_SIZE, $lock = true, $replac
$bytes_written = false;
clearstatcache();
if (is_file($file) && ($max_size && filesize($file) >= $max_size)) {
if (is_file($file) && ($max_size && (filesize($file) >= $max_size))) {
$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();
@ -198,6 +198,7 @@ function file_write($str, $file, $max_size = LOG_MAX_SIZE, $lock = true, $replac
rename($file, $new_name);
}
}
clearstatcache();
if (bb_mkdir(dirname($file))) {
if ($fp = fopen($file, 'ab+')) {

View file

@ -45,6 +45,7 @@
"ext-xml": "*",
"ext-xmlwriter": "*",
"ext-curl": "*",
"ext-ctype": "*",
"arokettu/bencode": "^4.1.0",
"bugsnag/bugsnag": "^v3.29.1",
"claviska/simpleimage": "^4.0",

View file

@ -17,7 +17,12 @@ if ($bb_cfg['bt_disable_dht'] && IS_GUEST) {
bb_simple_die($lang['BT_PRIVATE_TRACKER']);
}
$topic_id = !empty($_GET['topic']) ? (int)$_GET['topic'] : (http_response_code(404) && die($lang['INVALID_TOPIC_ID']));
$topic_id = !empty($_GET['topic']) ? (int)$_GET['topic'] : false;
if (!$topic_id) {
http_response_code(404);
bb_simple_die($lang['INVALID_TOPIC_ID']);
}
$sql = 'SELECT t.attach_id, t.info_hash, t.info_hash_v2, t.size, ad.physical_filename
FROM ' . BB_BT_TORRENTS . ' t
@ -30,7 +35,7 @@ $row = DB()->fetch_row($sql);
if (empty($row) || empty($row['physical_filename'])) {
http_response_code(404);
bb_simple_die($lang['TOPIC_POST_NOT_EXIST']);
bb_simple_die($lang['INVALID_TOPIC_ID_DB']);
}
if (empty($row['info_hash_v2'])) {

View file

@ -13,9 +13,11 @@ if (!defined('IN_AJAX')) {
global $bb_cfg, $lang, $user;
$mode = (string)$this->request['mode'];
$user_id = (int)$this->request['user_id'];
if (!$mode = (string)$this->request['mode']) {
$this->ajax_die('invalid mode (empty)');
}
$user_id = (int)$this->request['user_id'];
if (!$user_id or !$u_data = get_userdata($user_id)) {
$this->ajax_die($lang['NO_USER_ID_SPECIFIED']);
}
@ -33,7 +35,7 @@ switch ($mode) {
$response = get_avatar($user_id, $new_ext_id);
break;
default:
$this->ajax_die('Invalid mode');
$this->ajax_die('Invalid mode: ' . $mode);
}
DB()->query("UPDATE " . BB_USERS . " SET avatar_ext_id = $new_ext_id WHERE user_id = $user_id LIMIT 1");

View file

@ -16,6 +16,7 @@ global $bb_cfg, $lang;
if (!$user_id = (int)$this->request['user_id'] or !$profiledata = get_userdata($user_id)) {
$this->ajax_die($lang['NO_USER_ID_SPECIFIED']);
}
if (!$field = (string)$this->request['field']) {
$this->ajax_die('invalid profile field');
}

View file

@ -13,9 +13,11 @@ if (!defined('IN_AJAX')) {
global $bb_cfg, $lang, $userdata, $datastore;
$mode = (string)$this->request['mode'];
$html = '';
if (!$mode = (string)$this->request['mode']) {
$this->ajax_die('invalid mode (empty)');
}
$html = '';
switch ($mode) {
case 'birthday_week':
$stats = $datastore->get('stats');
@ -122,7 +124,7 @@ switch ($mode) {
break;
default:
$this->ajax_die('Invalid mode');
$this->ajax_die('Invalid mode: ' . $mode);
}
$this->response['html'] = $html;

View file

@ -95,7 +95,7 @@ switch ($mode) {
break;
default:
$this->ajax_die('Invalid mode');
$this->ajax_die('Invalid mode: ' . $mode);
}
$this->response['mode'] = $mode;

View file

@ -13,27 +13,31 @@ if (!defined('IN_AJAX')) {
global $userdata, $lang;
$req_uid = (int)$this->request['user_id'];
$mode = (string)$this->request['mode'];
if (!$mode = (string)$this->request['mode']) {
$this->ajax_die('invalid mode (empty)');
}
if ($req_uid == $userdata['user_id'] || IS_ADMIN) {
switch ($mode) {
case 'generate':
if (empty($this->request['confirmed'])) {
$this->prompt_for_confirm($lang['BT_GEN_PASSKEY_NEW']);
}
if (!$req_uid = (int)$this->request['user_id']) {
$this->ajax_die($lang['NO_USER_ID_SPECIFIED']);
}
if (!$passkey = \TorrentPier\Legacy\Torrent::generate_passkey($req_uid, IS_ADMIN)) {
$this->ajax_die('Could not insert passkey');
}
\TorrentPier\Legacy\Torrent::tracker_rm_user($req_uid);
$this->response['passkey'] = $passkey;
break;
default:
$this->ajax_die('Invalid mode');
}
} else {
if (!IS_ADMIN && $req_uid != $userdata['user_id']) {
$this->ajax_die($lang['NOT_AUTHORISED']);
}
switch ($mode) {
case 'generate':
if (empty($this->request['confirmed'])) {
$this->prompt_for_confirm($lang['BT_GEN_PASSKEY_NEW']);
}
if (!$passkey = \TorrentPier\Legacy\Torrent::generate_passkey($req_uid, IS_ADMIN)) {
$this->ajax_die('Could not insert passkey');
}
\TorrentPier\Legacy\Torrent::tracker_rm_user($req_uid);
$this->response['passkey'] = $passkey;
break;
default:
$this->ajax_die('Invalid mode: ' . $mode);
}

View file

@ -18,8 +18,8 @@ if (!$mode = (string)$this->request['mode']) {
}
$map = new TorrentPier\Sitemap();
$html = '';
$html = '';
switch ($mode) {
case 'create':
$map->createSitemap();

View file

@ -17,8 +17,13 @@ if (!$bb_cfg['tor_thank']) {
$this->ajax_die($lang['MODULE_OFF']);
}
$mode = (string)$this->request['mode'];
$topic_id = (int)$this->request['topic_id'];
if (!$mode = (string)$this->request['mode']) {
$this->ajax_die('invalid mode (empty)');
}
if (!$topic_id = (int)$this->request['topic_id']) {
$this->ajax_die($lang['INVALID_TOPIC_ID']);
}
switch ($mode) {
case 'add':
@ -47,7 +52,7 @@ switch ($mode) {
break;
default:
$this->ajax_die('Invalid mode');
$this->ajax_die('Invalid mode: ' . $mode);
}
$this->response['mode'] = $mode;

View file

@ -48,7 +48,7 @@ switch ($mode) {
break;
default:
$this->ajax_die('Invalid mode');
$this->ajax_die('Invalid mode: ' . $mode);
}
$this->response['html'] = $html;

View file

@ -599,7 +599,7 @@ function bt_show_ip($ip, $port = '')
return $ip;
}
return ($bb_cfg['bt_show_ip_only_moder']) ? false : \TorrentPier\Helpers\IPHelper::anonymizeIP($ip);
return $bb_cfg['bt_show_ip_only_moder'] ? false : \TorrentPier\Helpers\IPHelper::anonymizeIP($ip);
}
function bt_show_port($port)
@ -610,7 +610,7 @@ function bt_show_port($port)
return $port;
}
return ($bb_cfg['bt_show_port_only_moder']) ? false : $port;
return $bb_cfg['bt_show_port_only_moder'] ? false : $port;
}
function checkbox_get_val(&$key, &$val, $default = 1, $on = 1, $off = 0)
@ -843,7 +843,7 @@ function get_bt_userdata($user_id)
return $btu;
}
function get_bt_ratio($btu)
function get_bt_ratio($btu): ?float
{
return
(!empty($btu['u_down_total']) && $btu['u_down_total'] > MIN_DL_FOR_RATIO)
@ -851,7 +851,7 @@ function get_bt_ratio($btu)
: null;
}
function show_bt_userdata($user_id)
function show_bt_userdata($user_id): void
{
global $template;
@ -1672,7 +1672,7 @@ function obtain_word_list(&$orig_word, &$replacement_word)
function bb_die($msg_text)
{
global $ajax, $bb_cfg, $lang, $template, $theme, $userdata;
global $ajax, $bb_cfg, $lang, $template, $theme, $userdata, $user;
if (defined('IN_AJAX')) {
$ajax->ajax_die($msg_text);
@ -1692,7 +1692,7 @@ function bb_die($msg_text)
// If empty session
if (empty($userdata)) {
$userdata = \TorrentPier\Sessions::session_pagestart();
$userdata = $user->session_start();
}
// If the header hasn't been output then do it

View file

@ -32,7 +32,7 @@ class Sessions
*
* @return bool|array
*/
public static function cache_get_userdata(string $id)
public static function cache_get_userdata(string $id): bool|array
{
if (self::ignore_cached_userdata()) {
return false;
@ -81,9 +81,9 @@ class Sessions
/**
* Delete user sessions from cache
*
* @param string|int $user_id
* @param int|string $user_id
*/
public static function cache_rm_user_sessions($user_id)
public static function cache_rm_user_sessions(int|string $user_id): void
{
$user_id = get_id_csv(explode(',', (string)$user_id));
@ -134,31 +134,13 @@ class Sessions
/**
* Delete user sessions from cache and database
*
* @param string|int $user_id
* @param int|string $user_id
*/
public static function delete_user_sessions($user_id)
public static function delete_user_sessions(int|string $user_id): void
{
self::cache_rm_user_sessions($user_id);
$user_id = get_id_csv(explode(',', (string)$user_id));
DB()->query("DELETE FROM " . BB_SESSIONS . " WHERE session_user_id IN($user_id)");
}
/**
* Start user session on page header
* @param string $user_ip
* @param int $page_id
* @param bool $req_login
*
* @return array
* @deprecated
*/
public static function session_pagestart($user_ip = USER_IP, $page_id = 0, bool $req_login = false): array
{
global $user;
$user->session_start(['req_login' => $req_login]);
return $user->data;
}
}