misuzu/public/manage/general/emoticon.php

51 lines
1.5 KiB
PHP
Raw Normal View History

2019-07-05 00:14:05 +00:00
<?php
namespace Misuzu;
2019-07-05 00:14:05 +00:00
require_once '../../../misuzu.php';
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), General::PERM_MANAGE_EMOTES)) {
2019-07-05 00:14:05 +00:00
echo render_error(403);
return;
}
$emoteId = !empty($_GET['e']) && is_string($_GET['e']) ? (int)$_GET['e'] : 0;
2019-12-09 02:41:34 +00:00
$isNew = $emoteId <= 0;
$emoteInfo = !$isNew ? Emoticon::byId($emoteId) : new Emoticon;
2019-07-05 00:14:05 +00:00
2019-12-11 18:10:54 +00:00
if(CSRF::validateRequest() && isset($_POST['emote_order']) && isset($_POST['emote_hierarchy']) && !empty($_POST['emote_url']) && !empty($_POST['emote_strings'])) {
2019-12-09 02:41:34 +00:00
$emoteInfo->setUrl($_POST['emote_url'])
->setHierarchy($_POST['emote_hierarchy'])
->setOrder($_POST['emote_order'])
->save();
if($isNew && !$emoteInfo->hasId())
throw new \Exception("SOMETHING HAPPENED");
$setStrings = array_column($emoteInfo->getStrings(), 'emote_string');
$applyStrings = explode(' ', mb_strtolower($_POST['emote_strings']));
$removeStrings = [];
foreach($setStrings as $string) {
if(!in_array($string, $applyStrings)) {
$removeStrings[] = $string;
}
}
2019-07-05 00:14:05 +00:00
2019-12-09 02:41:34 +00:00
$setStrings = array_diff($setStrings, $removeStrings);
foreach($applyStrings as $string) {
if(!in_array($string, $setStrings)) {
$setStrings[] = $string;
2019-07-05 00:14:05 +00:00
}
}
2019-12-09 02:41:34 +00:00
foreach($removeStrings as $string)
$emoteInfo->removeString($string);
foreach($setStrings as $string)
$emoteInfo->addString($string);
2019-07-05 00:14:05 +00:00
}
Template::render('manage.general.emoticon', [
2019-12-09 02:41:34 +00:00
'emote_info' => $emoteInfo,
2019-07-05 00:14:05 +00:00
]);