diff -r 8f6143115bf5 -r a8a21e1c7afa punbb/include/functions.php --- a/punbb/include/functions.php Wed Jul 11 21:28:39 2007 -0400 +++ b/punbb/include/functions.php Thu Jul 12 01:04:01 2007 -0400 @@ -27,40 +27,38 @@ // function check_cookie(&$pun_user) { - global $db, $db_type, $pun_config, $cookie_name, $cookie_seed; - - $now = time(); - $expire = $now + 31536000; // The cookie expires after a year - - // We assume it's a guest - $cookie = array('user_id' => 1, 'password_hash' => 'Guest'); - - // If a cookie is set, we get the user_id and password hash from it - if (isset($_COOKIE[$cookie_name])) - list($cookie['user_id'], $cookie['password_hash']) = @unserialize($_COOKIE[$cookie_name]); - - if ($cookie['user_id'] > 1) - { - // Check if there's a user with the user ID and password hash from the cookie - $result = $db->query('SELECT u.*, g.*, o.logged, o.idle FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$db->prefix.'online AS o ON o.user_id=u.id WHERE u.id='.intval($cookie['user_id'])) or error('Unable to fetch user information', __FILE__, __LINE__, $db->error()); - $pun_user = $db->fetch_assoc($result); - - // If user authorisation failed - if (!isset($pun_user['id']) || md5($cookie_seed.$pun_user['password']) !== $cookie['password_hash']) - { - pun_setcookie(0, random_pass(8), $expire); - set_default_user(); - - return; - } - - // Set a default language if the user selected language no longer exists + // Import Enano + global $db, $session, $paths, $template, $plugins; // Common objects + + // Import PunBB + global $pun_db, $db_type, $pun_config, $cookie_name, $cookie_seed; + + $now = time(); + + if(!$session->started) + $session->start(); + + if($session->user_logged_in) + { + $result = $pun_db->query( + 'SELECT eu.*, u.*, eu.real_name AS realname, eu.user_level AS g_id, g.*, 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 (!@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']; @@ -75,40 +73,27 @@ { // Update the online list if (!$pun_user['logged']) - { - $pun_user['logged'] = $now; - - // With MySQL/MySQLi, REPLACE INTO avoids a user having two rows in the online table - switch ($db_type) - { - case 'mysql': - case 'mysqli': - $db->query('REPLACE INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$pun_user['logged'].')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error()); - break; - - default: - $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$pun_user['logged'].')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error()); - break; - } - } + $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'])) { - $db->query('UPDATE '.$db->prefix.'users SET last_visit='.$pun_user['logged'].' WHERE id='.$pun_user['id']) or error('Unable to update user visit data', __FILE__, __LINE__, $db->error()); + $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' : ''; - $db->query('UPDATE '.$db->prefix.'online SET logged='.$now.$idle_sql.' WHERE user_id='.$pun_user['id']) or error('Unable to update online list', __FILE__, __LINE__, $db->error()); + $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(); + } + else + { + set_default_user(); + } } @@ -117,37 +102,22 @@ // function set_default_user() { - global $db, $db_type, $pun_user, $pun_config; + global $pun_db, $pun_user, $pun_config; $remote_addr = get_remote_address(); // Fetch guest user - $result = $db->query('SELECT u.*, g.*, o.logged FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$db->prefix.'online AS o ON o.ident=\''.$remote_addr.'\' WHERE u.id=1') or error('Unable to fetch guest information', __FILE__, __LINE__, $db->error()); - if (!$db->num_rows($result)) - exit('Unable to fetch guest information. The table \''.$db->prefix.'users\' must contain an entry with id = 1 that represents anonymous users.'); + $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 = $db->fetch_assoc($result); + $pun_user = $pun_db->fetch_assoc($result); // Update online list if (!$pun_user['logged']) - { - $pun_user['logged'] = time(); - - // With MySQL/MySQLi, REPLACE INTO avoids a user having two rows in the online table - switch ($db_type) - { - case 'mysql': - case 'mysqli': - $db->query('REPLACE INTO '.$db->prefix.'online (user_id, ident, logged) VALUES(1, \''.$db->escape($remote_addr).'\', '.$pun_user['logged'].')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error()); - break; - - default: - $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES(1, \''.$db->escape($remote_addr).'\', '.$pun_user['logged'].')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error()); - break; - } - } + $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 - $db->query('UPDATE '.$db->prefix.'online SET logged='.time().' WHERE ident=\''.$db->escape($remote_addr).'\'') or error('Unable to update online list', __FILE__, __LINE__, $db->error()); + $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']; @@ -180,7 +150,7 @@ // function check_bans() { - global $db, $pun_config, $lang_common, $pun_user, $pun_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) @@ -195,14 +165,14 @@ // Has this ban expired? if ($cur_ban['expire'] != '' && $cur_ban['expire'] <= time()) { - $db->query('DELETE FROM '.$db->prefix.'bans WHERE id='.$cur_ban['id']) or error('Unable to delete expired ban', __FILE__, __LINE__, $db->error()); + $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'])) { - $db->query('DELETE FROM '.$db->prefix.'online WHERE ident=\''.$db->escape($pun_user['username']).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $db->error()); + $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); } @@ -216,7 +186,7 @@ if (substr($user_ip, 0, strlen($cur_ban_ips[$i])) == $cur_ban_ips[$i]) { - $db->query('DELETE FROM '.$db->prefix.'online WHERE ident=\''.$db->escape($pun_user['username']).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $db->error()); + $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); } } @@ -237,32 +207,31 @@ // function update_users_online() { - global $db, $pun_config, $pun_user; + global $pun_db, $pun_config, $pun_user; $now = time(); // Fetch all online list entries that are older than "o_timeout_online" - $result = $db->query('SELECT * FROM '.$db->prefix.'online WHERE logged<'.($now-$pun_config['o_timeout_online'])) or error('Unable to fetch old entries from online list', __FILE__, __LINE__, $db->error()); - while ($cur_user = $db->fetch_assoc($result)) + $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') - $db->query('DELETE FROM '.$db->prefix.'online WHERE ident=\''.$db->escape($cur_user['ident']).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $db->error()); + $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'])) { - $db->query('UPDATE '.$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__, $db->error()); - $db->query('DELETE FROM '.$db->prefix.'online WHERE user_id='.$cur_user['user_id']) or error('Unable to delete from online list', __FILE__, __LINE__, $db->error()); + $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') - $db->query('UPDATE '.$db->prefix.'online SET idle=1 WHERE user_id='.$cur_user['user_id']) or error('Unable to insert into online list', __FILE__, __LINE__, $db->error()); + $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 // @@ -283,26 +252,26 @@ $links[] = '