$_GET['t'] = 'avatarsel';
$_GET[$p[++$i]] = $p[++$i];
$_GET['t'] = 'pmuserloc';
$_GET['js_redr'] = $p[1];
$_GET['email'] = urldecode($p[1]);
$_GET['t'] = 'coppa_fax';
$_GET['rng'] = isset($p[1]) ? $p[1] : 0;
$_GET['rng2'] = isset($p[2]) ? $p[2] : 0;
$_GET['u'] = isset($p[3]) ? $p[3] : 0;
$_GET['start'] = isset($p[4]) ? $p[4] : 0;
$_GET['sub'] = !empty($p[5]);
$_GET[($p[1][0] == 'i' ? 'ip' : 'user')] = isset($p[2]) ? $p[2] : '';
if (isset($p[1], $p[2])) {
case 'cal': /* Calendar */
if ($p[1] == 'u' && isset($p[2])) {
$_GET['start'] = isset($p[3]) ? $p[3] : 0;
if ($p[1] == 'f' && isset($p[2])) {
$_GET['start'] = isset($p[3]) ? $p[3] : 0;
case 'page': /* Static page */
// Page not specified, redirect to front page.
$GLOBALS['t'] = $_GET['t'];
} else if (isset($_GET['t'])) {
$GLOBALS['t'] = (string) $_GET['t'];
} else if (isset($_POST['t'])) {
$GLOBALS['t'] = (string) $_POST['t'];
if ($GLOBALS['t'] == 'register') {
$GLOBALS['THREADS_PER_PAGE_F'] = $GLOBALS['THREADS_PER_PAGE']; // Store old value.
header('P3P: CP="ALL CUR OUR IND UNI ONL INT CNT STA"'); /* P3P Policy. */
/* Fetch an object with the user's session, profile & theme info. */
if (!($u = ses_get()) && defined('plugins')) {
/* Call auto-login plugins. */
$u = plugin_call_hook('AUTO_LOGIN');
} else if ($u->id != 1 && (!$GLOBALS['is_post'] || sq_check(1, $u->sq, $u->id, $u->ses_id))) {
/* Store the last visit date for registered user. */
q('UPDATE fud30_users SET last_visit='. __request_timestamp__ .' WHERE id='. $u->id);
if ($GLOBALS['FUD_OPT_3'] & 1) { // SESSION_COOKIES
setcookie($GLOBALS['COOKIE_NAME'], $u->ses_id, 0, $GLOBALS['COOKIE_PATH'], $GLOBALS['COOKIE_DOMAIN']);
if (!$u->sq || __request_timestamp__ - $u->last_visit > 180) { // 3 min.
$u->sq = $sq = regen_sq($u->id);
if (!$GLOBALS['is_post']) {
// Prevent spiders from doing funny stuff.
if (($u->users_opt & 1073741824) && $GLOBALS['is_post']) { // is_spider
/* Disable caching for registered users and POST requests. */
if ($GLOBALS['is_post'] || $u->id > 1) {
header('Cache-Control: no-store, private, must-revalidate, proxy-revalidate, post-check=0, pre-check=0, max-age=0, s-maxage=0');
header('Expires: Mon, 21 Jan 1980 06:01:01 GMT');
header('Pragma: no-cache');
$u->data = unserialize($u->data);
$uo = $u->users_opt = (int)$u->users_opt;
/* This should allow path_info & normal themes to work properly within 1 forum. */
if ($o2 & 32768 && !($u->theme_opt & 4)) {
/* Handle PM disabling for users. */
if (!($GLOBALS['is_a'] = $uo & 1048576) && $uo & 33554432) {
if (empty($u->time_zone) || @date_default_timezone_set($u->time_zone) === FALSE) {
date_default_timezone_set($GLOBALS['SERVER_TZ']);
$GLOBALS['good_locale'] = setlocale(LC_ALL, $u->locale);
/* Call inituser plugins. */
if (defined('plugins')) {
plugin_call_hook('INITUSER', $u);
/* View format for threads & messages. */
define('d_thread_view', $uo & 256 ? 'msg' : 'tree');
define('t_thread_view', $uo & 128 ? 'thread' : 'threadt');
if ($GLOBALS['t'] === 0) {
$GLOBALS['t'] = $_GET['t'] = d_thread_view;
} else if ($GLOBALS['t'] === 1) {
$GLOBALS['t'] = $_GET['t'] = t_thread_view;
/* Define theme path, may already be set by a plugin. */
defined('fud_theme') or define('fud_theme', 'theme/'. ($u->theme_name ? $u->theme_name : 'default') .'/');
/* Define _uid, which, will tell us if this is a 'real' user or not. */
define('__fud_real_user__', ($u->id != 1 ? $u->id : 0));
define('_uid', __fud_real_user__ && ($uo & 131072) && !($uo & 2097152) ? $u->id : 0);
/* Allow user to set their own topics per page value, as long as it is smaller then the max. */
if (__fud_real_user__ && $GLOBALS['THREADS_PER_PAGE'] > $u->topics_per_page) {
$GLOBALS['THREADS_PER_PAGE'] = (int) $u->topics_per_page;
/* Define constants used to track URL sessions & referrals. */
define('s', $u->ses_id); define('_hs', '<input type="hidden" name="S" value="'. s .'" /><input type="hidden" name="SQ" value="'. $sq .'" />');
define('_rsid', __fud_real_user__ .'/'. s .'/');
define('_rsid', 'rid='. __fud_real_user__ .'&S='. s);
define('_rsid', 'S='. s);
define('s', ''); define('_hs', '<input type="hidden" name="SQ" value="'. $sq .'" />');
define('_rsid', __fud_real_user__ .'/');
define('_rsid', 'rid='. __fud_real_user__);
define('_rsidl', ($o2 & 32768 ? _rsid : str_replace('&', '&', _rsid)));
function user_register_forum_view($frm_id)
if (__dbtype__ == 'mysql') { // MySQL optimization.
q('INSERT INTO fud30_forum_read (forum_id, user_id, last_view) VALUES ('. $frm_id .', '. _uid .', '. __request_timestamp__ .') ON DUPLICATE KEY UPDATE last_view=VALUES(last_view)');
if (!db_li('INSERT INTO fud30_forum_read (forum_id, user_id, last_view) VALUES ('. $frm_id .', '. _uid .', '. __request_timestamp__ .')', $ef)) {
q('UPDATE fud30_forum_read SET last_view='. __request_timestamp__ .' WHERE forum_id='. $frm_id .' AND user_id='. _uid);
function user_register_thread_view($thread_id, $tm=__request_timestamp__, $msg_id=0)
if (__dbtype__ == 'mysql') { // MySQL optimization.
q('INSERT INTO fud30_read (last_view, msg_id, thread_id, user_id) VALUES('. $tm .', '. $msg_id .', '. $thread_id .', '. _uid .') ON DUPLICATE KEY UPDATE last_view=VALUES(last_view), msg_id=VALUES(msg_id)');
if (!db_li('INSERT INTO fud30_read (last_view, msg_id, thread_id, user_id) VALUES('. $tm .', '. $msg_id .', '. $thread_id .', '. _uid .')', $ef)) {
q('UPDATE fud30_read SET last_view='. $tm .', msg_id='. $msg_id .' WHERE thread_id='. $thread_id .' AND user_id='. _uid);
function user_set_post_count($uid)
$pd = db_saq('SELECT MAX(id), count(*) FROM fud30_msg WHERE poster_id='. $uid .' AND apr=1');
$level_id = (int) q_singleval(q_limit('SELECT id FROM fud30_level WHERE post_count <= '. $pd[1] .' ORDER BY post_count DESC', 1));
q('UPDATE fud30_users SET u_last_post_id='. (int)$pd[0] .', posted_msg_count='. (int)$pd[1] .', level_id='. $level_id .' WHERE id='. $uid);
function user_mark_all_read($id)
q('UPDATE fud30_users SET last_read='. __request_timestamp__ .' WHERE id='. $id);
q('DELETE FROM fud30_read WHERE user_id='. $id);
q('DELETE FROM fud30_forum_read WHERE user_id='. $id);
function user_mark_forum_read($id, $fid, $last_view)
if (__dbtype__ == 'mysql') { // MySQL optimization.
q('INSERT INTO fud30_read (user_id, thread_id, msg_id, last_view) SELECT '. $id .', id, last_post_id, '. __request_timestamp__ .' FROM fud30_thread WHERE forum_id='. $fid .' AND last_post_date > '. $last_view .' ON DUPLICATE KEY UPDATE last_view=VALUES(last_view), msg_id=VALUES(msg_id)');
} else if (__dbtype__ == 'sqlite') { // SQLite optimization.
q('REPLACE INTO fud30_read (user_id, thread_id, msg_id, last_view) SELECT '. $id .', id, last_post_id, '. __request_timestamp__ .' FROM fud30_thread WHERE forum_id='. $fid .' AND last_post_date > '. $last_view);
} else { // Other databases.
if (!db_li('INSERT INTO fud30_read (user_id, thread_id, msg_id, last_view) SELECT '. $id .', id, last_post_id, '. __request_timestamp__ .' FROM fud30_thread WHERE forum_id='. $fid .' AND last_post_date > '. $last_view, $ef)) {
q('UPDATE fud30_read SET user_id='. $id .', msg_id=t.last_post_id, last_view='. __request_timestamp__ .' FROM (SELECT id, last_post_id FROM fud30_thread WHERE forum_id='. $fid .' AND last_post_date > '. $last_view .') t WHERE user_id='. $id .' AND thread_id=t.id');
user_register_forum_view($fid);
function sq_check($post, &$sq, $uid=__fud_real_user__, $ses=s)
/* No sequence # check for anonymous users. */
if ($post && isset($_POST['SQ'])) {
} else if (!$post && isset($_GET['SQ'])) {
if ($GLOBALS['t'] == 'post' || $GLOBALS['t'] == 'ppost') {
header('Location: [[relativeurl]]/index.php?S='. $ses);
function regen_sq($uid=__fud_real_user__)
$sq = md5(get_random_value(128));
q('UPDATE fud30_users SET sq=\''. $sq .'\' WHERE id='. $uid);
if (isset($_SERVER['REMOTE_ADDR']) && !defined('no_session')) {
$GLOBALS['usr'] = init_user();
/* BUST_A_PUNK enabled. */
if ($FUD_OPT_2 & 524288 && isset($_COOKIE[$COOKIE_NAME .'1']) && $t != 'error') {
/* Check PHP_COMPRESSION_ENABLE. */
if ($FUD_OPT_2 & 16384 && $t != 'getfile') {
ini_set('zlib.output_compression_level', (int)$PHP_COMPRESSION_LEVEL);
ob_start('ob_gzhandler');
if (isset($_GET['th']) || isset($_GET['goto'])) {
$t = $_GET['t'] = d_thread_view;
} else if (isset($_GET['frm_id'])) {
$t = $_GET['t'] = t_thread_view;
$t = $_GET['t'] = 'index';
} else if (preg_match('/[^a-z_]/', $t) || !@file_exists($WWW_ROOT_DISK . fud_theme . $t .'.php')) {
// Page not found, redirect to front page.
/* Call themed template. */
if (defined('plugins')) {
$t = plugin_call_hook('PRE_TEMPLATE', $t);
if (isset($plugin_hooks['POST_TEMPLATE'])) {
ob_start(); // Start capturing output for POST_TEMPLATE plugins.
require($WWW_ROOT_DISK . fud_theme .'language.inc'); // Initialize theme's language helper functions.
require($WWW_ROOT_DISK . fud_theme . $t .'.php');
if (defined('plugins') && isset($plugin_hooks['POST_TEMPLATE'])) {
$template_data = ob_get_contents();
echo plugin_call_hook('POST_TEMPLATE', $template_data);
while (ob_get_level() > 0) ob_end_flush(); // Flush all output to browser.
if (!isset($_GET['prevloaded'])) {
th_inc_view_count($frm->id);
if ($frm->last_forum_view < $obj2->post_stamp) {
user_register_forum_view($frm->forum_id);
if ($frm->last_view < $obj2->post_stamp) {
user_register_thread_view($frm->id, $obj2->post_stamp, $obj2->id);
th_inc_view_count($msg_obj->thread_id);
if ($frm->last_forum_view < $msg_obj->post_stamp) {
user_register_forum_view($msg_obj->forum_id);
if ($frm->last_view < $msg_obj->post_stamp) {
user_register_thread_view($msg_obj->thread_id, $msg_obj->post_stamp, $msg_obj->id);
/* Clear expired sessions AND anonymous sessions older than 1 day. */
q('DELETE FROM fud30_ses WHERE time_sec<'. (__request_timestamp__- ($FUD_OPT_3 & 1 ? $SESSION_TIMEOUT : $COOKIE_TIMEOUT)) .' OR (user_id>2000000000 AND time_sec<'. (__request_timestamp__- 86400) .')');
user_register_forum_view($frm_id);