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