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
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.9.4dev - 2019-12-02
38 namespace Galette\Controllers
;
40 use Psr\Container\ContainerInterface
;
41 use Slim\Http\Request
;
42 use Slim\Http\Response
;
45 * Galette abstract controller
47 * @category Controllers
48 * @name AbstractController
50 * @author Johan Cwiklinski <johan@x-tnd.be>
51 * @copyright 2019-2020 The Galette Team
52 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
53 * @link http://galette.tuxfamily.org
54 * @since Available since 0.9.4dev - 2019-12-02
57 abstract class AbstractController
62 * @var Galette\Core\Db
67 * @var Galette\Core\Login
72 * @var Galette\Core\Preferences
74 protected $preferences;
77 * @var Slim\Views\Smarty
82 * @var Galette\Core\Logo
87 * @var Galette\Core\Plugins
97 * @var Galette\Core\History
102 * @var Galette\Core\I18n
111 * @var Slim\Flash\Messages
116 * @var Galette\Entity\FieldsConfig
118 protected $fields_config;
123 protected $members_fields;
128 protected $members_fields_cats;
132 * @var Galette\Handlers\NotFound
134 protected $notFoundHandler;
139 * @param ContainerInterface $container COntainer instance
141 public function __construct(ContainerInterface
$container)
143 $this->container
= $container;
144 //set variosu services we need
145 $this->zdb
= $container->get('zdb');
146 $this->login
= $container->get('login');
147 $this->preferences
= $container->get('preferences');
148 $this->view
= $container->get('view');
149 $this->logo
= $container->get('logo');
150 $this->print_logo
= $container->get('print_logo');
151 $this->plugins
= $container->get('plugins');
152 $this->router
= $container->get('router');
153 $this->history
= $container->get('history');
154 $this->i18n
= $container->get('i18n');
155 $this->session
= $container->get('session');
156 $this->flash
= $container->get('flash');
157 $this->fields_config
= $container->get('fields_config');
158 $this->notFoundHandler
= $container->get('notFoundHandler');
159 $this->members_fields
= $container->get('members_fields');
160 $this->members_fields_cats
= $container->get('members_fields_cats');
164 * Galette redirection workflow
165 * Each user have a default homepage depending on it status (logged in or not, its credentials, etc.
167 * @param Request $request PSR Request
168 * @param Response $response PSR Response
169 * @param array $args Request arguments ['r']
173 protected function galetteRedirect(Request
$request, Response
$response, array $args = [])
175 //reinject flash messages so they're not lost
176 $flashes = $this->flash
->getMessages();
177 foreach ($flashes as $type => $messages) {
178 foreach ($messages as $message) {
179 $this->container
->get('flash')->addMessage($type, $message);
183 if ($this->login
->isLogged()) {
185 if ($this->session
->urlRedirect
!== null) {
186 $urlRedirect = $this->getGaletteBaseUrl($request) . $this->session
->urlRedirect
;
187 $this->session
->urlRedirect
= null;
190 if ($urlRedirect !== null) {
193 ->withHeader('Location', $urlRedirect);
195 if ($this->login
->isSuperAdmin()
196 ||
$this->login
->isAdmin()
197 ||
$this->login
->isStaff()
199 if (!isset($_COOKIE['show_galette_dashboard'])
200 ||
$_COOKIE['show_galette_dashboard'] == 1
204 ->withHeader('Location', $this->router
->pathFor('dashboard'));
208 ->withHeader('Location', $this->router
->pathFor('members'));
213 ->withHeader('Location', $this->router
->pathFor('dashboard'));
219 ->withHeader('Location', $this->router
->pathFor('login'));
224 * Get base URL fixed for proxies
226 * @param Request $request PSR Request
230 private function getGaletteBaseUrl(Request
$request)
235 '|https?://' . $_SERVER['HTTP_HOST'] . '(:\d+)?' . '|'
238 $request->getUri()->getBaseUrl()
240 if (strlen($url) && substr($url, -1) !== '/') {