]> git.agnieray.net Git - galette.git/blob - galette/includes/routes/plugins.routes.php
Scrutinizer Auto-Fixes (#59)
[galette.git] / galette / includes / routes / plugins.routes.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Plugins routes
7 *
8 * PHP version 5
9 *
10 * Copyright © 2015 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Routes
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2015 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since 0.9dev 2015-10-28
36 */
37
38 $app->group(
39 '/plugins',
40 function() use ($authenticate, $app) {
41 $container = $this->getContainer();
42 $modules = $container->plugins->getModules();
43
44 //Global route to access plugin resources (CSS, JS, images, ...)
45 $this->get(
46 '/{plugin}/res/{path:.*}',
47 function($request, $response, $args) {
48 $plugin = $args['plugin'];
49 $path = $args['path'];
50 $ext = pathinfo($args['path'])['extension'];
51 $auth_ext = [
52 'js' => 'text/javascript',
53 'css' => 'text/css',
54 'png' => 'image/png',
55 'jpg' => 'image/jpg',
56 'jpeg' => 'image/jpg',
57 'gif' => 'image/gif'
58 ];
59 if (strpos($path, '../') === false && isset($auth_ext[$ext])) {
60 $file = $this->plugins->getFile(
61 $plugin,
62 $path
63 );
64
65 $response = $response->withHeader('Content-type', $auth_ext[$ext]);
66
67 $body = $response->getBody();
68 $body->write(file_get_contents($file));
69 return $response;
70 } else {
71 $this->halt(
72 500,
73 _T("Invalid extension!")
74 );
75 }
76 }
77 )->setName('plugin_res');
78
79 //Declare configured routes for each plugin
80 foreach ($modules as $module_id => $module) {
81 $container['Plugin ' . $module['name']] = function($c) use ($module_id) {
82 return $module_id;
83 };
84
85 $this->group(
86 '/' . $module['route'],
87 function() use ($module, $module_id, $authenticate) {
88 //Plugin home: give information
89 $this->get(
90 '',
91 function($request, $response) use ($module) {
92 $params = [
93 'page_title' => $module['name'],
94 'name' => $module['name'],
95 'version' => $module['version'],
96 'date' => $module['date'],
97 'author' => $module['author']
98 ];
99 if ($this->login->isAdmin()) {
100 $params['module'] = $module;
101 }
102 // display page
103 $this->view->render(
104 $response,
105 'plugin_info.tpl',
106 $params
107 );
108 return $response;
109 }
110 )->setName($module['route'] . 'Info')->add($authenticate);
111
112 $f = $module['root'] . '/_routes.php';
113 include_once $f;
114 }
115 );
116 }
117 }
118 );