WowPress-Tailwind/theme/inc/config-routing.php

155 lines
5.2 KiB
PHP
Raw Normal View History

2024-04-15 23:07:29 +02:00
<?php
2024-08-07 22:34:54 +02:00
use WoWPress\Models\Character;
use WoWPress\Models\CharacterList;
2024-05-02 23:31:44 +02:00
use WoWPress\Models\Log;
2024-04-16 15:25:22 +02:00
use WoWPress\Models\Raid;
2024-05-02 21:29:31 +02:00
use WoWPress\Models\SKS;
2024-04-22 15:38:22 +02:00
use WoWPress\Models\User;
2024-04-16 15:25:22 +02:00
2024-04-15 23:07:29 +02:00
add_filter('generate_rewrite_rules', function ($wp_rewrite) {
$wp_rewrite->rules = array_merge(
['roster/?$' => 'index.php?wowpress_page=roster'],
2024-04-22 15:38:22 +02:00
['raids/?$' => 'index.php?wowpress_page=raids&year=' . date('Y') . "&month=" . date('m')],
2024-04-15 23:07:29 +02:00
['raids/(\d+)/(\d+)?$' => 'index.php?wowpress_page=raids&year=$matches[1]&month=$matches[2]'],
2024-04-16 15:25:22 +02:00
['raid/(\d+)/?$' => 'index.php?wowpress_page=raid&raid_id=$matches[1]'],
2024-04-15 23:07:29 +02:00
['request/?$' => 'index.php?wowpress_page=form_request'],
2024-04-22 15:38:22 +02:00
['sks/?$' => 'index.php?wowpress_page=sks'],
2024-05-02 21:29:31 +02:00
['sks/([A-Za-z-0-9 ]+)?$' => 'index.php?wowpress_page=sks&list_name=$matches[1]'],
2024-05-02 23:31:44 +02:00
['logs/?$' => 'index.php?wowpress_page=logs'],
2024-06-27 23:08:34 +02:00
['db/?$' => 'index.php?wowpress_page=db'],
['kummerkasten/?$' => 'index.php?wowpress_page=complaints'],
['kummerkasten/(\d+)/?$' => 'index.php?wowpress_page=complaints&complaint_id=$matches[1]'],
2024-08-07 22:34:54 +02:00
['lists/?$' => 'index.php?wowpress_page=lists'],
['list/(\d+)/?$' => 'index.php?wowpress_page=lists&list_id=$matches[1]'],
2024-05-02 23:31:44 +02:00
2024-04-15 23:07:29 +02:00
$wp_rewrite->rules
);
});
add_filter('query_vars', function ($query_vars) {
$query_vars[] = 'wowpress_page';
$query_vars[] = 'year';
$query_vars[] = 'month';
2024-04-16 15:25:22 +02:00
$query_vars[] = 'raid_id';
2024-04-22 15:38:22 +02:00
$query_vars[] = 'list_name';
2024-08-07 22:34:54 +02:00
$query_vars[] = 'list_id';
$query_vars[] = 'complaint_id';
2024-04-22 15:38:22 +02:00
2024-04-15 23:07:29 +02:00
return $query_vars;
});
add_action('template_redirect', function () {
$page = get_query_var('wowpress_page');
2024-04-22 15:38:22 +02:00
setGlobalUser();
2024-04-15 23:07:29 +02:00
switch ($page) {
2024-06-27 23:08:34 +02:00
case 'db':
isAllowed('wowpress_edit_site');
wowpress_database();
header('Location: /');
die;
break;
2024-08-07 22:34:54 +02:00
case 'lists':
$list = get_query_var('list_id');
$list = CharacterList::find($list);
if ($list) {
$GLOBALS['wowpress']['page_title'] = $list->list_name;
include plugin_dir_path(__FILE__) . '../pages/single_charlist.php';
} else {
$GLOBALS['wowpress']['page_title'] = "Charakterlisten";
include plugin_dir_path(__FILE__) . '../pages/charlists.php';
}
die;
break;
case 'complaints':
isAllowed('wowpress_view_complaints');
$GLOBALS['wowpress']['page_title'] = "Kummerkasten";
include plugin_dir_path(__FILE__) . '../pages/complaints.php';
die;
break;
2024-04-15 23:07:29 +02:00
case 'roster':
$GLOBALS['wowpress']['page_title'] = "Gildenverzeichnis";
include plugin_dir_path(__FILE__) . '../pages/roster.php';
die;
break;
2024-04-22 15:38:22 +02:00
case 'sks':
isAllowed('wowpress_view_raids');
$GLOBALS['wowpress']['page_title'] = "SKS-Liste";
$GLOBALS['wowpress']['liste'] = get_query_var('list_name', null);
include plugin_dir_path(__FILE__) . '../pages/sks.php';
die;
break;
2024-05-02 23:31:44 +02:00
case 'logs':
2024-08-07 22:34:54 +02:00
# $cl = new CharacterList();
# $cl->list_name = "Strike-Liste TWW Season 1";
# $cl->border_color = "red";
# $cl->max_count = 6;
# $cl->notify = true;
# $cl->save();
2024-09-20 09:43:17 +02:00
#$cl = CharacterList::find(14);
2024-08-07 22:34:54 +02:00
2024-09-20 09:43:17 +02:00
#$char = Character::first();
2024-08-07 22:34:54 +02:00
#$char = Character::find(8);
2024-09-20 09:43:17 +02:00
#$cl->addItem($char,'Richtig Dumm','2024-09-26');
2024-08-07 22:34:54 +02:00
2024-09-20 09:43:17 +02:00
#dd($cl->characters);
2024-08-07 22:34:54 +02:00
2024-09-20 09:43:17 +02:00
#exit;
2024-05-02 23:31:44 +02:00
isAllowed('wowpress_edit_raids');
$GLOBALS['wowpress']['page_title'] = "Logs";
echo "<div style='display:flex;flex-direction:column;gap:2em;'>";
echo '<hr style="width:100%">';
2024-08-07 22:34:54 +02:00
foreach (Log::all() as $log) {
?>
2024-05-02 23:31:44 +02:00
<div style="display:flex;flex-direction:column;gap:1em;">
2024-08-07 22:34:54 +02:00
<div>Message: <?= $log->message ?></div>
<div>Action: <?= $log->action ?></div>
<div>Logged: <?= format_date($log->created_at, "dd.MM.YY HH:mm") ?></div>
2024-05-02 23:31:44 +02:00
</div>
<hr style="width:100%">
2024-08-07 22:34:54 +02:00
<?php
2024-05-02 23:31:44 +02:00
}
echo "<div>";
die;
break;
2024-04-15 23:07:29 +02:00
case 'raids':
2024-04-22 15:38:22 +02:00
# isAllowed('wowpress_view_raids');
2024-04-15 23:07:29 +02:00
$GLOBALS['wowpress']['page_title'] = "Raids";
2024-09-20 09:43:17 +02:00
$GLOBALS['wowpress']['raids']['year'] = get_query_var('year')?:date('Y');
$GLOBALS['wowpress']['raids']['month'] = get_query_var('month')?:date('n');
2024-04-15 23:07:29 +02:00
include plugin_dir_path(__FILE__) . '../pages/raids.php';
die;
break;
2024-04-16 15:25:22 +02:00
case 'raid':
2024-04-22 15:38:22 +02:00
isAllowed('wowpress_view_raids');
2024-04-16 15:25:22 +02:00
$raid = Raid::find(get_query_var('raid_id'));
$GLOBALS['wowpress']['raid'] = $raid;
$GLOBALS['wowpress']['page_title'] = $raid->title;
include plugin_dir_path(__FILE__) . '../pages/single_raid.php';
die;
break;
2024-04-15 23:07:29 +02:00
case 'form_request':
include plugin_dir_path(__FILE__) . '../request.php';
die;
default:
// DO NOTHING
break;
}
});