]> git.agnieray.net Git - galette.git/blob - galette/includes/main.inc.php
56a14a7415d151e5fd32acb97da8024a4efff2c2
[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 define('GALETTE_THEME', 'themes/default/');
61 $app = new \Galette\Core\LightSlimApp();
62 } else {
63 $app = new \Galette\Core\SlimApp();
64 }
65
66 //CONFIGURE AND START SESSION
67
68 //Session duration
69 if (!defined('GALETTE_TIMEOUT')) {
70 //See https://php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime
71 define('GALETTE_TIMEOUT', 0);
72 }
73
74 $session_name = '';
75 //since PREFIX_DB and NAME_DB are required to properly instanciate sessions,
76 // we have to check here if they're assigned
77 if ($installer || !defined('PREFIX_DB') || !defined('NAME_DB')) {
78 $session_name = 'install_' . str_replace('.', '_', GALETTE_VERSION);
79 } else {
80 $session_name = PREFIX_DB . '_' . NAME_DB . '_' . str_replace('.', '_', GALETTE_VERSION);
81 }
82 $session_name = 'galette_' . $session_name;
83 $session = new \RKA\SessionMiddleware([
84 'name' => $session_name,
85 'lifetime' => GALETTE_TIMEOUT
86 ]);
87
88 $session->start();
89 $app->add($session);
90
91 // Set up dependencies
92 require GALETTE_ROOT . '/includes/dependencies.php';
93
94 if ($needs_update) {
95 $app->add(
96 new \Galette\Middleware\UpdateAndMaintenance(
97 $container->get('i18n'),
98 \Galette\Middleware\UpdateAndMaintenance::NEED_UPDATE
99 )
100 );
101
102 $app->run();
103 die();
104 }
105
106 $smarty = $app->getContainer()->get('view')->getSmarty();
107 require_once GALETTE_ROOT . 'includes/smarty.inc.php';
108
109 /**
110 * Authentication middleware
111 */
112 $authenticate = new \Galette\Middleware\Authenticate($container);
113
114 //Maintainance middleware
115 if ('MAINT' === GALETTE_MODE && !$container->get('login')->isSuperAdmin()) {
116 $app->add(
117 new \Galette\Middleware\UpdateAndMaintenance(
118 $i18n,
119 \Galette\Middleware\UpdateAndMaintenance::MAINTENANCE
120 )
121 );
122 }
123
124 /**
125 * Trailing slash middleware
126 */
127 $app->add('\Galette\Middleware\TrailingSlash');
128
129 /**
130 * Change language middleware
131 *
132 * Require determineRouteBeforeAppMiddleware to be on.
133 */
134 $app->add('\Galette\Middleware\Language');
135
136 //Telemetry update middleware
137 $app->add('\Galette\Middleware\Telemetry');
138
139 /**
140 * Check routes ACLs
141 * This is important this one to be the last, so it'll be executed first.
142 */
143 $app->add('\Galette\Middleware\CheckAcls');
144
145 require_once GALETTE_ROOT . 'includes/routes/main.routes.php';
146 require_once GALETTE_ROOT . 'includes/routes/authentication.routes.php';
147 require_once GALETTE_ROOT . 'includes/routes/management.routes.php';
148 require_once GALETTE_ROOT . 'includes/routes/members.routes.php';
149 require_once GALETTE_ROOT . 'includes/routes/groups.routes.php';
150 require_once GALETTE_ROOT . 'includes/routes/contributions.routes.php';
151 require_once GALETTE_ROOT . 'includes/routes/public_pages.routes.php';
152 require_once GALETTE_ROOT . 'includes/routes/ajax.routes.php';
153 require_once GALETTE_ROOT . 'includes/routes/plugins.routes.php';
154
155 $app->run();
156
157 if (isset($profiler)) {
158 $profiler->stop();
159 }