WowPress-Tailwind/theme/request.php

415 lines
16 KiB
PHP
Raw Normal View History

2024-04-15 23:07:29 +02:00
<?php
require_once('vendor/autoload.php');
use Illuminate\Support\Facades\Redirect;
2024-08-07 22:34:54 +02:00
use Wenprise\Eloquent\Database;
use Wenprise\Eloquent\Facades\DB;
use Wenprise\Eloquent\Model;
2024-04-15 23:07:29 +02:00
use WoWPress\Models\Character;
2024-08-07 22:34:54 +02:00
use WoWPress\Models\CharacterList;
use WoWPress\Models\CharacterListItem;
use WoWPress\Models\Complaint;
use WoWPress\Models\Log;
2024-06-27 23:06:15 +02:00
use WoWPress\Models\Notification;
2024-04-23 00:44:42 +02:00
use WoWPress\Models\Raid;
use WoWPress\Models\Signup;
2024-04-23 22:43:54 +02:00
use WoWPress\Models\SKS;
2024-09-20 20:02:10 +02:00
use WoWPress\Models\SKSHistory;
2024-04-22 15:38:22 +02:00
use WoWPress\Models\User;
2024-04-15 23:07:29 +02:00
if (empty($_POST['action'])) {
exit(404);
}
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php')) {
/** Loads the WordPress Environment and Template */
require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php');
}
switch ($_POST['action']) {
case 'addCharacter':
2024-04-22 15:38:22 +02:00
isAllowed('wowpress_edit_characters');
if (isset($_POST['addCharacter_nonce']) && wp_verify_nonce($_POST['addCharacter_nonce'], 'addCharacter')) {
if (isset($_POST['name']) && isset($_POST['realm'])) {
$char = Character::whereName($_POST['name'])->whereRealm($_POST['realm'])->first();
if (empty($char->ID)) {
$char = new Character();
$char->name = $_POST['name'];
$char->realm = $_POST['realm'];
2024-11-02 20:27:01 +01:00
$char->save();
2024-04-22 15:38:22 +02:00
$char->updateFromAPI();
$char->updateMedia();
2024-04-15 23:07:29 +02:00
}
}
}
break;
case 'deleteCharacter':
2024-04-22 15:38:22 +02:00
isAllowed('wowpress_edit_characters');
if (isset($_POST['deleteCharacter_nonce']) && wp_verify_nonce($_POST['deleteCharacter_nonce'], 'deleteCharacter')) {
if (isset($_POST['id'])) {
$char = Character::find($_POST['id']);
if ($char->ID) {
$char->delete();
2024-04-15 23:07:29 +02:00
}
}
}
break;
case 'updateCharacter':
2024-04-22 15:38:22 +02:00
isAllowed('wowpress_edit_characters');
if (isset($_POST['updateCharacter_nonce']) && wp_verify_nonce($_POST['updateCharacter_nonce'], 'updateCharacter')) {
if (isset($_POST['id'])) {
$char = Character::find($_POST['id']);
if ($char->ID) {
$char->updateFromAPI();
$char->updateMedia();
}
}
}
break;
2024-04-23 00:44:42 +02:00
case 'toggleRaidchar':
isAllowed('wowpress_edit_characters');
if (isset($_POST['toggleRaidchar_nonce']) && wp_verify_nonce($_POST['toggleRaidchar_nonce'], 'toggleRaidchar')) {
if (isset($_POST['id'])) {
$char = Character::find($_POST['id']);
if ($char->ID) {
$char->raidchar = !$char->raidchar;
$char->save();
}
}
}
break;
2024-04-22 15:38:22 +02:00
case 'changeUser':
isAllowed('wowpress_edit_characters');
if (isset($_POST['changeUser_nonce']) && wp_verify_nonce($_POST['changeUser_nonce'], 'changeUser')) {
if (isset($_POST['char_id']) && isset($_POST['uid'])) {
$char = Character::find($_POST['char_id']);
$user = User::find($_POST['uid']);
if (!empty($char->ID)) {
if (empty($user->ID)) {
$char->user_id = null;
$char->save();
} else
$char->user_id = $user->ID;
$char->save();
2024-04-15 23:07:29 +02:00
}
}
}
break;
2024-04-23 00:44:42 +02:00
case 'importRaid':
isAllowed('wowpress_edit_raids');
if (isset($_POST['importRaid_nonce']) && wp_verify_nonce($_POST['importRaid_nonce'], 'importRaid')) {
if (isset($_POST['id_wowaudit'])) {
2024-04-23 22:43:54 +02:00
if (!empty(Raid::where('id_wowaudit', $_POST['id_wowaudit'])->first())) {
2024-04-23 00:44:42 +02:00
break;
}
$raid = new Raid();
$raid->id_wowaudit = $_POST['id_wowaudit'];
2024-04-23 22:43:54 +02:00
2024-04-23 00:44:42 +02:00
$raid->sync();
2024-04-23 22:43:54 +02:00
if (!empty($raid->title)) {
2024-04-23 00:44:42 +02:00
$raid->save();
}
}
}
break;
case 'signupRaid':
isAllowed('wowpress_view_raids');
if (isset($_POST['signupRaid_nonce']) && wp_verify_nonce($_POST['signupRaid_nonce'], 'signupRaid')) {
if (isset($_POST['raid_id']) && isset($_POST['raid_character']) && isset($_POST['raid_status']) && isset($_POST['raid_role']) && isset($_POST['comment'])) {
$char = Character::find($_POST['raid_character']);
$raid = Raid::find($_POST['raid_id']);
if ($char->can_edit) {
if (!$char->id_wowaudit) {
$cw = $char->user->characters()->whereNot('id_wowaudit', 'NULL')->first();
if (empty($cw->ID)) {
break;
}
} else {
$cw = $char;
}
$comment = htmlentities2($_POST['comment']);
$signup = new Signup();
$signup->raid_id = $raid->ID;
$signup->character_id = $cw->ID;
$signup->setStatus($_POST['raid_status']);
$signup->setRole($_POST['raid_role']);
$signup->comment = $comment;
$sup = $signup->updateAPI($char);
if (!empty($sup['error'])) {
dd($sup);
}
$raid->sync(true);
$raid->save();
}
}
}
break;
2024-09-20 20:02:10 +02:00
case 'createSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['createSKS_nonce']) && wp_verify_nonce($_POST['createSKS_nonce'], 'createSKS')) {
if(isset($_POST['list_name'])){
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
break;
}
$list = new SKSHistory();
$list->list_name = $_POST['list_name'];
$list->active = true;
$list->fillWithRaiders();
$list->save();
}
}
break;
2024-04-23 22:43:54 +02:00
case 'addSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['addSKS_nonce']) && wp_verify_nonce($_POST['addSKS_nonce'], 'addSKS')) {
if (isset($_POST['name']) && isset($_POST['realm']) && isset($_POST['list_name'])) {
2024-09-20 20:02:10 +02:00
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->addChar($_POST['name'],$_POST['realm']);
2024-04-23 22:43:54 +02:00
}
}
}
break;
case 'toggleSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['toggleSKS_nonce']) && wp_verify_nonce($_POST['toggleSKS_nonce'], 'toggleSKS')) {
2024-09-20 20:02:10 +02:00
if (isset($_POST['list_name']) && isset($_POST['rank'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->toggleActive($_POST['rank']);
2024-04-23 22:43:54 +02:00
}
}
}
break;
case 'deleteSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['deleteSKS_nonce']) && wp_verify_nonce($_POST['deleteSKS_nonce'], 'deleteSKS')) {
2024-09-20 20:02:10 +02:00
if (isset($_POST['list_name']) && isset($_POST['char'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->removeChar($_POST['char']);
2024-04-23 22:43:54 +02:00
}
}
}
break;
case 'lootSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['lootSKS_nonce']) && wp_verify_nonce($_POST['lootSKS_nonce'], 'lootSKS')) {
2024-09-20 20:02:10 +02:00
if (isset($_POST['list_name']) && isset($_POST['char'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->loot($_POST['char']);
2024-04-23 22:43:54 +02:00
}
}
}
break;
2024-09-20 20:02:10 +02:00
case 'undoSKS':
2024-05-02 21:29:31 +02:00
isAllowed('wowpress_edit_raids');
2024-09-20 20:02:10 +02:00
if (isset($_POST['undoSKS_nonce']) && wp_verify_nonce($_POST['undoSKS_nonce'], 'undoSKS')) {
2024-05-02 21:29:31 +02:00
if (isset($_POST['list_name'])) {
2024-09-20 20:02:10 +02:00
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->undo();
2024-05-02 21:29:31 +02:00
}
}
}
break;
2024-09-20 20:02:10 +02:00
case 'redoSKS':
2024-05-02 21:29:31 +02:00
isAllowed('wowpress_edit_raids');
2024-09-20 20:02:10 +02:00
if (isset($_POST['redoSKS_nonce']) && wp_verify_nonce($_POST['redoSKS_nonce'], 'redoSKS')) {
if (isset($_POST['list_name'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->redo();
}
}
}
break;
case 'rollSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['rollSKS_nonce']) && wp_verify_nonce($_POST['rollSKS_nonce'], 'rollSKS')) {
if (isset($_POST['list_name'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->shuffle();
2024-04-23 22:43:54 +02:00
}
}
2024-05-02 21:29:31 +02:00
}
break;
case 'addComplaint':
isAllowed('wowpress_view_complaints');
if (isset($_POST['addComplaint_nonce']) && wp_verify_nonce($_POST['addComplaint_nonce'], 'addComplaint')) {
if (isset($_POST['complaint'])) {
$c = new Complaint();
$c->user_id = get_current_user_id();
$c->complaint = $_POST['complaint'];
$c->anonymous = !empty($_POST['hide']);
$c->save();
2024-08-07 22:34:54 +02:00
Notification::addCapabilityNotification("wowpress_edit_complaints", "Neuer Eintrag im Kummerkasten!");
}
}
break;
case 'commentComplaint':
isAllowed('wowpress_edit_complaints');
if (isset($_POST['commentComplaint_nonce']) && wp_verify_nonce($_POST['commentComplaint_nonce'], 'commentComplaint')) {
if (isset($_POST['complaint_id']) && isset($_POST['user_comment'])) {
$c = Complaint::find($_POST['complaint_id']);
if ($c) {
$c->user_comment = $_POST['user_comment'];
$c->save();
2024-06-27 23:06:15 +02:00
Notification::addNotification($c->user_id, "Neuer Kommentar im Kummerkasten!");
}
}
}
break;
case 'unhideComplaint':
isAllowed('wowpress_view_complaints');
if (isset($_POST['unhideComplaint_nonce']) && wp_verify_nonce($_POST['unhideComplaint_nonce'], 'unhideComplaint')) {
if (isset($_POST['complaint_id'])) {
$c = Complaint::find($_POST['complaint_id']);
if ($c && $c->user_id == get_current_user_id()) {
$c->anonymous = false;
$c->save();
}
}
}
break;
case 'slanderComplaint':
isAllowed('wowpress_edit_complaints');
if (isset($_POST['slanderComplaint_nonce']) && wp_verify_nonce($_POST['slanderComplaint_nonce'], 'slanderComplaint')) {
if (isset($_POST['complaint_id']) && isset($_POST['admin_comment'])) {
$c = Complaint::find($_POST['complaint_id']);
if ($c) {
$c->admin_comment = $_POST['admin_comment'];
$c->save();
}
}
}
break;
case 'trashComplaint':
isAllowed('wowpress_view_complaints');
if (isset($_POST['trashComplaint_nonce']) && wp_verify_nonce($_POST['trashComplaint_nonce'], 'trashComplaint')) {
if (isset($_POST['complaint_id'])) {
$c = Complaint::find($_POST['complaint_id']);
if ($c && $c->canTrash()) {
$c->trash();
}
}
}
break;
case 'restoreComplaint':
isAllowed('wowpress_edit_complaints');
if (isset($_POST['restoreComplaint_nonce']) && wp_verify_nonce($_POST['restoreComplaint_nonce'], 'restoreComplaint')) {
if (isset($_POST['complaint_id'])) {
$c = Complaint::find($_POST['complaint_id']);
if ($c) {
$c->restore();
}
}
}
break;
case 'deleteComplaint':
isAllowed('wowpress_edit_complaints');
if (isset($_POST['deleteComplaint_nonce']) && wp_verify_nonce($_POST['deleteComplaint_nonce'], 'deleteComplaint')) {
if (isset($_POST['complaint_id'])) {
$c = Complaint::find($_POST['complaint_id']);
if ($c) {
Log::write(json_encode(['user' => get_current_user_id(), 'complaint_by' => $c->user_id]), Log::LOG_COMPLAINT_DELETE);
$c->delete();
}
}
}
break;
2024-06-27 23:06:15 +02:00
case 'notificationSeen':
if (is_user_logged_in()) {
if (isset($_POST['notificationSeen_nonce']) && wp_verify_nonce($_POST['notificationSeen_nonce'], 'notificationSeen')) {
if (isset($_POST['notification_id'])) {
$note = Notification::find($_POST['notification_id']);
2024-08-05 20:19:44 +02:00
if (!empty($note->ID && $note->user_id == get_current_user_id())) {
2024-06-27 23:06:15 +02:00
$note->delete();
}
}
}
}
break;
2024-08-05 20:19:44 +02:00
case 'updatePageBG':
isAllowed('wowpress_edit_site');
if (isset($_POST['updatePageBG_nonce']) && wp_verify_nonce($_POST['updatePageBG_nonce'], 'updatePageBG')) {
2024-08-07 22:34:54 +02:00
if (isset($_FILES['bg']) && $_FILES['bg']['type'] == "image/jpeg") {
$bg_path = ABSPATH . "/wp-content/bg.jpg";
rename($_FILES['bg']['tmp_name'], $bg_path);
chmod(ABSPATH . "/wp-content/bg.jpg", 0644);
2024-08-05 20:19:44 +02:00
}
}
break;
case 'updateRaidTitle':
isAllowed('wowpress_edit_raids');
if (isset($_POST['updateRaidTitle_nonce']) && wp_verify_nonce($_POST['updateRaidTitle_nonce'], 'updateRaidTitle')) {
2024-08-07 22:34:54 +02:00
if (isset($_POST['raid_id']) && isset($_POST['name'])) {
2024-08-05 20:19:44 +02:00
$raid = Raid::find($_POST['raid_id']);
2024-08-07 22:34:54 +02:00
if ($raid) {
2024-08-05 20:19:44 +02:00
$raid->setTitle($_POST['name']);
}
}
}
2024-08-07 22:34:54 +02:00
case 'addList':
isAllowed('wowpress_edit_raids');
2024-09-20 20:02:10 +02:00
if (checkNonce('addList')) {
if (isset($_POST['list_name'], $_POST['border_color'])) {
2024-08-07 22:34:54 +02:00
$list = new CharacterList();
$list->list_name = $_POST['list_name'];
$list->border_color = $_POST['border_color'];
$list->notify = !empty($_POST['notify']);
$list->max_count = 18;
$list->save();
}
}
case 'addCharToList':
isAllowed('wowpress_edit_raids');
if (isset($_POST['addCharToList_nonce']) && wp_verify_nonce($_POST['addCharToList_nonce'], 'addCharToList')) {
2024-09-20 20:02:10 +02:00
if (isset($_POST['character_ID']) && isset($_POST['list_id'])) {
2024-08-07 22:34:54 +02:00
$list = CharacterList::find($_POST['list_id']);
$char = Character::find($_POST['character_ID']);
2024-09-20 20:02:10 +02:00
if ($char && $list) {
2024-08-07 22:34:54 +02:00
$comment = "";
$date = date('Y-m-d');
2024-09-20 20:02:10 +02:00
if (!empty($_POST['comment'])) {
2024-08-07 22:34:54 +02:00
$comment = $_POST['comment'];
}
2024-09-20 20:02:10 +02:00
if (!empty($_POST['date'])) {
2024-08-07 22:34:54 +02:00
$date = $_POST['date'];
}
2024-09-20 20:02:10 +02:00
$list->addItem($char, $comment, $date);
2024-08-07 22:34:54 +02:00
}
}
}
break;
case 'removeListItem':
isAllowed('wowpress_edit_raids');
2024-09-20 20:02:10 +02:00
if (checkNonce('removeListItem')) {
if (isset($_POST['item_id'])) {
2024-08-07 22:34:54 +02:00
$item_id = intval($_POST['item_id']);
$item = CharacterListItem::find($item_id);
2024-09-20 20:02:10 +02:00
if ($item) {
2024-08-07 22:34:54 +02:00
$item->delete();
2024-09-20 20:02:10 +02:00
#CharacterListItem::deleteOrphans();
2024-08-07 22:34:54 +02:00
}
2024-09-20 20:02:10 +02:00
}
2024-08-07 22:34:54 +02:00
}
break;
case 'cron':
2024-09-20 20:02:10 +02:00
if (isset($_POST['cron'])) {
switch ($_POST['cron']) {
2024-08-07 22:34:54 +02:00
case 'update_applications':
2024-08-05 20:19:44 +02:00
2024-08-07 22:34:54 +02:00
break;
}
}
break;
2024-04-15 23:07:29 +02:00
}
header('Location: ' . $_SERVER['HTTP_REFERER']);