function adrotate_click_callback() { define('DONOTCACHEPAGE', true); define('DONOTCACHEDB', true); define('DONOTCACHCEOBJECT', true); global $wpdb, $adrotate_config, $adrotate_debug; $meta = $_POST['track']; if ($adrotate_debug['track'] != true) { $meta = base64_decode($meta); } $meta = esc_attr($meta); list($ad, $group, $blog_id, $impression_timer) = explode(",", $meta, 4); if (is_numeric($ad) and is_numeric($group) and is_numeric($blog_id)) { if ($adrotate_config['enable_loggedin_clicks'] == 'Y' and is_user_logged_in() or !is_user_logged_in()) { $remote_ip = adrotate_get_remote_ip(); if (adrotate_is_bot() and $remote_ip != "unknown" and !empty($remote_ip)) { $now = adrotate_now(); $today = adrotate_date_start('day'); if ($adrotate_debug['timers'] == true) { $click_timer = $now; } else { $click_timer = $now - $adrotate_config['click_timer']; } $saved_timer = $wpdb->get_var($wpdb->prepare("SELECT `timer` FROM `" . $wpdb->prefix . "adrotate_tracker` WHERE `ipaddress` = '%s' AND `stat` = 'c' AND `bannerid` = %d ORDER BY `timer` DESC LIMIT 1;", $remote_ip, $ad)); if ($saved_timer < $click_timer) { $stats = $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . $wpdb->prefix . "adrotate_stats` WHERE `ad` = %d AND `group` = %d AND `thetime` = {$today};", $ad, $group)); if ($stats > 0) { $wpdb->query("UPDATE `" . $wpdb->prefix . "adrotate_stats` SET `clicks` = `clicks` + 1 WHERE `id` = {$stats};"); } else { $wpdb->insert($wpdb->prefix . 'adrotate_stats', array('ad' => $ad, 'group' => $group, 'thetime' => $today, 'clicks' => 1, 'impressions' => 1)); } $wpdb->insert($wpdb->prefix . 'adrotate_tracker', array('ipaddress' => $remote_ip, 'timer' => $now, 'bannerid' => $ad, 'stat' => 'c', 'useragent' => $useragent, 'country' => '', 'city' => '')); } } } unset($remote_ip, $track, $meta, $ad, $group, $remote, $banner); } wp_die(); }
function adrotate_geolocation() { global $wpdb, $ajdg_solutions_domain; if (!adrotate_has_cookie('geo') and adrotate_is_human()) { $adrotate_config = get_option('adrotate_config'); $remote_ip = adrotate_get_remote_ip(); $geo_result = array(); if ($adrotate_config['enable_geo'] == 1 or $adrotate_config['enable_geo'] == 2) { // Telize OR GeoBytes (deprecated) $adrotate_config['enable_geo'] = 5; // AdRotate Geo } if ($adrotate_config['enable_geo'] == 5) { // AdRotate Geo if (adrotate_is_networked()) { $adrotate_activate = get_site_option('adrotate_activate'); } else { $adrotate_activate = get_option('adrotate_activate'); } $args = array('headers' => array('User-Agent' => 'AdRotate Pro;' . get_option('siteurl')), 'sslverify' => false); $auth = base64_encode($adrotate_activate["instance"] . ':' . $adrotate_activate["key"]); $raw_response = wp_remote_get($ajdg_solutions_domain . 'api/geo/3/?auth=' . $auth . '&ip=' . $remote_ip, $args); $geo_result['provider'] = 'AdRotate Geo'; if (!is_wp_error($raw_response)) { $response = json_decode($raw_response['body'], true); $geo_result['status'] = $raw_response['response']['code']; if ($geo_result['status'] == 200) { $geo_result['city'] = isset($response['city']) ? strtolower($response['city']) : ''; $geo_result['dma'] = isset($response['dma']) ? strtolower($response['dma']) : ''; $geo_result['country'] = isset($response['country']) ? strtolower($response['country']) : ''; $geo_result['countrycode'] = isset($response['countrycode']) ? $response['countrycode'] : ''; $geo_result['state'] = isset($response['state']) ? strtolower($response['state']) : ''; $geo_result['statecode'] = isset($response['statecode']) ? strtolower($response['statecode']) : ''; } else { $geo_result['status'] = $raw_response['response']['code']; $geo_result['error'] = $raw_response['response']['message']; } update_option('adrotate_geo_requests', $response['queries_remaining']); } else { $geo_result['status'] = $raw_response->get_error_code(); $geo_result['error'] = $raw_response->get_error_message(); } } if ($adrotate_config['enable_geo'] == 3 or $adrotate_config['enable_geo'] == 4) { // MaxMind if ($adrotate_config['enable_geo'] == 3) { $service_type = 'country'; } if ($adrotate_config['enable_geo'] == 4) { $service_type = 'city'; } $args = array('headers' => array('user-agent' => 'AdRotate Pro;', 'Authorization' => 'Basic ' . base64_encode($adrotate_config["geo_email"] . ':' . $adrotate_config["geo_pass"]))); $raw_response = wp_remote_get('https://geoip.maxmind.com/geoip/v2.1/' . $service_type . '/' . $remote_ip, $args); $geo_result['provider'] = 'MaxMind ' . $service_type; if (!is_wp_error($raw_response)) { $response = json_decode($raw_response['body'], true); $geo_result['status'] = $raw_response['response']['code']; if ($geo_result['status'] == 200) { $geo_result['city'] = isset($response['city']['names']['en']) ? strtolower($response['city']['names']['en']) : ''; $geo_result['dma'] = isset($response['location']['metro_code']) ? strtolower($response['location']['metro_code']) : ''; $geo_result['country'] = isset($response['country']['names']['en']) ? strtolower($response['country']['names']['en']) : ''; $geo_result['countrycode'] = isset($response['country']['iso_code']) ? $response['country']['iso_code'] : ''; $geo_result['state'] = isset($response['subdivisions'][0]['names']['en']) ? strtolower($response['subdivisions'][0]['names']['en']) : ''; $geo_result['statecode'] = isset($response['subdivisions'][0]['iso_code']) ? strtolower($response['subdivisions'][0]['iso_code']) : ''; } else { $geo_result['status'] = $response['code']; $geo_result['error'] = $response['error']; if ($response['code'] == 'IP_ADDRESS_RESERVED') { $response['maxmind']['queries_remaining'] = 0; } if ($response['code'] == 'OUT_OF_QUERIES') { $response['maxmind']['queries_remaining'] = 0; } } update_option('adrotate_geo_requests', $response['maxmind']['queries_remaining']); } else { $geo_result['status'] = $raw_response->get_error_code(); $geo_result['error'] = $raw_response->get_error_message(); } } unset($raw_response, $response); setcookie('adrotate-geo', serialize($geo_result), time() + $adrotate_config['geo_cookie_life'], COOKIEPATH, COOKIE_DOMAIN); if (!isset($_SESSION['adrotate-geo'])) { $_SESSION['adrotate-geo'] = $geo_result; } } }