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;
122 * @var Galette\Handlers\NotFound
124 protected $notFoundHandler;
129 * @param ContainerInterface $container COntainer instance
131 public function __construct(ContainerInterface
$container)
133 $this->container
= $container;
134 //set variosu services we need
135 $this->zdb
= $container->get('zdb');
136 $this->login
= $container->get('login');
137 $this->preferences
= $container->get('preferences');
138 $this->view
= $container->get('view');
139 $this->logo
= $container->get('logo');
140 $this->print_logo
= $container->get('print_logo');
141 $this->plugins
= $container->get('plugins');
142 $this->router
= $container->get('router');
143 $this->history
= $container->get('history');
144 $this->i18n
= $container->get('i18n');
145 $this->session
= $container->get('session');
146 $this->flash
= $container->get('flash');
147 $this->fields_config
= $container->get('fields_config');
148 $this->notFoundHandler
= $container->get('notFoundHandler');
152 * Galette redirection workflow
153 * Each user have a default homepage depending on it status (logged in or not, its credentials, etc.
155 * @param Request $request PSR Request
156 * @param Response $response PSR Response
157 * @param array $args Request arguments ['r']
161 protected function galetteRedirect(Request
$request, Response
$response, array $args = [])
163 //reinject flash messages so they're not lost
164 $flashes = $this->flash
->getMessages();
165 foreach ($flashes as $type => $messages) {
166 foreach ($messages as $message) {
167 $this->container
->get('flash')->addMessage($type, $message);
171 if ($this->login
->isLogged()) {
173 if ($this->session
->urlRedirect
!== null) {
174 $urlRedirect = $this->getGaletteBaseUrl($request) . $this->session
->urlRedirect
;
175 $this->session
->urlRedirect
= null;
178 if ($urlRedirect !== null) {
181 ->withHeader('Location', $urlRedirect);
183 if ($this->login
->isSuperAdmin()
184 ||
$this->login
->isAdmin()
185 ||
$this->login
->isStaff()
187 if (!isset($_COOKIE['show_galette_dashboard'])
188 ||
$_COOKIE['show_galette_dashboard'] == 1
192 ->withHeader('Location', $this->router
->pathFor('dashboard'));
196 ->withHeader('Location', $this->router
->pathFor('members'));
201 ->withHeader('Location', $this->router
->pathFor('dashboard'));
207 ->withHeader('Location', $this->router
->pathFor('login'));
212 * Get base URL fixed for proxies
214 * @param Request $request PSR Request
218 private function getGaletteBaseUrl(Request
$request)
223 '|https?://' . $_SERVER['HTTP_HOST'] . '(:\d+)?' . '|'
226 $request->getUri()->getBaseUrl()
228 if (strlen($url) && substr($url, -1) !== '/') {