[go: up one dir, main page]

Menu

[r1105]: / trunk / core / init.php  Maximize  Restore  History

Download this file

206 lines (176 with data), 5.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/* This file is part of testMaker.
testMaker is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
testMaker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/**
* @package Core
*/
/*
$revision = '$Rev$';
$date = '$Date$';
$version = substr($revision, 6, -2);
$versiondate = substr($date, 7, 10);
define('VERSION', "3.1.1." . $revision);
define('VERSIONDATE', $versiondate);
*/
/**
* Represents the base directory of the core
*/
define("CORE", str_replace("\\", "/", dirname(__FILE__))."/");
/**
* The current version number of testMaker
*/
define("TM_VERSION", "3.4");
/**
* The version suffix for the current version (if any)
*/
define("TM_VERSION_SUFFIX", "");
/**
* The Level for gzcompress(), higher = more CPU load but better DB use (0-9), Default is 6
*/
define("GZCOMPRESSLVL", 6);
/**
* The max. execution time on this machine
*/
define("MAX_EXE_TIME", ini_get("max_execution_time"));
function return_bytes($val) {
$val = trim($val);
$last = strtolower($val[strlen($val)-1]);
switch($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
/**
* The Memory Limit in Bytes on this machine
*/
define("MEMORY_LIMIT", return_bytes(ini_get("memory_limit")));
/**
* Speedmode, do not make any memory checks. May lead to memory limit timeouts. (default: FALSE)
*/
define("SPEEDMODE", FALSE);
/**
* Stores the current time, to have a global concept of "now".
* Use this constant whenever you need the current time as in "time when the request started".
*/
define("NOW", time());
start("Adding translations");
libLoad("environment::Translation");
$GLOBALS["TRANSLATION"]->addRepository(CORE."translations/");
stop();
/* Load the configuration file.
* If that fails, bail out unless we're in the installer.
*/
start("Loading configuration file");
@include_once(CORE.'init/configuration.php');
$inInstaller = strpos(@$_SERVER['REQUEST_URI'], 'installer');
if (!defined('DB_TYPE')) {
if (!$inInstaller) {
libLoad("html::preInitErrorPage");
preInitErrorPage('init.error.no_config_file', array('core_dir' => CORE));
}
$config_loaded = false;
} else {
$config_loaded = true;
}
if (!defined('TMP_DIR') || !TMP_DIR) {
$tempDir = ROOT.'upload/temp';
if (! is_dir($tempDir) && !$inInstaller) {
mkdir($tempDir);
copy(CORE.".htaccess", $tempDir."/.htaccess");
}
} else {
$tempDir = TMP_DIR;
}
// Defining TM_TMP_DIR only here shuts up phpDocumentor
/**
* The path to the temporary directory
*/
define('TM_TMP_DIR', $tempDir);
if (!$inInstaller) {
register_shutdown_function("cleanTempDir");
}
stop();
start("Include some files");
require_once(CORE.'init/settings.php');
require_once(CORE.'environment/DataAccess.php');
if (!file_exists(dirname(__FILE__)."/../installer_off")) {
start("installer/Database.php");
require_once(INSTALLER.'Database.php');
stop();
start("installer/InstallFeedback.php");
require_once(INSTALLER.'InstallFeedback.php');
stop();
start("installer/AdvancedMigrations.php");
require_once(INSTALLER.'AdvancedMigrations.php');
stop();
require_once(INSTALLER.'Installer.php');
}
start("utilities::ObjectCache");
libLoad('utilities::ObjectCache');
stop();
stop();
if ($config_loaded) {
start("Database connection");
$dao = new DataAccess(DB_TYPE, DB_HOST, DB_NAME, DB_USER, DB_PASSWORD);
$dao->connect();
stop();
if (!file_exists(dirname(__FILE__)."/../installer_off")) {
start("Installer");
// Check if database needs to be updated
if (!$inInstaller) {
$inst = new MockInstaller();
$dbInst = new Database($inst);
$advMig = new AdvancedMigrations($inst);
$insFed = new InstallFeedback($inst);
if ($dbInst->checkDbInit() || $dbInst->checkAdvGroupsInit() || $advMig->doAllChecks() || $insFed->doAllChecks()) {
if (!$dbInst->check_connect()) {
libLoad('html::preInitErrorPage');
preInitErrorPage('init.error.db_no_connect');
}
$_GET['page'] = 'installer'; //echo'meh'; //b/
unset($_GET['action']);
$_GET['pending'] = '1';
}
}
stop();
}
if (!$inInstaller) {
require_once(CORE."types/DataObject.php");
require_once(CORE."types/BlockList.php");
require_once(CORE."types/TestStructure.php");
require_once(CORE."types/MimeTypes.php");
require_once(CORE.'types/TestStructure.php');
}
}
/**
* Cleans the temporary directory every 24 hours
* Files and empty directories older than 24 hours will be deleted
*/
function cleanTempDir()
{
// 24 hours
$age = 60 * 60 * 24;
$lastCleanFile = TM_TMP_DIR."/.lastclean";
if (@filemtime($lastCleanFile) + $age < NOW) {
if ($handle = fopen($lastCleanFile, "w")) {
fclose($handle);
libLoad("utilities::deleteOldFiles");
deleteOldFiles(TM_TMP_DIR, NOW, $age, TRUE);
}
}
}
?>