Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sean Harvey
committed
Mar 17, 2011
0 parents
commit 7db53b5
Showing
5 changed files
with
496 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
GeoIP Module | ||
============ | ||
|
||
Maintainer Contact | ||
------------------ | ||
Sean Harvey (Nickname: sharvey, halkyon) | ||
<sean (at) silverstripe (dot) com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/** | ||
* A simple extension to {@link DropdownField}, pre-configured to list countries. | ||
* It will default to the country of the current visitor or use the default | ||
* country code provided using {@link Geoip::set_default_country_code()}. | ||
* | ||
* @package forms | ||
* @subpackage fields-relational | ||
*/ | ||
class CountryDropdownField extends DropdownField { | ||
|
||
protected $defaultToVisitorCountry = true; | ||
|
||
function __construct($name, $title = null, $source = null, $value = "", $form=null) { | ||
if(!is_array($source)) $source = Geoip::getCountryDropDown(); | ||
if(!$value) $value = Geoip::visitor_country(); | ||
|
||
parent::__construct($name, ($title===null) ? $name : $title, $source, $value, $form); | ||
} | ||
|
||
function defaultToVisitorCountry($val) { | ||
$this->defaultToVisitorCountry = $val; | ||
} | ||
|
||
function Field() { | ||
$source = $this->getSource(); | ||
|
||
if($this->defaultToVisitorCountry && !$this->value || !isset($source[$this->value])) { | ||
$this->value = ($vc = Geoip::visitor_country()) ? $vc : Geoip::get_default_country_code(); | ||
} | ||
|
||
return parent::Field(); | ||
} | ||
} |
Oops, something went wrong.