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

99 lines
3.3 KiB
PHP
Raw Normal View History

2024-04-15 23:07:29 +02:00
<?php
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-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-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) {
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':
isAllowed('wowpress_edit_raids');
$GLOBALS['wowpress']['page_title'] = "Logs";
echo "<div style='display:flex;flex-direction:column;gap:2em;'>";
echo '<hr style="width:100%">';
foreach(Log::all() as $log){
?>
<div style="display:flex;flex-direction:column;gap:1em;">
<div>Message: <?=$log->message?></div>
<div>Action: <?=$log->action?></div>
<div>Logged: <?=format_date($log->created_at,"dd.mm.YY HH:MM")?></div>
</div>
<hr style="width:100%">
<?php
}
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";
$GLOBALS['wowpress']['raids']['year'] = get_query_var('year');
$GLOBALS['wowpress']['raids']['month'] = get_query_var('month');
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;
}
});