/**
* Get country information from a hostname or IP address.
*
- * @param string $host The hostname or IP address.
+ * @param string $host The hostname or IP address.
+ * @param string $datafile The datafile for the GeoIP lookup. If not set,
+ * will skip this lookup.
*
* @return mixed On success, return an array with the following entries:
* 'code' => Country Code
* 'name' => Country Name
* On failure, return false.
*/
- static public function getCountryByHost($host)
+ static public function getCountryByHost($host, $datafile = null)
{
/* List of generic domains that we know is not in the country TLD
list. See: http://www.iana.org/gtld/gtld.htm */
}
/* Try GeoIP lookup next. */
- $geoip = Horde_Nls_Geoip::singleton(!empty($GLOBALS['conf']['geoip']['datafile']) ? $GLOBALS['conf']['geoip']['datafile'] : null);
-
+ $geoip = new Horde_Nls_Geoip($datafile);
return $geoip->getCountryInfo($checkHost);
}
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
- * @author Michael Slusarz <slusarz@horde.org>
- * @package Horde_NLS
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package Nls
*/
class Horde_Nls_Geoip
{
const STANDARD_RECORD_LENGTH = 3;
/**
- * The singleton instance.
- *
- * @var Horde_Nls_Geoip
- */
- static protected $_instance;
-
- /**
* Country list.
*
* @var array
protected $_fh;
/**
- * Returns a reference to the global Horde_Nls_GeoIP object, only creating
- * it if it doesn't already exist.
- *
- * This method must be invoked as:
- * $geoip = Horde_Nls_Geoip::singleton($datafile);
- *
- * @param string $datafile The location of the GeoIP database.
- *
- * @return object Horde_Nls_Geoip The object instance.
- */
- static public function singleton($datafile)
- {
- if (!isset(self::$_instance)) {
- self::$_instance = new self($datafile);
- }
-
- return self::$_instance;
- }
-
- /**
* Constructor.
*
* @param string $datafile The location of the GeoIP database.
*/
static public function generateFlagImageByHost($host)
{
- $data = Horde_Nls::getCountryByHost($host);
+ $data = Horde_Nls::getCountryByHost($host, empty($GLOBALS['conf']['geoip']['datafile']) ? null : $GLOBALS['conf']['geoip']['datafile']);
+ );
if ($data === false) {
return '';
}