diff -r e3d7322305bf -r 5e1f1e916419 punbb/include/functions.php --- a/punbb/include/functions.php Sun Sep 02 11:00:57 2007 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1097 +0,0 @@ -started) - $session->start(); - - if($session->user_logged_in) - { - $result = $pun_db->query( - 'SELECT eu.*, u.*, eu.real_name AS realname, g.*, eu.user_level AS g_id, o.logged, o.idle - FROM '.$pun_db->prefix.'users AS u - LEFT JOIN '.table_prefix.'users AS eu - ON eu.user_id=u.id - INNER JOIN '.$pun_db->prefix.'groups AS g - ON u.group_id=g.g_id - LEFT JOIN '.$pun_db->prefix.'online AS o - ON o.user_id=u.id - WHERE u.id='.intval($session->user_id)) - or error('Unable to fetch user information', __FILE__, __LINE__, $pun_db->error()); - $pun_user = $pun_db->fetch_assoc($result); - // Set a default language if the user selected language no longer exists - if (!@file_exists(PUN_ROOT.'lang/'.$pun_user['language'])) - $pun_user['language'] = $pun_config['o_default_lang']; - - // Set a default style if the user selected style no longer exists - // if (!@file_exists(PUN_ROOT.'style/'.$pun_user['style'].'.css')) - // $pun_user['style'] = $pun_config['o_default_style']; - - if (!$pun_user['disp_topics']) - $pun_user['disp_topics'] = $pun_config['o_disp_topics_default']; - if (!$pun_user['disp_posts']) - $pun_user['disp_posts'] = $pun_config['o_disp_posts_default']; - - if ($pun_user['save_pass'] == '0') - $expire = 0; - - // Define this if you want this visit to affect the online list and the users last visit data - if (!defined('PUN_QUIET_VISIT')) - { - // Update the online list - if (!$pun_user['logged']) - $pun_db->query('INSERT INTO '.$pun_db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$pun_db->escape($pun_user['username']).'\', '.$now.')') or error('Unable to insert into online list', __FILE__, __LINE__, $pun_db->error()); - else - { - // Special case: We've timed out, but no other user has browsed the forums since we timed out - if ($pun_user['logged'] < ($now-$pun_config['o_timeout_visit'])) - { - $pun_db->query('UPDATE '.$pun_db->prefix.'users SET last_visit='.$pun_user['logged'].' WHERE id='.$pun_user['id']) or error('Unable to update user visit data', __FILE__, __LINE__, $pun_db->error()); - $pun_user['last_visit'] = $pun_user['logged']; - } - - $idle_sql = ($pun_user['idle'] == '1') ? ', idle=0' : ''; - $pun_db->query('UPDATE '.$pun_db->prefix.'online SET logged='.$now.$idle_sql.' WHERE user_id='.$pun_user['id']) or error('Unable to update online list', __FILE__, __LINE__, $pun_db->error()); - } - } - - $pun_user['is_guest'] = false; - } - else - { - set_default_user(); - } -} - - -// -// Fill $pun_user with default values (for guests) -// -function set_default_user() -{ - global $pun_db, $pun_user, $pun_config; - - $remote_addr = get_remote_address(); - - // Fetch guest user - $result = $pun_db->query('SELECT u.*, g.*, o.logged FROM '.$pun_db->prefix.'users AS u INNER JOIN '.$pun_db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$pun_db->prefix.'online AS o ON o.ident=\''.$remote_addr.'\' WHERE u.id=1') or error('Unable to fetch guest information', __FILE__, __LINE__, $pun_db->error()); - if (!$pun_db->num_rows($result)) - exit('Unable to fetch guest information. The table \''.$pun_db->prefix.'users\' must contain an entry with id = 1 that represents anonymous users.'); - - $pun_user = $pun_db->fetch_assoc($result); - - // Update online list - if (!$pun_user['logged']) - $pun_db->query('INSERT INTO '.$pun_db->prefix.'online (user_id, ident, logged) VALUES(1, \''.$pun_db->escape($remote_addr).'\', '.time().')') or error('Unable to insert into online list', __FILE__, __LINE__, $pun_db->error()); - else - $pun_db->query('UPDATE '.$pun_db->prefix.'online SET logged='.time().' WHERE ident=\''.$pun_db->escape($remote_addr).'\'') or error('Unable to update online list', __FILE__, __LINE__, $pun_db->error()); - - $pun_user['disp_topics'] = $pun_config['o_disp_topics_default']; - $pun_user['disp_posts'] = $pun_config['o_disp_posts_default']; - $pun_user['timezone'] = $pun_config['o_server_timezone']; - $pun_user['language'] = $pun_config['o_default_lang']; - $pun_user['style'] = $pun_config['o_default_style']; - $pun_user['is_guest'] = true; -} - - -// -// Set a cookie, PunBB style! -// -function pun_setcookie($user_id, $password_hash, $expire) -{ - global $cookie_name, $cookie_path, $cookie_domain, $cookie_secure, $cookie_seed; - - // Enable sending of a P3P header by removing // from the following line (try this if login is failing in IE6) -// @header('P3P: CP="CUR ADM"'); - - if (version_compare(PHP_VERSION, '5.2.0', '>=')) - setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$password_hash))), $expire, $cookie_path, $cookie_domain, $cookie_secure, true); - else - setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$password_hash))), $expire, $cookie_path.'; HttpOnly', $cookie_domain, $cookie_secure); -} - - -// -// Check whether the connecting user is banned (and delete any expired bans while we're at it) -// -function check_bans() -{ - global $pun_db, $pun_config, $lang_common, $pun_user, $pun_bans; - - // Admins aren't affected - if ($pun_user['g_id'] == PUN_ADMIN || !$pun_bans) - return; - - // Add a dot at the end of the IP address to prevent banned address 192.168.0.5 from matching e.g. 192.168.0.50 - $user_ip = get_remote_address().'.'; - $bans_altered = false; - - foreach ($pun_bans as $cur_ban) - { - // Has this ban expired? - if ($cur_ban['expire'] != '' && $cur_ban['expire'] <= time()) - { - $pun_db->query('DELETE FROM '.$pun_db->prefix.'bans WHERE id='.$cur_ban['id']) or error('Unable to delete expired ban', __FILE__, __LINE__, $pun_db->error()); - $bans_altered = true; - continue; - } - - if ($cur_ban['username'] != '' && !strcasecmp($pun_user['username'], $cur_ban['username'])) - { - $pun_db->query('DELETE FROM '.$pun_db->prefix.'online WHERE ident=\''.$pun_db->escape($pun_user['username']).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $pun_db->error()); - message($lang_common['Ban message'].' '.(($cur_ban['expire'] != '') ? $lang_common['Ban message 2'].' '.strtolower(format_time($cur_ban['expire'], true)).'. ' : '').(($cur_ban['message'] != '') ? $lang_common['Ban message 3'].'

'.pun_htmlspecialchars($cur_ban['message']).'

' : '

').$lang_common['Ban message 4'].' '.$pun_config['o_admin_email'].'.', true); - } - - if ($cur_ban['ip'] != '') - { - $cur_ban_ips = explode(' ', $cur_ban['ip']); - - for ($i = 0; $i < count($cur_ban_ips); ++$i) - { - $cur_ban_ips[$i] = $cur_ban_ips[$i].'.'; - - if (substr($user_ip, 0, strlen($cur_ban_ips[$i])) == $cur_ban_ips[$i]) - { - $pun_db->query('DELETE FROM '.$pun_db->prefix.'online WHERE ident=\''.$pun_db->escape($pun_user['username']).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $pun_db->error()); - message($lang_common['Ban message'].' '.(($cur_ban['expire'] != '') ? $lang_common['Ban message 2'].' '.strtolower(format_time($cur_ban['expire'], true)).'. ' : '').(($cur_ban['message'] != '') ? $lang_common['Ban message 3'].'

'.pun_htmlspecialchars($cur_ban['message']).'

' : '

').$lang_common['Ban message 4'].' '.$pun_config['o_admin_email'].'.', true); - } - } - } - } - - // If we removed any expired bans during our run-through, we need to regenerate the bans cache - if ($bans_altered) - { - require_once PUN_ROOT.'include/cache.php'; - generate_bans_cache(); - } -} - - -// -// Update "Users online" -// -function update_users_online() -{ - global $pun_db, $pun_config, $pun_user; - - $now = time(); - - // Fetch all online list entries that are older than "o_timeout_online" - $result = $pun_db->query('SELECT * FROM '.$pun_db->prefix.'online WHERE logged<'.($now-$pun_config['o_timeout_online'])) or error('Unable to fetch old entries from online list', __FILE__, __LINE__, $pun_db->error()); - while ($cur_user = $pun_db->fetch_assoc($result)) - { - // If the entry is a guest, delete it - if ($cur_user['user_id'] == '1') - $pun_db->query('DELETE FROM '.$pun_db->prefix.'online WHERE ident=\''.$pun_db->escape($cur_user['ident']).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $pun_db->error()); - else - { - // If the entry is older than "o_timeout_visit", update last_visit for the user in question, then delete him/her from the online list - if ($cur_user['logged'] < ($now-$pun_config['o_timeout_visit'])) - { - $pun_db->query('UPDATE '.$pun_db->prefix.'users SET last_visit='.$cur_user['logged'].' WHERE id='.$cur_user['user_id']) or error('Unable to update user visit data', __FILE__, __LINE__, $pun_db->error()); - $pun_db->query('DELETE FROM '.$pun_db->prefix.'online WHERE user_id='.$cur_user['user_id']) or error('Unable to delete from online list', __FILE__, __LINE__, $pun_db->error()); - } - else if ($cur_user['idle'] == '0') - $pun_db->query('UPDATE '.$pun_db->prefix.'online SET idle=1 WHERE user_id='.$cur_user['user_id']) or error('Unable to insert into online list', __FILE__, __LINE__, $pun_db->error()); - } - } -} - -// -// Generate the "navigator" that appears at the top of every page -// -function generate_navlinks() -{ - global $pun_config, $lang_common, $pun_user; - global $db, $session, $paths, $template, $plugins; // Common objects - - // Index and Userlist should always be displayed - $links[] = '