/** * Get Geo-Information for the current IP * * @param array(string) $locales List of locale codes to use in name property * from most preferred to least preferred. (Default: Site language, en) * @param array Property names with options. * @param boolean $skipCache TRUE: Do not use cache for this request. (Default: FALSE) * @return YellowTree\GeoipDetect\DataSources\City GeoInformation. * * @since 2.0.0 * @since 2.4.0 New parameter $skipCache * @since 2.5.0 Parameter $skipCache has been renamed to $options with 'skipCache' property */ function geoip_detect2_get_info_from_current_ip($locales = null, $options = array()) { return geoip_detect2_get_info_from_ip(geoip_detect2_get_client_ip(), $locales, $options); }
/** * @group external-http */ function testUpdate() { $s = new \YellowTree\GeoipDetect\DataSources\Auto\AutoDataSource(); $this->assertTrue($s->maxmindUpdate()); $record = geoip_detect2_get_info_from_ip(GEOIP_DETECT_TEST_IP); $this->assertValidGeoIP2Record($record, GEOIP_DETECT_TEST_IP); }
function testLookup() { $record = geoip_detect2_get_info_from_ip(GEOIP_DETECT_TEST_IP, array('en')); $this->assertValidGeoIP2Record($record, GEOIP_DETECT_TEST_IP); $this->assertSame(null, $record->city->name); $this->assertSame('Germany', $record->country->name); }
/** * Get Geo-Information for a specific IP * @param string $ip IP-Adress (currently only IPv4) * @return geoiprecord GeoInformation. (0 or NULL: no infos found.) * @deprecated since v2.0 */ function geoip_detect_get_info_from_ip($ip) { $ret = geoip_detect2_get_info_from_ip($ip); if ($ret == null || !$ret->country->name) { // Better way to detect "empty?" $ret = geoip_detect2_get_info_from_ip('me'); } $record = null; if (is_object($ret)) { $mapping = _geoip_detect_get_country_code_mapping(); $record = new geoiprecord(); $record->country_code = $ret->country->isoCode; $record->country_code3 = $mapping[$record->country_code]; $record->country_name = $ret->country->name; $record->region = $ret->mostSpecificSubdivision->isoCode; $record->region_name = $ret->mostSpecificSubdivision->name; $record->city = $ret->city->name; $record->postal_code = $ret->postal->code; $record->latitude = $ret->location->latitude; $record->longitude = $ret->location->longitude; $record->continent_code = $ret->continent->code; $record->metro_code = $ret->location->metroCode; $record->timezone = $ret->location->timeZone; } /** * Filter: geoip_detect_record_information * After loading the information from the GeoIP-Database, you can add or remove information from it. * @param geoiprecord $record Information found. * @param string $ip IP that was looked up * @return geoiprecord * @deprecated since v2.0 */ $record = apply_filters('geoip_detect_record_information', $record, $ip); return $record; }
function geoip_detect_lookup_page() { $ip_lookup_result = false; $message = ''; if (geoip_detect_verify_nonce()) { switch (@$_POST['action']) { case 'lookup': if (isset($_POST['ip'])) { $request_ip = $_POST['ip']; $request_skipCache = !empty($_POST['skip_cache']); $options = array('skipCache' => $request_skipCache); $request_locales = null; if (!empty($_POST['locales'])) { $request_locales = explode(',', $_POST['locales']); } $start = microtime(true); $ip_lookup_result = geoip_detect2_get_info_from_ip($request_ip, $request_locales, $options); $end = microtime(true); $ip_lookup_duration = $end - $start; } break; } } include_once GEOIP_PLUGIN_DIR . '/views/lookup.php'; }
/** * @group external-http */ function testLookupTimeout() { $before = microtime(true); $ret = geoip_detect2_get_info_from_ip(GEOIP_DETECT_TEST_IP, array('en'), array('timeout' => 0.01, 'skipCache' => true)); $after = microtime(true); $this->assertLessThan(0.2, $after - $before, 'Timeout option was not respected?'); $this->assertEmptyGeoIP2Record($ret, 'timed out'); }
function testManualInstall() { $ret = @copy(GEOIP_DETECT_TEST_DB_FILENAME, TEST_GEOIP_PLUGIN_DATA_FILENAME); if (!$ret) { $this->markTestSkipped('Test could not be executed: Copy failed'); } $record = geoip_detect2_get_info_from_ip(GEOIP_DETECT_TEST_IP); $this->assertValidGeoIP2Record($record, GEOIP_DETECT_TEST_IP); }
function testDescription() { $this->assertNotEmpty(geoip_detect2_get_current_source_description()); $record = geoip_detect2_get_info_from_ip(GEOIP_DETECT_TEST_IP); $this->assertNotEmpty(geoip_detect2_get_current_source_description($record)); $desc = do_shortcode('[geoip_detect2_get_current_source_description]'); $this->assertNotSame('[geoip_detect2_get_current_source_description]', $desc, 'Shortcode was not executed.'); $this->assertNotEmpty($desc, 'Shortcode returned empty string'); }
/** * @group external-http */ function testNoPassword() { remove_filter('pre_option_geoip-detect-precision-user_secret', array($this, 'filter_set_user_secret'), 101); add_filter('pre_option_geoip-detect-precision-user_secret', array($this, 'filter_set_wrong_user_secret'), 102); $record = geoip_detect2_get_info_from_ip(GEOIP_DETECT_TEST_IP); $this->assertTrue($record->isEmpty); $this->assertContains('Invalid user_id or license_key', $record->extra->error); }
function geoip_detect2_get_info_from_current_ip() { return geoip_detect2_get_info_from_ip(); }