From 2ed7c9c1b0f9aed9522a1deefb244ccb4ab85f3b Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sun, 9 Jan 2011 05:55:17 +0000 Subject: [PATCH] BUGFIX: fixed accessing private variable from Geoip. ENHANCEMENT: added Geoip::get_default_country_code(). Fixes #6315 git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@115364 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/CountryDropdownField.php | 16 ++++++++++------ integration/Geoip.php | 14 ++++++++++++-- tests/GeoipTest.php | 1 + 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/forms/CountryDropdownField.php b/forms/CountryDropdownField.php index 74e0606b6..6322c3631 100644 --- a/forms/CountryDropdownField.php +++ b/forms/CountryDropdownField.php @@ -1,11 +1,15 @@ getSource(); + if($this->defaultToVisitorCountry && !$this->value || !isset($source[$this->value])) { - $this->value = ($vc = Geoip::visitor_country()) ? $vc : Geoip::$default_country_code; + $this->value = ($vc = Geoip::visitor_country()) ? $vc : Geoip::get_default_country_code(); } + return parent::Field(); } -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/integration/Geoip.php b/integration/Geoip.php index ee2e6fa26..8b8ad6864 100755 --- a/integration/Geoip.php +++ b/integration/Geoip.php @@ -289,7 +289,7 @@ class Geoip { } /** - * Set the default country + * Set the default country code * * @param string $country_code */ @@ -297,6 +297,15 @@ class Geoip { self::$default_country_code = $country_code; } + /** + * Returns the default country code + * + * @return string + */ + public static function get_default_country_code() { + return self::$default_country_code; + } + /** * Find the country for an IP address. * @@ -365,7 +374,7 @@ class Geoip { // if geoip fails, lets default to default country code (if any) if(!isset($code) || !$code) { - $code = self::$default_country_code; + $code = self::get_default_country_code(); } return ($code) ? $code : false; @@ -408,6 +417,7 @@ class Geoip { /** * Returns the country name from the appropriate code. + * * @return null|string String if country found, null if none found */ static function countryCode2name($code) { diff --git a/tests/GeoipTest.php b/tests/GeoipTest.php index 74f10aa61..fa2f31741 100644 --- a/tests/GeoipTest.php +++ b/tests/GeoipTest.php @@ -7,5 +7,6 @@ class GeoipTest extends SapphireTest { Geoip::set_enabled(false); $this->assertEquals('DE', Geoip::visitor_country()); + $this->assertEquals('DE', Geoip::get_default_country_code()); } } \ No newline at end of file