]> git.agnieray.net Git - galette.git/blob - galette/includes/galette.inc.php
Bump version
[galette.git] / galette / includes / galette.inc.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Main Galette initialisation
7 *
8 * PHP version 5
9 *
10 * Copyright © 2009-2018 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 2007-2018 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 Available since 0.7-dev - 2007-10-07
35 */
36
37 //define galette's root directory
38 if (!defined('GALETTE_ROOT')) {
39 define('GALETTE_ROOT', __DIR__ . '/../');
40 }
41
42 require_once GALETTE_ROOT . 'config/versions.inc.php';
43 require_once GALETTE_ROOT . 'config/paths.inc.php';
44
45 // check required PHP version...
46 if (version_compare(PHP_VERSION, GALETTE_PHP_MIN, '<')) {
47 echo 'Galette is NOT compliant with your current PHP version. ' .
48 'Galette requires PHP ' . GALETTE_PHP_MIN .
49 ' minimum and current version is ' . phpversion();
50 die(1);
51 }
52
53 $time_start = microtime(true);
54 $cron = (PHP_SAPI === 'cli');
55
56 // define relative base path templating can use
57 if (!defined('GALETTE_BASE_PATH')) {
58 define('GALETTE_BASE_PATH', './');
59 }
60
61 //we'll only include relevant parts if we work from installer
62 if (!isset($installer)) {
63 $installer = false;
64 }
65 // test if galette is already installed or if we're form installer
66 // and redirect to install page if not
67 $installed = file_exists(GALETTE_CONFIG_PATH . 'config.inc.php');
68 if (!$installed && !$installer) {
69 header('location: ./installer.php');
70 die();
71 }
72
73 if (
74 file_exists(GALETTE_CONFIG_PATH . 'behavior.inc.php')
75 && !defined('GALETTE_TESTS') && !$cron
76 ) {
77 include_once GALETTE_CONFIG_PATH . 'behavior.inc.php';
78 }
79
80 if (isset($installer) && $installer !== true) {
81 //If we're not working from installer
82 include_once GALETTE_CONFIG_PATH . 'config.inc.php';
83 }
84
85 use Analog\Analog;
86 use Analog\Handler;
87 use Analog\Handler\LevelName;
88 use Galette\Core;
89
90 /*
91 BREAKS as of Galette 0.9-dev
92 // To help the built-in PHP dev server, check if the request was actually for
93 // something which should probably be served as a static file
94 if (PHP_SAPI === 'cli-server' && $_SERVER['SCRIPT_FILENAME'] !== __FILE__) {
95 return false;
96 }*/
97
98 require GALETTE_ROOT . '/vendor/autoload.php';
99
100 //start profiling
101 if (
102 defined('GALETTE_XHPROF_PATH')
103 && function_exists('xhprof_enable')
104 ) {
105 include_once __DIR__ . '/../lib/Galette/Common/XHProf.php';
106 $profiler = new Galette\Common\XHProf();
107 $profiler->start();
108 }
109
110 define('GALETTE_NIGHTLY', false);
111 define('GALETTE_VERSION', 'v0.9.4.1');
112
113 //Version to display
114 if (!defined('GALETTE_HIDE_VERSION')) {
115 define('GALETTE_DISPLAY_VERSION', \Galette\Core\Galette::gitVersion(false));
116 }
117
118 define('GALETTE_COMPAT_VERSION', '0.9.2');
119 define('GALETTE_DB_VERSION', '0.940');
120 if (!defined('GALETTE_MODE')) {
121 define('GALETTE_MODE', 'PROD'); //DEV, PROD, MAINT or DEMO
122 }
123
124 if (!isset($_COOKIE['show_galette_dashboard'])) {
125 setcookie(
126 'show_galette_dashboard',
127 true,
128 time() + 31536000 //valid for a year
129 );
130 }
131
132 if (!defined('GALETTE_DISPLAY_ERRORS')) {
133 if (GALETTE_MODE === 'DEV') {
134 define('GALETTE_DISPLAY_ERRORS', 1);
135 } else {
136 define('GALETTE_DISPLAY_ERRORS', 0);
137 }
138 }
139 ini_set('display_errors', 0);
140
141 set_include_path(
142 GALETTE_ZEND_PATH . PATH_SEPARATOR .
143 GALETTE_PHP_MAILER_PATH . PATH_SEPARATOR .
144 GALETTE_SMARTY_PATH . PATH_SEPARATOR .
145 get_include_path()
146 );
147
148 /*------------------------------------------------------------------------------
149 Logger stuff
150 ------------------------------------------------------------------------------*/
151
152 //change default format so the 3rd param is a string for level name
153 Analog::$format = "%s - %s - %s - %s\n";
154 $galette_run_log = null;
155 $galette_debug_log = Handler\Ignore::init();
156
157 if (!defined('GALETTE_LOG_LVL')) {
158 if (GALETTE_MODE === 'DEV') {
159 define('GALETTE_LOG_LVL', Analog::DEBUG);
160 } elseif (defined('GALETTE_TESTS')) {
161 define('GALETTE_LOG_LVL', Analog::NOTICE);
162 } else {
163 define('GALETTE_LOG_LVL', Analog::WARNING);
164 }
165 }
166
167 if (defined('GALETTE_TESTS')) {
168 $log_path = GALETTE_LOGS_PATH . 'tests.log';
169 $galette_run_log = LevelName::init(Handler\File::init($log_path));
170 } else {
171 if ((!$installer || ($installer && defined('GALETTE_LOGGER_CHECKED'))) && !$cron) {
172 if (GALETTE_LOG_LVL >= Analog::INFO) {
173 $now = new \DateTime();
174 $dbg_log_path = GALETTE_LOGS_PATH . 'galette_debug_' .
175 $now->format('Y-m-d') . '.log';
176 $galette_debug_log = LevelName::init(Handler\File::init($dbg_log_path));
177 } else {
178 $galette_debug_log = Handler\Ignore::init();
179 }
180 }
181 $galette_log_var = null;
182
183 if (defined('GALETTE_SYS_LOG') && GALETTE_SYS_LOG === true) {
184 //logs everything in PHP logs (per chance /var/log/http/error_log or /var/log/php-fpm/error.log)
185 $galette_run_log = Handler\Syslog::init('galette', 'user');
186 } else {
187 if (!$installer || ($installer && defined('GALETTE_LOGGER_CHECKED'))) {
188 //logs everything in galette log file
189 if (!isset($logfile)) {
190 //if no filename has been setted (ie. from install), set default one
191 $logfile = 'galette_run';
192 }
193 $log_path = GALETTE_LOGS_PATH . $logfile . '.log';
194 $galette_run_log = LevelName::init(Handler\File::init($log_path));
195 } else {
196 $galette_run_log = LevelName::init(Handler\Variable::init($galette_log_var));
197 }
198 }
199 if (!$installer) {
200 Core\Logs::cleanup();
201 }
202 }
203
204 Analog::handler(
205 Handler\Multi::init(
206 array(
207 Analog::NOTICE => Handler\Threshold::init(
208 $galette_run_log,
209 GALETTE_LOG_LVL
210 ),
211 Analog::DEBUG => $galette_debug_log
212 )
213 )
214 );
215
216 require_once GALETTE_ROOT . 'includes/functions.inc.php';
217
218 if (!$installer and !defined('GALETTE_TESTS')) {
219 //If we're not working from installer nor from tests
220 include_once GALETTE_CONFIG_PATH . 'config.inc.php';
221
222 /**
223 * Database instanciation
224 */
225 $zdb = new Core\Db();
226
227 if ($zdb->checkDbVersion()) {
228
229 /**
230 * Load preferences
231 */
232 $preferences = new Core\Preferences($zdb);
233
234 /**
235 * Set the path to the current theme templates
236 */
237 define(
238 '_CURRENT_THEME_PATH',
239 GALETTE_THEMES_PATH . $preferences->pref_theme . '/'
240 );
241
242 if (!defined('GALETTE_TPL_SUBDIR')) {
243 define(
244 'GALETTE_TPL_SUBDIR',
245 'templates/' . $preferences->pref_theme . '/'
246 );
247 }
248
249 if (!defined('GALETTE_THEME')) {
250 define(
251 'GALETTE_THEME',
252 'themes/' . $preferences->pref_theme . '/'
253 );
254 }
255 } else {
256 $needs_update = true;
257 }
258 }