|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
HCSF - A multilingual CMS and Shopsystem |
|
5
|
|
|
Copyright (C) 2014 Marcus Haase - [email protected] |
|
6
|
|
|
|
|
7
|
|
|
This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
it under the terms of the GNU General Public License as published by |
|
9
|
|
|
the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
(at your option) any later version. |
|
11
|
|
|
|
|
12
|
|
|
This program is distributed in the hope that it will be useful, |
|
13
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
GNU General Public License for more details. |
|
16
|
|
|
|
|
17
|
|
|
You should have received a copy of the GNU General Public License |
|
18
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace HaaseIT\HCSF\Controller\Admin; |
|
22
|
|
|
|
|
23
|
|
|
use HaaseIT\HCSF\HelperConfig; |
|
24
|
|
|
use HaaseIT\HCSF\UserPage; |
|
25
|
|
|
use HaaseIT\HCSF\HardcodedText; |
|
26
|
|
|
use Zend\ServiceManager\ServiceManager; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Class Pageadmin |
|
30
|
|
|
* @package HaaseIT\HCSF\Controller\Admin |
|
31
|
|
|
*/ |
|
32
|
|
|
class Pageadmin extends Base |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var \Zend\Diactoros\ServerRequest |
|
36
|
|
|
*/ |
|
37
|
|
|
private $request; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var null|array|object |
|
41
|
|
|
*/ |
|
42
|
|
|
private $post; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
private $get; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Pageadmin constructor. |
|
51
|
|
|
* @param ServiceManager $serviceManager |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct(ServiceManager $serviceManager) |
|
54
|
|
|
{ |
|
55
|
|
|
parent::__construct($serviceManager); |
|
56
|
|
|
/** @var \Zend\Diactoros\ServerRequest request */ |
|
57
|
|
|
$this->request = $serviceManager->get('request'); |
|
58
|
|
|
$this->post = $this->request->getParsedBody(); |
|
59
|
|
|
$this->get = $this->request->getQueryParams(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* |
|
64
|
|
|
*/ |
|
65
|
|
|
public function preparePage() |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
$this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager); |
|
68
|
|
|
$this->P->cb_pagetype = 'content'; |
|
69
|
|
|
$this->P->cb_subnav = 'admin'; |
|
70
|
|
|
|
|
71
|
|
|
$this->P->cb_customcontenttemplate = 'pageadmin'; |
|
72
|
|
|
|
|
73
|
|
|
// adding language to page here |
|
74
|
|
|
if (isset($_REQUEST["action"]) && $_REQUEST["action"] === 'insert_lang') { |
|
75
|
|
|
$this->insertLang(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (!isset($this->get["action"])) { |
|
79
|
|
|
$this->P->cb_customdata["pageselect"] = $this->showPageselect(); |
|
80
|
|
|
} elseif (($this->get["action"] === 'edit' || $this->get["action"] === 'delete') && isset($_REQUEST["page_key"]) && $_REQUEST["page_key"] != '') { |
|
81
|
|
|
if ($this->get["action"] === 'delete' && isset($this->post["delete"]) && $this->post["delete"] === 'do') { |
|
82
|
|
|
$this->handleDeletePage(); |
|
83
|
|
|
} else { // edit or update page |
|
84
|
|
|
$this->handleEditPage(); |
|
85
|
|
|
} |
|
86
|
|
|
} elseif ($this->get["action"] === 'addpage') { |
|
87
|
|
|
$this->handleAddPage(); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
protected function handleDeletePage() |
|
92
|
|
|
{ |
|
93
|
|
|
// delete and put message in customdata |
|
94
|
|
|
$Ptodelete = new UserPage($this->serviceManager, $this->get["page_key"], true); |
|
95
|
|
|
if ($Ptodelete->cb_id != NULL) { |
|
96
|
|
|
$Ptodelete->remove(); |
|
97
|
|
|
} else { |
|
98
|
|
|
die(HardcodedText::get('pageadmin_exception_pagetodeletenotfound')); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
$this->P->cb_customdata["deleted"] = true; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
protected function handleAddPage() |
|
104
|
|
|
{ |
|
105
|
|
|
$aErr = []; |
|
106
|
|
|
if (isset($this->post["addpage"]) && $this->post["addpage"] === 'do') { |
|
107
|
|
|
$sPagekeytoadd = \trim(\filter_input(INPUT_POST, 'pagekey', FILTER_SANITIZE_SPECIAL_CHARS)); |
|
108
|
|
|
|
|
109
|
|
|
if (mb_substr($sPagekeytoadd, 0, 2) === '/_') { |
|
110
|
|
|
$aErr["reservedpath"] = true; |
|
111
|
|
|
} elseif (strlen($sPagekeytoadd) < 4) { |
|
112
|
|
|
$aErr["keytooshort"] = true; |
|
113
|
|
|
} else { |
|
114
|
|
|
$Ptoadd = new UserPage($this->serviceManager, $sPagekeytoadd, true); |
|
115
|
|
|
if ($Ptoadd->cb_id == NULL) { |
|
116
|
|
|
if ($Ptoadd->insert($sPagekeytoadd)) { |
|
117
|
|
|
header('Location: /_admin/pageadmin.html?page_key='.$sPagekeytoadd.'&action=edit'); |
|
118
|
|
|
die(); |
|
|
|
|
|
|
119
|
|
|
} else { |
|
120
|
|
|
die(HardcodedText::get('pageadmin_exception_couldnotinsertpage')); |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
} else { |
|
123
|
|
|
$aErr["keyalreadyinuse"] = true; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
$this->P->cb_customdata["err"] = $aErr; |
|
127
|
|
|
unset($aErr); |
|
128
|
|
|
} |
|
129
|
|
|
$this->P->cb_customdata["showaddform"] = true; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @return array |
|
134
|
|
|
*/ |
|
135
|
|
|
protected function showPageselect() { |
|
136
|
|
|
$aGroups = []; |
|
137
|
|
|
foreach (HelperConfig::$core["admin_page_groups"] as $sValue) { |
|
138
|
|
|
$TMP = explode('|', $sValue); |
|
139
|
|
|
$aGroups[$TMP[0]] = $TMP[1]; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
$dbal = $this->serviceManager->get('dbal'); |
|
143
|
|
|
|
|
144
|
|
|
/** @var \Doctrine\DBAL\Query\QueryBuilder $queryBuilder */ |
|
145
|
|
|
$queryBuilder = $dbal->createQueryBuilder(); |
|
146
|
|
|
$queryBuilder |
|
147
|
|
|
->select('*') |
|
148
|
|
|
->from('content_base') |
|
149
|
|
|
->orderBy('cb_key') |
|
150
|
|
|
; |
|
151
|
|
|
$statement = $queryBuilder->execute(); |
|
152
|
|
|
|
|
153
|
|
|
while ($aResult = $statement->fetch()) { |
|
154
|
|
|
if (isset($aGroups[$aResult["cb_group"]])) { |
|
155
|
|
|
$aTree[$aResult["cb_group"]][] = $aResult; |
|
|
|
|
|
|
156
|
|
|
} else { |
|
157
|
|
|
$aTree["_"][] = $aResult; |
|
|
|
|
|
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
foreach ($aGroups as $sKey => $sValue) { |
|
162
|
|
|
if (isset($aTree[$sKey])) { |
|
163
|
|
|
$aOptions_g[] = $sKey.'|'.$sValue; |
|
|
|
|
|
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
return [ |
|
168
|
|
|
'options_groups' => isset($aOptions_g) ? $aOptions_g : [], |
|
169
|
|
|
'tree' => isset($aTree) ? $aTree : [], |
|
170
|
|
|
]; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
protected function insertLang() |
|
|
|
|
|
|
174
|
|
|
{ |
|
175
|
|
|
$Ptoinsertlang = new UserPage($this->serviceManager, $_REQUEST["page_key"], true); |
|
176
|
|
|
|
|
177
|
|
|
if ($Ptoinsertlang->cb_id != NULL && $Ptoinsertlang->oPayload->cl_id == NULL) { |
|
|
|
|
|
|
178
|
|
|
$Ptoinsertlang->oPayload->insert($Ptoinsertlang->cb_id); |
|
|
|
|
|
|
179
|
|
|
header('Location: /_admin/pageadmin.html?page_key='.$Ptoinsertlang->cb_key.'&action=edit'); |
|
180
|
|
|
die(); |
|
|
|
|
|
|
181
|
|
|
} else { |
|
182
|
|
|
die(HardcodedText::get('pageadmin_exception_couldnotinsertlang')); |
|
|
|
|
|
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
protected function handleEditPage() |
|
|
|
|
|
|
187
|
|
|
{ |
|
188
|
|
|
if (isset($_REQUEST["page_key"]) && $Ptoedit = new UserPage($this->serviceManager, $_REQUEST["page_key"], true)) { |
|
189
|
|
|
if (isset($_REQUEST["action_a"]) && $_REQUEST["action_a"] === 'true') { |
|
190
|
|
|
$Ptoedit = $this->updatePage($Ptoedit); |
|
191
|
|
|
} |
|
192
|
|
|
$this->P->cb_customdata["page"] = $Ptoedit; |
|
193
|
|
|
$this->P->cb_customdata["admin_page_types"] = HelperConfig::$core["admin_page_types"]; |
|
194
|
|
|
$this->P->cb_customdata["admin_page_groups"] = HelperConfig::$core["admin_page_groups"]; |
|
195
|
|
|
$aOptions = ['']; |
|
196
|
|
|
foreach (HelperConfig::$navigation as $sKey => $aValue) { |
|
197
|
|
|
if ($sKey === 'admin') { |
|
198
|
|
|
continue; |
|
199
|
|
|
} |
|
200
|
|
|
$aOptions[] = $sKey; |
|
201
|
|
|
} |
|
202
|
|
|
$this->P->cb_customdata["subnavarea_options"] = $aOptions; |
|
203
|
|
|
unset($aOptions); |
|
204
|
|
|
|
|
205
|
|
|
// show archived versions of this page |
|
206
|
|
|
if ($Ptoedit->oPayload->cl_id != NULL) { |
|
207
|
|
|
|
|
208
|
|
|
$dbal = $this->serviceManager->get('dbal'); |
|
209
|
|
|
|
|
210
|
|
|
/** @var \Doctrine\DBAL\Query\QueryBuilder $queryBuilder */ |
|
211
|
|
|
$queryBuilder = $dbal->createQueryBuilder(); |
|
212
|
|
|
$queryBuilder |
|
213
|
|
|
->select('*') |
|
214
|
|
|
->from('content_lang_archive') |
|
215
|
|
|
->where('cl_id = ?') |
|
216
|
|
|
->andWhere('cl_lang = ?') |
|
217
|
|
|
->setParameter(0, $Ptoedit->oPayload->cl_id) |
|
|
|
|
|
|
218
|
|
|
->setParameter(1, HelperConfig::$lang) |
|
219
|
|
|
->orderBy('cla_timestamp', 'DESC') |
|
220
|
|
|
; |
|
221
|
|
|
$statement = $queryBuilder->execute(); |
|
222
|
|
|
$iArchivedRows = $statement->rowCount(); |
|
223
|
|
|
|
|
224
|
|
|
if ($iArchivedRows > 0) { |
|
225
|
|
|
$aListSetting = [ |
|
226
|
|
|
['title' => 'cla_timestamp', 'key' => 'cla_timestamp', 'width' => '15%', 'linked' => false,], |
|
227
|
|
|
['title' => 'cl_html', 'key' => 'cl_html', 'width' => '40%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
|
228
|
|
|
['title' => 'cl_keywords', 'key' => 'cl_keywords', 'width' => '15%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
|
229
|
|
|
['title' => 'cl_description', 'key' => 'cl_description', 'width' => '15%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
|
230
|
|
|
['title' => 'cl_title', 'key' => 'cl_title', 'width' => '15%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
|
231
|
|
|
]; |
|
232
|
|
|
$aData = $statement->fetchAll(); |
|
233
|
|
|
$this->P->cb_customdata['archived_list'] = \HaaseIT\Toolbox\Tools::makeListtable( |
|
234
|
|
|
$aListSetting, |
|
235
|
|
|
$aData, |
|
236
|
|
|
$this->serviceManager->get('twig') |
|
237
|
|
|
); |
|
238
|
|
|
} |
|
239
|
|
|
} |
|
240
|
|
|
} else { |
|
241
|
|
|
die(HardcodedText::get('pageadmin_exception_pagenotfound')); |
|
|
|
|
|
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
protected function updatePage(UserPage $Ptoedit) |
|
|
|
|
|
|
246
|
|
|
{ |
|
247
|
|
|
if (HelperConfig::$core['pagetext_enable_purifier']) { |
|
248
|
|
|
$purifier = \HaaseIT\HCSF\Helper::getPurifier('page'); |
|
249
|
|
|
} else { |
|
250
|
|
|
$purifier = false; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
$Ptoedit->cb_pagetype = $this->post['page_type']; |
|
254
|
|
|
$Ptoedit->cb_group = $this->post['page_group']; |
|
255
|
|
|
$Ptoedit->cb_pageconfig = $this->post['page_config']; |
|
256
|
|
|
$Ptoedit->cb_subnav = $this->post['page_subnav']; |
|
257
|
|
|
$Ptoedit->purifier = $purifier; |
|
258
|
|
|
$Ptoedit->write(); |
|
259
|
|
|
|
|
260
|
|
|
if ($Ptoedit->oPayload->cl_id != NULL) { |
|
|
|
|
|
|
261
|
|
|
$Ptoedit->oPayload->cl_html = $this->post['page_html']; |
|
262
|
|
|
$Ptoedit->oPayload->cl_title = $this->post['page_title']; |
|
263
|
|
|
$Ptoedit->oPayload->cl_description = $this->post['page_description']; |
|
264
|
|
|
$Ptoedit->oPayload->cl_keywords = $this->post['page_keywords']; |
|
265
|
|
|
$Ptoedit->oPayload->purifier = $purifier; |
|
|
|
|
|
|
266
|
|
|
$Ptoedit->oPayload->write(); |
|
|
|
|
|
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
$Ptoedit = new UserPage($this->serviceManager, $_REQUEST["page_key"], true); |
|
270
|
|
|
$this->P->cb_customdata["updated"] = true; |
|
271
|
|
|
|
|
272
|
|
|
return $Ptoedit; |
|
273
|
|
|
} |
|
274
|
|
|
} |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: