コード例 #1
0
 public function testEachSourceForFormalValidity()
 {
     $sources = $this->registry->getAllSources();
     foreach ($sources as $source) {
         $id = $source->getId();
         $this->assertRegExp('/^[-_a-z0-9]+$/i', $id, 'Invalid chars in id name');
         $label = $source->getLabel();
         $this->assertNotEmpty($label, 'Label of "' . $id . '" missing.');
         $desc = geoip_detect2_get_current_source_description($id);
         $this->assertNotEmpty($desc, 'Description of "' . $id . '" missing.');
     }
 }
コード例 #2
0
function _geoip_detect2_get_reader($locales = null, $skipLocaleFilter = false, &$sourceId = '', $options = array())
{
    if (!$skipLocaleFilter) {
        /**
         * Filter: geoip_detect2_locales
         *
         * @param array(string) $locales
         *        	Current locales.
         */
        $locales = apply_filters('geoip_detect2_locales', $locales);
    }
    $reader = null;
    $source = DataSourceRegistry::getInstance()->getCurrentSource();
    if ($source) {
        $reader = $source->getReader($locales, $options);
        $sourceId = $source->getId();
    }
    /**
     * Filter: geoip_detect2_reader
     * You can customize your reader here.
     * This filter will be called for every IP request.
     *
     * @param
     *        	GeoIp2\Database\ProviderInterface Reader (by default: GeoLite City)
     * @param
     *        	array(string)							Locale precedence
     */
    $reader = apply_filters('geoip_detect2_reader', $reader, $locales);
    return $reader;
}
コード例 #3
0
/**
 * @deprecated since 2.4.0
 * @return string
 */
function geoip_detect_get_abs_db_filename()
{
    _doing_it_wrong('GeoIP Detection: geoip_detect_get_abs_db_filename', 'geoip_detect_get_abs_db_filename should not be called directly', '2.4.0');
    $source = \YellowTree\GeoipDetect\DataSources\DataSourceRegistry::getInstance()->getCurrentSource();
    if (method_exists($source, 'maxmindGetFilename')) {
        return $source->maxmindGetFilename();
    }
    return '';
}
コード例 #4
0
 function testDataSourceExists()
 {
     $registry = DataSourceRegistry::getInstance();
     $source = $registry->getCurrentSource();
     $this->assertNotNull($source, "Source was null");
     $this->assertSame('hostinfo', $source->getId(), 'Id of current source is incorrect');
     $reader = $source->getReader();
     $this->assertNotNull($reader, "Reader was null");
 }
コード例 #5
0
 function testDataSourceExists()
 {
     remove_filter('pre_option_geoip-detect-precision-user_secret', array($this, 'filter_set_user_secret'), 101);
     add_filter('pre_option_geoip-detect-precision-user_secret', array($this, 'filter_set_wrong_user_secret'), 102);
     $registry = DataSourceRegistry::getInstance();
     $source = $registry->getCurrentSource();
     $this->assertNotNull($source, "Source was null");
     $this->assertSame('precision', $source->getId(), 'Id of current source is incorrect');
     $reader = $source->getReader();
     $this->assertNotNull($reader, "Reader was null");
 }
コード例 #6
0
<?php

use YellowTree\GeoipDetect\DataSources\DataSourceRegistry;
$date_format = get_option('date_format') . ' ' . get_option('time_format');
$current_source = DataSourceRegistry::getInstance()->getCurrentSource();
$shortcode_options = array();
$shortcode_attr = '';
if (!empty($_POST['locales'])) {
    $shortcode_options['lang'] = $_POST['locales'];
}
if ($shortcode_options) {
    $shortcode_attr = '';
    foreach ($shortcode_options as $key => $value) {
        $shortcode_attr .= ' ' . $key . '="' . esc_attr($value) . '"';
    }
}
?>
<div class="wrap">
	<h1><?php 
_e('GeoIP Detection', 'geoip-detect');
?>
</h1>
	<a href="options-general.php?page=<?php 
echo GEOIP_PLUGIN_BASENAME;
?>
">Options</a>
	
	<p>
		<?php 
printf(__('<b>Selected data source:</b> %s', 'geoip-detect'), geoip_detect2_get_current_source_description());
?>
コード例 #7
0
ファイル: api.php プロジェクト: ryan2407/Vision
/**
 * Return a human-readable label of the currently chosen source.
 * @param string|\YellowTree\GeoipDetect\DataSources\City Id of the source or the returned record
 * @return string The label.
 * 
 * @since 2.3.1
 * @since 2.4.0 new parameter $source
 */
function geoip_detect2_get_current_source_description($source = null)
{
    if (is_object($source) && $source instanceof \YellowTree\GeoipDetect\DataSources\City) {
        $source = $source->extra->source;
    }
    $source = DataSourceRegistry::getInstance()->getSource($source);
    if ($source) {
        return $source->getShortLabel();
    }
    return 'Unknown';
}
コード例 #8
0
function geoip_detect_option_page()
{
    if (!current_user_can('manage_options')) {
        return;
    }
    $registry = DataSourceRegistry::getInstance();
    $sources = $registry->getAllSources();
    $currentSource = $registry->getCurrentSource();
    $message = '';
    $numeric_options = array('set_css_country', 'has_reverse_proxy', 'disable_pagecache');
    $text_options = array('external_ip');
    $option_names = array_merge($numeric_options, $text_options);
    if (geoip_detect_verify_nonce()) {
        switch (@$_POST['action']) {
            case 'update':
                $registry->setCurrentSource('auto');
                $s = new \YellowTree\GeoipDetect\DataSources\Auto\AutoDataSource();
                $ret = $s->maxmindUpdate();
                if ($ret === true) {
                    $message .= __('Updated successfully.', 'geoip-detect');
                } else {
                    $message .= __('Update failed.', 'geoip-detect') . ' ' . $ret;
                }
                break;
            case 'choose':
                $registry->setCurrentSource($_POST['options']['source']);
                $currentSource = $registry->getCurrentSource();
                break;
            case 'options-source':
                $messages = array();
                foreach ($sources as $s) {
                    $ret = $s->saveParameters($_POST);
                    if (is_string($ret) && $ret) {
                        $messages[] = $ret;
                    }
                }
                if ($messages) {
                    $message .= implode('<br />', $messages);
                }
                break;
            case 'options':
                // Empty IP Cache
                delete_transient('geoip_detect_external_ip');
                if (!empty($_POST['options']['external_ip'])) {
                    if (!geoip_detect_is_ip($_POST['options']['external_ip'])) {
                        $message .= 'The external IP "' . esc_html($_POST['options']['external_ip']) . '" is not a valid IP.';
                        unset($_POST['options']['external_ip']);
                    } else {
                        if (!geoip_detect_is_public_ip($_POST['options']['external_ip'])) {
                            $message .= 'Warning: The external IP "' . esc_html($_POST['options']['external_ip']) . '" is not a public internet IP, so it will probably not work.';
                        }
                    }
                }
                foreach ($option_names as $opt_name) {
                    if (in_array($opt_name, $numeric_options)) {
                        $opt_value = isset($_POST['options'][$opt_name]) ? (int) $_POST['options'][$opt_name] : 0;
                    } else {
                        $opt_value = isset($_POST['options'][$opt_name]) ? $_POST['options'][$opt_name] : '';
                    }
                    update_option('geoip-detect-' . $opt_name, $opt_value);
                }
                break;
        }
    }
    $wp_options = array();
    foreach ($option_names as $opt_name) {
        $wp_options[$opt_name] = get_option('geoip-detect-' . $opt_name);
    }
    $ipv6_supported = GEOIP_DETECT_IPV6_SUPPORTED;
    include_once GEOIP_PLUGIN_DIR . '/views/options.php';
}