| 1 | <?php |
|---|
| 2 | if (!defined('IA_HPHP_ENV')) { |
|---|
| 3 | require_once("../config.php"); |
|---|
| 4 | } |
|---|
| 5 | require_once(IA_ROOT_DIR."www/config.php"); |
|---|
| 6 | require_once(IA_ROOT_DIR."common/log.php"); |
|---|
| 7 | require_once(IA_ROOT_DIR."common/common.php"); |
|---|
| 8 | if (IA_DEVELOPMENT_MODE) { |
|---|
| 9 | log_print("- -- --- ---- ----- Request: ".$_SERVER['QUERY_STRING']); |
|---|
| 10 | } |
|---|
| 11 | check_requirements(); |
|---|
| 12 | require_once(IA_ROOT_DIR."common/security.php"); |
|---|
| 13 | require_once(IA_ROOT_DIR."www/url.php"); |
|---|
| 14 | require_once(IA_ROOT_DIR."www/utilities.php"); |
|---|
| 15 | require_once(IA_ROOT_DIR."www/identity.php"); |
|---|
| 16 | require_once(IA_ROOT_DIR."common/db/db.php"); |
|---|
| 17 | db_connect(); |
|---|
| 18 | |
|---|
| 19 | // restore identity (if such a session exists) |
|---|
| 20 | identity_restore(); |
|---|
| 21 | |
|---|
| 22 | // Do url validation. |
|---|
| 23 | // All urls that pass are valid, they can be missing wiki pages. |
|---|
| 24 | $page = request('page'); |
|---|
| 25 | |
|---|
| 26 | // Redirect to home if in / |
|---|
| 27 | if ($page == "") { |
|---|
| 28 | $page = "home"; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | // Check page name. |
|---|
| 32 | if (!is_page_name($page)) { |
|---|
| 33 | flash_error('invalid URL'); |
|---|
| 34 | redirect(url_home()); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | // Prepare some vars for url handler. |
|---|
| 39 | // Filter empty path elements. Strips extra '/'s |
|---|
| 40 | $page = normalize_page_name($page); |
|---|
| 41 | $pagepath = explode('/', $page); |
|---|
| 42 | |
|---|
| 43 | $urlstart = getattr($pagepath, 0, ''); |
|---|
| 44 | $page_id = implode('/', array_slice($pagepath, 1)); |
|---|
| 45 | $action = request('action', 'view'); |
|---|
| 46 | |
|---|
| 47 | // Direct mapping list |
|---|
| 48 | // Note: array_flip() flips keys with values in a dictionary. |
|---|
| 49 | // FIXME: change this to Romanian! |
|---|
| 50 | $directmaps = array_flip(array('register', 'changes', |
|---|
| 51 | 'login', 'logout', 'json', 'job_detail', |
|---|
| 52 | 'monitor', 'projector', 'submit', 'userinfo', |
|---|
| 53 | 'plot', 'search', |
|---|
| 54 | 'unsubscribe', 'resetpass', 'reeval', 'userwidget' |
|---|
| 55 | )); |
|---|
| 56 | |
|---|
| 57 | // |
|---|
| 58 | // Here comes the big url mapper. |
|---|
| 59 | // We include in the if statement to avoid an extra parsing load. |
|---|
| 60 | // |
|---|
| 61 | |
|---|
| 62 | // Trivial direct mappings |
|---|
| 63 | if (isset($directmaps[$urlstart])) { |
|---|
| 64 | require_once(IA_ROOT_DIR."www/controllers/{$urlstart}.php"); |
|---|
| 65 | $fname = "controller_{$urlstart}"; |
|---|
| 66 | $fname($page_id); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | // Account edit page |
|---|
| 70 | else if ($urlstart == 'account') { |
|---|
| 71 | require_once(IA_ROOT_DIR.'www/controllers/account.php'); |
|---|
| 72 | controller_account(getattr($pagepath, 1)); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | // Task creator |
|---|
| 76 | else if ($page == 'admin/problema-noua') { |
|---|
| 77 | require_once(IA_ROOT_DIR.'www/controllers/task.php'); |
|---|
| 78 | controller_task_create(); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | // Task deleter |
|---|
| 82 | else if ($page == 'admin/sterge-problema') { |
|---|
| 83 | require_once(IA_ROOT_DIR.'www/controllers/task.php'); |
|---|
| 84 | controller_task_delete(request("task_id")); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | // Task search |
|---|
| 88 | else if ($page == 'cauta-probleme') { |
|---|
| 89 | require_once(IA_ROOT_DIR.'www/controllers/task.php'); |
|---|
| 90 | controller_task_search(); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | // Task edit parameters |
|---|
| 94 | else if ($urlstart == 'problema' && $action == 'task-edit-params') { |
|---|
| 95 | require_once(IA_ROOT_DIR.'www/controllers/task.php'); |
|---|
| 96 | $task_id = implode("/", array_slice($pagepath, 1)); |
|---|
| 97 | controller_task_details($task_id); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | // Task edit tags |
|---|
| 101 | else if ($urlstart == 'problema' && $action == 'task-edit-tags') { |
|---|
| 102 | require_once(IA_ROOT_DIR.'www/controllers/task.php'); |
|---|
| 103 | $task_id = implode("/", array_slice($pagepath, 1)); |
|---|
| 104 | controller_task_tag($task_id); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | // Task edit ratings |
|---|
| 108 | else if ($urlstart == 'problema' && $action == 'task-edit-ratings') { |
|---|
| 109 | require_once(IA_ROOT_DIR.'www/controllers/task.php'); |
|---|
| 110 | $task_id = implode("/", array_slice($pagepath, 1)); |
|---|
| 111 | controller_task_ratings($task_id); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | // Task algorithm tags |
|---|
| 115 | else if ($page == 'admin/task-tags') { |
|---|
| 116 | require_once(IA_ROOT_DIR.'www/controllers/task_tags.php'); |
|---|
| 117 | if (request("action") == "add") { |
|---|
| 118 | controller_task_tags_add(); |
|---|
| 119 | } elseif (request("action") == "delete") { |
|---|
| 120 | controller_task_tags_delete(); |
|---|
| 121 | } elseif (request("action") == "rename") { |
|---|
| 122 | controller_task_tags_rename(); |
|---|
| 123 | } else { |
|---|
| 124 | controller_task_tags(); |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | // Round creator |
|---|
| 129 | else if ($page == 'admin/runda-noua') { |
|---|
| 130 | require_once(IA_ROOT_DIR.'www/controllers/round.php'); |
|---|
| 131 | controller_round_create(); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | // Round edit parameters |
|---|
| 135 | else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'runda' && |
|---|
| 136 | $action == 'edit-params') { |
|---|
| 137 | require_once(IA_ROOT_DIR.'www/controllers/round.php'); |
|---|
| 138 | $round_id = implode("/", array_slice($pagepath, 2)); |
|---|
| 139 | controller_round_details($round_id); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | // Round edit task order |
|---|
| 143 | else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'runda' && |
|---|
| 144 | $action == 'edit-task-order') { |
|---|
| 145 | require_once(IA_ROOT_DIR.'www/controllers/round.php'); |
|---|
| 146 | $round_id = implode("/", array_slice($pagepath, 2)); |
|---|
| 147 | controller_round_task_order($round_id); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | // Round delete |
|---|
| 151 | else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'runda' && |
|---|
| 152 | $action == 'sterge-runda') { |
|---|
| 153 | require_once(IA_ROOT_DIR.'www/controllers/round.php'); |
|---|
| 154 | require_once(IA_ROOT_DIR.'www/controllers/textblock.php'); |
|---|
| 155 | $round_id = implode("/", array_slice($pagepath, 2)); |
|---|
| 156 | if (request('delete-pages')) { |
|---|
| 157 | $v = request('textblocks'); |
|---|
| 158 | controller_textblock_delete_many($v, url_round_delete($round_id)); |
|---|
| 159 | } elseif (request('delete-round')) { |
|---|
| 160 | controller_round_delete($round_id); |
|---|
| 161 | } else { |
|---|
| 162 | controller_round_delete_view($round_id); |
|---|
| 163 | } |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | // Round registration |
|---|
| 167 | else if ($urlstart == 'inregistrare-runda') { |
|---|
| 168 | $obj_id = implode("/", array_slice($pagepath, 1)); |
|---|
| 169 | require_once(IA_ROOT_DIR.'www/controllers/round_register.php'); |
|---|
| 170 | controller_round_register($obj_id); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | // Round registered users |
|---|
| 174 | else if ($urlstart == 'lista-inregistrare') { |
|---|
| 175 | $obj_id = implode("/", array_slice($pagepath, 1)); |
|---|
| 176 | require_once(IA_ROOT_DIR.'www/controllers/round_register.php'); |
|---|
| 177 | controller_round_register_view($obj_id); |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | // Blog RSS feed |
|---|
| 181 | else if ($page == 'blog' && $action == 'rss') { |
|---|
| 182 | require_once(IA_ROOT_DIR.'www/controllers/blog.php'); |
|---|
| 183 | controller_blog_feed(); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | // Blog index |
|---|
| 187 | else if ($page == 'blog') { |
|---|
| 188 | require_once(IA_ROOT_DIR.'www/controllers/blog.php'); |
|---|
| 189 | controller_blog_index(); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | // Blog edit |
|---|
| 193 | else if ($urlstart == 'blog' && $action == 'edit') { |
|---|
| 194 | require_once(IA_ROOT_DIR.'www/controllers/textblock_edit.php'); |
|---|
| 195 | controller_textblock_edit($page, 'private'); |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | // Blog view |
|---|
| 199 | else if ($urlstart == 'blog' && $action == 'view') { |
|---|
| 200 | require_once(IA_ROOT_DIR.'www/controllers/blog.php'); |
|---|
| 201 | controller_blog_view($page, request('revision')); |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | // textblock controllers |
|---|
| 205 | // FIXME: quick array of sorts? |
|---|
| 206 | // - edit textblock |
|---|
| 207 | else if ($action == 'edit') { |
|---|
| 208 | require_once(IA_ROOT_DIR.'www/controllers/textblock_edit.php'); |
|---|
| 209 | controller_textblock_edit($page); |
|---|
| 210 | } |
|---|
| 211 | // - delete textblock |
|---|
| 212 | else if ($action == 'delete') { |
|---|
| 213 | require_once(IA_ROOT_DIR.'www/controllers/textblock.php'); |
|---|
| 214 | controller_textblock_delete($page); |
|---|
| 215 | } |
|---|
| 216 | // - delete textblock revision |
|---|
| 217 | else if ($action == 'delete-revision') { |
|---|
| 218 | require_once(IA_ROOT_DIR.'www/controllers/textblock.php'); |
|---|
| 219 | |
|---|
| 220 | $rev = request('revision'); |
|---|
| 221 | $rev_cnt = request('revision_count'); |
|---|
| 222 | controller_textblock_delete_revision($page, $rev, $rev_cnt); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | // - view textblock history |
|---|
| 226 | else if ($action == 'history') { |
|---|
| 227 | require_once(IA_ROOT_DIR.'www/controllers/textblock.php'); |
|---|
| 228 | controller_textblock_history($page); |
|---|
| 229 | } |
|---|
| 230 | // - move textblock |
|---|
| 231 | else if ($action == 'move') { |
|---|
| 232 | require_once(IA_ROOT_DIR.'www/controllers/textblock_move.php'); |
|---|
| 233 | controller_textblock_move($page); |
|---|
| 234 | } |
|---|
| 235 | // - copy textblock |
|---|
| 236 | else if ($action == 'copy') { |
|---|
| 237 | require_once(IA_ROOT_DIR.'www/controllers/textblock_copy.php'); |
|---|
| 238 | controller_textblock_copy($page); |
|---|
| 239 | } |
|---|
| 240 | // - restore textblock |
|---|
| 241 | else if ($action == 'restore') { |
|---|
| 242 | require_once(IA_ROOT_DIR.'www/controllers/textblock.php'); |
|---|
| 243 | controller_textblock_restore($page, request('revision')); |
|---|
| 244 | } |
|---|
| 245 | // - view textblock differences between revisions |
|---|
| 246 | else if ($action == 'diff') { |
|---|
| 247 | require_once(IA_ROOT_DIR.'www/controllers/textblock.php'); |
|---|
| 248 | controller_textblock_diff($page); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | // attachment controllers |
|---|
| 252 | // - create attachment |
|---|
| 253 | else if ($action == 'attach') { |
|---|
| 254 | require_once(IA_ROOT_DIR.'www/controllers/attachment.php'); |
|---|
| 255 | controller_attachment_create($page); |
|---|
| 256 | } |
|---|
| 257 | // - print attachment list |
|---|
| 258 | else if ($action == 'attach-list') { |
|---|
| 259 | require_once(IA_ROOT_DIR.'www/controllers/attachment.php'); |
|---|
| 260 | controller_attachment_list($page); |
|---|
| 261 | } |
|---|
| 262 | // - attachment delete |
|---|
| 263 | else if ($action == 'attach-del') { |
|---|
| 264 | require_once(IA_ROOT_DIR.'www/controllers/attachment.php'); |
|---|
| 265 | controller_attachment_delete($page, request('file')); |
|---|
| 266 | } |
|---|
| 267 | // - attachment rename |
|---|
| 268 | else if ($action == 'attach-rename') { |
|---|
| 269 | require_once(IA_ROOT_DIR.'www/controllers/attachment.php'); |
|---|
| 270 | controller_attachment_rename($page, request('old_name'), request('new_name')); |
|---|
| 271 | } |
|---|
| 272 | // - attachment download |
|---|
| 273 | else if ($action == 'download') { |
|---|
| 274 | if (request('resize')) { |
|---|
| 275 | require_once(IA_ROOT_DIR.'www/controllers/image_attachment.php'); |
|---|
| 276 | // download resized image |
|---|
| 277 | controller_attachment_resized_img($page, request('file'), request('resize')); |
|---|
| 278 | } else { |
|---|
| 279 | require_once(IA_ROOT_DIR.'www/controllers/attachment.php'); |
|---|
| 280 | // regular file download |
|---|
| 281 | controller_attachment_download($page, request('file'), request('safe_only', false) == 'true'); |
|---|
| 282 | } |
|---|
| 283 | } |
|---|
| 284 | else if ($action == 'attach-bulk-action') { |
|---|
| 285 | require_once(IA_ROOT_DIR.'www/controllers/attachment.php'); |
|---|
| 286 | if(request('download')) { |
|---|
| 287 | controller_attachment_download_zip($page, request_args()); |
|---|
| 288 | } else if(request('delete')) { |
|---|
| 289 | controller_attachment_delete_many($page, request_args()); |
|---|
| 290 | } |
|---|
| 291 | } |
|---|
| 292 | |
|---|
| 293 | // reset password |
|---|
| 294 | else if ('confirm' == $urlstart) { |
|---|
| 295 | // confirm reset password |
|---|
| 296 | require_once(IA_ROOT_DIR.'www/controllers/resetpass.php'); |
|---|
| 297 | controller_resetpass_confirm($page_id); |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | // user profile, view personal page / statistics / rating evolution |
|---|
| 301 | else if (IA_USER_TEXTBLOCK_PREFIX == $urlstart.'/' && |
|---|
| 302 | ('view' == $action || 'rating' == $action || 'stats' == $action )) { |
|---|
| 303 | require_once(IA_ROOT_DIR.'www/controllers/user.php'); |
|---|
| 304 | controller_user_view($page_id, $action, request('revision')); |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | // Newsletter index |
|---|
| 308 | else if ($page == 'newsletter') { |
|---|
| 309 | require_once(IA_ROOT_DIR.'www/controllers/newsletter.php'); |
|---|
| 310 | controller_newsletter_index(); |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | // Display one newsletter. |
|---|
| 314 | else if (IA_NEWSLETTER_TEXTBLOCK_PREFIX == $urlstart.'/' |
|---|
| 315 | && 'view' == $action) { |
|---|
| 316 | require_once(IA_ROOT_DIR.'www/controllers/newsletter.php'); |
|---|
| 317 | if ('body' == request('preview')) { |
|---|
| 318 | controller_newsletter_preview_body($page_id, request('revision')); |
|---|
| 319 | } else { |
|---|
| 320 | controller_newsletter_preview_frame($page_id, request('revision')); |
|---|
| 321 | } |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | // general textblock view |
|---|
| 325 | else if ($action == 'view') { |
|---|
| 326 | require_once(IA_ROOT_DIR.'www/controllers/textblock.php'); |
|---|
| 327 | controller_textblock_view($page, request('revision')); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | // invalid URL |
|---|
| 331 | else { |
|---|
| 332 | flash_error('URL invalid'); |
|---|
| 333 | redirect(url_home()); |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | ?> |
|---|