Version Notes
First stable release
Download this release
Release Info
Developer | Tikhonov Alex |
Extension | BrainActs_RestrictCheckout |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/local/AT/RestrictCheckout/Block/Rewrite/Checkout/Cart/Sidebar.php +27 -0
- app/code/local/AT/RestrictCheckout/Block/Rewrite/Checkout/Onepage/Link.php +24 -0
- app/code/local/AT/RestrictCheckout/Helper/Data.php +235 -0
- app/code/local/AT/RestrictCheckout/Helper/Rewrite/Checkout/Data.php +29 -0
- app/code/local/AT/RestrictCheckout/Model/Observer.php +51 -0
- app/code/local/AT/RestrictCheckout/Model/Rewrite/Catalog/Product.php +29 -0
- app/code/local/AT/RestrictCheckout/Model/System/Config/Source/Country.php +21 -0
- app/code/local/AT/RestrictCheckout/Model/System/Config/Source/Message.php +42 -0
- app/code/local/AT/RestrictCheckout/Model/System/Config/Source/Website.php +47 -0
- app/code/local/AT/RestrictCheckout/etc/config.xml +92 -0
- app/code/local/AT/RestrictCheckout/etc/system.xml +99 -0
- app/etc/modules/AT_RestrictCheckout.xml +9 -0
- app/locale/en_US/AT_RestrictCheckout.csv +9 -0
- lib/AT/MaxMind/GeoIP.php +1873 -0
- package.xml +18 -0
app/code/local/AT/RestrictCheckout/Block/Rewrite/Checkout/Cart/Sidebar.php
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class AT_RestrictCheckout_Block_Rewrite_Checkout_Cart_Sidebar extends Mage_Checkout_Block_Cart_Sidebar
|
4 |
+
{
|
5 |
+
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Check if one page checkout is available
|
9 |
+
*
|
10 |
+
* @return bool
|
11 |
+
*/
|
12 |
+
public function isPossibleOnepageCheckout()
|
13 |
+
{
|
14 |
+
/** @var AT_RestrictCheckout_Helper_Data $helper */
|
15 |
+
$helper = $this->helper('restrictcheckout');
|
16 |
+
|
17 |
+
if ($helper->isEnabled()) {
|
18 |
+
$allow = $helper->validate();
|
19 |
+
|
20 |
+
if (!$allow) {
|
21 |
+
return false;
|
22 |
+
}
|
23 |
+
}
|
24 |
+
|
25 |
+
return parent::isPossibleOnepageCheckout();
|
26 |
+
}
|
27 |
+
}
|
app/code/local/AT/RestrictCheckout/Block/Rewrite/Checkout/Onepage/Link.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class AT_RestrictCheckout_Block_Rewrite_Checkout_Onepage_Link extends Mage_Checkout_Block_Onepage_Link
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* @return bool
|
7 |
+
*/
|
8 |
+
public function isPossibleOnepageCheckout()
|
9 |
+
{
|
10 |
+
|
11 |
+
/** @var AT_RestrictCheckout_Helper_Data $helper */
|
12 |
+
$helper = $this->helper('restrictcheckout');
|
13 |
+
|
14 |
+
if ($helper->isEnabled()) {
|
15 |
+
$allow = $helper->validate();
|
16 |
+
|
17 |
+
if (!$allow) {
|
18 |
+
return false;
|
19 |
+
}
|
20 |
+
}
|
21 |
+
return parent::isPossibleOnepageCheckout();
|
22 |
+
|
23 |
+
}
|
24 |
+
}
|
app/code/local/AT/RestrictCheckout/Helper/Data.php
ADDED
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class AT_RestrictCheckout_Helper_Data extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
const XML_PATH_ENABLED = 'checkout/restriction/enabled';
|
7 |
+
|
8 |
+
const XML_PATH_PERMANENT = 'checkout/restriction/permanent';
|
9 |
+
|
10 |
+
const XML_PATH_GUEST = 'checkout/restriction/guest';
|
11 |
+
|
12 |
+
const XML_PATH_WEBSITE = 'checkout/restriction/website';
|
13 |
+
|
14 |
+
const XML_PATH_RANGES = 'checkout/restriction/zone';
|
15 |
+
|
16 |
+
const XML_PATH_COUNTRY = 'checkout/restriction/country';
|
17 |
+
|
18 |
+
const XML_PATH_MESSAGE_TYPE = 'checkout/restriction/message_type';
|
19 |
+
|
20 |
+
const XML_PATH_MESSAGE = 'checkout/restriction/message';
|
21 |
+
|
22 |
+
public function isEnabled()
|
23 |
+
{
|
24 |
+
return (bool)Mage::getStoreConfig(self::XML_PATH_ENABLED);
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @return bool
|
29 |
+
*/
|
30 |
+
public function validate()
|
31 |
+
{
|
32 |
+
|
33 |
+
$status = Mage::registry('checkoutRestrict');
|
34 |
+
|
35 |
+
if ($status != null) {
|
36 |
+
if ($status == 'deny') {
|
37 |
+
return false;
|
38 |
+
} else {
|
39 |
+
return true;
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
if ($this->isPermanentBlocked()) {
|
45 |
+
$this->setFlagRegistry('deny');
|
46 |
+
return false;
|
47 |
+
}
|
48 |
+
|
49 |
+
if ($this->isGuestBlocked()) {
|
50 |
+
$this->setFlagRegistry('deny');
|
51 |
+
return false;
|
52 |
+
}
|
53 |
+
|
54 |
+
if ($this->isWebsiteBlocked()) {
|
55 |
+
$this->setFlagRegistry('deny');
|
56 |
+
return false;
|
57 |
+
}
|
58 |
+
|
59 |
+
if ($this->isIpBlocked()) {
|
60 |
+
$this->setFlagRegistry('deny');
|
61 |
+
return false;
|
62 |
+
}
|
63 |
+
|
64 |
+
if ($this->isCountryBlocked()) {
|
65 |
+
|
66 |
+
$this->setFlagRegistry('deny');
|
67 |
+
|
68 |
+
return false;
|
69 |
+
}
|
70 |
+
|
71 |
+
|
72 |
+
$this->setFlagRegistry('allow');
|
73 |
+
return true;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* @return bool
|
78 |
+
*/
|
79 |
+
protected function isPermanentBlocked()
|
80 |
+
{
|
81 |
+
return (bool)Mage::getStoreConfig(self::XML_PATH_PERMANENT, Mage::app()->getStore()->getId());
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* @return bool
|
86 |
+
*/
|
87 |
+
protected function isGuestBlocked()
|
88 |
+
{
|
89 |
+
|
90 |
+
/** @var Mage_Customer_Model_Session $session */
|
91 |
+
$session = Mage::getSingleton('customer/session');
|
92 |
+
if ($session->isLoggedIn()) {
|
93 |
+
return false;
|
94 |
+
}
|
95 |
+
|
96 |
+
$status = (bool)Mage::getStoreConfig(self::XML_PATH_GUEST, Mage::app()->getStore()->getId());
|
97 |
+
|
98 |
+
if ($status) {
|
99 |
+
return true;
|
100 |
+
}
|
101 |
+
|
102 |
+
return false;
|
103 |
+
|
104 |
+
}
|
105 |
+
|
106 |
+
|
107 |
+
/**
|
108 |
+
* @return bool
|
109 |
+
*/
|
110 |
+
protected function isWebsiteBlocked()
|
111 |
+
{
|
112 |
+
$website = Mage::getStoreConfig(self::XML_PATH_WEBSITE, Mage::app()->getStore()->getId());
|
113 |
+
if (empty($website)) {
|
114 |
+
return false;
|
115 |
+
}
|
116 |
+
$websites = explode(',', $website);
|
117 |
+
|
118 |
+
if (is_array($websites) && in_array(Mage::app()->getStore()->getWebsiteId(), $websites)) {
|
119 |
+
return true;
|
120 |
+
} else {
|
121 |
+
if (Mage::app()->getStore()->getWebsiteId() == $websites) {
|
122 |
+
return true;
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
return false;
|
127 |
+
}
|
128 |
+
|
129 |
+
protected function isIpBlocked()
|
130 |
+
{
|
131 |
+
/** @var Mage_Core_Helper_Http $helper */
|
132 |
+
$helper = Mage::helper('core/http');
|
133 |
+
$ip = $helper->getRemoteAddr(false);
|
134 |
+
$ip = ip2long($ip);
|
135 |
+
|
136 |
+
$ranges = $this->getRanges();
|
137 |
+
if (!$ranges) {
|
138 |
+
return false;
|
139 |
+
}
|
140 |
+
foreach ($ranges as $item) {
|
141 |
+
|
142 |
+
if ($ip >= $item['low'] && $ip <= $item['high']) {
|
143 |
+
return true;
|
144 |
+
}
|
145 |
+
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
private function getRanges()
|
150 |
+
{
|
151 |
+
|
152 |
+
$data = Mage::getStoreConfig(self::XML_PATH_RANGES, Mage::app()->getStore()->getId());
|
153 |
+
$data = trim($data);
|
154 |
+
if (empty($data)) {
|
155 |
+
return false;
|
156 |
+
}
|
157 |
+
$rangeList = explode(';', $data);
|
158 |
+
|
159 |
+
$result = array();
|
160 |
+
foreach ($rangeList as $rangeItem) {
|
161 |
+
$resultItem = array();
|
162 |
+
$items = explode('-', $rangeItem);
|
163 |
+
if (isset($items[1])) {
|
164 |
+
$resultItem['low'] = ip2long($items[0]);
|
165 |
+
$resultItem['high'] = ip2long($items[1]);
|
166 |
+
}
|
167 |
+
$result[] = $resultItem;
|
168 |
+
}
|
169 |
+
|
170 |
+
|
171 |
+
return $result;
|
172 |
+
}
|
173 |
+
|
174 |
+
|
175 |
+
public function isCountryBlocked()
|
176 |
+
{
|
177 |
+
|
178 |
+
$countries = Mage::getStoreConfig(self::XML_PATH_COUNTRY, Mage::app()->getStore()->getId());
|
179 |
+
|
180 |
+
if (empty($countries)) {
|
181 |
+
return false;
|
182 |
+
}
|
183 |
+
|
184 |
+
$countries = explode(',', $countries);
|
185 |
+
|
186 |
+
|
187 |
+
/** @var Mage_Core_Helper_Http $helper */
|
188 |
+
$helper = Mage::helper('core/http');
|
189 |
+
$ip = $helper->getRemoteAddr(false);
|
190 |
+
|
191 |
+
$wrapper = new AT_MaxMind_GeoIP();
|
192 |
+
$path = Mage::getBaseDir() . '/var/maxmind/GeoIP.dat';
|
193 |
+
|
194 |
+
if (!file_exists($path)){
|
195 |
+
return false;
|
196 |
+
}
|
197 |
+
$gi = $wrapper->geoip_open($path, GEOIP_STANDARD);
|
198 |
+
|
199 |
+
$code = $wrapper->geoip_country_code_by_addr($gi, $ip);
|
200 |
+
$code = strtoupper($code);
|
201 |
+
if (empty($code) || $code == null) {
|
202 |
+
return false;
|
203 |
+
}
|
204 |
+
|
205 |
+
$wrapper->geoip_close();
|
206 |
+
|
207 |
+
|
208 |
+
if (is_array($countries) && in_array($code, $countries)) {
|
209 |
+
return true;
|
210 |
+
} else {
|
211 |
+
if ($code == $countries) {
|
212 |
+
return true;
|
213 |
+
}
|
214 |
+
}
|
215 |
+
|
216 |
+
return false;
|
217 |
+
|
218 |
+
}
|
219 |
+
|
220 |
+
|
221 |
+
public function setFlagRegistry($newStatus)
|
222 |
+
{
|
223 |
+
Mage::unregister('checkoutRestrict');
|
224 |
+
Mage::register('checkoutRestrict', $newStatus);
|
225 |
+
|
226 |
+
|
227 |
+
$type = Mage::getStoreConfig(self::XML_PATH_MESSAGE_TYPE, Mage::app()->getStore()->getId());
|
228 |
+
if ($type == 1 && $newStatus == 'deny') {
|
229 |
+
/** @var Mage_Core_Model_Session $session */
|
230 |
+
$session = Mage::getSingleton('core/session');
|
231 |
+
$session->addNotice(Mage::getStoreConfig(self::XML_PATH_MESSAGE, Mage::app()->getStore()->getId()));
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
}
|
app/code/local/AT/RestrictCheckout/Helper/Rewrite/Checkout/Data.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class AT_RestrictCheckout_Helper_Rewrite_Checkout_Data extends Mage_Checkout_Helper_Data
|
4 |
+
{
|
5 |
+
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Get onepage checkout availability
|
9 |
+
*
|
10 |
+
* @return bool
|
11 |
+
*/
|
12 |
+
public function canOnepageCheckout()
|
13 |
+
{
|
14 |
+
/** @var AT_RestrictCheckout_Helper_Data $helper */
|
15 |
+
$helper = Mage::helper('restrictcheckout');
|
16 |
+
|
17 |
+
if ($helper->isEnabled()) {
|
18 |
+
$allow = $helper->validate();
|
19 |
+
|
20 |
+
if (!$allow) {
|
21 |
+
return false;
|
22 |
+
}
|
23 |
+
}
|
24 |
+
|
25 |
+
return parent::canOnepageCheckout();
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
}
|
app/code/local/AT/RestrictCheckout/Model/Observer.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class AT_RestrictCheckout_Model_Observer
|
4 |
+
{
|
5 |
+
public function validate()
|
6 |
+
{
|
7 |
+
|
8 |
+
/** @var AT_RestrictCheckout_Helper_Data $helper */
|
9 |
+
$helper = Mage::helper('restrictcheckout');
|
10 |
+
|
11 |
+
if ($helper->isEnabled()) {
|
12 |
+
$helper->validate();
|
13 |
+
}
|
14 |
+
|
15 |
+
}
|
16 |
+
|
17 |
+
public function refresh()
|
18 |
+
{
|
19 |
+
Mage::unregister('checkoutRestrict');
|
20 |
+
}
|
21 |
+
|
22 |
+
|
23 |
+
public function removePaypalButtons($observer)
|
24 |
+
{
|
25 |
+
|
26 |
+
/** @var AT_RestrictCheckout_Helper_Data $helper */
|
27 |
+
$helper = Mage::helper('restrictcheckout');
|
28 |
+
|
29 |
+
if ($helper->isEnabled()) {
|
30 |
+
$allow = $helper->validate();
|
31 |
+
|
32 |
+
if (!$allow) {
|
33 |
+
/** @var Mage_Paypal_Block_Express_Shortcut $block */
|
34 |
+
$block = Mage::app()->getLayout()->getBlock('checkout.cart.methods.paypal_express.top');
|
35 |
+
|
36 |
+
if (null !== $block) {
|
37 |
+
$block->setTemplate('at/restrictcheckout/empty.phtml');
|
38 |
+
}
|
39 |
+
|
40 |
+
$block = Mage::app()->getLayout()->getBlock('checkout.cart.methods.paypal_express.bottom');
|
41 |
+
|
42 |
+
if (null !== $block) {
|
43 |
+
$block->setTemplate('at/restrictcheckout/empty.phtml');
|
44 |
+
}
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
return $this;
|
49 |
+
}
|
50 |
+
|
51 |
+
}
|
app/code/local/AT/RestrictCheckout/Model/Rewrite/Catalog/Product.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class AT_RestrictCheckout_Model_Rewrite_Catalog_Product extends Mage_Catalog_Model_Product
|
4 |
+
{
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Check is product available for sale
|
10 |
+
*
|
11 |
+
* @return bool
|
12 |
+
*/
|
13 |
+
public function isSalable()
|
14 |
+
{
|
15 |
+
/** @var AT_RestrictCheckout_Helper_Data $helper */
|
16 |
+
$helper = Mage::helper('restrictcheckout');
|
17 |
+
|
18 |
+
if ($helper->isEnabled()) {
|
19 |
+
$allow = $helper->validate();
|
20 |
+
|
21 |
+
if (!$allow) {
|
22 |
+
return $allow;
|
23 |
+
}
|
24 |
+
}
|
25 |
+
|
26 |
+
return parent::isSalable();
|
27 |
+
|
28 |
+
}
|
29 |
+
}
|
app/code/local/AT/RestrictCheckout/Model/System/Config/Source/Country.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class AT_RestrictCheckout_Model_System_Config_Source_Country
|
4 |
+
{
|
5 |
+
protected $_options;
|
6 |
+
|
7 |
+
public function toOptionArray()
|
8 |
+
{
|
9 |
+
|
10 |
+
if (!$this->_options) {
|
11 |
+
$this->_options = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false);
|
12 |
+
}
|
13 |
+
|
14 |
+
$options = $this->_options;
|
15 |
+
|
16 |
+
array_unshift($options, array('value'=>'', 'label'=> Mage::helper('adminhtml')->__('--Please Select--')));
|
17 |
+
|
18 |
+
|
19 |
+
return $options;
|
20 |
+
}
|
21 |
+
}
|
app/code/local/AT/RestrictCheckout/Model/System/Config/Source/Message.php
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category Mage
|
22 |
+
* @package Mage_Adminhtml
|
23 |
+
* @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
|
28 |
+
class AT_RestrictCheckout_Model_System_Config_Source_Message
|
29 |
+
{
|
30 |
+
protected $_options;
|
31 |
+
|
32 |
+
public function toOptionArray()
|
33 |
+
{
|
34 |
+
if (!$this->_options) {
|
35 |
+
$this->_options = array();
|
36 |
+
$this->_options[] = array('value'=>'0', 'label'=>'None');
|
37 |
+
$this->_options[] = array('value'=>'1', 'label'=>'Magento Message View');
|
38 |
+
//$this->_options[] = array('value'=>'2', 'label'=>'Popup'); //TODO Add logic to view message in popup
|
39 |
+
}
|
40 |
+
return $this->_options;
|
41 |
+
}
|
42 |
+
}
|
app/code/local/AT/RestrictCheckout/Model/System/Config/Source/Website.php
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category Mage
|
22 |
+
* @package Mage_Adminhtml
|
23 |
+
* @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
|
28 |
+
class AT_RestrictCheckout_Model_System_Config_Source_Website
|
29 |
+
{
|
30 |
+
protected $_options;
|
31 |
+
|
32 |
+
public function toOptionArray()
|
33 |
+
{
|
34 |
+
if (!$this->_options) {
|
35 |
+
$this->_options = array();
|
36 |
+
$this->_options[] = array('value'=>'', 'label'=>'--Please Select--');
|
37 |
+
foreach (Mage::app()->getWebsites() as $website) {
|
38 |
+
$id = $website->getId();
|
39 |
+
$name = $website->getName();
|
40 |
+
if ($id!=0) {
|
41 |
+
$this->_options[] = array('value'=>$id, 'label'=>$name);
|
42 |
+
}
|
43 |
+
}
|
44 |
+
}
|
45 |
+
return $this->_options;
|
46 |
+
}
|
47 |
+
}
|
app/code/local/AT/RestrictCheckout/etc/config.xml
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<AT_RestrictCheckout>
|
5 |
+
<version>1.0.0</version>
|
6 |
+
</AT_RestrictCheckout>
|
7 |
+
</modules>
|
8 |
+
<frontend>
|
9 |
+
<events>
|
10 |
+
<controller_action_predispatch>
|
11 |
+
<observers>
|
12 |
+
<checkout_validate_restriction>
|
13 |
+
<type>singleton</type>
|
14 |
+
<class>restrictcheckout/observer</class>
|
15 |
+
<method>validate</method>
|
16 |
+
</checkout_validate_restriction>
|
17 |
+
</observers>
|
18 |
+
</controller_action_predispatch>
|
19 |
+
|
20 |
+
<customer_login>
|
21 |
+
<observers>
|
22 |
+
<checkout_validate_refresh>
|
23 |
+
<type>singleton</type>
|
24 |
+
<class>restrictcheckout/observer</class>
|
25 |
+
<method>refresh</method>
|
26 |
+
</checkout_validate_refresh>
|
27 |
+
</observers>
|
28 |
+
</customer_login>
|
29 |
+
|
30 |
+
<controller_action_layout_render_before_checkout_cart_index>
|
31 |
+
<observers>
|
32 |
+
<checkout_cart_paypal_buttons>
|
33 |
+
<type>singleton</type>
|
34 |
+
<class>restrictcheckout/observer</class>
|
35 |
+
<method>removePaypalButtons</method>
|
36 |
+
</checkout_cart_paypal_buttons>
|
37 |
+
</observers>
|
38 |
+
</controller_action_layout_render_before_checkout_cart_index>
|
39 |
+
</events>
|
40 |
+
|
41 |
+
</frontend>
|
42 |
+
<adminhtml>
|
43 |
+
<translate>
|
44 |
+
<modules>
|
45 |
+
<AT_RestrictCheckout>
|
46 |
+
<files>
|
47 |
+
<default>AT_RestrictCheckout.csv</default>
|
48 |
+
</files>
|
49 |
+
</AT_RestrictCheckout>
|
50 |
+
</modules>
|
51 |
+
</translate>
|
52 |
+
</adminhtml>
|
53 |
+
|
54 |
+
<global>
|
55 |
+
<models>
|
56 |
+
<restrictcheckout>
|
57 |
+
<class>AT_RestrictCheckout_Model</class>
|
58 |
+
</restrictcheckout>
|
59 |
+
<catalog>
|
60 |
+
<rewrite>
|
61 |
+
<product>AT_RestrictCheckout_Model_Rewrite_Catalog_Product</product>
|
62 |
+
</rewrite>
|
63 |
+
</catalog>
|
64 |
+
</models>
|
65 |
+
|
66 |
+
<blocks>
|
67 |
+
<restrictcheckout>
|
68 |
+
<class>AT_RestrictCheckout_Block</class>
|
69 |
+
</restrictcheckout>
|
70 |
+
<checkout>
|
71 |
+
<rewrite>
|
72 |
+
<onepage_link>AT_RestrictCheckout_Block_Rewrite_Checkout_Onepage_Link</onepage_link>
|
73 |
+
<cart_sidebar>AT_RestrictCheckout_Block_Rewrite_Checkout_Cart_Sidebar</cart_sidebar>
|
74 |
+
</rewrite>
|
75 |
+
</checkout>
|
76 |
+
|
77 |
+
</blocks>
|
78 |
+
|
79 |
+
<helpers>
|
80 |
+
<restrictcheckout>
|
81 |
+
<class>AT_RestrictCheckout_Helper</class>
|
82 |
+
</restrictcheckout>
|
83 |
+
<checkout>
|
84 |
+
<rewrite>
|
85 |
+
<data>AT_RestrictCheckout_Helper_Rewrite_Checkout_Data</data>
|
86 |
+
</rewrite>
|
87 |
+
</checkout>
|
88 |
+
</helpers>
|
89 |
+
</global>
|
90 |
+
</config>
|
91 |
+
|
92 |
+
|
app/code/local/AT/RestrictCheckout/etc/system.xml
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<checkout>
|
5 |
+
<groups>
|
6 |
+
<restriction translate="label">
|
7 |
+
<label>Restriction Options</label>
|
8 |
+
<frontend_type>text</frontend_type>
|
9 |
+
<sort_order>100</sort_order>
|
10 |
+
<show_in_default>1</show_in_default>
|
11 |
+
<show_in_website>1</show_in_website>
|
12 |
+
<show_in_store>0</show_in_store>
|
13 |
+
<fields>
|
14 |
+
<enabled translate="label">
|
15 |
+
<label>Enable Restriction</label>
|
16 |
+
<frontend_type>select</frontend_type>
|
17 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
18 |
+
<sort_order>10</sort_order>
|
19 |
+
<show_in_default>1</show_in_default>
|
20 |
+
<show_in_website>1</show_in_website>
|
21 |
+
<show_in_store>0</show_in_store>
|
22 |
+
</enabled>
|
23 |
+
|
24 |
+
<permanent translate="label">
|
25 |
+
<label>Permanent Restriction</label>
|
26 |
+
<frontend_type>select</frontend_type>
|
27 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
28 |
+
<sort_order>20</sort_order>
|
29 |
+
<show_in_default>1</show_in_default>
|
30 |
+
<show_in_website>1</show_in_website>
|
31 |
+
<show_in_store>0</show_in_store>
|
32 |
+
</permanent>
|
33 |
+
|
34 |
+
<guest translate="label">
|
35 |
+
<label>Guest Restriction</label>
|
36 |
+
<frontend_type>select</frontend_type>
|
37 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
38 |
+
<sort_order>30</sort_order>
|
39 |
+
<show_in_default>1</show_in_default>
|
40 |
+
<show_in_website>1</show_in_website>
|
41 |
+
<show_in_store>0</show_in_store>
|
42 |
+
</guest>
|
43 |
+
|
44 |
+
<website translate="label">
|
45 |
+
<label>Block by Website</label>
|
46 |
+
<frontend_type>multiselect</frontend_type>
|
47 |
+
<source_model>restrictcheckout/system_config_source_website</source_model>
|
48 |
+
<sort_order>40</sort_order>
|
49 |
+
<show_in_default>1</show_in_default>
|
50 |
+
<show_in_website>1</show_in_website>
|
51 |
+
<show_in_store>0</show_in_store>
|
52 |
+
</website>
|
53 |
+
|
54 |
+
<zone translate="label">
|
55 |
+
<label>Block by IP Zone</label>
|
56 |
+
<frontend_type>textarea</frontend_type>
|
57 |
+
<sort_order>50</sort_order>
|
58 |
+
<show_in_default>1</show_in_default>
|
59 |
+
<show_in_website>1</show_in_website>
|
60 |
+
<show_in_store>0</show_in_store>
|
61 |
+
<comment>Format: 192.168.1.1-192.168.1.15 separated by semicolon.</comment>
|
62 |
+
</zone>
|
63 |
+
|
64 |
+
<country translate="label">
|
65 |
+
<label>Block by Country</label>
|
66 |
+
<frontend_type>multiselect</frontend_type>
|
67 |
+
<source_model>restrictcheckout/system_config_source_country</source_model>
|
68 |
+
<sort_order>60</sort_order>
|
69 |
+
<show_in_default>1</show_in_default>
|
70 |
+
<show_in_website>1</show_in_website>
|
71 |
+
<show_in_store>0</show_in_store>
|
72 |
+
<comment><![CDATA[To apply this method you should download <a target="_blank" href="http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz">MaxMind database</a> file and put by path [MAGENTO FOLDER]/var/maxmind/GeoIP.dat]]></comment>
|
73 |
+
</country>
|
74 |
+
|
75 |
+
<message_type>
|
76 |
+
<label>Message Type</label>
|
77 |
+
<frontend_type>select</frontend_type>
|
78 |
+
<source_model>restrictcheckout/system_config_source_message</source_model>
|
79 |
+
<sort_order>70</sort_order>
|
80 |
+
<show_in_default>1</show_in_default>
|
81 |
+
<show_in_website>1</show_in_website>
|
82 |
+
<show_in_store>0</show_in_store>
|
83 |
+
</message_type>
|
84 |
+
|
85 |
+
<message translate="label">
|
86 |
+
<label>Message</label>
|
87 |
+
<frontend_type>textarea</frontend_type>
|
88 |
+
<sort_order>80</sort_order>
|
89 |
+
<show_in_default>1</show_in_default>
|
90 |
+
<show_in_website>1</show_in_website>
|
91 |
+
<show_in_store>0</show_in_store>
|
92 |
+
</message>
|
93 |
+
|
94 |
+
</fields>
|
95 |
+
</restriction>
|
96 |
+
</groups>
|
97 |
+
</checkout>
|
98 |
+
</sections>
|
99 |
+
</config>
|
app/etc/modules/AT_RestrictCheckout.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<AT_RestrictCheckout>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
</AT_RestrictCheckout>
|
8 |
+
</modules>
|
9 |
+
</config>
|
app/locale/en_US/AT_RestrictCheckout.csv
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"Restriction Options","Restriction Options"
|
2 |
+
"Enable Restriction","Enable Restriction"
|
3 |
+
"Permanent Restriction","Permanent Restriction"
|
4 |
+
"Guest Restriction","Guest Restriction"
|
5 |
+
"Block by Website","Block by Website"
|
6 |
+
"Block by IP Zone","Block by IP Zone"
|
7 |
+
"Block by Country","Block by Country"
|
8 |
+
"Message Type","Message Type"
|
9 |
+
"Message","Message"
|
lib/AT/MaxMind/GeoIP.php
ADDED
@@ -0,0 +1,1873 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ATE_BEGIN_REV0", 16700000);
|
4 |
+
define("GEOIP_STATE_BEGIN_REV1", 16000000);
|
5 |
+
define("GEOIP_STANDARD", 0);
|
6 |
+
define("GEOIP_MEMORY_CACHE", 1);
|
7 |
+
define("GEOIP_SHARED_MEMORY", 2);
|
8 |
+
define("STRUCTURE_INFO_MAX_SIZE", 20);
|
9 |
+
define("DATABASE_INFO_MAX_SIZE", 100);
|
10 |
+
define("GEOIP_COUNTRY_EDITION", 1);
|
11 |
+
define("GEOIP_PROXY_EDITION", 8);
|
12 |
+
define("GEOIP_ASNUM_EDITION", 9);
|
13 |
+
define("GEOIP_NETSPEED_EDITION", 10);
|
14 |
+
define("GEOIP_REGION_EDITION_REV0", 7);
|
15 |
+
define("GEOIP_REGION_EDITION_REV1", 3);
|
16 |
+
define("GEOIP_CITY_EDITION_REV0", 6);
|
17 |
+
define("GEOIP_CITY_EDITION_REV1", 2);
|
18 |
+
define("GEOIP_ORG_EDITION", 5);
|
19 |
+
define("GEOIP_ISP_EDITION", 4);
|
20 |
+
define("SEGMENT_RECORD_LENGTH", 3);
|
21 |
+
define("STANDARD_RECORD_LENGTH", 3);
|
22 |
+
define("ORG_RECORD_LENGTH", 4);
|
23 |
+
define("MAX_RECORD_LENGTH", 4);
|
24 |
+
define("MAX_ORG_RECORD_LENGTH", 300);
|
25 |
+
define("GEOIP_SHM_KEY", 0x4f415401);
|
26 |
+
define("US_OFFSET", 1);
|
27 |
+
define("CANADA_OFFSET", 677);
|
28 |
+
define("WORLD_OFFSET", 1353);
|
29 |
+
define("FIPS_RANGE", 360);
|
30 |
+
define("GEOIP_UNKNOWN_SPEED", 0);
|
31 |
+
define("GEOIP_DIALUP_SPEED", 1);
|
32 |
+
define("GEOIP_CABLEDSL_SPEED", 2);
|
33 |
+
define("GEOIP_CORPORATE_SPEED", 3);
|
34 |
+
define("GEOIP_DOMAIN_EDITION", 11);
|
35 |
+
define("GEOIP_COUNTRY_EDITION_V6", 12);
|
36 |
+
define("GEOIP_LOCATIONA_EDITION", 13);
|
37 |
+
define("GEOIP_ACCURACYRADIUS_EDITION", 14);
|
38 |
+
define("GEOIP_CITYCOMBINED_EDITION", 15);
|
39 |
+
define("GEOIP_CITY_EDITION_REV1_V6", 30);
|
40 |
+
define("GEOIP_CITY_EDITION_REV0_V6", 31);
|
41 |
+
define("GEOIP_NETSPEED_EDITION_REV1", 32);
|
42 |
+
define("GEOIP_NETSPEED_EDITION_REV1_V6", 33);
|
43 |
+
define("GEOIP_USERTYPE_EDITION", 28);
|
44 |
+
define("GEOIP_USERTYPE_EDITION_V6", 29);
|
45 |
+
define("GEOIP_ASNUM_EDITION_V6", 21);
|
46 |
+
define("GEOIP_ISP_EDITION_V6", 22);
|
47 |
+
define("GEOIP_ORG_EDITION_V6", 23);
|
48 |
+
define("GEOIP_DOMAIN_EDITION_V6", 24);
|
49 |
+
|
50 |
+
define("CITYCOMBINED_FIXED_RECORD", 7);
|
51 |
+
|
52 |
+
|
53 |
+
class GeoIP
|
54 |
+
{
|
55 |
+
public $flags;
|
56 |
+
public $filehandle;
|
57 |
+
public $memory_buffer;
|
58 |
+
public $databaseType;
|
59 |
+
public $databaseSegments;
|
60 |
+
public $record_length;
|
61 |
+
public $shmid;
|
62 |
+
public $GEOIP_COUNTRY_CODE_TO_NUMBER = array(
|
63 |
+
"" => 0,
|
64 |
+
"AP" => 1,
|
65 |
+
"EU" => 2,
|
66 |
+
"AD" => 3,
|
67 |
+
"AE" => 4,
|
68 |
+
"AF" => 5,
|
69 |
+
"AG" => 6,
|
70 |
+
"AI" => 7,
|
71 |
+
"AL" => 8,
|
72 |
+
"AM" => 9,
|
73 |
+
"CW" => 10,
|
74 |
+
"AO" => 11,
|
75 |
+
"AQ" => 12,
|
76 |
+
"AR" => 13,
|
77 |
+
"AS" => 14,
|
78 |
+
"AT" => 15,
|
79 |
+
"AU" => 16,
|
80 |
+
"AW" => 17,
|
81 |
+
"AZ" => 18,
|
82 |
+
"BA" => 19,
|
83 |
+
"BB" => 20,
|
84 |
+
"BD" => 21,
|
85 |
+
"BE" => 22,
|
86 |
+
"BF" => 23,
|
87 |
+
"BG" => 24,
|
88 |
+
"BH" => 25,
|
89 |
+
"BI" => 26,
|
90 |
+
"BJ" => 27,
|
91 |
+
"BM" => 28,
|
92 |
+
"BN" => 29,
|
93 |
+
"BO" => 30,
|
94 |
+
"BR" => 31,
|
95 |
+
"BS" => 32,
|
96 |
+
"BT" => 33,
|
97 |
+
"BV" => 34,
|
98 |
+
"BW" => 35,
|
99 |
+
"BY" => 36,
|
100 |
+
"BZ" => 37,
|
101 |
+
"CA" => 38,
|
102 |
+
"CC" => 39,
|
103 |
+
"CD" => 40,
|
104 |
+
"CF" => 41,
|
105 |
+
"CG" => 42,
|
106 |
+
"CH" => 43,
|
107 |
+
"CI" => 44,
|
108 |
+
"CK" => 45,
|
109 |
+
"CL" => 46,
|
110 |
+
"CM" => 47,
|
111 |
+
"CN" => 48,
|
112 |
+
"CO" => 49,
|
113 |
+
"CR" => 50,
|
114 |
+
"CU" => 51,
|
115 |
+
"CV" => 52,
|
116 |
+
"CX" => 53,
|
117 |
+
"CY" => 54,
|
118 |
+
"CZ" => 55,
|
119 |
+
"DE" => 56,
|
120 |
+
"DJ" => 57,
|
121 |
+
"DK" => 58,
|
122 |
+
"DM" => 59,
|
123 |
+
"DO" => 60,
|
124 |
+
"DZ" => 61,
|
125 |
+
"EC" => 62,
|
126 |
+
"EE" => 63,
|
127 |
+
"EG" => 64,
|
128 |
+
"EH" => 65,
|
129 |
+
"ER" => 66,
|
130 |
+
"ES" => 67,
|
131 |
+
"ET" => 68,
|
132 |
+
"FI" => 69,
|
133 |
+
"FJ" => 70,
|
134 |
+
"FK" => 71,
|
135 |
+
"FM" => 72,
|
136 |
+
"FO" => 73,
|
137 |
+
"FR" => 74,
|
138 |
+
"SX" => 75,
|
139 |
+
"GA" => 76,
|
140 |
+
"GB" => 77,
|
141 |
+
"GD" => 78,
|
142 |
+
"GE" => 79,
|
143 |
+
"GF" => 80,
|
144 |
+
"GH" => 81,
|
145 |
+
"GI" => 82,
|
146 |
+
"GL" => 83,
|
147 |
+
"GM" => 84,
|
148 |
+
"GN" => 85,
|
149 |
+
"GP" => 86,
|
150 |
+
"GQ" => 87,
|
151 |
+
"GR" => 88,
|
152 |
+
"GS" => 89,
|
153 |
+
"GT" => 90,
|
154 |
+
"GU" => 91,
|
155 |
+
"GW" => 92,
|
156 |
+
"GY" => 93,
|
157 |
+
"HK" => 94,
|
158 |
+
"HM" => 95,
|
159 |
+
"HN" => 96,
|
160 |
+
"HR" => 97,
|
161 |
+
"HT" => 98,
|
162 |
+
"HU" => 99,
|
163 |
+
"ID" => 100,
|
164 |
+
"IE" => 101,
|
165 |
+
"IL" => 102,
|
166 |
+
"IN" => 103,
|
167 |
+
"IO" => 104,
|
168 |
+
"IQ" => 105,
|
169 |
+
"IR" => 106,
|
170 |
+
"IS" => 107,
|
171 |
+
"IT" => 108,
|
172 |
+
"JM" => 109,
|
173 |
+
"JO" => 110,
|
174 |
+
"JP" => 111,
|
175 |
+
"KE" => 112,
|
176 |
+
"KG" => 113,
|
177 |
+
"KH" => 114,
|
178 |
+
"KI" => 115,
|
179 |
+
"KM" => 116,
|
180 |
+
"KN" => 117,
|
181 |
+
"KP" => 118,
|
182 |
+
"KR" => 119,
|
183 |
+
"KW" => 120,
|
184 |
+
"KY" => 121,
|
185 |
+
"KZ" => 122,
|
186 |
+
"LA" => 123,
|
187 |
+
"LB" => 124,
|
188 |
+
"LC" => 125,
|
189 |
+
"LI" => 126,
|
190 |
+
"LK" => 127,
|
191 |
+
"LR" => 128,
|
192 |
+
"LS" => 129,
|
193 |
+
"LT" => 130,
|
194 |
+
"LU" => 131,
|
195 |
+
"LV" => 132,
|
196 |
+
"LY" => 133,
|
197 |
+
"MA" => 134,
|
198 |
+
"MC" => 135,
|
199 |
+
"MD" => 136,
|
200 |
+
"MG" => 137,
|
201 |
+
"MH" => 138,
|
202 |
+
"MK" => 139,
|
203 |
+
"ML" => 140,
|
204 |
+
"MM" => 141,
|
205 |
+
"MN" => 142,
|
206 |
+
"MO" => 143,
|
207 |
+
"MP" => 144,
|
208 |
+
"MQ" => 145,
|
209 |
+
"MR" => 146,
|
210 |
+
"MS" => 147,
|
211 |
+
"MT" => 148,
|
212 |
+
"MU" => 149,
|
213 |
+
"MV" => 150,
|
214 |
+
"MW" => 151,
|
215 |
+
"MX" => 152,
|
216 |
+
"MY" => 153,
|
217 |
+
"MZ" => 154,
|
218 |
+
"NA" => 155,
|
219 |
+
"NC" => 156,
|
220 |
+
"NE" => 157,
|
221 |
+
"NF" => 158,
|
222 |
+
"NG" => 159,
|
223 |
+
"NI" => 160,
|
224 |
+
"NL" => 161,
|
225 |
+
"NO" => 162,
|
226 |
+
"NP" => 163,
|
227 |
+
"NR" => 164,
|
228 |
+
"NU" => 165,
|
229 |
+
"NZ" => 166,
|
230 |
+
"OM" => 167,
|
231 |
+
"PA" => 168,
|
232 |
+
"PE" => 169,
|
233 |
+
"PF" => 170,
|
234 |
+
"PG" => 171,
|
235 |
+
"PH" => 172,
|
236 |
+
"PK" => 173,
|
237 |
+
"PL" => 174,
|
238 |
+
"PM" => 175,
|
239 |
+
"PN" => 176,
|
240 |
+
"PR" => 177,
|
241 |
+
"PS" => 178,
|
242 |
+
"PT" => 179,
|
243 |
+
"PW" => 180,
|
244 |
+
"PY" => 181,
|
245 |
+
"QA" => 182,
|
246 |
+
"RE" => 183,
|
247 |
+
"RO" => 184,
|
248 |
+
"RU" => 185,
|
249 |
+
"RW" => 186,
|
250 |
+
"SA" => 187,
|
251 |
+
"SB" => 188,
|
252 |
+
"SC" => 189,
|
253 |
+
"SD" => 190,
|
254 |
+
"SE" => 191,
|
255 |
+
"SG" => 192,
|
256 |
+
"SH" => 193,
|
257 |
+
"SI" => 194,
|
258 |
+
"SJ" => 195,
|
259 |
+
"SK" => 196,
|
260 |
+
"SL" => 197,
|
261 |
+
"SM" => 198,
|
262 |
+
"SN" => 199,
|
263 |
+
"SO" => 200,
|
264 |
+
"SR" => 201,
|
265 |
+
"ST" => 202,
|
266 |
+
"SV" => 203,
|
267 |
+
"SY" => 204,
|
268 |
+
"SZ" => 205,
|
269 |
+
"TC" => 206,
|
270 |
+
"TD" => 207,
|
271 |
+
"TF" => 208,
|
272 |
+
"TG" => 209,
|
273 |
+
"TH" => 210,
|
274 |
+
"TJ" => 211,
|
275 |
+
"TK" => 212,
|
276 |
+
"TM" => 213,
|
277 |
+
"TN" => 214,
|
278 |
+
"TO" => 215,
|
279 |
+
"TL" => 216,
|
280 |
+
"TR" => 217,
|
281 |
+
"TT" => 218,
|
282 |
+
"TV" => 219,
|
283 |
+
"TW" => 220,
|
284 |
+
"TZ" => 221,
|
285 |
+
"UA" => 222,
|
286 |
+
"UG" => 223,
|
287 |
+
"UM" => 224,
|
288 |
+
"US" => 225,
|
289 |
+
"UY" => 226,
|
290 |
+
"UZ" => 227,
|
291 |
+
"VA" => 228,
|
292 |
+
"VC" => 229,
|
293 |
+
"VE" => 230,
|
294 |
+
"VG" => 231,
|
295 |
+
"VI" => 232,
|
296 |
+
"VN" => 233,
|
297 |
+
"VU" => 234,
|
298 |
+
"WF" => 235,
|
299 |
+
"WS" => 236,
|
300 |
+
"YE" => 237,
|
301 |
+
"YT" => 238,
|
302 |
+
"RS" => 239,
|
303 |
+
"ZA" => 240,
|
304 |
+
"ZM" => 241,
|
305 |
+
"ME" => 242,
|
306 |
+
"ZW" => 243,
|
307 |
+
"A1" => 244,
|
308 |
+
"A2" => 245,
|
309 |
+
"O1" => 246,
|
310 |
+
"AX" => 247,
|
311 |
+
"GG" => 248,
|
312 |
+
"IM" => 249,
|
313 |
+
"JE" => 250,
|
314 |
+
"BL" => 251,
|
315 |
+
"MF" => 252,
|
316 |
+
"BQ" => 253,
|
317 |
+
"SS" => 254
|
318 |
+
);
|
319 |
+
|
320 |
+
public $GEOIP_COUNTRY_CODES = array(
|
321 |
+
"",
|
322 |
+
"AP",
|
323 |
+
"EU",
|
324 |
+
"AD",
|
325 |
+
"AE",
|
326 |
+
"AF",
|
327 |
+
"AG",
|
328 |
+
"AI",
|
329 |
+
"AL",
|
330 |
+
"AM",
|
331 |
+
"CW",
|
332 |
+
"AO",
|
333 |
+
"AQ",
|
334 |
+
"AR",
|
335 |
+
"AS",
|
336 |
+
"AT",
|
337 |
+
"AU",
|
338 |
+
"AW",
|
339 |
+
"AZ",
|
340 |
+
"BA",
|
341 |
+
"BB",
|
342 |
+
"BD",
|
343 |
+
"BE",
|
344 |
+
"BF",
|
345 |
+
"BG",
|
346 |
+
"BH",
|
347 |
+
"BI",
|
348 |
+
"BJ",
|
349 |
+
"BM",
|
350 |
+
"BN",
|
351 |
+
"BO",
|
352 |
+
"BR",
|
353 |
+
"BS",
|
354 |
+
"BT",
|
355 |
+
"BV",
|
356 |
+
"BW",
|
357 |
+
"BY",
|
358 |
+
"BZ",
|
359 |
+
"CA",
|
360 |
+
"CC",
|
361 |
+
"CD",
|
362 |
+
"CF",
|
363 |
+
"CG",
|
364 |
+
"CH",
|
365 |
+
"CI",
|
366 |
+
"CK",
|
367 |
+
"CL",
|
368 |
+
"CM",
|
369 |
+
"CN",
|
370 |
+
"CO",
|
371 |
+
"CR",
|
372 |
+
"CU",
|
373 |
+
"CV",
|
374 |
+
"CX",
|
375 |
+
"CY",
|
376 |
+
"CZ",
|
377 |
+
"DE",
|
378 |
+
"DJ",
|
379 |
+
"DK",
|
380 |
+
"DM",
|
381 |
+
"DO",
|
382 |
+
"DZ",
|
383 |
+
"EC",
|
384 |
+
"EE",
|
385 |
+
"EG",
|
386 |
+
"EH",
|
387 |
+
"ER",
|
388 |
+
"ES",
|
389 |
+
"ET",
|
390 |
+
"FI",
|
391 |
+
"FJ",
|
392 |
+
"FK",
|
393 |
+
"FM",
|
394 |
+
"FO",
|
395 |
+
"FR",
|
396 |
+
"SX",
|
397 |
+
"GA",
|
398 |
+
"GB",
|
399 |
+
"GD",
|
400 |
+
"GE",
|
401 |
+
"GF",
|
402 |
+
"GH",
|
403 |
+
"GI",
|
404 |
+
"GL",
|
405 |
+
"GM",
|
406 |
+
"GN",
|
407 |
+
"GP",
|
408 |
+
"GQ",
|
409 |
+
"GR",
|
410 |
+
"GS",
|
411 |
+
"GT",
|
412 |
+
"GU",
|
413 |
+
"GW",
|
414 |
+
"GY",
|
415 |
+
"HK",
|
416 |
+
"HM",
|
417 |
+
"HN",
|
418 |
+
"HR",
|
419 |
+
"HT",
|
420 |
+
"HU",
|
421 |
+
"ID",
|
422 |
+
"IE",
|
423 |
+
"IL",
|
424 |
+
"IN",
|
425 |
+
"IO",
|
426 |
+
"IQ",
|
427 |
+
"IR",
|
428 |
+
"IS",
|
429 |
+
"IT",
|
430 |
+
"JM",
|
431 |
+
"JO",
|
432 |
+
"JP",
|
433 |
+
"KE",
|
434 |
+
"KG",
|
435 |
+
"KH",
|
436 |
+
"KI",
|
437 |
+
"KM",
|
438 |
+
"KN",
|
439 |
+
"KP",
|
440 |
+
"KR",
|
441 |
+
"KW",
|
442 |
+
"KY",
|
443 |
+
"KZ",
|
444 |
+
"LA",
|
445 |
+
"LB",
|
446 |
+
"LC",
|
447 |
+
"LI",
|
448 |
+
"LK",
|
449 |
+
"LR",
|
450 |
+
"LS",
|
451 |
+
"LT",
|
452 |
+
"LU",
|
453 |
+
"LV",
|
454 |
+
"LY",
|
455 |
+
"MA",
|
456 |
+
"MC",
|
457 |
+
"MD",
|
458 |
+
"MG",
|
459 |
+
"MH",
|
460 |
+
"MK",
|
461 |
+
"ML",
|
462 |
+
"MM",
|
463 |
+
"MN",
|
464 |
+
"MO",
|
465 |
+
"MP",
|
466 |
+
"MQ",
|
467 |
+
"MR",
|
468 |
+
"MS",
|
469 |
+
"MT",
|
470 |
+
"MU",
|
471 |
+
"MV",
|
472 |
+
"MW",
|
473 |
+
"MX",
|
474 |
+
"MY",
|
475 |
+
"MZ",
|
476 |
+
"NA",
|
477 |
+
"NC",
|
478 |
+
"NE",
|
479 |
+
"NF",
|
480 |
+
"NG",
|
481 |
+
"NI",
|
482 |
+
"NL",
|
483 |
+
"NO",
|
484 |
+
"NP",
|
485 |
+
"NR",
|
486 |
+
"NU",
|
487 |
+
"NZ",
|
488 |
+
"OM",
|
489 |
+
"PA",
|
490 |
+
"PE",
|
491 |
+
"PF",
|
492 |
+
"PG",
|
493 |
+
"PH",
|
494 |
+
"PK",
|
495 |
+
"PL",
|
496 |
+
"PM",
|
497 |
+
"PN",
|
498 |
+
"PR",
|
499 |
+
"PS",
|
500 |
+
"PT",
|
501 |
+
"PW",
|
502 |
+
"PY",
|
503 |
+
"QA",
|
504 |
+
"RE",
|
505 |
+
"RO",
|
506 |
+
"RU",
|
507 |
+
"RW",
|
508 |
+
"SA",
|
509 |
+
"SB",
|
510 |
+
"SC",
|
511 |
+
"SD",
|
512 |
+
"SE",
|
513 |
+
"SG",
|
514 |
+
"SH",
|
515 |
+
"SI",
|
516 |
+
"SJ",
|
517 |
+
"SK",
|
518 |
+
"SL",
|
519 |
+
"SM",
|
520 |
+
"SN",
|
521 |
+
"SO",
|
522 |
+
"SR",
|
523 |
+
"ST",
|
524 |
+
"SV",
|
525 |
+
"SY",
|
526 |
+
"SZ",
|
527 |
+
"TC",
|
528 |
+
"TD",
|
529 |
+
"TF",
|
530 |
+
"TG",
|
531 |
+
"TH",
|
532 |
+
"TJ",
|
533 |
+
"TK",
|
534 |
+
"TM",
|
535 |
+
"TN",
|
536 |
+
"TO",
|
537 |
+
"TL",
|
538 |
+
"TR",
|
539 |
+
"TT",
|
540 |
+
"TV",
|
541 |
+
"TW",
|
542 |
+
"TZ",
|
543 |
+
"UA",
|
544 |
+
"UG",
|
545 |
+
"UM",
|
546 |
+
"US",
|
547 |
+
"UY",
|
548 |
+
"UZ",
|
549 |
+
"VA",
|
550 |
+
"VC",
|
551 |
+
"VE",
|
552 |
+
"VG",
|
553 |
+
"VI",
|
554 |
+
"VN",
|
555 |
+
"VU",
|
556 |
+
"WF",
|
557 |
+
"WS",
|
558 |
+
"YE",
|
559 |
+
"YT",
|
560 |
+
"RS",
|
561 |
+
"ZA",
|
562 |
+
"ZM",
|
563 |
+
"ME",
|
564 |
+
"ZW",
|
565 |
+
"A1",
|
566 |
+
"A2",
|
567 |
+
"O1",
|
568 |
+
"AX",
|
569 |
+
"GG",
|
570 |
+
"IM",
|
571 |
+
"JE",
|
572 |
+
"BL",
|
573 |
+
"MF",
|
574 |
+
"BQ",
|
575 |
+
"SS",
|
576 |
+
"O1"
|
577 |
+
);
|
578 |
+
|
579 |
+
public $GEOIP_COUNTRY_CODES3 = array(
|
580 |
+
"",
|
581 |
+
"AP",
|
582 |
+
"EU",
|
583 |
+
"AND",
|
584 |
+
"ARE",
|
585 |
+
"AFG",
|
586 |
+
"ATG",
|
587 |
+
"AIA",
|
588 |
+
"ALB",
|
589 |
+
"ARM",
|
590 |
+
"CUW",
|
591 |
+
"AGO",
|
592 |
+
"ATA",
|
593 |
+
"ARG",
|
594 |
+
"ASM",
|
595 |
+
"AUT",
|
596 |
+
"AUS",
|
597 |
+
"ABW",
|
598 |
+
"AZE",
|
599 |
+
"BIH",
|
600 |
+
"BRB",
|
601 |
+
"BGD",
|
602 |
+
"BEL",
|
603 |
+
"BFA",
|
604 |
+
"BGR",
|
605 |
+
"BHR",
|
606 |
+
"BDI",
|
607 |
+
"BEN",
|
608 |
+
"BMU",
|
609 |
+
"BRN",
|
610 |
+
"BOL",
|
611 |
+
"BRA",
|
612 |
+
"BHS",
|
613 |
+
"BTN",
|
614 |
+
"BVT",
|
615 |
+
"BWA",
|
616 |
+
"BLR",
|
617 |
+
"BLZ",
|
618 |
+
"CAN",
|
619 |
+
"CCK",
|
620 |
+
"COD",
|
621 |
+
"CAF",
|
622 |
+
"COG",
|
623 |
+
"CHE",
|
624 |
+
"CIV",
|
625 |
+
"COK",
|
626 |
+
"CHL",
|
627 |
+
"CMR",
|
628 |
+
"CHN",
|
629 |
+
"COL",
|
630 |
+
"CRI",
|
631 |
+
"CUB",
|
632 |
+
"CPV",
|
633 |
+
"CXR",
|
634 |
+
"CYP",
|
635 |
+
"CZE",
|
636 |
+
"DEU",
|
637 |
+
"DJI",
|
638 |
+
"DNK",
|
639 |
+
"DMA",
|
640 |
+
"DOM",
|
641 |
+
"DZA",
|
642 |
+
"ECU",
|
643 |
+
"EST",
|
644 |
+
"EGY",
|
645 |
+
"ESH",
|
646 |
+
"ERI",
|
647 |
+
"ESP",
|
648 |
+
"ETH",
|
649 |
+
"FIN",
|
650 |
+
"FJI",
|
651 |
+
"FLK",
|
652 |
+
"FSM",
|
653 |
+
"FRO",
|
654 |
+
"FRA",
|
655 |
+
"SXM",
|
656 |
+
"GAB",
|
657 |
+
"GBR",
|
658 |
+
"GRD",
|
659 |
+
"GEO",
|
660 |
+
"GUF",
|
661 |
+
"GHA",
|
662 |
+
"GIB",
|
663 |
+
"GRL",
|
664 |
+
"GMB",
|
665 |
+
"GIN",
|
666 |
+
"GLP",
|
667 |
+
"GNQ",
|
668 |
+
"GRC",
|
669 |
+
"SGS",
|
670 |
+
"GTM",
|
671 |
+
"GUM",
|
672 |
+
"GNB",
|
673 |
+
"GUY",
|
674 |
+
"HKG",
|
675 |
+
"HMD",
|
676 |
+
"HND",
|
677 |
+
"HRV",
|
678 |
+
"HTI",
|
679 |
+
"HUN",
|
680 |
+
"IDN",
|
681 |
+
"IRL",
|
682 |
+
"ISR",
|
683 |
+
"IND",
|
684 |
+
"IOT",
|
685 |
+
"IRQ",
|
686 |
+
"IRN",
|
687 |
+
"ISL",
|
688 |
+
"ITA",
|
689 |
+
"JAM",
|
690 |
+
"JOR",
|
691 |
+
"JPN",
|
692 |
+
"KEN",
|
693 |
+
"KGZ",
|
694 |
+
"KHM",
|
695 |
+
"KIR",
|
696 |
+
"COM",
|
697 |
+
"KNA",
|
698 |
+
"PRK",
|
699 |
+
"KOR",
|
700 |
+
"KWT",
|
701 |
+
"CYM",
|
702 |
+
"KAZ",
|
703 |
+
"LAO",
|
704 |
+
"LBN",
|
705 |
+
"LCA",
|
706 |
+
"LIE",
|
707 |
+
"LKA",
|
708 |
+
"LBR",
|
709 |
+
"LSO",
|
710 |
+
"LTU",
|
711 |
+
"LUX",
|
712 |
+
"LVA",
|
713 |
+
"LBY",
|
714 |
+
"MAR",
|
715 |
+
"MCO",
|
716 |
+
"MDA",
|
717 |
+
"MDG",
|
718 |
+
"MHL",
|
719 |
+
"MKD",
|
720 |
+
"MLI",
|
721 |
+
"MMR",
|
722 |
+
"MNG",
|
723 |
+
"MAC",
|
724 |
+
"MNP",
|
725 |
+
"MTQ",
|
726 |
+
"MRT",
|
727 |
+
"MSR",
|
728 |
+
"MLT",
|
729 |
+
"MUS",
|
730 |
+
"MDV",
|
731 |
+
"MWI",
|
732 |
+
"MEX",
|
733 |
+
"MYS",
|
734 |
+
"MOZ",
|
735 |
+
"NAM",
|
736 |
+
"NCL",
|
737 |
+
"NER",
|
738 |
+
"NFK",
|
739 |
+
"NGA",
|
740 |
+
"NIC",
|
741 |
+
"NLD",
|
742 |
+
"NOR",
|
743 |
+
"NPL",
|
744 |
+
"NRU",
|
745 |
+
"NIU",
|
746 |
+
"NZL",
|
747 |
+
"OMN",
|
748 |
+
"PAN",
|
749 |
+
"PER",
|
750 |
+
"PYF",
|
751 |
+
"PNG",
|
752 |
+
"PHL",
|
753 |
+
"PAK",
|
754 |
+
"POL",
|
755 |
+
"SPM",
|
756 |
+
"PCN",
|
757 |
+
"PRI",
|
758 |
+
"PSE",
|
759 |
+
"PRT",
|
760 |
+
"PLW",
|
761 |
+
"PRY",
|
762 |
+
"QAT",
|
763 |
+
"REU",
|
764 |
+
"ROU",
|
765 |
+
"RUS",
|
766 |
+
"RWA",
|
767 |
+
"SAU",
|
768 |
+
"SLB",
|
769 |
+
"SYC",
|
770 |
+
"SDN",
|
771 |
+
"SWE",
|
772 |
+
"SGP",
|
773 |
+
"SHN",
|
774 |
+
"SVN",
|
775 |
+
"SJM",
|
776 |
+
"SVK",
|
777 |
+
"SLE",
|
778 |
+
"SMR",
|
779 |
+
"SEN",
|
780 |
+
"SOM",
|
781 |
+
"SUR",
|
782 |
+
"STP",
|
783 |
+
"SLV",
|
784 |
+
"SYR",
|
785 |
+
"SWZ",
|
786 |
+
"TCA",
|
787 |
+
"TCD",
|
788 |
+
"ATF",
|
789 |
+
"TGO",
|
790 |
+
"THA",
|
791 |
+
"TJK",
|
792 |
+
"TKL",
|
793 |
+
"TKM",
|
794 |
+
"TUN",
|
795 |
+
"TON",
|
796 |
+
"TLS",
|
797 |
+
"TUR",
|
798 |
+
"TTO",
|
799 |
+
"TUV",
|
800 |
+
"TWN",
|
801 |
+
"TZA",
|
802 |
+
"UKR",
|
803 |
+
"UGA",
|
804 |
+
"UMI",
|
805 |
+
"USA",
|
806 |
+
"URY",
|
807 |
+
"UZB",
|
808 |
+
"VAT",
|
809 |
+
"VCT",
|
810 |
+
"VEN",
|
811 |
+
"VGB",
|
812 |
+
"VIR",
|
813 |
+
"VNM",
|
814 |
+
"VUT",
|
815 |
+
"WLF",
|
816 |
+
"WSM",
|
817 |
+
"YEM",
|
818 |
+
"MYT",
|
819 |
+
"SRB",
|
820 |
+
"ZAF",
|
821 |
+
"ZMB",
|
822 |
+
"MNE",
|
823 |
+
"ZWE",
|
824 |
+
"A1",
|
825 |
+
"A2",
|
826 |
+
"O1",
|
827 |
+
"ALA",
|
828 |
+
"GGY",
|
829 |
+
"IMN",
|
830 |
+
"JEY",
|
831 |
+
"BLM",
|
832 |
+
"MAF",
|
833 |
+
"BES",
|
834 |
+
"SSD",
|
835 |
+
"O1"
|
836 |
+
);
|
837 |
+
|
838 |
+
public $GEOIP_COUNTRY_NAMES = array(
|
839 |
+
"",
|
840 |
+
"Asia/Pacific Region",
|
841 |
+
"Europe",
|
842 |
+
"Andorra",
|
843 |
+
"United Arab Emirates",
|
844 |
+
"Afghanistan",
|
845 |
+
"Antigua and Barbuda",
|
846 |
+
"Anguilla",
|
847 |
+
"Albania",
|
848 |
+
"Armenia",
|
849 |
+
"Curacao",
|
850 |
+
"Angola",
|
851 |
+
"Antarctica",
|
852 |
+
"Argentina",
|
853 |
+
"American Samoa",
|
854 |
+
"Austria",
|
855 |
+
"Australia",
|
856 |
+
"Aruba",
|
857 |
+
"Azerbaijan",
|
858 |
+
"Bosnia and Herzegovina",
|
859 |
+
"Barbados",
|
860 |
+
"Bangladesh",
|
861 |
+
"Belgium",
|
862 |
+
"Burkina Faso",
|
863 |
+
"Bulgaria",
|
864 |
+
"Bahrain",
|
865 |
+
"Burundi",
|
866 |
+
"Benin",
|
867 |
+
"Bermuda",
|
868 |
+
"Brunei Darussalam",
|
869 |
+
"Bolivia",
|
870 |
+
"Brazil",
|
871 |
+
"Bahamas",
|
872 |
+
"Bhutan",
|
873 |
+
"Bouvet Island",
|
874 |
+
"Botswana",
|
875 |
+
"Belarus",
|
876 |
+
"Belize",
|
877 |
+
"Canada",
|
878 |
+
"Cocos (Keeling) Islands",
|
879 |
+
"Congo, The Democratic Republic of the",
|
880 |
+
"Central African Republic",
|
881 |
+
"Congo",
|
882 |
+
"Switzerland",
|
883 |
+
"Cote D'Ivoire",
|
884 |
+
"Cook Islands",
|
885 |
+
"Chile",
|
886 |
+
"Cameroon",
|
887 |
+
"China",
|
888 |
+
"Colombia",
|
889 |
+
"Costa Rica",
|
890 |
+
"Cuba",
|
891 |
+
"Cape Verde",
|
892 |
+
"Christmas Island",
|
893 |
+
"Cyprus",
|
894 |
+
"Czech Republic",
|
895 |
+
"Germany",
|
896 |
+
"Djibouti",
|
897 |
+
"Denmark",
|
898 |
+
"Dominica",
|
899 |
+
"Dominican Republic",
|
900 |
+
"Algeria",
|
901 |
+
"Ecuador",
|
902 |
+
"Estonia",
|
903 |
+
"Egypt",
|
904 |
+
"Western Sahara",
|
905 |
+
"Eritrea",
|
906 |
+
"Spain",
|
907 |
+
"Ethiopia",
|
908 |
+
"Finland",
|
909 |
+
"Fiji",
|
910 |
+
"Falkland Islands (Malvinas)",
|
911 |
+
"Micronesia, Federated States of",
|
912 |
+
"Faroe Islands",
|
913 |
+
"France",
|
914 |
+
"Sint Maarten (Dutch part)",
|
915 |
+
"Gabon",
|
916 |
+
"United Kingdom",
|
917 |
+
"Grenada",
|
918 |
+
"Georgia",
|
919 |
+
"French Guiana",
|
920 |
+
"Ghana",
|
921 |
+
"Gibraltar",
|
922 |
+
"Greenland",
|
923 |
+
"Gambia",
|
924 |
+
"Guinea",
|
925 |
+
"Guadeloupe",
|
926 |
+
"Equatorial Guinea",
|
927 |
+
"Greece",
|
928 |
+
"South Georgia and the South Sandwich Islands",
|
929 |
+
"Guatemala",
|
930 |
+
"Guam",
|
931 |
+
"Guinea-Bissau",
|
932 |
+
"Guyana",
|
933 |
+
"Hong Kong",
|
934 |
+
"Heard Island and McDonald Islands",
|
935 |
+
"Honduras",
|
936 |
+
"Croatia",
|
937 |
+
"Haiti",
|
938 |
+
"Hungary",
|
939 |
+
"Indonesia",
|
940 |
+
"Ireland",
|
941 |
+
"Israel",
|
942 |
+
"India",
|
943 |
+
"British Indian Ocean Territory",
|
944 |
+
"Iraq",
|
945 |
+
"Iran, Islamic Republic of",
|
946 |
+
"Iceland",
|
947 |
+
"Italy",
|
948 |
+
"Jamaica",
|
949 |
+
"Jordan",
|
950 |
+
"Japan",
|
951 |
+
"Kenya",
|
952 |
+
"Kyrgyzstan",
|
953 |
+
"Cambodia",
|
954 |
+
"Kiribati",
|
955 |
+
"Comoros",
|
956 |
+
"Saint Kitts and Nevis",
|
957 |
+
"Korea, Democratic People's Republic of",
|
958 |
+
"Korea, Republic of",
|
959 |
+
"Kuwait",
|
960 |
+
"Cayman Islands",
|
961 |
+
"Kazakhstan",
|
962 |
+
"Lao People's Democratic Republic",
|
963 |
+
"Lebanon",
|
964 |
+
"Saint Lucia",
|
965 |
+
"Liechtenstein",
|
966 |
+
"Sri Lanka",
|
967 |
+
"Liberia",
|
968 |
+
"Lesotho",
|
969 |
+
"Lithuania",
|
970 |
+
"Luxembourg",
|
971 |
+
"Latvia",
|
972 |
+
"Libya",
|
973 |
+
"Morocco",
|
974 |
+
"Monaco",
|
975 |
+
"Moldova, Republic of",
|
976 |
+
"Madagascar",
|
977 |
+
"Marshall Islands",
|
978 |
+
"Macedonia",
|
979 |
+
"Mali",
|
980 |
+
"Myanmar",
|
981 |
+
"Mongolia",
|
982 |
+
"Macau",
|
983 |
+
"Northern Mariana Islands",
|
984 |
+
"Martinique",
|
985 |
+
"Mauritania",
|
986 |
+
"Montserrat",
|
987 |
+
"Malta",
|
988 |
+
"Mauritius",
|
989 |
+
"Maldives",
|
990 |
+
"Malawi",
|
991 |
+
"Mexico",
|
992 |
+
"Malaysia",
|
993 |
+
"Mozambique",
|
994 |
+
"Namibia",
|
995 |
+
"New Caledonia",
|
996 |
+
"Niger",
|
997 |
+
"Norfolk Island",
|
998 |
+
"Nigeria",
|
999 |
+
"Nicaragua",
|
1000 |
+
"Netherlands",
|
1001 |
+
"Norway",
|
1002 |
+
"Nepal",
|
1003 |
+
"Nauru",
|
1004 |
+
"Niue",
|
1005 |
+
"New Zealand",
|
1006 |
+
"Oman",
|
1007 |
+
"Panama",
|
1008 |
+
"Peru",
|
1009 |
+
"French Polynesia",
|
1010 |
+
"Papua New Guinea",
|
1011 |
+
"Philippines",
|
1012 |
+
"Pakistan",
|
1013 |
+
"Poland",
|
1014 |
+
"Saint Pierre and Miquelon",
|
1015 |
+
"Pitcairn Islands",
|
1016 |
+
"Puerto Rico",
|
1017 |
+
"Palestinian Territory",
|
1018 |
+
"Portugal",
|
1019 |
+
"Palau",
|
1020 |
+
"Paraguay",
|
1021 |
+
"Qatar",
|
1022 |
+
"Reunion",
|
1023 |
+
"Romania",
|
1024 |
+
"Russian Federation",
|
1025 |
+
"Rwanda",
|
1026 |
+
"Saudi Arabia",
|
1027 |
+
"Solomon Islands",
|
1028 |
+
"Seychelles",
|
1029 |
+
"Sudan",
|
1030 |
+
"Sweden",
|
1031 |
+
"Singapore",
|
1032 |
+
"Saint Helena",
|
1033 |
+
"Slovenia",
|
1034 |
+
"Svalbard and Jan Mayen",
|
1035 |
+
"Slovakia",
|
1036 |
+
"Sierra Leone",
|
1037 |
+
"San Marino",
|
1038 |
+
"Senegal",
|
1039 |
+
"Somalia",
|
1040 |
+
"Suriname",
|
1041 |
+
"Sao Tome and Principe",
|
1042 |
+
"El Salvador",
|
1043 |
+
"Syrian Arab Republic",
|
1044 |
+
"Swaziland",
|
1045 |
+
"Turks and Caicos Islands",
|
1046 |
+
"Chad",
|
1047 |
+
"French Southern Territories",
|
1048 |
+
"Togo",
|
1049 |
+
"Thailand",
|
1050 |
+
"Tajikistan",
|
1051 |
+
"Tokelau",
|
1052 |
+
"Turkmenistan",
|
1053 |
+
"Tunisia",
|
1054 |
+
"Tonga",
|
1055 |
+
"Timor-Leste",
|
1056 |
+
"Turkey",
|
1057 |
+
"Trinidad and Tobago",
|
1058 |
+
"Tuvalu",
|
1059 |
+
"Taiwan",
|
1060 |
+
"Tanzania, United Republic of",
|
1061 |
+
"Ukraine",
|
1062 |
+
"Uganda",
|
1063 |
+
"United States Minor Outlying Islands",
|
1064 |
+
"United States",
|
1065 |
+
"Uruguay",
|
1066 |
+
"Uzbekistan",
|
1067 |
+
"Holy See (Vatican City State)",
|
1068 |
+
"Saint Vincent and the Grenadines",
|
1069 |
+
"Venezuela",
|
1070 |
+
"Virgin Islands, British",
|
1071 |
+
"Virgin Islands, U.S.",
|
1072 |
+
"Vietnam",
|
1073 |
+
"Vanuatu",
|
1074 |
+
"Wallis and Futuna",
|
1075 |
+
"Samoa",
|
1076 |
+
"Yemen",
|
1077 |
+
"Mayotte",
|
1078 |
+
"Serbia",
|
1079 |
+
"South Africa",
|
1080 |
+
"Zambia",
|
1081 |
+
"Montenegro",
|
1082 |
+
"Zimbabwe",
|
1083 |
+
"Anonymous Proxy",
|
1084 |
+
"Satellite Provider",
|
1085 |
+
"Other",
|
1086 |
+
"Aland Islands",
|
1087 |
+
"Guernsey",
|
1088 |
+
"Isle of Man",
|
1089 |
+
"Jersey",
|
1090 |
+
"Saint Barthelemy",
|
1091 |
+
"Saint Martin",
|
1092 |
+
"Bonaire, Saint Eustatius and Saba",
|
1093 |
+
"South Sudan",
|
1094 |
+
"Other"
|
1095 |
+
);
|
1096 |
+
|
1097 |
+
public $GEOIP_CONTINENT_CODES = array(
|
1098 |
+
"--",
|
1099 |
+
"AS",
|
1100 |
+
"EU",
|
1101 |
+
"EU",
|
1102 |
+
"AS",
|
1103 |
+
"AS",
|
1104 |
+
"NA",
|
1105 |
+
"NA",
|
1106 |
+
"EU",
|
1107 |
+
"AS",
|
1108 |
+
"NA",
|
1109 |
+
"AF",
|
1110 |
+
"AN",
|
1111 |
+
"SA",
|
1112 |
+
"OC",
|
1113 |
+
"EU",
|
1114 |
+
"OC",
|
1115 |
+
"NA",
|
1116 |
+
"AS",
|
1117 |
+
"EU",
|
1118 |
+
"NA",
|
1119 |
+
"AS",
|
1120 |
+
"EU",
|
1121 |
+
"AF",
|
1122 |
+
"EU",
|
1123 |
+
"AS",
|
1124 |
+
"AF",
|
1125 |
+
"AF",
|
1126 |
+
"NA",
|
1127 |
+
"AS",
|
1128 |
+
"SA",
|
1129 |
+
"SA",
|
1130 |
+
"NA",
|
1131 |
+
"AS",
|
1132 |
+
"AN",
|
1133 |
+
"AF",
|
1134 |
+
"EU",
|
1135 |
+
"NA",
|
1136 |
+
"NA",
|
1137 |
+
"AS",
|
1138 |
+
"AF",
|
1139 |
+
"AF",
|
1140 |
+
"AF",
|
1141 |
+
"EU",
|
1142 |
+
"AF",
|
1143 |
+
"OC",
|
1144 |
+
"SA",
|
1145 |
+
"AF",
|
1146 |
+
"AS",
|
1147 |
+
"SA",
|
1148 |
+
"NA",
|
1149 |
+
"NA",
|
1150 |
+
"AF",
|
1151 |
+
"AS",
|
1152 |
+
"AS",
|
1153 |
+
"EU",
|
1154 |
+
"EU",
|
1155 |
+
"AF",
|
1156 |
+
"EU",
|
1157 |
+
"NA",
|
1158 |
+
"NA",
|
1159 |
+
"AF",
|
1160 |
+
"SA",
|
1161 |
+
"EU",
|
1162 |
+
"AF",
|
1163 |
+
"AF",
|
1164 |
+
"AF",
|
1165 |
+
"EU",
|
1166 |
+
"AF",
|
1167 |
+
"EU",
|
1168 |
+
"OC",
|
1169 |
+
"SA",
|
1170 |
+
"OC",
|
1171 |
+
"EU",
|
1172 |
+
"EU",
|
1173 |
+
"NA",
|
1174 |
+
"AF",
|
1175 |
+
"EU",
|
1176 |
+
"NA",
|
1177 |
+
"AS",
|
1178 |
+
"SA",
|
1179 |
+
"AF",
|
1180 |
+
"EU",
|
1181 |
+
"NA",
|
1182 |
+
"AF",
|
1183 |
+
"AF",
|
1184 |
+
"NA",
|
1185 |
+
"AF",
|
1186 |
+
"EU",
|
1187 |
+
"AN",
|
1188 |
+
"NA",
|
1189 |
+
"OC",
|
1190 |
+
"AF",
|
1191 |
+
"SA",
|
1192 |
+
"AS",
|
1193 |
+
"AN",
|
1194 |
+
"NA",
|
1195 |
+
"EU",
|
1196 |
+
"NA",
|
1197 |
+
"EU",
|
1198 |
+
"AS",
|
1199 |
+
"EU",
|
1200 |
+
"AS",
|
1201 |
+
"AS",
|
1202 |
+
"AS",
|
1203 |
+
"AS",
|
1204 |
+
"AS",
|
1205 |
+
"EU",
|
1206 |
+
"EU",
|
1207 |
+
"NA",
|
1208 |
+
"AS",
|
1209 |
+
"AS",
|
1210 |
+
"AF",
|
1211 |
+
"AS",
|
1212 |
+
"AS",
|
1213 |
+
"OC",
|
1214 |
+
"AF",
|
1215 |
+
"NA",
|
1216 |
+
"AS",
|
1217 |
+
"AS",
|
1218 |
+
"AS",
|
1219 |
+
"NA",
|
1220 |
+
"AS",
|
1221 |
+
"AS",
|
1222 |
+
"AS",
|
1223 |
+
"NA",
|
1224 |
+
"EU",
|
1225 |
+
"AS",
|
1226 |
+
"AF",
|
1227 |
+
"AF",
|
1228 |
+
"EU",
|
1229 |
+
"EU",
|
1230 |
+
"EU",
|
1231 |
+
"AF",
|
1232 |
+
"AF",
|
1233 |
+
"EU",
|
1234 |
+
"EU",
|
1235 |
+
"AF",
|
1236 |
+
"OC",
|
1237 |
+
"EU",
|
1238 |
+
"AF",
|
1239 |
+
"AS",
|
1240 |
+
"AS",
|
1241 |
+
"AS",
|
1242 |
+
"OC",
|
1243 |
+
"NA",
|
1244 |
+
"AF",
|
1245 |
+
"NA",
|
1246 |
+
"EU",
|
1247 |
+
"AF",
|
1248 |
+
"AS",
|
1249 |
+
"AF",
|
1250 |
+
"NA",
|
1251 |
+
"AS",
|
1252 |
+
"AF",
|
1253 |
+
"AF",
|
1254 |
+
"OC",
|
1255 |
+
"AF",
|
1256 |
+
"OC",
|
1257 |
+
"AF",
|
1258 |
+
"NA",
|
1259 |
+
"EU",
|
1260 |
+
"EU",
|
1261 |
+
"AS",
|
1262 |
+
"OC",
|
1263 |
+
"OC",
|
1264 |
+
"OC",
|
1265 |
+
"AS",
|
1266 |
+
"NA",
|
1267 |
+
"SA",
|
1268 |
+
"OC",
|
1269 |
+
"OC",
|
1270 |
+
"AS",
|
1271 |
+
"AS",
|
1272 |
+
"EU",
|
1273 |
+
"NA",
|
1274 |
+
"OC",
|
1275 |
+
"NA",
|
1276 |
+
"AS",
|
1277 |
+
"EU",
|
1278 |
+
"OC",
|
1279 |
+
"SA",
|
1280 |
+
"AS",
|
1281 |
+
"AF",
|
1282 |
+
"EU",
|
1283 |
+
"EU",
|
1284 |
+
"AF",
|
1285 |
+
"AS",
|
1286 |
+
"OC",
|
1287 |
+
"AF",
|
1288 |
+
"AF",
|
1289 |
+
"EU",
|
1290 |
+
"AS",
|
1291 |
+
"AF",
|
1292 |
+
"EU",
|
1293 |
+
"EU",
|
1294 |
+
"EU",
|
1295 |
+
"AF",
|
1296 |
+
"EU",
|
1297 |
+
"AF",
|
1298 |
+
"AF",
|
1299 |
+
"SA",
|
1300 |
+
"AF",
|
1301 |
+
"NA",
|
1302 |
+
"AS",
|
1303 |
+
"AF",
|
1304 |
+
"NA",
|
1305 |
+
"AF",
|
1306 |
+
"AN",
|
1307 |
+
"AF",
|
1308 |
+
"AS",
|
1309 |
+
"AS",
|
1310 |
+
"OC",
|
1311 |
+
"AS",
|
1312 |
+
"AF",
|
1313 |
+
"OC",
|
1314 |
+
"AS",
|
1315 |
+
"EU",
|
1316 |
+
"NA",
|
1317 |
+
"OC",
|
1318 |
+
"AS",
|
1319 |
+
"AF",
|
1320 |
+
"EU",
|
1321 |
+
"AF",
|
1322 |
+
"OC",
|
1323 |
+
"NA",
|
1324 |
+
"SA",
|
1325 |
+
"AS",
|
1326 |
+
"EU",
|
1327 |
+
"NA",
|
1328 |
+
"SA",
|
1329 |
+
"NA",
|
1330 |
+
"NA",
|
1331 |
+
"AS",
|
1332 |
+
"OC",
|
1333 |
+
"OC",
|
1334 |
+
"OC",
|
1335 |
+
"AS",
|
1336 |
+
"AF",
|
1337 |
+
"EU",
|
1338 |
+
"AF",
|
1339 |
+
"AF",
|
1340 |
+
"EU",
|
1341 |
+
"AF",
|
1342 |
+
"--",
|
1343 |
+
"--",
|
1344 |
+
"--",
|
1345 |
+
"EU",
|
1346 |
+
"EU",
|
1347 |
+
"EU",
|
1348 |
+
"EU",
|
1349 |
+
"NA",
|
1350 |
+
"NA",
|
1351 |
+
"NA",
|
1352 |
+
"AF",
|
1353 |
+
"--"
|
1354 |
+
);
|
1355 |
+
}
|
1356 |
+
|
1357 |
+
class AT_MaxMind_GeoIP
|
1358 |
+
{
|
1359 |
+
function geoip_load_shared_mem($file)
|
1360 |
+
{
|
1361 |
+
$fp = fopen($file, "rb");
|
1362 |
+
if (!$fp) {
|
1363 |
+
print "error opening $file: $php_errormsg\n";
|
1364 |
+
exit;
|
1365 |
+
}
|
1366 |
+
$s_array = fstat($fp);
|
1367 |
+
$size = $s_array['size'];
|
1368 |
+
if (($shmid = @shmop_open(GEOIP_SHM_KEY, "w", 0, 0))) {
|
1369 |
+
shmop_delete($shmid);
|
1370 |
+
shmop_close($shmid);
|
1371 |
+
}
|
1372 |
+
$shmid = shmop_open(GEOIP_SHM_KEY, "c", 0644, $size);
|
1373 |
+
shmop_write($shmid, fread($fp, $size), 0);
|
1374 |
+
shmop_close($shmid);
|
1375 |
+
}
|
1376 |
+
|
1377 |
+
function _setup_segments($gi)
|
1378 |
+
{
|
1379 |
+
$gi->databaseType = GEOIP_COUNTRY_EDITION;
|
1380 |
+
$gi->record_length = STANDARD_RECORD_LENGTH;
|
1381 |
+
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
1382 |
+
$offset = shmop_size($gi->shmid) - 3;
|
1383 |
+
for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
|
1384 |
+
$delim = shmop_read($gi->shmid, $offset, 3);
|
1385 |
+
$offset += 3;
|
1386 |
+
if ($delim == (chr(255) . chr(255) . chr(255))) {
|
1387 |
+
$gi->databaseType = ord(shmop_read($gi->shmid, $offset, 1));
|
1388 |
+
if ($gi->databaseType >= 106) {
|
1389 |
+
$gi->databaseType -= 105;
|
1390 |
+
}
|
1391 |
+
$offset++;
|
1392 |
+
|
1393 |
+
if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) {
|
1394 |
+
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
|
1395 |
+
} elseif ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
|
1396 |
+
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
|
1397 |
+
} elseif (($gi->databaseType == GEOIP_CITY_EDITION_REV0)
|
1398 |
+
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV1)
|
1399 |
+
|| ($gi->databaseType == GEOIP_ORG_EDITION)
|
1400 |
+
|| ($gi->databaseType == GEOIP_ORG_EDITION_V6)
|
1401 |
+
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION)
|
1402 |
+
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
|
1403 |
+
|| ($gi->databaseType == GEOIP_ISP_EDITION)
|
1404 |
+
|| ($gi->databaseType == GEOIP_ISP_EDITION_V6)
|
1405 |
+
|| ($gi->databaseType == GEOIP_USERTYPE_EDITION)
|
1406 |
+
|| ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6)
|
1407 |
+
|| ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
|
1408 |
+
|| ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
|
1409 |
+
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
|
1410 |
+
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
|
1411 |
+
|| ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1)
|
1412 |
+
|| ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6)
|
1413 |
+
|| ($gi->databaseType == GEOIP_ASNUM_EDITION)
|
1414 |
+
|| ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)
|
1415 |
+
) {
|
1416 |
+
$gi->databaseSegments = 0;
|
1417 |
+
$buf = shmop_read($gi->shmid, $offset, SEGMENT_RECORD_LENGTH);
|
1418 |
+
for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) {
|
1419 |
+
$gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
|
1420 |
+
}
|
1421 |
+
if (($gi->databaseType == GEOIP_ORG_EDITION)
|
1422 |
+
|| ($gi->databaseType == GEOIP_ORG_EDITION_V6)
|
1423 |
+
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION)
|
1424 |
+
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
|
1425 |
+
|| ($gi->databaseType == GEOIP_ISP_EDITION)
|
1426 |
+
|| ($gi->databaseType == GEOIP_ISP_EDITION_V6)
|
1427 |
+
) {
|
1428 |
+
$gi->record_length = ORG_RECORD_LENGTH;
|
1429 |
+
}
|
1430 |
+
}
|
1431 |
+
break;
|
1432 |
+
} else {
|
1433 |
+
$offset -= 4;
|
1434 |
+
}
|
1435 |
+
}
|
1436 |
+
if (($gi->databaseType == GEOIP_COUNTRY_EDITION) ||
|
1437 |
+
($gi->databaseType == GEOIP_COUNTRY_EDITION_V6) ||
|
1438 |
+
($gi->databaseType == GEOIP_PROXY_EDITION) ||
|
1439 |
+
($gi->databaseType == GEOIP_NETSPEED_EDITION)
|
1440 |
+
) {
|
1441 |
+
$gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
|
1442 |
+
}
|
1443 |
+
} else {
|
1444 |
+
$filepos = ftell($gi->filehandle);
|
1445 |
+
fseek($gi->filehandle, -3, SEEK_END);
|
1446 |
+
for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
|
1447 |
+
$delim = fread($gi->filehandle, 3);
|
1448 |
+
if ($delim == (chr(255) . chr(255) . chr(255))) {
|
1449 |
+
$gi->databaseType = ord(fread($gi->filehandle, 1));
|
1450 |
+
if ($gi->databaseType >= 106) {
|
1451 |
+
$gi->databaseType -= 105;
|
1452 |
+
}
|
1453 |
+
if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) {
|
1454 |
+
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
|
1455 |
+
} elseif ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
|
1456 |
+
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
|
1457 |
+
} elseif (($gi->databaseType == GEOIP_CITY_EDITION_REV0)
|
1458 |
+
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV1)
|
1459 |
+
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
|
1460 |
+
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
|
1461 |
+
|| ($gi->databaseType == GEOIP_ORG_EDITION)
|
1462 |
+
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION)
|
1463 |
+
|| ($gi->databaseType == GEOIP_ISP_EDITION)
|
1464 |
+
|| ($gi->databaseType == GEOIP_ORG_EDITION_V6)
|
1465 |
+
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
|
1466 |
+
|| ($gi->databaseType == GEOIP_ISP_EDITION_V6)
|
1467 |
+
|| ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
|
1468 |
+
|| ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
|
1469 |
+
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
|
1470 |
+
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
|
1471 |
+
|| ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1)
|
1472 |
+
|| ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6)
|
1473 |
+
|| ($gi->databaseType == GEOIP_USERTYPE_EDITION)
|
1474 |
+
|| ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6)
|
1475 |
+
|| ($gi->databaseType == GEOIP_ASNUM_EDITION)
|
1476 |
+
|| ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)
|
1477 |
+
) {
|
1478 |
+
$gi->databaseSegments = 0;
|
1479 |
+
|
1480 |
+
$buf = fread($gi->filehandle, SEGMENT_RECORD_LENGTH);
|
1481 |
+
for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) {
|
1482 |
+
$gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
|
1483 |
+
}
|
1484 |
+
if (($gi->databaseType == GEOIP_ORG_EDITION)
|
1485 |
+
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION)
|
1486 |
+
|| ($gi->databaseType == GEOIP_ISP_EDITION)
|
1487 |
+
|| ($gi->databaseType == GEOIP_ORG_EDITION_V6)
|
1488 |
+
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
|
1489 |
+
|| ($gi->databaseType == GEOIP_ISP_EDITION_V6)
|
1490 |
+
) {
|
1491 |
+
$gi->record_length = ORG_RECORD_LENGTH;
|
1492 |
+
}
|
1493 |
+
}
|
1494 |
+
break;
|
1495 |
+
} else {
|
1496 |
+
fseek($gi->filehandle, -4, SEEK_CUR);
|
1497 |
+
}
|
1498 |
+
}
|
1499 |
+
if (($gi->databaseType == GEOIP_COUNTRY_EDITION) ||
|
1500 |
+
($gi->databaseType == GEOIP_COUNTRY_EDITION_V6) ||
|
1501 |
+
($gi->databaseType == GEOIP_PROXY_EDITION) ||
|
1502 |
+
($gi->databaseType == GEOIP_NETSPEED_EDITION)
|
1503 |
+
) {
|
1504 |
+
$gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
|
1505 |
+
}
|
1506 |
+
fseek($gi->filehandle, $filepos, SEEK_SET);
|
1507 |
+
}
|
1508 |
+
return $gi;
|
1509 |
+
}
|
1510 |
+
|
1511 |
+
# This should be only used for variable-length records where
|
1512 |
+
# $start + $maxLength may be greater than the shared mem size
|
1513 |
+
function _sharedMemRead($gi, $start, $maxLength)
|
1514 |
+
{
|
1515 |
+
$readLength = min(shmop_size($gi->shmid) - $start, $maxLength);
|
1516 |
+
return shmop_read($gi->shmid, $start, $readLength);
|
1517 |
+
}
|
1518 |
+
|
1519 |
+
function geoip_open($filename, $flags)
|
1520 |
+
{
|
1521 |
+
$gi = new GeoIP;
|
1522 |
+
$gi->flags = $flags;
|
1523 |
+
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
1524 |
+
$gi->shmid = shmop_open(GEOIP_SHM_KEY, "a", 0, 0);
|
1525 |
+
} else {
|
1526 |
+
$gi->filehandle = fopen($filename, "rb") or trigger_error("GeoIP API: Can not open $filename\n", E_USER_ERROR);
|
1527 |
+
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
1528 |
+
$s_array = fstat($gi->filehandle);
|
1529 |
+
$gi->memory_buffer = fread($gi->filehandle, $s_array['size']);
|
1530 |
+
}
|
1531 |
+
}
|
1532 |
+
|
1533 |
+
$gi = $this->_setup_segments($gi);
|
1534 |
+
return $gi;
|
1535 |
+
}
|
1536 |
+
|
1537 |
+
function geoip_close($gi)
|
1538 |
+
{
|
1539 |
+
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
1540 |
+
return true;
|
1541 |
+
}
|
1542 |
+
|
1543 |
+
return fclose($gi->filehandle);
|
1544 |
+
}
|
1545 |
+
|
1546 |
+
function geoip_country_id_by_name_v6($gi, $name)
|
1547 |
+
{
|
1548 |
+
$rec = dns_get_record($name, DNS_AAAA);
|
1549 |
+
if (!$rec) {
|
1550 |
+
return false;
|
1551 |
+
}
|
1552 |
+
$addr = $rec[0]["ipv6"];
|
1553 |
+
if (!$addr || $addr == $name) {
|
1554 |
+
return false;
|
1555 |
+
}
|
1556 |
+
return geoip_country_id_by_addr_v6($gi, $addr);
|
1557 |
+
}
|
1558 |
+
|
1559 |
+
function geoip_country_id_by_name($gi, $name)
|
1560 |
+
{
|
1561 |
+
$addr = gethostbyname($name);
|
1562 |
+
if (!$addr || $addr == $name) {
|
1563 |
+
return false;
|
1564 |
+
}
|
1565 |
+
return geoip_country_id_by_addr($gi, $addr);
|
1566 |
+
}
|
1567 |
+
|
1568 |
+
function geoip_country_code_by_name_v6($gi, $name)
|
1569 |
+
{
|
1570 |
+
$country_id = geoip_country_id_by_name_v6($gi, $name);
|
1571 |
+
if ($country_id !== false) {
|
1572 |
+
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
1573 |
+
}
|
1574 |
+
return false;
|
1575 |
+
}
|
1576 |
+
|
1577 |
+
function geoip_country_code_by_name($gi, $name)
|
1578 |
+
{
|
1579 |
+
$country_id = geoip_country_id_by_name($gi, $name);
|
1580 |
+
if ($country_id !== false) {
|
1581 |
+
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
1582 |
+
}
|
1583 |
+
return false;
|
1584 |
+
}
|
1585 |
+
|
1586 |
+
function geoip_country_name_by_name_v6($gi, $name)
|
1587 |
+
{
|
1588 |
+
$country_id = geoip_country_id_by_name_v6($gi, $name);
|
1589 |
+
if ($country_id !== false) {
|
1590 |
+
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
1591 |
+
}
|
1592 |
+
return false;
|
1593 |
+
}
|
1594 |
+
|
1595 |
+
function geoip_country_name_by_name($gi, $name)
|
1596 |
+
{
|
1597 |
+
$country_id = geoip_country_id_by_name($gi, $name);
|
1598 |
+
if ($country_id !== false) {
|
1599 |
+
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
1600 |
+
}
|
1601 |
+
return false;
|
1602 |
+
}
|
1603 |
+
|
1604 |
+
function geoip_country_id_by_addr_v6($gi, $addr)
|
1605 |
+
{
|
1606 |
+
$ipnum = inet_pton($addr);
|
1607 |
+
return _geoip_seek_country_v6($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
|
1608 |
+
}
|
1609 |
+
|
1610 |
+
function geoip_country_id_by_addr($gi, $addr)
|
1611 |
+
{
|
1612 |
+
$ipnum = ip2long($addr);
|
1613 |
+
return $this->_geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
|
1614 |
+
}
|
1615 |
+
|
1616 |
+
function geoip_country_code_by_addr_v6($gi, $addr)
|
1617 |
+
{
|
1618 |
+
$country_id = $this->geoip_country_id_by_addr_v6($gi, $addr);
|
1619 |
+
if ($country_id !== false) {
|
1620 |
+
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
1621 |
+
}
|
1622 |
+
return false;
|
1623 |
+
}
|
1624 |
+
|
1625 |
+
function geoip_country_code_by_addr($gi, $addr)
|
1626 |
+
{
|
1627 |
+
if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
|
1628 |
+
$record = $this->geoip_record_by_addr($gi, $addr);
|
1629 |
+
if ($record) {
|
1630 |
+
return $record->country_code;
|
1631 |
+
}
|
1632 |
+
} else {
|
1633 |
+
$country_id = $this->geoip_country_id_by_addr($gi, $addr);
|
1634 |
+
if ($country_id !== false) {
|
1635 |
+
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
1636 |
+
}
|
1637 |
+
}
|
1638 |
+
return false;
|
1639 |
+
}
|
1640 |
+
|
1641 |
+
function geoip_country_name_by_addr_v6($gi, $addr)
|
1642 |
+
{
|
1643 |
+
$country_id = $this->geoip_country_id_by_addr_v6($gi, $addr);
|
1644 |
+
if ($country_id !== false) {
|
1645 |
+
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
1646 |
+
}
|
1647 |
+
return false;
|
1648 |
+
}
|
1649 |
+
|
1650 |
+
function geoip_country_name_by_addr($gi, $addr)
|
1651 |
+
{
|
1652 |
+
if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
|
1653 |
+
$record = geoip_record_by_addr($gi, $addr);
|
1654 |
+
return $record->country_name;
|
1655 |
+
} else {
|
1656 |
+
$country_id = $this->geoip_country_id_by_addr($gi, $addr);
|
1657 |
+
if ($country_id !== false) {
|
1658 |
+
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
1659 |
+
}
|
1660 |
+
}
|
1661 |
+
return false;
|
1662 |
+
}
|
1663 |
+
|
1664 |
+
function _geoip_seek_country_v6($gi, $ipnum)
|
1665 |
+
{
|
1666 |
+
# arrays from unpack start with offset 1
|
1667 |
+
# yet another php mystery. array_merge work around
|
1668 |
+
# this broken behaviour
|
1669 |
+
$v6vec = array_merge(unpack("C16", $ipnum));
|
1670 |
+
|
1671 |
+
$offset = 0;
|
1672 |
+
for ($depth = 127; $depth >= 0; --$depth) {
|
1673 |
+
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
1674 |
+
$buf = _safe_substr(
|
1675 |
+
$gi->memory_buffer,
|
1676 |
+
2 * $gi->record_length * $offset,
|
1677 |
+
2 * $gi->record_length
|
1678 |
+
);
|
1679 |
+
} elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
|
1680 |
+
$buf = _sharedMemRead($gi,
|
1681 |
+
2 * $gi->record_length * $offset,
|
1682 |
+
2 * $gi->record_length
|
1683 |
+
);
|
1684 |
+
} else {
|
1685 |
+
fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
|
1686 |
+
or trigger_error("GeoIP API: fseek failed", E_USER_ERROR);
|
1687 |
+
$buf = fread($gi->filehandle, 2 * $gi->record_length);
|
1688 |
+
}
|
1689 |
+
$x = array(0, 0);
|
1690 |
+
for ($i = 0; $i < 2; ++$i) {
|
1691 |
+
for ($j = 0; $j < $gi->record_length; ++$j) {
|
1692 |
+
$x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
|
1693 |
+
}
|
1694 |
+
}
|
1695 |
+
|
1696 |
+
$bnum = 127 - $depth;
|
1697 |
+
$idx = $bnum >> 3;
|
1698 |
+
$b_mask = 1 << ($bnum & 7 ^ 7);
|
1699 |
+
if (($v6vec[$idx] & $b_mask) > 0) {
|
1700 |
+
if ($x[1] >= $gi->databaseSegments) {
|
1701 |
+
return $x[1];
|
1702 |
+
}
|
1703 |
+
$offset = $x[1];
|
1704 |
+
} else {
|
1705 |
+
if ($x[0] >= $gi->databaseSegments) {
|
1706 |
+
return $x[0];
|
1707 |
+
}
|
1708 |
+
$offset = $x[0];
|
1709 |
+
}
|
1710 |
+
}
|
1711 |
+
trigger_error("GeoIP API: Error traversing database - perhaps it is corrupt?", E_USER_ERROR);
|
1712 |
+
return false;
|
1713 |
+
}
|
1714 |
+
|
1715 |
+
function _geoip_seek_country($gi, $ipnum)
|
1716 |
+
{
|
1717 |
+
$offset = 0;
|
1718 |
+
for ($depth = 31; $depth >= 0; --$depth) {
|
1719 |
+
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
1720 |
+
$buf = _safe_substr(
|
1721 |
+
$gi->memory_buffer,
|
1722 |
+
2 * $gi->record_length * $offset,
|
1723 |
+
2 * $gi->record_length
|
1724 |
+
);
|
1725 |
+
} elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
|
1726 |
+
$buf = _sharedMemRead(
|
1727 |
+
$gi,
|
1728 |
+
2 * $gi->record_length * $offset,
|
1729 |
+
2 * $gi->record_length
|
1730 |
+
);
|
1731 |
+
} else {
|
1732 |
+
fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
|
1733 |
+
or trigger_error("GeoIP API: fseek failed", E_USER_ERROR);
|
1734 |
+
$buf = fread($gi->filehandle, 2 * $gi->record_length);
|
1735 |
+
}
|
1736 |
+
$x = array(0, 0);
|
1737 |
+
for ($i = 0; $i < 2; ++$i) {
|
1738 |
+
for ($j = 0; $j < $gi->record_length; ++$j) {
|
1739 |
+
$x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
|
1740 |
+
}
|
1741 |
+
}
|
1742 |
+
if ($ipnum & (1 << $depth)) {
|
1743 |
+
if ($x[1] >= $gi->databaseSegments) {
|
1744 |
+
return $x[1];
|
1745 |
+
}
|
1746 |
+
$offset = $x[1];
|
1747 |
+
} else {
|
1748 |
+
if ($x[0] >= $gi->databaseSegments) {
|
1749 |
+
return $x[0];
|
1750 |
+
}
|
1751 |
+
$offset = $x[0];
|
1752 |
+
}
|
1753 |
+
}
|
1754 |
+
trigger_error("GeoIP API: Error traversing database - perhaps it is corrupt?", E_USER_ERROR);
|
1755 |
+
return false;
|
1756 |
+
}
|
1757 |
+
|
1758 |
+
function _common_get_org($gi, $seek_org)
|
1759 |
+
{
|
1760 |
+
$record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments;
|
1761 |
+
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
1762 |
+
$org_buf = _sharedMemRead($gi, $record_pointer, MAX_ORG_RECORD_LENGTH);
|
1763 |
+
} else {
|
1764 |
+
fseek($gi->filehandle, $record_pointer, SEEK_SET);
|
1765 |
+
$org_buf = fread($gi->filehandle, MAX_ORG_RECORD_LENGTH);
|
1766 |
+
}
|
1767 |
+
$org_buf = _safe_substr($org_buf, 0, strpos($org_buf, "\0"));
|
1768 |
+
return $org_buf;
|
1769 |
+
}
|
1770 |
+
|
1771 |
+
function _get_org_v6($gi, $ipnum)
|
1772 |
+
{
|
1773 |
+
$seek_org = _geoip_seek_country_v6($gi, $ipnum);
|
1774 |
+
if ($seek_org == $gi->databaseSegments) {
|
1775 |
+
return null;
|
1776 |
+
}
|
1777 |
+
return _common_get_org($gi, $seek_org);
|
1778 |
+
}
|
1779 |
+
|
1780 |
+
function _get_org($gi, $ipnum)
|
1781 |
+
{
|
1782 |
+
$seek_org = _geoip_seek_country($gi, $ipnum);
|
1783 |
+
if ($seek_org == $gi->databaseSegments) {
|
1784 |
+
return null;
|
1785 |
+
}
|
1786 |
+
return _common_get_org($gi, $seek_org);
|
1787 |
+
}
|
1788 |
+
|
1789 |
+
|
1790 |
+
function geoip_name_by_addr_v6($gi, $addr)
|
1791 |
+
{
|
1792 |
+
if ($addr == null) {
|
1793 |
+
return 0;
|
1794 |
+
}
|
1795 |
+
$ipnum = inet_pton($addr);
|
1796 |
+
return _get_org_v6($gi, $ipnum);
|
1797 |
+
}
|
1798 |
+
|
1799 |
+
function geoip_name_by_addr($gi, $addr)
|
1800 |
+
{
|
1801 |
+
if ($addr == null) {
|
1802 |
+
return 0;
|
1803 |
+
}
|
1804 |
+
$ipnum = ip2long($addr);
|
1805 |
+
return _get_org($gi, $ipnum);
|
1806 |
+
}
|
1807 |
+
|
1808 |
+
function geoip_org_by_addr($gi, $addr)
|
1809 |
+
{
|
1810 |
+
return geoip_name_by_addr($gi, $addr);
|
1811 |
+
}
|
1812 |
+
|
1813 |
+
function _get_region($gi, $ipnum)
|
1814 |
+
{
|
1815 |
+
if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) {
|
1816 |
+
$seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV0;
|
1817 |
+
if ($seek_region >= 1000) {
|
1818 |
+
$country_code = "US";
|
1819 |
+
$region = chr(($seek_region - 1000) / 26 + 65) . chr(($seek_region - 1000) % 26 + 65);
|
1820 |
+
} else {
|
1821 |
+
$country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region];
|
1822 |
+
$region = "";
|
1823 |
+
}
|
1824 |
+
return array($country_code, $region);
|
1825 |
+
} elseif ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
|
1826 |
+
$seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV1;
|
1827 |
+
if ($seek_region < US_OFFSET) {
|
1828 |
+
$country_code = "";
|
1829 |
+
$region = "";
|
1830 |
+
} elseif ($seek_region < CANADA_OFFSET) {
|
1831 |
+
$country_code = "US";
|
1832 |
+
$region = chr(($seek_region - US_OFFSET) / 26 + 65) . chr(($seek_region - US_OFFSET) % 26 + 65);
|
1833 |
+
} elseif ($seek_region < WORLD_OFFSET) {
|
1834 |
+
$country_code = "CA";
|
1835 |
+
$region = chr(($seek_region - CANADA_OFFSET) / 26 + 65) . chr(($seek_region - CANADA_OFFSET) % 26 + 65);
|
1836 |
+
} else {
|
1837 |
+
$country_code = $gi->GEOIP_COUNTRY_CODES[(int)(($seek_region - WORLD_OFFSET) / FIPS_RANGE)];
|
1838 |
+
$region = "";
|
1839 |
+
}
|
1840 |
+
return array($country_code, $region);
|
1841 |
+
}
|
1842 |
+
return null;
|
1843 |
+
}
|
1844 |
+
|
1845 |
+
function geoip_region_by_addr($gi, $addr)
|
1846 |
+
{
|
1847 |
+
if ($addr == null) {
|
1848 |
+
return 0;
|
1849 |
+
}
|
1850 |
+
$ipnum = ip2long($addr);
|
1851 |
+
return _get_region($gi, $ipnum);
|
1852 |
+
}
|
1853 |
+
|
1854 |
+
function _safe_substr($string, $start, $length)
|
1855 |
+
{
|
1856 |
+
// workaround php's broken substr, strpos, etc handling with
|
1857 |
+
// mbstring.func_overload and mbstring.internal_encoding
|
1858 |
+
$mbExists = extension_loaded('mbstring');
|
1859 |
+
|
1860 |
+
if ($mbExists) {
|
1861 |
+
$enc = mb_internal_encoding();
|
1862 |
+
mb_internal_encoding('ISO-8859-1');
|
1863 |
+
}
|
1864 |
+
|
1865 |
+
$buf = substr($string, $start, $length);
|
1866 |
+
|
1867 |
+
if ($mbExists) {
|
1868 |
+
mb_internal_encoding($enc);
|
1869 |
+
}
|
1870 |
+
|
1871 |
+
return $buf;
|
1872 |
+
}
|
1873 |
+
}
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>BrainActs_RestrictCheckout</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>osm</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Hides add to cart and checkout button using simple rules.</summary>
|
10 |
+
<description>Hides add to cart and checkout button using simple rules.</description>
|
11 |
+
<notes>First stable release</notes>
|
12 |
+
<authors><author><name>Aleksandr Tykhnov</name><user>nakilon</user><email>tihonov.sania@gmail.com</email></author></authors>
|
13 |
+
<date>2016-11-14</date>
|
14 |
+
<time>11:40:25</time>
|
15 |
+
<contents><target name="mageetc"><dir name="modules"><file name="AT_RestrictCheckout.xml" hash="f8ec1fcc3e1425791c60c8f30d93748e"/></dir></target><target name="magelocal"><dir name="AT"><dir name="RestrictCheckout"><dir name="Block"><dir name="Rewrite"><dir name="Checkout"><dir name="Cart"><file name="Sidebar.php" hash="c4f82afd77667ee7a45f6071d6d2b1a2"/></dir><dir name="Onepage"><file name="Link.php" hash="841ac0a461df9fde17e95c0a6815ae27"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="0d95c9898e502cff500f50b64c722e75"/><dir name="Rewrite"><dir name="Checkout"><file name="Data.php" hash="3420cd8d1213cc06d930fade7e5b7514"/></dir></dir></dir><dir name="Model"><file name="Observer.php" hash="1cea3ce3587244c8d2c87851872250b2"/><dir name="Rewrite"><dir name="Catalog"><file name="Product.php" hash="9cd06bf2263f06cedc2380ee97732065"/></dir></dir><dir name="System"><dir name="Config"><dir name="Source"><file name="Country.php" hash="cb45fc395a2ba04cbbeeec57a3b77e2f"/><file name="Message.php" hash="36a0e3e7b68287cc373ca89fb6cb82bf"/><file name="Website.php" hash="88aabb7ca15d2c56c3cad4db7ad38bee"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="ac523e5bdc657e4d7e14ad3c9d358e9f"/><file name="system.xml" hash="9a54a0705bead25f7341addb8259e9ce"/></dir></dir></dir></target><target name="mage"><dir name="lib"><dir name="AT"><dir name="MaxMind"><file name="GeoIP.php" hash="39b1a7f935c085a256fb7bec0673e5e5"/></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="AT_RestrictCheckout.csv" hash="dbb5685def365ba1af4d4dbbf6fe8e24"/></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.3.0</min><max>7.0.4</max></php></required></dependencies>
|
18 |
+
</package>
|