示例#1
0
function geoip_detect2_add_body_classes($classes)
{
    if (!get_option('geoip-detect-set_css_country')) {
        return $classes;
    }
    $info = geoip_detect2_get_info_from_current_ip();
    if ($info->country->isoCode) {
        $classes[] = 'geoip-country-' . $info->country->isoCode;
    }
    if ($info->continent->code) {
        $classes[] = 'geoip-continent-' . $info->continent->code;
    }
    return $classes;
}
/**
 * Short Code
 * 
 * Examples:
 * `[geoip_detect2 property="country"]` -> Germany
 * `[geoip_detect2 property="country.isoCode"]` -> de
 * 
 * `[geoip_detect2 property="country" lang="de"]` -> Deutschland
 * `[geoip_detect2 property="country" lang="fr,de"]` -> Allemagne
 * `[geoip_detect2 property="country.confidence" default="default value"]` -> default value
 * 
 * @param string $property		Property to read. Instead of '->', use '.'
 * @param string $lang			Language(s) (optional. If not set, current site language is used.)
 * @param string $default 		Default Value that will be shown if value not set (optional)
 * @param string $skipCache		if 'true': Do not cache value
 */
function geoip_detect2_shortcode($attr)
{
    $skipCache = isset($attr['skip_cache']) && (strtolower($attr['skip_cache']) == 'true' || $attr['skip_cache'] == '1');
    $locales = isset($attr['lang']) ? $attr['lang'] . ',en' : 'en';
    $locales = apply_filters('geoip_detect2_locales', $locales);
    $defaultValue = isset($attr['default']) ? $attr['default'] : '';
    $properties = explode('.', $attr['property']);
    $options = array('skipCache' => $skipCache);
    $userInfo = geoip_detect2_get_info_from_current_ip($locales, $options);
    if ($userInfo->isEmpty) {
        return $defaultValue . '<!-- GeoIP Detect: No information found for this IP (' . geoip_detect2_get_client_ip() . ') -->';
    }
    $return = '';
    try {
        if (count($properties) == 1) {
            $return = $userInfo->{$properties[0]};
        } else {
            if (count($properties) == 2) {
                $return = $userInfo->{$properties[0]};
                if (!is_object($return)) {
                    throw new \RuntimeException('Invalid property name.');
                }
                $return = $return->{$properties[1]};
            } else {
                throw new \RuntimeException('Only 1 dot supported. Please send a bug report to show me the shortcode you used if you need it ...');
            }
        }
    } catch (\RuntimeException $e) {
        return $defaultValue . '<!-- GeoIP Detect: Invalid property name. -->';
    }
    if (is_object($return) && $return instanceof \GeoIp2\Record\AbstractPlaceRecord) {
        $return = $return->name;
    }
    if (is_object($return) || is_array($return)) {
        return $defaultValue . '<!-- GeoIP Detect: Invalid property name (sub-property missing). -->';
    }
    if ($return) {
        return (string) $return;
    } else {
        return $defaultValue;
    }
}
function salesforce_w2l_field_value_geoip_example($val, $field, $form)
{
    if (!function_exists('geoip_detect2_get_info_from_current_ip')) {
        return;
    }
    $form_id = 1;
    // form id to act upon
    $field_name = 'country__c';
    // API Name of the field your want to autofill
    if ($form == $form_id && $field_name == $field) {
        $userInfo = geoip_detect2_get_info_from_current_ip();
        //$val = $userInfo->country->isoCode; // e.g. US
        $val = $userInfo->country->name;
        // e.g. United States
    }
    return $val;
}
<div style="margin:0px auto;max-width: 800px;">

	<?php 
$geo = geoip_detect2_get_info_from_current_ip();
$geo_state = $geo->mostSpecificSubdivision->name;
$theme = site_url() . '/wp-content/themes/coverguy-original/images/';
if (CG_LOCAL == 'US_EN') {
    $reg_state = array('California', 'Washington', 'Oregon', 'Idaho', 'Nevada', 'Utah', 'New Mexico', 'Arizona', 'Colorado', 'Texas', 'Oklahoma', 'Kansas', 'Montana', 'Wyoming', 'South Dekota', 'Nebraska', 'Florida', 'Georgia', 'Alabama', 'Louisiana', 'Mississippi', 'Arkansas', 'Hawaii', 'South Carolina', 'Tennessee', 'Kentucky', 'Missouri');
    if (in_array($geo_state, $reg_state)) {
        ?>

	<div class="indexImage" style="background-image: url('<?php 
        echo $theme;
        ?>
index_top_US_EN_harsh.jpg');position:relative;">
		<div class="indexBlock" style="font-size: 31px;padding-top:25px;padding-left:23px;">Made to handle all of<br/><?php 
        echo $geo_state;
        ?>
's Climates</div>
	</div>

	<?php 
    } else {
        ?>
		
		<?php 
        if (!$geo_state) {
            $geo_state = 'North America';
        }
        ?>
		
 function testCurrentIp()
 {
     $record = geoip_detect2_get_info_from_current_ip();
     $this->assertValidGeoIP2Record($record, 'current_ip');
 }