Merge branch 'master' of feistymeow.org:feisty_meow
[feisty_meow.git] / production / example_apps / shared_calendar / src / Controller / PagesController.php
1 <?php
2 /**
3  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4  * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
11  * @link      http://cakephp.org CakePHP(tm) Project
12  * @since     0.2.9
13  * @license   http://www.opensource.org/licenses/mit-license.php MIT License
14  */
15 namespace App\Controller;
16
17 use Cake\Core\Configure;
18 use Cake\Network\Exception\ForbiddenException;
19 use Cake\Network\Exception\NotFoundException;
20 use Cake\View\Exception\MissingTemplateException;
21
22 /**
23  * Static content controller
24  *
25  * This controller will render views from Template/Pages/
26  *
27  * @link http://book.cakephp.org/3.0/en/controllers/pages-controller.html
28  */
29 class PagesController extends AppController
30 {
31
32     /**
33      * Displays a view
34      *
35      * @param string ...$path Path segments.
36      * @return void|\Cake\Network\Response
37      * @throws \Cake\Network\Exception\ForbiddenException When a directory traversal attempt.
38      * @throws \Cake\Network\Exception\NotFoundException When the view file could not
39      *   be found or \Cake\View\Exception\MissingTemplateException in debug mode.
40      */
41     public function display(...$path)
42     {
43         $count = count($path);
44         if (!$count) {
45             return $this->redirect('/');
46         }
47         if (in_array('..', $path, true) || in_array('.', $path, true)) {
48             throw new ForbiddenException();
49         }
50         $page = $subpage = null;
51
52         if (!empty($path[0])) {
53             $page = $path[0];
54         }
55         if (!empty($path[1])) {
56             $subpage = $path[1];
57         }
58         $this->set(compact('page', 'subpage'));
59
60         try {
61             $this->render(implode('/', $path));
62         } catch (MissingTemplateException $e) {
63             if (Configure::read('debug')) {
64                 throw $e;
65             }
66             throw new NotFoundException();
67         }
68     }
69 }