root / branches / 1.2 / header.php

View | Annotate | Download (14.6 KB)

1
<?php
2
/**
3
 * $Id: header.php 522 2005-09-21 23:15:33Z eofredj $
4
[HEADER]
5
 */
6
error_reporting(E_ALL ^ E_NOTICE);
7
//error_reporting(E_ALL);
8
set_magic_quotes_runtime(0);
9
10
/* Some PHP Constants */
11
if(version_compare(phpversion(), '5', '<')) {
12
        define('__METHOD__', 'Unidentified Method (PHP < 5.0.0)');
13
        define('E_STRICT', 2048);
14
}
15
16
/* Some Oxygen Constants */
17
define('O2_VERSION', '[VERSION]');
18
define('DATA_VERSION', 2);
19
20
define('ICO_SMILEY', 0);
21
define('ICO_PICON', 1);
22
23
define('STATUS_ANONYMOUS', 0);
24
define('STATUS_BANNED', 1);
25
define('STATUS_WAITING', 2);
26
define('STATUS_MEMBER', 4);
27
define('STATUS_MODERATOR', 8);
28
define('STATUS_SUPER_MODERATOR', 16);
29
define('STATUS_ADMINISTRATOR', 32);
30
31
define('MAX_SUBJECT_LENGTH', 255);
32
33
define('O2_RIGHT', true);
34
35
if(!defined('O2_PATH')) {
36
        define('O2_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
37
}
38
39
define('CLASSES', O2_PATH . 'class/');
40
define('FILES', O2_PATH . 'files/');
41
define('TPLDIR', FILES . 'templates/');
42
43
define('O2_URL', ((isset($_SERVER['HTTPS']) && 0 == strcasecmp($_SERVER['HTTPS'], 'on'))? 'https://' : 'http://') . rtrim($_SERVER['HTTP_HOST'] . '/' . ltrim(dirname($_SERVER['PHP_SELF']), '/'), '/'));
44
45
if(file_exists(FILES . 'config/config.php')) {
46
        require(FILES . 'config/config.php');
47
}
48
49
/**
50
 * Oxygen seems not to be installed
51
 */
52
if(!defined('O2_SET') || !O2_SET) {
53
        header('Location: ' . O2_URL . '/install/setup.php');
54
        exit;
55
}
56
57
/**
58
 * Oxygen seems not to be the up to date version
59
 */
60
if(!defined('CFG_VERSION') || CFG_VERSION != O2_VERSION) {
61
        header('Location: ' . O2_URL . '/install/update.php');
62
        exit;
63
}
64
65
require_once(O2_PATH . 'include/dataprocess.inc.php');
66
require_once(O2_PATH . 'include/cacheprocess.inc.php');
67
require_once(O2_PATH . 'include/bbcode.inc.php');
68
require_once(O2_PATH . 'include/functions.inc.php');
69
require_once(O2_PATH . 'include/widget.inc.php');
70
require_once(O2_PATH . 'include/tblfunctions.inc.php');
71
require_once(O2_PATH . 'include/var_register.inc.php');
72
require_once(CLASSES . 'db.class.php');
73
require_once(CLASSES . 'templates.class.php');
74
require_once(CLASSES . 'widget.class.php');
75
require_once(CLASSES . 'mail.class.php');
76
require_once(CLASSES . 'messenger.class.php');
77
require_once(CLASSES . 'themeArray.class.php');
78
require_once(CLASSES . 'themeItem.class.php');
79
require_once(CLASSES . 'forumArray.class.php');
80
require_once(CLASSES . 'forumItem.class.php');
81
require_once(CLASSES . 'favorites.class.php');
82
require_once(CLASSES . 'timing.class.php');
83
require_once(CLASSES . 'bbcode.class.php');
84
require_once(CLASSES . 'geshi.class.php');
85
require_once(CLASSES . 'browser.class.php');
86
require_once(CLASSES . 'language.class.php');
87
require_once(CLASSES . 'session.class.php');
88
require_once(CLASSES . 'network.class.php');
89
90
/**
91
 * Configuration du Logger
92
 */
93
define('LOG4PHP_DIR', CLASSES . 'log4php/');
94
define('LOG4PHP_CONFIGURATION', O2_PATH . 'files/config/log4php.properties');
95
require_once(LOG4PHP_DIR . '/LoggerManager.php');
96
97
$logger =& LoggerManager::getLogger('main');
98
99
$now = time();
100
$timer = new exectime($now);
101
$browser = new browser();
102
103
$dategen = date('Ymd');
104
$dstoffset = (int) date('I');
105
$tempcache = array();
106
$o2cache = array();
107
$lang = array();
108
$trans = getdate($now);
109
$today = mktime(0, 0, 0, $trans['mon'], $trans['mday'], $trans['year']);
110
111
$logtime = 900;
112
$privuser = '';
113
$huser = array();
114
$headmsg = array();
115
$tagInline = array('b', 'bg', 'blink', 'color', 'font', 'i', 'size', 'strike', 'sub', 'sup', 'title', 'u');
116
$tagBlock = array('align', 'center', 'code', 'col', 'email', 'li', 'list', 'marquee', 'member', 'php', 'quote', 'row', 'spoiler', 'sql', 'stx', 'table', 'url');
117
118
list($usec, $sec) = explode(' ', microtime());
119
mt_srand((float) $sec + ((float) $usec * 100000));
120
121
$db =& db::getInstance($dbconfig);
122
if(false === $db->connect()) {
123
        $logger->fatal('Connection DB : failed');
124
        die('Connection DB : failed');
125
}
126
unset($dbconfig);
127
$db->debug(3);
128
$logger->info('Connection DB : successful');
129
130
$tpl =& new templater();
131
$tpl->assign_by_ref('db', $db);
132
133
$bbPool =& new bbcodePool();
134
$bbT =& new bbcodeTransformer($bbPool);
135
$tags = array_merge($tagBlock, $tagInline);
136
$bbT->handleTags($tags);
137
138
$bbTinline = new bbcodeTransformer($bbPool);
139
$tags = $tagInline;
140
$bbTinline->handleTags($tags);
141
$bbTinline->disableAutolink();
142
/*******************************************************************************
143
 * Récupération des paramètres de configuration généraux
144
 */
145
$rs = $db->query(sprintf('SELECT * FROM %s', $db->table('settings')), __FILE__, __LINE__);
146
while($setting = $rs->fetch_assoc()) {
147
        $settings[$setting['variable']] = $setting['value'];
148
}
149
$settings['now'] = $now;
150
$settings['logintime'] = 900;
151
$settings['boardurl'] = O2_URL;
152
$settings['reg_name_min_length'] = 3;
153
$settings['reg_name_max_length'] = 32;
154
$settings['reg_pw_min_length'] = 4;
155
$settings['sessiontype'] = 'native';
156
$settings['i18n']['langtype'] = 'phparray';
157
$settings['i18n']['defaultLocale'] = 'en';
158
$tpl->assign_by_ref('settings', $settings);
159
$lang =& language::getInstance($settings['i18n']);
160
$tpl->setLang($lang);
161
$lang->loadTranslationTable();
162
163
$tpl->addTitle($settings['bbname'], O2_URL);
164
165
if(!defined('NO_GZIP')) {
166
        if($settings['gzipcompress'] == 'yes' && strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
167
                $headmsg['gzipstatus'] = '| GZIP ';
168
                ob_start('ob_gzhandler');
169
        } else {
170
                ob_start();
171
        }
172
}
173
174
/*******************************************************************************
175
 * Ouverture de session
176
 */
177
$session =& session::factory($db, $settings);
178
$huser = $session->getUser($browser);
179
$session->cleaning();
180
$tpl->assign_by_ref('session', $session);
181
182
/**
183
 * Default values
184
 */
185
$time3600 = 3600 * (isset($huser['timeoffset']) ? (int) ($huser['timeoffset'] + $dstoffset) : (int) ($dstoffset + $settings['countryoffset']));
186
187
$visittodaylist = array();
188
if($settings['visittodaydate'] != $today) {
189
        $rs = $db->query(sprintf('SELECT uid, username, status FROM %s WHERE lastvisit>=%d ORDER BY lastvisit', $db->table('members'), $today), __FILE__, __LINE__);
190
        while($memberstoday = $rs->fetch_assoc()) {
191
                $memberstoday['uid'] = (int) $memberstoday['uid'];
192
                $memberstoday['status'] = (int) $memberstoday['status'];
193
                $visittodaylist[$memberstoday['uid']] =  $memberstoday;
194
        }
195
        $db->query(sprintf('UPDATE %s SET value=%s WHERE variable=%s', $db->table('settings'), $db->textFormat(serialize($visittodaylist)), $db->textFormat('visittodaylist')), __FILE__, __LINE__);
196
        $db->query(sprintf('UPDATE %s SET value=%s WHERE variable=%s', $db->table('settings'), $db->textFormat($today), $db->textFormat('visittodaydate')), __FILE__, __LINE__);
197
} else {
198
        $visittodaylist = unserialize($settings['visittodaylist']);
199
}
200
201
if(0 != $huser['uid'] && !isset($visittodaylist[$huser['uid']])) {
202
        $visittodaylist[$huser['uid']] = array('uid' => $huser['uid'], 'username' => $huser['username'], 'status' => $huser['status']);
203
        $db->query(sprintf('UPDATE %s SET value=%s WHERE variable=%s', $db->table('settings'), $db->textFormat(serialize($visittodaylist)), $db->textFormat('visittodaylist')), __FILE__, __LINE__);
204
}
205
206
$headmsg['sql_name'] = $db->rdbms;
207
$headmsg['sql_url'] = $db->url;
208
$headmsg['sql_version'] = $db->version();
209
$headmsg['php_version'] = phpversion();
210
$headmsg['zend_version'] = zend_version();
211
212
if($settings['regstatus'] == 'yes') {
213
        if($settings['coppa'] == 'yes') {
214
                $reglink = '<a href="member.php?action=coppa">' . $lang->getTranslation('textregister') . '</a>';
215
        } else {
216
                $reglink = '<a href="member.php?action=reg">' . $lang->getTranslation('textregister') . '</a>';
217
        }
218
}
219
220
$month_names = array(1 => $lang->getTranslation('timejan'), $lang->getTranslation('timefeb'), $lang->getTranslation('timemar'), $lang->getTranslation('timeapr'), $lang->getTranslation('timemay'), $lang->getTranslation('timejun'), $lang->getTranslation('timejul'), $lang->getTranslation('timeaug'), $lang->getTranslation('timesep'), $lang->getTranslation('timeoct'), $lang->getTranslation('timenov'), $lang->getTranslation('timedec'));
221
$day_names = array('&nbsp;', $lang->getTranslation('timemon'), $lang->getTranslation('timetue'), $lang->getTranslation('timewed'), $lang->getTranslation('timethu'), $lang->getTranslation('timefri'), $lang->getTranslation('timesat'), $lang->getTranslation('timesun'));
222
223
$timestamp = $now + $time3600;
224
225
if(0 != $huser['uid']) {
226
        $memcp = '<a href="memcp.php">' . $lang->getTranslation('textusercp') . '</a>';
227
        if(STATUS_ADMINISTRATOR === $huser['status']) {
228
                $cplink = ' - <a href="cp.php">' . $lang->getTranslation('textcp') . '</a>';
229
        }
230
        $headmsg['notify'] = $lang->getTranslation('loggedin') . ' [ <span class="loginas">' . $huser['username'] . '</span> ]<br/>[<a href="misc.php?action=logout">' . $lang->getTranslation('textlogout') . '</a>' . ' - ' . $memcp  . $cplink . ']';
231
        $tpl->teval('oxygen_member', array('tplname' => 'oxygen_user'));
232
} else {
233
        $headmsg['notify'] = $lang->getTranslation('notloggedin') . ' [<a href="misc.php?action=login">' . $lang->getTranslation('textlogin') . '</a>' . ' - ' . $reglink . ']';
234
        $tpl->teval('oxygen_guest', array('tplname' => 'oxygen_user'));
235
}
236
237
/*******************************************************************************
238
 * Vérification du statut du forum
239
 */
240
if($settings['bbstatus'] == 'no' && STATUS_ADMINISTRATOR !== $huser['status'] && ($action != 'login' && $action != 'lostpw')) {
241
        // Cache Smilies
242
        smcwcache(true, false);
243
        $smilies = $o2cache['smilies'];
244
        if($smilies[0] > 0) {
245
                $bbT->addSmilies($smilies[1]);
246
        }
247
        $settings['bboffreason'] = $bbT->processHtml($settings['bboffreason']);
248
        $settings['bboffreason'] = $bbT->processWrap($settings['bboffreason']);
249
        message($lang->getTranslation('textbboffnote') . ' ' . $bbT->processTags($settings['bboffreason'], true));
250
        exit;
251
}
252
253
/*******************************************************************************
254
 * Lecture autorisée aux non inscrits ?
255
 */
256
if($settings['regviewonly'] == 'yes') {
257
        $allowedaction = array('reg' => 1, 'login' => 1, 'lostpw' => 1, 'coppa' => 1);
258
        if(STATUS_ANONYMOUS == $huser['status'] && !isset($allowedaction[$action])) {
259
                $message = "$lang[reggedonly] $reglink $lang[textor] <a href=\"misc.php?action=login\">$lang[textlogin]</a><br/>";
260
                message($message);
261
                exit;
262
        }
263
}
264
265
/*******************************************************************************
266
 * Vérification du statut du membre
267
 */
268
$ips = explode('.', $session->ip);
269
/*
270
$rs = $db->query(sprintf('SELECT id FROM %s WHERE (ip1=%d OR ip1=-1) AND (ip2=%d OR ip2=-1) AND (ip3=%d OR ip3=-1) AND (ip4=%d OR ip4=-1)', $db->table('banned'), $ips[0], $ips[1], $ips[2], $ips[3]), __FILE__, __LINE__);
271
$result = $rs->fetch_assoc();
272
*/
273
if(STATUS_BANNED === $huser['status'] || ($result && STATUS_ADMINISTRATOR !== $huser['status'])) {
274
        if($huser['uid']) {
275
                redirect('index.php');
276
                logout();
277
        } else {
278
                message($lang->getTranslation('bannedmessage'));
279
        }
280
        exit;
281
}
282
283
/*******************************************************************************
284
 * Gestion des plugins simples
285
 */
286
$headmsg['pluglink'] = pluglink('no');
287
288
/*******************************************************************************
289
 * Récupère les nouvelles à afficher
290
 */
291
/*
292
$newslist = array();
293
$rs = $db->query(sprintf('SELECT nid, author, dateline, subject FROM %s WHERE timestart < %2$d AND timeend > %2$d ORDER BY dateline DESC', $db->table('news'), $now), __FILE__, __LINE__);
294
if($rs->num_rows() > 0) {
295
        while($news = $rs->fetch_assoc()) {
296
                $news['date'] = datecvt($news['dateline']);
297
                $thisbg = 'altbg' . (($j++ % 2) + 1);
298
                $news['subject'] = $bbTinline->processHtml($news['subject']);
299
                $news['subject'] = $bbTinline->processTags($news['subject']);
300
                $newslist[] = $news;
301
        }
302
        $tpl->assign('newslist', $newslist);
303
        $tpl->teval('oxygen_news');
304
}
305
*/
306
/*******************************************************************************
307
 * Vérifie la présence de message privés non lus.
308
 */
309
if(0 !== $huser['uid'] && 0 !== $huser['msn_new_msg']) {
310
        $headmsg['new_msn_msg_popup'] = sprintf($lang->getTranslation('msn_new_unread'), $huser['msn_new_msg']);
311
        if($huser['msn_popup'] && 1 == $huser['msn_popup_new']) {
312
                $headmsg['onload'] = "msn_popup({$huser['msn_new_msg']}); ";
313
                $db->query(sprintf('UPDATE %s SET msn_popup_new=0 WHERE uid=%d', $db->table('members'), $huser['uid']), __FILE__, __LINE__);
314
        }
315
        $huser['msn_new_msg_display'] = sprintf('<span class="msnnew">%d</span>', $huser['msn_new_msg']);
316
}
317
318
if(isset($headmsg['onload'])) {
319
        $headmsg['onload'] = ' onload="' . $headmsg['onload'] . '"';
320
}
321
322
/*******************************************************************************
323
 * Prépare les thèmes
324
 */
325
$themes = new themeArray($db);
326
if(false === ($themeItem = $themes->getThemeById($huser['theme_id']))) {
327
        $themeItem = $themes->getThemeById($settings['theme_id']);
328
}
329
$themeItem->setJS('js/oxygen.js');
330
$tpl->setTheme($themeItem);
331
332
/*******************************************************************************
333
 * Prépare le quickjump
334
 */
335
$forums = new forumArray($db, $huser);
336
$forumarray = array();
337
foreach($forums->getAllowedList() as $forumItem) {
338
        $forum = $forumItem->getRawdata();
339
        $forumarray[] = array('fid' => $forumItem->getProperty('fid'), 'offsetname' => $forumItem->getProperty('offset') . $forumItem->getProperty('name'), 'style' => $forumItem->getProperty('style'));
340
}
341
342
$fid = empty($_REQUEST['fid']) ? 0 : (int) $_REQUEST['fid'];
343
$action = empty($_REQUEST['action']) ? '' : preg_replace('`[^[:alnum:]]`', '', $_REQUEST['action']);
344
345
$pop = new wdgPopup('quickjump');
346
$pop->setBlank($lang->getTranslation('quickjump'), 0);
347
$pop->setKeyName('fid');
348
$pop->setValueName('offsetname');
349
$pop->setStyleName('style');
350
$pop->setRawAttr('onchange="redirlocate(this, \'index.php?fid=\');"');
351
$pop->setValues($forumarray);
352
$pop->selected = $fid;
353
$headmsg['quickjump'] = $pop->render();
354
355
$tpl->assign('headmsg', $headmsg);
356
357
/*******************************************************************************
358
 * Start Stats Visitors
359
 */
360
if('yes' === $settings['agentstatsstatus']) {
361
        $o2stats_ref = getcookie('stats_ref');
362
        $useragent = $_SERVER['HTTP_USER_AGENT'];
363
        if($o2stats_ref !== md5($dategen . $useragent)) {
364
                include('include/agents.inc.php');
365
                if(isset($browser) || isset($os)) {
366
                        $db->query(sprintf('UPDATE %s SET count = count + 1, time=%d, complete=%s WHERE type=%s AND name=%s',
367
                                $db->table('stats'),
368
                                $now,
369
                                $db->textFormat($useragent),
370
                                $db->textFormat('browser'),
371
                                $db->textFormat($browser)), __FILE__, __LINE__);
372
                        $db->query(sprintf('UPDATE %s SET count = count + 1, time=%d, complete=%s WHERE type=%s AND name=%s',
373
                                $db->table('stats'),
374
                                $now,
375
                                $db->textFormat($useragent),
376
                                $db->textFormat('os'),
377
                                $db->textFormat($os)), __FILE__, __LINE__);
378
                        o2cookie('stats_ref', md5($dategen . $useragent), NULL);
379
                } else if(isset($bot)) {
380
                        $db->query(sprintf('UPDATE %s SET count = count + 1, time=%d, complete=%s WHERE type=%s AND name=%s',
381
                                $db->table('stats'),
382
                                $now,
383
                                $db->textFormat($useragent),
384
                                $db->textFormat('bot'),
385
                                $db->textFormat($bot)), __FILE__, __LINE__);
386
                }
387
        }
388
        include 'include/referer.inc.php';
389
}
390
391
?>