1
|
|
|
<?php |
2
|
|
|
namespace core\admin\contenus; |
3
|
|
|
|
4
|
|
|
use core\App; |
5
|
|
|
use core\contenus\Contenus; |
6
|
|
|
use core\functions\ChaineCaractere; |
7
|
|
|
use core\HTML\flashmessage\FlashMessage; |
8
|
|
|
|
9
|
|
|
class GestionContenus extends Contenus { |
10
|
|
|
use GestionErreurContenus; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
14
|
|
|
public function getErreur() { |
15
|
|
|
return $this->erreur; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
private function getParentId($parent) { |
19
|
|
|
$dbc = \core\App::getDb(); |
20
|
|
|
|
21
|
|
|
if ($parent == "") { |
22
|
|
|
return 0; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$query = $dbc->select("ID_page")->from("page")->where("titre", " LIKE ", '"%'.$parent.'%"', "", true)->get(); |
26
|
|
|
|
27
|
|
|
if (count($query) == 1) { |
28
|
|
|
foreach ($query as $obj) { |
29
|
|
|
return $obj->ID_page; |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return 0; |
34
|
|
|
} |
35
|
|
|
//-------------------------- FIN GETTER ----------------------------------------------------------------------------// |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
|
39
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
40
|
|
|
/** |
41
|
|
|
* @param string $new_page |
42
|
|
|
* @return bool |
43
|
|
|
*/ |
44
|
|
|
private function setCreerFichier($new_page) { |
45
|
|
|
$page_type = ROOT."config/page_type/page_type.html"; |
46
|
|
|
|
47
|
|
|
if ((!file_exists($new_page)) && (copy($page_type, $new_page))) { |
48
|
|
|
return true; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
FlashMessage::setFlash("Impossible de créer cette page, veuillez réeseyer dans un moment. Si le problème persiste contactez votre administrateur."); |
52
|
|
|
$this->erreur = true; |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* fonction qui permet de créer un page |
58
|
|
|
* @param $balise_title |
59
|
|
|
* @param $url |
60
|
|
|
* @param $meta_description |
61
|
|
|
* @param $titre_page |
62
|
|
|
* @param $parent |
63
|
|
|
*/ |
64
|
|
|
public function setCreerPage($balise_title, $url, $meta_description, $titre_page, $parent, $affiche = 1) { |
65
|
|
|
$dbc = \core\App::getDb(); |
66
|
|
|
$url = ChaineCaractere::setUrl($url); |
67
|
|
|
$nom_page = explode("/", $url); |
68
|
|
|
$nom_page = end($nom_page); |
69
|
|
|
$new_page = ROOT."app/views/".$nom_page.".html"; |
70
|
|
|
$this->getTestParam($balise_title, $url, $meta_description, $titre_page); |
71
|
|
|
|
72
|
|
|
if ($this->erreur === true) { |
73
|
|
|
$this->setErreurContenus(); |
74
|
|
|
return false; |
75
|
|
|
} |
76
|
|
|
if ($this->setCreerFichier($new_page) === false) { |
77
|
|
|
return false; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$parent = intval($this->getParentId($parent)); |
81
|
|
|
$dbc->insert("titre", $titre_page)->insert("url", $url)->insert("meta_description", $meta_description) |
82
|
|
|
->insert("balise_title", $balise_title)->insert("parent", $parent) |
83
|
|
|
->insert("affiche", $affiche)->into("page")->set(); |
84
|
|
|
|
85
|
|
|
$this->id_page = $dbc->lastInsertId(); |
86
|
|
|
$this->url = $url; |
87
|
|
|
if ($parent == "") { |
88
|
|
|
$this->setAjoutLienNavigation("ID_page", $this->id_page, 1); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* function that will create a redirection on an other site |
94
|
|
|
* @param $balise_title |
95
|
|
|
* @param $url |
96
|
|
|
* @param $titre_page |
97
|
|
|
* @param $parent |
98
|
|
|
*/ |
99
|
|
|
public function setCreerPageRedirect($balise_title, $url, $titre_page, $parent, $affiche = 1) { |
100
|
|
|
$dbc = \core\App::getDb(); |
101
|
|
|
$this->getTestParam($balise_title, $url, "", $titre_page); |
102
|
|
|
|
103
|
|
|
if ($this->erreur !== true) { |
104
|
|
|
$parent = intval($this->getParentId($parent)); |
105
|
|
|
$dbc->insert("titre", $titre_page)->insert("url", $url)->insert("balise_title", $balise_title)->insert("parent", $parent)->insert("affiche", $affiche)->insert("target", "_blanck")->into("page")->set(); |
106
|
|
|
$this->id_page = $dbc->lastInsertId(); |
107
|
|
|
if ($parent == "") { |
108
|
|
|
$this->setAjoutLienNavigation("ID_page", $this->id_page, 1); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
else { |
112
|
|
|
$this->setErreurContenus(); |
113
|
|
|
$this->erreur = true; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* fonction qui permet de modifier une page en fonction de son id |
119
|
|
|
* @param $id_page |
120
|
|
|
* @param $balise_title |
121
|
|
|
* @param $url |
122
|
|
|
* @param $meta_description |
123
|
|
|
* @param $titre_page |
124
|
|
|
* @param $parent |
125
|
|
|
* @param $contenu |
126
|
|
|
*/ |
127
|
|
|
public function setModifierPage($id_page, $balise_title, $url, $meta_description, $titre_page, $parent, $affiche = 1) { |
128
|
|
|
$dbc = \core\App::getDb(); |
129
|
|
|
$new_url = explode("/", $url); |
130
|
|
|
$new_filename = ROOT."app/views/".ChaineCaractere::setUrl(end($new_url)).".html"; |
131
|
|
|
|
132
|
|
|
if ((file_exists($new_filename) || ($id_page == 1)) && ($this->url != $url)) {echo("fdg"); |
133
|
|
|
FlashMessage::setFlash("Impossible de modifier cette page, veuillez contacter votre administrateur pour corriger ce problème"); |
134
|
|
|
$this->erreur = true; |
135
|
|
|
return false; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$this->id_page = $id_page; |
139
|
|
|
$this->getTestParam($balise_title, $url, $meta_description, $titre_page, $id_page); |
140
|
|
|
|
141
|
|
|
if ($this->erreur !== true) { |
142
|
|
|
$old_url = explode("/", $this->url); |
143
|
|
|
$filename = ROOT."app/views/".end($old_url).".html"; |
144
|
|
|
|
145
|
|
|
rename($filename, $new_filename); |
146
|
|
|
|
147
|
|
|
$parent = intval($this->getParentId($parent)); |
148
|
|
|
$dbc->update("titre", $titre_page) |
149
|
|
|
->update("url", ChaineCaractere::setUrl(end($new_url))) |
150
|
|
|
->update("meta_description", $meta_description) |
151
|
|
|
->update("balise_title", $balise_title) |
152
|
|
|
->update("parent", $parent) |
153
|
|
|
->update("affiche", $affiche) |
154
|
|
|
->from("page")->where("ID_page", "=", $id_page, "", true) |
155
|
|
|
->set(); |
156
|
|
|
|
157
|
|
|
$this->setModifierLienNavigation("ID_page", $id_page, $this->getParentId($parent), $affiche); |
158
|
|
|
$this->url = ChaineCaractere::setUrl(end($new_url)); |
159
|
|
|
} |
160
|
|
|
else { |
161
|
|
|
$this->setErreurContenus(); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param $id_page |
167
|
|
|
* @param $contenu |
168
|
|
|
*/ |
169
|
|
|
public function setModifierContenu($id_page, $contenu) { |
170
|
|
|
$dbc = \core\App::getDb(); |
171
|
|
|
|
172
|
|
|
$dbc->update("contenu", $contenu)->from("page")->where("ID_page", "=", $id_page)->set(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* fonction qui permet de supprimer une page, test si fichier exist, si oui on delete |
177
|
|
|
* @param $id_page |
178
|
|
|
*/ |
179
|
|
|
public function setSupprimerPage() { |
180
|
|
|
$url = explode("/", $this->url); |
181
|
|
|
$filename = ROOT."app/views/".end($url).".html"; |
182
|
|
|
|
183
|
|
|
if (file_exists($filename) && $this->id_page != 1) { |
184
|
|
|
unlink($filename); |
185
|
|
|
$this->setSupprimerLienNavigation(); |
186
|
|
|
|
187
|
|
|
return true; |
188
|
|
|
} |
189
|
|
|
else if (ChaineCaractere::FindInString($this->url, "http://") === true) { |
190
|
|
|
$this->setSupprimerLienNavigation(); |
191
|
|
|
} |
192
|
|
|
else { |
193
|
|
|
FlashMessage::setFlash("Impossible de supprimer cette page, veuillez contacter votre administrateur pour corriger ce problème"); |
194
|
|
|
$this->erreur = true; |
195
|
|
|
return false; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param string $id |
201
|
|
|
* @param string $value_id |
202
|
|
|
* @param integer $affiche |
203
|
|
|
*/ |
204
|
|
|
private function setAjoutLienNavigation($id, $value_id, $affiche) { |
205
|
|
|
if ($affiche !== null) { |
206
|
|
|
App::getNav()->setAjoutLien($id, $value_id); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param string $id |
212
|
|
|
* @param integer $affiche |
213
|
|
|
*/ |
214
|
|
|
private function setModifierLienNavigation($id, $id_page, $parent, $affiche) { |
215
|
|
|
if ($parent != "") { |
216
|
|
|
App::getNav()->setSupprimerLien($id, $id_page); |
217
|
|
|
} |
218
|
|
|
else if (($affiche == 0) && ($parent == "")) { |
219
|
|
|
App::getNav()->setSupprimerLien($id, $id_page); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* delete link in nav and delete page in table |
225
|
|
|
*/ |
226
|
|
|
private function setSupprimerLienNavigation() { |
227
|
|
|
$dbc = App::getDb(); |
228
|
|
|
|
229
|
|
|
$dbc->delete()->from("page")->where("ID_page", "=", $this->id_page)->del(); |
230
|
|
|
|
231
|
|
|
App::getNav()->setSupprimerLien("ID_page", $this->id_page); |
232
|
|
|
} |
233
|
|
|
//-------------------------- FIN SETTER ----------------------------------------------------------------------------// |
234
|
|
|
} |