-
Notifications
You must be signed in to change notification settings - Fork 4
/
Router.php
executable file
·45 lines (40 loc) · 1.4 KB
/
Router.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace PressDo;
require 'helpers/Config.php';
use PressDo\Config;
class Router {
// Parse requested URI
public static function handle_uri($request_uri, $query_string) : object|null
{
if($request_uri == '/'):
Header('Location: /w/'.rawurlencode(Config::get('frontpage')));
exit;
endif;
// 0/1/2/3
$uriset = explode('/', explode('?', $request_uri)[0]);
$uri_data = (object) [
'page' => $uriset[1]=='w'?'wiki':$uriset[1]
];
if(count($uriset) > 2 && $uri_data->page !== 'member'){
$uri_data->title = urldecode(implode('/', array_slice($uriset, 2)));
$uri_data->titleurl = implode('/', array_slice($uriset, 2));
}else{
$uri_data->menu = $uriset[2];
$uri_data->title = urldecode(implode('/', array_slice($uriset, 3)));
$uri_data->titleurl = implode('/', array_slice($uriset, 3));
}
$query = [];
parse_str($query_string, $query);
$uri_data->query = (object) $query;
switch($uri_data->page){
case 'member':
case 'admin':
case 'api':
require 'controllers/'.$uri_data->page.'/'.$uri_data->menu.'.php';
break;
default:
require 'controllers/'.$uri_data->page.'.php';
}
return $uri_data;
}
}