Web Interfaces of PROSUME

PagesController.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 0.2.9
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace App\Controller;
  16. use Cake\Core\Configure;
  17. use Cake\Http\Exception\ForbiddenException;
  18. use Cake\Http\Exception\NotFoundException;
  19. use Cake\View\Exception\MissingTemplateException;
  20. /**
  21. * Static content controller
  22. *
  23. * This controller will render views from Template/Pages/
  24. *
  25. * @link https://book.cakephp.org/3.0/en/controllers/pages-controller.html
  26. */
  27. class PagesController extends AppController
  28. {
  29. /**
  30. * Displays a view
  31. *
  32. * @param array ...$path Path segments.
  33. * @return \Cake\Http\Response|null
  34. * @throws \Cake\Http\Exception\ForbiddenException When a directory traversal attempt.
  35. * @throws \Cake\Http\Exception\NotFoundException When the view file could not
  36. * be found or \Cake\View\Exception\MissingTemplateException in debug mode.
  37. */
  38. public function display(...$path)
  39. {
  40. $count = count($path);
  41. if (!$count) {
  42. return $this->redirect('/');
  43. }
  44. if (in_array('..', $path, true) || in_array('.', $path, true)) {
  45. throw new ForbiddenException();
  46. }
  47. $page = $subpage = null;
  48. if (!empty($path[0])) {
  49. $page = $path[0];
  50. }
  51. if (!empty($path[1])) {
  52. $subpage = $path[1];
  53. }
  54. $this->set(compact('page', 'subpage'));
  55. try {
  56. $this->render(implode('/', $path));
  57. } catch (MissingTemplateException $exception) {
  58. if (Configure::read('debug')) {
  59. throw $exception;
  60. }
  61. throw new NotFoundException();
  62. }
  63. }
  64. }