forked from wodim/fearqdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
120 lines (103 loc) · 3.6 KB
/
init.php
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
<?php
/*
fearqdb - quote database system
Copyright (C) 2011-2012 David Martí <neikokz at gmail dot com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require('config.php');
if (file_exists('local.php')) {
require('local.php');
}
define('include_dir', 'include/');
define('modules_dir', 'modules/');
define('classes_dir', 'classes/');
require(include_dir.'utils.php');
require(include_dir.'defines.php');
/* initialise db */
require(classes_dir.'db.php');
$db = new DB();
$db->type = $config['db']['type'];
$db->debug = $config['db']['debug'];
$db->persistent = $config['db']['persistent'];
$db->file = $config['db']['file'];
$db->user = $config['db']['user'];
$db->pass = $config['db']['pass'];
$db->name = $config['db']['name'];
$db->socket = $config['db']['socket'];
$db->host = $config['db']['host'];
if (!$db->init()) {
header('HTTP/1.1 500 Internal Server Error');
die('DBE');
}
/* read settings, determine virtual host */
require(classes_dir.'settings.php');
$settings = new Settings();
if (!$settings->init() &&
!preg_match('/^\/_\//', $_SERVER['REQUEST_URI'])) {
header('HTTP/1.1 500 Internal Server Error');
die('VHE');
}
/* initialise memcache */
require(classes_dir.'memcache.php');
$memcache = new Memcache();
$memcache->enabled = $config['memcache']['enabled'];
$memcache->server = $config['memcache']['server'];
$memcache->port = $config['memcache']['port'];
$memcache->prefix = $config['memcache']['prefix'] ? $config['memcache']['prefix'] : 'fearqdb';
$memcache->debug = $config['memcache']['debug'];
$memcache->init();
/* encoding */
if ($db->type == 'mysql') {
$db->query(sprintf('SET NAMES utf8 COLLATE %s', $settings->collate));
}
mb_internal_encoding('utf8');
// initialize Haanga
require(include_dir.'Haanga.php');
Haanga::configure(array(
'template_dir' => 'templates/',
'cache_dir' => 'templates/compiled/',
'compiler' => array(
'global' => array('settings', 'session'),
'strip_whitespace' => true,
'allow_exec' => false,
'autoescape' => false
)
));
// initialize the html engine
require(classes_dir.'html.php');
$html = new HTML();
// initiailze session
require(classes_dir.'session.php');
$session = new Session();
$session->init();
// initialize push engine
require(classes_dir.'push.php');
$push = new Push();
$push->init();
// configure gettext's locale
putenv('LC_ALL='.$settings->locale);
setlocale(LC_ALL, $settings->locale);
bindtextdomain('messages', './locale');
textdomain('messages');
// redir to /login if not in ^/login already
if (!is_bot() && ($settings->privacy_level == 2
&& $session->level == 'anonymous'
&& !preg_match(sprintf('/^%s(login|api|userlogin|_)/', preg_quote($settings->base_url, '/')), $_SERVER['REQUEST_URI']))) {
$html->do_sysmsg(_('Log in'), _('You must log in to read any quote.'), 403);
}
/* make privacy_level_for_bots effective */
if (is_bot()
&& $settings->privacy_level_for_bots == 2
&& !preg_match(sprintf('/^%s(rss|robots\.txt)/', preg_quote($settings->base_url, '/')), $_SERVER['REQUEST_URI'])) {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden'); /* so what */
}