This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Alpha\Controller; |
||
4 | |||
5 | use Alpha\Util\Logging\Logger; |
||
6 | use Alpha\Util\Logging\KPI; |
||
7 | use Alpha\Util\Config\ConfigProvider; |
||
8 | use Alpha\Util\Security\SecurityUtils; |
||
9 | use Alpha\Util\Extension\TCPDFFacade; |
||
10 | use Alpha\Util\Http\Request; |
||
11 | use Alpha\Util\Http\Response; |
||
12 | use Alpha\Util\Service\ServiceFactory; |
||
13 | use Alpha\Util\File\FileUtils; |
||
14 | use Alpha\Model\Article; |
||
15 | use Alpha\Model\ArticleComment; |
||
16 | use Alpha\Model\Type\Relation; |
||
17 | use Alpha\View\View; |
||
18 | use Alpha\View\ViewState; |
||
19 | use Alpha\View\Widget\Button; |
||
20 | use Alpha\Exception\SecurityException; |
||
21 | use Alpha\Exception\AlphaException; |
||
22 | use Alpha\Exception\RecordNotFoundException; |
||
23 | use Alpha\Exception\IllegalArguementException; |
||
24 | use Alpha\Exception\ResourceNotFoundException; |
||
25 | use Alpha\Exception\FileNotFoundException; |
||
26 | use Alpha\Model\ActiveRecord; |
||
27 | use Alpha\Controller\Front\FrontController; |
||
28 | |||
29 | /** |
||
30 | * Controller used handle Article objects. |
||
31 | * |
||
32 | * @since 1.0 |
||
33 | * |
||
34 | * @author John Collins <[email protected]> |
||
35 | * @license http://www.opensource.org/licenses/bsd-license.php The BSD License |
||
36 | * @copyright Copyright (c) 2018, John Collins (founder of Alpha Framework). |
||
37 | * All rights reserved. |
||
38 | * |
||
39 | * <pre> |
||
40 | * Redistribution and use in source and binary forms, with or |
||
41 | * without modification, are permitted provided that the |
||
42 | * following conditions are met: |
||
43 | * |
||
44 | * * Redistributions of source code must retain the above |
||
45 | * copyright notice, this list of conditions and the |
||
46 | * following disclaimer. |
||
47 | * * Redistributions in binary form must reproduce the above |
||
48 | * copyright notice, this list of conditions and the |
||
49 | * following disclaimer in the documentation and/or other |
||
50 | * materials provided with the distribution. |
||
51 | * * Neither the name of the Alpha Framework nor the names |
||
52 | * of its contributors may be used to endorse or promote |
||
53 | * products derived from this software without specific |
||
54 | * prior written permission. |
||
55 | * |
||
56 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
||
57 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
||
58 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
||
59 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
60 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
||
61 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||
62 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
63 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
64 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||
65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
66 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
||
67 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
68 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
69 | * </pre> |
||
70 | */ |
||
71 | class ArticleController extends ActiveRecordController implements ControllerInterface |
||
72 | { |
||
73 | /** |
||
74 | * The Article record object that this controller is currently working with. |
||
75 | * |
||
76 | * @var \Alpha\Model\Article |
||
77 | * |
||
78 | * @since 3.0 |
||
79 | */ |
||
80 | protected $record = null; |
||
81 | |||
82 | /** |
||
83 | * Trace logger. |
||
84 | * |
||
85 | * @var \Alpha\Util\Logging\Logger |
||
86 | * |
||
87 | * @since 1.0 |
||
88 | */ |
||
89 | private static $logger = null; |
||
0 ignored issues
–
show
Comprehensibility
introduced
by
![]() |
|||
90 | |||
91 | /** |
||
92 | * constructor to set up the object. |
||
93 | * |
||
94 | * @since 1.0 |
||
95 | */ |
||
96 | public function __construct() |
||
97 | { |
||
98 | self::$logger = new Logger('ArticleController'); |
||
99 | self::$logger->debug('>>__construct()'); |
||
100 | |||
101 | // ensure that the super class constructor is called, indicating the rights group |
||
102 | parent::__construct('Public'); |
||
103 | |||
104 | self::$logger->debug('<<__construct'); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Handle GET requests. |
||
109 | * |
||
110 | * @param \Alpha\Util\Http\Request |
||
111 | * |
||
112 | * @return \Alpha\Util\Http\Response |
||
113 | * |
||
114 | * @throws \Alpha\Exception\ResourceNotFoundException |
||
115 | * |
||
116 | * @since 1.0 |
||
117 | */ |
||
118 | public function doGET($request) |
||
119 | { |
||
120 | self::$logger->debug('>>doGET($request=['.var_export($request, true).'])'); |
||
121 | |||
122 | $config = ConfigProvider::getInstance(); |
||
123 | |||
124 | $params = $request->getParams(); |
||
125 | |||
126 | $body = ''; |
||
127 | |||
128 | // handle requests for PDFs |
||
129 | if (isset($params['title']) && (isset($params['pdf']) || $request->getHeader('Accept') == 'application/pdf')) { |
||
130 | try { |
||
131 | $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); |
||
132 | |||
133 | if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { |
||
134 | $record = new $params['ActiveRecordType']; |
||
135 | } else { |
||
136 | $record = new Article(); |
||
137 | } |
||
138 | $record->loadByAttribute('title', $title); |
||
139 | $this->record = $record; |
||
140 | |||
141 | ActiveRecord::disconnect(); |
||
142 | |||
143 | $pdf = new TCPDFFacade($record); |
||
144 | $pdfData = $pdf->getPDFData(); |
||
145 | $pdfDownloadName = str_replace(' ', '-', $record->get('title').'.pdf'); |
||
146 | |||
147 | $headers = array( |
||
148 | 'Pragma' => 'public', |
||
149 | 'Expires' => 0, |
||
150 | 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', |
||
151 | 'Content-Transfer-Encoding' => 'binary', |
||
152 | 'Content-Type' => 'application/pdf', |
||
153 | 'Content-Length' => strlen($pdfData), |
||
154 | 'Content-Disposition' => 'attachment; filename="'.$pdfDownloadName.'";', |
||
155 | ); |
||
156 | |||
157 | return new Response(200, $pdfData, $headers); |
||
158 | } catch (IllegalArguementException $e) { |
||
159 | self::$logger->error($e->getMessage()); |
||
160 | throw new ResourceNotFoundException($e->getMessage()); |
||
161 | } catch (RecordNotFoundException $e) { |
||
162 | self::$logger->error($e->getMessage()); |
||
163 | throw new ResourceNotFoundException($e->getMessage()); |
||
164 | } |
||
165 | } |
||
166 | |||
167 | // view edit article requests |
||
168 | if ((isset($params['view']) && $params['view'] == 'edit') && (isset($params['title']) || isset($params['ActiveRecordID']))) { |
||
169 | if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { |
||
170 | $record = new $params['ActiveRecordType']; |
||
171 | } else { |
||
172 | $record = new Article(); |
||
173 | } |
||
174 | |||
175 | try { |
||
176 | if (isset($params['title'])) { |
||
177 | $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); |
||
178 | $record->loadByAttribute('title', $title); |
||
179 | } else { |
||
180 | $record->load($params['ActiveRecordID']); |
||
181 | } |
||
182 | } catch (RecordNotFoundException $e) { |
||
183 | self::$logger->warn($e->getMessage()); |
||
184 | $body .= View::renderErrorPage(404, 'Failed to find the requested article!'); |
||
185 | |||
186 | return new Response(404, $body, array('Content-Type' => 'text/html')); |
||
187 | } |
||
188 | |||
189 | ActiveRecord::disconnect(); |
||
190 | |||
191 | $this->record = $record; |
||
192 | $view = View::getInstance($record); |
||
193 | |||
194 | // set up the title and meta details |
||
195 | $this->setTitle($record->get('title').' (editing)'); |
||
196 | $this->setDescription('Page to edit '.$record->get('title').'.'); |
||
197 | $this->setKeywords('edit,article'); |
||
198 | |||
199 | $body .= View::displayPageHead($this); |
||
200 | |||
201 | $message = $this->getStatusMessage(); |
||
202 | if (!empty($message)) { |
||
203 | $body .= $message; |
||
204 | } |
||
205 | |||
206 | $body .= $view->editView(array('URI' => $request->getURI())); |
||
207 | $body .= View::renderDeleteForm($request->getURI()); |
||
208 | |||
209 | $body .= View::displayPageFoot($this); |
||
210 | self::$logger->debug('<<doGET'); |
||
211 | |||
212 | return new Response(200, $body, array('Content-Type' => 'text/html')); |
||
213 | } |
||
214 | |||
215 | // handle requests for viewing articles |
||
216 | if (isset($params['title']) || isset($params['ActiveRecordID'])) { |
||
217 | $KDP = new KPI('viewarticle'); |
||
218 | if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { |
||
219 | $record = new $params['ActiveRecordType']; |
||
220 | } else { |
||
221 | $record = new Article(); |
||
222 | } |
||
223 | |||
224 | try { |
||
225 | if (isset($params['title'])) { |
||
226 | $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); |
||
227 | |||
228 | $record->loadByAttribute('title', $title, false, array('ID', 'version_num', 'created_ts', 'updated_ts', 'title', 'author', 'published', 'content', 'headerContent')); |
||
229 | } else { |
||
230 | $record->load($params['ActiveRecordID']); |
||
231 | } |
||
232 | |||
233 | if (!$record->get('published')) { |
||
234 | throw new RecordNotFoundException('Attempted to load an article which is not published yet'); |
||
235 | } |
||
236 | |||
237 | $record->set('tags', $record->getID()); |
||
238 | } catch (IllegalArguementException $e) { |
||
239 | self::$logger->warn($e->getMessage()); |
||
240 | throw new ResourceNotFoundException('The file that you have requested cannot be found!'); |
||
241 | } catch (RecordNotFoundException $e) { |
||
242 | self::$logger->warn($e->getMessage()); |
||
243 | throw new ResourceNotFoundException('The article that you have requested cannot be found!'); |
||
244 | } |
||
245 | |||
246 | $this->record = $record; |
||
247 | $this->setTitle($record->get('title')); |
||
248 | $this->setDescription($record->get('description')); |
||
249 | |||
250 | $recordView = View::getInstance($record); |
||
251 | |||
252 | $body .= View::displayPageHead($this); |
||
253 | |||
254 | $message = $this->getStatusMessage(); |
||
255 | if (!empty($message)) { |
||
256 | $body .= $message; |
||
257 | } |
||
258 | |||
259 | $body .= $recordView->markdownView(); |
||
260 | |||
261 | $body .= View::displayPageFoot($this); |
||
262 | |||
263 | $KDP->log(); |
||
264 | |||
265 | return new Response(200, $body, array('Content-Type' => 'text/html')); |
||
266 | } |
||
267 | |||
268 | // handle requests to view an article stored in a file |
||
269 | if (isset($params['file'])) { |
||
270 | try { |
||
271 | $record = new Article(); |
||
272 | |||
273 | // just checking to see if the file path is absolute or not |
||
274 | if (mb_substr($params['file'], 0, 1) == '/') { |
||
275 | $record->loadContentFromFile($params['file']); |
||
276 | } else { |
||
277 | $record->loadContentFromFile($config->get('app.root').'docs/'.$params['file']); |
||
278 | } |
||
279 | } catch (IllegalArguementException $e) { |
||
280 | self::$logger->error($e->getMessage()); |
||
281 | throw new ResourceNotFoundException($e->getMessage()); |
||
282 | } catch (FileNotFoundException $e) { |
||
283 | self::$logger->warn($e->getMessage().' File path is ['.$params['file'].']'); |
||
284 | throw new ResourceNotFoundException('Failed to load the requested article from the file system!'); |
||
285 | } |
||
286 | |||
287 | $this->record = $record; |
||
288 | $this->setTitle($record->get('title')); |
||
289 | |||
290 | $recordView = View::getInstance($record); |
||
291 | |||
292 | $body .= View::displayPageHead($this, false); |
||
0 ignored issues
–
show
The call to
View::displayPageHead() has too many arguments starting with false .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
293 | |||
294 | $body .= $recordView->markdownView(); |
||
295 | |||
296 | $body .= View::displayPageFoot($this); |
||
297 | |||
298 | return new Response(200, $body, array('Content-Type' => 'text/html')); |
||
299 | } |
||
300 | |||
301 | // handle requests to view a list of articles |
||
302 | if (isset($params['start'])) { |
||
303 | return parent::doGET($request); |
||
304 | } |
||
305 | |||
306 | // create a new article requests |
||
307 | $record = new Article(); |
||
308 | $view = View::getInstance($record); |
||
309 | |||
310 | // set up the title and meta details |
||
311 | $this->setTitle('Creating article'); |
||
312 | $this->setDescription('Page to create a new article.'); |
||
313 | $this->setKeywords('create,article'); |
||
314 | |||
315 | $body .= View::displayPageHead($this); |
||
316 | |||
317 | $message = $this->getStatusMessage(); |
||
318 | if (!empty($message)) { |
||
319 | $body .= $message; |
||
320 | } |
||
321 | |||
322 | $fields = array('formAction' => $this->request->getURI()); |
||
323 | $body .= $view->createView($fields); |
||
324 | |||
325 | $body .= View::displayPageFoot($this); |
||
326 | self::$logger->debug('<<doGET'); |
||
327 | |||
328 | return new Response(200, $body, array('Content-Type' => 'text/html')); |
||
329 | } |
||
330 | |||
331 | /** |
||
332 | * Method to handle PUT requests. |
||
333 | * |
||
334 | * @param \Alpha\Util\Http\Request |
||
335 | * |
||
336 | * @return \Alpha\Util\Http\Response |
||
337 | * |
||
338 | * @since 1.0 |
||
339 | */ |
||
340 | public function doPUT($request) |
||
341 | { |
||
342 | self::$logger->debug('>>doPUT($request=['.var_export($request, true).'])'); |
||
343 | |||
344 | $config = ConfigProvider::getInstance(); |
||
345 | |||
346 | $params = $request->getParams(); |
||
347 | |||
348 | if (!isset($params['ActiveRecordID']) && isset($params['title'])) { |
||
349 | $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); |
||
350 | $record = new Article(); |
||
351 | $record->loadByAttribute('title', $title); |
||
352 | $params['ActiveRecordID'] = $record->getID(); |
||
353 | |||
354 | $request->addParams(array('ActiveRecordID' => $params['ActiveRecordID'])); |
||
355 | } |
||
356 | |||
357 | if (!isset($params['ActiveRecordType'])) { |
||
358 | $request->addParams(array('ActiveRecordType' => 'Alpha\Model\Article')); |
||
359 | } |
||
360 | |||
361 | $response = parent::doPUT($request); |
||
362 | |||
363 | if ($this->getNextJob() != '') { |
||
364 | $response->redirect($this->getNextJob()); |
||
365 | } else { |
||
366 | if ($this->request->isSecureURI()) { |
||
367 | $response->redirect(FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=Alpha\Model\Article&ActiveRecordID='.$this->record->getID().'&view=edit')); |
||
368 | } else { |
||
369 | $title = str_replace(' ', $config->get('cms.url.title.separator'), $this->record->get('title')); |
||
370 | $response->redirect($config->get('app.url').'/a/'.$title.'/edit'); |
||
371 | } |
||
372 | } |
||
373 | |||
374 | self::$logger->debug('<<doPUT'); |
||
375 | |||
376 | return $response; |
||
377 | } |
||
378 | |||
379 | /** |
||
380 | * Method to handle DELETE requests. |
||
381 | * |
||
382 | * @param \Alpha\Util\Http\Request |
||
383 | * |
||
384 | * @return \Alpha\Util\Http\Response |
||
385 | * |
||
386 | * @since 2.0 |
||
387 | */ |
||
388 | public function doDELETE($request) |
||
389 | { |
||
390 | self::$logger->debug('>>doDELETE($request=['.var_export($request, true).'])'); |
||
391 | |||
392 | $this->setUnitOfWork(array()); |
||
393 | |||
394 | self::$logger->debug('<<doDELETE'); |
||
395 | |||
396 | return parent::doDELETE($request); |
||
397 | } |
||
398 | |||
399 | /** |
||
400 | * Renders custom HTML header content. |
||
401 | * |
||
402 | * @return string |
||
403 | * |
||
404 | * @since 1.0 |
||
405 | */ |
||
406 | public function during_displayPageHead_callback() |
||
407 | { |
||
408 | $config = ConfigProvider::getInstance(); |
||
409 | |||
410 | $params = $this->request->getParams(); |
||
411 | |||
412 | $html = ''; |
||
413 | |||
414 | if ((isset($params['view']) && ($params['view'] == 'edit' || $params['view'] == 'create')) || (isset($params['ActiveRecordType']) && !isset($params['ActiveRecordID']))) { |
||
415 | $fieldid = ($config->get('security.encrypt.http.fieldnames') ? 'text_field_'.base64_encode(SecurityUtils::encrypt('content')).'_0' : 'text_field_content_0'); |
||
416 | |||
417 | $html .= ' |
||
418 | <script type="text/javascript"> |
||
419 | $(document).ready(function() { |
||
420 | $(\'[id="'.$fieldid.'"]\').pagedownBootstrap({ |
||
421 | \'sanatize\': false |
||
422 | }); |
||
423 | }); |
||
424 | </script>'; |
||
425 | } elseif (isset($params['view']) && $params['view'] == 'print') { |
||
426 | $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('app.url').'/css/print.css">'; |
||
427 | } |
||
428 | |||
429 | if ($this->record instanceof Article) { |
||
430 | $headerContent = $this->record->get('headerContent'); |
||
431 | if ($headerContent != '') { |
||
432 | $html .= $headerContent; |
||
433 | } |
||
434 | } |
||
435 | |||
436 | return $html; |
||
437 | } |
||
438 | |||
439 | /** |
||
440 | * Callback that inserts the CMS level header. |
||
441 | * |
||
442 | * @return string |
||
443 | * |
||
444 | * @since 1.0 |
||
445 | */ |
||
446 | public function insert_CMSDisplayStandardHeader_callback() |
||
447 | { |
||
448 | if ($this->request->getParam('token') != null) { |
||
449 | return ''; |
||
450 | } |
||
451 | |||
452 | if (!$this->record instanceof Article) { |
||
453 | return ''; |
||
454 | } |
||
455 | |||
456 | $config = ConfigProvider::getInstance(); |
||
457 | |||
458 | $html = ''; |
||
459 | |||
460 | if ($config->get('cms.display.standard.header')) { |
||
461 | $html .= '<p><a href="'.$config->get('app.url').'">'.$config->get('app.title').'</a> '; |
||
462 | $html .= 'Date Added: <em>'.$this->record->getCreateTS()->getDate().'</em> '; |
||
463 | $html .= 'Last Updated: <em>'.$this->record->getUpdateTS()->getDate().'</em> '; |
||
464 | $html .= 'Revision: <em>'.$this->record->getVersion().'</em></p>'; |
||
465 | } |
||
466 | |||
467 | $html .= $config->get('cms.header'); |
||
468 | |||
469 | return $html; |
||
470 | } |
||
471 | |||
472 | /** |
||
473 | * Callback used to render footer content, including comments, votes and print/PDF buttons when |
||
474 | * enabled to do so. |
||
475 | * |
||
476 | * @return string |
||
477 | * |
||
478 | * @since 1.0 |
||
479 | */ |
||
480 | public function before_displayPageFoot_callback() |
||
481 | { |
||
482 | $config = ConfigProvider::getInstance(); |
||
483 | $sessionProvider = $config->get('session.provider.name'); |
||
484 | $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
||
485 | |||
486 | $html = ''; |
||
487 | $params = $this->request->getParams(); |
||
488 | |||
489 | // this will ensure that direct requests to ActiveRecordController will be re-directed here. |
||
490 | if (isset($this->record) && !$this->record->isTransient()) { |
||
491 | $this->setName($config->get('app.url').$this->request->getURI()); |
||
492 | $this->setUnitOfWork(array($config->get('app.url').$this->request->getURI(), $config->get('app.url').$this->request->getURI())); |
||
493 | } else { |
||
494 | $this->setUnitOfWork(array()); |
||
495 | } |
||
496 | |||
497 | if ($this->record != null) { |
||
498 | if (isset($params['view']) && $params['view'] == 'detailed') { |
||
499 | if ($config->get('cms.display.comments')) { |
||
500 | $html .= $this->renderComments(); |
||
501 | } |
||
502 | |||
503 | if ($config->get('cms.display.tags')) { |
||
504 | $html .= $this->renderTags(); |
||
505 | } |
||
506 | |||
507 | if ($config->get('cms.display.votes')) { |
||
508 | $rating = $this->record->getArticleScore(); |
||
509 | $votes = $this->record->getArticleVotes(); |
||
510 | $html .= '<p>Average Article User Rating: <strong>'.$rating.'</strong> out of 10 (based on <strong>'.count($votes).'</strong> votes)</p>'; |
||
511 | } |
||
512 | |||
513 | if (!$this->record->checkUserVoted() && $config->get('cms.voting.allowed')) { |
||
514 | $html .= $this->renderVotes(); |
||
515 | } |
||
516 | |||
517 | ActiveRecord::disconnect(); |
||
518 | |||
519 | if ($config->get('cms.allow.print.versions')) { |
||
520 | $html .= ' '; |
||
521 | $temp = new Button("window.open('".$this->record->get('printURL')."')", 'Open Printer Version', 'printBut'); |
||
522 | $html .= $temp->render(); |
||
523 | } |
||
524 | |||
525 | $html .= ' '; |
||
526 | if ($config->get('cms.allow.pdf.versions')) { |
||
527 | $html .= ' '; |
||
528 | $temp = new Button("document.location = '".FrontController::generateSecureURL("act=Alpha\Controller\ArticleController&mode=pdf&title=".$this->record->get('title'))."';", 'Open PDF Version', 'pdfBut'); |
||
529 | $html .= $temp->render(); |
||
530 | } |
||
531 | |||
532 | // render edit button for admins only |
||
533 | if ($session->get('currentUser') instanceof \Alpha\Model\Person && $session->get('currentUser')->inGroup('Admin')) { |
||
534 | $html .= ' '; |
||
535 | $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ArticleController&mode=edit&ActiveRecordID='.$this->record->getID())."'", 'Edit', 'editBut'); |
||
536 | $html .= $button->render(); |
||
537 | } |
||
538 | } |
||
539 | |||
540 | if ($config->get('cms.display.standard.footer')) { |
||
541 | $html .= $this->renderStandardFooter(); |
||
542 | } |
||
543 | } |
||
544 | |||
545 | $html .= $config->get('cms.footer'); |
||
546 | |||
547 | return $html; |
||
548 | } |
||
549 | |||
550 | /** |
||
551 | * Method for displaying the user comments for the article. |
||
552 | * |
||
553 | * @return string |
||
554 | * |
||
555 | * @since 1.0 |
||
556 | */ |
||
557 | private function renderComments() |
||
558 | { |
||
559 | $config = ConfigProvider::getInstance(); |
||
560 | $sessionProvider = $config->get('session.provider.name'); |
||
561 | $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
||
562 | |||
563 | $html = ''; |
||
564 | |||
565 | $comments = $this->record->getArticleComments(); |
||
566 | $commentsCount = count($comments); |
||
567 | |||
568 | $URL = FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType=Alpha\Model\ArticleComment'); |
||
569 | |||
570 | $fields = array('formAction' => $URL); |
||
571 | |||
572 | if ($config->get('cms.display.comments') && $commentsCount > 0) { |
||
573 | $html .= '<h2>There are ['.$commentsCount.'] user comments for this article</h2>'; |
||
574 | |||
575 | for ($i = 0; $i < $commentsCount; ++$i) { |
||
576 | $view = View::getInstance($comments[$i]); |
||
577 | $html .= $view->markdownView($fields); |
||
578 | } |
||
579 | } |
||
580 | |||
581 | if ($session->get('currentUser') != null && $config->get('cms.comments.allowed')) { |
||
582 | $comment = new ArticleComment(); |
||
583 | $comment->set('articleID', $this->record->getID()); |
||
584 | |||
585 | $view = View::getInstance($comment); |
||
586 | $html .= $view->createView($fields); |
||
587 | } |
||
588 | |||
589 | return $html; |
||
590 | } |
||
591 | |||
592 | /** |
||
593 | * Method for displaying the tags for the article. |
||
594 | * |
||
595 | * @return string |
||
596 | * |
||
597 | * @since 3.0 |
||
598 | */ |
||
599 | private function renderTags() |
||
600 | { |
||
601 | $config = ConfigProvider::getInstance(); |
||
602 | $relation = $this->record->getPropObject('tags'); |
||
603 | |||
604 | $html = ''; |
||
605 | |||
606 | if ($relation instanceof Relation) { |
||
607 | $tags = $relation->getRelated(); |
||
608 | |||
609 | if (count($tags) > 0) { |
||
610 | $html .= '<p>Tags:'; |
||
611 | |||
612 | foreach ($tags as $tag) { |
||
613 | $html .= ' <a href="'.$config->get('app.url').'/search/'.$tag->get('content').'">'.$tag->get('content').'</a>'; |
||
614 | } |
||
615 | $html .= '</p>'; |
||
616 | } |
||
617 | } |
||
618 | |||
619 | return $html; |
||
620 | } |
||
621 | |||
622 | /** |
||
623 | * Method for displaying the votes for the article. |
||
624 | * |
||
625 | * @return string |
||
626 | * |
||
627 | * @since 3.0 |
||
628 | */ |
||
629 | private function renderVotes() |
||
630 | { |
||
631 | $config = ConfigProvider::getInstance(); |
||
632 | $sessionProvider = $config->get('session.provider.name'); |
||
633 | $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
||
634 | |||
635 | $URL = FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType=Alpha\Model\ArticleVote'); |
||
636 | $html = '<form action="'.$URL.'" method="post" accept-charset="UTF-8">'; |
||
637 | $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('score')) : 'score'); |
||
638 | $html .= '<p>Please rate this article from 1-10 (10 being the best):'. |
||
639 | '<select name="'.$fieldname.'">'. |
||
640 | '<option value="1">1'. |
||
641 | '<option value="2">2'. |
||
642 | '<option value="3">3'. |
||
643 | '<option value="4">4'. |
||
644 | '<option value="5">5'. |
||
645 | '<option value="6">6'. |
||
646 | '<option value="7">7'. |
||
647 | '<option value="8">8'. |
||
648 | '<option value="9">9'. |
||
649 | '<option value="10">10'. |
||
650 | '</select></p> '; |
||
651 | |||
652 | $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('articleID')) : 'articleID'); |
||
653 | $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->record->getID().'"/>'; |
||
654 | |||
655 | $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('personID')) : 'personID'); |
||
656 | $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$session->get('currentUser')->getID().'"/>'; |
||
657 | |||
658 | $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('statusMessage')) : 'statusMessage'); |
||
659 | $html .= '<input type="hidden" name="'.$fieldname.'" value="Thank you for rating this article!"/>'; |
||
660 | |||
661 | $temp = new Button('submit', 'Vote!', 'voteBut'); |
||
662 | $html .= $temp->render(); |
||
663 | |||
664 | $html .= View::renderSecurityFields(); |
||
665 | $html .= '<form>'; |
||
666 | |||
667 | return $html; |
||
668 | } |
||
669 | |||
670 | /** |
||
671 | * Method for displaying the standard CMS footer for the article. |
||
672 | * |
||
673 | * @return string |
||
674 | * |
||
675 | * @since 3.0 |
||
676 | */ |
||
677 | private function renderStandardFooter() |
||
678 | { |
||
679 | $html = '<p>Article URL: <a href="'.$this->record->get('URL').'">'.$this->record->get('URL').'</a><br>'; |
||
680 | $html .= 'Title: '.$this->record->get('title').'<br>'; |
||
681 | $html .= 'Author: '.$this->record->get('author').'</p>'; |
||
682 | |||
683 | return $html; |
||
684 | } |
||
685 | } |
||
686 |