diff --git a/tailwind/custom/file-header.css b/tailwind/custom/file-header.css index 56abe20..38d470d 100644 --- a/tailwind/custom/file-header.css +++ b/tailwind/custom/file-header.css @@ -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 diff --git a/tailwind/tailwind.css b/tailwind/tailwind.css index 6c0e347..2c42f30 100644 --- a/tailwind/tailwind.css +++ b/tailwind/tailwind.css @@ -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 { diff --git a/theme/functions.php b/theme/functions.php index e685013..b298b50 100644 --- a/theme/functions.php +++ b/theme/functions.php @@ -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(), + ]); } diff --git a/theme/inc/config-functions.php b/theme/inc/config-functions.php index 6855014..e51b894 100644 --- a/theme/inc/config-functions.php +++ b/theme/inc/config-functions.php @@ -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'); + } diff --git a/theme/inc/config-routing.php b/theme/inc/config-routing.php index df18492..d978169 100644 --- a/theme/inc/config-routing.php +++ b/theme/inc/config-routing.php @@ -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'; diff --git a/theme/pages/complaints.php b/theme/pages/complaints.php index e69de29..46e50c6 100644 --- a/theme/pages/complaints.php +++ b/theme/pages/complaints.php @@ -0,0 +1,182 @@ + + + +
+
+
+

Willkommen in unserem Kummerkasten

+

+ Du hast etwas auf dem Herzen, möchtest deinem Ärger Luft machen oder uns einfach nur so etwas mitteilen?
+ Dann ist hier der richtige Ort dafür! +

+

+ Keiner außer dir (und den Offis) kann sehen was du hier schreibst. +

+

+ 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.
+ 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. +

+
+ + +
+

Neue Einsendung

+ +
+ + +
+
+ + first())) : ?> +
+

Einsendungen

+
+ + + +
"> + deleted_at) : ?> +
Eintrag gelöscht
+ +
+
+ canEdit() && (!$complaint->anonymous || $forceShow)) : + ?> +
+ +
user->user_name ?>
+
+ canEdit() && $complaint->anonymous) : + ?> + + + +
+ complaint ?> +
+ deleted_at) : ?> + + canEdit()) : + ?> + + + canEdit()) : + ?> + + + +
+ user_comment) || $complaint->canEdit()) : + ?> +
+
+ +
+ canEdit() ? "placeholder='Rückmeldung eingeben...'" : "disabled" ?> name="user_comment" form="commentComplaintID ?>" 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="user_comment ?>"> + canEdit()) : + ?> + + + +
+ canEdit()) : + ?> + +
+
+ +
+ + + +
+ +
+
+ + +
+
+ +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']); diff --git a/theme/wowpress/Database/CreateComplaintTable.php b/theme/wowpress/Database/CreateComplaintTable.php new file mode 100644 index 0000000..24f08bc --- /dev/null +++ b/theme/wowpress/Database/CreateComplaintTable.php @@ -0,0 +1,21 @@ + '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', + ]; + +} diff --git a/theme/wowpress/Models/Complaint.php b/theme/wowpress/Models/Complaint.php index eabc467..78831af 100644 --- a/theme/wowpress/Models/Complaint.php +++ b/theme/wowpress/Models/Complaint.php @@ -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); + } + + } \ No newline at end of file diff --git a/theme/wowpress/Models/Log.php b/theme/wowpress/Models/Log.php index d267380..50f68ef 100644 --- a/theme/wowpress/Models/Log.php +++ b/theme/wowpress/Models/Log.php @@ -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){ diff --git a/theme/wowpress/Models/User.php b/theme/wowpress/Models/User.php index 1eb9440..b5cc458 100644 --- a/theme/wowpress/Models/User.php +++ b/theme/wowpress/Models/User.php @@ -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); + } }