Improved look of mentions a tad.
This commit is contained in:
parent
757362102f
commit
8df64722ac
3 changed files with 36 additions and 8 deletions
|
@ -21,6 +21,16 @@
|
||||||
margin-bottom: 3px;
|
margin-bottom: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__mention {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: 700;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&__actions {
|
&__actions {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
@ -55,13 +55,6 @@ function user_id_from_username(string $username): int
|
||||||
return $getId->execute() ? (int)$getId->fetchColumn() : 0;
|
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');
|
define('MSZ_USER_AVATAR_FORMAT', '%d.msz');
|
||||||
|
|
||||||
function user_avatar_delete(int $userId): void
|
function user_avatar_delete(int $userId): void
|
||||||
|
|
|
@ -39,7 +39,32 @@ function comments_parse_for_store(string $text): string
|
||||||
function comments_parse_for_display(string $text): string
|
function comments_parse_for_display(string $text): string
|
||||||
{
|
{
|
||||||
return preg_replace_callback(MSZ_COMMENTS_MARKUP_USER_ID, function ($matches) {
|
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);
|
}, $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue