forked from vasilensotirov/Youtube-Ittalents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
90 lines (86 loc) · 2.88 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
use exceptions\BaseException;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
function handleExceptions(Exception $exception){
$status = $exception instanceof BaseException ? $exception->getStatusCode() : 500;
$msg = $exception->getMessage();
if ($status == 500){
$msg = "Server error!";
}
header($_SERVER["SERVER_PROTOCOL"]." " . $status);
$html = "<h3 style='color: red'>$msg</h3>";
include_once "view/main.php";
echo $html;
/*$obj = new stdClass();
$obj->msg = $exception->getMessage();
$obj->status = $status;*/
//echo json_encode($obj);
}
set_exception_handler("handleExceptions");
//AUTOCOMPLETE
spl_autoload_register(function ($class){
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class) . ".php";
require_once $class;
});
session_start();
$fileNotFoundFlag = false;
$controllerName = isset($_GET["target"]) ? $_GET["target"] : "video";
$methodName = isset($_GET["action"]) ? $_GET["action"] : "getAll";
$view = isset($_GET["view"]) ? $_GET["view"] : "main";
/*if (!isset($_SESSION["logged_user"])) {
$controllerName="view";
$methodName="viewRouter";
$view = "login";
}*/
$controllerClassName = "\\controller\\" . ucfirst($controllerName) . "Controller";
if (class_exists($controllerClassName)){
$controller = new $controllerClassName();
if($controllerName == "view"){
if (isset($_SESSION["logged_user"])) {
$controller->$methodName($view);
}
else {
if ($view != 'login' && $view != 'register') {
$controller->$methodName('login');
die();
}
else {
$controller->$methodName($view);
}
}
} else if (method_exists($controller, $methodName)){
if (!(in_array($methodName, array ("login", "register", "getById", "getByOwnerId", "getAll",
"getTrending", "getHistory", "getWatchLater", "getLikedVideos", "getMyPlaylists", "subscriptions",
"clickedUser", "clickedPlaylist", "search", "viewRouter")))){
if (!isset($_SESSION["logged_user"])){
header("HTTP/1.0 401 Not Authorized");
die();
}
}
return $controller->$methodName();
}
else {
$fileNotFoundFlag = true;
}
}
else {
$fileNotFoundFlag = true;
}
if ($fileNotFoundFlag === true){
header("Location:index.php?target=video&action=getAll");
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="styles/style.css">
<link rel="script" href="js/script.js">
<title>Document</title>
</head>
<body>