misuzu/public-legacy/manage/general/emoticon.php
flash 383e2ed0e0 Rewrote the user information class.
This one took multiple days and it pretty invasive into the core of Misuzu so issue might (will) arise, there's also some features that have gone temporarily missing in the mean time and some inefficiencies introduced that will be fixed again at a later time.
The old class isn't gone entirely because I still have to figure out what I'm gonna do about validation, but for the most part this knocks out one of the "layers of backwards compatibility", as I've been referring to it, and is moving us closer to a future where Flashii actually gets real updates.
If you run into anything that's broken and you're inhibited from reporting it through the forum, do it through chat or mail me at flashii-issues@flash.moe.
2023-08-02 22:12:47 +00:00

111 lines
3.5 KiB
PHP

<?php
namespace Misuzu;
use RuntimeException;
if(!$msz->isLoggedIn() || !perms_check_user(MSZ_PERMS_GENERAL, $msz->getActiveUser()->getId(), MSZ_PERM_GENERAL_MANAGE_EMOTES)) {
echo render_error(403);
return;
}
$emotes = $msz->getEmotes();
$emoteId = (string)filter_input(INPUT_GET, 'e', FILTER_SANITIZE_NUMBER_INT);
$loadEmoteInfo = fn() => $emotes->getEmoteById($emoteId, true);
if(empty($emoteId))
$isNew = true;
else
try {
$isNew = false;
$emoteInfo = $loadEmoteInfo();
} catch(RuntimeException $ex) {
echo render_error(404);
return;
}
// 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')));
if($isNew || $url !== $emoteInfo->getUrl()) {
$checkUrl = $emotes->checkEmoteUrl($url);
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;
}
}
if($order == 0)
$order = null;
if($isNew) {
$emoteInfo = $emotes->createEmote($url, $minRank, $order);
} else {
if($order === $emoteInfo->getOrder())
$order = null;
if($minRank === $emoteInfo->getMinRank())
$minRank = null;
if($url === $emoteInfo->getUrl())
$url = null;
if($order !== null || $minRank !== null || $url !== null)
$emotes->updateEmote($emoteInfo, $order, $minRank, $url);
}
$sCurrent = $emoteInfo->getStringsRaw();
$sApply = $strings;
$sRemove = [];
foreach($sCurrent as $string)
if(!in_array($string, $sApply)) {
$sRemove[] = $string;
$emotes->removeEmoteString($string);
}
$sCurrent = array_diff($sCurrent, $sRemove);
foreach($sApply as $string)
if(!in_array($string, $sCurrent)) {
$checkString = $emotes->checkEmoteString($string);
if($checkString === '') {
$emotes->addEmoteString($emoteInfo, $string);
} 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;
}
$msz->createAuditLog(
$isNew ? 'EMOTICON_CREATE' : 'EMOTICON_EDIT',
[$emoteInfo->getId()]
);
if($isNew) {
url_redirect('manage-general-emoticon', ['emote' => $emoteInfo->getId()]);
return;
} else $emoteInfo = $loadEmoteInfo();
break;
}
Template::render('manage.general.emoticon', [
'emote_new' => $isNew,
'emote_info' => $emoteInfo ?? null,
]);