-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
152 lines (148 loc) · 6.76 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
session_start();
require_once('vendor/autoload.php');
use \Blog\Controllers\Frontend\FrontendController;
use \Blog\Controllers\Backend\BackendController;
try {
if (!empty($_GET['action'])) {
if ($_GET['action'] == 'listPostsView') {
$frontendController = new FrontendController();
echo $frontendController->listPostsView();
} elseif ($_GET['action'] == 'postView') {
if (isset($_GET['id']) && $_GET['id'] > 0 && !isset($_GET['report'])) {
$frontendController = new FrontendController();
echo $frontendController->postView($_GET['id']);
} elseif (isset($_GET['id']) && $_GET['id'] > 0 && isset($_GET['report']) && $_GET['report'] = true ) {
$frontendController = new FrontendController();
echo $frontendController->postView();
} else {
throw new Exception('L\'id du billet est invalide');
}
} elseif ($_GET['action'] == 'addComment') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
if (!empty($_POST['pseudo']) && !empty($_POST['content'])) {
$frontendController = new FrontendController();
$frontendController->addComment(htmlspecialchars($_GET['id']), htmlspecialchars($_POST['pseudo']), htmlspecialchars($_POST['content']));
if ($affectedPost === false) {
throw new Exception('Impossible d\'ajouter le commentaire !');
} else {
header('Location: index.php?action=postView&id=' . $_GET['id']);
}
} else {
throw new Exception('Tous les champs ne sont pas remplis !');
}
}
} elseif ($_GET['action'] == 'reportComment') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
if (isset($_GET['postid']) && $_GET['postid'] > 0) {
$frontendController = new FrontendController();
$frontendController->reportComment(htmlspecialchars($_GET['id']));
header('location: index.php?action=postView&id=' . $_GET['postid']);
} else {
throw new Exception('L\'id de l\'article n\'est pas valide');
}
} else {
throw new Exception('L\'id du commentaire n\'est pas valide');
}
} elseif ($_GET['action'] == 'loginView' ) {
$frontendController = new FrontendController();
echo $frontendController->loginView();
} elseif ($_GET['action'] == 'verifyLogin' ) {
if (!empty($_POST['pseudo']) && !empty($_POST['password'])) {
$frontendController = new FrontendController();
if ($frontendController->verifyLogin(htmlspecialchars($_POST['pseudo']), htmlspecialchars($_POST['password']))) {
header('location: index.php?action=listPostsAdmin');
} else {
throw new Exception('Identifiant ou mot de pass invalide');
}
} else {
throw new Exception('identifiant manquant');
}
} elseif ($_GET['action'] == 'legalNoticeView') {
$frontendController = new FrontendController();
echo $frontendController->legalNoticeView();
}
/*------------------------Admin Part------------------------*/
elseif ($_SESSION){
if ($_GET['action'] == 'listPostsAdmin') {
$backendController = new BackendController();
echo $backendController->listPostsAdmin();
} elseif ($_GET['action'] == 'listCommentsAdmin') {
$backendController = new BackendController();
echo $backendController->listCommentsAdmin();
} elseif ($_GET['action'] == 'restoreComment') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
$backendController = new backendController();
$backendController->restoreComment(htmlspecialchars($_GET['id']));
header('location: index.php?action=listCommentsAdmin');
} else {
throw new Exception('L\'id n\'est pas valide');
}
} elseif ($_GET['action'] == 'addPost') {
if (!empty($_POST['title']) && !empty($_POST['content'])) {
$backendController = new backendController();
$backendController->addPost(htmlspecialchars($_POST['title']), $_POST['content']);
if ($affectedLines === false) {
throw new Exception('Impossible d\'ajouter l\'article');
} else {
header('Location: index.php?action=listPostsAdmin');
}
} else {
throw new Exception('Tous les champs ne sont pas remplis !');
}
} elseif ($_GET['action'] == 'removeComment') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
$backendController = new backendController();
$backendController->removeComment(htmlspecialchars($_GET['id']));
header('location: index.php?action=listCommentsAdmin');
} else {
throw new Exception('L\'id n\'est pas valide');
}
} elseif ($_GET['action'] == 'removePost') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
$backendController = new backendController();
$backendController->removePost(htmlspecialchars($_GET['id']));
header('location: index.php?action=listPostsAdmin');
} else {
throw new Exception('L\'id n\'est pas valide');
}
} elseif ($_GET['action'] == 'newPostAdmin') {
$backendController = new BackendController();
echo $backendController->newPostAdmin();
} elseif ($_GET['action'] == 'modifPostAdmin') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
$backendController = new BackendController();
echo $backendController->modifPostAdmin(htmlspecialchars($_GET['id']));
} else {
throw new Exception('L\'id du billet est invalide');
}
} elseif ($_GET['action'] == 'sendModifPost') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
if (!empty($_POST['title']) && !empty($_POST['content'])) {
$backendController = new BackendController();
$backendController->sendModifPost(htmlspecialchars($_POST['title']), $_POST['content'], htmlspecialchars($_GET['id']));
header('location: index.php?action=listPostsAdmin');
} else {
throw new Exception('Les champs n\'ons pas étais remplis');
}
} else {
throw new Exception('L\'id du billet est invalide');
}
} elseif ($_GET['action'] == 'sessionDestroy') {
$backendController = new BackendController();
$backendController->sessionDestroy();
header('location: index.php');
} else {
throw new Exception('Session expirée ou page introuvable');
}
} else {
throw new Exception('Session expirée ou page introuvable');
}
} else {
$frontendController = new FrontendController();
echo $frontendController->listPostsView();
}
}
catch (Exception $e) {
echo 'Erreur: ' .$e->getMessage();
}