Improved look of mentions a tad.

This commit is contained in:
flash 2018-08-17 03:49:43 +02:00
parent 757362102f
commit 8df64722ac
3 changed files with 36 additions and 8 deletions

View file

@ -21,6 +21,16 @@
margin-bottom: 3px;
}
&__mention {
color: inherit;
text-decoration: none;
font-weight: 700;
&:hover {
text-decoration: underline;
}
}
&__actions {
list-style: none;
display: flex;

View file

@ -55,13 +55,6 @@ function user_id_from_username(string $username): int
return $getId->execute() ? (int)$getId->fetchColumn() : 0;
}
function user_username_from_id(int $userId): string
{
$getId = Database::prepare('SELECT `username` FROM `msz_users` WHERE `user_id` = :user_id');
$getId->bindValue('user_id', $userId);
return $getId->execute() ? (string)$getId->fetchColumn() : 'deleted';
}
define('MSZ_USER_AVATAR_FORMAT', '%d.msz');
function user_avatar_delete(int $userId): void

View file

@ -39,7 +39,32 @@ function comments_parse_for_store(string $text): string
function comments_parse_for_display(string $text): string
{
return preg_replace_callback(MSZ_COMMENTS_MARKUP_USER_ID, function ($matches) {
return '<a href="/profile.php?u=' . $matches[1] . '">@' . user_username_from_id($matches[1]) . '</a>';
$getInfo = Database::prepare('
SELECT
u.`user_id`, u.`username`,
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
FROM `msz_users` as u
LEFT JOIN `msz_roles` as r
ON u.`display_role` = r.`role_id`
WHERE `user_id` = :user_id
');
$getInfo->bindValue('user_id', $matches[1]);
$info = $getInfo->execute() ? $getInfo->fetch(PDO::FETCH_ASSOC) : [];
if (!$info) {
return $matches[0];
}
return '<a href="/profile.php?u='
. $info['user_id']
. '" class="comment__mention" style="'
. html_colour($info['user_colour'], [
'color' => '%s',
'text-shadow' => '0 0 5px %s',
])
. '">@'
. $info['username']
. '</a>';
}, $text);
}