function testUpdate()
 {
     $this->assertTrue(geoip_detect_update());
     $record = geoip_detect_get_info_from_ip(GEOIP_DETECT_TEST_IP);
     $this->assertValidGeoIPRecord($record, GEOIP_DETECT_TEST_IP);
     $record = geoip_detect_get_info_from_ip('192.168.1.1');
     $this->assertValidGeoIPRecord($record, '192.168.1.1');
 }
 function testManualInstall()
 {
     $ret = @copy(GEOIP_DETECT_TEST_DB_FILENAME, TEST_GEOIP_PLUGIN_DATA_FILENAME);
     if (!$ret) {
         $this->skip('Test could not be executed: Copy failed');
     }
     $this->assertNotSame('', geoip_detect_get_abs_db_filename(), 'Did not detect manual database');
     $record = geoip_detect_get_info_from_ip(GEOIP_DETECT_TEST_IP);
     $this->assertValidGeoIPRecord($record, GEOIP_DETECT_TEST_IP);
 }
示例#3
0
/**
 * If no information was found, use the external IP of the server and try again.
 * This is necessary to allow local development servers to return sensical data.
 * 
 * @param geoiprecord $record Information found.
 * @return geoiprecord	Hopefully more accurate information. 
 */
function geoip_detect_add_external_ip($record)
{
    static $avoid_recursion = false;
    // Flag in order to retry only once
    if ($avoid_recursion) {
        return $record;
    }
    // This is the retry with the external adress, so don't do anything
    if (!is_object($record)) {
        $external_ip = geoip_detect_get_external_ip_adress();
        $avoid_recursion = true;
        $record = geoip_detect_get_info_from_ip($external_ip);
        $avoid_recursion = false;
    }
    return $record;
}
function geoip_detect_plugin_page()
{
    geoip_detect_set_cron_schedule();
    $ip_lookup_result = false;
    $last_update = 0;
    $message = '';
    switch (@$_POST['action']) {
        case 'update':
            $ret = geoip_detect_update();
            if ($ret === true) {
                $message .= __('Updated successfully.', 'geoip-detect');
            } else {
                $message .= __('Update failed.', 'geoip-detect') . ' ' . $ret;
            }
            break;
        case 'lookup':
            if (isset($_POST['ip'])) {
                $ip = $_POST['ip'];
                $ip_lookup_result = geoip_detect_get_info_from_ip($ip);
            }
            break;
        case 'options':
            $opt_value = isset($_POST['options']['set_css_country']) ? (int) $_POST['options']['set_css_country'] : 0;
            update_option('geoip-detect-set_css_country', $opt_value);
            $opt_value = isset($_POST['options']['data_filename']) ? $_POST['options']['data_filename'] : 'GeoLiteCity.dat';
            update_option('geoip-detect-data_filename', $opt_value);
            break;
    }
    $data_file = geoip_detect_get_abs_db_filename();
    if (file_exists($data_file)) {
        $last_update = filemtime($data_file);
    } else {
        $message .= __('No GeoIP Database found. Click on the button "Update now" or follow the installation instructions.', 'geoip-detect');
        $last_update = 0;
    }
    if (empty($custom_filename)) {
        $next_cron_update = wp_next_scheduled('geoipdetectupdate');
    }
    $options = array();
    $options['set_css_country'] = (int) get_option('geoip-detect-set_css_country');
    $options['data_filename'] = get_option('geoip-detect-data_filename');
    include_once dirname(__FILE__) . '/views/plugin_page.php';
}
示例#5
0
/**
 * Get Geo-Information for the current IP
 * @param string 		$ip (IPv4)
 * @return geoiprecord	GeoInformation. (0 / NULL: no infos found.)
 */
function geoip_detect_get_info_from_current_ip()
{
    // TODO: Use Proxy IP if available
    return geoip_detect_get_info_from_ip(@$_SERVER['REMOTE_ADDR']);
}
 public function process_feed($feed, $entry, $form)
 {
     $geoip_data = array();
     $this->log_debug('Processing feed.');
     // login to Bitrix24
     $api = $this->get_api();
     if (!is_object($api)) {
         $this->log_error('Failed to set up the API');
         return null;
     }
     // retrieve name => value pairs for all fields mapped in the 'mappedFields' field map
     $field_map = $this->get_field_map_fields($feed, 'mappedFields');
     $merge_vars = array();
     foreach ($field_map as $name => $field_id) {
         // $field_id can also be a string like 'date_created'
         switch (strtolower($field_id)) {
             case 'geoip_country':
             case 'geoip_city':
                 if (function_exists('geoip_detect_get_info_from_ip')) {
                     if (!$geoip_data) {
                         $geoip_data = geoip_detect_get_info_from_ip(@$_SERVER['REMOTE_ADDR']);
                     }
                     $geoip_field_key = $field_id == 'geoip_country' ? 'country_name' : 'city';
                     $merge_vars[$name] = $geoip_data->{$geoip_field_key};
                 }
                 break;
             case 'browser_name':
                 $merge_vars[$name] = @$_SERVER['HTTP_USER_AGENT'];
                 break;
             case 'form_title':
                 $merge_vars[$name] = rgar($form, 'title');
                 break;
             case 'date_created':
             case 'ip':
             case 'source_url':
                 $merge_vars[$name] = rgar($entry, strtolower($field_id));
                 break;
             default:
                 $field = RGFormsModel::get_field($form, $field_id);
                 $is_integer = $field_id == intval($field_id);
                 $input_type = RGFormsModel::get_input_type($field);
                 $field_value = rgar($entry, $field_id);
                 if (in_array($name, array('EMAIL', 'PHONE', 'WEB', 'IM'))) {
                     $merge_vars[$name] = array(array('VALUE' => $field_value, 'VALUE_TYPE' => 'OTHER'));
                 } else {
                     if ($is_integer && $input_type == 'address') {
                         $merge_vars[$name] = $this->get_address($entry, $field_id);
                     } else {
                         if ($is_integer && $input_type == 'name') {
                             $merge_vars[$name] = $this->get_name($entry, $field_id);
                         } else {
                             if ($is_integer && $input_type == 'phone' && $field['phoneFormat'] == 'standard') {
                                 // reformat phone to go to bitrix24 when standard format (US/CAN)
                                 // needs to be in the format NPA-NXX-LINE 404-555-1212 when US/CAN
                                 $phone = $field_value;
                                 if (preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $phone, $matches)) {
                                     $phone = sprintf('%s-%s-%s', $matches[1], $matches[2], $matches[3]);
                                 }
                                 $merge_vars[$name] = $phone;
                             } else {
                                 if ($is_integer && RGFormsModel::get_input_type($field) == 'checkbox') {
                                     $selected = array();
                                     foreach ($field['inputs'] as $input) {
                                         $index = (string) $input['id'];
                                         if (!rgempty($index, $entry)) {
                                             $selected[] = apply_filters('gform_bitrix24_field_value', rgar($entry, $index), $form['id'], $field_id, $entry);
                                         }
                                     }
                                     $merge_vars[$name] = join(', ', $selected);
                                 } else {
                                     $merge_vars[$name] = apply_filters('gform_bitrix24_field_value', $field_value, $form['id'], $field_id, $entry);
                                 }
                             }
                         }
                     }
                 }
         }
     }
     try {
         $response = $api->add($merge_vars);
     } catch (\Bitrix24\Bitrix24ApiException $ex) {
         $this->refresh_token();
         $api = $this->get_api();
         $response = $api->add($merge_vars);
     }
     return $response['result'] > 0;
 }
示例#7
0
 function testRegionName()
 {
     $record = geoip_detect_get_info_from_ip(GEOIP_DETECT_TEST_IP);
     $this->assertGreaterThan(1, strlen($record->region_name), 'Region Name: "' . $record->region_name);
 }
/**
 * Get Geo-Information for the current IP
 * @param string 		$ip (IPv4)
 * @return geoiprecord	GeoInformation. (0 / NULL: no infos found.)
 * @deprecated since v2.0
 */
function geoip_detect_get_info_from_current_ip()
{
    return geoip_detect_get_info_from_ip(geoip_detect2_get_client_ip());
}