Added field filtering to API endpoints and store colour presets in the database.

This commit is contained in:
flash 2025-03-28 01:47:08 +00:00
parent 12d40e69a5
commit a1398fb179
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
16 changed files with 727 additions and 117 deletions
public-legacy/manage/general

View file

@ -19,8 +19,8 @@ if(empty($emoteId))
else
try {
$isNew = false;
$emoteInfo = $msz->emotes->getEmote($emoteId);
$emoteStrings = iterator_to_array($msz->emotes->getEmoteStrings($emoteInfo));
$emoteInfo = $msz->emotesCtx->emotes->getEmote($emoteId);
$emoteStrings = iterator_to_array($msz->emotesCtx->emotes->getEmoteStrings($emoteInfo));
} catch(RuntimeException $ex) {
Template::throwError(404);
}
@ -33,7 +33,7 @@ while($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) {
$strings = explode(' ', !empty($_POST['em_strings']) && is_scalar($_POST['em_strings']) ? trim((string)$_POST['em_strings']) : '');
if($isNew || $url !== $emoteInfo->url) {
$checkUrl = $msz->emotes->checkEmoteUrl($url);
$checkUrl = $msz->emotesCtx->emotes->checkEmoteUrl($url);
if($checkUrl !== '') {
echo match($checkUrl) {
'empty' => 'URL may not be empty.',
@ -49,7 +49,7 @@ while($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) {
$order = null;
if($isNew) {
$emoteInfo = $msz->emotes->createEmote($url, $minRank, $order);
$emoteInfo = $msz->emotesCtx->emotes->createEmote($url, $minRank, $order);
} else {
if($order === $emoteInfo->order)
$order = null;
@ -59,7 +59,7 @@ while($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) {
$url = null;
if($order !== null || $minRank !== null || $url !== null)
$msz->emotes->updateEmote($emoteInfo, $order, $minRank, $url);
$msz->emotesCtx->emotes->updateEmote($emoteInfo, $order, $minRank, $url);
}
$sCurrent = XArray::select($emoteStrings, fn($stringInfo) => $stringInfo->string);
@ -69,16 +69,16 @@ while($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) {
foreach($sCurrent as $string)
if(!in_array($string, $sApply)) {
$sRemove[] = $string;
$msz->emotes->removeEmoteString($string);
$msz->emotesCtx->emotes->removeEmoteString($string);
}
$sCurrent = array_diff($sCurrent, $sRemove);
foreach($sApply as $string)
if(!in_array($string, $sCurrent)) {
$checkString = $msz->emotes->checkEmoteString($string);
$checkString = $msz->emotesCtx->emotes->checkEmoteString($string);
if($checkString === '') {
$msz->emotes->addEmoteString($emoteInfo, $string);
$msz->emotesCtx->emotes->addEmoteString($emoteInfo, $string);
} else {
echo match($checkString) {
'empty' => 'String may not be empty.',

View file

@ -13,26 +13,26 @@ if(CSRF::validateRequest() && !empty($_GET['emote'])) {
$emoteId = !empty($_GET['emote']) && is_scalar($_GET['emote']) ? (string)$_GET['emote'] : '';
try {
$emoteInfo = $msz->emotes->getEmote($emoteId);
$emoteInfo = $msz->emotesCtx->emotes->getEmote($emoteId);
} catch(RuntimeException $ex) {
Template::throwError(404);
}
if(!empty($_GET['delete'])) {
$msz->emotes->deleteEmote($emoteInfo);
$msz->emotesCtx->emotes->deleteEmote($emoteInfo);
$msz->createAuditLog('EMOTICON_DELETE', [$emoteInfo->id]);
} else {
if(isset($_GET['order'])) {
$order = !empty($_GET['order']) && is_scalar($_GET['order']) ? (string)$_GET['order'] : '';
$offset = $order === 'i' ? 10 : ($order === 'd' ? -10 : 0);
$msz->emotes->updateEmoteOrderOffset($emoteInfo, $offset);
$msz->emotesCtx->emotes->updateEmoteOrderOffset($emoteInfo, $offset);
$msz->createAuditLog('EMOTICON_ORDER', [$emoteInfo->id]);
}
if(isset($_GET['alias'])) {
$alias = !empty($_GET['alias']) && is_scalar($_GET['alias']) ? (string)$_GET['alias'] : '';
if($msz->emotes->checkEmoteString($alias) === '') {
$msz->emotes->addEmoteString($emoteInfo, $alias);
if($msz->emotesCtx->emotes->checkEmoteString($alias) === '') {
$msz->emotesCtx->emotes->addEmoteString($emoteInfo, $alias);
$msz->createAuditLog('EMOTICON_ALIAS', [$emoteInfo->id, $alias]);
}
}
@ -43,5 +43,5 @@ if(CSRF::validateRequest() && !empty($_GET['emote'])) {
}
Template::render('manage.general.emoticons', [
'emotes' => $msz->emotes->getEmotes(),
'emotes' => $msz->emotesCtx->emotes->getEmotes(),
]);