You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
615 B

  1. <?php
  2. use GeoIp2\Database\Reader;
  3. register_hook('init', function () {
  4. global $config;
  5. if (isset($config['checkIpLocation']) && !$config['checkIpLocation']) {
  6. return;
  7. }
  8. $reader = new Reader('data/GeoIP/GeoLite2-City.mmdb');
  9. try {
  10. $record = $reader->city($_SERVER['REMOTE_ADDR']);
  11. $config['defaultView']['lat'] = $record->location->latitude;
  12. $config['defaultView']['lon'] = $record->location->longitude;
  13. $config['defaultView']['zoom'] = 10;
  14. }
  15. catch (Exception $e) {
  16. // ignore error
  17. trigger_error("Can't resolve IP address: " . $e->getMessage(), E_USER_WARNING);
  18. }
  19. });