function testManualInstall() { $ret = @copy(GEOIP_DETECT_TEST_DB_FILENAME, TEST_GEOIP_PLUGIN_DATA_FILENAME); if (!$ret) { $this->skip('Test could not be executed: Copy failed'); } $this->assertNotSame('', geoip_detect_get_abs_db_filename(), 'Did not detect manual database'); $record = geoip_detect_get_info_from_ip(GEOIP_DETECT_TEST_IP); $this->assertValidGeoIPRecord($record, GEOIP_DETECT_TEST_IP); }
/** * Get Geo-Information for a specific IP * @param string $ip IP-Adress (currently only IPv4) * @return geoiprecord GeoInformation. (0 or NULL: no infos found.) */ function geoip_detect_get_info_from_ip($ip) { $data_file = geoip_detect_get_abs_db_filename(); if (!$data_file) { return 0; } $gi = geoip_open($data_file, GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $ip); geoip_close($gi); $record = apply_filters('geoip_detect_record_information', $record, $ip); return $record; }
function geoip_detect_plugin_page() { geoip_detect_set_cron_schedule(); $ip_lookup_result = false; $last_update = 0; $message = ''; switch (@$_POST['action']) { case 'update': $ret = geoip_detect_update(); if ($ret === true) { $message .= __('Updated successfully.', 'geoip-detect'); } else { $message .= __('Update failed.', 'geoip-detect') . ' ' . $ret; } break; case 'lookup': if (isset($_POST['ip'])) { $ip = $_POST['ip']; $ip_lookup_result = geoip_detect_get_info_from_ip($ip); } break; case 'options': $opt_value = isset($_POST['options']['set_css_country']) ? (int) $_POST['options']['set_css_country'] : 0; update_option('geoip-detect-set_css_country', $opt_value); $opt_value = isset($_POST['options']['data_filename']) ? $_POST['options']['data_filename'] : 'GeoLiteCity.dat'; update_option('geoip-detect-data_filename', $opt_value); break; } $data_file = geoip_detect_get_abs_db_filename(); if (file_exists($data_file)) { $last_update = filemtime($data_file); } else { $message .= __('No GeoIP Database found. Click on the button "Update now" or follow the installation instructions.', 'geoip-detect'); $last_update = 0; } if (empty($custom_filename)) { $next_cron_update = wp_next_scheduled('geoipdetectupdate'); } $options = array(); $options['set_css_country'] = (int) get_option('geoip-detect-set_css_country'); $options['data_filename'] = get_option('geoip-detect-data_filename'); include_once dirname(__FILE__) . '/views/plugin_page.php'; }