blob: 8986dfe1f09b07555b58e36821a32d978347f924 (
plain) (
blame)
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
|
<?php
$VIEWS_DIR = __DIR__ . '/..';
$CONTROLLERS_DIR = __DIR__ . '/../../controllers';
$MODELS_DIR = __DIR__ . '/../../models';
$uri = rtrim($_SERVER['REQUEST_URI'], '/');
$root = '/' . @explode('/', $uri, 3)[1];
function route_view() {
global $root;
global $uri;
switch ($root) {
case '/archive': return '/archive';
case '/profile': return '/profile';
case '/register': return '/register';
case '/login': return '/login';
}
switch ($uri) {
case '': case '/': case '/home':
return '/home';
case '/authenticate':
return '/profile/authenticate.php';
default:
http_response_code(404);
return '/404';
}
}
$view = $VIEWS_DIR . route_view();
require_once '../../models/database.php';
foreach (glob($MODELS_DIR . '/*.php') as $filename) {
require_once $filename;
}
if (str_ends_with($view, '.php')) {
require_once $view;
}
else {
@include_once "$view/meta.php";
if (isset($controller)) {
require_once "$CONTROLLERS_DIR/$controller.php";
require_once "$CONTROLLERS_DIR/meta.php";
}
require_once './header.php';
require_once "$view/index.php";
require_once './footer.php';
}
|