This repository has been archived by the owner on Jan 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
77 lines (52 loc) · 1.82 KB
/
index.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
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
<?php
namespace PlayStore;
include('config.inc.php');
//default controller
$ctrl = 'Welcome';
//action = controller name. could be send with either GET or POST
$action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING);
if (!$action) $action = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_STRING);
//direct_rendering=true means don't output main template, only conntent from controller
$direct_rendering = filter_input(INPUT_GET, 'direct_rendering', FILTER_VALIDATE_BOOLEAN);
if (!$direct_rendering) $direct_rendering = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_STRING);
if ($action){
if (file_exists('controller/'.$action.'.php')){
$ctrl = $action;
}else{
http_response_code(404);
return;
}
}
////if accessing protected pages without being logged, redirect to LoginForm
session_start();
if (!in_array($ctrl, DMZ) && !isset($_SESSION['user_id'])){
//redirect to login
header("Location: /index.php?action=LoginForm");
}
//load controller definition
include('controller/'.$ctrl.'.php');
$ctrlClassName = "PlayStore\\Controller\\".$ctrl;
$controller = new $ctrlClassName();
//inject current_ user id
if (isset($_SESSION['user_id'])) {
$controller->setCurrentUserId($_SESSION['user_id']);
$controller->setCurrentUserName($_SESSION['current_user']);
$controller->setIsAdmin($_SESSION['isadmin']);
}
//load output from controllers into memory
ob_start();
$controller->run();
$content = ob_get_clean();
//
if ($direct_rendering){ //don't render with template
echo $content;
}else{
$data = array(
"errors"=>$controller->getErrors(),
"content"=>$content,
"current_user" => $controller->getCurrentUserName(),
"isadmin" => $controller->isAdmin()
);
//load view
require(PATH_VIEW.'/MainTemplate.php');
}