Skip to content

Commit

Permalink
Add placeholder for statistics modal when no messages are found
Browse files Browse the repository at this point in the history
Remove redundant checks
Fix encoding issue
Change let to const
  • Loading branch information
RevertIT committed Apr 2, 2024
1 parent 215c857 commit 54e5e45
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
12 changes: 1 addition & 11 deletions inc/plugins/rt/src/Chat/ChatHandler/AbstractChatHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,8 @@ protected function getError(): array|bool
*/
protected function renderTemplate(int $messageId, int $uid, int $touid = 0, string $message, int $dateline): bool|array
{
if (empty($messageId))
{
return false;
}

$user = get_user($uid);

if (empty($user))
{
return false;
}

// Parse bbcodes
$parser_options = [
"allow_html" => 0,
Expand All @@ -129,7 +119,7 @@ protected function renderTemplate(int $messageId, int $uid, int $touid = 0, stri
$row['date'] = my_date('relative', $dateline);
$row['avatar'] = !empty($this->mybb->user['avatar']) ? htmlspecialchars_uni($this->mybb->user['avatar']) : "{$this->mybb->settings['bburl']}/images/default_avatar.png";
$row['username'] = isset($user['uid'], $user['username'], $user['usergroup'], $user['displaygroup']) ? build_profile_link(format_name($user['username'], $user['usergroup'], $user['displaygroup']), $user['uid']) : $this->lang->na;
$row['original_message'] = base64_encode(htmlspecialchars_uni($message));
$row['original_message'] = base64_encode($message);
$row['message'] = $this->parser->parse_message($message, $parser_options);

// Action bar
Expand Down
4 changes: 2 additions & 2 deletions inc/plugins/rt/src/Chat/ChatHandler/Read.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getMessages(array $loadedMessages = []): mixed
$row['dateline'] = $row['dateline'] ?? TIME_NOW;
$row['avatar'] = !empty($row['avatar']) ? htmlspecialchars_uni($row['avatar']) : "{$this->mybb->settings['bburl']}/images/default_avatar.png";
$row['username'] = isset($row['uid'], $row['username'], $row['usergroup'], $row['displaygroup']) ? build_profile_link(format_name($row['username'], $row['usergroup'], $row['displaygroup']), $row['uid']) : $this->lang->na;
$row['original_message'] = isset($row['message']) ? base64_encode(htmlspecialchars_uni($row['message'])) : null;
$row['original_message'] = isset($row['message']) ? base64_encode($row['message']) : null;
$row['message'] = isset($row['message']) ? $this->parser->parse_message($row['message'], $parser_options) : null;

$rt_chat_whisper = '';
Expand Down Expand Up @@ -229,7 +229,7 @@ public function getMessageBeforeId(int $messageId): array
$row['dateline'] = $row['dateline'] ?? TIME_NOW;
$row['avatar'] = !empty($row['avatar']) ? htmlspecialchars_uni($row['avatar']) : "{$this->mybb->settings['bburl']}/images/default_avatar.png";
$row['username'] = isset($row['uid'], $row['username'], $row['usergroup'], $row['displaygroup']) ? build_profile_link(format_name($row['username'], $row['usergroup'], $row['displaygroup']), $row['uid']) : $this->lang->na;
$row['original_message'] = isset($row['message']) ? base64_encode(htmlspecialchars_uni($row['message'])) : null;
$row['original_message'] = isset($row['message']) ? base64_encode($row['message']) : null;
$row['message'] = isset($row['message']) ? $this->parser->parse_message($row['message'], $parser_options) : null;

$rt_chat_whisper = '';
Expand Down
2 changes: 1 addition & 1 deletion inc/plugins/rt/src/Chat/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Core
'description' => 'RT Chat is a modern and responsive MyBB chat plugin which utilizes MyBB cache system when retrieving messages via ajax.',
'author' => 'RevertIT',
'authorsite' => 'https://github.com/RevertIT/',
'version' => '1.4',
'version' => '1.5',
'compatibility' => '18*',
'codename' => 'rt_chat',
'prefix' => 'rt_chat',
Expand Down
43 changes: 26 additions & 17 deletions inc/plugins/rt/src/Chat/Hooks/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,32 @@ public function misc_start(): void
if ($mybb->get_input('action') === 'statistics')
{
$top5 = $rt_cache->query("
SELECT
COUNT(message) AS total_messages,
c.uid,
u.username,
u.usergroup,
u.displaygroup
FROM
".TABLE_PREFIX."rtchat c
LEFT JOIN ".TABLE_PREFIX."users u ON
u.uid = c.uid
GROUP BY
u.uid
ORDER BY
total_messages
DESC
LIMIT 10;
")->cache('top_10_posters', 1800)->execute();
SELECT
COUNT(message) AS total_messages,
c.uid,
u.username,
u.usergroup,
u.displaygroup
FROM
".TABLE_PREFIX."rtchat c
LEFT JOIN ".TABLE_PREFIX."users u ON
u.uid = c.uid
GROUP BY
u.uid
ORDER BY
total_messages
DESC
LIMIT 10;
")->cache('top_10_posters', 1800)->execute();

// Placeholder when no messages found in chat
if (empty($top5))
{
$top5[] = [
'username' => $lang->na,
'total_messages' => 0
];
}

$rt_chat_statistics_row = '';
foreach ($top5 as $row)
Expand Down
2 changes: 1 addition & 1 deletion jscripts/rt_chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @license http://opensource.org/licenses/mit-license.php MIT license
*/

let RT_Chat =
const RT_Chat =
{
oldestMessageId: null,
isActive: true,
Expand Down

0 comments on commit 54e5e45

Please sign in to comment.