Exemplo n.º 1
0
 /**
  * Construct new GeoIpTool instance.
  *
  * @param string $file GeoIP database file
  * @param string $flags Flags to pass into geoip_open()
  * @access public
  */
 function GeoIpTool($file, $flags)
 {
     if (!file_exists($file)) {
         if (is_null($file)) {
             $file = '(null)';
         }
         trigger_error("{$file}: No such file or directory; You can download the GeoLite City database for free at Maxmind.com", E_USER_WARNING);
     } elseif (!is_readable($file)) {
         trigger_error("{$file}: The GeoIP database file is not readable, please correct permissions.", E_USER_WARNING);
     } else {
         if ($flags & GEOIP_SHARED_MEMORY) {
             @geoip_load_shared_mem($file);
         }
         $this->__geoip = @geoip_open($file, $flags);
         if (!$this->__geoip) {
             trigger_error("{$file}: Failed to load the GeoIP database!", E_USER_WARNING);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Constructor
  *
  * @param string $config
  */
 public function __construct($config = NULL)
 {
     $this->_config = $config === NULL ? Kohana::$config->load('geoip3') : $config;
     if (!extension_loaded('geoip')) {
         if (!class_exists('GeoIP', FALSE)) {
             // Load MaxMind GeoIP classes
             require_once Kohana::find_file('vendor', 'maxmind/geoip');
             require_once Kohana::find_file('vendor', 'maxmind/geoipcity');
             require_once Kohana::find_file('vendor', 'maxmind/geoipregionvars');
         }
         if ($this->_config->useshm) {
             geoip_load_shared_mem($this->_config->dbfile);
             $this->_geoinstance = geoip_open($this->_config->dbfile, GEOIP_SHARED_MEMORY);
         } else {
             $this->_geoinstance = geoip_open($this->_config->dbfile, GEOIP_STANDARD);
         }
     } else {
         $this->_extension = true;
     }
 }
Exemplo n.º 3
0
 function widget_geotrace($host, $w = '100%', $h = '100%')
 {
     //http://maps.google.com/?ie=UTF8&ll=37.0625,-95.677068&spn=31.013085,55.634766&t=h&z=4
     $p = '';
     // GeoLiteCity
     if (file_exists('GeoLiteCity.dat')) {
         geoip_load_shared_mem('GeoLiteCity.dat');
         $gi = geoip_open('GeoLiteCity.dat', GEOIP_SHARED_MEMORY);
         $host = gethostbyname($host);
         $a = GeoIP_record_by_addr($gi, $host);
         geoip_close($gi);
         // DEBUG
         //      echo '<pre><tt>';
         //      print_r ($a);
         $p .= '' . '<iframe width="' . $w . '" height="' . $h . '"' . ' frameborder="0"' . ' scrolling="no"' . ' marginheight="0"' . ' marginwidth="0"' . ' src="http://www.openstreetmap.org/export/embed.html?bbox=' . ($a->longitude - 0.005) . ',' . ($a->latitude - 0.005) . ',' . ($a->longitude + 0.005) . ',' . ($a->latitude + 0.005) . '&layer=mapnik"' . '>' . '</iframe>';
     }
     return $p;
 }