Use DEFAULT_CHARSET constant instead of hardcoded string (#1734)

* Use `DEFAULT_CHARSET` constant instead of hardcoded string

* Update CHANGELOG.md

* Update defines.php

* Update info.php

* Updated

* Update page_header.tpl

* Update index.tpl

* Update index.tpl
This commit is contained in:
Roman Kelesidis 2025-01-05 00:57:20 +07:00 committed by GitHub
commit e5aaaf4abd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 35 additions and 33 deletions

View file

@ -10,6 +10,7 @@
- Added `m4a` extension support in M3U playback [\#1724](https://github.com/torrentpier/torrentpier/pull/1724) ([belomaxorka](https://github.com/belomaxorka)) - Added `m4a` extension support in M3U playback [\#1724](https://github.com/torrentpier/torrentpier/pull/1724) ([belomaxorka](https://github.com/belomaxorka))
- Created `VersionHelper.php` [\#1731](https://github.com/torrentpier/torrentpier/pull/1731) ([belomaxorka](https://github.com/belomaxorka)) - Created `VersionHelper.php` [\#1731](https://github.com/torrentpier/torrentpier/pull/1731) ([belomaxorka](https://github.com/belomaxorka))
- Drop Ocelot announcer support 🫡 [\#1727](https://github.com/torrentpier/torrentpier/pull/1727) ([belomaxorka](https://github.com/belomaxorka)) - Drop Ocelot announcer support 🫡 [\#1727](https://github.com/torrentpier/torrentpier/pull/1727) ([belomaxorka](https://github.com/belomaxorka))
- Use `DEFAULT_CHARSET` constant instead of hardcoded string [\#1734](https://github.com/torrentpier/torrentpier/pull/1734) ([belomaxorka](https://github.com/belomaxorka))
- Replaced some `html_entity_decode` to engine's built-in function [\#1733](https://github.com/torrentpier/torrentpier/pull/1733) ([belomaxorka](https://github.com/belomaxorka)) - Replaced some `html_entity_decode` to engine's built-in function [\#1733](https://github.com/torrentpier/torrentpier/pull/1733) ([belomaxorka](https://github.com/belomaxorka))
- Show torrent's announcers list in `filelist.php` page [\#1708](https://github.com/torrentpier/torrentpier/pull/1708) ([belomaxorka](https://github.com/belomaxorka)) - Show torrent's announcers list in `filelist.php` page [\#1708](https://github.com/torrentpier/torrentpier/pull/1708) ([belomaxorka](https://github.com/belomaxorka))
- [PHP 8.4] Fixed some deprecations [\#1718](https://github.com/torrentpier/torrentpier/pull/1718) ([belomaxorka](https://github.com/belomaxorka)) - [PHP 8.4] Fixed some deprecations [\#1718](https://github.com/torrentpier/torrentpier/pull/1718) ([belomaxorka](https://github.com/belomaxorka))

View file

@ -234,7 +234,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
} else { } else {
// Generate frameset // Generate frameset
$template->assign_vars([ $template->assign_vars([
'CONTENT_ENCODING' => $bb_cfg['charset'], 'CONTENT_ENCODING' => DEFAULT_CHARSET,
'TPL_ADMIN_FRAMESET' => true, 'TPL_ADMIN_FRAMESET' => true,
]); ]);
send_no_cache_headers(); send_no_cache_headers();

View file

@ -239,7 +239,7 @@ function clean_filename($fname)
* @param ?string $charset * @param ?string $charset
* @return string * @return string
*/ */
function htmlCHR($txt, bool $double_encode = false, int $quote_style = ENT_QUOTES, ?string $charset = 'UTF-8'): string function htmlCHR($txt, bool $double_encode = false, int $quote_style = ENT_QUOTES, ?string $charset = DEFAULT_CHARSET): string
{ {
return (string)htmlspecialchars($txt ?? '', $quote_style, $charset, $double_encode); return (string)htmlspecialchars($txt ?? '', $quote_style, $charset, $double_encode);
} }

2
dl.php
View file

@ -53,7 +53,7 @@ function send_file_to_browser($attachment, $upload_dir)
header('Pragma: public'); header('Pragma: public');
$real_filename = clean_filename(basename($attachment['real_filename'])); $real_filename = clean_filename(basename($attachment['real_filename']));
$mimetype = $attachment['mimetype'] . ';'; $mimetype = $attachment['mimetype'] . ';';
$charset = "charset={$bb_cfg['charset']};"; $charset = 'charset=' . DEFAULT_CHARSET . ';';
// Send out the Headers // Send out the Headers
header("Content-Type: $mimetype $charset name=\"$real_filename\""); header("Content-Type: $mimetype $charset name=\"$real_filename\"");

View file

@ -43,7 +43,7 @@ switch ((string)$_REQUEST['show'] ?? 'not_found') {
$require = is_file($htmlDir . $info['src']) ? ($htmlDir . $info['src']) : false; $require = is_file($htmlDir . $info['src']) ? ($htmlDir . $info['src']) : false;
$template->assign_vars([ $template->assign_vars([
'PAGE_TITLE' => mb_strtoupper($info['title'], 'UTF-8'), 'PAGE_TITLE' => mb_strtoupper($info['title'], DEFAULT_CHARSET),
'REQUIRE' => $require ? file_get_contents($require) : $lang['NOT_FOUND'], 'REQUIRE' => $require ? file_get_contents($require) : $lang['NOT_FOUND'],
]); ]);

View file

@ -57,15 +57,15 @@ if (isset($ffpInfo->streams)) {
$result = '<span class="warnColor2">' . sprintf($lang['AUDIO_TRACK'], (!isset($stream->index) || $stream->index === 0) ? 1 : $stream->index) . '</span><br/>'; $result = '<span class="warnColor2">' . sprintf($lang['AUDIO_TRACK'], (!isset($stream->index) || $stream->index === 0) ? 1 : $stream->index) . '</span><br/>';
if (isset($stream->tags->language)) { if (isset($stream->tags->language)) {
if (isset($stream->tags->title)) { if (isset($stream->tags->title)) {
$result .= '<b>' . mb_strtoupper($stream->tags->language, 'UTF-8') . ' (' . $stream->tags->title . ')' . '</b>'; $result .= '<b>' . mb_strtoupper($stream->tags->language, DEFAULT_CHARSET) . ' (' . $stream->tags->title . ')' . '</b>';
} else { } else {
$result .= '<b>' . mb_strtoupper($stream->tags->language, 'UTF-8') . '</b>'; $result .= '<b>' . mb_strtoupper($stream->tags->language, DEFAULT_CHARSET) . '</b>';
} }
$result .= '<br/>'; $result .= '<br/>';
} }
if (!empty($stream->codec_name)) { if (!empty($stream->codec_name)) {
$result .= sprintf($lang['AUDIO_CODEC'], $stream->codec_long_name, mb_strtoupper($stream->codec_name, 'UTF-8')) . '<br/>'; $result .= sprintf($lang['AUDIO_CODEC'], $stream->codec_long_name, mb_strtoupper($stream->codec_name, DEFAULT_CHARSET)) . '<br/>';
} }
if (!empty($stream->bit_rate)) { if (!empty($stream->bit_rate)) {
$result .= sprintf($lang['BITRATE'], humn_bitrate((int)$stream->bit_rate)) . '<br/>'; $result .= sprintf($lang['BITRATE'], humn_bitrate((int)$stream->bit_rate)) . '<br/>';
@ -87,7 +87,7 @@ if (isset($ffpInfo->streams)) {
$data = [ $data = [
'filesize' => sprintf($lang['FILESIZE'] . ': <b>%s</b>', humn_size($ffpInfo->format->size)), 'filesize' => sprintf($lang['FILESIZE'] . ': <b>%s</b>', humn_size($ffpInfo->format->size)),
'resolution' => (!$isAudio && isset($videoCodecInfo)) ? sprintf($lang['RESOLUTION'], $videoCodecInfo->width . 'x' . $videoCodecInfo->height) : '', 'resolution' => (!$isAudio && isset($videoCodecInfo)) ? sprintf($lang['RESOLUTION'], $videoCodecInfo->width . 'x' . $videoCodecInfo->height) : '',
'video_codec' => (!$isAudio && isset($videoCodecInfo->codec_name)) ? sprintf($lang['VIDEO_CODEC'], $videoCodecInfo->codec_long_name, mb_strtoupper($videoCodecInfo->codec_name, 'UTF-8')) : '', 'video_codec' => (!$isAudio && isset($videoCodecInfo->codec_name)) ? sprintf($lang['VIDEO_CODEC'], $videoCodecInfo->codec_long_name, mb_strtoupper($videoCodecInfo->codec_name, DEFAULT_CHARSET)) : '',
'audio_dub' => implode('<hr/>', $audioDub) 'audio_dub' => implode('<hr/>', $audioDub)
]; ];

View file

@ -85,7 +85,7 @@ switch ($this->request['type']) {
if ($post['post_id'] == $post['topic_first_post_id']) { if ($post['post_id'] == $post['topic_first_post_id']) {
$message = "[quote]" . $post['topic_title'] . "[/quote]\r"; $message = "[quote]" . $post['topic_title'] . "[/quote]\r";
} }
if (mb_strlen($message, 'UTF-8') > 1000) { if (mb_strlen($message, DEFAULT_CHARSET) > 1000) {
$this->response['redirect'] = make_url(POSTING_URL . '?mode=quote&' . POST_POST_URL . '=' . $post_id); $this->response['redirect'] = make_url(POSTING_URL . '?mode=quote&' . POST_POST_URL . '=' . $post_id);
} }
@ -112,7 +112,7 @@ switch ($this->request['type']) {
if ($post['poster_id'] != $userdata['user_id'] && !$is_auth['auth_mod']) { if ($post['poster_id'] != $userdata['user_id'] && !$is_auth['auth_mod']) {
$this->ajax_die($lang['EDIT_OWN_POSTS']); $this->ajax_die($lang['EDIT_OWN_POSTS']);
} }
if ((mb_strlen($post['post_text'], 'UTF-8') > 1000) || $post['post_attachment'] || ($post['topic_first_post_id'] == $post_id)) { if ((mb_strlen($post['post_text'], DEFAULT_CHARSET) > 1000) || $post['post_attachment'] || ($post['topic_first_post_id'] == $post_id)) {
$this->response['redirect'] = make_url(POSTING_URL . '?mode=editpost&' . POST_POST_URL . '=' . $post_id); $this->response['redirect'] = make_url(POSTING_URL . '?mode=editpost&' . POST_POST_URL . '=' . $post_id);
} elseif ($this->request['type'] == 'editor') { } elseif ($this->request['type'] == 'editor') {
$text = (string)$this->request['text']; $text = (string)$this->request['text'];

View file

@ -170,7 +170,6 @@ $bb_cfg['posting_url'] = 'posting.php'; # "http://{$domain_name}/posting.php"
$bb_cfg['pm_url'] = 'privmsg.php'; # "http://{$domain_name}/privmsg.php" $bb_cfg['pm_url'] = 'privmsg.php'; # "http://{$domain_name}/privmsg.php"
// Language // Language
$bb_cfg['charset'] = 'UTF-8';
$bb_cfg['lang'] = [ $bb_cfg['lang'] = [
// Languages available for selecting // Languages available for selecting
'af' => [ 'af' => [

View file

@ -30,13 +30,16 @@ define('TEMPLATES_DIR', BB_PATH . '/styles/templates');
// System // System
define('APP_NAME', 'TorrentPier'); define('APP_NAME', 'TorrentPier');
define('DEFAULT_CHARSET', 'UTF-8');
define('UPDATER_URL', 'https://api.github.com/repos/torrentpier/torrentpier/releases'); define('UPDATER_URL', 'https://api.github.com/repos/torrentpier/torrentpier/releases');
define('UPDATER_FILE', INT_DATA_DIR . '/updater.json'); define('UPDATER_FILE', INT_DATA_DIR . '/updater.json');
define('API_IP_URL', 'https://freeipapi.com/api/json/');
define('CHECKSUMS_FILE', INT_DATA_DIR . '/checksums.md5'); define('CHECKSUMS_FILE', INT_DATA_DIR . '/checksums.md5');
define('RESTORE_CORRUPT_CONFIRM_FILE', INT_DATA_DIR . '/rescorrupt.integrity'); define('RESTORE_CORRUPT_CONFIRM_FILE', INT_DATA_DIR . '/rescorrupt.integrity');
define('COOKIE_DBG', 'bb_dbg'); define('COOKIE_DBG', 'bb_dbg');
// TODO: Move in another section
define('API_IP_URL', 'https://freeipapi.com/api/json/');
// Templates // Templates
define('ADMIN_TPL_DIR', TEMPLATES_DIR . '/admin/'); define('ADMIN_TPL_DIR', TEMPLATES_DIR . '/admin/');
define('XS_USE_ISSET', '1'); define('XS_USE_ISSET', '1');

View file

@ -772,13 +772,13 @@ function get_user_id($username)
function str_short($text, $max_length, $space = ' ') function str_short($text, $max_length, $space = ' ')
{ {
if (!empty($max_length) && !empty($text) && (mb_strlen($text, 'UTF-8') > $max_length)) { if (!empty($max_length) && !empty($text) && (mb_strlen($text, DEFAULT_CHARSET) > $max_length)) {
$text = mb_substr($text, 0, $max_length, 'UTF-8'); $text = mb_substr($text, 0, $max_length, DEFAULT_CHARSET);
if ($last_space_pos = $max_length - (int)strpos(strrev($text), (string)$space)) { if ($last_space_pos = $max_length - (int)strpos(strrev($text), (string)$space)) {
if ($last_space_pos > round($max_length * 3 / 4)) { if ($last_space_pos > round($max_length * 3 / 4)) {
$last_space_pos--; $last_space_pos--;
$text = mb_substr($text, 0, $last_space_pos, 'UTF-8'); $text = mb_substr($text, 0, $last_space_pos, DEFAULT_CHARSET);
} }
} }
$text .= '...'; $text .= '...';
@ -927,7 +927,7 @@ function bb_update_config($params, $table = BB_CONFIG)
function clean_username($username) function clean_username($username)
{ {
$username = mb_substr(htmlspecialchars(str_replace("\'", "'", trim($username))), 0, 25, 'UTF-8'); $username = mb_substr(htmlspecialchars(str_replace("\'", "'", trim($username))), 0, 25, DEFAULT_CHARSET);
$username = rtrim($username, "\\"); $username = rtrim($username, "\\");
$username = str_replace("'", "\'", $username); $username = str_replace("'", "\'", $username);
@ -1372,7 +1372,7 @@ function bb_simple_die($txt, $status_code = null)
{ {
global $bb_cfg; global $bb_cfg;
header('Content-Type: text/plain; charset=' . $bb_cfg['charset']); header('Content-Type: text/plain; charset=' . DEFAULT_CHARSET);
if (isset($status_code)) { if (isset($status_code)) {
http_response_code($status_code); http_response_code($status_code);
@ -2028,9 +2028,9 @@ function hash_search($hash)
$info_hash = DB()->escape(pack('H*', $hash)); $info_hash = DB()->escape(pack('H*', $hash));
// Check info_hash version // Check info_hash version
if (mb_strlen($hash, 'UTF-8') == 40) { if (mb_strlen($hash, DEFAULT_CHARSET) == 40) {
$info_hash_where = "WHERE info_hash = '$info_hash'"; $info_hash_where = "WHERE info_hash = '$info_hash'";
} elseif (mb_strlen($hash, 'UTF-8') == 64) { } elseif (mb_strlen($hash, DEFAULT_CHARSET) == 64) {
$info_hash_where = "WHERE info_hash_v2 = '$info_hash'"; $info_hash_where = "WHERE info_hash_v2 = '$info_hash'";
} else { } else {
bb_die(sprintf($lang['HASH_INVALID'], $hash)); bb_die(sprintf($lang['HASH_INVALID'], $hash));

View file

@ -364,7 +364,7 @@ function commify(?float $num, int $decimals = 0, ?string $decimal_separator = '.
* @param string $encoding * @param string $encoding
* @return string * @return string
*/ */
function html_ent_decode(string $string, int $flags = ENT_QUOTES, string $encoding = 'UTF-8'): string function html_ent_decode(string $string, int $flags = ENT_QUOTES, string $encoding = DEFAULT_CHARSET): string
{ {
return html_entity_decode($string, $flags, $encoding); return html_entity_decode($string, $flags, $encoding);
} }

View file

@ -111,7 +111,7 @@ $template->assign_vars([
// The following assigns all _common_ variables that may be used at any point in a template // The following assigns all _common_ variables that may be used at any point in a template
$template->assign_vars([ $template->assign_vars([
'SIMPLE_HEADER' => !empty($gen_simple_header), 'SIMPLE_HEADER' => !empty($gen_simple_header),
'CONTENT_ENCODING' => $bb_cfg['charset'], 'CONTENT_ENCODING' => DEFAULT_CHARSET,
'IN_ADMIN' => defined('IN_ADMIN'), 'IN_ADMIN' => defined('IN_ADMIN'),
'USER_HIDE_CAT' => (BB_SCRIPT == 'index'), 'USER_HIDE_CAT' => (BB_SCRIPT == 'index'),

View file

@ -481,7 +481,7 @@ foreach ($profile_fields as $field => $can_edit) {
if ($submit && $sig != $pr_data['user_sig']) { if ($submit && $sig != $pr_data['user_sig']) {
$sig = prepare_message($sig); $sig = prepare_message($sig);
if (mb_strlen($sig, 'UTF-8') > $bb_cfg['max_sig_chars']) { if (mb_strlen($sig, DEFAULT_CHARSET) > $bb_cfg['max_sig_chars']) {
$errors[] = $lang['SIGNATURE_TOO_LONG']; $errors[] = $lang['SIGNATURE_TOO_LONG'];
} elseif (preg_match('#<(a|b|i|u|table|tr|td|img) #i', $sig) || preg_match('#(href|src|target|title)=#i', $sig)) { } elseif (preg_match('#<(a|b|i|u|table|tr|td|img) #i', $sig) || preg_match('#(href|src|target|title)=#i', $sig)) {
$errors[] = $lang['SIGNATURE_ERROR_HTML']; $errors[] = $lang['SIGNATURE_ERROR_HTML'];

View file

@ -255,7 +255,7 @@ class Dev
$sql = str_compact($sql); $sql = str_compact($sql);
if (!empty($_COOKIE['sql_log_full'])) { if (!empty($_COOKIE['sql_log_full'])) {
if (mb_strlen($sql, 'UTF-8') > $max_len) { if (mb_strlen($sql, DEFAULT_CHARSET) > $max_len) {
$sql = mb_substr($sql, 0, 50) . ' [...cut...] ' . mb_substr($sql, -50); $sql = mb_substr($sql, 0, 50) . ' [...cut...] ' . mb_substr($sql, -50);
} }
} }

View file

@ -31,7 +31,7 @@ class VersionHelper
public static function removerPrefix(string $version): string public static function removerPrefix(string $version): string
{ {
$version = trim($version); $version = trim($version);
$version = mb_strtolower($version, 'UTF-8'); $version = mb_strtolower($version, DEFAULT_CHARSET);
return str_replace(self::VERSION_PREFIX, '', $version); return str_replace(self::VERSION_PREFIX, '', $version);
} }

View file

@ -322,7 +322,7 @@ class BBCode
{ {
$max_len = 70; $max_len = 70;
$href = $m[1]; $href = $m[1];
$name = (mb_strlen($href, 'UTF-8') > $max_len) ? mb_substr($href, 0, $max_len - 19) . '...' . mb_substr($href, -16) : $href; $name = (mb_strlen($href, DEFAULT_CHARSET) > $max_len) ? mb_substr($href, 0, $max_len - 19) . '...' . mb_substr($href, -16) : $href;
return $this->nofollow_url($href, $name); return $this->nofollow_url($href, $name);
} }

View file

@ -62,7 +62,7 @@ class Updater
$response = file_get_contents(UPDATER_URL, context: $context); $response = file_get_contents(UPDATER_URL, context: $context);
if ($response !== false) { if ($response !== false) {
$this->jsonResponse = json_decode(mb_convert_encoding($response, 'UTF-8', mb_detect_encoding($response)), true); $this->jsonResponse = json_decode(mb_convert_encoding($response, DEFAULT_CHARSET, mb_detect_encoding($response)), true);
} }
// Empty JSON result // Empty JSON result

View file

@ -45,10 +45,10 @@ class Validate
$username = clean_username($username); $username = clean_username($username);
// Length // Length
if (mb_strlen($username, 'UTF-8') > USERNAME_MAX_LENGTH) { if (mb_strlen($username, DEFAULT_CHARSET) > USERNAME_MAX_LENGTH) {
return $lang['USERNAME_TOO_LONG']; return $lang['USERNAME_TOO_LONG'];
} }
if (mb_strlen($username, 'UTF-8') < USERNAME_MIN_LENGTH) { if (mb_strlen($username, DEFAULT_CHARSET) < USERNAME_MIN_LENGTH) {
return $lang['USERNAME_TOO_SMALL']; return $lang['USERNAME_TOO_SMALL'];
} }
@ -170,10 +170,10 @@ class Validate
} }
// Length // Length
if (mb_strlen($password, 'UTF-8') > PASSWORD_MAX_LENGTH) { if (mb_strlen($password, DEFAULT_CHARSET) > PASSWORD_MAX_LENGTH) {
return sprintf($lang['CHOOSE_PASS_ERR_MAX'], PASSWORD_MAX_LENGTH); return sprintf($lang['CHOOSE_PASS_ERR_MAX'], PASSWORD_MAX_LENGTH);
} }
if (mb_strlen($password, 'UTF-8') < PASSWORD_MIN_LENGTH) { if (mb_strlen($password, DEFAULT_CHARSET) < PASSWORD_MIN_LENGTH) {
return sprintf($lang['CHOOSE_PASS_ERR_MIN'], PASSWORD_MIN_LENGTH); return sprintf($lang['CHOOSE_PASS_ERR_MIN'], PASSWORD_MIN_LENGTH);
} }

View file

@ -3,8 +3,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{$bb_cfg['default_lang']}"> <html lang="{$bb_cfg['default_lang']}">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset={CONTENT_ENCODING}"/> <meta charset="{CONTENT_ENCODING}">
<meta http-equiv="Content-Style-Type" content="text/css"/>
<link rel="shortcut icon" href="{SITE_URL}favicon.png" type="image/x-icon"> <link rel="shortcut icon" href="{SITE_URL}favicon.png" type="image/x-icon">
<title>{L_ADMIN}</title> <title>{L_ADMIN}</title>
</head> </head>

View file

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{$bb_cfg['default_lang']}"> <html lang="{$bb_cfg['default_lang']}">
<head> <head>
<meta charset="utf-8"> <meta charset="{CONTENT_ENCODING}">
<meta http-equiv="X-UA-Compatible" content="IE=Edge"> <meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="initial-scale=1.0"> <meta name="viewport" content="initial-scale=1.0">
<meta name="generator" content="{#APP_NAME#}"> <meta name="generator" content="{#APP_NAME#}">