maxmind->queriesRemaining; // This seems to be approximate. update_option('geoip-detect-precision-remaining_credits', $credits); } return $ret; } public function close() { } } class PrecisionDataSource extends AbstractDataSource { protected $known_api_types = array( 'country' => array('label' => 'Country'), 'city' => array('label' => 'City'), 'insights' => array('label' => 'Insights')); public function __construct() { parent::__construct(); } public function getId() { return 'precision'; } public function getLabel() { return __('Maxmind Precision Web-API', 'geoip-detect'); } public function getDescriptionHTML() { return __('Maxmind Precision Services', 'geoip-detect'); } public function getStatusInformationHTML() { $html = ''; $html .= sprintf(__('API Type: %s', 'geoip-detect'), ucfirst(get_option('geoip-detect-precision_api_type', 'city'))) . '
'; $remaining = get_option('geoip-detect-precision-remaining_credits'); if ($remaining !== false) { $html .= sprintf(__('Remaining Credits: ca. %s', 'geoip-detect'), $remaining) . '
'; } if (!$this->isWorking()) $html .= '
' . __('Maxmind Precision only works with a given user id and secret.', 'geoip-detect') . '
'; return $html; } public function getParameterHTML() { $user_id = (int) get_option('geoip-detect-precision-user_id'); $user_secret = esc_attr(get_option('geoip-detect-precision-user_secret')); $current_api_type = get_option('geoip-detect-precision_api_type'); $label_user_id = __('User ID:', 'geoip-detect'); $label_user_secret = __('License key:', 'geoip-detect'); $label_api_type = __('API Type:', 'geoip-detect'); $html = <<
$label_user_secret
$label_api_type '; return $html; } public function saveParameters($post) { $message = ''; if (isset($post['options_precision']['user_id'])) { $user_id = (int) $post['options_precision']['user_id']; update_option('geoip-detect-precision-user_id', $user_id); } if (isset($post['options_precision']['user_secret'])) { $user_secret = trim($post['options_precision']['user_secret']); 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 (geoip_detect2_is_source_active('precision') && !$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());