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']) { $_GET['SQ'] = $sq; } else { $_POST['SQ'] = $sq; } } else { $sq =& $u->sq; } } // Prevent spiders from doing funny stuff. if (($u->users_opt & 1073741824) && $GLOBALS['is_post']) { // is_spider die('Bad bot!'); } /* 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'); } if ($u->data) { $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)) { $o2 ^= 32768; } /* Handle PM disabling for users. */ if (!($GLOBALS['is_a'] = $uo & 1048576) && $uo & 33554432) { $o1 = $o1 &~ 1024; } /* Set timezone. */ if (empty($u->time_zone) || @date_default_timezone_set($u->time_zone) === FALSE) { date_default_timezone_set($GLOBALS['SERVER_TZ']); } /* Set locale. */ $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; } $GLOBALS['sq'] = $sq; /* Define constants used to track URL sessions & referrals. */ if ($o1 & 128) { define('s', $u->ses_id); define('_hs', ''); if ($o2 & 8192) { if ($o2 & 32768) { define('_rsid', __fud_real_user__ .'/'. s .'/'); } else { define('_rsid', 'rid='. __fud_real_user__ .'&S='. s); } } else { if ($o2 & 32768) { define('_rsid', s .'/'); } else { define('_rsid', 'S='. s); } } } else { define('s', ''); define('_hs', ''); if ($o2 & 8192) { if ($o2 & 32768) { define('_rsid', __fud_real_user__ .'/'); } else { define('_rsid', 'rid='. __fud_real_user__); } } else { define('_rsid', ''); } } define('_rsidl', ($o2 & 32768 ? _rsid : str_replace('&', '&', _rsid))); return $u; } 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)'); return; } 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)'); return; } 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 (!$uid) { return 1; } if ($post && isset($_POST['SQ'])) { $s = $_POST['SQ']; } else if (!$post && isset($_GET['SQ'])) { $s = $_GET['SQ']; } else { $s = 0; } if ($sq !== $s) { if ($GLOBALS['t'] == 'post' || $GLOBALS['t'] == 'ppost') { define('fud_bad_sq', 1); $sq = regen_sq($uid); return 1; } header('Location: [[relativeurl]]/index.php?S='. $ses); exit; } return 1; } function regen_sq($uid=__fud_real_user__) { $sq = md5(get_random_value(128)); q('UPDATE fud30_users SET sq=\''. $sq .'\' WHERE id='. $uid); return $sq; } if (isset($_SERVER['REMOTE_ADDR']) && !defined('no_session')) { $GLOBALS['usr'] = init_user(); } ?>