Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Put this user in the online log.
- function writeLog($force = false)
- {
- global $user_info, $user_settings, $context, $modSettings, $settings, $topic, $board, $smcFunc, $sourcedir;
- // If we are showing who is viewing a topic, let's see if we are, and force an update if so - to make it accurate.
- if (!empty($settings['display_who_viewing']) && ($topic || $board))
- {
- // Take the opposite approach!
- $force = true;
- // Don't update for every page - this isn't wholly accurate but who cares.
- if ($topic)
- {
- if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic)
- $force = false;
- $_SESSION['last_topic_id'] = $topic;
- }
- }
- // Are they a spider we should be tracking? Mode = 1 gets tracked on its spider check...
- if (!empty($user_info['possibly_robot']) && !empty($modSettings['spider_mode']) && $modSettings['spider_mode'] > 1)
- {
- require_once($sourcedir . '/ManageSearchEngines.php');
- logSpider();
- }
- // Don't mark them as online more than every so often.
- if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force)
- return;
- if (!empty($modSettings['who_enabled']))
- {
- $serialized = $_GET + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
- // In the case of a dlattach action, session_var may not be set.
- if (!isset($context['session_var']))
- $context['session_var'] = $_SESSION['session_var'];
- unset($serialized['sesc'], $serialized[$context['session_var']]);
- $serialized = serialize($serialized);
- }
- else
- $serialized = '';
- // Guests use 0, members use their session ID.
- $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
- // Grab the last all-of-SMF-specific log_online deletion time.
- $do_delete = cache_get_data('log_online-update', 30) < time() - 30;
- // If the last click wasn't a long time ago, and there was a last click...
- if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= time() - $modSettings['lastActive'] * 20)
- {
- if ($do_delete)
- {
- $smcFunc['db_query']('delete_log_online_interval', '
- DELETE FROM {db_prefix}log_online
- WHERE log_time < {int:log_time}
- AND session != {string:session}',
- array(
- 'log_time' => time() - $modSettings['lastActive'] * 60,
- 'session' => $session_id,
- )
- );
- // Cache when we did it last.
- cache_put_data('log_online-update', time(), 30);
- }
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}log_online
- SET log_time = {int:log_time}, ip = IFNULL(INET_ATON({string:ip}), 0), url = {string:url}
- WHERE session = {string:session}',
- array(
- 'log_time' => time(),
- 'ip' => $user_info['ip'],
- 'url' => $serialized,
- 'session' => $session_id,
- )
- );
- // Guess it got deleted.
- if ($smcFunc['db_affected_rows']() == 0)
- $_SESSION['log_time'] = 0;
- }
- else
- $_SESSION['log_time'] = 0;
- // Otherwise, we have to delete and insert.
- if (empty($_SESSION['log_time']))
- {
- if ($do_delete || !empty($user_info['id']))
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}log_online
- WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'),
- array(
- 'current_member' => $user_info['id'],
- 'log_time' => time() - $modSettings['lastActive'] * 60,
- )
- );
- $smcFunc['db_insert']($do_delete ? 'ignore' : 'replace',
- '{db_prefix}log_online',
- array('session' => 'string', 'id_member' => 'int', 'id_spider' => 'int', 'log_time' => 'int', 'ip' => 'raw', 'url' => 'string'),
- array($session_id, $user_info['id'], empty($_SESSION['id_robot']) ? 0 : $_SESSION['id_robot'], time(), 'IFNULL(INET_ATON(\'' . $user_info['ip'] . '\'), 0)', $serialized),
- array('session')
- );
- }
- // Mark your session as being logged.
- $_SESSION['log_time'] = time();
- // Well, they are online now.
- if (empty($_SESSION['timeOnlineUpdated']))
- $_SESSION['timeOnlineUpdated'] = time();
- // Set their login time, if not already done within the last minute.
- if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60)
- {
- // Don't count longer than 15 minutes.
- if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15)
- $_SESSION['timeOnlineUpdated'] = time();
- $user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
- updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in']));
- if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
- cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
- $user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
- $_SESSION['timeOnlineUpdated'] = time();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement