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.

29 lines
727 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. if (!file_exists('data/GeoIP/GeoLite2-City.mmdb')) {
  9. $config['checkIpLocation'] = false;
  10. return;
  11. }
  12. $reader = new Reader('data/GeoIP/GeoLite2-City.mmdb');
  13. try {
  14. $record = $reader->city($_SERVER['REMOTE_ADDR']);
  15. $config['defaultView']['lat'] = $record->location->latitude;
  16. $config['defaultView']['lon'] = $record->location->longitude;
  17. $config['defaultView']['zoom'] = 10;
  18. }
  19. catch (Exception $e) {
  20. // ignore error
  21. trigger_error("Can't resolve IP address: " . $e->getMessage(), E_USER_WARNING);
  22. }
  23. });