4 * Copyright © 2003-2024 The Galette Team
6 * This file is part of Galette (https://galette.eu).
8 * Galette is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * Galette is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
22 use Slim\Psr7\Request
;
23 use Slim\Psr7\Response
;
27 function (\Slim\Routing\RouteCollectorProxy
$app) use ($authenticate): void
{
28 /** @var $container \DI\Container */
29 $container = $app->getContainer();
30 $modules = $container->get('plugins')->getModules();
32 //Global route to access plugin resources (CSS, JS, images, ...)
34 '/{plugin}/res/{path:.*}',
35 function (Request
$request, Response
$response, $plugin, $path) use ($container) {
36 $ext = pathinfo($path)['extension'];
38 'js' => 'text/javascript',
42 'jpeg' => 'image/jpg',
44 'svg' => 'image/svg+xml',
45 'map' => 'application/json',
46 'woff' => 'application/font-woff',
47 'woff2' => 'application/font-woff2'
49 if (strpos($path, '../') === false && isset($auth_ext[$ext])) {
50 $file = $container->get('plugins')->getFile(
55 $response = $response->withHeader('Content-type', $auth_ext[$ext]);
57 $body = $response->getBody();
58 $body->write(file_get_contents($file));
61 throw new \
RuntimeException(
63 'Invalid extension %1$s (%2$s)!',
71 )->setName('plugin_res');
73 //Declare configured routes for each plugin
74 foreach ($modules as $module_id => $module) {
75 $container->set('Plugin ' . $module['name'], ['module' => $module, 'module_id' => $module_id]);
78 '/' . $module['route'],
79 //$module_id may be used in included _routes.php from plugin.
80 function (\Slim\Routing\RouteCollectorProxy
$app) use ($module, $module_id, $authenticate, $container): void
{
81 //Plugin home: give information
84 function ($request, $response) use ($module, $container) {
86 'page_title' => $module['name'],
87 'name' => $module['name'],
88 'version' => $module['version'],
89 'date' => $module['date'],
90 'author' => $module['author']
92 if ($container->get('login')->isAdmin()) {
93 $params['module'] = $module;
96 $container->get(\Slim\Views\Twig
::class)->render(
98 'pages/plugin_info.html.twig',
103 )->setName($module['route'] . 'Info')->add($authenticate);
105 $f = $module['root'] . '/_routes.php';