forked from noackorama/ZensusPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_route.php
24 lines (24 loc) · 1.06 KB
/
get_route.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
<?php
function get_route($route = '')
{
$route = substr(parse_url($route ?: $_SERVER['REQUEST_URI'], PHP_URL_PATH), strlen($GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP']));
if (strpos($route, 'plugins.php/') !== false) {
$trails = explode('plugins.php/', $route);
$pieces = explode('/', $trails[1]);
$route = 'plugins.php/' . $pieces[0] . ($pieces[1] ? '/' . $pieces[1] : '') . ($pieces[2] ? '/' . $pieces[2] : '');
} elseif (strpos($route, 'dispatch.php/') !== false) {
$trails = explode('dispatch.php/', $route);
$dispatcher = new StudipDispatcher();
$pieces = explode('/', $trails[1]);
foreach ($pieces as $index => $piece) {
$trail .= ($trail ? '/' : '') . $piece;
if ($dispatcher->file_exists($trail . '.php')) {
$route = 'dispatch.php/' . $trail . ($pieces[$index+1] ? '/' . $pieces[$index+1] : '');
}
}
}
while (substr($route, strlen($route)-6, 6) == '/index') {
$route = substr($route, 0, strlen($route)-6);
}
return $route;
}