-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
78 lines (70 loc) · 4.2 KB
/
Copy pathindex.php
File metadata and controls
78 lines (70 loc) · 4.2 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
require('./controller/common.php');
$HTTPMethod = $_SERVER['REQUEST_METHOD'];
if (!in_array($HTTPMethod, array('GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'OPTIONS'))) {
exit('Unsupport HTTP method');
}
$NotFound = true;
$HTTPParameters = array();
if (in_array($HTTPMethod, array('PUT', 'DELETE', 'OPTIONS'))) {
parse_str(file_get_contents('php://input'), $HTTPParameters);
}
$ShortRequestURI = $_SERVER['REQUEST_URI'];
$HTTPMethod = $_SERVER['REQUEST_METHOD'];
$Routes = array();
$URLPath = '';
$Routes['GET']['/'] = 'home';
$Routes['GET']['/index'] = 'home';
$Routes['GET']['/login'] = 'login';
$Routes['GET']['/logout'] = 'logout';
$Routes['GET']['/register'] = 'register';
$Routes['GET']['/profile/(?<action>modify|presentation)'] = 'profile';
$Routes['GET']['/activities/(?<action>my|ongoing|due|submit)'] = 'activities';
$Routes['GET']['/groups/(?<action>my|all)'] = 'groups';
$Routes['GET']['/a/(?<id>[0-9]+)'] = 'activity';
$Routes['GET']['/g/(?<id>[0-9]+)'] = 'group';
$Routes['GET']['/t/(?<id>[0-9]+)'] = 'topic';
$Routes['GET']['/u/(?<id>[0-9]+)'] = 'user';
$Routes['GET']['/activities/new'] = 'newActivity';
$Routes['GET']['/groups/new'] = 'newGroup';
$Routes['GET']['/activity/invite'] = 'invite';
$Routes['POST']['/login'] = 'login';
$Routes['POST']['/register'] = 'register';
$Routes['POST']['/activity/new'] = 'newActivity';
$Routes['POST']['/activity/join'] = 'activity';
$Routes['POST']['/activity/delete'] = 'activities';
$Routes['POST']['/group/new'] = 'newGroup';
$Routes['POST']['/group/join'] = 'group';
$Routes['POST']['/user/follow'] = 'relationship';
$Routes['POST']['/user/modify'] = 'profile';
$Routes['POST']['/activity/invite'] = 'invite';
foreach ($Routes as $Method => $SubRoutes) {
if ($Method === $HTTPMethod) {
$ParametersVariableName = '_' . $Method;
foreach ($SubRoutes as $URL => $Controller) {
if (preg_match("#^" . $URL . "$#i", $ShortRequestURI, $Parameters)) {
// echo '<br><br><br><br><br><br><br><br>';
// echo $URL;
// foreach ($Parameters as $Key => $Value) {
// echo $Key." => ".$Value."<br>";
// }
// echo "122<br>";
$NotFound = false;
$Parameters = array_merge($Parameters, $HTTPParameters);
// foreach ($HTTPParameters as $Key => $Value) {
// echo $Key." => ".$Value."<br>";
// }
foreach ($Parameters as $Key => $Value) {
if (!is_int($Key)) {
${$ParametersVariableName}[$Key] = urldecode($Value);
$_REQUEST[$Key] = urldecode($Value);
}
}
$UrlPath = $Controller;
break 2;
}
}
break;
}
}
require(__DIR__ . '/controller/' . $UrlPath . '.php');