Add comment undeletion functionality
[aur.git] / web / html / index.php
blob3787d4e42a76908ee1f05b631cb3810931fd856d
1 <?php
2 set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');
4 include_once("aur.inc.php");
5 include_once("pkgfuncs.inc.php");
7 $path = $_SERVER['PATH_INFO'];
8 $tokens = explode('/', $path);
10 if (config_get_bool('options', 'enable-maintenance') && (empty($tokens[1]) || ($tokens[1] != "css" && $tokens[1] != "images"))) {
11 if (!in_array($_SERVER['REMOTE_ADDR'], explode(" ", config_get('options', 'maintenance-exceptions')))) {
12 header("HTTP/1.0 503 Service Unavailable");
13 include "./503.php";
14 return;
18 if (!empty($tokens[1]) && '/' . $tokens[1] == get_pkg_route()) {
19 if (!empty($tokens[2])) {
20 /* TODO: Create a proper data structure to pass variables from
21 * the routing framework to the individual pages instead of
22 * initializing arbitrary variables here. */
23 $pkgname = $tokens[2];
24 $pkgid = pkg_from_name($pkgname);
26 if (!$pkgid) {
27 header("HTTP/1.0 404 Not Found");
28 include "./404.php";
29 return;
33 include get_route('/' . $tokens[1]);
34 } elseif (!empty($tokens[1]) && '/' . $tokens[1] == get_pkgbase_route()) {
35 if (!empty($tokens[2])) {
36 /* TODO: Create a proper data structure to pass variables from
37 * the routing framework to the individual pages instead of
38 * initializing arbitrary variables here. */
39 $pkgbase_name = $tokens[2];
40 $base_id = pkgbase_from_name($pkgbase_name);
42 if (!$base_id) {
43 header("HTTP/1.0 404 Not Found");
44 include "./404.php";
45 return;
48 if (!empty($tokens[3])) {
49 /* TODO: Remove support for legacy URIs and move these
50 * actions to separate modules. */
51 switch ($tokens[3]) {
52 case "adopt":
53 $_POST['do_Adopt'] = __('Adopt');
54 break;
55 case "disown":
56 include('pkgdisown.php');
57 return;
58 case "vote":
59 $_POST['do_Vote'] = __('Vote');
60 break;
61 case "unvote":
62 $_POST['do_UnVote'] = __('UnVote');
63 break;
64 case "notify":
65 $_POST['do_Notify'] = __('Notify');
66 break;
67 case "unnotify":
68 $_POST['do_UnNotify'] = __('UnNotify');
69 break;
70 case "flag":
71 include('pkgflag.php');
72 return;
73 case "unflag":
74 $_POST['do_UnFlag'] = __('UnFlag');
75 break;
76 case "flag-comment":
77 include('pkgflagcomment.php');
78 return;
79 case "delete":
80 include('pkgdel.php');
81 return;
82 case "merge":
83 include('pkgmerge.php');
84 return;
85 case "voters":
86 $_GET['N'] = $tokens[2];
87 include('voters.php');
88 return;
89 case "request":
90 include('pkgreq.php');
91 return;
92 case "comaintainers":
93 include('comaintainers.php');
94 return;
95 case "edit-comment":
96 include('commentedit.php');
97 return;
98 default:
99 header("HTTP/1.0 404 Not Found");
100 include "./404.php";
101 return;
104 $_POST['IDs'] = array(pkgbase_from_name($tokens[2]) => '1');
108 include get_route('/' . $tokens[1]);
109 } elseif (!empty($tokens[1]) && '/' . $tokens[1] == get_pkgreq_route()) {
110 if (!empty($tokens[2])) {
111 /* TODO: Create a proper data structure to pass variables from
112 * the routing framework to the individual pages instead of
113 * initializing arbitrary variables here. */
114 if (!empty($tokens[3]) && $tokens[3] == 'close') {
115 $pkgreq_id = $tokens[2];
116 } else {
117 $pkgreq_id = null;
120 if (!$pkgreq_id) {
121 header("HTTP/1.0 404 Not Found");
122 include "./404.php";
123 return;
127 include get_route('/' . $tokens[1]);
128 } elseif (!empty($tokens[1]) && '/' . $tokens[1] == get_user_route()) {
129 if (!empty($tokens[2])) {
130 $_REQUEST['ID'] = uid_from_username($tokens[2]);
132 if (!$_REQUEST['ID']) {
133 header("HTTP/1.0 404 Not Found");
134 include "./404.php";
135 return;
138 if (!empty($tokens[3])) {
139 if ($tokens[3] == 'edit') {
140 $_REQUEST['Action'] = "DisplayAccount";
141 } elseif ($tokens[3] == 'update') {
142 $_REQUEST['Action'] = "UpdateAccount";
143 } elseif ($tokens[3] == 'delete') {
144 $_REQUEST['Action'] = "DeleteAccount";
145 } else {
146 header("HTTP/1.0 404 Not Found");
147 include "./404.php";
148 return;
150 } else {
151 $_REQUEST['Action'] = "AccountInfo";
154 include get_route('/' . $tokens[1]);
155 } elseif (get_route($path) !== NULL) {
156 include get_route($path);
157 } else {
158 switch ($path) {
159 case "/css/archweb.css":
160 case "/css/aurweb.css":
161 case "/css/cgit.css":
162 case "/css/archnavbar/archnavbar.css":
163 header("Content-Type: text/css");
164 readfile("./$path");
165 break;
166 case "/images/ajax-loader.gif":
167 header("Content-Type: image/gif");
168 readfile("./$path");
169 break;
170 case "/css/archnavbar/archlogo.gif":
171 header("Content-Type: image/png");
172 readfile("./$path");
173 break;
174 case "/css/archnavbar/archlogo.png":
175 case "/css/archnavbar/aurlogo.png":
176 case "/images/favicon.ico":
177 case "/images/titlelogo.png":
178 case "/images/x.png":
179 header("Content-Type: image/png");
180 readfile("./$path");
181 break;
182 case "/images/x.min.svg":
183 case "/images/action-undo.min.svg":
184 case "/images/pencil.min.svg":
185 case "/images/pin.min.svg":
186 case "/images/unpin.min.svg":
187 case "/images/rss.svg":
188 case "/images/new.svg":
189 header("Content-Type: image/svg+xml");
190 readfile("./$path");
191 break;
192 case "/js/bootstrap-typeahead.min.js":
193 header("Content-Type: application/javascript");
194 readfile("./$path");
195 break;
196 case "/packages.gz":
197 case "/pkgbase.gz":
198 header("Content-Type: text/plain");
199 header("Content-Encoding: gzip");
200 readfile("./$path");
201 break;
202 default:
203 header("HTTP/1.0 404 Not Found");
204 include "./404.php";
205 break;