示例#1
0
            return '';
        }
        try {
            $reader = new \GeoIp2\Database\Reader($filename);
            $metadata = $reader->metadata();
            $reader->close();
        } catch (\Exception $e) {
            if (WP_DEBUG) {
                echo 'Error while creating reader for "' . $filename . '": ' . $e->getMessage();
            }
            return '';
        }
        return $filename;
    }
    protected function maxmindGetFileDescription()
    {
        $reader = $this->getReader();
        if (!method_exists($reader, 'metadata')) {
            return 'Unknown';
        }
        try {
            $metadata = $reader->metadata();
            $desc = $metadata->description;
            return $desc['en'];
        } catch (\Exception $e) {
            return 'Unknown';
        }
    }
}
geoip_detect2_register_source(new ManualDataSource());
示例#2
0
            update_option('geoip-detect-precision-user_secret', $user_secret);
        }
        if (isset($post['options_precision']['api_type'])) {
            if (isset($this->known_api_types[$post['options_precision']['api_type']])) {
                update_option('geoip-detect-precision_api_type', $post['options_precision']['api_type']);
            }
        }
        if (!$this->isWorking()) {
            $message .= __('Maxmind Precision only works with a given user id and secret.', 'geoip-detect');
        }
        return $message;
    }
    public function getReader($locales = array('en'), $options = array())
    {
        if (!$this->isWorking()) {
            return null;
        }
        $user_id = get_option('geoip-detect-precision-user_id');
        $user_secret = get_option('geoip-detect-precision-user_secret');
        $client = new PrecisionReader($user_id, $user_secret, $options);
        return $client;
    }
    public function isWorking()
    {
        $user_id = get_option('geoip-detect-precision-user_id');
        $user_secret = get_option('geoip-detect-precision-user_secret');
        return !(empty($user_id) || empty($user_secret));
    }
}
geoip_detect2_register_source(new PrecisionDataSource());
示例#3
0
         */
        $do_it = apply_filters('geoip_detect_cron_do_update', !GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED, false);
        if ($do_it) {
            $this->maxmindUpdate();
        }
        $this->schedule_next_cron_run();
    }
    public function set_cron_schedule()
    {
        $next = wp_next_scheduled('geoipdetectupdate');
        if (!$next) {
            $this->schedule_next_cron_run();
        }
    }
    public function schedule_next_cron_run()
    {
        // The Lite databases are updated on the first tuesday of each month. Maybe not at midnight, so we schedule it for the night afterwards.
        $next = strtotime('first tuesday of next month + 1 day');
        wp_schedule_single_event($next, 'geoipdetectupdate');
    }
    public function activate()
    {
        $this->set_cron_schedule();
    }
    public function deactivate()
    {
        wp_clear_scheduled_hook('geoipdetectupdate');
    }
}
geoip_detect2_register_source(new AutoDataSource());
    }
    public function getLabel()
    {
        return __('HostIP.info Web-API', 'geoip-detect');
    }
    public function getDescriptionHTML()
    {
        return __('Free (Licence: GPL)<br />(only English names, does only have the following fields: country name, country ID and city name)', 'geoip-detect');
    }
    public function getStatusInformationHTML()
    {
        return __('You can choose a Maxmind database below.', 'geoip-detect');
    }
    public function getParameterHTML()
    {
        return '';
    }
    public function activate()
    {
    }
    public function getReader($locales = array('en'), $options = array())
    {
        return new Reader($options);
    }
    public function isWorking()
    {
        return true;
    }
}
geoip_detect2_register_source(new HostInfoDataSource());