3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Galette abstract controller
10 * Copyright © 2019-2022 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
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.
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.
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/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2019-2022 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 * @link http://galette.tuxfamily.org
34 * @since Available since 0.9.4dev - 2019-12-02
37 namespace Galette\Controllers
;
39 use Psr\Container\ContainerInterface
;
40 use Slim\Http\Request
;
41 use Slim\Http\Response
;
44 * Galette abstract controller
46 * @category Controllers
47 * @name AbstractController
49 * @author Johan Cwiklinski <johan@x-tnd.be>
50 * @copyright 2019-2022 The Galette Team
51 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
52 * @link http://galette.tuxfamily.org
53 * @since Available since 0.9.4dev - 2019-12-02
56 abstract class AbstractController
61 * @var \Galette\Core\Db
66 * @var \Galette\Core\Login
71 * @var \Galette\Core\Preferences
73 protected $preferences;
76 * @var \Slim\Views\Twig
81 * @var \Galette\Core\Logo
86 * @var \Galette\Core\PrintLogo
88 protected $print_logo;
91 * @var \Galette\Core\Plugins
101 * @var \Galette\Core\History
106 * @var \Galette\Core\I18n
111 * @var \Galette\Core\L10n
120 * @var \Slim\Flash\Messages
125 * @var \Galette\Entity\FieldsConfig
127 protected $fields_config;
130 * @var \Galette\Entity\ListsConfig
132 protected $lists_config;
134 * @Inject("members_fields")
137 protected $members_fields;
139 * @Inject("members_form_fields")
142 protected $members_form_fields;
144 * @Inject("members_fields_cats")
147 protected $members_fields_cats;
151 * @var \Galette\Handlers\NotFound
153 protected $notFoundHandler;
158 * @param ContainerInterface $container Container instance
160 public function __construct(ContainerInterface
$container)
162 $this->container
= $container;
163 //set various services we need
164 $this->zdb
= $container->get('zdb');
165 $this->login
= $container->get('login');
166 $this->preferences
= $container->get('preferences');
167 $this->view
= $container->get('view');
168 $this->logo
= $container->get('logo');
169 $this->print_logo
= $container->get('print_logo');
170 $this->router
= $container->get('router');
171 $this->history
= $container->get('history');
172 $this->i18n
= $container->get('i18n');
173 $this->l10n
= $container->get('l10n');
174 $this->session
= $container->get('session');
175 $this->flash
= $container->get('flash');
176 $this->fields_config
= $container->get('fields_config');
177 $this->lists_config
= $container->get('lists_config');
178 $this->notFoundHandler
= $container->get('notFoundHandler');
179 $this->members_fields
= $container->get('members_fields');
180 $this->members_form_fields
= $container->get('members_form_fields');
181 $this->members_fields_cats
= $container->get('members_fields_cats');
185 * Galette redirection workflow
186 * Each user have a default homepage depending on it status (logged in or not, its credentials, etc.
188 * @param Request $request PSR Request
189 * @param Response $response PSR Response
193 protected function galetteRedirect(Request
$request, Response
$response)
195 //reinject flash messages so they're not lost
196 $flashes = $this->flash
->getMessages();
197 foreach ($flashes as $type => $messages) {
198 foreach ($messages as $message) {
199 $this->container
->get('flash')->addMessage($type, $message);
203 if ($this->login
->isLogged()) {
205 if ($this->session
->urlRedirect
!== null) {
206 $urlRedirect = $this->getGaletteBaseUrl($request) . $this->session
->urlRedirect
;
207 $this->session
->urlRedirect
= null;
210 if ($urlRedirect !== null) {
213 ->withHeader('Location', $urlRedirect);
216 $this->login
->isSuperAdmin()
217 ||
$this->login
->isAdmin()
218 ||
$this->login
->isStaff()
221 !isset($_COOKIE['show_galette_dashboard'])
222 ||
$_COOKIE['show_galette_dashboard'] == 1
226 ->withHeader('Location', $this->router
->pathFor('dashboard'));
230 ->withHeader('Location', $this->router
->pathFor('members'));
235 ->withHeader('Location', $this->router
->pathFor('dashboard'));
241 ->withHeader('Location', $this->router
->pathFor('login'));
246 * Get base URL fixed for proxies
248 * @param Request $request PSR Request
252 private function getGaletteBaseUrl(Request
$request)
257 '|https?://' . $_SERVER['HTTP_HOST'] . '(:\d+)?' . '|'
260 $request->getUri()->getBaseUrl()
262 if (strlen($url) && substr($url, -1) !== '/') {
269 * Get route arguments
270 * php-di bridge pass each variable, not an array of all arguments
272 * @param Request $request PSR Request
276 protected function getArgs(Request
$request): array
278 $route = $request->getAttribute('route');
279 $args = $route->getArguments();