From 7beb4afa72eea5610d4f54ffa67b058d991f241e Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Tue, 26 Dec 2023 17:38:16 +0700 Subject: [PATCH] Some improvements for Ban functionality (#1262) * Some improvements for Ban functionality * Updated * Updated * Update functions.php * Updated * Update viewprofile.php * Update viewtopic.php * Updated * Updated * Updated * Updated * Update mysql.sql * Updated * Updated --- admin/admin_user_ban.php | 127 +----------------- common.php | 20 --- composer.json | 8 ++ install/sql/mysql.sql | 6 +- library/defines.php | 18 --- library/includes/functions.php | 21 +++ library/includes/init_bb.php | 14 ++ library/includes/ucp/viewprofile.php | 10 +- library/language/source/main.php | 27 +--- src/Helpers/IsHelper.php | 11 -- src/Legacy/Common/User.php | 10 -- src/Legacy/Poll.php | 2 +- src/Validate.php | 4 +- styles/templates/admin/admin_user_ban.tpl | 28 ---- styles/templates/default/css/main_content.css | 27 ++-- .../templates/default/usercp_viewprofile.tpl | 2 +- styles/templates/default/viewtopic.tpl | 2 +- viewtopic.php | 18 +-- 18 files changed, 83 insertions(+), 272 deletions(-) diff --git a/admin/admin_user_ban.php b/admin/admin_user_ban.php index 2467cd223..c35b196f8 100644 --- a/admin/admin_user_ban.php +++ b/admin/admin_user_ban.php @@ -16,8 +16,6 @@ require __DIR__ . '/pagestart.php'; if (isset($_POST['submit'])) { $user_bansql = ''; - $email_bansql = ''; - $ip_bansql = ''; $user_list = []; if (!empty($_POST['username'])) { @@ -29,28 +27,6 @@ if (isset($_POST['submit'])) { $user_list[] = $this_userdata['user_id']; } - $ip_list = []; - if (isset($_POST['ban_ip'])) { - $ip_list_temp = explode(',', $_POST['ban_ip']); - - foreach ($ip_list_temp as $ip) { - if (\TorrentPier\Helpers\IPHelper::isValid($ip)) { - $ip_list[] = \TorrentPier\Helpers\IPHelper::ip2long($ip); - } - } - } - - $email_list = []; - if (isset($_POST['ban_email'])) { - $email_list_temp = explode(',', $_POST['ban_email']); - - foreach ($email_list_temp as $i => $iValue) { - if (preg_match('/^(([a-z0-9&\'\.\-_\+])|(\*))+@(([a-z0-9\-])|(\*))+\.([a-z0-9\-]+\.)*?[a-z]+$/is', trim($email_list_temp[$i]))) { - $email_list[] = trim($email_list_temp[$i]); - } - } - } - $sql = 'SELECT * FROM ' . BB_BANLIST; if (!($result = DB()->sql_query($sql))) { bb_die('Could not obtain banlist information'); @@ -60,6 +36,7 @@ if (isset($_POST['submit'])) { DB()->sql_freeresult($result); $kill_session_sql = ''; + for ($i = 0, $iMax = count($user_list); $i < $iMax; $i++) { $in_banlist = false; for ($j = 0, $jMax = count($current_banlist); $j < $jMax; $j++) { @@ -78,30 +55,6 @@ if (isset($_POST['submit'])) { } } - for ($i = 0, $iMax = count($ip_list); $i < $iMax; $i++) { - $in_banlist = false; - for ($j = 0, $jMax = count($current_banlist); $j < $jMax; $j++) { - if ($ip_list[$i] == $current_banlist[$j]['ban_ip']) { - $in_banlist = true; - } - } - - if (!$in_banlist) { - if (preg_match('/(ff\.)|(\.ff)/is', chunk_split($ip_list[$i], 2, '.'))) { - $kill_ip_sql = "session_ip LIKE '" . str_replace('.', '', preg_replace('/(ff\.)|(\.ff)/is', '%', chunk_split($ip_list[$i], 2, '.'))) . "'"; - } else { - $kill_ip_sql = "session_ip = '" . $ip_list[$i] . "'"; - } - - $kill_session_sql .= (($kill_session_sql != '') ? ' OR ' : '') . $kill_ip_sql; - - $sql = 'INSERT INTO ' . BB_BANLIST . " (ban_ip) VALUES ('" . $ip_list[$i] . "')"; - if (!DB()->sql_query($sql)) { - bb_die('Could not insert ban_ip info into database'); - } - } - } - // Now we'll delete all entries from the session table if ($kill_session_sql != '') { $sql = 'DELETE FROM ' . BB_SESSIONS . " WHERE $kill_session_sql"; @@ -110,22 +63,6 @@ if (isset($_POST['submit'])) { } } - for ($i = 0, $iMax = count($email_list); $i < $iMax; $i++) { - $in_banlist = false; - for ($j = 0, $jMax = count($current_banlist); $j < $jMax; $j++) { - if ($email_list[$i] == $current_banlist[$j]['ban_email']) { - $in_banlist = true; - } - } - - if (!$in_banlist) { - $sql = 'INSERT INTO ' . BB_BANLIST . " (ban_email) VALUES ('" . DB()->escape($email_list[$i]) . "')"; - if (!DB()->sql_query($sql)) { - bb_die('Could not insert ban_email info into database'); - } - } - } - $where_sql = ''; if (isset($_POST['unban_user'])) { @@ -138,26 +75,6 @@ if (isset($_POST['submit'])) { } } - if (isset($_POST['unban_ip'])) { - $ip_list = $_POST['unban_ip']; - - for ($i = 0, $iMax = count($ip_list); $i < $iMax; $i++) { - if ($ip_list[$i] != -1) { - $where_sql .= (($where_sql != '') ? ', ' : '') . DB()->escape($ip_list[$i]); - } - } - } - - if (isset($_POST['unban_email'])) { - $email_list = $_POST['unban_email']; - - for ($i = 0, $iMax = count($email_list); $i < $iMax; $i++) { - if ($email_list[$i] != -1) { - $where_sql .= (($where_sql != '') ? ', ' : '') . DB()->escape($email_list[$i]); - } - } - } - if ($where_sql != '') { $sql = 'DELETE FROM ' . BB_BANLIST . " WHERE ban_id IN ($where_sql)"; if (!DB()->sql_query($sql)) { @@ -168,10 +85,7 @@ if (isset($_POST['submit'])) { bb_die($lang['BAN_UPDATE_SUCESSFUL'] . '

' . sprintf($lang['CLICK_RETURN_BANADMIN'], '', '') . '

' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); } else { $template->assign_vars(['S_BANLIST_ACTION' => 'admin_user_ban.php']); - $userban_count = 0; - $ipban_count = 0; - $emailban_count = 0; $sql = 'SELECT b.ban_id, u.user_id, u.username FROM ' . BB_BANLIST . ' b, ' . BB_USERS . ' u @@ -195,50 +109,11 @@ if (isset($_POST['submit'])) { if ($select_userlist == '') { $select_userlist = ''; } - $select_userlist = ''; - $sql = 'SELECT ban_id, ban_ip, ban_email FROM ' . BB_BANLIST . ' ORDER BY ban_ip'; - if (!($result = DB()->sql_query($sql))) { - bb_die('Could not select current ip ban list'); - } - - $banlist = DB()->sql_fetchrowset($result); - DB()->sql_freeresult($result); - - $select_iplist = ''; - $select_emaillist = ''; - - for ($i = 0, $iMax = count($banlist); $i < $iMax; $i++) { - $ban_id = $banlist[$i]['ban_id']; - - if (!empty($banlist[$i]['ban_ip'])) { - $ban_ip = str_replace('255', '*', \TorrentPier\Helpers\IPHelper::long2ip_extended($banlist[$i]['ban_ip'])); - $select_iplist .= ''; - $ipban_count++; - } elseif (!empty($banlist[$i]['ban_email'])) { - $ban_email = $banlist[$i]['ban_email']; - $select_emaillist .= ''; - $emailban_count++; - } - } - - if ($select_iplist == '') { - $select_iplist = ''; - } - - if ($select_emaillist == '') { - $select_emaillist = ''; - } - - $select_iplist = ''; - $select_emaillist = ''; - $template->assign_vars([ 'U_SEARCH_USER' => './../search.php?mode=searchuser', 'S_UNBAN_USERLIST_SELECT' => $select_userlist, - 'S_UNBAN_IPLIST_SELECT' => $select_iplist, - 'S_UNBAN_EMAILLIST_SELECT' => $select_emaillist, 'S_BAN_ACTION' => 'admin_user_ban.php' ]); } diff --git a/common.php b/common.php index caaf7e207..b3455ce98 100644 --- a/common.php +++ b/common.php @@ -164,26 +164,6 @@ switch ($bb_cfg['datastore_type']) { $datastore = new TorrentPier\Legacy\Datastore\File($bb_cfg['cache']['db_dir'] . 'datastore/', $bb_cfg['cache']['prefix']); } -if (CHECK_REQIREMENTS['status'] && !CACHE('bb_cache')->get('system_req')) { - // [1] Check PHP Version - if (!\TorrentPier\Helpers\IsHelper::isPHP(CHECK_REQIREMENTS['php_min_version'])) { - die("TorrentPier requires PHP version " . CHECK_REQIREMENTS['php_min_version'] . "+ Your PHP version " . PHP_VERSION); - } - - // [2] Check installed PHP Extensions on server - $data = []; - foreach (CHECK_REQIREMENTS['ext_list'] as $ext) { - if (!extension_loaded($ext)) { - $data[] = '' . $ext . ''; - } - } - if (!empty($data)) { - die(sprintf("TorrentPier requires %s extension(s) installed on server", implode(', ', $data))); - } - - CACHE('bb_cache')->set('system_req', true); -} - // Functions function utime() { diff --git a/composer.json b/composer.json index 15971bc6d..5501573a9 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,14 @@ }, "require": { "php": "^8.1", + "ext-mysqli": "*", + "ext-mbstring": "*", + "ext-json": "*", + "ext-bcmath": "*", + "ext-intl": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "ext-curl": "*", "arokettu/bencode": "^4.1.0", "bugsnag/bugsnag": "^v3.29.1", "claviska/simpleimage": "^4.0", diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index 26a3f9378..9f890ac6c 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -149,10 +149,8 @@ CREATE TABLE IF NOT EXISTS `bb_banlist` ( `ban_id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT, `ban_userid` MEDIUMINT(8) NOT NULL DEFAULT '0', - `ban_ip` VARCHAR(42) NOT NULL DEFAULT '0', - `ban_email` VARCHAR(255) NOT NULL DEFAULT '', - PRIMARY KEY (`ban_id`), - KEY `ban_ip_user_id` (`ban_ip`, `ban_userid`) + `ban_reason` VARCHAR(255) NOT NULL DEFAULT '', + PRIMARY KEY (`ban_id`, `ban_userid`) ) ENGINE = MyISAM DEFAULT CHARSET = utf8; diff --git a/library/defines.php b/library/defines.php index 73fbb6040..21c244e69 100644 --- a/library/defines.php +++ b/library/defines.php @@ -14,24 +14,6 @@ if (!defined('BB_ROOT')) { // System define('APP_NAME', 'TorrentPier'); -define('CHECK_REQIREMENTS', [ - 'status' => true, - 'php_min_version' => '8.1.0', - 'ext_list' => [ - 'json', - // 'gd', (optional) - // 'zlib', (optional) - 'curl', - // 'tidy', (optional) - 'mysqli', - 'bcmath', - 'mbstring', - 'intl', - 'xml', - 'xmlwriter', - ], -]); - // Path (trailing slash '/' at the end: XX_PATH - without, XX_DIR - with) define('ADMIN_DIR', BB_PATH . '/admin'); define('DATA_DIR', BB_PATH . '/data'); diff --git a/library/includes/functions.php b/library/includes/functions.php index c27fd6845..c332c03b7 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -2170,3 +2170,24 @@ function user_birthday_icon($user_birthday, $user_id): string return ($bb_cfg['birthday_enabled'] && $current_date == $user_birthday) ? '' . $lang['HAPPY_BIRTHDAY'] . '' : ''; } + +/** + * Returns information about user ban + * + * @param int $userId + * @return array + */ +function getUserBanInfo(int $userId): array +{ + return DB()->fetch_row("SELECT * FROM " . BB_BANLIST . " WHERE ban_userid = $userId LIMIT 1"); +} + +/** + * Returns information about all bans + * + * @return array + */ +function getAllBans(): array +{ + return DB()->fetch_rowset("SELECT * FROM " . BB_BANLIST); +} diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index 946cc89a5..8e5ba6b5f 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -394,6 +394,20 @@ $user = new TorrentPier\Legacy\Common\User(); $userdata =& $user->data; +/** + * Initial ban check + */ +if ($banInfo = getUserBanInfo($user->id)) { + if (!IS_GUEST) { + $user->session_end(); + } + if (!empty($banInfo['ban_reason'])) { + bb_die($lang['YOU_BEEN_BANNED'] . '

' . $banInfo['ban_reason']); + } else { + bb_die($lang['YOU_BEEN_BANNED']); + } +} + /** * Cron */ diff --git a/library/includes/ucp/viewprofile.php b/library/includes/ucp/viewprofile.php index 172f7ee39..cd0745734 100644 --- a/library/includes/ucp/viewprofile.php +++ b/library/includes/ucp/viewprofile.php @@ -74,9 +74,12 @@ if (bf($profiledata['user_opt'], 'user_opt', 'dis_sig')) { $signature = bbcode2html($signature); } -$user_banned = false; -if (DB()->fetch_row('SELECT ban_userid FROM ' . BB_BANLIST . " WHERE ban_userid = {$profiledata['user_id']} LIMIT 1")) { - $user_banned = true; +// Ban information +if ($banInfo = getUserBanInfo($profiledata['user_id'])) { + $template->assign_block_vars('ban', [ + 'IS_BANNED' => true, + 'BAN_REASON' => $banInfo['ban_reason'] + ]); } $template->assign_vars([ @@ -85,7 +88,6 @@ $template->assign_vars([ 'PROFILE_USER_ID' => $profiledata['user_id'], 'PROFILE_USER' => $profile_user_id, 'USER_REGDATE' => bb_date($profiledata['user_regdate'], 'Y-m-d H:i', false), - 'BANNED' => $user_banned, 'POSTER_RANK' => ($poster_rank) ? "" . $poster_rank . "" : $lang['USER'], 'RANK_IMAGE' => $rank_image, 'RANK_SELECT' => $rank_select, diff --git a/library/language/source/main.php b/library/language/source/main.php index 5fff68cbb..b77a47425 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -1740,35 +1740,12 @@ $lang['CLICK_RETURN_FORUMAUTH'] = 'Click %sHere%s to return to Forum Permissions // Banning $lang['BAN_CONTROL'] = 'Ban Control'; -$lang['BAN_EXPLAIN'] = 'Here you can control the banning of users. You can achieve this by banning either or both of a specific user or an individual or range of IP addresses. These methods prevent a user from even reaching the index page of your board. To prevent a user from registering under a different username you can also specify a banned email address. Please note that banning an email address alone will not prevent that user from being able to log on or post to your board. You should use one of the first two methods to achieve this.'; -$lang['BAN_EXPLAIN_WARN'] = 'Please note that entering a range of IP addresses results in all the addresses between the start and end being added to the banlist. Attempts will be made to minimise the number of addresses added to the database by introducing wildcards automatically where appropriate. If you really must enter a range, try to keep it small or better yet state specific addresses.'; - -$lang['SELECT_IP'] = 'Select an IP address'; -$lang['SELECT_EMAIL'] = 'Select an Email address'; - +$lang['BAN_EXPLAIN'] = 'Here you can control the banning of users.'; $lang['BAN_USERNAME'] = 'Ban one or more specific users'; $lang['BAN_USERNAME_EXPLAIN'] = 'You can ban multiple users in one go using the appropriate combination of mouse and keyboard for your computer and browser'; - -$lang['BAN_IP'] = 'Ban one or more IP addresses'; -$lang['IP_HOSTNAME'] = 'IP addresses'; -$lang['BAN_IP_EXPLAIN'] = 'To specify several different IP addresses separate them with commas.'; - -$lang['BAN_EMAIL'] = 'Ban one or more email addresses'; -$lang['BAN_EMAIL_EXPLAIN'] = 'To specify more than one email address, separate them with commas. To specify a wildcard username, use * like *@hotmail.com'; - -$lang['UNBAN_USERNAME'] = 'Un-ban one more specific users'; +$lang['UNBAN_USERNAME'] = 'Unban one more specific users'; $lang['UNBAN_USERNAME_EXPLAIN'] = 'You can unban multiple users in one go using the appropriate combination of mouse and keyboard for your computer and browser'; - -$lang['UNBAN_IP'] = 'Un-ban one or more IP addresses'; -$lang['UNBAN_IP_EXPLAIN'] = 'You can unban multiple IP addresses in one go using the appropriate combination of mouse and keyboard for your computer and browser'; - -$lang['UNBAN_EMAIL'] = 'Un-ban one or more email addresses'; -$lang['UNBAN_EMAIL_EXPLAIN'] = 'You can unban multiple email addresses in one go using the appropriate combination of mouse and keyboard for your computer and browser'; - $lang['NO_BANNED_USERS'] = 'No banned usernames'; -$lang['NO_BANNED_IP'] = 'No banned IP addresses'; -$lang['NO_BANNED_EMAIL'] = 'No banned email addresses'; - $lang['BAN_UPDATE_SUCESSFUL'] = 'The banlist has been updated successfully'; $lang['CLICK_RETURN_BANADMIN'] = 'Click %sHere%s to return to Ban Control'; diff --git a/src/Helpers/IsHelper.php b/src/Helpers/IsHelper.php index add336e43..abb8fe9eb 100644 --- a/src/Helpers/IsHelper.php +++ b/src/Helpers/IsHelper.php @@ -15,17 +15,6 @@ namespace TorrentPier\Helpers; */ class IsHelper { - /** - * Determines if the current version of PHP is equal to or greater than the supplied value - * - * @param string $version - * @return bool TRUE if the current version is $version or higher - */ - public static function isPHP(string $version): bool - { - return version_compare(PHP_VERSION, $version, '>='); - } - /** * Return true if server have SSL * diff --git a/src/Legacy/Common/User.php b/src/Legacy/Common/User.php index 902cefb2b..31b7ba132 100644 --- a/src/Legacy/Common/User.php +++ b/src/Legacy/Common/User.php @@ -240,16 +240,6 @@ class User $user_id = (int)$this->data['user_id']; $mod_admin_session = ((int)$this->data['user_level'] === ADMIN || (int)$this->data['user_level'] === MOD); - // Initial ban check against user_id or IP address - if ($is_user) { - $where_sql = 'ban_ip = ' . USER_IP; - $where_sql .= $login ? " OR ban_userid = $user_id" : ''; - - if (DB()->fetch_row("SELECT ban_id FROM " . BB_BANLIST . " WHERE $where_sql LIMIT 1")) { - bb_simple_die($lang['YOU_BEEN_BANNED']); - } - } - // Generate passkey if (!\TorrentPier\Legacy\Torrent::getPasskey($this->data['user_id'])) { if (!\TorrentPier\Legacy\Torrent::generate_passkey($this->data['user_id'], true)) { diff --git a/src/Legacy/Poll.php b/src/Legacy/Poll.php index 106fa5a94..1025f51ba 100644 --- a/src/Legacy/Poll.php +++ b/src/Legacy/Poll.php @@ -151,7 +151,7 @@ class Poll */ public static function userIsAlreadyVoted(int $topic_id, int $user_id): bool { - return (bool)DB()->fetch_row("SELECT user_id FROM " . BB_POLL_USERS . " WHERE topic_id = $topic_id AND user_id = $user_id LIMIT 1"); + return (bool)DB()->fetch_row("SELECT 1 FROM " . BB_POLL_USERS . " WHERE topic_id = $topic_id AND user_id = $user_id LIMIT 1"); } /** diff --git a/src/Validate.php b/src/Validate.php index b50e4d3d2..62f24a8a9 100644 --- a/src/Validate.php +++ b/src/Validate.php @@ -32,10 +32,9 @@ class Validate * * @return bool|string */ - public static function username(string $username, bool $check_ban_and_taken = true) + public static function username(string $username, bool $check_ban_and_taken = true): bool|string { global $user, $lang; - static $name_chars = 'a-z0-9а-яё_@$%^&;(){}\#\-\'.:+ '; // Check for empty @@ -43,7 +42,6 @@ class Validate return $lang['CHOOSE_A_NAME']; } - $username = str_compact($username); $username = clean_username($username); // Length diff --git a/styles/templates/admin/admin_user_ban.tpl b/styles/templates/admin/admin_user_ban.tpl index 8d41e0064..8390a3349 100644 --- a/styles/templates/admin/admin_user_ban.tpl +++ b/styles/templates/admin/admin_user_ban.tpl @@ -20,34 +20,6 @@ {L_USERNAME}:
{L_UNBAN_USERNAME_EXPLAIN} {S_UNBAN_USERLIST_SELECT} - - {L_BAN_IP} - - - {L_IP_HOSTNAME}:
{L_BAN_IP_EXPLAIN} - - - - {L_UNBAN_IP} - - - {L_IP_HOSTNAME}:
{L_UNBAN_IP_EXPLAIN} - {S_UNBAN_IPLIST_SELECT} - - - {L_BAN_EMAIL} - - - {L_EMAIL_ADDRESS}:
{L_BAN_EMAIL_EXPLAIN} - - - - {L_UNBAN_EMAIL} - - - {L_EMAIL_ADDRESS}:
{L_UNBAN_EMAIL_EXPLAIN} - {S_UNBAN_EMAILLIST_SELECT} -    diff --git a/styles/templates/default/css/main_content.css b/styles/templates/default/css/main_content.css index f74d6426f..ad0a53e97 100644 --- a/styles/templates/default/css/main_content.css +++ b/styles/templates/default/css/main_content.css @@ -150,7 +150,7 @@ table.forums { display: none; } -.subforums+.moderators { +.subforums + .moderators { margin-top: 0; } @@ -172,7 +172,8 @@ table.forums { margin-right: 1px; } -.sf_separator {} +.sf_separator { +} .sf_title a { text-decoration: none; @@ -218,7 +219,8 @@ table.forums { white-space: nowrap; } -.f_stat_topics {} +.f_stat_topics { +} .f_stat_posts { padding-left: 3px; @@ -490,14 +492,14 @@ a.postLink:visited { } .poster-banned { - background:#f6f6f6; - border:1px solid #b71c1c; - padding:4px; - border-radius:2px; - font-size:11px; - font-weight:bold; - letter-spacing:1px; - text-align:center + background: #f6f6f6; + border: 1px solid #b71c1c; + padding: 4px; + border-radius: 2px; + font-size: 11px; + font-weight: bold; + letter-spacing: 1px; + text-align: center } .poster_info .avatar { @@ -602,7 +604,8 @@ table.peers td { border: 1px #A5AFB4 solid; } -.dl_list {} +.dl_list { +} .dl_list td { text-align: center; diff --git a/styles/templates/default/usercp_viewprofile.tpl b/styles/templates/default/usercp_viewprofile.tpl index 98085beeb..3899ea8a0 100644 --- a/styles/templates/default/usercp_viewprofile.tpl +++ b/styles/templates/default/usercp_viewprofile.tpl @@ -295,7 +295,7 @@ ajax.callback.index_data = function(data) { {L_USERNAME}: {USERNAME} - {L_BANNED} + {L_BANNED} diff --git a/styles/templates/default/viewtopic.tpl b/styles/templates/default/viewtopic.tpl index 43398ce1b..58ec82394 100644 --- a/styles/templates/default/viewtopic.tpl +++ b/styles/templates/default/viewtopic.tpl @@ -361,7 +361,7 @@ function build_poll_add_form (src_el)

{postrow.POSTER_NAME} ®

-

{L_BANNED}

+

{L_BANNED}

{postrow.POSTER_RANK}

{postrow.RANK_IMAGE}

{postrow.POSTER_AVATAR}

diff --git a/viewtopic.php b/viewtopic.php index 3e988acf5..53274d923 100644 --- a/viewtopic.php +++ b/viewtopic.php @@ -317,15 +317,13 @@ if ($t_data['topic_show_first_post'] && $start) { u.user_opt, u.user_gender, u.user_birthday, p.*, g.group_name, g.group_description, g.group_id, g.group_signature, g.avatar_ext_id as rg_avatar_id, u2.username as mc_username, u2.user_rank as mc_user_rank, - h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text, - ban.ban_userid + h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text FROM " . BB_POSTS . " p LEFT JOIN " . BB_USERS . " u ON(u.user_id = p.poster_id) LEFT JOIN " . BB_POSTS_TEXT . " pt ON(pt.post_id = p.post_id) LEFT JOIN " . BB_POSTS_HTML . " h ON(h.post_id = p.post_id) LEFT JOIN " . BB_USERS . " u2 ON(u2.user_id = p.mc_user_id) LEFT JOIN " . BB_GROUPS . " g ON(g.group_id = p.poster_rg_id) - LEFT JOIN " . BB_BANLIST . " ban ON(ban.ban_userid = u.user_id) WHERE p.post_id = {$t_data['topic_first_post_id']} LIMIT 1 @@ -340,15 +338,13 @@ $sql = " u.user_opt, u.user_gender, u.user_birthday, p.*, g.group_name, g.group_description, g.group_id, g.group_signature, g.avatar_ext_id as rg_avatar_id, u2.username as mc_username, u2.user_rank as mc_user_rank, - h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text, - ban.ban_userid + h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text FROM " . BB_POSTS . " p LEFT JOIN " . BB_USERS . " u ON(u.user_id = p.poster_id) LEFT JOIN " . BB_POSTS_TEXT . " pt ON(pt.post_id = p.post_id) LEFT JOIN " . BB_POSTS_HTML . " h ON(h.post_id = p.post_id) LEFT JOIN " . BB_USERS . " u2 ON(u2.user_id = p.mc_user_id) LEFT JOIN " . BB_GROUPS . " g ON(g.group_id = p.poster_rg_id) - LEFT JOIN " . BB_BANLIST . " ban ON(ban.ban_userid = u.user_id) WHERE p.topic_id = $topic_id $limit_posts_time GROUP BY p.post_id @@ -595,7 +591,6 @@ for ($i = 0; $i < $total_posts; $i++) { $poster_rank = $rank_image = ''; $user_rank = $postrow[$i]['user_rank']; - $user_ban_status = $postrow[$i]['ban_userid']; if (!$user->opt_js['h_rnk_i'] and isset($ranks[$user_rank])) { $rank_image = ($bb_cfg['show_rank_image'] && $ranks[$user_rank]['rank_image']) ? '' : ''; $poster_rank = $bb_cfg['show_rank_text'] ? $ranks[$user_rank]['rank_title'] : ''; @@ -694,7 +689,6 @@ for ($i = 0; $i < $total_posts; $i++) { 'POSTER_NAME_JS' => addslashes($poster), 'POSTER_RANK' => $poster_rank, 'RANK_IMAGE' => $rank_image, - 'POSTER_BANNED' => $user_ban_status, 'POSTER_JOINED' => $bb_cfg['show_poster_joined'] ? $poster_longevity : '', 'POSTER_JOINED_DATE' => $poster_joined, @@ -741,6 +735,14 @@ for ($i = 0; $i < $total_posts; $i++) { 'RG_SIG_ATTACH' => $postrow[$i]['attach_rg_sig'] ]); + // Ban information + if ($banInfo = getUserBanInfo($poster_id)) { + $template->assign_block_vars('postrow.ban', [ + 'IS_BANNED' => true, + 'BAN_REASON' => $banInfo['ban_reason'] + ]); + } + if (isset($postrow[$i]['post_attachment']) && $is_auth['auth_download'] && function_exists('display_post_attachments')) { display_post_attachments($post_id, $postrow[$i]['post_attachment']); }