📄 functions.php
字号:
}
function pop_up_window( $title = "华酷论坛", $text = "" )
{
global $ibforums;
global $DB;
$css = "\n<style>\n<!--\n".str_replace( "<#IMG_DIR#>", $ibforums->skin['img_dir'], $ibforums->skin['css_text'] )."\n//-->\n</style>";
$html = "<html>\n \t <head>\n\t\t\t\t\t<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n\t\t\t\t\t<meta name='author' content='Powered By HuaCooL Network'>\n\t\t\t\t\t<meta name='copyright' content='Copyright 2002-2003 www.ibfchina.com, HuaCooL Network'>\n \t <title>{$title}</title>\n \t {$css}\n \t </head>\n \t <body topmargin='0' leftmargin='0' rightmargin='0' marginwidth='0' marginheight='0' alink='#000000' vlink='#000000'>\n \t {$text}\n \t </body>\n \t </html>\n \t ";
$TAGS = $DB->query( "SELECT macro_value, macro_replace FROM ibf_macro WHERE macro_set='{$ibforums->skin['macro_id']}'" );
while ( $row = $DB->fetch_row( $TAGS ) )
{
if ( $row['macro_value'] != "" )
{
$html = str_replace( "<{".$row['macro_value']."}>", $row['macro_replace'], $html );
}
}
$html = str_replace( "<#IMG_DIR#>", $ibforums->skin['img_dir'], $html );
$DB->close_db( );
if ( $ibforums->vars['disable_gzip'] != 1 )
{
$buffer = ob_get_contents( );
ob_end_clean( );
ob_start( "ob_gzhandler" );
print $buffer;
}
$this->do_headers( );
echo $html;
exit( );
}
}
class session
{
var $ip_address = 0;
var $user_agent = "";
var $time_now = 0;
var $session_id = 0;
var $session_dead_id = 0;
var $session_user_id = 0;
var $session_user_pass = "";
var $last_click = 0;
var $location = "";
var $member = array( );
function authorise( )
{
global $DB;
global $INFO;
global $ibforums;
global $std;
global $HTTP_USER_AGENT;
if ( 0 < $ibforums->vars['load_limit'] && file_exists( "/proc/loadavg" ) && ( $fh = @fopen( "/proc/loadavg", "r" ) ) )
{
$data = @fread( $fh, 6 );
@fclose( $fh );
$load_avg = explode( " ", $data );
$ibforums->server_load = trim( $load_avg[0] );
if ( $ibforums->vars['load_limit'] < $ibforums->server_load )
{
$std->error( array( "LEVEL" => 1, "MSG" => "server_too_busy", "INIT" => 1 ) );
}
}
if ( $ibforums->vars['ban_ip'] )
{
$ips = explode( "|", $ibforums->vars['ban_ip'] );
foreach ( $ips as $ip )
{
$ip = preg_replace( "/\\*/", ".*", $ip );
if ( preg_match( "/{$ip}/", $ibforums->input['IP_ADDRESS'] ) )
{
$std->error( array( "LEVEL" => 1, "MSG" => "you_are_banned", "INIT" => 1 ) );
}
}
}
$this->member = array(
"id" => 0,
"password" => "",
"name" => "",
"mgroup" => $INFO['guest_group']
);
if ( $ibforums->input['act'] == "Reg" || $ibforums->input['act'] == "Attach" )
{
return $this->member;
}
$this->ip_address = $ibforums->input['IP_ADDRESS'];
$this->user_agent = substr( $HTTP_USER_AGENT, 0, 50 );
$this->time_now = time( );
$cookie = array( );
$cookie['session_id'] = $std->my_getcookie( "session_id" );
$cookie['member_id'] = $std->my_getcookie( "member_id" );
$cookie['pass_hash'] = $std->my_getcookie( "pass_hash" );
if ( !empty( $cookie['session_id'] ) )
{
$this->get_session( $cookie['session_id'] );
}
else if ( !empty( $ibforums->input['s'] ) )
{
$this->get_session( $ibforums->input['s'] );
}
else
{
$this->session_id = 0;
}
$ibforums->input['Privacy'] = $std->select_var( array(
1 => $ibforums->input['Privacy'],
2 => $std->my_getcookie( "anonlogin" )
) );
if ( $this->session_id != 0 && !empty( $this->session_id ) )
{
if ( $this->session_user_id != 0 && !empty( $this->session_user_id ) )
{
$this->load_member( $this->session_user_id );
if ( !$this->member['id'] || $this->member['id'] == 0 )
{
$this->unload_member( );
$this->update_guest_session( );
}
else
{
$this->update_member_session( );
}
}
else
{
$this->update_guest_session( );
}
}
else if ( $cookie['member_id'] != "" && $cookie['pass_hash'] != "" )
{
$this->load_member( $cookie['member_id'] );
if ( !$this->member['id'] || $this->member['id'] == 0 )
{
$this->unload_member( );
$this->create_guest_session( );
}
else if ( $this->member['password'] == $cookie['pass_hash'] )
{
$this->create_member_session( );
}
else
{
$this->unload_member( );
$this->create_guest_session( );
}
}
else
{
$this->create_guest_session( );
}
if ( !$this->member['id'] )
{
$this->member = $std->set_up_guest( );
$DB->query( "SELECT * from ibf_groups WHERE g_id='".$INFO['guest_group']."'" );
$group = $DB->fetch_row( );
foreach ( $group as $k => $v )
{
$this->member[$k] = $v;
}
}
if ( $this->member['id'] )
{
if ( !$ibforums->input['last_activity'] )
{
if ( $this->member['last_activity'] )
{
$ibforums->input['last_activity'] = $this->member['last_activity'];
}
else
{
$ibforums->input['last_activity'] = $this->time_now;
}
}
if ( !$ibforums->input['last_visit'] )
{
if ( $this->member['last_visit'] )
{
$ibforums->input['last_visit'] = $this->member['last_visit'];
}
else
{
$ibforums->input['last_visit'] = $this->time_now;
}
}
if ( !$this->member['last_visit'] )
{
$DB->query( "UPDATE ibf_members SET last_visit='".$this->time_now."', last_activity='".$this->time_now."' WHERE id='".$this->member['id']."'" );
}
else if ( 300 < time( ) - $ibforums->input['last_activity'] )
{
$DB->query( "UPDATE ibf_members SET last_activity='".$this->time_now."' WHERE id='".$this->member['id']."'" );
}
}
$std->my_setcookie( "session_id", $this->session_id, -1 );
return $this->member;
}
function load_member( $member_id = 0 )
{
global $DB;
global $std;
global $ibforums;
if ( $member_id != 0 )
{
$DB->query( "SELECT mod.mid as is_mod, m.id, m.name, m.mgroup, m.password, m.email, m.allow_post, m.view_sigs, m.view_avs, m.view_pop, m.view_img, m.auto_track,\n m.mod_posts, m.language, m.skin, m.new_msg, m.show_popup, m.msg_total, m.time_offset, m.posts, m.joined, m.last_post,\n \t\t\t\t m.last_visit, m.last_activity, m.dst_in_use, m.view_prefs, g.*\n \t\t\t\t FROM ibf_members m\n \t\t\t\t LEFT JOIN ibf_groups g ON (g.g_id=m.mgroup)\n \t\t\t\t LEFT JOIN ibf_moderators mod ON (mod.member_id=m.id OR mod.group_id=m.mgroup )\n \t\t\t\t WHERE m.id='{$member_id}'" );
if ( $DB->get_num_rows( ) )
{
$this->member = $DB->fetch_row( );
}
if ( $this->member['id'] == 0 || empty( $this->member['id'] ) )
{
$this->unload_member( );
}
}
unset( $member_id );
}
function unload_member( )
{
global $DB;
global $std;
global $ibforums;
$std->my_setcookie( "member_id", "0", -1 );
$std->my_setcookie( "pass_hash", "0", -1 );
$this->member['id'] = 0;
$this->member['name'] = "";
$this->member['password'] = "";
}
function update_member_session( )
{
global $DB;
global $ibforums;
if ( empty( $this->session_id ) || $this->session_id == 0 )
{
$this->create_member_session( );
}
else if ( empty( $this->member['id'] ) )
{
$this->unload_member( );
$this->create_guest_session( );
}
else
{
$query = "UPDATE ibf_sessions SET member_name='".$this->member['name']."', "."member_id='".$this->member['id']."', "."member_group='".$this->member['mgroup']."', ";
$query .= "login_type='".$ibforums->input['Privacy']."', running_time='".$this->time_now."', in_forum='".$ibforums->input['f']."', in_topic='".$ibforums->input['t']."', location='".$ibforums->input['act'].",".$ibforums->input['p'].",".$ibforums->input['CODE']."' ";
$query .= "WHERE id='".$this->session_id."'";
$DB->query( $query );
}
}
function update_guest_session( )
{
global $DB;
global $ibforums;
global $INFO;
if ( empty( $this->session_id ) || $this->session_id == 0 )
{
$this->create_guest_session( );
}
else
{
$query = "UPDATE ibf_sessions SET member_name='',member_id='0',member_group='".$INFO['guest_group']."'";
$query .= ",login_type='0', running_time='".$this->time_now."', in_forum='".$ibforums->input['f']."', in_topic='".$ibforums->input['t']."', location='".$ibforums->input['act'].",".$ibforums->input['p'].",".$ibforums->input['CODE']."' ";
$query .= "WHERE id='".$this->session_id."'";
$DB->query( $query );
}
}
function get_session( $session_id = "" )
{
global $DB;
global $INFO;
global $std;
$result = array( );
$query = "";
$session_id = preg_replace( "/([^a-zA-Z0-9])/", "", $session_id );
if ( !empty( $session_id ) )
{
if ( $INFO['match_browser'] == 1 )
{
$query = " AND browser='".$this->user_agent."'";
}
$DB->query( "SELECT id, member_id, running_time, location FROM ibf_sessions WHERE id='".$session_id."' and ip_address='".$this->ip_address."'".$query );
if ( $DB->get_num_rows( ) != 1 )
{
$this->session_dead_id = $session_id;
$this->session_id = 0;
$this->session_user_id = 0;
return;
}
else
{
$result = $DB->fetch_row( );
if ( $result['id'] == "" )
{
$this->session_dead_id = $session_id;
$this->session_id = 0;
$this->session_user_id = 0;
unset( $result );
return;
}
else
{
$this->session_id = $result['id'];
$this->session_user_id = $result['member_id'];
$this->last_click = $result['running_time'];
$this->location = $result['location'];
unset( $result );
}
}
}
}
function create_member_session( )
{
global $DB;
global $INFO;
global $std;
global $ibforums;
if ( $this->member['id'] )
{
$INFO['session_expiration'] = $INFO['session_expiration'] ? time( ) - $INFO['session_expiration'] : time( ) - 3600;
$DB->query( "DELETE FROM ibf_sessions WHERE running_time < {$INFO['session_expiration']} or member_id='".$this->member['id']."'" );
$this->session_id = md5( uniqid( microtime( ) ) );
$DB->query( "INSERT INTO ibf_sessions (id, member_name, member_id, ip_address, browser, running_time, location, login_type, member_group) VALUES ('".$this->session_id."', '".$this->member['name']."', '".$this->member['id']."', '".$this->ip_address."', '".$this->user_agent."', '".$this->time_now."', "."',,', '".$ibforums->input['Privacy']."', ".$this->member['mgroup'].")" );
if ( 300 < time( ) - $this->member['last_activity'] )
{
$std->my_setcookie( "topicsread", "" );
$DB->query( "UPDATE ibf_members SET last_visit=last_activity, last_activity='".$this->time_now."' WHERE id='".$this->member['id']."'" );
$ibforums->input['last_visit'] = $this->member['last_activity'];
$ibforums->input['last_activity'] = $this->time_now;
}
}
else
{
$this->create_guest_session( );
}
}
function create_guest_session( )
{
global $DB;
global $INFO;
global $std;
global $ibforums;
if ( $this->session_dead_id != 0 && !empty( $this->session_dead_id ) )
{
$extra = " or id='".$this->session_dead_id."'";
}
else
{
$extra = "";
}
$INFO['session_expiration'] = $INFO['session_expiration'] ? time( ) - $INFO['session_expiration'] : time( ) - 3600;
$DB->query( "DELETE FROM ibf_sessions WHERE running_time < {$INFO['session_expiration']} or ip_address='".$this->ip_address."'".$extra );
$this->session_id = md5( uniqid( microtime( ) ) );
$DB->query( "INSERT INTO ibf_sessions (id, member_name, member_id, ip_address, browser, running_time, location, login_type, member_group) VALUES ('".$this->session_id."', '', '0', '".$this->ip_address."', '".$this->user_agent."', '".$this->time_now."', "."',,', '0', ".$INFO['guest_group'].")" );
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -