Sweetapple_Geotargeting - Version 0.1.3

Version Notes

Compatible with Magento Community Edition 1.7.0, 1.7.1 and 1.7.2.

Download this release

Release Info

Developer Sweet-Apple
Extension Sweetapple_Geotargeting
Version 0.1.3
Comparing to
See all releases


Code changes from version 0.1.2 to 0.1.3

app/code/local/Sweetapple/Geotargeting/Helper/Data.php CHANGED
@@ -48,7 +48,9 @@ class Sweetapple_Geotargeting_Helper_Data extends Mage_Core_Helper_Abstract {
48
  $ip = $this->_getIPToTest( $ip );
49
 
50
  // Update the DB if necessary...
51
- $this->_updateDatabase();
 
 
52
 
53
  //Get the country code...
54
  require_once( $this->_modulePath . "/GeoIP/geoip.class.php" );
@@ -69,7 +71,7 @@ class Sweetapple_Geotargeting_Helper_Data extends Mage_Core_Helper_Abstract {
69
 
70
 
71
  /**
72
- * Returns the IP to test, using first specfic IP, then value from Module settings, finally $_SERVER['REMOTE_ADDR']
73
  * @param string $ip
74
  * @return string
75
  */
@@ -87,7 +89,7 @@ class Sweetapple_Geotargeting_Helper_Data extends Mage_Core_Helper_Abstract {
87
  * Checks if the cached database needs updating. Updates are released on the first Tuesday of the month...
88
  * @return bool
89
  */
90
- private function _databaseNeedsUpdate()
91
  {
92
 
93
  if( file_exists( $this->_databasePath ) ){
@@ -114,21 +116,23 @@ class Sweetapple_Geotargeting_Helper_Data extends Mage_Core_Helper_Abstract {
114
  */
115
  private function _updateDatabase()
116
  {
117
- if( $this->_databaseNeedsUpdate() ){
 
118
 
119
- $store = Mage::app()->getStore();
120
- $updateUrl = $store->getConfig( self::XML_PATH_GEOIP_UPDATE_PATH );
 
 
 
121
 
122
- $client = new Zend_Http_Client($updateUrl);
123
- $response = $client->request(Zend_Http_Client::GET);
124
- // getBody() automatically decodes the body! Nice one Zend!
125
- $gzBody = $response->getBody();
126
- $body = $this->_gzdecode( $gzBody );
127
 
128
- return ( file_put_contents( $this->_databasePath, $body ) !== false) ? true : false ;
129
- }
130
 
131
- return true;
 
 
 
132
  }
133
 
134
 
48
  $ip = $this->_getIPToTest( $ip );
49
 
50
  // Update the DB if necessary...
51
+ if($this->_checkDatabaseNeedsUpdate()) {
52
+ $this->_updateDatabase();
53
+ }
54
 
55
  //Get the country code...
56
  require_once( $this->_modulePath . "/GeoIP/geoip.class.php" );
71
 
72
 
73
  /**
74
+ * Returns the IP to test, using first specific IP, then value from Module settings, finally $_SERVER['REMOTE_ADDR']
75
  * @param string $ip
76
  * @return string
77
  */
89
  * Checks if the cached database needs updating. Updates are released on the first Tuesday of the month...
90
  * @return bool
91
  */
92
+ private function _checkDatabaseNeedsUpdate()
93
  {
94
 
95
  if( file_exists( $this->_databasePath ) ){
116
  */
117
  private function _updateDatabase()
118
  {
119
+ $store = Mage::app()->getStore();
120
+ $updateUrl = $store->getConfig( self::XML_PATH_GEOIP_UPDATE_PATH );
121
 
122
+ $client = new Zend_Http_Client($updateUrl);
123
+ $response = $client->request(Zend_Http_Client::GET);
124
+ // getBody() automatically decodes the body! Nice one Zend!
125
+ $gzBody = $response->getBody();
126
+ $body = $this->_gzdecode( $gzBody );
127
 
128
+ return ( file_put_contents( $this->_databasePath, $body ) !== false) ? true : false ;
129
+ }
 
 
 
130
 
 
 
131
 
132
+
133
+ public function updateDatabase()
134
+ {
135
+ $this->_updateDatabase();
136
  }
137
 
138
 
app/code/local/Sweetapple/Geotargeting/Model/{Testip.php → Validator/Testip.php} RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Sweetapple_Geotargeting_Model_Testip
4
  *
5
  * This module was developed by Sweet-Apple. If you require any
6
  * support or have any questions please contact us at info@sweet-apple.co.uk.
@@ -12,7 +12,7 @@
12
  * @license OSL v3.0
13
  */
14
 
15
- class Sweetapple_Geotargeting_Model_Testip extends Mage_Core_Model_Config_Data {
16
 
17
 
18
  /**
@@ -26,17 +26,18 @@ class Sweetapple_Geotargeting_Model_Testip extends Mage_Core_Model_Config_Data {
26
  if( (strlen($newIP) == 0 ) || $validateIp->isValid( $newIP) ){
27
  return parent::save(); //call original save method to save value
28
  }else{
29
- Mage::getSingleton('adminhtml/session')->addError('Please enter a valid IP address for the Download URL.');
30
  }
31
  }
32
 
33
 
34
  /**
35
- * After downloadurl is changed in System->Config clear the value stored in the session
36
  * @return Mage_Core_Model_Abstract|void
37
  */
38
  protected function _afterSave()
39
  {
 
40
  Mage::getSingleton('core/session')->setData('sweetapple_geoip_country');
41
  }
42
 
1
  <?php
2
  /**
3
+ * Sweetapple_Geotargeting_Model_Validator_Testip
4
  *
5
  * This module was developed by Sweet-Apple. If you require any
6
  * support or have any questions please contact us at info@sweet-apple.co.uk.
12
  * @license OSL v3.0
13
  */
14
 
15
+ class Sweetapple_Geotargeting_Model_Validator_Testip extends Mage_Core_Model_Config_Data {
16
 
17
 
18
  /**
26
  if( (strlen($newIP) == 0 ) || $validateIp->isValid( $newIP) ){
27
  return parent::save(); //call original save method to save value
28
  }else{
29
+ Mage::getSingleton('adminhtml/session')->addError('Please enter a valid IP address for the Test IP Address field.');
30
  }
31
  }
32
 
33
 
34
  /**
35
+ * After Test IP Address is changed in System->Config clear the value stored in the session
36
  * @return Mage_Core_Model_Abstract|void
37
  */
38
  protected function _afterSave()
39
  {
40
+
41
  Mage::getSingleton('core/session')->setData('sweetapple_geoip_country');
42
  }
43
 
app/code/local/Sweetapple/Geotargeting/Model/Validator/Updateurl.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sweetapple_Geotargeting_Model_Validator_UpdateUrl
4
+ *
5
+ * This module was developed by Sweet-Apple. If you require any
6
+ * support or have any questions please contact us at info@sweet-apple.co.uk.
7
+ *
8
+ * @category Sweetapple
9
+ * @package Sweetapple_Geotargeting
10
+ * @author Clive Sweeting, Sweet-Apple <info@sweet-apple.co.uk>
11
+ * @copyright Copyright (c) 2013 Sweet-Apple (http://www.sweet-apple.co.uk)
12
+ * @license OSL v3.0
13
+ */
14
+
15
+ class Sweetapple_Geotargeting_Model_Validator_UpdateUrl extends Mage_Core_Model_Config_Data {
16
+
17
+
18
+ /**
19
+ * Before saving, check a valid IP adddress has been entered...
20
+ * @return Mage_Core_Model_Abstract
21
+ */
22
+ public function save()
23
+ {
24
+ $newUrl = $this->getValue(); //get the value from our config
25
+
26
+ if(filter_var($newUrl, FILTER_VALIDATE_URL))
27
+ {
28
+ return parent::save(); //call original save method to save value
29
+ }
30
+ else
31
+ {
32
+ Mage::getSingleton('adminhtml/session')->addError('Please enter a valid URL for the Database Update URL field.');
33
+ }
34
+ }
35
+
36
+
37
+ /**
38
+ * After downloadurl is changed in System->Config clear the value stored in the session
39
+ * @return Mage_Core_Model_Abstract|void
40
+ */
41
+ protected function _afterSave()
42
+ {
43
+ $_ipHelper = Mage::helper('sweetapple_geotargeting/data'); /* @var $_ipHelper Sweetapple_Geotargeting_Helper_Data */
44
+ $_ipHelper->updateDatabase();
45
+ }
46
+
47
+ }
app/code/local/Sweetapple/Geotargeting/etc/system.xml CHANGED
@@ -52,16 +52,17 @@
52
  <show_in_default>1</show_in_default>
53
  <fields>
54
  <download_url translate="label">
 
55
  <label>Database Update URL</label>
56
- <comment><![CDATA[ Enter the URL to the <strong>GeoLite Country</strong> in <strong>Binary/GZIP</strong> format. This URL should very infrequently change, but you can find the most update to date link on this <a href="http://dev.maxmind.com/geoip/legacy/geolite" target="_blank">page</a><br /><br /> The module automatically updates the database on the first Wednesday of every month..]]></comment>
57
  <frontend_type>text</frontend_type>
58
  <sort_order>10</sort_order>
59
  <show_in_default>1</show_in_default>
60
  </download_url>
61
  <test_ip translate="label">
62
- <backend_model>sweetapple_geotargeting/testip</backend_model>
63
  <label>Test IP Address</label>
64
- <comment><![CDATA[ Enter an IP Address you wish to use to test the GeoIP functionality. You can find suitable IP address <a href="http://www.nirsoft.net/countryip/" target="_blank">here</a> Please remember to delete this after testing, otherwise all requests on the site will be tested against this value.<br /><br />More robust testing can be done through using a <strong>Web Proxy</strong> to simulate traffic from another physical location. ..]]></comment>
65
  <frontend_type>text</frontend_type>
66
  <sort_order>20</sort_order>
67
  <show_in_default>1</show_in_default>
52
  <show_in_default>1</show_in_default>
53
  <fields>
54
  <download_url translate="label">
55
+ <backend_model>sweetapple_geotargeting/validator_updateurl</backend_model>
56
  <label>Database Update URL</label>
57
+ <comment><![CDATA[ Enter the URL to the <strong>GeoLite Country</strong> in <strong>Binary/GZIP</strong> format. This URL should very infrequently change, but you can find the most update to date link on this <a href="http://dev.maxmind.com/geoip/legacy/geolite" target="_blank">page</a><br /><br /> The module automatically updates the database on changing this value and on the first Wednesday of every month.]]></comment>
58
  <frontend_type>text</frontend_type>
59
  <sort_order>10</sort_order>
60
  <show_in_default>1</show_in_default>
61
  </download_url>
62
  <test_ip translate="label">
63
+ <backend_model>sweetapple_geotargeting/validator_testip</backend_model>
64
  <label>Test IP Address</label>
65
+ <comment><![CDATA[ Enter an IP Address you wish to use to test the GeoIP functionality. You can find suitable IP address <a href="http://www.nirsoft.net/countryip/" target="_blank">here</a> Please remember to delete this after testing, otherwise all requests on the site will be tested against this value.<br /><br />More robust testing can be done through using a <strong>Web Proxy</strong> to simulate traffic from another physical location.]]></comment>
66
  <frontend_type>text</frontend_type>
67
  <sort_order>20</sort_order>
68
  <show_in_default>1</show_in_default>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Sweetapple_Geotargeting</name>
4
- <version>0.1.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/OSL-3.0">OSL v3.0 </license>
7
  <channel>community</channel>
@@ -23,9 +23,9 @@ echo $this-&gt;getLayout()-&gt;createBlock('cms/block')-&gt;setBlockId('home_pag
23
  </description>
24
  <notes>Compatible with Magento Community Edition 1.7.0, 1.7.1 and 1.7.2.</notes>
25
  <authors><author><name>Sweet-Apple</name><user>Sweet-Apple</user><email>info@sweet-apple.co.uk</email></author></authors>
26
- <date>2013-06-08</date>
27
- <time>06:15:50</time>
28
- <contents><target name="magelocal"><dir name="Sweetapple"><dir name="Geotargeting"><dir name="Block"><file name="Geotargeting.php" hash="e01db5ffd2619aea9ef77c56b57f108e"/></dir><dir name="GeoIP"><file name="GeoIP.dat" hash="acc4ad4f2f6078669cd0a7b44ba5a779"/><file name="geoip.class.php" hash="7d979a4e5e469cdc93033f53d31f4a3f"/><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><dir name="Helper"><file name="Data.php" hash="dbed97adf319044aee2fb80f983c9a75"/></dir><dir name="Model"><file name="Testip.php" hash="63dfecfe786799296619e57a232f8f9a"/></dir><dir name="etc"><file name="config.xml" hash="3a10bf4280a5a24429b3fefb7603adc1"/><file name="system.xml" hash="b90472aa6888bb44ecc010b80e921b3f"/></dir><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sweetapple_Geotargeting.xml" hash="fa46b233d4234ecb58ce1a8ea97aeeaf"/></dir></target></contents>
29
  <compatible/>
30
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
31
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Sweetapple_Geotargeting</name>
4
+ <version>0.1.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/OSL-3.0">OSL v3.0 </license>
7
  <channel>community</channel>
23
  </description>
24
  <notes>Compatible with Magento Community Edition 1.7.0, 1.7.1 and 1.7.2.</notes>
25
  <authors><author><name>Sweet-Apple</name><user>Sweet-Apple</user><email>info@sweet-apple.co.uk</email></author></authors>
26
+ <date>2013-06-09</date>
27
+ <time>11:24:09</time>
28
+ <contents><target name="magelocal"><dir name="Sweetapple"><dir name="Geotargeting"><dir name="Block"><file name="Geotargeting.php" hash="e01db5ffd2619aea9ef77c56b57f108e"/></dir><dir name="GeoIP"><file name="GeoIP.dat" hash="acc4ad4f2f6078669cd0a7b44ba5a779"/><file name="geoip.class.php" hash="7d979a4e5e469cdc93033f53d31f4a3f"/><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><dir name="Helper"><file name="Data.php" hash="71e3b7b4769f50261a7248e1498031eb"/></dir><dir name="Model"><dir name="Validator"><file name="Testip.php" hash="670b1a8ba14c544770702bc9322f8b94"/><file name="Updateurl.php" hash="2f4e919fe61414301cd03ab00479e7e3"/></dir></dir><dir name="etc"><file name="config.xml" hash="3a10bf4280a5a24429b3fefb7603adc1"/><file name="system.xml" hash="9c7967f5ce72fa392a96057e43e32e9b"/></dir><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sweetapple_Geotargeting.xml" hash="fa46b233d4234ecb58ce1a8ea97aeeaf"/></dir></target></contents>
29
  <compatible/>
30
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
31
  </package>