1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Admin\View; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Admin; |
5
|
|
|
use Redaxscript\Dater; |
6
|
|
|
use Redaxscript\Html; |
7
|
|
|
use Redaxscript\Module; |
8
|
|
|
use function count; |
9
|
|
|
use function htmlspecialchars; |
10
|
|
|
use function json_decode; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* children class to create the article form |
14
|
|
|
* |
15
|
|
|
* @since 3.0.0 |
16
|
|
|
* |
17
|
|
|
* @package Redaxscript |
18
|
|
|
* @category View |
19
|
|
|
* @author Henry Ruhs |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
class ArticleForm extends ViewAbstract |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* render the view |
26
|
|
|
* |
27
|
|
|
* @since 3.0.0 |
28
|
|
|
* |
29
|
|
|
* @param int $articleId identifier of the article |
30
|
|
|
* |
31
|
4 |
|
* @return string |
32
|
|
|
*/ |
33
|
4 |
|
|
34
|
4 |
|
public function render(int $articleId = null) : string |
35
|
4 |
|
{ |
36
|
4 |
|
$output = Module\Hook::trigger('adminArticleFormStart'); |
37
|
4 |
|
$helperOption = new Helper\Option($this->_language); |
38
|
4 |
|
$articleModel = new Admin\Model\Article(); |
39
|
|
|
$article = $articleModel->getById($articleId); |
40
|
|
|
$dater = new Dater(); |
41
|
|
|
$dater->init($article->date); |
42
|
4 |
|
|
43
|
|
|
/* html element */ |
44
|
4 |
|
|
45
|
|
|
$titleElement = new Html\Element(); |
46
|
4 |
|
$titleElement |
47
|
|
|
->init('h2', |
48
|
4 |
|
[ |
49
|
4 |
|
'class' => 'rs-admin-title-content', |
50
|
4 |
|
]) |
51
|
|
|
->text($article->title ? : $this->_language->get('article_new')); |
52
|
4 |
|
$formElement = new Admin\Html\Form($this->_registry, $this->_language); |
53
|
|
|
$formElement->init( |
54
|
|
|
[ |
55
|
|
|
'form' => |
56
|
|
|
[ |
57
|
|
|
'class' => 'rs-admin-js-validate rs-admin-js-alias rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default' |
58
|
|
|
], |
59
|
|
|
'button' => |
60
|
|
|
[ |
61
|
|
|
'create' => |
62
|
|
|
[ |
63
|
|
|
'name' => self::class |
64
|
|
|
], |
65
|
|
|
'save' => |
66
|
|
|
[ |
67
|
|
|
'name' => self::class |
68
|
|
|
] |
69
|
|
|
], |
70
|
|
|
'link' => |
71
|
4 |
|
[ |
72
|
|
|
'cancel' => |
73
|
|
|
[ |
74
|
|
|
'href' => $this->_registry->get('articlesEdit') && $this->_registry->get('articlesDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/articles' : $this->_registry->get('parameterRoute') . 'admin' |
75
|
4 |
|
], |
76
|
|
|
'delete' => |
77
|
|
|
[ |
78
|
|
|
'href' => $article->id ? $this->_registry->get('parameterRoute') . 'admin/delete/articles/' . $article->id . '/' . $this->_registry->get('token') : null |
79
|
|
|
] |
80
|
|
|
] |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
/* create the form */ |
84
|
|
|
|
85
|
|
|
$formElement |
86
|
4 |
|
|
87
|
|
|
/* article */ |
88
|
4 |
|
|
89
|
|
|
->radio( |
90
|
|
|
[ |
91
|
|
|
'id' => self::class . '\Article', |
92
|
|
|
'class' => 'rs-admin-fn-status-tab', |
93
|
4 |
|
'name' => self::class . '\Tab', |
94
|
|
|
'checked' => 'checked' |
95
|
4 |
|
]) |
96
|
|
|
->label($this->_language->get('article'), |
|
|
|
|
97
|
|
|
[ |
98
|
4 |
|
'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
99
|
4 |
|
'for' => self::class . '\Article' |
100
|
|
|
]) |
101
|
4 |
|
->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
102
|
|
|
->label($this->_language->get('title'), |
|
|
|
|
103
|
4 |
|
[ |
104
|
|
|
'for' => 'title' |
105
|
4 |
|
]) |
106
|
4 |
|
->text( |
107
|
4 |
|
[ |
108
|
4 |
|
'autofocus' => 'autofocus', |
109
|
4 |
|
'class' => 'rs-admin-js-alias-input rs-admin-field-default rs-admin-field-text', |
110
|
4 |
|
'id' => 'title', |
111
|
|
|
'name' => 'title', |
112
|
4 |
|
'required' => 'required', |
113
|
4 |
|
'value' => $article->title |
114
|
|
|
]) |
115
|
4 |
|
->append('</li><li>') |
116
|
|
|
->label($this->_language->get('alias'), |
|
|
|
|
117
|
4 |
|
[ |
118
|
|
|
'for' => 'alias' |
119
|
4 |
|
]) |
120
|
4 |
|
->text( |
121
|
4 |
|
[ |
122
|
4 |
|
'class' => 'rs-admin-js-alias-output rs-admin-field-default rs-admin-field-text', |
123
|
4 |
|
'id' => 'alias', |
124
|
4 |
|
'name' => 'alias', |
125
|
|
|
'pattern' => '[a-zA-Z0-9-]+', |
126
|
4 |
|
'required' => 'required', |
127
|
4 |
|
'value' => $article->alias |
128
|
|
|
]) |
129
|
4 |
|
->append('</li><li>') |
130
|
|
|
->label($this->_language->get('description'), |
|
|
|
|
131
|
4 |
|
[ |
132
|
|
|
'for' => 'description' |
133
|
4 |
|
]) |
134
|
4 |
|
->textarea( |
135
|
4 |
|
[ |
136
|
4 |
|
'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small', |
137
|
4 |
|
'id' => 'description', |
138
|
|
|
'name' => 'description', |
139
|
4 |
|
'rows' => 1, |
140
|
4 |
|
'value' => $article->description |
141
|
|
|
]) |
142
|
4 |
|
->append('</li><li>') |
143
|
|
|
->label($this->_language->get('keywords'), |
|
|
|
|
144
|
4 |
|
[ |
145
|
|
|
'for' => 'keywords' |
146
|
4 |
|
]) |
147
|
4 |
|
->textarea( |
148
|
4 |
|
[ |
149
|
4 |
|
'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small', |
150
|
4 |
|
'id' => 'keywords', |
151
|
|
|
'name' => 'keywords', |
152
|
4 |
|
'rows' => 1, |
153
|
4 |
|
'value' => $article->keywords |
154
|
|
|
]) |
155
|
4 |
|
->append('</li><li>') |
156
|
|
|
->label($this->_language->get('robots'), |
|
|
|
|
157
|
4 |
|
[ |
158
|
|
|
'for' => 'robots' |
159
|
4 |
|
]) |
160
|
|
|
->select($helperOption->getRobotArray(), |
161
|
|
|
[ |
162
|
4 |
|
$article->robots |
163
|
|
|
], |
164
|
|
|
[ |
165
|
4 |
|
'id' => 'robots', |
166
|
4 |
|
'name' => 'robots' |
167
|
|
|
]) |
168
|
4 |
|
->append('</li><li>') |
169
|
|
|
->label($this->_language->get('text'), |
|
|
|
|
170
|
4 |
|
[ |
171
|
|
|
'for' => 'text' |
172
|
4 |
|
]) |
173
|
4 |
|
->textarea( |
174
|
4 |
|
[ |
175
|
4 |
|
'class' => 'rs-admin-js-editor rs-admin-js-resize rs-admin-field-textarea', |
176
|
4 |
|
'id' => 'text', |
177
|
|
|
'name' => 'text', |
178
|
4 |
|
'required' => 'required', |
179
|
|
|
'value' => htmlspecialchars($article->text, ENT_QUOTES) |
180
|
|
|
]) |
181
|
|
|
->append('</li></ul>') |
182
|
4 |
|
|
183
|
|
|
/* general */ |
184
|
4 |
|
|
185
|
|
|
->radio( |
186
|
|
|
[ |
187
|
|
|
'id' => self::class . '\General', |
188
|
4 |
|
'class' => 'rs-admin-fn-status-tab', |
189
|
|
|
'name' => self::class . '\Tab' |
190
|
4 |
|
]) |
191
|
|
|
->label($this->_language->get('general'), |
|
|
|
|
192
|
|
|
[ |
193
|
4 |
|
'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
194
|
4 |
|
'for' => self::class . '\General' |
195
|
|
|
]) |
196
|
4 |
|
->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
197
|
|
|
->label($this->_language->get('language'), |
|
|
|
|
198
|
4 |
|
[ |
199
|
|
|
'for' => 'language' |
200
|
4 |
|
]) |
201
|
|
|
->select($helperOption->getLanguageArray(), |
202
|
|
|
[ |
203
|
4 |
|
$article->language |
204
|
|
|
], |
205
|
|
|
[ |
206
|
4 |
|
'id' => 'language', |
207
|
4 |
|
'name' => 'language' |
208
|
|
|
]) |
209
|
4 |
|
->append('</li><li>') |
210
|
|
|
->label($this->_language->get('template'), |
|
|
|
|
211
|
4 |
|
[ |
212
|
|
|
'for' => 'template' |
213
|
4 |
|
]) |
214
|
|
|
->select($helperOption->getTemplateArray(), |
215
|
|
|
[ |
216
|
4 |
|
$article->template |
217
|
|
|
], |
218
|
|
|
[ |
219
|
4 |
|
'id' => 'template', |
220
|
4 |
|
'name' => 'template' |
221
|
|
|
]) |
222
|
4 |
|
->append('</li><li>') |
223
|
|
|
->label($this->_language->get('article_sibling'), |
|
|
|
|
224
|
4 |
|
[ |
225
|
|
|
'for' => 'sibling' |
226
|
4 |
|
]) |
227
|
|
|
->select($helperOption->getSiblingForArticleArray($article->id), |
228
|
|
|
[ |
229
|
4 |
|
$article->sibling |
230
|
|
|
], |
231
|
|
|
[ |
232
|
4 |
|
'id' => 'sibling', |
233
|
|
|
'name' => 'sibling' |
234
|
|
|
]) |
235
|
4 |
|
->append('</li><li>') |
236
|
4 |
|
->label($this->_language->get('category'), |
|
|
|
|
237
|
|
|
[ |
238
|
4 |
|
'for' => 'category' |
239
|
|
|
]) |
240
|
4 |
|
->select($helperOption->getCategoryArray(), |
241
|
|
|
[ |
242
|
4 |
|
$article->category |
243
|
|
|
], |
244
|
|
|
[ |
245
|
4 |
|
'id' => 'category', |
246
|
|
|
'name' => 'category' |
247
|
|
|
]) |
248
|
4 |
|
->append('</li></ul>') |
249
|
|
|
|
250
|
|
|
/* customize */ |
251
|
|
|
|
252
|
4 |
|
->radio( |
253
|
|
|
[ |
254
|
4 |
|
'id' => self::class . '\Customize', |
255
|
|
|
'class' => 'rs-admin-fn-status-tab', |
256
|
|
|
'name' => self::class . '\Tab' |
257
|
|
|
]) |
258
|
4 |
|
->label($this->_language->get('customize'), |
|
|
|
|
259
|
|
|
[ |
260
|
4 |
|
'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
261
|
|
|
'for' => self::class . '\Customize' |
262
|
|
|
]) |
263
|
4 |
|
->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
264
|
4 |
|
->label($this->_language->get('headline'), |
|
|
|
|
265
|
|
|
[ |
266
|
4 |
|
'for' => 'headline' |
267
|
|
|
]) |
268
|
4 |
|
->select($helperOption->getToggleArray(), |
269
|
|
|
[ |
270
|
4 |
|
$article->id ? $article->headline : 1 |
271
|
|
|
], |
272
|
|
|
[ |
273
|
4 |
|
'id' => 'headline', |
274
|
|
|
'name' => 'headline' |
275
|
|
|
]) |
276
|
4 |
|
->append('</li><li>') |
277
|
4 |
|
->label($this->_language->get('byline'), |
|
|
|
|
278
|
|
|
[ |
279
|
4 |
|
'for' => 'byline' |
280
|
|
|
]) |
281
|
4 |
|
->select($helperOption->getToggleArray(), |
282
|
|
|
[ |
283
|
4 |
|
$article->id ? $article->byline : 1 |
284
|
|
|
], |
285
|
|
|
[ |
286
|
4 |
|
'id' => 'byline', |
287
|
|
|
'name' => 'byline' |
288
|
|
|
]) |
289
|
4 |
|
->append('</li><li>') |
290
|
4 |
|
->label($this->_language->get('comments'), |
|
|
|
|
291
|
|
|
[ |
292
|
4 |
|
'for' => 'comments' |
293
|
|
|
]) |
294
|
4 |
|
->select($helperOption->getToggleArray(), |
295
|
|
|
[ |
296
|
4 |
|
$article->comments |
297
|
|
|
], |
298
|
|
|
[ |
299
|
4 |
|
'id' => 'comments', |
300
|
|
|
'name' => 'comments' |
301
|
|
|
]) |
302
|
4 |
|
->append('</li><li>') |
303
|
4 |
|
->label($this->_language->get('status'), |
|
|
|
|
304
|
|
|
[ |
305
|
4 |
|
'for' => 'status' |
306
|
|
|
]) |
307
|
4 |
|
->select($helperOption->getVisibleArray(), |
308
|
|
|
[ |
309
|
4 |
|
$article->id ? $article->status : 1 |
310
|
|
|
], |
311
|
|
|
[ |
312
|
4 |
|
'id' => 'status', |
313
|
|
|
'name' => 'status' |
314
|
|
|
]) |
315
|
4 |
|
->append('</li><li>') |
316
|
4 |
|
->label($this->_language->get('rank'), |
|
|
|
|
317
|
|
|
[ |
318
|
4 |
|
'for' => 'rank' |
319
|
|
|
]) |
320
|
4 |
|
->number( |
321
|
|
|
[ |
322
|
4 |
|
'id' => 'rank', |
323
|
4 |
|
'name' => 'rank', |
324
|
4 |
|
'value' => $article->id ? $article->rank : $articleModel->query()->max('rank') + 1 |
325
|
|
|
]) |
326
|
4 |
|
->append('</li>'); |
327
|
4 |
|
if ($this->_registry->get('groupsEdit')) |
328
|
|
|
{ |
329
|
|
|
$formElement |
330
|
1 |
|
->append('<li>') |
331
|
1 |
|
->label($this->_language->get('access'), |
|
|
|
|
332
|
|
|
[ |
333
|
1 |
|
'for' => 'access' |
334
|
|
|
]) |
335
|
1 |
|
->select($helperOption->getGroupArray(), |
336
|
1 |
|
(array)json_decode($article->access), |
337
|
|
|
[ |
338
|
1 |
|
'id' => 'access', |
339
|
1 |
|
'name' => 'access[]', |
340
|
1 |
|
'multiple' => 'multiple', |
341
|
1 |
|
'size' => count($helperOption->getGroupArray()) |
342
|
|
|
]) |
343
|
1 |
|
->append('</li>'); |
344
|
|
|
} |
345
|
|
|
$formElement |
346
|
4 |
|
->append('<li>') |
347
|
4 |
|
->label($this->_language->get('date'), |
|
|
|
|
348
|
|
|
[ |
349
|
4 |
|
'for' => 'date' |
350
|
|
|
]) |
351
|
4 |
|
->datetime( |
352
|
|
|
[ |
353
|
4 |
|
'id' => 'date', |
354
|
4 |
|
'name' => 'date', |
355
|
4 |
|
'value' => $dater->formatField() |
356
|
|
|
]) |
357
|
4 |
|
->append('</li></ul>') |
358
|
4 |
|
->hidden( |
359
|
|
|
[ |
360
|
4 |
|
'name' => 'id', |
361
|
4 |
|
'value' => $article->id |
362
|
|
|
]) |
363
|
4 |
|
->token() |
364
|
4 |
|
->append('<div class="rs-admin-wrapper-button">') |
365
|
4 |
|
->cancel(); |
366
|
4 |
|
if ($article->id) |
367
|
|
|
{ |
368
|
2 |
|
if ($this->_registry->get('articlesDelete')) |
369
|
|
|
{ |
370
|
1 |
|
$formElement->delete(); |
371
|
|
|
} |
372
|
2 |
|
if ($this->_registry->get('articlesEdit')) |
373
|
|
|
{ |
374
|
2 |
|
$formElement->save(); |
375
|
|
|
} |
376
|
|
|
} |
377
|
2 |
|
else if ($this->_registry->get('articlesNew')) |
378
|
|
|
{ |
379
|
1 |
|
$formElement->create(); |
380
|
|
|
} |
381
|
4 |
|
$formElement->append('</div>'); |
382
|
|
|
|
383
|
|
|
/* collect output */ |
384
|
|
|
|
385
|
4 |
|
$output .= $titleElement . $formElement; |
386
|
4 |
|
$output .= Module\Hook::trigger('adminArticleFormEnd'); |
387
|
4 |
|
return $output; |
388
|
|
|
} |
389
|
|
|
} |
390
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.