Version Description
- Bugfix: check for IPv6 compatibility on settings page
Download this release
Release Info
Developer | Tom Braider |
Plugin | Count per Day |
Version | 3.5.4 |
Comparing to | |
See all releases |
Code changes from version 3.5.3 to 3.5.4
- counter-core.php +54 -34
- counter-options.php +13 -7
- counter.php +18 -16
- geoip.php +31 -24
- map/map.php +6 -2
- readme.txt +4 -3
counter-core.php
CHANGED
@@ -11,9 +11,9 @@ if (!defined('ABSPATH'))
|
|
11 |
* include GeoIP addon if available
|
12 |
*/
|
13 |
$cpd_geoip_dir = WP_CONTENT_DIR.'/count-per-day-geoip/';
|
14 |
-
if ( file_exists($cpd_geoip_dir.'geoip.inc') )
|
15 |
include_once('geoip.php');
|
16 |
-
$cpd_geoip = ( class_exists('GeoIp') && file_exists($cpd_geoip_dir.'GeoIP.dat') ) ? 1 : 0;
|
17 |
|
18 |
/**
|
19 |
* helper functions
|
@@ -268,8 +268,8 @@ function checkInstalledVersion()
|
|
268 |
*/
|
269 |
function anonymize_ip( $ip )
|
270 |
{
|
271 |
-
//
|
272 |
-
if (
|
273 |
return $ip;
|
274 |
|
275 |
if ( $this->options['debug'] )
|
@@ -1574,64 +1574,84 @@ function cpdColumnContent($column_name, $id = 0)
|
|
1574 |
function loadGeoIpAddon()
|
1575 |
{
|
1576 |
global $cpd_path, $cpd_geoip_dir;
|
1577 |
-
|
1578 |
-
$source = 'https://raw.githubusercontent.com/maxmind/geoip-api-php/master/src/geoip.inc';
|
1579 |
-
$dest = $cpd_geoip_dir.'geoip.inc';
|
1580 |
|
1581 |
// create dir
|
1582 |
if (!is_dir($cpd_geoip_dir))
|
1583 |
-
mkdir($cpd_geoip_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1584 |
|
1585 |
// get remote file
|
1586 |
$file = file_get_contents($source, 'r');
|
1587 |
|
1588 |
// write new locale file
|
1589 |
-
|
|
|
1590 |
|
1591 |
if (is_file($dest))
|
|
|
|
|
1592 |
return __('GeoIP Addon installed.', 'cpd');
|
|
|
1593 |
else
|
1594 |
-
echo '<div class="error"><p>'.sprintf(__('Sorry, an error occurred. Load the file from %s and copy it to wp-content/count-per-day-geoip/ directory.', 'cpd'), '<a href="'.$source.'">'.$source.'</a>').'</p></div>';
|
1595 |
}
|
1596 |
|
1597 |
/**
|
1598 |
* Windows server < PHP 5.3
|
1599 |
* PHP without IPv6 support
|
1600 |
*/
|
1601 |
-
function inetPton($ip)
|
1602 |
{
|
1603 |
-
|
1604 |
-
if (strpos($ip, '.') !== FALSE)
|
1605 |
{
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
$ip = explode(':',$ip);
|
1611 |
-
$ip = pack('N',ip2long($ip[count($ip)-1]));
|
1612 |
-
}
|
1613 |
}
|
1614 |
-
|
1615 |
-
|
|
|
1616 |
{
|
1617 |
$ip = explode(':', $ip);
|
1618 |
-
$parts=8-count($ip);
|
1619 |
-
$res=''
|
1620 |
-
|
|
|
1621 |
{
|
1622 |
-
if ($seg!='')
|
1623 |
$res .= str_pad($seg, 4, '0', STR_PAD_LEFT);
|
1624 |
-
|
1625 |
-
|
1626 |
-
|
1627 |
-
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
|
|
1631 |
}
|
1632 |
$ip = pack('H'.strlen($res), $res);
|
1633 |
}
|
|
|
|
|
|
|
|
|
1634 |
return $ip;
|
1635 |
}
|
1636 |
|
1637 |
-
} // class
|
|
11 |
* include GeoIP addon if available
|
12 |
*/
|
13 |
$cpd_geoip_dir = WP_CONTENT_DIR.'/count-per-day-geoip/';
|
14 |
+
if ( file_exists($cpd_geoip_dir.'geoip.inc') && filesize($cpd_geoip_dir.'geoip.inc') > 1000 ) // not empty
|
15 |
include_once('geoip.php');
|
16 |
+
$cpd_geoip = ( class_exists('GeoIp') && file_exists($cpd_geoip_dir.'GeoIP.dat') && filesize($cpd_geoip_dir.'GeoIP.dat') > 1000 ) ? 1 : 0;
|
17 |
|
18 |
/**
|
19 |
* helper functions
|
268 |
*/
|
269 |
function anonymize_ip( $ip )
|
270 |
{
|
271 |
+
// only IPv4
|
272 |
+
if( !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) )
|
273 |
return $ip;
|
274 |
|
275 |
if ( $this->options['debug'] )
|
1574 |
function loadGeoIpAddon()
|
1575 |
{
|
1576 |
global $cpd_path, $cpd_geoip_dir;
|
|
|
|
|
|
|
1577 |
|
1578 |
// create dir
|
1579 |
if (!is_dir($cpd_geoip_dir))
|
1580 |
+
if (!mkdir($cpd_geoip_dir))
|
1581 |
+
{
|
1582 |
+
echo '<div class="error"><p>'.sprintf(__('Could not create directory %s!', 'cpd'), '<code>wp-content/count-per-day-geoip</code>').'</p></div>';
|
1583 |
+
return false;
|
1584 |
+
};
|
1585 |
+
|
1586 |
+
// function checks
|
1587 |
+
if ( !ini_get('allow_url_fopen') )
|
1588 |
+
{
|
1589 |
+
echo '<div class="error"><p>'.__('Sorry, <code>allow_url_fopen</code> is disabled!', 'cpd').'</p></div>';
|
1590 |
+
return false;
|
1591 |
+
}
|
1592 |
+
|
1593 |
+
$source = 'https://raw.githubusercontent.com/maxmind/geoip-api-php/master/src/geoip.inc';
|
1594 |
+
$dest = $cpd_geoip_dir.'geoip.inc';
|
1595 |
|
1596 |
// get remote file
|
1597 |
$file = file_get_contents($source, 'r');
|
1598 |
|
1599 |
// write new locale file
|
1600 |
+
if ( is_writable($cpd_geoip_dir) )
|
1601 |
+
file_put_contents($dest, $file);
|
1602 |
|
1603 |
if (is_file($dest))
|
1604 |
+
{
|
1605 |
+
@chmod($dest, 0755);
|
1606 |
return __('GeoIP Addon installed.', 'cpd');
|
1607 |
+
}
|
1608 |
else
|
1609 |
+
echo '<div class="error"><p>'.sprintf(__('Sorry, an error occurred. Load the file from %s and copy it to wp-content/count-per-day-geoip/ directory.', 'cpd'), '<a href="'.$source.'" target="_blank">'.$source.'</a>').'</p></div>';
|
1610 |
}
|
1611 |
|
1612 |
/**
|
1613 |
* Windows server < PHP 5.3
|
1614 |
* PHP without IPv6 support
|
1615 |
*/
|
1616 |
+
static function inetPton($ip)
|
1617 |
{
|
1618 |
+
// convert to IPv6 e.g. '::62.149.142.175' or '62.149.142.175'
|
1619 |
+
if ( strpos($ip, '.') !== FALSE )
|
1620 |
{
|
1621 |
+
$ip = explode(':', $ip);
|
1622 |
+
$ip = $ip[count($ip) - 1];
|
1623 |
+
$ip = explode('.', $ip);
|
1624 |
+
$ip = '::FFFF:'.sprintf("%'.02s", dechex($ip[0])).sprintf("%'.02s", dechex($ip[1])).':'.sprintf("%'.02s", dechex($ip[2])).sprintf("%'.02s", dechex($ip[3]));
|
|
|
|
|
|
|
1625 |
}
|
1626 |
+
|
1627 |
+
// IPv6
|
1628 |
+
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
1629 |
{
|
1630 |
$ip = explode(':', $ip);
|
1631 |
+
$parts = 8 - count($ip);
|
1632 |
+
$res = '';
|
1633 |
+
$replaced = 0;
|
1634 |
+
foreach ( $ip as $seg )
|
1635 |
{
|
1636 |
+
if ( $seg != '' )
|
1637 |
$res .= str_pad($seg, 4, '0', STR_PAD_LEFT);
|
1638 |
+
elseif ( $replaced == 0 )
|
1639 |
+
{
|
1640 |
+
for ( $i = 0; $i <= $parts; $i++ )
|
1641 |
+
$res .= '0000';
|
1642 |
+
$replaced = 1;
|
1643 |
+
}
|
1644 |
+
elseif ( $replaced == 1 )
|
1645 |
+
$res .= '0000';
|
1646 |
}
|
1647 |
$ip = pack('H'.strlen($res), $res);
|
1648 |
}
|
1649 |
+
else
|
1650 |
+
// Dummy IP if no valid IP found
|
1651 |
+
$ip = inetPton('127.0.0.1');
|
1652 |
+
|
1653 |
return $ip;
|
1654 |
}
|
1655 |
|
1656 |
+
} // class
|
1657 |
+
|
counter-options.php
CHANGED
@@ -92,7 +92,7 @@ if(!empty($_POST['do']))
|
|
92 |
{
|
93 |
$result = CpdGeoIp::updateGeoIpFile();
|
94 |
echo '<div class="updated"><p>'.$result.'</p></div>';
|
95 |
-
if ( file_exists($
|
96 |
$cpd_geoip = 1;
|
97 |
}
|
98 |
break;
|
@@ -102,16 +102,17 @@ if(!empty($_POST['do']))
|
|
102 |
$result = $count_per_day->loadGeoIpAddon();
|
103 |
if ($result)
|
104 |
echo '<div class="updated"><p>'.$result.'</p></div>';
|
105 |
-
if ( file_exists($cpd_path.'geoip.php') && file_exists($cpd_geoip_dir.'geoip.inc') )
|
106 |
{
|
107 |
include_once($cpd_path.'geoip.php');
|
108 |
-
if ( !file_exists($cpd_geoip_dir.'GeoIP.dat') )
|
109 |
{
|
110 |
// download new GeoIP database
|
111 |
$result = CpdGeoIp::updateGeoIpFile();
|
112 |
-
echo
|
113 |
}
|
114 |
-
$
|
|
|
115 |
}
|
116 |
break;
|
117 |
|
@@ -750,7 +751,12 @@ switch($mode) {
|
|
750 |
<div class="postbox">
|
751 |
<h3><span class="cpd_icon cpd_geoip"> </span> <?php _e('GeoIP - Countries', 'cpd') ?></h3>
|
752 |
<div class="inside">
|
753 |
-
|
|
|
|
|
|
|
|
|
|
|
754 |
<p>
|
755 |
<?php _e('You can get the country data for all entries in database by checking the IP adress against the GeoIP database. This can take a while!', 'cpd') ?>
|
756 |
</p>
|
@@ -774,7 +780,7 @@ switch($mode) {
|
|
774 |
</form>
|
775 |
<?php } ?>
|
776 |
|
777 |
-
<?php if ( !file_exists($cpd_geoip_dir.'geoip.inc') ) {
|
778 |
// install GeoIP Addon
|
779 |
echo '<p style="color:red">'.__('To get country data by checking the IP addresses you need to install the GeoIP Addon.<br>Because it is not under GPL I had to delete this function from WordPress plugin repository.', 'cpd').'</p>';
|
780 |
echo '<p>'.sprintf(__('The directory %s will be created.', 'cpd'), '<code>wp-content/count-per-day-geoip</code>').'</p>';
|
92 |
{
|
93 |
$result = CpdGeoIp::updateGeoIpFile();
|
94 |
echo '<div class="updated"><p>'.$result.'</p></div>';
|
95 |
+
if ( file_exists($cpd_geoip_dir.'GeoIP.dat') && filesize($cpd_geoip_dir.'GeoIP.dat') > 1000 )
|
96 |
$cpd_geoip = 1;
|
97 |
}
|
98 |
break;
|
102 |
$result = $count_per_day->loadGeoIpAddon();
|
103 |
if ($result)
|
104 |
echo '<div class="updated"><p>'.$result.'</p></div>';
|
105 |
+
if ( file_exists($cpd_path.'geoip.php') && file_exists($cpd_geoip_dir.'geoip.inc') && filesize($cpd_geoip_dir.'geoip.inc') > 1000 )
|
106 |
{
|
107 |
include_once($cpd_path.'geoip.php');
|
108 |
+
if ( !file_exists($cpd_geoip_dir.'GeoIP.dat') || filesize($cpd_geoip_dir.'GeoIP.dat') < 1000 )
|
109 |
{
|
110 |
// download new GeoIP database
|
111 |
$result = CpdGeoIp::updateGeoIpFile();
|
112 |
+
echo $result;
|
113 |
}
|
114 |
+
if ( file_exists($cpd_geoip_dir.'GeoIP.dat') && filesize($cpd_geoip_dir.'GeoIP.dat') > 1000 )
|
115 |
+
$cpd_geoip = 1;
|
116 |
}
|
117 |
break;
|
118 |
|
751 |
<div class="postbox">
|
752 |
<h3><span class="cpd_icon cpd_geoip"> </span> <?php _e('GeoIP - Countries', 'cpd') ?></h3>
|
753 |
<div class="inside">
|
754 |
+
|
755 |
+
<?php if ( $cpd_geoip ) {
|
756 |
+
|
757 |
+
if ( (!function_exists('inet_pton') || !@inet_pton('::127.0.0.1') ) && !defined('CPD_GEOIP_PATCH') )
|
758 |
+
echo '<p style="color:red">'.sprintf(__("ERROR: NO IPv6 SUPPORT<br/>Please load, unzip and copy this patched %s to %s.", 'cpd'), '<a href="http://www.tomsdimension.de/downloads/geoipincpatch">geoip.inc</a>', "<code>$cpd_geoip_dir</code>").'</p>';
|
759 |
+
?>
|
760 |
<p>
|
761 |
<?php _e('You can get the country data for all entries in database by checking the IP adress against the GeoIP database. This can take a while!', 'cpd') ?>
|
762 |
</p>
|
780 |
</form>
|
781 |
<?php } ?>
|
782 |
|
783 |
+
<?php if ( !file_exists($cpd_geoip_dir.'geoip.inc') || filesize($cpd_geoip_dir.'geoip.inc') < 1000 ) {
|
784 |
// install GeoIP Addon
|
785 |
echo '<p style="color:red">'.__('To get country data by checking the IP addresses you need to install the GeoIP Addon.<br>Because it is not under GPL I had to delete this function from WordPress plugin repository.', 'cpd').'</p>';
|
786 |
echo '<p>'.sprintf(__('The directory %s will be created.', 'cpd'), '<code>wp-content/count-per-day-geoip</code>').'</p>';
|
counter.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Count Per Day
|
4 |
Plugin URI: http://www.tomsdimension.de/wp-plugins/count-per-day
|
5 |
Description: Counter, shows reads and visitors per page; today, yesterday, last week, last months ... on dashboard, per shortcode or in widget.
|
6 |
-
Version: 3.5.
|
7 |
License: Postcardware
|
8 |
Author: Tom Braider
|
9 |
Author URI: http://www.tomsdimension.de
|
@@ -13,7 +13,7 @@ if (!defined('ABSPATH'))
|
|
13 |
exit;
|
14 |
|
15 |
$cpd_dir_name = 'count-per-day';
|
16 |
-
$cpd_version = '3.5.
|
17 |
|
18 |
if (strpos($_SERVER['SERVER_NAME'], '.test'))
|
19 |
$cpd_path = str_replace('/', DIRECTORY_SEPARATOR, ABSPATH.PLUGINDIR.'/'.$cpd_dir_name.'/');
|
@@ -148,14 +148,13 @@ function count( $x, $page = 'x' )
|
|
148 |
$count = $this->mysqlQuery('var', $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->cpd_counter WHERE ip=$this->aton(%s) AND date=%s AND page=%d", $userip, $date, $page), 'count check '.__LINE__);
|
149 |
if ( !$count )
|
150 |
{
|
151 |
-
|
152 |
// IP to IPv4
|
153 |
-
if (
|
154 |
{
|
155 |
// IPv4
|
156 |
$userip2 = $userip;
|
157 |
}
|
158 |
-
else
|
159 |
{
|
160 |
// IPv6
|
161 |
// store dummy ipv4 until we can handle ipv6
|
@@ -167,6 +166,12 @@ function count( $x, $page = 'x' )
|
|
167 |
$unpacked = array_slice($unpacked, 12);
|
168 |
$userip2 = implode('.', $unpacked);
|
169 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
// save count
|
172 |
if ($cpd_geoip)
|
@@ -174,15 +179,11 @@ function count( $x, $page = 'x' )
|
|
174 |
// with GeoIP addon save country
|
175 |
$gi = geoip_open($cpd_geoip_dir.'GeoIP.dat', GEOIP_STANDARD);
|
176 |
|
177 |
-
if (
|
178 |
-
|
|
|
179 |
|
180 |
-
|
181 |
-
// IPv4
|
182 |
-
$country = strtolower(geoip_country_code_by_addr_v6($gi, '::'.$userip));
|
183 |
-
else
|
184 |
-
// IPv6
|
185 |
-
$country = strtolower(geoip_country_code_by_addr_v6($gi, $userip));
|
186 |
|
187 |
if (empty($country))
|
188 |
$country = '-';
|
@@ -1311,11 +1312,12 @@ function getMap( $what = 'visitors', $width = 500, $height = 430 )
|
|
1311 |
$vo = array();
|
1312 |
foreach ($oc as $ip => $x)
|
1313 |
{
|
1314 |
-
|
|
|
1315 |
// IPv4 -> IPv6
|
1316 |
$ip = '::'.$ip;
|
1317 |
-
|
1318 |
-
|
1319 |
}
|
1320 |
}
|
1321 |
else
|
3 |
Plugin Name: Count Per Day
|
4 |
Plugin URI: http://www.tomsdimension.de/wp-plugins/count-per-day
|
5 |
Description: Counter, shows reads and visitors per page; today, yesterday, last week, last months ... on dashboard, per shortcode or in widget.
|
6 |
+
Version: 3.5.4
|
7 |
License: Postcardware
|
8 |
Author: Tom Braider
|
9 |
Author URI: http://www.tomsdimension.de
|
13 |
exit;
|
14 |
|
15 |
$cpd_dir_name = 'count-per-day';
|
16 |
+
$cpd_version = '3.5.4';
|
17 |
|
18 |
if (strpos($_SERVER['SERVER_NAME'], '.test'))
|
19 |
$cpd_path = str_replace('/', DIRECTORY_SEPARATOR, ABSPATH.PLUGINDIR.'/'.$cpd_dir_name.'/');
|
148 |
$count = $this->mysqlQuery('var', $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->cpd_counter WHERE ip=$this->aton(%s) AND date=%s AND page=%d", $userip, $date, $page), 'count check '.__LINE__);
|
149 |
if ( !$count )
|
150 |
{
|
|
|
151 |
// IP to IPv4
|
152 |
+
if (filter_var($userip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
|
153 |
{
|
154 |
// IPv4
|
155 |
$userip2 = $userip;
|
156 |
}
|
157 |
+
else if (filter_var($userip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
158 |
{
|
159 |
// IPv6
|
160 |
// store dummy ipv4 until we can handle ipv6
|
166 |
$unpacked = array_slice($unpacked, 12);
|
167 |
$userip2 = implode('.', $unpacked);
|
168 |
}
|
169 |
+
else
|
170 |
+
{
|
171 |
+
// no valid IP address -> dummy
|
172 |
+
$userip = '127.0.0.1';
|
173 |
+
$userip2 = $userip;
|
174 |
+
}
|
175 |
|
176 |
// save count
|
177 |
if ($cpd_geoip)
|
179 |
// with GeoIP addon save country
|
180 |
$gi = geoip_open($cpd_geoip_dir.'GeoIP.dat', GEOIP_STANDARD);
|
181 |
|
182 |
+
if (filter_var($userip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
|
183 |
+
// IPv4 -> IPv6
|
184 |
+
$userip = '::'.$userip;
|
185 |
|
186 |
+
$country = strtolower(geoip_country_code_by_addr_v6($gi, $userip));
|
|
|
|
|
|
|
|
|
|
|
187 |
|
188 |
if (empty($country))
|
189 |
$country = '-';
|
1312 |
$vo = array();
|
1313 |
foreach ($oc as $ip => $x)
|
1314 |
{
|
1315 |
+
// if ( strpos($ip,'.') !== false && strpos($ip,':') === false)
|
1316 |
+
if( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) )
|
1317 |
// IPv4 -> IPv6
|
1318 |
$ip = '::'.$ip;
|
1319 |
+
$country = strtoupper(geoip_country_code_by_addr_v6($gi, $ip));
|
1320 |
+
$cpd_data[$country] = (isset($cpd_data[$country])) ? $cpd_data[$country] + 1 : 1;
|
1321 |
}
|
1322 |
}
|
1323 |
else
|
geoip.php
CHANGED
@@ -23,15 +23,16 @@ static function getCountry( $ip )
|
|
23 |
global $cpd_geoip_dir;
|
24 |
|
25 |
// IPv4 > IPv6
|
26 |
-
if
|
27 |
$ip = "::$ip";
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
if (filter_var($ip, FILTER_VALIDATE_IP))
|
32 |
{
|
|
|
|
|
33 |
$c = strtolower(geoip_country_code_by_addr_v6($gi, $ip));
|
34 |
$cname = geoip_country_name_by_addr_v6($gi, $ip);
|
|
|
35 |
}
|
36 |
|
37 |
if ( empty($c) )
|
@@ -39,7 +40,6 @@ static function getCountry( $ip )
|
|
39 |
$c = 'unknown';
|
40 |
$cname = '';
|
41 |
}
|
42 |
-
geoip_close($gi);
|
43 |
$country = array( $c, '<div class="cpd-flag cpd-flag-'.$c.'" title="'.$cname.'"></div>', $cname );
|
44 |
return $country;
|
45 |
}
|
@@ -58,7 +58,7 @@ static function updateDB()
|
|
58 |
foreach ($res as $r)
|
59 |
{
|
60 |
$c = '';
|
61 |
-
if (
|
62 |
{
|
63 |
// IPv4
|
64 |
$ip = explode('.', $r->realip);
|
@@ -73,7 +73,7 @@ static function updateDB()
|
|
73 |
// get country
|
74 |
$c = strtolower(geoip_country_code_by_addr_v6($gi, '::'.$r->realip));
|
75 |
}
|
76 |
-
else
|
77 |
{
|
78 |
// IPv6
|
79 |
if ( strpos($r->realip, '::1') === 0
|
@@ -106,10 +106,10 @@ static function updateGeoIpFile()
|
|
106 |
|
107 |
// function checks
|
108 |
if ( !ini_get('allow_url_fopen') )
|
109 |
-
return 'Sorry, <code>allow_url_fopen</code> is disabled!';
|
110 |
|
111 |
if ( !function_exists('gzopen') )
|
112 |
-
return __('Sorry, necessary functions (zlib) not installed or enabled in php.ini.', 'cpd');
|
113 |
|
114 |
$gzfile = 'http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz';
|
115 |
$file = $cpd_geoip_dir.'GeoIP.dat';
|
@@ -118,24 +118,31 @@ static function updateGeoIpFile()
|
|
118 |
$h = gzopen($gzfile, 'rb');
|
119 |
$content = gzread($h, 2000000);
|
120 |
fclose($h);
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
// write new locale file
|
130 |
-
$h = fopen($file, 'wb');
|
131 |
-
fwrite($h, $content);
|
132 |
-
fclose($h);
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
return __('New GeoIP database installed.', 'cpd');
|
137 |
else
|
138 |
-
return __('Sorry, an error occurred. Try again or check the access rights of directory "wp-content/count-per-day-geoip".', 'cpd');
|
139 |
}
|
140 |
|
141 |
|
23 |
global $cpd_geoip_dir;
|
24 |
|
25 |
// IPv4 > IPv6
|
26 |
+
if( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) )
|
27 |
$ip = "::$ip";
|
28 |
|
29 |
+
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
|
|
|
|
30 |
{
|
31 |
+
// IPv6
|
32 |
+
$gi = geoip_open($cpd_geoip_dir.'GeoIP.dat', GEOIP_STANDARD);
|
33 |
$c = strtolower(geoip_country_code_by_addr_v6($gi, $ip));
|
34 |
$cname = geoip_country_name_by_addr_v6($gi, $ip);
|
35 |
+
geoip_close($gi);
|
36 |
}
|
37 |
|
38 |
if ( empty($c) )
|
40 |
$c = 'unknown';
|
41 |
$cname = '';
|
42 |
}
|
|
|
43 |
$country = array( $c, '<div class="cpd-flag cpd-flag-'.$c.'" title="'.$cname.'"></div>', $cname );
|
44 |
return $country;
|
45 |
}
|
58 |
foreach ($res as $r)
|
59 |
{
|
60 |
$c = '';
|
61 |
+
if ( filter_var($r->realip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) )
|
62 |
{
|
63 |
// IPv4
|
64 |
$ip = explode('.', $r->realip);
|
73 |
// get country
|
74 |
$c = strtolower(geoip_country_code_by_addr_v6($gi, '::'.$r->realip));
|
75 |
}
|
76 |
+
else if ( filter_var($r->realip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) )
|
77 |
{
|
78 |
// IPv6
|
79 |
if ( strpos($r->realip, '::1') === 0
|
106 |
|
107 |
// function checks
|
108 |
if ( !ini_get('allow_url_fopen') )
|
109 |
+
return '<div class="error"><p>'.__('Sorry, <code>allow_url_fopen</code> is disabled!', 'cpd').'</p></div>';
|
110 |
|
111 |
if ( !function_exists('gzopen') )
|
112 |
+
return '<div class="error"><p>'.__('Sorry, necessary functions (zlib) not installed or enabled in php.ini.', 'cpd').'</p></div>';
|
113 |
|
114 |
$gzfile = 'http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz';
|
115 |
$file = $cpd_geoip_dir.'GeoIP.dat';
|
118 |
$h = gzopen($gzfile, 'rb');
|
119 |
$content = gzread($h, 2000000);
|
120 |
fclose($h);
|
121 |
+
|
122 |
+
if ( strlen($content) < 1000000 )
|
123 |
+
return '<div class="error"><p>'.__('Sorry, could not read the GeoIP database file.', 'cpd').'</p></div>';
|
124 |
+
|
125 |
+
if ( is_writable($cpd_geoip_dir) )
|
126 |
+
{
|
127 |
+
// delete local file
|
128 |
+
if (is_file($file))
|
129 |
+
unlink($file);
|
130 |
+
|
131 |
+
// file deleted?
|
132 |
+
$del = (is_file($file)) ? 0 : 1;
|
133 |
+
|
134 |
+
// write new locale file
|
135 |
+
$h = fopen($file, 'wb');
|
136 |
+
fwrite($h, $content);
|
137 |
+
fclose($h);
|
138 |
|
139 |
+
@chmod($file, 0755);
|
140 |
+
}
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
+
if ( is_file($file) && $del && filesize($file) > 1000000 )
|
143 |
+
return '<div class="updated"><p>'.__('New GeoIP database installed.', 'cpd').'</p></div>';
|
|
|
144 |
else
|
145 |
+
return '<div class="error"><p>'.__('Sorry, an error occurred. Try again or check the access rights of directory "wp-content/count-per-day-geoip".', 'cpd').'</p></div>';
|
146 |
}
|
147 |
|
148 |
|
map/map.php
CHANGED
@@ -18,10 +18,14 @@ if ( $what == 'online' )
|
|
18 |
$vo = array();
|
19 |
foreach ($oc as $ip => $x)
|
20 |
{
|
21 |
-
|
|
|
22 |
// IPv4 -> IPv6
|
23 |
$ip = '::'.$ip;
|
24 |
-
|
|
|
|
|
|
|
25 |
$data[$country] = (isset($data[$country])) ? $data[$country] + 1 : 1;
|
26 |
}
|
27 |
}
|
18 |
$vo = array();
|
19 |
foreach ($oc as $ip => $x)
|
20 |
{
|
21 |
+
$country = '-';
|
22 |
+
if( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) )
|
23 |
// IPv4 -> IPv6
|
24 |
$ip = '::'.$ip;
|
25 |
+
|
26 |
+
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
27 |
+
// IPv6
|
28 |
+
$country = strtoupper(geoip_country_code_by_addr_v6($gi, $ip));
|
29 |
$data[$country] = (isset($data[$country])) ? $data[$country] + 1 : 1;
|
30 |
}
|
31 |
}
|
readme.txt
CHANGED
@@ -3,14 +3,12 @@ Contributors: Tom Braider
|
|
3 |
Tags: counter, count, posts, visits, reads, dashboard, widget, shortcode
|
4 |
Requires at least: 3.0
|
5 |
Tested up to: 4.6
|
6 |
-
Stable tag: 3.5.
|
7 |
License: Postcardware :)
|
8 |
Donate link: http://www.tomsdimension.de/postcards
|
9 |
|
10 |
Visit Counter, shows reads and visitors per page, visitors today, yesterday, last week, last months and other statistics.
|
11 |
|
12 |
-
|
13 |
-
|
14 |
== Description ==
|
15 |
|
16 |
* count reads and visitors
|
@@ -308,6 +306,9 @@ show( $before, $after, $show, $count, $page )'
|
|
308 |
|
309 |
== Changelog ==
|
310 |
|
|
|
|
|
|
|
311 |
= 3.5.3 =
|
312 |
+ Bugfix: undefined function cpd_inet_pton (once again)
|
313 |
|
3 |
Tags: counter, count, posts, visits, reads, dashboard, widget, shortcode
|
4 |
Requires at least: 3.0
|
5 |
Tested up to: 4.6
|
6 |
+
Stable tag: 3.5.4
|
7 |
License: Postcardware :)
|
8 |
Donate link: http://www.tomsdimension.de/postcards
|
9 |
|
10 |
Visit Counter, shows reads and visitors per page, visitors today, yesterday, last week, last months and other statistics.
|
11 |
|
|
|
|
|
12 |
== Description ==
|
13 |
|
14 |
* count reads and visitors
|
306 |
|
307 |
== Changelog ==
|
308 |
|
309 |
+
= 3.5.4 =
|
310 |
+
+ Bugfix: check for IPv6 compatibility on settings page
|
311 |
+
|
312 |
= 3.5.3 =
|
313 |
+ Bugfix: undefined function cpd_inet_pton (once again)
|
314 |
|