Added some base stuff for warnings.
This commit is contained in:
parent
74910eddb6
commit
f345b7fe51
7 changed files with 234 additions and 0 deletions
46
assets/less/classes/profile/warning.less
Normal file
46
assets/less/classes/profile/warning.less
Normal file
|
@ -0,0 +1,46 @@
|
|||
.profile__warning {
|
||||
margin: 2px;
|
||||
padding: 1px;
|
||||
border-radius: 2px;
|
||||
border: 1px solid var(--accent-colour);
|
||||
|
||||
&--warning {
|
||||
--accent-colour: #666;
|
||||
}
|
||||
|
||||
&--silence {
|
||||
--accent-colour: #f70;
|
||||
}
|
||||
|
||||
&--ban {
|
||||
--accent-colour: #c33;
|
||||
}
|
||||
|
||||
&__public {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
&__type {
|
||||
min-width: 60px;
|
||||
text-align: center;
|
||||
background-color: var(--accent-colour);
|
||||
border-radius: 1px;
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
&__datetime {
|
||||
min-width: 100px;
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
&__note {
|
||||
padding: 1px 4px;
|
||||
}
|
||||
|
||||
&__private {
|
||||
border-top: 1px solid var(--accent-colour);
|
||||
margin-top: 1px;
|
||||
padding: 1px 4px;
|
||||
}
|
||||
}
|
|
@ -122,6 +122,7 @@ html {
|
|||
@import "classes/profile/about";
|
||||
@import "classes/profile/guidelines";
|
||||
@import "classes/profile/background-settings";
|
||||
@import "classes/profile/warning";
|
||||
|
||||
// Changelog
|
||||
@import "classes/changelog";
|
||||
|
|
42
database/2018_12_24_203231_add_warnings_table.php
Normal file
42
database/2018_12_24_203231_add_warnings_table.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
namespace Misuzu\DatabaseMigrations\AddWarningsTable;
|
||||
|
||||
use PDO;
|
||||
|
||||
function migrate_up(PDO $conn): void
|
||||
{
|
||||
$conn->exec("
|
||||
CREATE TABLE `msz_user_warnings` (
|
||||
`warning_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`user_id` INT(10) UNSIGNED NOT NULL,
|
||||
`user_ip` VARBINARY(16) NOT NULL,
|
||||
`issuer_id` INT(10) UNSIGNED NULL DEFAULT NULL,
|
||||
`issuer_ip` VARBINARY(16) NOT NULL,
|
||||
`warning_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`warning_type` TINYINT(3) UNSIGNED NOT NULL,
|
||||
`warning_note` VARCHAR(255) NOT NULL,
|
||||
`warning_note_private` TEXT NOT NULL,
|
||||
PRIMARY KEY (`warning_id`),
|
||||
INDEX `user_warnings_user_foreign` (`user_id`),
|
||||
INDEX `user_warnings_issuer_foreign` (`issuer_id`),
|
||||
INDEX `user_warnings_indices` (`warning_created`, `warning_type`),
|
||||
CONSTRAINT `user_warnings_issuer_foreign`
|
||||
FOREIGN KEY (`issuer_id`)
|
||||
REFERENCES `msz_users` (`user_id`)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE SET NULL,
|
||||
CONSTRAINT `user_warnings_user_foreign`
|
||||
FOREIGN KEY (`user_id`)
|
||||
REFERENCES `msz_users` (`user_id`)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
)
|
||||
");
|
||||
}
|
||||
|
||||
function migrate_down(PDO $conn): void
|
||||
{
|
||||
$conn->exec("
|
||||
DROP TABLE `msz_user_warnings`;
|
||||
");
|
||||
}
|
|
@ -64,6 +64,7 @@ require_once 'src/Users/role.php';
|
|||
require_once 'src/Users/session.php';
|
||||
require_once 'src/Users/user.php';
|
||||
require_once 'src/Users/validation.php';
|
||||
require_once 'src/Users/warning.php';
|
||||
|
||||
config_load(MSZ_ROOT . '/config/config.ini');
|
||||
mail_prepare(config_get_default([], 'Mail'));
|
||||
|
|
|
@ -89,6 +89,7 @@ switch ($mode) {
|
|||
break;
|
||||
}
|
||||
|
||||
$warnings = user_warning_fetch($userId, 90);
|
||||
$notices = [];
|
||||
|
||||
if ($isEditing) {
|
||||
|
@ -323,6 +324,8 @@ switch ($mode) {
|
|||
'profile_notices' => $notices,
|
||||
'can_edit' => $canEdit,
|
||||
'is_editing' => $isEditing,
|
||||
'warnings' => $warnings,
|
||||
'can_view_private_note' => $viewingOwnProfile,
|
||||
'profile_fields' => user_session_active() ? user_profile_fields_display($profile, !$isEditing) : [],
|
||||
'friend_info' => user_session_active() ? user_relation_info(user_session_current('user_id', 0), $profile['user_id']) : [],
|
||||
]);
|
||||
|
|
100
src/Users/warning.php
Normal file
100
src/Users/warning.php
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
define('MSZ_WARN_NOTE', 0);
|
||||
define('MSZ_WARN_SILENCE', 1);
|
||||
define('MSZ_WARN_BAN', 2);
|
||||
|
||||
define('MSZ_WARN_TYPES', [
|
||||
MSZ_WARN_NOTE, MSZ_WARN_SILENCE, MSZ_WARN_BAN,
|
||||
]);
|
||||
|
||||
function user_warning_add(
|
||||
int $userId,
|
||||
string $userIp,
|
||||
int $issuerId,
|
||||
string $issuerIp,
|
||||
int $type,
|
||||
string $publicNote,
|
||||
string $privateNote
|
||||
): int {
|
||||
if (!in_array($type, MSZ_WARN_TYPES, true)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
$addWarning = db_prepare('
|
||||
INSERT INTO `msz_user_warnings`
|
||||
(`user_id`, `user_ip`, `issuer_id`, `issuer_ip`, `warning_type`, `warning_note`, `warning_note_private`)
|
||||
VALUES
|
||||
(:user_id, INET6_ATON(:user_ip), :issuer_id, INET6_ATON(:issuer_ip), :type, :note, :note_private)
|
||||
');
|
||||
$addWarning->bindValue('user_id', $userId);
|
||||
$addWarning->bindValue('user_ip', $userIp);
|
||||
$addWarning->bindValue('issuer_id', $issuerId);
|
||||
$addWarning->bindValue('issuer_ip', $issuerIp);
|
||||
$addWarning->bindValue('type', $type);
|
||||
$addWarning->bindValue('note', $publicNote);
|
||||
$addWarning->bindValue('note_private', $privateNote);
|
||||
|
||||
if (!$addWarning->execute()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int)db_last_insert_id();
|
||||
}
|
||||
|
||||
function user_warning_count(int $userId): int
|
||||
{
|
||||
if ($userId < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$countWarnings = db_prepare('
|
||||
SELECT COUNT(`warning_id`)
|
||||
FROM `msz_user_warnings`
|
||||
WHERE `user_id` = :user_id
|
||||
');
|
||||
$countWarnings->bindValue('user_id', $userId);
|
||||
return (int)($countWarnings->execute() ? $countWarnings->fetchColumn() : 0);
|
||||
}
|
||||
|
||||
function user_warning_remove(int $warningId): bool
|
||||
{
|
||||
if ($warningId < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$removeWarning = db_prepare('
|
||||
DELETE FROM `msz_user_warnings`
|
||||
WHERE `warning_id` = :warning_id
|
||||
');
|
||||
$removeWarning->bindValue('warning_id', $warningId);
|
||||
return $removeWarning->execute();
|
||||
}
|
||||
|
||||
function user_warning_fetch(
|
||||
int $userId,
|
||||
?int $days = null
|
||||
): array {
|
||||
$fetchWarnings = db_prepare(sprintf(
|
||||
'
|
||||
SELECT
|
||||
uw.`warning_id`, uw.`warning_created`, uw.`warning_type`, uw.`warning_note`,
|
||||
uw.`warning_note_private`, uw.`user_id`, uw.`issuer_id`,
|
||||
INET6_NTOA(uw.`user_ip`) AS `user_ip`, INET6_NTOA(uw.`issuer_ip`) AS `issuer_ip`,
|
||||
iu.`username` AS `issuer_username`
|
||||
FROM `msz_user_warnings` AS uw
|
||||
LEFT JOIN `msz_users` AS iu
|
||||
ON iu.`user_id` = uw.`issuer_id`
|
||||
WHERE uw.`user_id` = :user_id
|
||||
%s
|
||||
',
|
||||
$days !== null ? 'AND uw.`warning_created` >= NOW() - INTERVAL :days DAY' : ''
|
||||
));
|
||||
$fetchWarnings->bindValue('user_id', $userId);
|
||||
|
||||
if ($days !== null) {
|
||||
$fetchWarnings->bindValue('days', $days);
|
||||
}
|
||||
|
||||
$warnings = $fetchWarnings->execute() ? $fetchWarnings->fetchAll(PDO::FETCH_ASSOC) : false;
|
||||
return $warnings ? $warnings : [];
|
||||
}
|
|
@ -156,6 +156,47 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if warnings|length > 0 %}
|
||||
<div class="container container--no-overflow">
|
||||
{{ container_title('Account Standing') }}
|
||||
|
||||
{% for warning in warnings %}
|
||||
{% if warning.warning_type == constant('MSZ_WARN_SILENCE') %}
|
||||
{% set warning_text = 'Silence' %}
|
||||
{% set warning_class = 'silence' %}
|
||||
{% elseif warning.warning_type == constant('MSZ_WARN_BAN') %}
|
||||
{% set warning_text = 'Ban' %}
|
||||
{% set warning_class = 'ban' %}
|
||||
{% else %}
|
||||
{% set warning_text = 'Warning' %}
|
||||
{% set warning_class = 'warning' %}
|
||||
{% endif %}
|
||||
|
||||
<div class="profile__warning profile__warning--{{ warning_class }}" id="warning-{{ warning.warning_id }}">
|
||||
<div class="profile__warning__public">
|
||||
<div class="profile__warning__type">
|
||||
{{ warning_text }}
|
||||
</div>
|
||||
|
||||
<time datetime="{{ warning.warning_created|date('c') }}" title="{{ warning.warning_created|date('r') }}" class="profile__warning__datetime">
|
||||
{{ warning.warning_created|time_diff }}
|
||||
</time>
|
||||
|
||||
<div class="profile__warning__note">
|
||||
{{ warning.warning_note }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if can_view_private_note and warning.warning_note_private|length > 0 %}
|
||||
<div class="profile__warning__private">
|
||||
{{ warning.warning_note_private|nl2br }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue