2022-09-13 13:14:49 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu;
|
|
|
|
|
2023-07-12 21:52:55 +00:00
|
|
|
use RuntimeException;
|
2023-08-05 13:50:15 +00:00
|
|
|
use Index\XArray;
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
if(!$msz->authInfo->getPerms('global')->check(Perm::G_EMOTES_MANAGE))
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(403);
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2023-07-12 21:52:55 +00:00
|
|
|
$emoteId = (string)filter_input(INPUT_GET, 'e', FILTER_SANITIZE_NUMBER_INT);
|
2023-11-26 22:23:47 +00:00
|
|
|
$emoteInfo = [];
|
|
|
|
$emoteStrings = [];
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2023-07-12 21:52:55 +00:00
|
|
|
if(empty($emoteId))
|
|
|
|
$isNew = true;
|
|
|
|
else
|
|
|
|
try {
|
|
|
|
$isNew = false;
|
2024-11-30 04:09:29 +00:00
|
|
|
$emoteInfo = $msz->emotes->getEmote($emoteId);
|
|
|
|
$emoteStrings = iterator_to_array($msz->emotes->getEmoteStrings($emoteInfo));
|
2023-07-12 21:52:55 +00:00
|
|
|
} catch(RuntimeException $ex) {
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(404);
|
2023-07-12 21:52:55 +00:00
|
|
|
}
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2023-07-12 21:52:55 +00:00
|
|
|
// make errors not echos lol
|
|
|
|
while($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) {
|
|
|
|
$order = (int)filter_input(INPUT_POST, 'em_order', FILTER_SANITIZE_NUMBER_INT);
|
|
|
|
$minRank = (int)filter_input(INPUT_POST, 'em_minrank', FILTER_SANITIZE_NUMBER_INT);
|
|
|
|
$url = trim((string)filter_input(INPUT_POST, 'em_url'));
|
|
|
|
$strings = explode(' ', trim((string)filter_input(INPUT_POST, 'em_strings')));
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
if($isNew || $url !== $emoteInfo->url) {
|
|
|
|
$checkUrl = $msz->emotes->checkEmoteUrl($url);
|
2023-07-12 21:52:55 +00:00
|
|
|
if($checkUrl !== '') {
|
|
|
|
echo match($checkUrl) {
|
|
|
|
'empty' => 'URL may not be empty.',
|
|
|
|
'spaces' => 'URL may not end or start with spaces.',
|
|
|
|
'used' => 'This URL already belongs to another emoticon.',
|
|
|
|
default => 'URL cannot be accepted: ' . $checkUrl,
|
|
|
|
};
|
|
|
|
break;
|
2022-09-13 13:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-12 21:52:55 +00:00
|
|
|
if($order == 0)
|
|
|
|
$order = null;
|
|
|
|
|
|
|
|
if($isNew) {
|
2024-11-30 04:09:29 +00:00
|
|
|
$emoteInfo = $msz->emotes->createEmote($url, $minRank, $order);
|
2023-07-12 21:52:55 +00:00
|
|
|
} else {
|
2024-11-30 04:09:29 +00:00
|
|
|
if($order === $emoteInfo->order)
|
2023-07-12 21:52:55 +00:00
|
|
|
$order = null;
|
2024-11-30 04:09:29 +00:00
|
|
|
if($minRank === $emoteInfo->minRank)
|
2023-07-12 21:52:55 +00:00
|
|
|
$minRank = null;
|
2024-11-30 04:09:29 +00:00
|
|
|
if($url === $emoteInfo->url)
|
2023-07-12 21:52:55 +00:00
|
|
|
$url = null;
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2023-07-15 02:05:49 +00:00
|
|
|
if($order !== null || $minRank !== null || $url !== null)
|
2024-11-30 04:09:29 +00:00
|
|
|
$msz->emotes->updateEmote($emoteInfo, $order, $minRank, $url);
|
2022-09-13 13:14:49 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
$sCurrent = XArray::select($emoteStrings, fn($stringInfo) => $stringInfo->string);
|
2023-07-12 21:52:55 +00:00
|
|
|
$sApply = $strings;
|
|
|
|
$sRemove = [];
|
|
|
|
|
|
|
|
foreach($sCurrent as $string)
|
|
|
|
if(!in_array($string, $sApply)) {
|
|
|
|
$sRemove[] = $string;
|
2024-11-30 04:09:29 +00:00
|
|
|
$msz->emotes->removeEmoteString($string);
|
2023-07-12 21:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$sCurrent = array_diff($sCurrent, $sRemove);
|
|
|
|
|
|
|
|
foreach($sApply as $string)
|
|
|
|
if(!in_array($string, $sCurrent)) {
|
2024-11-30 04:09:29 +00:00
|
|
|
$checkString = $msz->emotes->checkEmoteString($string);
|
2023-07-12 21:52:55 +00:00
|
|
|
if($checkString === '') {
|
2024-11-30 04:09:29 +00:00
|
|
|
$msz->emotes->addEmoteString($emoteInfo, $string);
|
2023-07-12 21:52:55 +00:00
|
|
|
} else {
|
|
|
|
echo match($checkString) {
|
|
|
|
'empty' => 'String may not be empty.',
|
|
|
|
'spaces' => 'String may not end or start with spaces.',
|
|
|
|
'case' => 'String must be lowercase.',
|
|
|
|
'format' => 'String must follow proper formatting.',
|
|
|
|
'used' => 'This string has already been used for another emoticon.',
|
|
|
|
default => 'String cannot be accepted: ' . $checkString,
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sCurrent[] = $string;
|
|
|
|
}
|
|
|
|
|
2023-07-17 17:43:17 +00:00
|
|
|
$msz->createAuditLog(
|
|
|
|
$isNew ? 'EMOTICON_CREATE' : 'EMOTICON_EDIT',
|
2024-11-30 04:09:29 +00:00
|
|
|
[$emoteInfo->id]
|
2023-07-15 02:05:49 +00:00
|
|
|
);
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
Tools::redirect($msz->urls->format('manage-general-emoticon', ['emote' => $emoteInfo->id]));
|
2023-08-05 13:50:15 +00:00
|
|
|
return;
|
2022-09-13 13:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Template::render('manage.general.emoticon', [
|
2023-07-12 21:52:55 +00:00
|
|
|
'emote_new' => $isNew,
|
2023-11-26 22:23:47 +00:00
|
|
|
'emote_info' => $emoteInfo,
|
|
|
|
'emote_strings' => $emoteStrings,
|
2022-09-13 13:14:49 +00:00
|
|
|
]);
|