Merge branch 'master' into Some-enhancements-in-default-template-(Part-2)

This commit is contained in:
Roman Kelesidis 2024-01-21 02:08:47 +07:00 committed by GitHub
commit 6febbe07b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 146 additions and 57 deletions

View file

@ -6,14 +6,18 @@
**Merged pull requests:**
- Release 2.4.1 🦉 ([belomaxorka](https://github.com/belomaxorka), [kovalensky](https://github.com/kovalensky))
- Added support for fastly cdn [\#1327](https://github.com/torrentpier/torrentpier/pull/1327) ([belomaxorka](https://github.com/belomaxorka), [kovalensky](https://github.com/kovalensky))
- Used declensions for days in some cases [\#1310](https://github.com/torrentpier/torrentpier/pull/1310) ([belomaxorka](https://github.com/belomaxorka))
- Used datastore to show statistic for more performance [\#1309](https://github.com/torrentpier/torrentpier/pull/1309) ([belomaxorka](https://github.com/belomaxorka))
- Used `humn_size()` to count average of releases in tr_stats.php [\#1313](https://github.com/torrentpier/torrentpier/pull/1313) ([belomaxorka](https://github.com/belomaxorka))
- Some enhancements in default template [\#1312](https://github.com/torrentpier/torrentpier/pull/1312) ([belomaxorka](https://github.com/belomaxorka))
- Some enhancements in default template (Part 2) [\#1322](https://github.com/torrentpier/torrentpier/pull/1322) ([belomaxorka](https://github.com/belomaxorka))
- Set response code in some cases [\#1319](https://github.com/torrentpier/torrentpier/pull/1319) ([belomaxorka](https://github.com/belomaxorka))
- Fixed auth(): empty $f_access [\#1329](https://github.com/torrentpier/torrentpier/pull/1329) ([belomaxorka](https://github.com/belomaxorka))
- Fixed HTTP 500 while cron running in server-side [\#1321](https://github.com/torrentpier/torrentpier/pull/1321) ([belomaxorka](https://github.com/belomaxorka))
- Minor improvements [\#1306](https://github.com/torrentpier/torrentpier/pull/1306), [\#1307](https://github.com/torrentpier/torrentpier/pull/1307), [\#1308](https://github.com/torrentpier/torrentpier/pull/1308), [\#1315](https://github.com/torrentpier/torrentpier/pull/1315) ([belomaxorka](https://github.com/belomaxorka))
- Sending debug errors to us 🌚 via Telegram bot [\#1323](https://github.com/torrentpier/torrentpier/pull/1323) ([belomaxorka](https://github.com/belomaxorka))
- Minor improvements [\#1306](https://github.com/torrentpier/torrentpier/pull/1306), [\#1307](https://github.com/torrentpier/torrentpier/pull/1307), [\#1308](https://github.com/torrentpier/torrentpier/pull/1308), [\#1315](https://github.com/torrentpier/torrentpier/pull/1315), [\#1328](https://github.com/torrentpier/torrentpier/pull/1328) ([belomaxorka](https://github.com/belomaxorka))
- Some bugfixes [\#1326](https://github.com/torrentpier/torrentpier/pull/1326) ([belomaxorka](https://github.com/belomaxorka))
- Updated deps [\#1304](https://github.com/torrentpier/torrentpier/pull/1304), [\#1305](https://github.com/torrentpier/torrentpier/pull/1305) ([belomaxorka](https://github.com/belomaxorka))
## [v2.4.0](https://github.com/torrentpier/torrentpier/tree/v2.4.0) (2024-01-01)

View file

@ -64,13 +64,12 @@ if (!isset($_REQUEST['dosearch'])) {
}
$forums = [];
$last_cat_id = -1;
$forums_list = '';
if (DB()->num_rows($result) != 0) {
$template->assign_block_vars('forums_exist', []);
$last_cat_id = -1;
$forums_list = '';
while ($row = DB()->sql_fetchrow($result)) {
if ($row['cat_id'] != $last_cat_id) {
$forums_list .= '<optgroup label="' . htmlCHR($row['cat_title']) . '">';

View file

@ -41,9 +41,12 @@ if (!defined('BB_SCRIPT')) {
header('X-Frame-Options: SAMEORIGIN');
date_default_timezone_set('UTC');
// Cloudflare
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
// Set remote address
$allowedCDNs = ['HTTP_X_FORWARDED_FOR', 'HTTP_FASTLY_CLIENT_IP', 'HTTP_CF_CONNECTING_IP'];
foreach ($allowedCDNs as $allowedCDN) {
if (isset($_SERVER[$allowedCDN]) && filter_var($_SERVER[$allowedCDN], FILTER_VALIDATE_IP)) {
$_SERVER['REMOTE_ADDR'] = $_SERVER[$allowedCDN];
}
}
// Get all constants

View file

@ -37,15 +37,15 @@
},
"require": {
"php": "^8.1",
"ext-mysqli": "*",
"ext-mbstring": "*",
"ext-json": "*",
"ext-bcmath": "*",
"ext-ctype": "*",
"ext-curl": "*",
"ext-intl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-mysqli": "*",
"ext-xml": "*",
"ext-xmlwriter": "*",
"ext-curl": "*",
"ext-ctype": "*",
"arokettu/bencode": "^4.1.0",
"bugsnag/bugsnag": "^v3.29.1",
"claviska/simpleimage": "^4.0",
@ -53,6 +53,7 @@
"filp/whoops": "^2.15",
"gigablah/sphinxphp": "2.0.8",
"google/recaptcha": "^1.3",
"jacklul/monolog-telegram": "^3.1",
"josantonius/cookie": "^2.0",
"longman/ip-tools": "1.2.1",
"monolog/monolog": "^3.4",

76
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "29829118bcf2c44f41d12e79091d79e6",
"content-hash": "3e19fe76f513cea154195f8eb132bfa0",
"packages": [
{
"name": "arokettu/bencode",
@ -1037,6 +1037,67 @@
],
"time": "2023-12-03T20:05:35+00:00"
},
{
"name": "jacklul/monolog-telegram",
"version": "3.1.0",
"source": {
"type": "git",
"url": "https://github.com/jacklul/monolog-telegram.git",
"reference": "ec8674fbd280bbb369b5f48447259e44a92f39c8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jacklul/monolog-telegram/zipball/ec8674fbd280bbb369b5f48447259e44a92f39c8",
"reference": "ec8674fbd280bbb369b5f48447259e44a92f39c8",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-mbstring": "*",
"monolog/monolog": "^3.0",
"php": "^8.1"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "^3.2",
"vlucas/phpdotenv": "^5.0"
},
"suggest": {
"ext-curl": "cURL generally works better and is recommended"
},
"type": "library",
"autoload": {
"psr-4": {
"jacklul\\MonologTelegramHandler\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jack'lul",
"email": "jacklulcat@gmail.com",
"homepage": "https://jacklul.github.io",
"role": "Developer"
}
],
"description": "Monolog handler that sends logs through Telegram bot to any chat in HTML format",
"keywords": [
"bot",
"log",
"logging",
"monolog",
"telegram"
],
"support": {
"issues": "https://github.com/jacklul/monolog-telegram/issues",
"source": "https://github.com/jacklul/monolog-telegram"
},
"time": "2023-11-21T18:26:36+00:00"
},
{
"name": "josantonius/cookie",
"version": "v2.0.6",
@ -2957,15 +3018,16 @@
"prefer-lowest": false,
"platform": {
"php": "^8.1",
"ext-mysqli": "*",
"ext-mbstring": "*",
"ext-json": "*",
"ext-bcmath": "*",
"ext-ctype": "*",
"ext-curl": "*",
"ext-intl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-mysqli": "*",
"ext-xml": "*",
"ext-xmlwriter": "*",
"ext-curl": "*"
"ext-xmlwriter": "*"
},
"platform-dev": [],
"plugin-api-version": "2.6.0"
"plugin-api-version": "2.3.0"
}

View file

@ -245,25 +245,3 @@ function search_attachments($order_by, &$total_rows)
return $attachments;
}
/**
* Perform limit statement on arrays
*
* @param $array
* @param $start
* @param $pagelimit
* @return array
*/
function limit_array($array, $start, $pagelimit)
{
// array from start - start+pagelimit
$limit = (count($array) < ($start + $pagelimit)) ? count($array) : $start + $pagelimit;
$limit_array = [];
for ($i = $start; $i < $limit; $i++) {
$limit_array[] = $array[$i];
}
return $limit_array;
}

View file

@ -13,6 +13,12 @@ if (!defined('BB_ROOT')) {
// System
define('APP_NAME', 'TorrentPier');
define('DEBUG_TELEGRAM_SENDER', [
// Send bug reports to developers
// Better not turn it off! But you can turn it off anyway for privacy reasons (It's easy, just remove this constant)
'token' => '5956771201:AAFQZ4edS475VWdfdbeSuAvBnhzHnhg-hCc',
'chat_id' => 669508248
]);
// Path (trailing slash '/' at the end: XX_PATH - without, XX_DIR - with)
define('ADMIN_DIR', BB_PATH . '/admin');

View file

@ -269,6 +269,14 @@ function auth($type, $forum_id, $ug_data, array $f_access = [], $group_perm = UG
$auth = $auth_fields = $u_access = [];
$add_auth_type_desc = ($forum_id != AUTH_LIST_ALL);
// Check forum existence
if (!forum_exists()) {
return [];
}
if ($add_auth_type_desc && !forum_exists($forum_id)) {
return [];
}
//
// Get $auth_fields
//
@ -304,7 +312,7 @@ function auth($type, $forum_id, $ug_data, array $f_access = [], $group_perm = UG
}
if (empty($f_access)) {
return [];
trigger_error(__FUNCTION__ . '(): empty $f_access', E_USER_ERROR);
}
//
@ -1824,8 +1832,12 @@ function get_topic_title($topic_id)
return $row['topic_title'];
}
function forum_exists($forum_id): bool
function forum_exists($forum_id = null): bool
{
if (!isset($forum_id)) {
return (bool)DB()->fetch_row("SELECT * FROM " . BB_FORUMS . " LIMIT 1");
}
return (bool)DB()->fetch_row("SELECT forum_id FROM " . BB_FORUMS . " WHERE forum_id = $forum_id LIMIT 1");
}

View file

@ -21,6 +21,9 @@ use Whoops\Handler\PlainTextHandler;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run;
use jacklul\MonologTelegramHandler\TelegramHandler;
use jacklul\MonologTelegramHandler\TelegramFormatter;
use Exception;
/**
@ -92,7 +95,11 @@ class Dev
*/
$loggingInConsole = new PlainTextHandler();
$loggingInConsole->loggerOnly(true);
$loggingInConsole->setLogger((new Logger(APP_NAME, [(new BrowserConsoleHandler())->setFormatter((new LineFormatter(null, null, true)))])));
$loggingInConsole->setLogger((new Logger(
APP_NAME,
[(new BrowserConsoleHandler())
->setFormatter((new LineFormatter(null, null, true)))]
)));
$whoops->pushHandler($loggingInConsole);
/**
@ -101,10 +108,28 @@ class Dev
if (ini_get('log_errors') == 1) {
$loggingInFile = new PlainTextHandler();
$loggingInFile->loggerOnly(true);
$loggingInFile->setLogger((new Logger(APP_NAME, [(new StreamHandler(WHOOPS_LOG_FILE))->setFormatter((new LineFormatter(null, null, true)))])));
$loggingInFile->setLogger((new Logger(
APP_NAME,
[(new StreamHandler(WHOOPS_LOG_FILE))
->setFormatter((new LineFormatter(null, null, true)))]
)));
$whoops->pushHandler($loggingInFile);
}
/**
* Send debug to us :D
*/
if (defined('DEBUG_TELEGRAM_SENDER') && is_array(DEBUG_TELEGRAM_SENDER)) {
$telegramSender = new PlainTextHandler();
$telegramSender->loggerOnly(true);
$telegramSender->setLogger((new Logger(
APP_NAME,
[(new TelegramHandler(DEBUG_TELEGRAM_SENDER['token'], DEBUG_TELEGRAM_SENDER['chat_id']))
->setFormatter(new TelegramFormatter())]
)));
$whoops->pushHandler($telegramSender);
}
$whoops->register();
}

View file

@ -727,9 +727,9 @@ class User
* @param $auth_type
* @param string $return_as
*
* @return array|bool|string
* @return array|string
*/
public function get_excluded_forums($auth_type, $return_as = 'csv')
public function get_excluded_forums($auth_type, string $return_as = 'csv')
{
$excluded = [];
@ -754,14 +754,13 @@ class User
}
}
switch ($return_as) {
case 'csv':
return implode(',', $excluded);
case 'array':
return $excluded;
case 'flip':
return array_flip(explode(',', $excluded));
}
return match ($return_as) {
'csv' => implode(',', $excluded),
'flip_csv' => implode(',', array_flip($excluded)),
'array' => $excluded,
'flip' => array_flip($excluded),
default => [],
};
}
/**

View file

@ -843,7 +843,7 @@ class Torrent
* @param int|string $user_id
* @return bool|string
*/
public static function getPasskey($user_id)
public static function getPasskey(int|string $user_id): bool|string
{
if ($passkey = DB()->fetch_row("SELECT auth_key FROM " . BB_BT_USERS . " WHERE user_id = " . (int)$user_id . " LIMIT 1")) {
return $passkey['auth_key'];

View file

@ -398,7 +398,7 @@ ajax.callback.index_data = function(data) {
<!-- IF SHOW_PASSKEY -->
[ {L_BT_PASSKEY}: <span id="passkey-btn"><a class="med" href="#" onclick="$('#passkey-gen').show(); $('#passkey-btn').hide(); return false;">{L_BT_PASSKEY_VIEW}</a></span>
<span id="passkey-gen" class="med" style="display: none;">
<b id="passkey" class="med bold">{AUTH_KEY}</b>&nbsp;|&nbsp;<a href="#" onclick="ajax.exec({ action: 'passkey', mode: 'generate', user_id : {PROFILE_USER_ID} }); return false;">{L_BT_GEN_PASSKEY}</a>
<b id="passkey" class="med bold"><!-- IF AUTH_KEY -->{AUTH_KEY}<!-- ELSE -->{L_NOSELECT}<!-- ENDIF --></b>&nbsp;|&nbsp;<a href="#" onclick="ajax.exec({ action: 'passkey', mode: 'generate', user_id : {PROFILE_USER_ID} }); return false;">{L_BT_GEN_PASSKEY}</a>
</span> ]
<!-- ENDIF -->
</td>