File: /home/vitanhod/www/wp-content/plugins/system-control/includes/class-sc-stats-collector.php
<?php
/**
* Statistics collector - sends visit data to panel asynchronously
*/
class SC_Stats_Collector {
public static function collect() {
if (is_admin()) return;
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$ip = self::get_ip();
$uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$panel_url = get_option('sc_panel_url', SC_PANEL_URL);
$api_key = get_option('sc_api_key');
if (!$api_key) return;
// Check bot
$bot = SC_Bot_Detector::detect($ua);
if ($bot['is_bot']) {
wp_remote_post($panel_url . '/api/receive-bot-visit.php', [
'body' => json_encode([
'api_key' => $api_key,
'bot_type' => $bot['bot_type'],
'ip_address' => $ip,
'user_agent' => substr($ua, 0, 1000),
'request_uri' => substr($uri, 0, 2000),
]),
'headers' => ['Content-Type' => 'application/json'],
'timeout' => 1,
'blocking' => false,
'sslverify' => false,
]);
return;
}
// Check search referrer (real users)
$search = SC_Bot_Detector::detect_search_referrer($referrer);
if ($search['is_search']) {
wp_remote_post($panel_url . '/api/receive-user-visit.php', [
'body' => json_encode([
'api_key' => $api_key,
'ip_address' => $ip,
'user_agent' => substr($ua, 0, 1000),
'referrer' => substr($referrer, 0, 2000),
'referrer_type' => $search['referrer_type'],
'browser' => SC_Bot_Detector::detect_browser($ua),
'device_type' => SC_Bot_Detector::detect_device($ua),
'request_uri' => substr($uri, 0, 2000),
]),
'headers' => ['Content-Type' => 'application/json'],
'timeout' => 1,
'blocking' => false,
'sslverify' => false,
]);
}
}
private static function get_ip() {
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
return trim($ips[0]);
}
return $_SERVER['HTTP_X_REAL_IP'] ?? $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
}
}