|
From: OryNider <ory...@us...> - 2008-02-28 06:27:47
|
Update of /cvsroot/mxbb/mx_shotcast/includes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21483/mx_shotcast/includes Modified Files: common.php Log Message: cvs commit test Index: common.php =================================================================== RCS file: /cvsroot/mxbb/mx_shotcast/includes/common.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** common.php 24 Feb 2008 01:26:47 -0000 1.4 --- common.php 28 Feb 2008 06:26:42 -0000 1.5 *************** *** 2,6 **** /** * ! * @package mxBB Portal Module - mx_shotcast * @version $Id$ * @copyright (c) 2002-2006 [OryNider] mxBB Development Team --- 2,6 ---- /** * ! * @package Mx-Publisher Module - mx_shotcast * @version $Id$ * @copyright (c) 2002-2006 [OryNider] mxBB Development Team *************** *** 9,14 **** */ - - // // Security check --- 9,12 ---- *************** *** 22,28 **** // Define table names. // ! define('SHOTCAST_CONFIG_TABLE', $mx_table_prefix.'shotcast_config'); ! define('SHOTCAST_SESSION_TABLE', $mx_table_prefix.'shotcast_session'); // --- 20,31 ---- // Define table names. // + @define('SHOTCAST_CONFIG_TABLE', $mx_table_prefix.'shotcast_config'); + @define('SHOTCAST_SESSION_TABLE', $mx_table_prefix.'shotcast_session'); ! //Check for shotcast version ! if(file_exists($mx_root_path . "modules/mx_radio/includes/common.$phpEx")) ! { ! !defined('SHOTCAST_SESSION_TABLE') ? define('SHOTCAST_SESSION_TABLE', $mx_table_prefix.'radio_session') : false; ! } // *************** *** 55,59 **** } - // // Load language files. --- 58,61 ---- *************** *** 67,70 **** --- 69,73 ---- include($module_root_path . 'language/lang_english/lang_admin.' . $phpEx); } + //Load main laguage file if( file_exists($module_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx) ) { *************** *** 79,85 **** // Common definitions... // ! $cfg_shotcastname = $board_config['sitename'] . ' -> ' . 'shotcast'; // ================================================================================ --- 82,110 ---- // Common definitions... // ! $time = date("U"); $cfg_shotcastname = $board_config['sitename'] . ' -> ' . 'shotcast'; + if(empty($user_ip)) + { + $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : getenv('REMOTE_ADDR') ); + $user_ip = phpBB2::encode_ip($client_ip); + } + + $user_id = $userdata['user_id']; + $nick = str_replace(" ", "_", $userdata['username']); + $radio_bot_id = ANONYMOUS; + + if (($userdata['user_id'] != ANONYMOUS) && defined('ONLINE_ADV_SESSION_TABLE')) + { + if($this_agent) + { + $nick = $this_agent; + } + + if ($this_bot_id) + { + $radio_bot_id = $this_bot_id; + } + } // ================================================================================ *************** *** 88,94 **** // ! // Get shotcast Settings from config table // - if( defined('IN_SHOTCAST') ) { --- 113,118 ---- // ! // Get radio Settings from config table // if( defined('IN_SHOTCAST') ) { *************** *** 109,169 **** } // ================================================================================ // [ COMMON FUNCTIONS ] // ================================================================================ - // $mx_user->init($user_ip, PAGE_INDEX); - // $nick = str_replace(" ", "_", $userdata['username']); - function user_listensc($nick) { ! global $shotcast_config, $db; ! $current_time=date("U"); ! $sql = "DELETE FROM ".SHOTCAST_SESSION_TABLE." WHERE username = '".addslashes($nick)."'"; ! if( !$result = $db->sql_query($sql) ) { ! die("SQL Error in function user_listen(): DELETE<br />" . $sql); } ! $sql = "INSERT INTO ".SHOTCAST_SESSION_TABLE." (username, time)" . ! " VALUES ('" .addslashes($nick). "', ".$current_time.")"; ! if( !$result = $db->sql_query($sql) ) { ! die("SQL Error in function user_listen(): INSERT<br />" . $sql); } } ! ! //Update user statue "listening/not listening" ! function update_shotcast_users($nick,$time) { ! global $shotcast_config, $board_config, $db, $lang; ! ! $sql="update ".SHOTCAST_SESSION_TABLE." set time='$time' where username='$nick'"; ! if( !$result = $db->sql_query($sql) ) { ! die("SQL Error in function update_shotcast_users(): UPDATE<br />" . $sql); } } function drop_shotcast_users($period) { ! global $shotcast_config, $board_config, $db, $lang; ! $current_time=date("U"); //prevent delay ! $period=$period+2; // Calcul max_time ! $max_time=$current_time-$period; ! ! $sql="delete from ".SHOTCAST_SESSION_TABLE." where time<'$max_time'"; ! if( !$result = $db->sql_query($sql) ) ! { ! die("SQL Error in function drop_shotcast_users()"); ! } } ?> --- 133,219 ---- } + //read check period + $period = $shotcast_config['check_period'] * 1000; + // ================================================================================ // [ COMMON FUNCTIONS ] // ================================================================================ function user_listensc($nick) { ! global $userdata, $shotcast_config, $db, $user_ip, $radio_bot_id; ! $current_time = date("U"); ! $user_id = $userdata['user_id']; ! ! $sql = "DELETE FROM " . SHOTCAST_SESSION_TABLE . " ! WHERE session_ip = '" . $user_ip . "'"; ! if(!$result = $db->sql_query($sql)) { ! mx_message_die(CRITICAL_ERROR, 'SQL Error in function user_listensc(): DELETE<br />', '', __LINE__, __FILE__, $sql); } ! ! $sql = "INSERT INTO " . SHOTCAST_SESSION_TABLE . " ! (user_id, username, time, session_ip, bot_id) ! VALUES ('$user_id', '" . addslashes($nick) . "', '$current_time', '$user_ip', '$radio_bot_id')"; ! if(!$result = $db->sql_query($sql)) { ! mx_message_die(CRITICAL_ERROR, 'SQL Error in function user_listensc(): INSERT INTO<br />', '', __LINE__, __FILE__, $sql); } } ! //Update user statue "listening/not listening" ! //Since this is loaded in a iframe it's not need for debuging code ! function update_shotcast_users($nick) { ! global $shotcast_config, $db, $lang, $user_ip; ! ! $time = date("U"); ! $sql = "UPDATE " . SHOTCAST_SESSION_TABLE . " ! SET time = $time ! WHERE session_ip = '" . $user_ip . "'"; ! if(!$result = $db->sql_query($sql)) { ! $sql = "UPDATE " . SHOTCAST_SESSION_TABLE . " ! SET time = $time ! WHERE username = '" . $nick . "'"; ! $db->sql_query($sql); } + /* + if(defined('RADIO_SESSION_TABLE')) + { + $sql = "DELETE FROM " . RADIO_SESSION_TABLE . " + WHERE session_ip = '$user_ip'"; + $db->sql_query($sql); + $sql = "INSERT INTO " . RADIO_SESSION_TABLE . " + (user_id, username, time, session_ip, bot_id) + VALUES ('$user_id', '" . addslashes($nick) . "', '$time', '$user_ip', '$radio_bot_id')"; + $db->sql_query($sql); + } + */ } + function drop_shotcast_users($period) { ! global $shotcast_config, $db, $lang; ! $current_time = date("U"); //prevent delay ! $period = $period + 2; // Calcul max_time ! $max_time = $current_time - $period; ! $sql = "DELETE FROM " . SHOTCAST_SESSION_TABLE . " WHERE time < {$max_time}"; ! if(!$result = $db->sql_query($sql)) ! { ! mx_message_die(CRITICAL_ERROR, 'SQL Error in function drop_shotcast_users()', '', __LINE__, __FILE__, $sql); ! } } + + // REMOVE OLD SESSIONS + drop_shotcast_users($period); ?> |