]>
git.agnieray.net Git - galette.git/blob - galette/includes/galette.inc.php
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Main Galette initialisation
10 * Copyright © 2009-2021 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 2007-2021 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
37 //define galette's root directory
38 if (!defined('GALETTE_ROOT')) {
39 define('GALETTE_ROOT', __DIR__
. '/../');
42 require_once GALETTE_ROOT
. 'config/versions.inc.php';
43 require_once GALETTE_ROOT
. 'config/paths.inc.php';
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();
53 $time_start = microtime(true);
54 $cron = (PHP_SAPI
=== 'cli');
56 // define relative base path templating can use
57 if (!defined('GALETTE_BASE_PATH')) {
58 define('GALETTE_BASE_PATH', './');
61 //we'll only include relevant parts if we work from installer
62 if (!isset($installer)) {
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');
71 } else if ($installed) {
72 include_once GALETTE_CONFIG_PATH
. 'config.inc.php';
76 file_exists(GALETTE_CONFIG_PATH
. 'behavior.inc.php')
77 && !defined('GALETTE_TESTS') && !$cron
79 include_once GALETTE_CONFIG_PATH
. 'behavior.inc.php';
84 use Analog\Handler\LevelName
;
87 require GALETTE_ROOT
. '/vendor/autoload.php';
91 defined('GALETTE_XHPROF_PATH')
92 && function_exists('xhprof_enable')
94 include_once __DIR__
. '/../lib/Galette/Common/XHProf.php';
95 $profiler = new Galette\Common\
XHProf();
99 define('GALETTE_NIGHTLY', false);
100 define('GALETTE_VERSION', 'v0.9.5.2');
103 if (!defined('GALETTE_HIDE_VERSION')) {
104 define('GALETTE_DISPLAY_VERSION', \Galette\Core\Galette
::gitVersion(false));
107 define('GALETTE_COMPAT_VERSION', '0.9.5');
108 define('GALETTE_DB_VERSION', '0.950');
109 if (!defined('GALETTE_MODE')) {
110 define('GALETTE_MODE', \Galette\Core\Galette
::MODE_PROD
);
113 if (!isset($_COOKIE['show_galette_dashboard'])) {
115 'show_galette_dashboard',
118 'expires' => time() +
31536000, //valid for a year
124 if (!defined('GALETTE_DISPLAY_ERRORS')) {
125 if (GALETTE_MODE
=== \Galette\Core\Galette
::MODE_DEV
) {
126 define('GALETTE_DISPLAY_ERRORS', 1);
128 define('GALETTE_DISPLAY_ERRORS', 0);
131 ini_set('display_errors', (defined('GALETTE_TESTS') ?
'1' : '0'));
133 /*------------------------------------------------------------------------------
135 ------------------------------------------------------------------------------*/
137 error_reporting(E_ALL
);
138 set_error_handler(function ($severity, $message, $file, $line) {
139 if (error_reporting() & $severity) {
140 throw new \
ErrorException($message, 0, $severity, $file, $line);
144 //change default format so the 3rd param is a string for level name
145 Analog
::$format = "%s - %s - %s - %s\n";
146 $galette_run_log = null;
148 if (!defined('GALETTE_LOG_LVL')) {
149 if (GALETTE_MODE
=== 'DEV') {
150 define('GALETTE_LOG_LVL', Analog
::DEBUG
);
151 } elseif (defined('GALETTE_TESTS')) {
152 define('GALETTE_LOG_LVL', Analog
::NOTICE
);
154 define('GALETTE_LOG_LVL', Analog
::WARNING
);
158 if (defined('GALETTE_TESTS')) {
159 $log_path = GALETTE_LOGS_PATH
. 'tests.log';
160 $galette_run_log = LevelName
::init(Handler\File
::init($log_path));
162 $galette_log_var = null;
164 if (!$installer ||
($installer && defined('GALETTE_LOGGER_CHECKED'))) {
165 //logs everything in galette log file
166 if (!isset($logfile)) {
167 //if no filename has been setted (ie. from install), set default one
168 $logfile = 'galette';
170 $log_path = GALETTE_LOGS_PATH
. $logfile . '.log';
171 $galette_run_log = LevelName
::init(Handler\File
::init($log_path));
173 $galette_run_log = LevelName
::init(Handler\Variable
::init($galette_log_var));
176 Core\Logs
::cleanup();
180 Analog
::handler($galette_run_log);
182 require_once GALETTE_ROOT
. 'includes/functions.inc.php';
184 //If we're not working from tests
185 if ($installed && !defined('GALETTE_TESTS')) {
188 * Database instantiation
190 $zdb = new Core\
Db();
192 if ($zdb->checkDbVersion()) {
197 $preferences = new Core\
Preferences($zdb);
200 * Set the path to the current theme templates
203 '_CURRENT_THEME_PATH',
204 GALETTE_THEMES_PATH
. $preferences->pref_theme
. '/'
207 if (!defined('GALETTE_TPL_SUBDIR')) {
209 'GALETTE_TPL_SUBDIR',
210 'templates/' . $preferences->pref_theme
. '/'
214 if (!defined('GALETTE_THEME')) {
217 'themes/' . $preferences->pref_theme
. '/'
221 $needs_update = true;
225 $plugins = new Galette\Core\
Plugins();
226 //make sure plugins autoload is called before session start
227 $plugins->autoload(GALETTE_PLUGINS_PATH
);