These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 CommentForm extends ViewAbstract |
||
23 | { |
||
24 | /** |
||
25 | * render the view |
||
26 | * |
||
27 | * @since 3.0.0 |
||
28 | * |
||
29 | * @param int $commentId identifier of the comment |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | |||
34 | public function render(int $commentId = null) : string |
||
35 | { |
||
36 | $output = Module\Hook::trigger('adminCommentFormStart'); |
||
37 | $helperOption = new Helper\Option($this->_language); |
||
38 | $commentModel = new Admin\Model\Comment(); |
||
39 | $comment = $commentModel->getById($commentId); |
||
40 | $dater = new Dater(); |
||
41 | $dater->init($comment->date); |
||
42 | |||
43 | /* html element */ |
||
44 | |||
45 | $titleElement = new Html\Element(); |
||
46 | $titleElement |
||
47 | ->init('h2', |
||
48 | [ |
||
49 | 'class' => 'rs-admin-title-content', |
||
50 | ]) |
||
51 | ->text($comment->author ? : $this->_language->get('comment_new')); |
||
52 | $formElement = new Admin\Html\Form($this->_registry, $this->_language); |
||
53 | $formElement->init( |
||
54 | [ |
||
55 | 'form' => |
||
56 | [ |
||
57 | 'class' => 'rs-admin-js-validate 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 | [ |
||
72 | 'cancel' => |
||
73 | [ |
||
74 | 'href' => $this->_registry->get('commentsEdit') && $this->_registry->get('commentsDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/comments' : $this->_registry->get('parameterRoute') . 'admin' |
||
75 | ], |
||
76 | 'delete' => |
||
77 | [ |
||
78 | 'href' => $comment->id ? $this->_registry->get('parameterRoute') . 'admin/delete/comments/' . $comment->id . '/' . $this->_registry->get('token') : null |
||
79 | ] |
||
80 | ] |
||
81 | ]); |
||
82 | |||
83 | /* create the form */ |
||
84 | |||
85 | $formElement |
||
86 | |||
87 | /* comment */ |
||
88 | |||
89 | ->radio( |
||
90 | [ |
||
91 | 'id' => self::class . '\Comment', |
||
92 | 'class' => 'rs-admin-fn-status-tab', |
||
93 | 'name' => self::class . '\Tab', |
||
94 | 'checked' => 'checked' |
||
95 | ]) |
||
96 | ->label($this->_language->get('comment'), |
||
97 | [ |
||
98 | 'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
||
99 | 'for' => self::class . '\Comment' |
||
100 | ]) |
||
101 | ->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
||
102 | ->label($this->_language->get('url'), |
||
103 | [ |
||
104 | 'for' => 'url' |
||
105 | ]) |
||
106 | ->url( |
||
107 | [ |
||
108 | 'id' => 'url', |
||
109 | 'name' => 'url', |
||
110 | 'value' => $comment->url |
||
111 | ]) |
||
112 | ->append('</li><li>') |
||
113 | ->label('* ' . $this->_language->get('text'), |
||
114 | [ |
||
115 | 'for' => 'text' |
||
116 | ]) |
||
117 | ->textarea( |
||
118 | [ |
||
119 | 'class' => 'rs-admin-js-editor rs-admin-js-resize rs-admin-field-textarea', |
||
120 | 'id' => 'text', |
||
121 | 'name' => 'text', |
||
122 | 'required' => 'required', |
||
123 | 'value' => htmlspecialchars($comment->text, ENT_QUOTES) |
||
124 | ]) |
||
125 | ->append('</li></ul>') |
||
126 | |||
127 | /* general */ |
||
128 | |||
129 | ->radio( |
||
130 | [ |
||
131 | 'id' => self::class . '\General', |
||
132 | 'class' => 'rs-admin-fn-status-tab', |
||
133 | 'name' => self::class . '\Tab' |
||
134 | ]) |
||
135 | ->label($this->_language->get('general'), |
||
136 | [ |
||
137 | 'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
||
138 | 'for' => self::class . '\General' |
||
139 | ]) |
||
140 | ->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
||
141 | ->label($this->_language->get('language'), |
||
142 | [ |
||
143 | 'for' => 'language' |
||
144 | ]) |
||
145 | ->select($helperOption->getLanguageArray(), |
||
146 | [ |
||
147 | 'value' => $comment->language |
||
148 | ], |
||
149 | [ |
||
150 | 'id' => 'language', |
||
151 | 'name' => 'language' |
||
152 | ]) |
||
153 | ->append('</li><li>') |
||
154 | ->label($this->_language->get('article'), |
||
155 | [ |
||
156 | 'for' => 'article' |
||
157 | ]) |
||
158 | ->select($helperOption->getArticleForCommentArray(), |
||
159 | [ |
||
160 | $comment->article |
||
161 | ], |
||
162 | [ |
||
163 | 'id' => 'article', |
||
164 | 'name' => 'article' |
||
165 | ]) |
||
166 | ->append('</li></ul>') |
||
167 | |||
168 | /* customize */ |
||
169 | |||
170 | ->radio( |
||
171 | [ |
||
172 | 'id' => self::class . '\Customize', |
||
173 | 'class' => 'rs-admin-fn-status-tab', |
||
174 | 'name' => self::class . '\Tab' |
||
175 | ]) |
||
176 | ->label($this->_language->get('customize'), |
||
177 | [ |
||
178 | 'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
||
179 | 'for' => self::class . '\Customize' |
||
180 | ]) |
||
181 | ->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
||
182 | ->label($this->_language->get('status'), |
||
0 ignored issues
–
show
|
|||
183 | [ |
||
184 | 'for' => 'status' |
||
185 | ]) |
||
186 | ->select($helperOption->getVisibleArray(), |
||
187 | [ |
||
188 | $comment->id ? $comment->status : 1 |
||
189 | ], |
||
190 | [ |
||
191 | 'id' => 'status', |
||
192 | 'name' => 'status' |
||
193 | ]) |
||
194 | ->append('</li><li>') |
||
195 | ->label($this->_language->get('rank'), |
||
196 | [ |
||
197 | 'for' => 'rank' |
||
198 | ]) |
||
199 | ->number( |
||
200 | [ |
||
201 | 'id' => 'rank', |
||
202 | 'name' => 'rank', |
||
203 | 'value' => $comment->id ? $comment->rank : $commentModel->query()->max('rank') + 1 |
||
204 | ]) |
||
205 | ->append('</li>'); |
||
206 | if ($this->_registry->get('groupsEdit')) |
||
207 | { |
||
208 | $formElement |
||
209 | ->append('<li>') |
||
210 | ->label($this->_language->get('access'), |
||
211 | [ |
||
212 | 'for' => 'access' |
||
213 | ]) |
||
214 | ->select($helperOption->getGroupArray(), |
||
215 | (array)json_decode($comment->access), |
||
216 | [ |
||
217 | 'id' => 'access', |
||
218 | 'name' => 'access[]', |
||
219 | 'multiple' => 'multiple', |
||
220 | 'size' => count($helperOption->getGroupArray()) |
||
221 | ]) |
||
222 | ->append('</li>'); |
||
223 | } |
||
224 | $formElement |
||
225 | ->append('<li>') |
||
226 | ->label($this->_language->get('date'), |
||
227 | [ |
||
228 | 'for' => 'date' |
||
229 | ]) |
||
230 | ->datetime( |
||
231 | [ |
||
232 | 'id' => 'date', |
||
233 | 'name' => 'date', |
||
234 | 'value' => $dater->formatField() |
||
235 | ]) |
||
236 | ->append('</li></ul>') |
||
237 | ->hidden( |
||
238 | [ |
||
239 | 'name' => 'id', |
||
240 | 'value' => $comment->id |
||
241 | ]) |
||
242 | ->token() |
||
243 | ->append('<div class="rs-admin-wrapper-button">') |
||
244 | ->cancel(); |
||
245 | if ($comment->id) |
||
246 | { |
||
247 | if ($this->_registry->get('commentsDelete')) |
||
248 | { |
||
249 | $formElement->delete(); |
||
250 | } |
||
251 | if ($this->_registry->get('commentsEdit')) |
||
252 | { |
||
253 | $formElement->save(); |
||
254 | } |
||
255 | } |
||
256 | else if ($this->_registry->get('commentsNew')) |
||
257 | { |
||
258 | $formElement->create(); |
||
259 | } |
||
260 | $formElement->append('</div>'); |
||
261 | |||
262 | /* collect output */ |
||
263 | |||
264 | $output .= $titleElement . $formElement; |
||
265 | $output .= Module\Hook::trigger('adminCommentFormEnd'); |
||
266 | return $output; |
||
267 | } |
||
268 | } |
||
269 |
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.