-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
130 lines (115 loc) · 4.64 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
function autoloader($class) {
$fileLib = 'lib/' . $class . '.php';
$fileCont = 'controller/' . $class . '.php';
$fileView = 'view/' . $class . '.php';
$fileConf = 'config/' . $class . '.php';
$fileModel = 'model/' . $class . '.php';
if(file_exists($fileLib)){
require_once $fileLib;
} else if(file_exists($fileCont)){
require_once $fileCont;
}else if(file_exists($fileView)){
require_once $fileView;
}else if(file_exists($fileConf)){
require_once $fileConf;
}else if(file_exists($fileModel)){
require_once $fileModel;
}
}
spl_autoload_register('autoloader');
require_once("/config/conf.php");/*
require_once("/lib/Controller.php");*/
$url = isset($_GET['url'])? $_GET['url'] : 'index';
$url = rtrim($url, '/');
$url = explode('/',$url);
if(!checkController($url[0]) || count($url) > 3){
$controller = new Error("Zadaná stránka neexistuje!");
$controller->index();
return false;
}
$controller = new $url[0];
if(isset($url[2])){
if (method_exists($controller, $url[1])){
$reflection = new ReflectionMethod($controller, $url[1]);
if($reflection->isPublic() && $url[1] != "__construct"){
$controller->$url[1]($url[2]);
}else {
$controller = new Error("Zadaná stránka neexistuje");
$controller->index();
}
} else {
$controller = new Error("Zadaná stránka neexistuje");
$controller->index();
}
return false;
return false;
}else if(isset($url[1])){
if (method_exists($controller, $url[1])){
$reflection = new ReflectionMethod($controller, $url[1]);
if($reflection->isPublic() && $url[1] != "__construct"){
$controller->$url[1]();
}else {
$controller = new Error("Zadaná stránka neexistuje");
$controller->index();
}
} else {
$controller = new Error("Zadaná stránka neexistuje");
$controller->index();
}
return false;
}
$controller->index();
function checkController($url){
return file_exists('controller/' . $url . '.php') && is_subclass_of($url, "Controller");
}
/*require_once 'Twig/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader); // takhle je to bez cache
$template = $twig->loadTemplate('template1.html');
session_start();
$url = "index samotny";
if (isset($_GET['url'])) {
$url = $_GET['url'];
if($url == 'login'){
$_SESSION['lol'] = 'lol';
}else if($url == 'logout'){
$_SESSION = array();
session_destroy();
}else if($url == 'upform'){
$template = $twig->loadTemplate('template2.html');
}else if($url == 'upload'){
$target_dir = "uploads/";
$uploadOk = 1;
if(isset($_FILES["fileToUpload"])){
$imageFileType = pathinfo(basename($_FILES["fileToUpload"]["name"]),PATHINFO_EXTENSION);
$target_file = $target_dir . 'lol' . rand(10,100) . "." . $imageFileType;
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = @getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
} else {
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
}
echo $template->render(array('url' => $url, 'title' => 'INDEX', 'debug' => print_r($_SESSION,true)));*/
?>