3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Main Galette initialisation
10 * Copyright © 2009-2014 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-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
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.7-dev - 2007-10-07
38 if (!defined('GALETTE_PHP_MIN')) {
39 define('GALETTE_PHP_MIN', '5.5');
42 // check required PHP version...
43 if (version_compare(PHP_VERSION
, GALETTE_PHP_MIN
, '<')) {
44 echo 'Galette is NOT compliant with your current PHP version. ' .
45 'Galette requires PHP ' . GALETTE_PHP_MIN
.
46 ' minimum and current version is ' . phpversion();
50 $time_start = microtime(true);
51 $cron = (PHP_SAPI
=== 'cli');
53 //define galette's root directory
54 if (!defined('GALETTE_ROOT')) {
55 define('GALETTE_ROOT', __DIR__
. '/../');
58 // define relative base path templating can use
59 if (!defined('GALETTE_BASE_PATH')) {
60 define('GALETTE_BASE_PATH', './');
63 require_once GALETTE_ROOT
. 'config/versions.inc.php';
64 require_once GALETTE_ROOT
. 'config/paths.inc.php';
66 //we'll only include relevant parts if we work from installer
67 if (!isset($installer)) {
70 // test if galette is already installed or if we're form installer
71 // and redirect to install page if not
72 $installed = file_exists(GALETTE_CONFIG_PATH
. 'config.inc.php');
73 if (!$installed && !$installer) {
74 header('location: install/index.php');
78 if (file_exists(GALETTE_CONFIG_PATH
. 'behavior.inc.php')
79 && !defined('GALETTE_TESTS') && !$cron
81 include_once GALETTE_CONFIG_PATH
. 'behavior.inc.php';
84 if (isset($installer) && $installer !== true) {
85 //If we're not working from installer
86 include_once GALETTE_CONFIG_PATH
. 'config.inc.php';
89 if (!function_exists('password_hash')) {
90 include_once GALETTE_PASSWORD_COMPAT_PATH
. '/password.php';
93 use Galette\Common\ClassLoader
;
97 /*require_once GALETTE_ROOT . 'lib/Galette/Common/ClassLoader.php';
98 require_once GALETTE_SLIM_PATH . 'Slim/Slim.php';
100 $galetteLoader = new ClassLoader('Galette', GALETTE_ROOT . 'lib');
101 $zendLoader = new ClassLoader('Zend', GALETTE_ZEND_PATH);
102 $analogLoader = new ClassLoader('Analog', GALETTE_ANALOG_PATH);
103 $smartyLoader = new ClassLoader(null, GALETTE_SMARTY_PATH);
104 $smartyLoader->setFileExtension('.class.php');
106 $galetteLoader->register();
107 $zendLoader->register();
108 $analogLoader->register();
109 $smartyLoader->register();
111 \Slim\Slim::registerAutoloader();
112 require_once GALETTE_SLIM_VIEWS_PATH . 'Smarty.php';*/
114 // To help the built-in PHP dev server, check if the request was actually for
115 // something which should probably be served as a static file
116 if (PHP_SAPI
=== 'cli-server' && $_SERVER['SCRIPT_FILENAME'] !== __FILE__
) {
120 require GALETTE_ROOT
. '/vendor/autoload.php';
123 if (defined('GALETTE_XHPROF_PATH')
124 && function_exists('xhprof_enable')
126 include_once __DIR__
. '/../lib/Galette/Common/XHProf.php';
127 $profiler = new Galette\Common\
XHProf();
131 //we start a php session
134 define('GALETTE_VERSION', 'v0.9dev');
135 define('GALETTE_COMPAT_VERSION', '0.9');
136 define('GALETTE_DB_VERSION', '0.820');
137 if (!defined('GALETTE_MODE')) {
138 define('GALETTE_MODE', 'PROD'); //DEV, PROD, MAINT or DEMO
141 if (!isset($_COOKIE['show_galette_dashboard'])) {
143 'show_galette_dashboard',
145 time()+
31536000 //valid for a year
149 if (!defined('GALETTE_DISPLAY_ERRORS')) {
150 define('GALETTE_DISPLAY_ERRORS', 0);
152 ini_set('display_errors', GALETTE_DISPLAY_ERRORS
);
155 GALETTE_ZEND_PATH
. PATH_SEPARATOR
.
156 GALETTE_PHP_MAILER_PATH
. PATH_SEPARATOR
.
157 GALETTE_SMARTY_PATH
. PATH_SEPARATOR
.
161 /*------------------------------------------------------------------------------
163 ------------------------------------------------------------------------------*/
164 if (!$cron && (!defined('GALETTE_HANDLE_ERRORS')
165 || GALETTE_HANDLE_ERRORS
=== true)
167 //set custom error handler
170 "Galette\Core\Error",
176 $galette_run_log = null;
177 $galette_debug_log = \Analog\Handler\Ignore
::init();
179 if (!defined('GALETTE_LOG_LVL')) {
180 if (GALETTE_MODE
=== 'DEV') {
181 define('GALETTE_LOG_LVL', \Analog\Analog
::DEBUG
);
183 define('GALETTE_LOG_LVL', \Analog\Analog
::WARNING
);
187 if (defined('GALETTE_TESTS')) {
188 //FIXME: we should check logs files from tests
189 $galette_run_log = \Analog\Handler\Ignore
::init();
191 if ((!$installer ||
($installer && defined('GALETTE_LOGGER_CHECKED'))) && !$cron) {
192 $now = new \
DateTime();
193 $dbg_log_path = GALETTE_LOGS_PATH
. 'galette_debug_' .
194 $now->format('Y-m-d') . '.log';
195 $galette_debug_log = \Analog\Handler\File
::init($dbg_log_path);
197 $galette_log_var = null;
199 if (GALETTE_MODE
=== 'DEV' ||
$cron
200 ||
( defined('GALETTE_SYS_LOG') && GALETTE_SYS_LOG
=== true )
202 //logs everything in PHP logs (per chance /var/log/http/error_log or /var/log/php-fpm/error.log)
203 $galette_run_log = \Analog\Handler\Stderr
::init();
205 if (!$installer ||
($installer && defined('GALETTE_LOGGER_CHECKED'))) {
206 //logs everything in galette log file
207 if (!isset($logfile)) {
208 //if no filename has been setted (ie. from install), set default one
209 $logfile = 'galette_run';
211 $log_path = GALETTE_LOGS_PATH
. $logfile . '.log';
212 $galette_run_log = \Analog\Handler\File
::init($log_path);
214 $galette_run_log = \Analog\Handler\Variable
::init($galette_log_var);
217 Core\Logs
::cleanup();
221 \Analog\Handler\Multi
::init(
223 Analog
::NOTICE
=> \Analog\Handler\Threshold
::init(
227 Analog
::DEBUG
=> $galette_debug_log
232 require_once GALETTE_ROOT
. 'includes/functions.inc.php';
234 //FIXME: native sessions should not be used right now
235 $session_name = null;
236 //since PREFIX_DB and NAME_DB are required to properly instanciate sessions,
237 // we have to check here if they're assigned
238 if ($installer ||
!defined('PREFIX_DB') ||
!defined('NAME_DB')) {
239 $session_name = 'galette_install';
241 $session_name = PREFIX_DB
. '_' . NAME_DB
;
243 $session = &$_SESSION['galette'][$session_name];
245 if (!$installer and !defined('GALETTE_TESTS')) {
246 //If we're not working from installer nor from tests
247 include_once GALETTE_CONFIG_PATH
. 'config.inc.php';
250 * Database instanciation
252 $zdb = new Core\
Db();
254 if ($zdb->checkDbVersion()
255 ||
strpos($_SERVER['PHP_SELF'], 'picture.php') !== false
261 $preferences = new Core\
Preferences($zdb);
264 * Set the path to the current theme templates
267 '_CURRENT_TEMPLATE_PATH',
268 GALETTE_TEMPLATES_PATH
. $preferences->pref_theme
. '/'
271 if (!defined('GALETTE_TPL_SUBDIR')) {
273 'GALETTE_TPL_SUBDIR',
274 'templates/' . $preferences->pref_theme
. '/'
278 if (!defined('GALETTE_THEME')) {
281 'themes/' . $preferences->pref_theme
. '/'
288 /*if (isset($session['login'])) {
289 $login = unserialize(
294 $login = new Core\Login($zdb, $i18n, $session);
297 /** TODO: login is now handled in dependencies.php; the cron case should be aswell */
299 $login->logCron(basename($argv[0], '.php'));
302 $needs_update = true;