3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Galette abstract controller
10 * Copyright © 2019-2020 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-2020 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-2020 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\Smarty
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
115 * @var \Slim\Flash\Messages
120 * @var \Galette\Entity\FieldsConfig
122 protected $fields_config;
125 * @var \Galette\Entity\ListsConfig
127 protected $lists_config;
132 protected $members_fields;
137 protected $members_form_fields;
142 protected $members_fields_cats;
146 * @var \Galette\Handlers\NotFound
148 protected $notFoundHandler;
153 * @param ContainerInterface $container Container instance
155 public function __construct(ContainerInterface
$container)
157 $this->container
= $container;
158 //set variosu services we need
159 $this->zdb
= $container->get('zdb');
160 $this->login
= $container->get('login');
161 $this->preferences
= $container->get('preferences');
162 $this->view
= $container->get('view');
163 $this->logo
= $container->get('logo');
164 $this->print_logo
= $container->get('print_logo');
165 $this->plugins
= $container->get('plugins');
166 $this->router
= $container->get('router');
167 $this->history
= $container->get('history');
168 $this->i18n
= $container->get('i18n');
169 $this->session
= $container->get('session');
170 $this->flash
= $container->get('flash');
171 $this->fields_config
= $container->get('fields_config');
172 $this->lists_config
= $container->get('lists_config');
173 $this->notFoundHandler
= $container->get('notFoundHandler');
174 $this->members_fields
= $container->get('members_fields');
175 $this->members_form_fields
= $container->get('members_form_fields');
176 $this->members_fields_cats
= $container->get('members_fields_cats');
180 * Galette redirection workflow
181 * Each user have a default homepage depending on it status (logged in or not, its credentials, etc.
183 * @param Request $request PSR Request
184 * @param Response $response PSR Response
185 * @param array $args Request arguments ['r']
189 protected function galetteRedirect(Request
$request, Response
$response, array $args = [])
191 //reinject flash messages so they're not lost
192 $flashes = $this->flash
->getMessages();
193 foreach ($flashes as $type => $messages) {
194 $this->container
->get('flash')->addMessage($type, $message);
197 if ($this->login
->isLogged()) {
199 if ($this->session
->urlRedirect
!== null) {
200 $urlRedirect = $this->getGaletteBaseUrl($request) . $this->session
->urlRedirect
;
201 $this->session
->urlRedirect
= null;
204 if ($urlRedirect !== null) {
207 ->withHeader('Location', $urlRedirect);
210 $this->login
->isSuperAdmin()
211 ||
$this->login
->isAdmin()
212 ||
$this->login
->isStaff()
215 !isset($_COOKIE['show_galette_dashboard'])
216 ||
$_COOKIE['show_galette_dashboard'] == 1
220 ->withHeader('Location', $this->router
->pathFor('dashboard'));
224 ->withHeader('Location', $this->router
->pathFor('members'));
229 ->withHeader('Location', $this->router
->pathFor('dashboard'));
235 ->withHeader('Location', $this->router
->pathFor('login'));
240 * Get base URL fixed for proxies
242 * @param Request $request PSR Request
246 private function getGaletteBaseUrl(Request
$request)
251 '|https?://' . $_SERVER['HTTP_HOST'] . '(:\d+)?' . '|'
254 $request->getUri()->getBaseUrl()
256 if (strlen($url) && substr($url, -1) !== '/') {