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

145 lines
5.2 KiB
PHP
Raw Permalink 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-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-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-09-20 20:02:10 +02:00
case 'import_sks':
isAllowed('wowpress_edit_site');
echo "<pre>";
foreach(SKS::getLists() as $list){
$list_there = SKSHistory::where('list_name',$list->list_name)->first();
if(empty($list_there)){
$export = $list->export();
$sks = SKSHistory::createList($list->list_name,$export);
$sks->save();
}
}
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':
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;
}
});