Added horribad quote administration thing.
This commit is contained in:
parent
836f7272c5
commit
39ff56a6b7
4 changed files with 216 additions and 37 deletions
|
@ -19,6 +19,47 @@ switch ($_GET['v'] ?? null) {
|
||||||
echo tpl_render('manage.general.logs');
|
echo tpl_render('manage.general.logs');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'quotes':
|
||||||
|
$setId = (int)($_GET['s'] ?? '');
|
||||||
|
$quoteId = (int)($_GET['q'] ?? '');
|
||||||
|
|
||||||
|
if (!empty($_POST['quote']) && csrf_verify('add_quote', $_POST['csrf'] ?? '')) {
|
||||||
|
$quoteTime = strtotime($_POST['quote']['time'] ?? '');
|
||||||
|
$parentId = empty($_POST['quote']['parent']) ? null : (int)($_POST['quote']['parent']);
|
||||||
|
|
||||||
|
$quoteId = chat_quotes_add(
|
||||||
|
$_POST['quote']['text'] ?? null,
|
||||||
|
$_POST['quote']['user']['name'] ?? null,
|
||||||
|
empty($_POST['quote']['user']['colour']) ? MSZ_COLOUR_INHERIT : (int)($_POST['quote']['user']['colour']),
|
||||||
|
empty($_POST['quote']['user']['id']) ? null : (int)($_POST['quote']['user']['id']),
|
||||||
|
empty($_POST['quote']['parent']) || $_POST['quote']['id'] == $parentId ? null : (int)($_POST['quote']['parent']),
|
||||||
|
$quoteTime ? $quoteTime : null,
|
||||||
|
empty($_POST['quote']['id']) ? null : (int)($_POST['quote']['id'])
|
||||||
|
);
|
||||||
|
|
||||||
|
header('Location: ?v=quotes' . ($setId ? '&s=' . $setId : '&q=' . $quoteId));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($quoteId) {
|
||||||
|
tpl_vars([
|
||||||
|
'current_quote' => chat_quotes_single($quoteId),
|
||||||
|
'quote_parent' => $setId,
|
||||||
|
]);
|
||||||
|
} elseif ($setId > 0) {
|
||||||
|
tpl_var('quote_set', chat_quotes_set($setId));
|
||||||
|
}
|
||||||
|
|
||||||
|
$quoteCount = chat_quotes_count(true);
|
||||||
|
$quotes = chat_quotes_parents($_GET['o'] ?? 0);
|
||||||
|
|
||||||
|
echo tpl_render('manage.general.quotes', [
|
||||||
|
'quote_count' => $quoteCount,
|
||||||
|
'quote_offset' => (int)($_GET['o'] ?? 0),
|
||||||
|
'quote_parents' => $quotes,
|
||||||
|
]);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'emoticons':
|
case 'emoticons':
|
||||||
if (!perms_check($generalPerms, MSZ_PERM_GENERAL_MANAGE_EMOTICONS)) {
|
if (!perms_check($generalPerms, MSZ_PERM_GENERAL_MANAGE_EMOTICONS)) {
|
||||||
echo render_error(403);
|
echo render_error(403);
|
||||||
|
|
|
@ -1,35 +1,121 @@
|
||||||
<?php
|
<?php
|
||||||
|
define('MSZ_CHAT_QUOTES_TAKE', 15);
|
||||||
|
|
||||||
function chat_quotes_add(
|
function chat_quotes_add(
|
||||||
string $text,
|
string $text,
|
||||||
string $username,
|
string $username,
|
||||||
int $colour,
|
int $colour,
|
||||||
?int $userId = null,
|
?int $userId = null,
|
||||||
?int $parent = null,
|
?int $parent = null,
|
||||||
?int $time = null
|
?int $time = null,
|
||||||
|
?int $quoteId = null
|
||||||
): int {
|
): int {
|
||||||
$insert = db_prepare('
|
if ($quoteId > 0) {
|
||||||
INSERT INTO `msz_chat_quotes` (
|
$insert = db_prepare('
|
||||||
`quote_parent`, `quote_user_id`, `quote_username`,
|
UPDATE `msz_chat_quotes`
|
||||||
`quote_user_colour`, `quote_timestamp`, `quote_text`
|
SET `quote_parent` = :parent,
|
||||||
) VALUES (
|
`quote_user_id` = :user_id,
|
||||||
:parent, :user_id, :username, :user_colour, :time, :text
|
`quote_username` = :username,
|
||||||
)
|
`quote_user_colour` = :user_colour,
|
||||||
');
|
`quote_timestamp` = :time,
|
||||||
|
`quote_text` = :text
|
||||||
|
WHERE `quote_id` = :id
|
||||||
|
');
|
||||||
|
$insert->bindValue('id', $quoteId);
|
||||||
|
} else {
|
||||||
|
$insert = db_prepare('
|
||||||
|
INSERT INTO `msz_chat_quotes` (
|
||||||
|
`quote_parent`, `quote_user_id`, `quote_username`,
|
||||||
|
`quote_user_colour`, `quote_timestamp`, `quote_text`
|
||||||
|
) VALUES (
|
||||||
|
:parent, :user_id, :username, :user_colour, :time, :text
|
||||||
|
)
|
||||||
|
');
|
||||||
|
}
|
||||||
|
|
||||||
$insert->bindValue('parent', $parent);
|
$insert->bindValue('parent', $parent < 1 ? null : $parent);
|
||||||
$insert->bindValue('user_id', $userId);
|
$insert->bindValue('user_id', $userId < 1 ? null : $userId);
|
||||||
$insert->bindValue('username', $username);
|
$insert->bindValue('username', $username);
|
||||||
$insert->bindValue('user_colour', $colour);
|
$insert->bindValue('user_colour', $colour);
|
||||||
$insert->bindValue('time', date('Y-m-d H:i:s', $time ?? time()));
|
$insert->bindValue('time', date('Y-m-d H:i:s', $time < 1 ? time() : $time));
|
||||||
$insert->bindValue('text', $text);
|
$insert->bindValue('text', $text);
|
||||||
|
|
||||||
return $insert->execute() ? db_last_insert_id() : 0;
|
return $insert->execute() ? db_last_insert_id() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function chat_quotes_count(bool $parentsOnly = false): int
|
||||||
|
{
|
||||||
|
return db_query(sprintf('
|
||||||
|
SELECT COUNT(`quote_id`)
|
||||||
|
FROM `msz_chat_quotes`
|
||||||
|
%s
|
||||||
|
', $parentsOnly ? 'WHERE `quote_parent` IS NULL' : ''))->fetchColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
function chat_quotes_single(int $quoteId): array
|
||||||
|
{
|
||||||
|
if ($quoteId < 1) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$getSingle = db_prepare('
|
||||||
|
SELECT `quote_id`, `quote_parent`, `quote_user_id`, `quote_username`, `quote_user_colour`, `quote_timestamp`, `quote_text`
|
||||||
|
FROM `msz_chat_quotes`
|
||||||
|
WHERE `quote_id` = :quote
|
||||||
|
');
|
||||||
|
$getSingle->bindValue('quote', $quoteId);
|
||||||
|
$single = $getSingle->execute() ? $getSingle->fetch(PDO::FETCH_ASSOC) : [];
|
||||||
|
return $single ? $single : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function chat_quotes_parents(int $offset = 0, int $take = MSZ_CHAT_QUOTES_TAKE): array
|
||||||
|
{
|
||||||
|
$getAll = $take < 1 || $offset < 0;
|
||||||
|
|
||||||
|
$getParents = db_prepare(sprintf('
|
||||||
|
SELECT `quote_id`, `quote_user_id`, `quote_username`, `quote_user_colour`, `quote_timestamp`, `quote_text`
|
||||||
|
FROM `msz_chat_quotes`
|
||||||
|
WHERE `quote_parent` IS NULL
|
||||||
|
ORDER BY `quote_id` DESC
|
||||||
|
%s
|
||||||
|
', $getAll ? '' : 'LIMIT :offset, :take'));
|
||||||
|
|
||||||
|
if (!$getAll) {
|
||||||
|
$getParents->bindValue('take', $take);
|
||||||
|
$getParents->bindValue('offset', $offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
$parents = $getParents->execute() ? $getParents->fetchAll() : [];
|
||||||
|
return $parents ? $parents : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function chat_quotes_set(int $parentId): array
|
||||||
|
{
|
||||||
|
$getParent = db_prepare('
|
||||||
|
SELECT `quote_id`, `quote_user_id`, `quote_username`, `quote_user_colour`, `quote_timestamp`, `quote_text`
|
||||||
|
FROM `msz_chat_quotes`
|
||||||
|
WHERE `quote_parent` IS NULL
|
||||||
|
AND `quote_id` = :parent
|
||||||
|
');
|
||||||
|
$getParent->bindValue('parent', $parentId);
|
||||||
|
$parent = $getParent->execute() ? $getParent->fetch(PDO::FETCH_ASSOC) : [];
|
||||||
|
return $parent ? array_merge([$parent], chat_quotes_children($parent['quote_id'])) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function chat_quotes_children(int $parentId): array
|
||||||
|
{
|
||||||
|
$getChildren = db_prepare('
|
||||||
|
SELECT `quote_id`, `quote_user_id`, `quote_username`, `quote_user_colour`, `quote_timestamp`, `quote_text`
|
||||||
|
FROM `msz_chat_quotes`
|
||||||
|
WHERE `quote_parent` = :parent
|
||||||
|
');
|
||||||
|
$getChildren->bindValue('parent', $parentId);
|
||||||
|
$children = $getChildren->execute() ? $getChildren->fetchAll(PDO::FETCH_ASSOC) : [];
|
||||||
|
return $children ? $children : [];
|
||||||
|
}
|
||||||
|
|
||||||
function chat_quotes_random(): array
|
function chat_quotes_random(): array
|
||||||
{
|
{
|
||||||
$quotes = [];
|
|
||||||
|
|
||||||
$parent = db_query('
|
$parent = db_query('
|
||||||
SELECT `quote_id`, `quote_user_id`, `quote_username`, `quote_user_colour`, `quote_timestamp`, `quote_text`
|
SELECT `quote_id`, `quote_user_id`, `quote_username`, `quote_user_colour`, `quote_timestamp`, `quote_text`
|
||||||
FROM `msz_chat_quotes`
|
FROM `msz_chat_quotes`
|
||||||
|
@ -37,27 +123,5 @@ function chat_quotes_random(): array
|
||||||
ORDER BY RAND()
|
ORDER BY RAND()
|
||||||
')->fetch(PDO::FETCH_ASSOC);
|
')->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if (!$parent) {
|
return $parent ? array_merge([$parent], chat_quotes_children($parent['quote_id'])) : [];
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$quotes[] = $parent;
|
|
||||||
|
|
||||||
$getChildren = db_prepare('
|
|
||||||
SELECT `quote_id`, `quote_user_id`, `quote_username`, `quote_user_colour`, `quote_timestamp`, `quote_text`
|
|
||||||
FROM `msz_chat_quotes`
|
|
||||||
WHERE `quote_parent` = :parent
|
|
||||||
');
|
|
||||||
$getChildren->bindValue('parent', $parent['quote_id']);
|
|
||||||
$children = $getChildren->execute() ? $getChildren->fetchAll(PDO::FETCH_ASSOC) : [];
|
|
||||||
|
|
||||||
if ($children) {
|
|
||||||
$quotes = array_merge($quotes, $children);
|
|
||||||
}
|
|
||||||
|
|
||||||
usort($quotes, function ($rowA, $rowB) {
|
|
||||||
return strcmp($rowA['quote_timestamp'], $rowB['quote_timestamp']);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $quotes;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ function manage_get_menu(int $userId): array
|
||||||
|
|
||||||
$menu = [];
|
$menu = [];
|
||||||
$menu['General']['Overview'] = '/manage/index.php?v=overview';
|
$menu['General']['Overview'] = '/manage/index.php?v=overview';
|
||||||
|
$menu['General']['Quotes'] = '/manage/index.php?v=quotes';
|
||||||
|
|
||||||
if (perms_check($perms['general'], MSZ_PERM_GENERAL_VIEW_LOGS)) {
|
if (perms_check($perms['general'], MSZ_PERM_GENERAL_VIEW_LOGS)) {
|
||||||
$menu['General']['Logs'] = '/manage/index.php?v=logs';
|
$menu['General']['Logs'] = '/manage/index.php?v=logs';
|
||||||
|
|
73
templates/manage/general/quotes.twig
Normal file
73
templates/manage/general/quotes.twig
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
{% extends 'manage/general/master.twig' %}
|
||||||
|
{% from 'home/macros.twig' import chat_quote_display %}
|
||||||
|
{% from 'macros.twig' import pagination %}
|
||||||
|
|
||||||
|
{% block manage_content %}
|
||||||
|
<div class="container container--new">
|
||||||
|
<div class="container__title">Quotes</div>
|
||||||
|
|
||||||
|
{% if current_quote is defined %}
|
||||||
|
<form method="post" action="">
|
||||||
|
{{ 'add_quote'|csrf|raw }}
|
||||||
|
<input type="hidden" name="quote[id]" value="{{ current_quote.quote_id|default(0) }}">
|
||||||
|
|
||||||
|
* = optional
|
||||||
|
|
||||||
|
<table style="color:inherit">
|
||||||
|
<tr>
|
||||||
|
<td>Parent ID*</td>
|
||||||
|
<td><input type="number" name="quote[parent]" value="{{ current_quote.quote_parent|default(quote_parent) }}" class="input__text input__text--new"></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>User ID*</td>
|
||||||
|
<td><input type="number" name="quote[user][id]" class="input__text input__text--new" value="{{ current_quote.quote_user_id|default(0) }}"></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Date/time*</td>
|
||||||
|
<td><input type="text" name="quote[time]" class="input__text input__text--new" value="{{ current_quote.quote_timestamp|default(0)|date('Y-m-d H:i:s') }}"></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Username</td>
|
||||||
|
<td><input type="text" required name="quote[user][name]" class="input__text input__text--new" value="{{ current_quote.quote_username|default() }}"></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>User Colour</td>
|
||||||
|
<td><input type="number" required name="quote[user][colour]" class="input__text input__text--new" value="{{ current_quote.quote_user_colour|default(constant('MSZ_COLOUR_INHERIT')) }}"></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<textarea name="quote[text]" required class="input__textarea input__textarea--new">{{ current_quote.quote_text|default() }}</textarea>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<button class="input__button input__button--new">Save</button>
|
||||||
|
</form>
|
||||||
|
{% elseif quote_set is defined %}
|
||||||
|
{{ chat_quote_display(quote_set) }}
|
||||||
|
|
||||||
|
<a href="?v=quotes&q=-1&s={{ quote_set[0].quote_id }}" class="input__button input__button--new">Add</a>
|
||||||
|
|
||||||
|
Edit:
|
||||||
|
{% for key, quote in quote_set %}
|
||||||
|
<a href="?v=quotes&q={{ quote.quote_id }}&s={{ quote_set[0].quote_id }}" class="input__button input__button--new">{{ key + 1 }} ({{ quote.quote_username }})</a>
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<a href="?v=quotes&q=-1" class="input__button input__button--new">Create</a>
|
||||||
|
|
||||||
|
{% for parent in quote_parents %}
|
||||||
|
<div class="container container--new">
|
||||||
|
<a href="?v=quotes&s={{ parent.quote_id }}" class="container__title container__title--link">{{ parent.quote_timestamp|date('Y-m-d') }}</a>
|
||||||
|
{{ chat_quote_display([parent]) }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{{ pagination(quote_count, 15, quote_offset, '?v=quotes') }}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
Add table
Reference in a new issue