Free version - Commercial Version', 'geoip-detect'); } public function getStatusInformationHTML() { $built = $last_update = 0; $html = array(); $date_format = get_option('date_format') . ' ' . get_option('time_format'); $file = $this->maxmindGetFilename(); if (!$file) return '' . __('No Maxmind database found.', 'geoip-detect') . ''; $relative_file = geoip_detect_get_relative_path(ABSPATH, $file); $html[] = sprintf(__('Database file: %s', 'geoip-detect'), $relative_file); $reader = $this->getReader(); if ($reader) { $metadata = $reader->metadata(); $built = $metadata->buildEpoch; $last_update = is_readable($file) ? filemtime($file) : ''; $html[] = sprintf(__('Last updated: %s', 'geoip-detect'), $last_update ? date_i18n($date_format, $last_update) : __('Never', 'geoip-detect')); $html[] = sprintf(__('Database data from: %s', 'geoip-detect'), date_i18n($date_format, $built) ); } return implode('
', $html); } public function getParameterHTML() { $manual_file = esc_attr(get_option('geoip-detect-manual_file')); $current_value = ''; if ( get_option('geoip-detect-manual_file_validated') && get_option('geoip-detect-manual_file') != get_option('geoip-detect-manual_file_validated') && ABSPATH . get_option('geoip-detect-manual_file') != get_option('geoip-detect-manual_file_validated') ) { $current_value = '
' . sprintf(__('Current value: %s', 'geoip-detect'), get_option('geoip-detect-manual_file_validated')); } $label = __('Filepath to mmdb-file:', 'geoip-detect'); $desc = __('e.g. wp-content/uploads/GeoLite2-Country.mmdb or absolute filepath', 'geoip-detect'); $html = <<$label

$desc $current_value
HTML; return $html; } public function saveParameters($post) { $message = ''; $file = isset($post['options_manual']['manual_file']) ? $post['options_manual']['manual_file'] : ''; if (!empty($file)) { update_option('geoip-detect-manual_file', $file); $validated_filename = self::maxmindValidateFilename($file); if (empty($validated_filename)) { $message .= __('The manual datafile has not been found or is not a mmdb-File. ', 'geoip-detect'); } else { update_option('geoip-detect-manual_file_validated', $validated_filename); } } return $message; } public function getShortLabel() { return $this->maxmindGetFileDescription(); } public function getReader($locales = array('en'), $options = array()) { $reader = null; $data_file = $this->maxmindGetFilename(); if ($data_file) { try { $reader = new \GeoIp2\Database\Reader ( $data_file, $locales ); } catch ( \Exception $e ) { if (WP_DEBUG) printf(__('Error while creating reader for "%s": %s', 'geoip-detect'), $data_file, $e->getMessage()); } } return $reader; } public function isWorking() { $filename = $this->maxmindGetFilename(); if (!is_readable($filename)) return false; return true; } public function maxmindGetFilename() { $data_filename = get_option('geoip-detect-manual_file_validated'); // Allow placing the file in the plugin folder for backwards compat if (!$data_filename || !file_exists($data_filename)) { $data_filename = GEOIP_PLUGIN_DIR . '/' . GEOIP_DETECT_DATA_FILENAME; } if (!file_exists($data_filename)) { // Maybe site root changed? $data_filename = $this->maxmindValidateFilename(get_option('geoip-detect-manual_file')); } $data_filename = apply_filters('geoip_detect_get_abs_db_filename', $data_filename); return $data_filename; } public static function maxmindValidateFilename($filename) { // Maybe make path absolute if (file_exists(ABSPATH . $filename)) $filename = ABSPATH . $filename; if (!is_readable($filename)) return ''; try { $reader = new \GeoIp2\Database\Reader($filename); $reader->metadata(); /* Try to read from it ... the result doesn't actually interest me. */ $reader->close(); } catch ( \Exception $e ) { // Not readable, so do not accept this filename return ''; } return $filename; } protected function maxmindGetFileDescription() { $reader = $this->getReader(); if (!method_exists($reader, 'metadata')) return __('Maxmind File Database (file does not exist or is not readable)', 'geoip-detect'); try { $metadata = $reader->metadata(); $desc = $metadata->description; return $desc['en']; } catch (\Exception $e) { return __('Maxmind File Database (file does not exist or is not readable)', 'geoip-detect'); } } } geoip_detect2_register_source(new ManualDataSource());