_setup_segments

The Google Font Fix setup segments function.

Description

_setup_segments( $gi ); 

Parameters (1)

0. $gi
The gi.

Usage

  1. if ( !function_exists( '_setup_segments' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-font-fix/geo/geoip.inc.php'; 
  3.  
  4. // The gi. 
  5. $gi = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _setup_segments($gi); 
  9.  

Defined (1)

The function is defined in the following location(s).

/geo/geoip.inc.php  
  1. function _setup_segments($gi) 
  2. $gi->databaseType = GEOIP_COUNTRY_EDITION
  3. $gi->record_length = STANDARD_RECORD_LENGTH
  4. if ($gi->flags & GEOIP_SHARED_MEMORY) { 
  5. $offset = shmop_size($gi->shmid) - 3; 
  6. for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { 
  7. $delim = shmop_read($gi->shmid, $offset, 3); 
  8. $offset += 3; 
  9. if ($delim == (chr(255) . chr(255) . chr(255))) { 
  10. $gi->databaseType = ord(shmop_read($gi->shmid, $offset, 1)); 
  11. if ($gi->databaseType >= 106) { 
  12. $gi->databaseType -= 105; 
  13. $offset++; 
  14.  
  15. if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { 
  16. $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0
  17. } elseif ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { 
  18. $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1
  19. } elseif (($gi->databaseType == GEOIP_CITY_EDITION_REV0
  20. || ($gi->databaseType == GEOIP_CITY_EDITION_REV1
  21. || ($gi->databaseType == GEOIP_ORG_EDITION
  22. || ($gi->databaseType == GEOIP_ORG_EDITION_V6
  23. || ($gi->databaseType == GEOIP_DOMAIN_EDITION
  24. || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6
  25. || ($gi->databaseType == GEOIP_ISP_EDITION
  26. || ($gi->databaseType == GEOIP_ISP_EDITION_V6
  27. || ($gi->databaseType == GEOIP_USERTYPE_EDITION
  28. || ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6
  29. || ($gi->databaseType == GEOIP_LOCATIONA_EDITION
  30. || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION
  31. || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6
  32. || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6
  33. || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1
  34. || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6
  35. || ($gi->databaseType == GEOIP_ASNUM_EDITION
  36. || ($gi->databaseType == GEOIP_ASNUM_EDITION_V6
  37. ) { 
  38. $gi->databaseSegments = 0; 
  39. $buf = shmop_read($gi->shmid, $offset, SEGMENT_RECORD_LENGTH); 
  40. for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) { 
  41. $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); 
  42. if (($gi->databaseType == GEOIP_ORG_EDITION
  43. || ($gi->databaseType == GEOIP_ORG_EDITION_V6
  44. || ($gi->databaseType == GEOIP_DOMAIN_EDITION
  45. || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6
  46. || ($gi->databaseType == GEOIP_ISP_EDITION
  47. || ($gi->databaseType == GEOIP_ISP_EDITION_V6
  48. ) { 
  49. $gi->record_length = ORG_RECORD_LENGTH
  50. break; 
  51. } else { 
  52. $offset -= 4; 
  53. if (($gi->databaseType == GEOIP_COUNTRY_EDITION) || 
  54. ($gi->databaseType == GEOIP_COUNTRY_EDITION_V6) || 
  55. ($gi->databaseType == GEOIP_PROXY_EDITION) || 
  56. ($gi->databaseType == GEOIP_NETSPEED_EDITION
  57. ) { 
  58. $gi->databaseSegments = GEOIP_COUNTRY_BEGIN
  59. } else { 
  60. $filepos = ftell($gi->filehandle); 
  61. fseek($gi->filehandle, -3, SEEK_END); 
  62. for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { 
  63. $delim = fread($gi->filehandle, 3); 
  64. if ($delim == (chr(255) . chr(255) . chr(255))) { 
  65. $gi->databaseType = ord(fread($gi->filehandle, 1)); 
  66. if ($gi->databaseType >= 106) { 
  67. $gi->databaseType -= 105; 
  68. if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { 
  69. $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0
  70. } elseif ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { 
  71. $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1
  72. } elseif (($gi->databaseType == GEOIP_CITY_EDITION_REV0
  73. || ($gi->databaseType == GEOIP_CITY_EDITION_REV1
  74. || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6
  75. || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6
  76. || ($gi->databaseType == GEOIP_ORG_EDITION
  77. || ($gi->databaseType == GEOIP_DOMAIN_EDITION
  78. || ($gi->databaseType == GEOIP_ISP_EDITION
  79. || ($gi->databaseType == GEOIP_ORG_EDITION_V6
  80. || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6
  81. || ($gi->databaseType == GEOIP_ISP_EDITION_V6
  82. || ($gi->databaseType == GEOIP_LOCATIONA_EDITION
  83. || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION
  84. || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6
  85. || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6
  86. || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1
  87. || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6
  88. || ($gi->databaseType == GEOIP_USERTYPE_EDITION
  89. || ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6
  90. || ($gi->databaseType == GEOIP_ASNUM_EDITION
  91. || ($gi->databaseType == GEOIP_ASNUM_EDITION_V6
  92. ) { 
  93. $gi->databaseSegments = 0; 
  94.  
  95. $buf = fread($gi->filehandle, SEGMENT_RECORD_LENGTH); 
  96. for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) { 
  97. $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); 
  98. if (($gi->databaseType == GEOIP_ORG_EDITION
  99. || ($gi->databaseType == GEOIP_DOMAIN_EDITION
  100. || ($gi->databaseType == GEOIP_ISP_EDITION
  101. || ($gi->databaseType == GEOIP_ORG_EDITION_V6
  102. || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6
  103. || ($gi->databaseType == GEOIP_ISP_EDITION_V6
  104. ) { 
  105. $gi->record_length = ORG_RECORD_LENGTH
  106. break; 
  107. } else { 
  108. fseek($gi->filehandle, -4, SEEK_CUR); 
  109. if (($gi->databaseType == GEOIP_COUNTRY_EDITION) || 
  110. ($gi->databaseType == GEOIP_COUNTRY_EDITION_V6) || 
  111. ($gi->databaseType == GEOIP_PROXY_EDITION) || 
  112. ($gi->databaseType == GEOIP_NETSPEED_EDITION
  113. ) { 
  114. $gi->databaseSegments = GEOIP_COUNTRY_BEGIN
  115. fseek($gi->filehandle, $filepos, SEEK_SET); 
  116. return $gi;