]> git.agnieray.net Git - galette.git/blob - galette/includes/main.inc.php
Switch to PSR12, phpcbf fix
[galette.git] / galette / includes / main.inc.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Galette's instanciation and routes
7 *
8 * PHP version 5
9 *
10 * Copyright © 2012-2014 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
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.
18 *
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.
23 *
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/>.
26 *
27 * @category Main
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2012-2014 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 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since 0.8.2dev 2014-11-10
36 */
37
38 use Slim\Slim;
39 use Slim\Route;
40 use Galette\Core\Login;
41 use Analog\Analog;
42
43 $time_start = microtime(true);
44
45 //define galette's root directory
46 if (!defined('GALETTE_ROOT')) {
47 define('GALETTE_ROOT', __DIR__ . '/../');
48 }
49
50 // define relative base path templating can use
51 if (!defined('GALETTE_BASE_PATH')) {
52 define('GALETTE_BASE_PATH', '../');
53 }
54
55 $needs_update = false;
56 /** @ignore */
57 require_once GALETTE_ROOT . 'includes/galette.inc.php';
58
59 //Galette needs database update!
60 if ($needs_update) {
61 $app = new \Slim\App(
62 array(
63 'templates.path' => GALETTE_ROOT . 'templates/default/',
64 'mode' => 'NEED_UPDATE'
65 )
66 );
67
68 define(
69 'GALETTE_THEME',
70 'themes/default/'
71 );
72
73 require_once GALETTE_ROOT . 'includes/dependencies.php';
74
75 $app->add(
76 new \Galette\Middleware\UpdateAndMaintenance(
77 $i18n,
78 \Galette\Middleware\UpdateAndMaintenance::NEED_UPDATE
79 )
80 );
81
82 $app->run();
83 die();
84 } else {
85 $app = new \Slim\App(
86 [
87 'settings' => [
88 'determineRouteBeforeAppMiddleware' => true,
89 'displayErrorDetails' => (GALETTE_MODE === 'DEV'),
90 'addContentLengthHeader' => false,
91 // monolog settings
92 'logger' => [
93 'name' => 'galette',
94 'level' => \Monolog\Logger::DEBUG,
95 'path' => GALETTE_LOGS_PATH . '/galette_slim.log',
96 ],
97 //'routerCacheFile' => (GALETTE_MODE === 'DEV') ? false : GALETTE_CACHE_DIR . '/fastroute.cache' //disabled until properly handled
98 ],
99 'mode' => 'PROD'
100 ]
101 );
102 }
103
104 //Session duration
105 if (!defined('GALETTE_TIMEOUT')) {
106 //See php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime
107 define('GALETTE_TIMEOUT', 0);
108 }
109
110 $plugins = new Galette\Core\Plugins();
111 $plugins->autoload(GALETTE_PLUGINS_PATH);
112
113 $session_name = '';
114 //since PREFIX_DB and NAME_DB are required to properly instanciate sessions,
115 // we have to check here if they're assigned
116 if ($installer || !defined('PREFIX_DB') || !defined('NAME_DB')) {
117 $session_name = 'install_' . str_replace('.', '_', GALETTE_VERSION);
118 } else {
119 $session_name = PREFIX_DB . '_' . NAME_DB . '_' . str_replace('.', '_', GALETTE_VERSION);
120 }
121 $session_name = 'galette_' . $session_name;
122 $session = new \RKA\SessionMiddleware([
123 'name' => $session_name,
124 'lifetime' => GALETTE_TIMEOUT
125 ]);
126 $app->add($session);
127 $session->start();
128
129 // Set up dependencies
130 require GALETTE_ROOT . '/includes/dependencies.php';
131
132 $smarty = $app->getContainer()->get('view')->getSmarty();
133 require_once GALETTE_ROOT . 'includes/smarty.inc.php';
134
135 /**
136 * Authentication middleware
137 */
138 $authenticate = new \Galette\Middleware\Authenticate($container);
139
140 //Maintainance middleware
141 if ('MAINT' === GALETTE_MODE && !$container->get('login')->isSuperAdmin()) {
142 $app->add(
143 new \Galette\Middleware\UpdateAndMaintenance(
144 $i18n,
145 \Galette\Middleware\UpdateAndMaintenance::MAINTENANCE
146 )
147 );
148 }
149
150 /**
151 * Trailing slash middleware
152 */
153 $app->add('\Galette\Middleware\TrailingSlash');
154
155 /**
156 * Change language middleware
157 *
158 * Require determineRouteBeforeAppMiddleware to be on.
159 */
160 $app->add('\Galette\Middleware\Language');
161
162 //Telemetry update middleware
163 $app->add('\Galette\Middleware\Telemetry');
164
165 /**
166 * Check routes ACLs
167 * This is important this one to be the last, so it'll be executed first.
168 */
169 $app->add('\Galette\Middleware\CheckAcls');
170
171 require_once GALETTE_ROOT . 'includes/routes/main.routes.php';
172 require_once GALETTE_ROOT . 'includes/routes/authentication.routes.php';
173 require_once GALETTE_ROOT . 'includes/routes/management.routes.php';
174 require_once GALETTE_ROOT . 'includes/routes/members.routes.php';
175 require_once GALETTE_ROOT . 'includes/routes/groups.routes.php';
176 require_once GALETTE_ROOT . 'includes/routes/contributions.routes.php';
177 require_once GALETTE_ROOT . 'includes/routes/public_pages.routes.php';
178 require_once GALETTE_ROOT . 'includes/routes/ajax.routes.php';
179 require_once GALETTE_ROOT . 'includes/routes/plugins.routes.php';
180
181 $app->run();
182
183 if (isset($profiler)) {
184 $profiler->stop();
185 }