-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
133 lines (130 loc) · 4.9 KB
/
Copy pathindex.php
File metadata and controls
133 lines (130 loc) · 4.9 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
require('controller/frontend.php');
require('controller/backend.php');
try {
$action = (isset($_GET['action']) ? $_GET['action'] : 'justShowHome' );
switch ($action) {
case "listPosts":
$frontendController = new FrontendController;
$frontendController->listPosts();
break;
case "post":
if (isset($_GET['id']) && $_GET['id'] > 0) {
$frontendController = new FrontendController;
$frontendController->post();
} else {
throw new Exception('Missing id');
}
break;
case "showBlog":
$frontendController = new FrontendController;
if(isset($_GET['page'])) {
$frontendController->showBlog($_GET['page']);
} else {
$frontendController->showBlog();
}
break;
case "showAbout":
$frontendController = new FrontendController;
$frontendController->showAbout();
break;
case "addComment":
if (isset($_GET['id']) && $_GET['id'] > 0) {
if (!empty($_POST['author']) && !empty($_POST['content'])&& !empty($_POST['email'])) {
$frontendController = new FrontendController;
$frontendController->addComment($_GET['id'], $_POST['author'],$_POST['email'], $_POST['content'], $_POST['responseId']);
}
else {
throw new Exception('Tous les champs ne sont pas remplis !');
}
}
else {
throw new Exception('Aucun identifiant de billet envoyé');
}
break;
case "flagComment":
if (isset($_GET['commentId']) && isset($_GET['postId']) && isset($_GET['status']) && $_GET['commentId'] > 0 && $_GET['postId'] > 0 ){
$frontendController = new FrontendController;
$frontendController->flagComment($_GET['commentId'], $_GET['postId'], $_GET['status'] );
} else {
throw new Exception('Impossible de signaler ce commentaire');
}
break;
case "showLogin":
$backendController = new BackendController();
$backendController->showLogin();
break;
case "login":
if(isset($_POST['email']) && isset($_POST['password'])) {
if(!empty($_POST['email']) && !empty($_POST['password'])) {
$backendController = new BackendController();
$rememberMe = (isset($_POST['rememberMe']) ? true : false );
$backendController->login($_POST['email'], $_POST['password'], $rememberMe);
} else {
throw new Exception('You should provide both an email and a passord');
}
} else {
throw new Exception('You should provide both an email and a passord');
}
break;
case "showDashboard":
$backendController = new BackendController();
$backendController->showDashboard();
break;
case "showDashboardPosts":
$backendController = new BackendController();
if(isset($_GET['page'])) {
$backendController->showPaginatedPosts($_GET['page']);
} else {
$backendController->showPaginatedPosts();
}
break;
case "showDashboardComments":
$backendController = new BackendController();
if(isset($_GET['page'])) {
$backendController->showPaginatedComments($_GET['page']);
} else {
$backendController->showPaginatedComments();
}
break;
case "updateComment":
if (isset($_GET['commentId']) && isset($_GET['status']) && isset($_GET['url'])) {
$backendController = new BackendController();
$backendController->updateComment($_GET['commentId'], $_GET['status'], $_GET['url']);
}
break;
case "updatePost":
$backendController = new BackendController();
if (isset($_GET['status']) && isset($_GET['postId']) && $_GET['postId'] > 0 ){
$backendController->updatePostStatus($_GET['postId'], $_GET['status'], $_GET['return'] );
} elseif(isset($_GET['id']) && isset($_POST['title']) && isset($_POST['content']) && $_GET['id'] > 0) {
$backendController->updatePostContent($_GET['id'], $_POST['title'], $_POST['content']);
} elseif(isset($_POST['title']) && isset($_POST['content'])) {
$backendController->addPost($_POST['title'], $_POST['content']);
} else {
throw new Exception('Impossible de publier cet article');
}
break;
case "deletePost":
$backendController = new BackendController();
if (isset($_GET['postId']) && $_GET['postId'] > 0 ){
$backendController->deletePost($_GET['postId'], $_GET['return'] );
}
break;
case "showEditor":
$backendController = new BackendController();
$backendController->showEditor($_GET['id']);
break;
case "logout":
$backendController = new BackendController();
$backendController->logout();
break;
default:
$frontendController = new FrontendController;
$frontendController->listPosts();
break;
}
} catch (Exception $e) {
$errorMessage = $e->getMessage();
require('view/errorView.php');
}