WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

WC_Geo_IP::_common_get_record() private WC 1.0

Common get record.

{} Это метод класса: WC_Geo_IP{}

Хуков нет.

Возвращает

WC_Geo_IP_Record. instance

Использование

// private - только в коде основоного (родительского) класса
$result = $this->_common_get_record( $seek_country );
$seek_country(строка) (обязательный)

Код WC_Geo_IP::_common_get_record() WC 4.7.1

<?php
private function _common_get_record( $seek_country ) {
	// workaround php's broken substr, strpos, etc handling with
	// mbstring.func_overload and mbstring.internal_encoding
	$mbExists = extension_loaded( 'mbstring' );
	if ( $mbExists ) {
		$enc = mb_internal_encoding();
		mb_internal_encoding( 'ISO-8859-1' );
	}

	$record_pointer = $seek_country + ( 2 * $this->record_length - 1 ) * $this->databaseSegments;

	if ( $this->flags & self::GEOIP_MEMORY_CACHE ) {
		$record_buf = substr( $this->memory_buffer, $record_pointer, FULL_RECORD_LENGTH );
	} elseif ( $this->flags & self::GEOIP_SHARED_MEMORY ) {
		$record_buf = @shmop_read( $this->shmid, $record_pointer, FULL_RECORD_LENGTH );
	} else {
		fseek( $this->filehandle, $record_pointer, SEEK_SET );
		$record_buf = fread( $this->filehandle, FULL_RECORD_LENGTH );
	}

	$record                 = new WC_Geo_IP_Record();
	$record_buf_pos         = 0;
	$char                   = ord( substr( $record_buf, $record_buf_pos, 1 ) );
	$record->country_code   = $this->GEOIP_COUNTRY_CODES[ $char ];
	$record->country_code3  = $this->GEOIP_COUNTRY_CODES3[ $char ];
	$record->country_name   = $this->GEOIP_COUNTRY_NAMES[ $char ];
	$record->continent_code = $this->GEOIP_CONTINENT_CODES[ $char ];
	$str_length             = 0;

	$record_buf_pos++;

	// Get region
	$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
	while ( 0 != $char ) {
		$str_length++;
		$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
	}

	if ( $str_length > 0 ) {
		$record->region = substr( $record_buf, $record_buf_pos, $str_length );
	}

	$record_buf_pos += $str_length + 1;
	$str_length      = 0;

	// Get city
	$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
	while ( 0 != $char ) {
		$str_length++;
		$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
	}

	if ( $str_length > 0 ) {
		$record->city = substr( $record_buf, $record_buf_pos, $str_length );
	}

	$record_buf_pos += $str_length + 1;
	$str_length      = 0;

	// Get postal code
	$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
	while ( 0 != $char ) {
		$str_length++;
		$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
	}

	if ( $str_length > 0 ) {
		$record->postal_code = substr( $record_buf, $record_buf_pos, $str_length );
	}

	$record_buf_pos += $str_length + 1;

	// Get latitude and longitude
	$latitude  = 0;
	$longitude = 0;
	for ( $j = 0; $j < 3; ++$j ) {
		$char      = ord( substr( $record_buf, $record_buf_pos++, 1 ) );
		$latitude += ( $char << ( $j * 8 ) );
	}

	$record->latitude = ( $latitude / 10000 ) - 180;

	for ( $j = 0; $j < 3; ++$j ) {
		$char       = ord( substr( $record_buf, $record_buf_pos++, 1 ) );
		$longitude += ( $char << ( $j * 8 ) );
	}

	$record->longitude = ( $longitude / 10000 ) - 180;

	if ( self::GEOIP_CITY_EDITION_REV1 == $this->databaseType ) {
		$metroarea_combo = 0;
		if ( 'US' === $record->country_code ) {
			for ( $j = 0; $j < 3; ++$j ) {
				$char             = ord( substr( $record_buf, $record_buf_pos++, 1 ) );
				$metroarea_combo += ( $char << ( $j * 8 ) );
			}

			$record->metro_code = $record->dma_code = floor( $metroarea_combo / 1000 );
			$record->area_code  = $metroarea_combo % 1000;
		}
	}

	if ( $mbExists ) {
		mb_internal_encoding( $enc );
	}

	return $record;
}