Notifications

master
Seph 2024-06-27 23:06:15 +02:00
parent 0c58c8dbaa
commit 8bf81bcea2
8 changed files with 143 additions and 22 deletions

View File

@ -4,6 +4,7 @@ use WoWPress\Database\CreateCacheTable;
use WoWPress\Database\CreateCharacterTable;
use WoWPress\Database\CreateComplaintTable;
use WoWPress\Database\CreateLogTable;
use WoWPress\Database\CreateNotificationTable;
use WoWPress\Database\CreateRaidTable;
use WoWPress\Database\CreateSignupTable;
use WoWPress\Database\CreateSKSTable;
@ -161,7 +162,7 @@ if (!function_exists('wowpress_database')) :
CreateSKSTable::sql(),
CreateLogTable::sql(),
CreateComplaintTable::sql(),
CreateNotificationTable::sql(),
]);
}
@ -479,12 +480,13 @@ function wowpress_add_category_meta($taxonomy)
/** Avatar Filters */
add_filter('get_avatar_url', '\WoWPress\Models\User::getAvatar', 10, 3);
add_filter('asgarosforum_filter_username', '\WoWPress\Models\User::getUsername', 10, 2);
add_filter('asgarosforum_filter_username', '\WoWPress\Models\User::getUsername', 10, 2);
/** Login redirect */
add_filter('login_redirect', fn() => "/");
add_filter('login_redirect', fn () => "/");
function sanitize($word){
$char = new Character();
return $char->sanitize($word);
}
function sanitize($word)
{
$char = new Character();
return $char->sanitize($word);
}

View File

@ -27,7 +27,7 @@ $complaints = Complaint::getAll();
<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>
Du hast etwas auf dem Herzen oder uns einfach nur so etwas mitteilen?<br>
Dann ist hier der richtige Ort dafür!
</p>
<p>
@ -35,7 +35,6 @@ $complaints = Complaint::getAll();
</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) : ?>
@ -47,7 +46,7 @@ $complaints = Complaint::getAll();
<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="show" value="1" class="btn btn-outline btn-alliance flex-grow bg-black bg-opacity-60 backdrop-blur-md">Mit Charnamen senden <?= 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>
@ -65,8 +64,8 @@ $complaints = Complaint::getAll();
<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="shadow p-auto flex flex-col gap-2 <?= strtotime($complaint->deleted_at."") > 0 ? "border border-dashed border-white bg-green-800 bg-opacity-60 backdrop-blur-md" : "bg-black bg-opacity-60 backdrop-blur-md" ?>">
<?php if (strtotime($complaint->deleted_at."") > 0) : ?>
<div class="text-end">Eintrag gelöscht</div>
<?php endif; ?>
<div class="flex flex-col gap-2">
@ -97,7 +96,7 @@ $complaints = Complaint::getAll();
<div class="border border-white p-2 text-white w-full">
<?= $complaint->complaint ?>
</div>
<?php if (!$complaint->deleted_at) : ?>
<?php if (!(strtotime($complaint->deleted_at."") > 0)) : ?>
<button type="submit" form="trashComplaint<?= $complaint->ID ?>" class="btn btn-outline btn-red">
<?= Icon::get('o-trash') ?>
</button>

View File

@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Redirect;
use WoWPress\Models\Character;
use WoWPress\Models\Complaint;
use WoWPress\Models\Log;
use WoWPress\Models\Notification;
use WoWPress\Models\Raid;
use WoWPress\Models\Signup;
use WoWPress\Models\SKS;
@ -255,6 +256,7 @@ switch ($_POST['action']) {
if ($c) {
$c->user_comment = $_POST['user_comment'];
$c->save();
Notification::addNotification($c->user_id, "Neuer Kommentar im Kummerkasten!");
}
}
}
@ -317,6 +319,18 @@ switch ($_POST['action']) {
}
}
break;
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']);
if(!empty($note->ID && $note->user_id == get_current_user_id())){
$note->delete();
}
}
}
}
break;
}
header('Location: ' . $_SERVER['HTTP_REFERER']);

View File

@ -10,6 +10,13 @@
use WoWPress\Frontend\Icon;
use WoWPress\Frontend\NavWalker;
use WoWPress\Models\Notification;
if (is_user_logged_in()) {
$notifications = Notification::getAll();
} else {
$notifications = [];
}
?>
@ -45,7 +52,7 @@ use WoWPress\Frontend\NavWalker;
</svg>
</div>
</div>
<div x-data="{ open: false }" class="flex flex-col max-w-screen-xl px-4 py-2 mx-auto xl:items-center xl:justify-center xl:flex-row xl:px-8">
<div x-data="{ open: false, notification: false }" class="flex flex-col max-w-screen-xl px-4 py-2 mx-auto xl:items-center xl:justify-center xl:flex-row xl:px-8">
<div class="py-2 xl:hidden flex flex-row items-center justify-center gap-2" style="--btn-color : white">
<button class="btn btn-outline flex-grow" @click="open = !open">
Menü
@ -61,9 +68,35 @@ use WoWPress\Frontend\NavWalker;
<a class="btn btn-outline btn-red" href="/wp-login.php">Login</a>
<?php else : ?>
<a class="btn btn-outline btn-alliance" href="/wp-admin/profile.php">Profil</a>
<?php if (!empty($notifications->first())) : ?>
<a href="#" class="btn btn-outline btn-alliance" @click="notification = !notification">
&nbsp;
<span class="relative flex h-3 w-3">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-alliance opacity-75"></span>
<span class="relative inline-flex rounded-full h-3 w-3 bg-alliance"></span>
</span>
&nbsp;
</a>
<?php endif; ?>
<?php endif; ?>
</div>
<?php if (!empty($notifications->first())) : ?>
<div x-show="notification">
<div class="p-2 flex flex-col mt-1 gap-2 shadow" style="background-color:var(--color-deepblue)">
<?php foreach ($notifications as $notification) : ?>
<div class="p-2 border flex flex-row gap-1 justify-between">
<form class="hidden" method="POST" action="/request" id="deleteNotification<?= $notification->ID ?>">
<input type="hidden" name="action" value="notificationSeen">
<input type="hidden" name="notification_id" value="<?= $notification->ID ?>">
<?php wp_nonce_field('notificationSeen', 'notificationSeen_nonce'); ?>
</form>
<div><?= $notification->note ?></div>
<button type="submit" class="cursor-pointer" form="deleteNotification<?= $notification->ID ?>"><?= Icon::get('o-x-circle') ?> </button>
</div>
<?php endforeach; ?>
</div>
</div>
<? endif; ?>
<nav id="site-navigation" :class="{'flex': open, 'hidden': !open}" class="flex-col flex-grow pb-4 md:pb-0 hidden xl:flex xl:justify-center xl:flex-row gap-2">
<?php
@ -81,15 +114,45 @@ use WoWPress\Frontend\NavWalker;
?>
<div class="hidden xl:flex">
<?php if (!is_user_logged_in()) : ?>
<a class="btn btn-outline btn-red" href="/wp-login.php">Login</a>
<?php else : ?>
<a class="btn btn-outline btn-alliance" href="/wp-admin/profile.php">Profil</a>
<?php if (!is_user_logged_in()) : ?>
<a class="btn btn-outline btn-red" href="/wp-login.php">Login</a>
<?php else : ?>
<a class="btn btn-outline btn-alliance" href="/wp-admin/profile.php">Profil</a>
<?php endif; ?>
<?php endif; ?>
</div>
<?php if (is_user_logged_in() && !empty($notifications->first())) : ?>
<div x-data="{notification:false}">
<div class="hidden xl:flex">
<a href="#" class="btn btn-outline btn-alliance" @click="notification = !notification">
Benachrichtigungen
<span class="relative flex h-3 w-3">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-alliance opacity-75"></span>
<span class="relative inline-flex rounded-full h-3 w-3 bg-alliance"></span>
</span>
</a>
</div>
<?php if (!empty($notifications->first())) : ?>
<div x-show="notification">
<div class="p-2 flex flex-col mt-1 absolute gap-2 shadow" style="background-color:var(--color-deepblue)">
<?php foreach ($notifications as $notification) : ?>
<div class="p-2 border flex flex-row gap-1 justify-between">
<form class="hidden" action="/request" method="POST" id="deleteNotification<?= $notification->ID ?>">
<input type="hidden" name="action" value="notificationSeen">
<input type="hidden" name="notification_id" value="<?= $notification->ID ?>">
<?php wp_nonce_field('notificationSeen', 'notificationSeen_nonce'); ?>
</form>
<div><?= $notification->note ?></div>
<button type="submit" class="cursor-pointer" form="deleteNotification<?= $notification->ID ?>"><?= Icon::get('o-x-circle') ?> </button>
</div>
<?php endforeach; ?>
</div>
</div>
<? endif; ?>
</div>
<?php endif; ?>
</nav><!-- #site-navigation -->
</div>

View File

@ -0,0 +1,17 @@
<?php
namespace WoWPress\Database;
class CreateNotificationTable extends CreateTable
{
public static $table_name = "notifications";
public static $fields = [
'user_id' => 'mediumint',
'note' => 'text NOT NULL',
'created_at' => 'timestamp NOT NULL',
'updated_at' => 'timestamp NOT NULL',
];
}

View File

@ -41,7 +41,7 @@ class Complaint extends Model{
}
public function canEdit(){
return current_user_can('wowpress_edit_complaints') && (get_current_user_id() != $this->user_id);
return current_user_can('wowpress_edit_complaints');# && (get_current_user_id() != $this->user_id);
}

View File

@ -0,0 +1,26 @@
<?php
namespace WoWPress\Models;
use Wenprise\Eloquent\Model;
class Notification extends Model{
protected $table = "wowpress_notifications";
public $timestamps = true;
protected $primaryKey = 'ID';
protected $guarded = ['ID'];
public static function addNotification($user_id,$note_text){
$note = new Notification();
$note->user_id = $user_id;
$note->note = $note_text;
$note->save();
}
public static function getAll(){
return Notification::where('user_id',get_current_user_id())->get();
}
}

BIN
wowpress_2.zip 100644

Binary file not shown.