function get_ip_record($user_ip) { global $path_visitor_maps; //假定 GeoLiteCity.data 放在与此文件同一目录下 $gi = geoip_open_VMWO(__DIR__ . '/GeoLiteCity.dat', VMWO_GEOIP_STANDARD); $record = geoip_record_by_addr_VMWO($gi, "{$user_ip}"); geoip_close_VMWO($gi); //你可以直接使用上面取出的 $record 数据 return $record; }
$subj = str_replace('[' . $key . ']', $data, $subj); } } $subj = preg_replace('/(\\[ex_field)(\\d+)(\\])/', '', $subj); // remove empty ex_field tags $posted_form_name = $si_contact_opt['form_name'] != '' ? $si_contact_opt['form_name'] : sprintf(__('Form: %d', 'si-contact-form'), $form_id_num); $subj = str_replace('[form_label]', $posted_form_name, $subj); $posted_data['subject'] = $subj; // lookup country info for this ip // geoip lookup using Visitor Maps and Who's Online plugin $geo_loc = ''; if ($si_contact_opt['sender_info_enable'] == 'true' && file_exists(WP_PLUGIN_DIR . '/visitor-maps/include-whos-online-geoip.php') && file_exists(WP_PLUGIN_DIR . '/visitor-maps/GeoLiteCity.dat')) { require_once WP_PLUGIN_DIR . '/visitor-maps/include-whos-online-geoip.php'; $gi = geoip_open_VMWO(WP_PLUGIN_DIR . '/visitor-maps/GeoLiteCity.dat', VMWO_GEOIP_STANDARD); $record = geoip_record_by_addr_VMWO($gi, $_SERVER['REMOTE_ADDR']); geoip_close_VMWO($gi); $li = array(); $li['city_name'] = isset($record->city) ? $record->city : ''; $li['state_name'] = isset($record->country_code) && isset($record->region) ? $GEOIP_REGION_NAME[$record->country_code][$record->region] : ''; $li['state_code'] = isset($record->region) ? strtoupper($record->region) : ''; $li['country_name'] = isset($record->country_name) ? $record->country_name : '--'; $li['country_code'] = isset($record->country_code) ? strtoupper($record->country_code) : '--'; $li['latitude'] = isset($record->latitude) ? $record->latitude : '0'; $li['longitude'] = isset($record->longitude) ? $record->longitude : '0'; if ($li['city_name'] != '') { if ($li['country_code'] == 'US') { $geo_loc = $li['city_name']; if ($li['state_code'] != '') { $geo_loc = $li['city_name'] . ', ' . strtoupper($li['state_code']); } } else {
static function get_user_info() { // Gathers user info to include in the email message // Returns the user info string global $current_user, $user_ID; // see if current WP user get_currentuserinfo(); // lookup country info for this ip // geoip lookup using Visitor Maps and Who's Online plugin $geo_loc = ''; if (file_exists(WP_PLUGIN_DIR . '/visitor-maps/include-whos-online-geoip.php') && file_exists(WP_PLUGIN_DIR . '/visitor-maps/GeoLiteCity.dat')) { require_once WP_PLUGIN_DIR . '/visitor-maps/include-whos-online-geoip.php'; $gi = geoip_open_VMWO(WP_PLUGIN_DIR . '/visitor-maps/GeoLiteCity.dat', VMWO_GEOIP_STANDARD); $record = geoip_record_by_addr_VMWO($gi, $_SERVER['REMOTE_ADDR']); geoip_close_VMWO($gi); $li = array(); $li['city_name'] = isset($record->city) ? $record->city : ''; $li['state_name'] = isset($record->country_code) && isset($record->region) ? $GEOIP_REGION_NAME[$record->country_code][$record->region] : ''; $li['state_code'] = isset($record->region) ? strtoupper($record->region) : ''; $li['country_name'] = isset($record->country_name) ? $record->country_name : '--'; $li['country_code'] = isset($record->country_code) ? strtoupper($record->country_code) : '--'; $li['latitude'] = isset($record->latitude) ? $record->latitude : '0'; $li['longitude'] = isset($record->longitude) ? $record->longitude : '0'; if ($li['city_name'] != '') { if ($li['country_code'] == 'US') { $geo_loc = $li['city_name']; if ($li['state_code'] != '') { $geo_loc = $li['city_name'] . ', ' . strtoupper($li['state_code']) . self::$php_eol; } } else { // all non us countries $geo_loc = $li['city_name'] . ', ' . strtoupper($li['country_code']) . self::$php_eol; } } else { $geo_loc = '~ ' . $li['country_name'] . self::$php_eol; } $geo_loc .= 'http://maps.google.com/maps?q=' . $li['latitude'] . ',' . $li['longitude']; } // add some info about sender to the email message $userdomain = ''; $userdomain = gethostbyaddr($_SERVER['REMOTE_ADDR']); $user_info_string = ''; $user_info = array(); if (self::$form_options['email_html'] == 'true') { $user_info_string = '<div style="background:#eee;border:1px solid gray;color:gray;padding:1em;margin:1em 0;">'; } if ($user_ID != '') { //user logged in if ($current_user->user_login != '') { $user_info['wp_user'] = __('From a WordPress user', 'si-contact-form') . ': ' . $current_user->user_login; } if ($current_user->user_email != '') { $user_info['wp_user_email'] = __('User email', 'si-contact-form') . ': ' . $current_user->user_email; } if ($current_user->user_firstname != '') { $user_info['wp_user_first_name'] = __('User first name', 'si-contact-form') . ': ' . $current_user->user_firstname; } if ($current_user->user_lastname != '') { $user_info['wp_user_last_name'] = __('User last name', 'si-contact-form') . ': ' . $current_user->user_lastname; } if ($current_user->display_name != '') { $user_info['wp_user_display_name'] = __('User display name', 'si-contact-form') . ': ' . $current_user->display_name; } } $user_info['wp_user_ip'] = __('Sent from (ip address)', 'si-contact-form') . ': ' . esc_attr($_SERVER['REMOTE_ADDR']) . " ({$userdomain})"; if ($geo_loc != '') { $user_info['wp_user_location'] = __('Location', 'si-contact-form') . ': ' . $geo_loc; self::$form_data['sender_location'] = __('Location', 'si-contact-form') . ': ' . $geo_loc; } $user_info['wp_user_date'] = __('Date/Time', 'si-contact-form') . ': ' . date_i18n(get_option('date_format') . ' ' . get_option('time_format'), current_time('timestamp')); $user_info['wp_user_referer'] = __('Coming from (referer)', 'si-contact-form') . ': ' . esc_url(self::$form_action_url); $user_info['wp_user_agent'] = __('Using (user agent)', 'si-contact-form') . ': ' . FSCF_Util::clean_input($_SERVER['HTTP_USER_AGENT']) . self::$php_eol; // filter hook to allow modify $user_info array $user_info = apply_filters('si_contact_user_info', $user_info, self::$form_id_num); foreach ($user_info as $k => $v) { $user_info_string .= $v . self::$php_eol; } if (self::$form_options['email_html'] == 'true') { $user_info_string .= '</div>'; } return $user_info_string; }
function get_location_info($user_ip) { // this function looks up location info from the maxmind geoip database // and returns country_info array // lookup country info for this ip // geoip lookup require_once $this->setting['geolite_path'] . 'include-whos-online-geoip.php'; $gi = geoip_open_VMWO($this->setting['geolite_path'] . 'GeoLiteCity.dat', VMWO_GEOIP_STANDARD); $record = geoip_record_by_addr_VMWO($gi, "{$user_ip}"); geoip_close_VMWO($gi); $location_info = array(); // Create Result Array $location_info['provider'] = ''; $location_info['city_name'] = isset($record->city) ? $record->city : '~'; $location_info['state_name'] = isset($record->country_code) && isset($record->region) ? $GEOIP_REGION_NAME[$record->country_code][$record->region] : '~'; $location_info['state_code'] = isset($record->region) ? strtoupper($record->region) : '~'; $location_info['country_name'] = isset($record->country_name) ? $record->country_name : '~'; $location_info['country_code'] = isset($record->country_code) ? strtoupper($record->country_code) : '~'; $location_info['latitude'] = isset($record->latitude) ? $record->latitude : '~'; $location_info['longitude'] = isset($record->longitude) ? $record->longitude : '~'; return $location_info; }
function get_location_info($user_ip) { // this function looks up location info from the maxmind geoip database // and returns $country_info array global $path_visitor_maps; // lookup country info for this ip // geoip lookup require_once $path_visitor_maps . 'include-whos-online-geoip.php'; $gi = geoip_open_VMWO($path_visitor_maps . 'GeoLiteCity.dat', VMWO_GEOIP_STANDARD); $record = geoip_record_by_addr_VMWO($gi, "{$user_ip}"); geoip_close_VMWO($gi); $location_info = array(); // Create Result Array $location_info['provider'] = ''; $location_info['city_name'] = isset($record->city) ? $record->city : ''; $location_info['state_name'] = isset($record->country_code) && isset($record->region) ? $GEOIP_REGION_NAME[$record->country_code][$record->region] : ''; $location_info['state_code'] = isset($record->region) ? strtoupper($record->region) : ''; $location_info['country_name'] = isset($record->country_name) ? $record->country_name : '--'; $location_info['country_code'] = isset($record->country_code) ? strtoupper($record->country_code) : '--'; $location_info['latitude'] = isset($record->latitude) ? $record->latitude : '0'; $location_info['longitude'] = isset($record->longitude) ? $record->longitude : '0'; // this fixes accent characters on UTF-8, only when the blog charset is set to UTF-8 if (strtolower(get_option('blog_charset')) == 'utf-8' && function_exists('utf8_encode')) { if ($location_info['city_name'] != '') { $location_info['city_name'] = utf8_encode($location_info['city_name']); } if ($location_info['state_name'] != '') { $location_info['state_name'] = utf8_encode($location_info['state_name']); } if ($location_info['country_name'] != '') { $location_info['country_name'] = utf8_encode($location_info['country_name']); } } return $location_info; }