Kummerkasten und kleinere Schönheits-OPs

master
Seph 2024-06-20 21:42:05 +02:00
parent 53062fbae1
commit 0c58c8dbaa
11 changed files with 352 additions and 6 deletions

View File

@ -4,7 +4,7 @@ Theme URI: https://nebelkrieger.de
Author: Yorndar
Author URI: https://nebelkrieger.de
Description: The next gen NK-Theme
Version: 0.3.5
Version: 0.4.0
Tested up to: 6.2
Requires PHP: 8.0
License: GNU General Public License v2 or later

View File

@ -70,15 +70,16 @@
body {
background-color: unset;
--body-bg: url('https://bnetcmsus-a.akamaihd.net/cms/blog_header/3i/3ITOIMA3P61U1699028715242.png');
--body-bg: url('https://sephger.de/nkbg.png');
position: relative;
z-index: -10;
@apply min-h-screen;
}
.bg-glass {
@apply backdrop-blur-md;
background-color: var(--color-glass);
backdrop-filter: blur(10px);
}
.shadow {

View File

@ -2,6 +2,7 @@
use WoWPress\Database\CreateCacheTable;
use WoWPress\Database\CreateCharacterTable;
use WoWPress\Database\CreateComplaintTable;
use WoWPress\Database\CreateLogTable;
use WoWPress\Database\CreateRaidTable;
use WoWPress\Database\CreateSignupTable;
@ -159,6 +160,8 @@ if (!function_exists('wowpress_database')) :
CreateSignupTable::sql(),
CreateSKSTable::sql(),
CreateLogTable::sql(),
CreateComplaintTable::sql(),
]);
}

View File

@ -39,6 +39,9 @@ function set_roles()
$admin->add_cap('wowpress_view_raids');
$admin->add_cap('wowpress_view_teamspeak');
$admin->add_cap('wowpress_view_birthdays');
$admin->add_cap('wowpress_view_complaints');
$admin->add_cap('wowpress_edit_complaints');
foreach (get_role('administrator')->capabilities as $cap => $status) {
@ -64,6 +67,12 @@ function set_roles()
$novize->add_cap('wowpress_view_birthdays');
$ff->add_cap('wowpress_view_birthdays');
$rl->add_cap('wowpress_view_complaints');
$raider->add_cap('wowpress_view_complaints');
$novize->add_cap('wowpress_view_complaints');
$ff->add_cap('wowpress_view_complaints');
}

View File

@ -15,6 +15,8 @@ add_filter('generate_rewrite_rules', function ($wp_rewrite) {
['sks/?$' => 'index.php?wowpress_page=sks'],
['sks/([A-Za-z-0-9 ]+)?$' => 'index.php?wowpress_page=sks&list_name=$matches[1]'],
['logs/?$' => 'index.php?wowpress_page=logs'],
['kummerkasten/?$' => 'index.php?wowpress_page=complaints'],
['kummerkasten/(\d+)/?$' => 'index.php?wowpress_page=complaints&complaint_id=$matches[1]'],
$wp_rewrite->rules
);
@ -26,6 +28,7 @@ add_filter('query_vars', function ($query_vars) {
$query_vars[] = 'month';
$query_vars[] = 'raid_id';
$query_vars[] = 'list_name';
$query_vars[] = 'complaint_id';
return $query_vars;
@ -38,6 +41,12 @@ add_action('template_redirect', function () {
switch ($page) {
case 'complaints':
isAllowed('wowpress_view_complaints');
$GLOBALS['wowpress']['page_title'] = "Kummerkasten";
include plugin_dir_path(__FILE__) . '../pages/complaints.php';
die;
break;
case 'roster':
$GLOBALS['wowpress']['page_title'] = "Gildenverzeichnis";
include plugin_dir_path(__FILE__) . '../pages/roster.php';

View File

@ -0,0 +1,182 @@
<?php
use Illuminate\Support\Facades\Auth;
use WoWPress\Frontend\Icon;
use WoWPress\Models\Complaint;
use WoWPress\Models\User;
set_sidebar_status('top', false);
get_header();
$can_edit = current_user_can('wowpress_edit_complaints');
$forceShow = false;
$complaints = Complaint::getAll();
#$complaints = [];
?>
<section id="primary" style="margin-top:calc(-1 * var(--wowp-gap))">
<main id="main">
<div class="bg-black bg-opacity-60 backdrop-blur-md shadow p-auto text-center flex flex-col gap-2">
<h2 class="text-3xl font-bold">Willkommen in unserem Kummerkasten</h2>
<p>
Du hast etwas auf dem Herzen, möchtest deinem Ärger Luft machen oder uns einfach nur so etwas mitteilen?<br>
Dann ist hier der richtige Ort dafür!
</p>
<p>
Keiner außer dir (und den Offis) kann sehen was du hier schreibst.
</p>
<p>
Wenn du "unerkannt" bleiben möchtest kannst du das Formular auch "anonym" absenden. Allerdings kann man in der Datenbank trotzdem sehen wer das Formular abgeschickt hat, um Missbrauch zu vermeiden.<br>
Hier musst du darauf vertrauen, dass der Webseiten-Gott nicht so gemein ist und in der Datenbank auf die Suche geht. Normalsterbliche Offis können allerdings nicht sehen wer das Formular abgeschickt hat.
</p>
</div>
<?php if (!$can_edit || true) : ?>
<form id="addComplaint" method="POST" action="/request" class="hidden">
<input type="hidden" name="action" value="addComplaint">
<?php wp_nonce_field('addComplaint', 'addComplaint_nonce'); ?>
</form>
<div class="bg-black bg-opacity-60 backdrop-blur-md shadow p-auto flex flex-col gap-2">
<h3 class="text-2xl font-bold text-center">Neue Einsendung</h3>
<textarea form="addComplaint" name="complaint" id="complaint" class="bg-black bg-opacity-60 backdrop-blur-md text-white border-white focus:ring-alliance focus:border-alliance" rows="5"></textarea>
<div class="flex flex-row gap-2">
<button form="addComplaint" type="submit" name="show" value="1" class="btn btn-outline btn-alliance flex-grow bg-black bg-opacity-60 backdrop-blur-md">Absenden <?= Icon::get('o-paper-airplane') ?></button>
<button form="addComplaint" type="submit" name="hide" value="1" class="btn btn-outline btn-alliance flex-grow bg-black bg-opacity-60 backdrop-blur-md">Anonym senden <?= Icon::get('o-paper-airplane') ?></button>
</div>
</div>
<?php endif; ?>
<?php if (!empty($complaints->first())) : ?>
<div class="bg-black bg-opacity-60 backdrop-blur-md shadow p-auto flex flex-col gap-2">
<h3 class="text-2xl font-bold text-center">Einsendungen</h3>
</div>
<?php
foreach ($complaints as $complaint) :
?>
<form id="trashComplaint<?= $complaint->ID ?>" method="POST" action="/request" class="hidden">
<input type="hidden" name="action" value="trashComplaint">
<input type="hidden" name="complaint_id" value="<?= $complaint->ID ?>">
<?php wp_nonce_field('trashComplaint', 'trashComplaint_nonce'); ?>
</form>
<div class="shadow p-auto flex flex-col gap-2 <?= $complaint->deleted_at ? "border border-dashed border-white bg-green-800 bg-opacity-60 backdrop-blur-md" : "bg-black bg-opacity-60 backdrop-blur-md" ?>">
<?php if ($complaint->deleted_at) : ?>
<div class="text-end">Eintrag gelöscht</div>
<?php endif; ?>
<div class="flex flex-col gap-2">
<div class="flex flex-col xl:flex-row gap-2 items-stretch">
<?php
if ($complaint->canEdit() && (!$complaint->anonymous || $forceShow)) :
?>
<div class="flex flex-col items-center">
<img src="<?= $complaint->user->avatar ?>" alt="" class="">
<div class="p-2 bg-glass w-full text-center"><?= $complaint->user->user_name ?></div>
</div>
<?php
endif;
if (!$complaint->canEdit() && $complaint->anonymous) :
?>
<form id="unhideComplaint<?= $complaint->ID ?>" method="POST" action="/request" class="hidden">
<input type="hidden" name="action" value="unhideComplaint">
<input type="hidden" name="complaint_id" value="<?= $complaint->ID ?>">
<?php wp_nonce_field('unhideComplaint', 'unhideComplaint_nonce'); ?>
</form>
<button type="submit" form="unhideComplaint<?= $complaint->ID ?>" class="btn btn-outline btn-orange">
<?= Icon::get('o-user-plus') ?>
<div>Anonymität aufheben</div>
</button>
<?php
endif;
?>
<div class="border border-white p-2 text-white w-full">
<?= $complaint->complaint ?>
</div>
<?php if (!$complaint->deleted_at) : ?>
<button type="submit" form="trashComplaint<?= $complaint->ID ?>" class="btn btn-outline btn-red">
<?= Icon::get('o-trash') ?>
</button>
<?php
elseif ($complaint->canEdit()) :
?>
<form id="restoreComplaint<?= $complaint->ID ?>" method="POST" action="/request" class="hidden">
<input type="hidden" name="action" value="restoreComplaint">
<input type="hidden" name="complaint_id" value="<?= $complaint->ID ?>">
<?php wp_nonce_field('restoreComplaint', 'restoreComplaint_nonce'); ?>
</form>
<button type="submit" form="restoreComplaint<?= $complaint->ID ?>" class="btn btn-outline btn-green">
<?= Icon::get('o-arrow-path') ?>
</button>
<?php
endif;
if ($complaint->canEdit()) :
?>
<form id="deleteComplaint<?= $complaint->ID ?>" method="POST" action="/request" class="hidden">
<input type="hidden" name="action" value="deleteComplaint">
<input type="hidden" name="complaint_id" value="<?= $complaint->ID ?>">
<?php wp_nonce_field('deleteComplaint', 'deleteComplaint_nonce'); ?>
</form>
<button type="submit" form="deleteComplaint<?= $complaint->ID ?>" class="btn btn-outline btn-red">
<?= Icon::get('o-x-circle') ?>
</button>
<?php
endif;
?>
</div>
<?php
if (!empty($complaint->user_comment) || $complaint->canEdit()) :
?>
<div class="flex flex-row gap-2 items-center">
<div class="text-alliance">
<?= Icon::get('o-shield-check') ?>
</div>
<input <?= $complaint->canEdit() ? "placeholder='Rückmeldung eingeben...'" : "disabled" ?> name="user_comment" form="commentComplaint<?= $complaint->ID ?>" type="text" class="border border-alliance p-2 text-white flex-grow bg-blue-50 bg-opacity-0 focus:ring-alliance focus:border-alliance" value="<?= $complaint->user_comment ?>">
<?php
if ($complaint->canEdit()) :
?>
<form id="commentComplaint<?= $complaint->ID ?>" method="POST" action="/request" class="hidden">
<input type="hidden" name="action" value="commentComplaint">
<input type="hidden" name="complaint_id" value="<?= $complaint->ID ?>">
<?php wp_nonce_field('commentComplaint', 'commentComplaint_nonce'); ?>
</form>
<button type="submit" form="commentComplaint<?= $complaint->ID ?>" class="btn btn-outline btn-alliance"><?= Icon::get('o-paper-airplane') ?></button>
<?php
endif;
?>
</div>
<?php
endif;
if ($complaint->canEdit()) :
?>
<form id="slanderComplaint<?= $complaint->ID ?>" method="POST" action="/request" class="hidden">
<input type="hidden" name="action" value="slanderComplaint">
<input type="hidden" name="complaint_id" value="<?= $complaint->ID ?>">
<?php wp_nonce_field('slanderComplaint', 'slanderComplaint_nonce'); ?>
</form>
<div class="flex flex-row gap-2 items-center">
<div class="text-deathknight">
<?= Icon::get('o-shield-exclamation') ?>
</div>
<input placeholder="Offi-Kommentar eingeben..." form="slanderComplaint<?= $complaint->ID ?>" name="admin_comment" type="text" class="border border-dashed border-deathknight p-2 text-white flex-grow bg-opacity-0 bg-blue-50 focus:ring-deathknight focus:border-deathknight" value="<?= $complaint->admin_comment ?>">
<button type="submit" form="slanderComplaint<?= $complaint->ID ?>" class="btn btn-outline btn-deathknight"><?= Icon::get('o-paper-airplane') ?></button>
</div>
<?php
endif;
?>
</div>
</div>
<?php
endforeach;
?>
<?php endif; ?>
</main>
</section>
<?php
get_footer();

View File

@ -3,6 +3,8 @@ require_once('vendor/autoload.php');
use Illuminate\Support\Facades\Redirect;
use WoWPress\Models\Character;
use WoWPress\Models\Complaint;
use WoWPress\Models\Log;
use WoWPress\Models\Raid;
use WoWPress\Models\Signup;
use WoWPress\Models\SKS;
@ -233,6 +235,88 @@ switch ($_POST['action']) {
}
}
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();
}
}
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();
}
}
}
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;
}
header('Location: ' . $_SERVER['HTTP_REFERER']);

View File

@ -0,0 +1,21 @@
<?php
namespace WoWPress\Database;
class CreateComplaintTable extends CreateTable
{
public static $table_name = "complaints";
public static $fields = [
'user_id' => 'mediumint',
'anonymous' => 'boolean',
'complaint' => 'text NOT NULL',
'user_comment' => 'text',
'admin_comment' => 'text',
'created_at' => 'timestamp NOT NULL',
'updated_at' => 'timestamp NOT NULL',
'deleted_at' => 'timestamp',
];
}

View File

@ -3,14 +3,46 @@
namespace WoWPress\Models;
use Wenprise\Eloquent\Model;
use WoWPress\Api\BattleNet;
class Complaint extends Model{
protected $table = "wowpress_complaints";
public $timestamps = false;
public $timestamps = true;
protected $primaryKey = 'ID';
protected $guarded = ['ID'];
public static function getAll(){
if(current_user_can('wowpress_edit_complaints')){
return static::all()->sortBy(fn ($a) => $a->deleted_at);
}else{
return static::where('user_id',get_current_user_id())
->where('deleted_at',null)
->get();
}
}
public function canTrash(){
return current_user_can('wowpress_edit_complaints') || $this->user_id == get_current_user_id();
}
public function trash(){
$this->deleted_at = date('Y-m-d H:i:s');
$this->save();
}
public function restore(){
$this->deleted_at = null;
$this->save();
}
public function user(){
return $this->belongsTo(User::class);
}
public function canEdit(){
return current_user_can('wowpress_edit_complaints') && (get_current_user_id() != $this->user_id);
}
}

View File

@ -16,6 +16,7 @@ class Log extends Model
const LOG_LOOT = "log.sks.loot";
const LOG_ROLL = "log.sks.roll";
const LOG_SIGNUP = "log.raid.signup";
const LOG_COMPLAINT_DELETE = "log.complaint.delete";
public static function write(string $message,string $action = Log::LOG_DEFAULT){

View File

@ -7,7 +7,7 @@ use Wenprise\ORM\WP\User as WPUser;
class User extends WPUser
{
public static function logged_in(){
public static function logged_in(): User{
if(is_user_logged_in()){
return User::find(get_current_user_id());
}
@ -89,4 +89,8 @@ class User extends WPUser
}
return "priest";
}
public function can($capability){
return user_can($this->ID,$capability);
}
}