Remove Bugdar::$input.
[bugdar.git] / includes / init.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2002-2007 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 error_reporting(E_ALL & ~E_NOTICE);
23
24 // ###################################################################
25 // initialize the database
26
27 define('ISSO_MT_START', microtime());
28 define('ISSO_CHECK_POST_REFERER', 1);
29
30 // TODO(port): Define this in index.php instead.
31 define('BUGDAR_ROOT', dirname(dirname(__FILE__)));
32
33 require_once('./includes/version.php');
34
35 require_once('./framework/kernel.php');
36 $bugsys = new ISSO();
37
38 $bugsys->setAppPath(getcwd());
39 $bugsys->setApplication('Bugdar');
40 $bugsys->setAppVersion(BUGDAR_VERSION);
41
42 if (!file_exists('./includes/config.php'))
43 {
44 echo 'includes/config.php needs to be present!';
45 exit;
46 }
47
48 require_once('./includes/config.php');
49
50 $bugsys->setDebug($debug);
51 define('DEVDEBUG', $debug);
52 unset($debug);
53
54 // ###################################################################
55 // init the big three
56 $bugsys->options = array();
57 $bugsys->userinfo = array();
58
59 class Bugdar
60 {
61 /*! @var \PDO The database connection instance. */
62 static $db = NULL;
63
64 static $options = array();
65 static $user = array();
66 static $datastore = array();
67 }
68
69 // ###################################################################
70 // Hoplite early initialization.
71
72 define('HOPLITE_ROOT', dirname(__FILE__) . '/hoplite');
73
74 if (DEVDEBUG) {
75 require_once HOPLITE_ROOT . '/base/profiling.php';
76 \hoplite\base\Profiling::EnableProfiling();
77 }
78
79 // ###################################################################
80 // Connect to the database.
81
82 $pdo_class = '\\PDO';
83 if (DEVDEBUG) {
84 require_once HOPLITE_ROOT . '/data/profiling_pdo.php';
85 $pdo_class = '\\hoplite\\data\\ProfilingPDO';
86 }
87 Bugdar::$db = new $pdo_class("mysql:dbname=$database;host=$servername", $username, $password);
88 unset($database, $servername, $username, $password);
89
90 // Let ISSO handle the database connection failure message.
91 $bugsys->load('db_mysql_pdo', 'db', true);
92 $db->connect(Bugdar::$db);
93
94 Bugdar::$db->SetAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
95 Bugdar::$db->SetAttribute(\PDO::ATTR_EMULATE_PREPARES, FALSE);
96 Bugdar::$db->SetAttribute(\PDO::ATTR_STRINGIFY_FETCHES, FALSE);
97
98 if ($utf8)
99 {
100 $db->query("SET NAMES utf8");
101 }
102
103 // don't use sql strict mode
104 $db->query("SET sql_mode = ''");
105
106 $bugsys->load('functions', 'funct', true);
107 $bugsys->load('xml', 'xml', true);
108
109 // change cookie expiration to one hour
110 $funct->cookieexp = 3600;
111
112 define('TABLE_PREFIX', $tableprefix);
113 define('COOKIE_PREFIX', $cookieprefix);
114
115 unset($usepconnect, $tableprefix, $cookieprefix);
116
117 require_once('./includes/functions_datastore.php');
118 require_once('./includes/functions.php');
119 require_once('./includes/language.php');
120
121 // ###################################################################
122 // Hoplite late initialization.
123
124 require_once HOPLITE_ROOT . '/data/model.php';
125 \hoplite\data\Model::set_db(Bugdar::$db);
126
127 // ###################################################################
128 // send nocache
129 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
130 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
131 header("Cache-Control: no-store, no-cache, must-revalidate");
132 header("Cache-Control: post-check=0, pre-check=0", false);
133 if ($utf8)
134 {
135 header("Content-Type: text/html; charset=\"utf8\"");
136 }
137 header("Pragma: no-cache");
138
139 // ###################################################################
140 // populate our caches
141 $db->showerrors = false;
142 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
143 $db->showerrors = true;
144
145 if (!$datastoretemp)
146 {
147 echo '<div style="font-size: 18px"><strong>Notice:</strong> This error could be caused if you have not installed Bugdar. If this is the case, you can run the installer <a href="install/install.php">here</a>.</div><br />';
148 $db->error('Invalid SQL error');
149 }
150
151 while ($store = $db->fetch_array($datastoretemp))
152 {
153 Bugdar::$datastore["$store[title]"] = unserialize($store['data']);
154 }
155
156 $bugsys->options = Bugdar::$datastore['setting'];
157 $bugsys->options['columnoptions'] = unserialize($bugsys->options['columnoptions']);
158 unset(Bugdar::$datastore['setting']);
159 Bugdar::$options = $bugsys->options;
160
161 $bugsys->setAppVersion($bugsys->options['trackerversion']);
162
163 // ###################################################################
164 // load permissions
165
166 require_once('./includes/permissions.php');
167
168 // ###################################################################
169 // load userinfo
170
171 $authMethod = ((defined('USE_DEFAULT_AUTH_METHOD') AND constant('USE_DEFAULT_AUTH_METHOD') == 1) ? 'default' : $bugsys->options['authmethod']);
172 require_once('./includes/auth/auth_' . $authMethod . '.php');
173
174 $authClass = 'Authentication' . str_replace(' ', '', ucwords(str_replace('_', ' ', $authMethod)));
175 $bugsys->auth = $auth = new $authClass();
176
177 if ($auth->authenticateCookies())
178 {
179 $bugsys->userinfo = $auth->fetchBugdarUser();
180 $bugsys->userinfo['permissions'] = FetchUserPermissions($bugsys->userinfo);
181 $bugsys->userinfo['displaytitle'] = Bugdar::$datastore['usergroup'][ $bugsys->userinfo['usergroupid'] ]['displaytitle'];
182 $bugsys->userinfo['columnoptions'] = unserialize($bugsys->userinfo['columnoptions']);
183 }
184 else
185 {
186 $bugsys->userinfo = fetch_guest_user();
187 }
188 Bugdar::$user = $bugsys->userinfo;
189
190 // ###################################################################
191 // initialize localization system
192
193 $language = fetch_user_language();
194
195 $stylevar['lang'] = $language['langcode'];
196 $stylevar['lang_dir'] = $language['direction'];
197 $stylevar['charset'] = $language['charset'];
198 $stylevar['left'] = ($language['direction'] == 'ltr' ? 'left' : 'right');
199 $stylevar['right'] = ($language['direction'] == 'ltr' ? 'right' : 'left');
200
201 require_once('./includes/definitions.php');
202
203 // ###################################################################
204 // initialize the date system
205 $bugsys->load('date', 'datef', true);
206 $datef->usertz = $bugsys->userinfo['timezone'] + ($bugsys->userinfo['usedst'] * 1);
207 $bugsys->debug('user tz = ' . $bugsys->userinfo['timezone'] . '; use version = ' . $datef->usertz);
208 $datef->fetch_offset();
209
210 // ###################################################################
211 // mail system
212 $bugsys->load('mail', 'mail', true);
213 $mail->setFromAddress($bugsys->options['webmasteremail']);
214 $mail->setFromName(T('Bugdar Notification'));
215