-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.php
More file actions
109 lines (107 loc) · 4.17 KB
/
router.php
File metadata and controls
109 lines (107 loc) · 4.17 KB
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
<?php
/**
* Routing
* PHP version 7.1.9
*
* @category Routing
* @package Projet3
* @author Neok <neokdev@gmail.com>
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @see http://www.projet3.nekbot.com/
*/
require 'controller/frontend/post.php';
require 'controller/frontend/comment.php';
require 'controller/backend/admin.php';
require 'controller/backend/adminpost.php';
require 'controller/backend/admincomment.php';
require 'controller/backend/login.php';
try {
if (isset($_GET['action'])) {
if ($_GET['action'] == 'getPosts') {
getPosts();
} elseif ($_GET['action'] == 'post') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
getPostComment($_GET['id']);
} else {
throw new Exception('Aucun identifiant de billet envoyé');
}
} elseif ($_GET['action'] == 'addComment') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
if (!empty($_POST['author']) && !empty($_POST['comment'])) {
addComment($_GET['id'], $_POST['author'], $_POST['comment'], $_POST['g-recaptcha-response']);
} else {
throw new Exception('Tous les champs ne sont pas remplis !');
}
} else {
throw new Exception('Aucun identifiant de billet envoyé');
}
} elseif ($_GET['action'] == 'addpost') {
if (!empty($_POST['title']) && !empty($_POST['postContent'])) {
addPost($_POST['title'], $_POST['postContent']);
} else {
throw new Exception('Tous les champs ne sont pas remplis !');
}
} elseif ($_GET['action'] == 'setpost') {
if (isset($_GET['id']) && isset($_POST['title']) && isset($_POST['postContent'])) {
setPost($_GET['id'], $_POST['title'], $_POST['postContent']);
} elseif (isset($_GET['id'])) {
showAdminSetPost($_GET['id']);
} else {
throw new Exception('L\'id de billet est invalide.');
}
} elseif ($_GET['action'] == 'logout') {
include 'controller/backend/logout.php';
logout();
} elseif ($_GET['action'] == 'deletepost') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
delPost($_GET['id']);
} else {
throw new Exception('Erreur de suppréssion de billet.');
}
} elseif ($_GET['action'] == 'reportcomment') {
SetReportComment($_GET['post_id'], $_GET['id']);
} elseif ($_GET['action'] == 'allowcomment') {
setAllowComment($_GET['id']);
} elseif ($_GET['action'] == 'deleteuser') {
delUser($_GET['id']);
} elseif ($_GET['action'] == 'deletecomment') {
delComment($_GET['id']);
} else {
throw new Exception('Action incorrecte');
}
} elseif (isset($_GET['p'])) {
if ($_GET['p'] == 'login') {
if (isset($_POST['submitlogin'])) {
if (!empty($_POST['email']) && !empty($_POST['password'])) {
login($_POST['email'], $_POST['password']);
} else {
throw new Exception('Veuillez remplir tous les champs');
}
} else {
showLogin();
}
} elseif ($_GET['p'] == 'admin') {
if (isset($_POST['mail'])) {
setUser($_POST['mailmail'], $_POST['mailconfirm'], $_POST['mailpass']);
} elseif (isset($_POST['pass'])) {
setUserPass($_POST['passpass'], $_POST['passconfirm']);
} elseif (isset($_POST['user'])) {
addUser($_POST['adminmail'], $_POST['adminpass'], $_POST['adminconfirm']);
} else {
showAdmin();
}
} elseif ($_GET['p'] == 'home') {
getPosts();
} else {
header('HTTP/1.1 404 Not Found');
}
} else {
getPosts();
}
}
catch(Exception $e) {
$errorMessage = $e->getMessage();
include '../views/errorView.php';
include '../views/nav.php';
include '../views/template.php';
}