Skip to content

Commit 93cbcb7

Browse files
author
Jerry Bramstång
committed
Added ability to mock ip through admin
1 parent 1b0e4a1 commit 93cbcb7

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Webbhuset GeoIP Info Block
4+
*
5+
* @category Webbhuset
6+
* @package Webbhuset_Geoip
7+
* @author Webbhuset <[email protected]>
8+
*/
9+
class Webbhuset_Geoip_Block_System_Config_Info
10+
extends Mage_Adminhtml_Block_System_Config_Form_Field
11+
{
12+
/**
13+
* Remove scope label
14+
*
15+
* @param Varien_Data_Form_Element_Abstract $element
16+
* @return string
17+
*/
18+
public function render(Varien_Data_Form_Element_Abstract $element)
19+
{
20+
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
21+
22+
return parent::render($element);
23+
}
24+
25+
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
26+
{
27+
$ip = Mage::helper('webbhusetgeoip')->getIp();
28+
$geoIP = Mage::getSingleton('webbhusetgeoip/country');
29+
$currentCountry = $geoIP->getCountry();
30+
31+
if (!$currentCountry) {
32+
$currentCountry = "no match for IP";
33+
} else {
34+
$country = Mage::getModel('directory/country')->loadByCode($currentCountry);
35+
$countryName = $country->getName();
36+
$currentCountry = "{$countryName} ({$currentCountry})";
37+
}
38+
39+
$html = "<table><tr><td><td><td></tr>";
40+
$html .="<tr><td>Country:<td><td>{$currentCountry}<td></tr>";
41+
$html .="<tr><td>Current IP:<td><td>{$ip}<td></tr>";
42+
$html .= "</table>";
43+
44+
return $html;
45+
}
46+
}

app/code/community/Webbhuset/Geoip/Helper/Data.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,22 @@ public function extract($archive, $destination, $files)
8888

8989
return 0;
9090
}
91+
92+
/**
93+
* Returns remote IP or if configured replaces it with configured mock IP
94+
*
95+
* @return string
96+
*/ public function getIp()
97+
{
98+
$remoteIp = Mage::helper('core/http')->getRemoteAddr();
99+
$localIp = Mage::getStoreConfi('webbhusetgeoip/debug/local_ip');
100+
$devIp = Mage::getStoreConfi('webbhusetgeoip/debug/mock_ip');
101+
$debug = Mage::getStoreConfi('webbhusetgeoip/debug/enabled');
102+
103+
if ($localIp == $remoteIp && $devIp && $debug) {
104+
return $devIp;
105+
}
106+
107+
return $remoteIp;
108+
}
91109
}

app/code/community/Webbhuset/Geoip/etc/system.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,55 @@
8585
</geoip_synchronize>
8686
</fields>
8787
</general>
88+
<debug translate="label">
89+
<label>Debug</label>
90+
<sort_order>1000</sort_order>
91+
<show_in_default>1</show_in_default>
92+
<show_in_website>0</show_in_website>
93+
<show_in_store>0</show_in_store>
94+
<expanded>1</expanded>
95+
<fields>
96+
<enabled translate="label comment">
97+
<label>Enable Debug mode</label>
98+
<comment>This will enable you to replace your IP.</comment>
99+
<sort_order>10</sort_order>
100+
<frontend_type>select</frontend_type>
101+
<source_model>adminhtml/system_config_source_yesno</source_model>
102+
<default>0</default>
103+
<show_in_default>1</show_in_default>
104+
<show_in_website>1</show_in_website>
105+
<show_in_store>1</show_in_store>
106+
</enabled>
107+
<local_ip translate="label comment">
108+
<label>Local Ip</label>
109+
<comment>Your IP.</comment>
110+
<sort_order>20</sort_order>
111+
<frontend_type>text</frontend_type>
112+
<show_in_default>1</show_in_default>
113+
<show_in_website>1</show_in_website>
114+
<show_in_store>1</show_in_store>
115+
</local_ip>
116+
<mock_ip translate="label comment">
117+
<label>Mock IP</label>
118+
<comment>The IP to replace yours with.</comment>
119+
<sort_order>30</sort_order>
120+
<frontend_type>text</frontend_type>
121+
<show_in_default>1</show_in_default>
122+
<show_in_website>1</show_in_website>
123+
<show_in_store>1</show_in_store>
124+
</mock_ip>
125+
<geoip_info translate="label comment">
126+
<label>GeoIP info</label>
127+
<frontend_type>text</frontend_type>
128+
<frontend_model>webbhusetgeoip/system_config_info</frontend_model>
129+
<sort_order>40</sort_order>
130+
<show_in_default>1</show_in_default>
131+
<show_in_website>1</show_in_website>
132+
<show_in_store>1</show_in_store>
133+
<comment>geoip info</comment>
134+
</geoip_info>
135+
</fields>
136+
</debug>
88137
</groups>
89138
</webbhusetgeoip>
90139
</sections>

0 commit comments

Comments
 (0)