Count per Day - Version 3.5.1

Version Description

  • back in WordPress plugin repository
  • Bugfix: Worldmap shortcode
Download this release

Release Info

Developer Tom Braider
Plugin Icon 128x128 Count per Day
Version 3.5.1
Comparing to
See all releases

Code changes from version 3.4.1 to 3.5.1

ajax.php CHANGED
@@ -1,23 +1,22 @@
1
<?php
2
if ( $_GET['f'] == 'count' )
3
{
4
- // answer only for 20 seconds after calling
5
- if ( empty($_GET['time']) || time() - $_GET['time'] > 20 )
6
- {
7
- header("HTTP/1.0 403 Forbidden");
8
- die('wrong request');
9
- }
10
-
11
- if (!session_id()) session_start();
12
- $cpd_wp = (!empty($_SESSION['cpd_wp'])) ? $_SESSION['cpd_wp'] : '../../../';
13
- require_once($cpd_wp.'wp-load.php');
14
-
15
$cpd_funcs = array ( 'show',
16
'getReadsAll', 'getReadsToday', 'getReadsYesterday', 'getReadsLastWeek', 'getReadsThisMonth',
17
'getUserAll', 'getUserToday', 'getUserYesterday', 'getUserLastWeek', 'getUserThisMonth',
18
'getUserPerDay', 'getUserOnline', 'getFirstCount' );
19
20
- $page = (int) $_GET['page'];
21
if ( is_numeric($page) )
22
{
23
$count_per_day->count( '', $page );
1
<?php
2
+ if (!defined('ABSPATH'))
3
+ exit;
4
+
5
+ // answer only for 20 seconds after calling
6
+ if ( empty($_GET['time']) || time() - $_GET['time'] > 20 )
7
+ {
8
+ header("HTTP/1.0 403 Forbidden");
9
+ die('wrong request');
10
+ }
11
+
12
if ( $_GET['f'] == 'count' )
13
{
14
$cpd_funcs = array ( 'show',
15
'getReadsAll', 'getReadsToday', 'getReadsYesterday', 'getReadsLastWeek', 'getReadsThisMonth',
16
'getUserAll', 'getUserToday', 'getUserYesterday', 'getUserLastWeek', 'getUserThisMonth',
17
'getUserPerDay', 'getUserOnline', 'getFirstCount' );
18
19
+ $page = (int) $_GET['cpage'];
20
if ( is_numeric($page) )
21
{
22
$count_per_day->count( '', $page );
counter-core.php CHANGED
@@ -4,12 +4,16 @@
4
* Count Per Day - core functions
5
*/
6
7
/**
8
- * include GeoIP addon
9
*/
10
- if ( file_exists($cpd_path.'geoip/geoip.php') )
11
- include_once($cpd_path.'geoip/geoip.php');
12
- $cpd_geoip = ( class_exists('CpdGeoIp') && file_exists($cpd_path.'geoip/GeoIP.dat') ) ? 1 : 0;
13
14
/**
15
* helper functions
@@ -89,7 +93,6 @@ function init()
89
}
90
91
// locale support
92
- // if (defined('WPLANG') && function_exists('load_plugin_textdomain'))
93
load_plugin_textdomain('cpd', false, $cpd_dir_name.'/locale');
94
95
// adds stylesheet
@@ -125,12 +128,47 @@ function init()
125
if (strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/') !== false )
126
add_action('admin_enqueue_scripts', array(&$this,'addThickbox'));
127
128
- // Session
129
- if (strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/') !== false )
130
- add_action('init', array(&$this,'startSession'), 1);
131
-
132
$this->aton = 'INET_ATON';
133
$this->ntoa = 'INET_NTOA';
134
}
135
136
/**
@@ -155,19 +193,6 @@ function addJquery()
155
function addThickbox()
156
{
157
wp_enqueue_script('thickbox');
158
- // if (strpos($_SERVER['QUERY_STRING'], 'cpd_metaboxes') !== false)
159
- // wp_enqueue_script('cpd_flot', $this->dir.'/js/jquery.flot.min.js', 'jQuery');
160
- }
161
-
162
-
163
- /**
164
- * starts session to provide WP variables to "addons"
165
- */
166
- function startSession()
167
- {
168
- if (!session_id())
169
- session_start();
170
- $_SESSION['cpd_wp'] = ABSPATH;
171
}
172
173
/**
@@ -208,12 +233,12 @@ function mysqlQuery( $kind = '', $sql = '', $func = '' )
208
if ( $this->options['debug'] )
209
{
210
$con = $wpdb->dbh;
211
- $errno = (isset($con->errno)) ? $con->errno : mysql_errno($con);
212
- $error = (isset($con->error)) ? $con->error : mysql_error($con);
213
$d = number_format( microtime(true) - $t , 5);
214
$m = sprintf("%.2f", memory_get_usage()/1048576).' MB';
215
$error = (!$r && $errno) ? '<b style="color:red">ERROR:</b> '.$errno.' - '.$error.' - ' : '';
216
- $this->queries[] = $func." : <b>$d</b> - $m<br/><code>$preparedSql</code><br/>$error";
217
$this->queries[0] += $d;
218
}
219
@@ -229,7 +254,10 @@ function checkInstalledVersion()
229
if ( $this->options['version'] != $cpd_version )
230
{
231
$this->checkVersion();
232
- echo '<div class="updated"><p>'.sprintf(__('"Count per Day" updated to version %s.', 'cpd'), $cpd_version).'</p></div>';
233
}
234
}
235
@@ -269,6 +297,8 @@ function getPostID()
269
global $wp_query;
270
// find PostID
271
if ( !is_404() ) :
272
if ( $this->options['autocount'] && is_singular() )
273
{
274
// single page with autocount on
@@ -288,9 +318,6 @@ function getPostID()
288
else if ( is_category() || is_tag() )
289
// category or tag => negativ ID in CpD DB
290
$p = 0 - $wp_query->get_queried_object_id();
291
- else
292
- // index, date, search and other "list" pages will count only once
293
- $p = 0;
294
$this->page = $p;
295
if ( $this->options['debug'] )
296
$this->queries[] = 'called Function: <b style="color:blue">getPostID</b> page ID: <code>'.$p.'</code>';
@@ -393,11 +420,11 @@ function createTables()
393
$sql = "CREATE TABLE IF NOT EXISTS `$cpd_c` (
394
`id` int(10) NOT NULL auto_increment,
395
`ip` int(10) unsigned NOT NULL,
396
- `client` varchar(250) NOT NULL,
397
`date` date NOT NULL,
398
`page` mediumint(9) NOT NULL,
399
`country` CHAR(2) NOT NULL,
400
- `referer` varchar(250) NOT NULL,
401
PRIMARY KEY (`id`),
402
KEY `idx_page` (`page`),
403
KEY `idx_dateip` (`date`,`ip`) )
@@ -443,16 +470,6 @@ function createTables()
443
$sql .= 'ADD KEY `idx_dateip` (`date`,`ip`), ADD KEY `idx_page` (`page`)';
444
$this->mysqlQuery('', $sql, 'make keys '.__LINE__);
445
446
- // column country
447
- $this->mysqlQuery('', "SELECT country FROM `$cpd_c` LIMIT 1", 'check country '.__LINE__);
448
- if ((int) mysql_errno() == 1054)
449
- $this->mysqlQuery('', "ALTER TABLE `$cpd_c` ADD `country` CHAR(2) NOT NULL", 'make country '.__LINE__);
450
-
451
- // column referrer
452
- $this->mysqlQuery('', "SELECT referer FROM `$cpd_c` LIMIT 1", 'check referer '.__LINE__);
453
- if ((int) mysql_errno() == 1054)
454
- $this->mysqlQuery('', "ALTER TABLE `$cpd_c` ADD `referer` VARCHAR(100) NOT NULL", 'make referer '.__LINE__);
455
-
456
// delete table "counter-online", since v3.0
457
$this->mysqlQuery('', "DROP TABLE IF EXISTS `$cpd_o`", 'table online '.__LINE__);
458
@@ -497,7 +514,6 @@ function showQueries()
497
498
echo '<div style="position:absolute;margin:10px;padding:10px;border:1px red solid;background:#fff;clear:both">
499
<b>Count per Day - DEBUG: '.round($this->queries[0], 3).' s</b><ol>'."\n";
500
- // var_dump($wpdb->dbh);
501
echo '<li>'
502
.'<b>Server:</b> '.$_SERVER['SERVER_SOFTWARE'].'<br/>'
503
.'<b>PHP:</b> '.phpversion().'<br/>'
@@ -513,8 +529,6 @@ function showQueries()
513
echo "\n<li><b>POST:</b><br/>\n";
514
var_dump($_POST);
515
echo '</li>';
516
- echo "\n<li><b>SESSION:</b><br/>\n";
517
- var_dump($_SESSION);
518
echo '</li>';
519
echo "\n<li><b>Table:</b><br /><b>$wpdb->cpd_counter</b>:\n";
520
$res = $this->mysqlQuery('rows', "SHOW FIELDS FROM `$wpdb->cpd_counter`", 'showFields' );
@@ -532,11 +546,11 @@ function showQueries()
532
echo "</ol>\n";
533
?>
534
<p>GeoIP:
535
- d_ir=<?php echo substr(decoct(fileperms($cpd_path.'geoip/')), -3) ?>
536
- f_ile=<?php echo (is_file($cpd_path.'geoip/GeoIP.dat')) ? substr(decoct(fileperms($cpd_path.'geoip/GeoIP.dat')), -3) : '-'; ?>
537
- f_open=<?php echo (function_exists('fopen')) ? 'true' : 'false' ?>
538
- g_zopen=<?php echo (function_exists('gzopen')) ? 'true' : 'false' ?>
539
- a_llow_url_fopen=<?php echo (ini_get('allow_url_fopen')) ? 'true' : 'false' ?>
540
</p>
541
<?php
542
echo '</div>';
@@ -571,7 +585,7 @@ function addJS()
571
function addAjaxScript()
572
{
573
$this->getPostID();
574
- $time = time();
575
echo <<< JSEND
576
<script type="text/javascript">
577
// Count per Day
@@ -579,7 +593,7 @@ function addAjaxScript()
579
var cpdTime = new Date().getTime() / 1000;
580
jQuery(document).ready( function()
581
{
582
- jQuery.get('{$this->dir}/ajax.php?f=count&page={$this->page}&time='+cpdTime, function(text)
583
{
584
var cpd_funcs = text.split('|');
585
for(var i = 0; i < cpd_funcs.length; i++)
@@ -635,7 +649,6 @@ function menu($content)
635
global $cpd_dir_name;
636
if (function_exists('add_options_page'))
637
{
638
- // $menutitle = '<img src="'.$this->img('cpd_menu.gif').'" alt="/" style="width:9px;height:12px;" /> Count per Day';
639
$menutitle = 'Count per Day';
640
add_options_page('CountPerDay', $menutitle, 'manage_options', $cpd_dir_name.'/counter-options.php') ;
641
}
@@ -684,7 +697,7 @@ function updateOptions()
684
'startreads' => '',
685
'anoip' => 0,
686
'massbotlimit' => 25,
687
- 'clients' => 'Firefox, MSIE, Chrome, Safari, Opera',
688
'ajax' => 0,
689
'debug' => 0,
690
'referers' => 1,
@@ -739,7 +752,6 @@ function screenLayoutColumns($columns, $screen)
739
*/
740
function setAdminMenu()
741
{
742
- // $menutitle = '<img src="'.$this->img('cpd_menu.gif').'" alt="" style="width:12px;height:12px;" /> Count per Day';
743
$menutitle = 'Count per Day';
744
$this->pagehook = add_submenu_page('index.php', 'CountPerDay', $menutitle, $this->options['whocansee'], CPD_METABOX, array(&$this, 'onShowPage'));
745
add_action('load-'.$this->pagehook, array(&$this, 'onLoadPage'));
@@ -901,7 +913,6 @@ function shortUserPerMonth() { return $this->getUserPerMonth(true, true); }
901
function shortUserPerPost() { return $this->getUserPerPost(0, true, true); }
902
function shortCountries() { return $this->getCountries(0, true, false, true); }
903
function shortCountriesUsers(){ return $this->getCountries(0, true, true, true); }
904
- // function shortMostVisitedPosts(){ return $this->getMostVisitedPosts(0, 0, true, false, true); }
905
function shortReferers() { return $this->getReferers(0, true, 0); }
906
function shortDayWithMostReads(){ return $this->getDayWithMostReads(true, true); }
907
function shortDayWithMostUsers(){ return $this->getDayWithMostUsers(true, true); }
@@ -937,10 +948,9 @@ function shortShowMap( $atts )
937
extract( shortcode_atts( array(
938
'width' => 500,
939
'height' => 340,
940
- 'what' => 'reads',
941
- 'min' => 0
942
), $atts) );
943
- return $this->getMap( $what, $width, $height, $min );
944
}
945
946
/**
@@ -989,6 +999,7 @@ function getMassBots( $limit )
989
function export( $days = 180 )
990
{
991
global $wpdb;
992
$t = $wpdb->cpd_counter;
993
$tname = $t.'_last_'.$days.'_days_'.date_i18n('Y-m-d_H-i-s').'.csv';
994
$path = tempnam(sys_get_temp_dir(), 'cpdexport');
@@ -1046,7 +1057,7 @@ function export( $days = 180 )
1046
$tfile = basename($path);
1047
echo '<div class="updated"><p>';
1048
_e('Download the export file:', 'cpd');
1049
- echo ' <a href="'.$this->dir.'/download.php?f='.$tfile.'&amp;n='.$tname.'">'.$tname.'</a><br/>';
1050
echo '</p></div>';
1051
1052
endif;
@@ -1127,7 +1138,6 @@ function backup()
1127
// add values
1128
$v = '';
1129
foreach ($row as $val)
1130
- // $v .= "'".mysql_real_escape_string($val)."',";
1131
$v .= "'".esc_sql($val)."',";
1132
$v = '('.substr($v,0,-1).'),';
1133
@@ -1193,9 +1203,9 @@ function backup()
1193
$tfile = basename($path);
1194
$tofile = basename($opath);
1195
echo sprintf(__('Backup of counter table saved in %s.', 'cpd'),
1196
- '<a href="'.$this->dir.'/download.php?f='.$tfile.'&amp;n='.$tname.'">'.$tname.'</a>').'<br/>';
1197
echo sprintf(__('Backup of counter options and collection saved in %s.', 'cpd'),
1198
- '<a href="'.$this->dir.'/download.php?f='.$tofile.'&amp;n='.$toname.'">'.$toname.'</a>');
1199
}
1200
else
1201
{
@@ -1558,4 +1568,30 @@ function cpdColumnContent($column_name, $id = 0)
1558
}
1559
}
1560
1561
} // class
4
* Count Per Day - core functions
5
*/
6
7
+ if (!defined('ABSPATH'))
8
+ exit;
9
+
10
/**
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
93
}
94
95
// locale support
96
load_plugin_textdomain('cpd', false, $cpd_dir_name.'/locale');
97
98
// adds stylesheet
128
if (strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/') !== false )
129
add_action('admin_enqueue_scripts', array(&$this,'addThickbox'));
130
131
$this->aton = 'INET_ATON';
132
$this->ntoa = 'INET_NTOA';
133
+
134
+ // include scripts
135
+ if (is_admin())
136
+ {
137
+ add_action('init', array(&$this,'addCpdIncludes'));
138
+ }
139
+ }
140
+
141
+ /**
142
+ * include scripts
143
+ */
144
+ function addCpdIncludes()
145
+ {
146
+ global $count_per_day, $wpdb, $cpd_geoip, $cpd_geoip_dir;
147
+
148
+ if (empty($_GET['page']))
149
+ return;
150
+
151
+ switch ($_GET['page'])
152
+ {
153
+ case 'cpd_notes':
154
+ include_once('notes.php');
155
+ exit;
156
+ case 'cpd_massbots':
157
+ include_once('massbots.php');
158
+ exit;
159
+ case 'cpd_userperspan':
160
+ include_once('userperspan.php');
161
+ exit;
162
+ case 'cpd_map':
163
+ include_once('map/map.php');
164
+ exit;
165
+ case 'cpd_ajax':
166
+ include_once('ajax.php');
167
+ exit;
168
+ case 'cpd_download':
169
+ include_once('download.php');
170
+ exit;
171
+ }
172
}
173
174
/**
193
function addThickbox()
194
{
195
wp_enqueue_script('thickbox');
196
}
197
198
/**
233
if ( $this->options['debug'] )
234
{
235
$con = $wpdb->dbh;
236
+ $errno = (isset($con->errno)) ? $con->errno : mysqli_errno($con);
237
+ $error = (isset($con->error)) ? $con->error : mysqli_error($con);
238
$d = number_format( microtime(true) - $t , 5);
239
$m = sprintf("%.2f", memory_get_usage()/1048576).' MB';
240
$error = (!$r && $errno) ? '<b style="color:red">ERROR:</b> '.$errno.' - '.$error.' - ' : '';
241
+ $this->queries[] = $func." : <b>$d</b> - $m<br/><code>$kind - $preparedSql</code><br/>$error";
242
$this->queries[0] += $d;
243
}
244
254
if ( $this->options['version'] != $cpd_version )
255
{
256
$this->checkVersion();
257
+ echo '<div class="updated">
258
+ <p>'.sprintf(__('"Count per Day" updated to version %s.', 'cpd'), $cpd_version).'</p>
259
+ <p>'.sprintf(__('Please check the %s section!', 'cpd'), '<a href="options-general.php?page=count-per-day%2Fcounter-options.php&tab=tools">GeoIP</a>').'</p>
260
+ </div>';
261
}
262
}
263
297
global $wp_query;
298
// find PostID
299
if ( !is_404() ) :
300
+ // index, date, search and other "list" pages will count only once
301
+ $p = 0;
302
if ( $this->options['autocount'] && is_singular() )
303
{
304
// single page with autocount on
318
else if ( is_category() || is_tag() )
319
// category or tag => negativ ID in CpD DB
320
$p = 0 - $wp_query->get_queried_object_id();
321
$this->page = $p;
322
if ( $this->options['debug'] )
323
$this->queries[] = 'called Function: <b style="color:blue">getPostID</b> page ID: <code>'.$p.'</code>';
420
$sql = "CREATE TABLE IF NOT EXISTS `$cpd_c` (
421
`id` int(10) NOT NULL auto_increment,
422
`ip` int(10) unsigned NOT NULL,
423
+ `client` varchar(500) NOT NULL,
424
`date` date NOT NULL,
425
`page` mediumint(9) NOT NULL,
426
`country` CHAR(2) NOT NULL,
427
+ `referer` varchar(500) NOT NULL,
428
PRIMARY KEY (`id`),
429
KEY `idx_page` (`page`),
430
KEY `idx_dateip` (`date`,`ip`) )
470
$sql .= 'ADD KEY `idx_dateip` (`date`,`ip`), ADD KEY `idx_page` (`page`)';
471
$this->mysqlQuery('', $sql, 'make keys '.__LINE__);
472
473
// delete table "counter-online", since v3.0
474
$this->mysqlQuery('', "DROP TABLE IF EXISTS `$cpd_o`", 'table online '.__LINE__);
475
514
515
echo '<div style="position:absolute;margin:10px;padding:10px;border:1px red solid;background:#fff;clear:both">
516
<b>Count per Day - DEBUG: '.round($this->queries[0], 3).' s</b><ol>'."\n";
517
echo '<li>'
518
.'<b>Server:</b> '.$_SERVER['SERVER_SOFTWARE'].'<br/>'
519
.'<b>PHP:</b> '.phpversion().'<br/>'
529
echo "\n<li><b>POST:</b><br/>\n";
530
var_dump($_POST);
531
echo '</li>';
532
echo '</li>';
533
echo "\n<li><b>Table:</b><br /><b>$wpdb->cpd_counter</b>:\n";
534
$res = $this->mysqlQuery('rows', "SHOW FIELDS FROM `$wpdb->cpd_counter`", 'showFields' );
546
echo "</ol>\n";
547
?>
548
<p>GeoIP:
549
+ dir=<?php echo substr(decoct(fileperms($cpd_geoip_dir)), -3) ?>
550
+ file=<?php echo (is_file($cpd_geoip_dir.'GeoIP.dat')) ? substr(decoct(fileperms($cpd_geoip_dir.'GeoIP.dat')), -3) : '-'; ?>
551
+ fopen=<?php echo (function_exists('fopen')) ? 'true' : 'false' ?>
552
+ gzopen=<?php echo (function_exists('gzopen')) ? 'true' : 'false' ?>
553
+ allow_url_fopen=<?php echo (ini_get('allow_url_fopen')) ? 'true' : 'false' ?>
554
</p>
555
<?php
556
echo '</div>';
585
function addAjaxScript()
586
{
587
$this->getPostID();
588
+ $wp = ADMIN_COOKIE_PATH;
589
echo <<< JSEND
590
<script type="text/javascript">
591
// Count per Day
593
var cpdTime = new Date().getTime() / 1000;
594
jQuery(document).ready( function()
595
{
596
+ jQuery.get('{$wp}/?page=cpd_ajax&f=count&cpage={$this->page}&time='+cpdTime, function(text)
597
{
598
var cpd_funcs = text.split('|');
599
for(var i = 0; i < cpd_funcs.length; i++)
649
global $cpd_dir_name;
650
if (function_exists('add_options_page'))
651
{
652
$menutitle = 'Count per Day';
653
add_options_page('CountPerDay', $menutitle, 'manage_options', $cpd_dir_name.'/counter-options.php') ;
654
}
697
'startreads' => '',
698
'anoip' => 0,
699
'massbotlimit' => 25,
700
+ 'clients' => 'Firefox, Edge, MSIE, Chrome, Safari, Opera',
701
'ajax' => 0,
702
'debug' => 0,
703
'referers' => 1,
752
*/
753
function setAdminMenu()
754
{
755
$menutitle = 'Count per Day';
756
$this->pagehook = add_submenu_page('index.php', 'CountPerDay', $menutitle, $this->options['whocansee'], CPD_METABOX, array(&$this, 'onShowPage'));
757
add_action('load-'.$this->pagehook, array(&$this, 'onLoadPage'));
913
function shortUserPerPost() { return $this->getUserPerPost(0, true, true); }
914
function shortCountries() { return $this->getCountries(0, true, false, true); }
915
function shortCountriesUsers(){ return $this->getCountries(0, true, true, true); }
916
function shortReferers() { return $this->getReferers(0, true, 0); }
917
function shortDayWithMostReads(){ return $this->getDayWithMostReads(true, true); }
918
function shortDayWithMostUsers(){ return $this->getDayWithMostUsers(true, true); }
948
extract( shortcode_atts( array(
949
'width' => 500,
950
'height' => 340,
951
+ 'what' => 'reads'
952
), $atts) );
953
+ return $this->getMap( $what, $width, $height );
954
}
955
956
/**
999
function export( $days = 180 )
1000
{
1001
global $wpdb;
1002
+ $days = intval($days);
1003
$t = $wpdb->cpd_counter;
1004
$tname = $t.'_last_'.$days.'_days_'.date_i18n('Y-m-d_H-i-s').'.csv';
1005
$path = tempnam(sys_get_temp_dir(), 'cpdexport');
1057
$tfile = basename($path);
1058
echo '<div class="updated"><p>';
1059
_e('Download the export file:', 'cpd');
1060
+ echo ' <a href="index.php?page=cpd_download&amp;f='.$tfile.'&amp;n='.$tname.'">'.$tname.'</a><br/>';
1061
echo '</p></div>';
1062
1063
endif;
1138
// add values
1139
$v = '';
1140
foreach ($row as $val)
1141
$v .= "'".esc_sql($val)."',";
1142
$v = '('.substr($v,0,-1).'),';
1143
1203
$tfile = basename($path);
1204
$tofile = basename($opath);
1205
echo sprintf(__('Backup of counter table saved in %s.', 'cpd'),
1206
+ '<a href="index.php?page=cpd_download&amp;f='.$tfile.'&amp;n='.$tname.'">'.$tname.'</a>').'<br/>';
1207
echo sprintf(__('Backup of counter options and collection saved in %s.', 'cpd'),
1208
+ '<a href="index.php?page=cpd_download&amp;f='.$tofile.'&amp;n='.$toname.'">'.$toname.'</a>');
1209
}
1210
else
1211
{
1568
}
1569
}
1570
1571
+ /**
1572
+ * load GeoIP Script from Maxmind GIT
1573
+ */
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
+ file_put_contents($dest, $file);
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
} // class
counter-options.php CHANGED
@@ -4,6 +4,9 @@
4
* Count Per Day - Options and Administration
5
*/
6
7
// check form
8
if(!empty($_POST['do']))
9
{
@@ -94,6 +97,24 @@ if(!empty($_POST['do']))
94
}
95
break;
96
97
// delete massbots
98
case 'cpd_delete_massbots' :
99
if ( isset($_POST['limit']) )
@@ -125,6 +146,12 @@ if(!empty($_POST['do']))
125
case 'cpd_reset' :
126
if(trim($_POST['reset_cpd_yes']) == 'yes')
127
{
128
$wpdb->query('TRUNCATE TABLE '.$wpdb->cpd_counter);
129
$wpdb->query('TRUNCATE TABLE '.$wpdb->cpd_counter_useronline);
130
$wpdb->query('TRUNCATE TABLE '.$wpdb->cpd_notes);
@@ -338,7 +365,7 @@ if(!empty($_POST['do']))
338
update_option('count_per_day_search', $searches);
339
unset($searches);
340
echo '<div class="updated"><p>'.__('Old search strings deleted', 'cpd').'</p></div>';
341
-
342
343
// delete clients and referers
344
case 'cpd_clientsclean' :
@@ -353,6 +380,7 @@ if(!empty($_POST['do']))
353
$count_per_day->mysqlQuery('', $cpd_sql, 'deleteClients '.__LINE__);
354
355
echo '<div class="updated"><p>'.__('Clients and referers deleted', 'cpd').'</p></div>';
356
357
default:
358
break;
@@ -465,7 +493,7 @@ switch($mode) {
465
echo '<a href="http://www.utrace.de/?query='.$ip.'">'.$ip.'</a></td>'
466
.'<td style="white-space:nowrap;">'.mysql2date(get_option('date_format'), $row->date).'</td>'
467
.'<td>'.htmlentities($row->client).'</td>'
468
- .'<td style="text-align:right;"><a href="'.$count_per_day->dir.'/massbots.php?dmbip='.$row->longip.'&amp;dmbdate='.$row->date.'&amp;KeepThis=true&amp;TB_iframe=true" title="Count per Day" class="thickbox">'
469
.$row->posts.'</a></td>'
470
.'</tr>';
471
$sum += $row->posts;
@@ -528,7 +556,7 @@ switch($mode) {
528
echo '<a href="http://www.utrace.de/?query='.$ip.'">'.$ip.'</a></td>'
529
.'<td style="white-space:nowrap;">'.mysql2date(get_option('date_format'), $row->date).'</td>'
530
.'<td>'.htmlentities($row->client).'</td>'
531
- .'<td style="text-align:right;"><a href="'.$count_per_day->dir.'/massbots.php?dmbip='.$row->longip.'&amp;dmbdate='.$row->date.'&amp;KeepThis=true&amp;TB_iframe=true" title="Count per Day" class="thickbox">'
532
.$row->posts.'</a></td>'
533
.'</tr>';
534
$sum += $row->posts;
@@ -722,10 +750,10 @@ switch($mode) {
722
<div class="postbox">
723
<h3><span class="cpd_icon cpd_geoip">&nbsp;</span> <?php _e('GeoIP - Countries', 'cpd') ?></h3>
724
<div class="inside">
725
- <p>
726
- <?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') ?>
727
- </p>
728
<?php if ( $cpd_geoip ) { ?>
729
<form method="post" action="<?php echo $mysiteurl ?>">
730
<p>
731
<input type="hidden" name="do" value="cpd_countries" />
@@ -745,6 +773,19 @@ switch($mode) {
745
</p>
746
</form>
747
<?php } ?>
748
<p>
749
<span class="cpd-r"><?php _e('More informations about GeoIP', 'cpd') ?>:
750
<a href="https://www.maxmind.com">www.maxmind.com</a></span>&nbsp;
@@ -887,7 +928,7 @@ switch($mode) {
887
<tr>
888
<th scope="row" style="white-space:nowrap"><?php _e('Post types', 'cpd') ?>:</th>
889
<td>
890
- <input class="code" type="text" name="cpd_posttypes" size="50" value="<?php echo str_replace(',', ', ', $o['posttypes']); ?>" /><br/>
891
<?php _e('Only count these post types. Leave empty to count them all.', 'cpd') ?><br/>
892
<?php printf(__('Current post types: %s', 'cpd'), '<code>'.implode(', ', get_post_types()).'</code>'); ?>
893
</td>
@@ -917,10 +958,10 @@ switch($mode) {
917
<tr>
918
<th scope="row" style="white-space:nowrap"><?php _e('Who can see it', 'cpd') ?>:</th>
919
<td>
920
- <?php $cus = (in_array($o['whocansee'], array('manage_options','manage_links','publish_posts','edit_posts','read'))) ? 0 : 1 ?>
921
<select id="cpd_whocansee" name="cpd_whocansee" onchange="checkcustom()">
922
<option value="manage_options" <?php selected($o['whocansee'], 'manage_options') ?>><?php echo translate_user_role('Administrator') ?> </option>
923
- <option value="manage_links" <?php selected($o['whocansee'], 'manage_links') ?>><?php echo translate_user_role('Editor') ?></option>
924
<option value="publish_posts" <?php selected($o['whocansee'], 'publish_posts') ?>><?php echo translate_user_role('Author') ?></option>
925
<option value="edit_posts" <?php selected($o['whocansee'], 'edit_posts') ?>><?php echo translate_user_role('Contributor') ?></option>
926
<option value="read" <?php selected($o['whocansee'], 'read') ?>><?php echo translate_user_role('Subscriber') ?></option>
4
* Count Per Day - Options and Administration
5
*/
6
7
+ if (!defined('ABSPATH'))
8
+ exit;
9
+
10
// check form
11
if(!empty($_POST['do']))
12
{
97
}
98
break;
99
100
+ // install GeoIP addon
101
+ case 'cpd_loadgeoipaddon' :
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 '<div class="updated"><p>'.$result.'</p></div>';
113
+ }
114
+ $cpd_geoip = 1;
115
+ }
116
+ break;
117
+
118
// delete massbots
119
case 'cpd_delete_massbots' :
120
if ( isset($_POST['limit']) )
146
case 'cpd_reset' :
147
if(trim($_POST['reset_cpd_yes']) == 'yes')
148
{
149
+ delete_option('count_per_day_notes');
150
+ delete_option('count_per_day_search');
151
+ delete_option('count_per_day_online');
152
+ delete_option('count_per_day_summary');
153
+ delete_option('count_per_day_collected');
154
+ delete_option('count_per_day_posts');
155
$wpdb->query('TRUNCATE TABLE '.$wpdb->cpd_counter);
156
$wpdb->query('TRUNCATE TABLE '.$wpdb->cpd_counter_useronline);
157
$wpdb->query('TRUNCATE TABLE '.$wpdb->cpd_notes);
365
update_option('count_per_day_search', $searches);
366
unset($searches);
367
echo '<div class="updated"><p>'.__('Old search strings deleted', 'cpd').'</p></div>';
368
+ break;
369
370
// delete clients and referers
371
case 'cpd_clientsclean' :
380
$count_per_day->mysqlQuery('', $cpd_sql, 'deleteClients '.__LINE__);
381
382
echo '<div class="updated"><p>'.__('Clients and referers deleted', 'cpd').'</p></div>';
383
+ break;
384
385
default:
386
break;
493
echo '<a href="http://www.utrace.de/?query='.$ip.'">'.$ip.'</a></td>'
494
.'<td style="white-space:nowrap;">'.mysql2date(get_option('date_format'), $row->date).'</td>'
495
.'<td>'.htmlentities($row->client).'</td>'
496
+ .'<td style="text-align:right;"><a href="?page=cpd_massbots&amp;dmbip='.$row->longip.'&amp;dmbdate='.$row->date.'&amp;KeepThis=true&amp;TB_iframe=true" title="Count per Day" class="thickbox">'
497
.$row->posts.'</a></td>'
498
.'</tr>';
499
$sum += $row->posts;
556
echo '<a href="http://www.utrace.de/?query='.$ip.'">'.$ip.'</a></td>'
557
.'<td style="white-space:nowrap;">'.mysql2date(get_option('date_format'), $row->date).'</td>'
558
.'<td>'.htmlentities($row->client).'</td>'
559
+ .'<td style="text-align:right;"><a href="index.php?page=cpd_massbots&amp;dmbip='.$row->longip.'&amp;dmbdate='.$row->date.'&amp;KeepThis=true&amp;TB_iframe=true" title="Count per Day" class="thickbox">'
560
.$row->posts.'</a></td>'
561
.'</tr>';
562
$sum += $row->posts;
750
<div class="postbox">
751
<h3><span class="cpd_icon cpd_geoip">&nbsp;</span> <?php _e('GeoIP - Countries', 'cpd') ?></h3>
752
<div class="inside">
753
<?php if ( $cpd_geoip ) { ?>
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>
757
<form method="post" action="<?php echo $mysiteurl ?>">
758
<p>
759
<input type="hidden" name="do" value="cpd_countries" />
773
</p>
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>';
781
+ ?>
782
+ <form method="post" action="<?php echo $mysiteurl ?>">
783
+ <p>
784
+ <input type="hidden" name="do" value="cpd_loadgeoipaddon" />
785
+ <input type="submit" name="loadgeoipaddon" value="<?php _e('Install GeoIP addon', 'cpd') ?>" class="button" />
786
+ </p>
787
+ </form>
788
+ <?php } ?>
789
<p>
790
<span class="cpd-r"><?php _e('More informations about GeoIP', 'cpd') ?>:
791
<a href="https://www.maxmind.com">www.maxmind.com</a></span>&nbsp;
928
<tr>
929
<th scope="row" style="white-space:nowrap"><?php _e('Post types', 'cpd') ?>:</th>
930
<td>
931
+ <input class="code" type="text" name="cpd_posttypes" size="50" value="<?php echo (isset($o['posttypes'])) ? str_replace(',', ', ', $o['posttypes']) : ''; ?>" /><br/>
932
<?php _e('Only count these post types. Leave empty to count them all.', 'cpd') ?><br/>
933
<?php printf(__('Current post types: %s', 'cpd'), '<code>'.implode(', ', get_post_types()).'</code>'); ?>
934
</td>
958
<tr>
959
<th scope="row" style="white-space:nowrap"><?php _e('Who can see it', 'cpd') ?>:</th>
960
<td>
961
+ <?php $cus = (in_array($o['whocansee'], array('manage_options','edit_others_posts','publish_posts','edit_posts','read'))) ? 0 : 1 ?>
962
<select id="cpd_whocansee" name="cpd_whocansee" onchange="checkcustom()">
963
<option value="manage_options" <?php selected($o['whocansee'], 'manage_options') ?>><?php echo translate_user_role('Administrator') ?> </option>
964
+ <option value="edit_others_posts" <?php selected($o['whocansee'], 'edit_others_posts') ?>><?php echo translate_user_role('Editor') ?></option>
965
<option value="publish_posts" <?php selected($o['whocansee'], 'publish_posts') ?>><?php echo translate_user_role('Author') ?></option>
966
<option value="edit_posts" <?php selected($o['whocansee'], 'edit_posts') ?>><?php echo translate_user_role('Contributor') ?></option>
967
<option value="read" <?php selected($o['whocansee'], 'read') ?>><?php echo translate_user_role('Subscriber') ?></option>
counter.css CHANGED
@@ -13,7 +13,11 @@
13
14
h2 .cpd_icon {
15
vertical-align: top;
16
- margin-top:5px;
17
}
18
19
.cpd_backups {
13
14
h2 .cpd_icon {
15
vertical-align: top;
16
+ margin-top:2px;
17
+ }
18
+
19
+ #cpdtoolccs h3 {
20
+ margin-left: 1em;
21
}
22
23
.cpd_backups {
counter.php CHANGED
@@ -3,14 +3,17 @@
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.4.1
7
License: Postcardware
8
Author: Tom Braider
9
Author URI: http://www.tomsdimension.de
10
*/
11
12
$cpd_dir_name = 'count-per-day';
13
- $cpd_version = '3.4.1';
14
15
if (strpos($_SERVER['SERVER_NAME'], '.test'))
16
$cpd_path = str_replace('/', DIRECTORY_SEPARATOR, ABSPATH.PLUGINDIR.'/'.$cpd_dir_name.'/');
@@ -27,7 +30,7 @@ class CountPerDay extends CountPerDayCore
27
/**
28
* constructor
29
*/
30
- function CountPerDay()
31
{
32
$this->init();
33
}
@@ -70,7 +73,7 @@ function show( $before='', $after=' reads', $show = true, $count = true, $page =
70
*/
71
function count( $x, $page = 'x' )
72
{
73
- global $wpdb, $wp_query, $cpd_path, $cpd_geoip, $userdata;
74
75
if ($this->options['debug'])
76
$this->queries[] = 'called Function: <b style="color:blue">count</b> page: <code>'.$page.'</code>';
@@ -145,35 +148,42 @@ function count( $x, $page = 'x' )
145
$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__);
146
if ( !$count )
147
{
148
// save count
149
if ($cpd_geoip)
150
{
151
// with GeoIP addon save country
152
- $gi = cpd_geoip_open($cpd_path.'geoip/GeoIP.dat', GEOIP_STANDARD);
153
154
if (!filter_var($userip, FILTER_VALIDATE_IP))
155
$userip = '127.0.0.1';
156
157
if ( strpos($userip,'.') !== false && strpos($userip,':') === false)
158
- {
159
// IPv4
160
- $country = strtolower(cpd_geoip_country_code_by_addr_v6($gi, '::'.$userip));
161
- $userip2 = $userip;
162
- }
163
else
164
- {
165
// IPv6
166
- $country = strtolower(cpd_geoip_country_code_by_addr_v6($gi, $userip));
167
-
168
- // store dummy ipv4 until we can handle ipv6
169
- $packed = cpd_inet_pton($userip);
170
- if (strlen($packed) === 4)
171
- $unpacked = array_pad(unpack( "C4", $packed), -16, 0);
172
- else
173
- $unpacked = array_merge(unpack( "C16", $packed));
174
- $unpacked = array_slice($unpacked, 12);
175
- $userip2 = implode('.', $unpacked);
176
- }
177
if (empty($country))
178
$country = '-';
179
@@ -185,7 +195,7 @@ function count( $x, $page = 'x' )
185
else
186
// without country
187
$this->mysqlQuery('', $wpdb->prepare("INSERT INTO $wpdb->cpd_counter (page, ip, client, date, referer)
188
- VALUES (%d, $this->aton(%s), %s, %s, %s)", $page, $userip2, $client, $date, $referer), 'count insert '.__LINE__);
189
}
190
// online counter
191
$oc = (array) get_option('count_per_day_online');
@@ -282,7 +292,7 @@ function getFlotChart( $limit = 0 )
282
// create data array
283
$data = array();
284
for ( $day = $start_time; $day < $end_time; $day = $day + 86400 )
285
- $data[$day] = array(0, 0);
286
287
// reads
288
$sql = $wpdb->prepare("
@@ -294,7 +304,7 @@ function getFlotChart( $limit = 0 )
294
$res = $this->mysqlQuery('rows', $sql, 'ChartReads '.__LINE__);
295
if ($res)
296
foreach ($res as $row)
297
- $data[strtotime($row->date)][0] = $row->count;
298
299
// visitors
300
$sql = $wpdb->prepare("
@@ -309,15 +319,15 @@ function getFlotChart( $limit = 0 )
309
$res = $this->mysqlQuery('rows', $sql, 'ChartVisitors '.__LINE__);
310
if ($res)
311
foreach ($res as $row)
312
- $data[strtotime($row->date)][1] = $row->count;
313
-
314
// fill data array
315
$reads = array();
316
$visitors = array();
317
foreach ( $data as $day => $values )
318
{
319
- $reads[] = '['.$day.'000,'.$values[0].']';
320
- $visitors[] = '['.$day.'000,'.$values[1].']';
321
}
322
$reads_line = '['.implode(',', $reads).']';
323
$visitors_line = '['.implode(',', $visitors).']';
@@ -413,6 +423,10 @@ function getFlotChart( $limit = 0 )
413
});
414
}
415
416
plotAccordingToChoices();
417
});
418
//]]>
@@ -425,7 +439,7 @@ function getFlotChart( $limit = 0 )
425
*/
426
function getUserOnline( $frontend = false, $country = false, $return = false )
427
{
428
- global $wpdb, $cpd_geoip, $cpd_path;
429
$c = '';
430
431
$oc = get_option('count_per_day_online');
@@ -434,22 +448,22 @@ function getUserOnline( $frontend = false, $country = false, $return = false )
434
{
435
// map link
436
if ( !$frontend && file_exists($cpd_path.'map/map.php') )
437
- $c .= '<div style="margin: 5px 0 10px 0;"><a href="'.$this->dir.'/map/map.php?map=online'
438
.'&amp;KeepThis=true&amp;TB_iframe=true" title="Count per Day - '.__('Map', 'cpd').'" class="thickbox button">'.__('Map', 'cpd').'</a></div>';
439
440
// countries list
441
- $geoip = new GeoIPCpd();
442
- $gi = cpd_geoip_open($cpd_path.'geoip/GeoIP.dat', GEOIP_STANDARD);
443
444
$vo = array();
445
foreach ( $oc as $ip=>$x )
446
{
447
if ( strpos($ip,'.') !== false && strpos($ip,':') === false)
448
// IPv4
449
- $country = strtolower(cpd_geoip_country_code_by_addr_v6($gi, '::'.$ip));
450
else
451
// IPv6
452
- $country = strtolower(cpd_geoip_country_code_by_addr_v6($gi, $ip));
453
$id = $geoip->GEOIP_COUNTRY_CODE_TO_NUMBER[strtoupper($country)];
454
if ( empty($id) )
455
{
@@ -892,7 +906,7 @@ function getVisitedPostsOnDay( $date = 0, $limit = 0, $show_form = true, $show_n
892
<input name="daytoshow" value="'.$date.'" size="11" />
893
<input type="submit" name="showday" value="'.__('Show').'" class="button" />';
894
if ( $show_notes )
895
- echo ' <a href="'.$this->dir.'/notes.php?KeepThis=true&amp;TB_iframe=true" title="Count per Day - '.__('Notes', 'cpd').'" class="button thickbox">'.__('Notes', 'cpd').'</a> ';
896
echo '</form>';
897
}
898
if (isset($note))
@@ -949,8 +963,11 @@ function getClients( $return = false )
949
{
950
$c = trim($c);
951
$sql = "SELECT COUNT(*) FROM $wpdb->cpd_counter WHERE client LIKE '%%".$c."%%'";
952
- if ( strtolower($c) == 'safari' ) // don't count chrome too while counting safari
953
- $sql .= " AND client NOT LIKE '%%chrome%%'";
954
$count = $this->mysqlQuery('var', $sql, 'getClients_'.$c.'_ '.__LINE__);
955
$percent = number_format(100 * $count / $all, 0);
956
$rest -= $percent;
@@ -1123,17 +1140,16 @@ function getUserPer_SQL( $sql, $name = '', $frontend = false, $limit = 0 )
1123
return;
1124
}
1125
1126
-
1127
$r = '<ul class="cpd_front_list">';
1128
foreach ( $m as $row )
1129
{
1130
$r .= '<li>';
1131
// link only for editors in backend
1132
- if ( current_user_can('manage_links') && !$frontend )
1133
{
1134
if ( $row->post_id > 0 )
1135
$r .= '<a href="post.php?action=edit&amp;post='.$row->post_id.'"><img src="'.$this->img('cpd_pen.png').'" alt="[e]" title="'.__('Edit Post').'" style="width:9px;height:12px;" /></a> '
1136
- .'<a href="'.$this->dir.'/userperspan.php?page='.$row->post_id.'&amp;KeepThis=true&amp;TB_iframe=true" class="thickbox" title="Count per Day"><img src="'.$this->img('cpd_calendar.png').'" alt="[v]" style="width:12px;height:12px;" /></a> ';
1137
else
1138
$r .= '<img src="'.$this->img('cpd_trans.png').'" alt="" style="width:25px;height:12px;" />';
1139
}
@@ -1159,12 +1175,6 @@ function getUserPer_SQL( $sql, $name = '', $frontend = false, $limit = 0 )
1159
return $r;
1160
}
1161
1162
-
1163
- /**
1164
- * shows visitors of the last days
1165
- */
1166
-
1167
-
1168
/**
1169
* shows searchstrings
1170
*/
@@ -1233,20 +1243,20 @@ function dashboardWidget()
1233
*/
1234
function getCountries( $limit = 0, $frontend = false, $visitors = false, $return = false )
1235
{
1236
- global $wpdb, $cpd_path, $cpd_geoip;
1237
$c = '';
1238
1239
// with GeoIP addon only
1240
if ( $cpd_geoip )
1241
{
1242
- $geoip = new GeoIPCpD();
1243
if ( $limit == 0 )
1244
$limit = max( 0, $this->options['countries'] );
1245
1246
// map link
1247
if (!$frontend && file_exists($cpd_path.'map/map.php') )
1248
{
1249
- $c .= '<div style="margin: 5px 0 10px 0;"><a href="'.$this->dir.'/map/map.php?map=';
1250
if ( $visitors )
1251
$c .= 'visitors';
1252
else
@@ -1284,29 +1294,91 @@ function getCountries( $limit = 0, $frontend = false, $visitors = false, $return
1284
* @param string $what visitors|reads|online
1285
* @param int $width size
1286
* @param int $height size
1287
- * @param int $min : 1 disable title, legend and zoombar
1288
*/
1289
- function getMap( $what = 'visitors', $width = 500, $height = 340, $min = 0 )
1290
{
1291
- $divid = uniqid('cpdmap_');
1292
- $dir = $this->dir.'/map/';
1293
?>
1294
- <script type="text/javascript" src="<?php echo $dir ?>swfobject.js"></script>
1295
- <div id="<?php echo $divid ?>" class="cpd_worldmap" style="width:<?php echo $width ?>px; height:<?php echo $height ?>px; background:#4499FF;">
1296
- <strong>Flash World Map</strong>
1297
- </div>
1298
<script type="text/javascript">
1299
- //<![CDATA[
1300
- var so = new SWFObject("<?php echo $dir ?>ammap.swf", "ammap", "100%", "100%", "8", "#4499FF");
1301
- so.addVariable("path", "<?php echo $dir ?>");
1302
- so.addVariable("settings_file", escape("<?php echo $dir ?>settings.xml.php?map=<?php echo $what ?>&min=<?php echo $min ?>"));
1303
- so.addVariable("data_file", escape("<?php echo $dir ?>data.xml.php?map=<?php echo $what ?>&min=<?php echo $min ?>"));
1304
- so.write("<?php echo $divid ?>");
1305
- //]]>
1306
- </script>
1307
<?php
1308
}
1309
1310
} // class end
1311
1312
@@ -1332,10 +1404,10 @@ class CountPerDay_Widget extends WP_Widget
1332
var $names;
1333
1334
// constructor
1335
- function CountPerDay_Widget() {
1336
$this->funcs = array_slice( $this->fields, 2, 14);
1337
$this->names = array_slice( $this->fields, 16, 14);
1338
- parent::WP_Widget('countperday_widget', 'Count per Day',
1339
array('description' => __('Statistics', 'cpd')), array('width' => 270) );
1340
}
1341
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.1
7
License: Postcardware
8
Author: Tom Braider
9
Author URI: http://www.tomsdimension.de
10
*/
11
12
+ if (!defined('ABSPATH'))
13
+ exit;
14
+
15
$cpd_dir_name = 'count-per-day';
16
+ $cpd_version = '3.5.1';
17
18
if (strpos($_SERVER['SERVER_NAME'], '.test'))
19
$cpd_path = str_replace('/', DIRECTORY_SEPARATOR, ABSPATH.PLUGINDIR.'/'.$cpd_dir_name.'/');
30
/**
31
* constructor
32
*/
33
+ function __construct()
34
{
35
$this->init();
36
}
73
*/
74
function count( $x, $page = 'x' )
75
{
76
+ global $wpdb, $wp_query, $cpd_path, $cpd_geoip, $cpd_geoip_dir, $userdata;
77
78
if ($this->options['debug'])
79
$this->queries[] = 'called Function: <b style="color:blue">count</b> page: <code>'.$page.'</code>';
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 ( strpos($userip,'.') !== false && strpos($userip,':') === false)
154
+ {
155
+ // IPv4
156
+ $userip2 = $userip;
157
+ }
158
+ else
159
+ {
160
+ // IPv6
161
+ // store dummy ipv4 until we can handle ipv6
162
+ $packed = cpd_inet_pton($userip);
163
+ if (strlen($packed) === 4)
164
+ $unpacked = array_pad(unpack( "C4", $packed), -16, 0);
165
+ else
166
+ $unpacked = array_merge(unpack( "C16", $packed));
167
+ $unpacked = array_slice($unpacked, 12);
168
+ $userip2 = implode('.', $unpacked);
169
+ }
170
+
171
// save count
172
if ($cpd_geoip)
173
{
174
// with GeoIP addon save country
175
+ $gi = geoip_open($cpd_geoip_dir.'GeoIP.dat', GEOIP_STANDARD);
176
177
if (!filter_var($userip, FILTER_VALIDATE_IP))
178
$userip = '127.0.0.1';
179
180
if ( strpos($userip,'.') !== false && strpos($userip,':') === false)
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 = '-';
189
195
else
196
// without country
197
$this->mysqlQuery('', $wpdb->prepare("INSERT INTO $wpdb->cpd_counter (page, ip, client, date, referer)
198
+ VALUES (%d, $this->aton(%s), %s, %s, %s)", $page, $userip2, $client, $date, $referer), 'count insert '.__LINE__.' - '.$userip.' - '.$userip2.' -');
199
}
200
// online counter
201
$oc = (array) get_option('count_per_day_online');
292
// create data array
293
$data = array();
294
for ( $day = $start_time; $day < $end_time; $day = $day + 86400 )
295
+ $data[date('Y,n,j', $day)] = array(0, 0);
296
297
// reads
298
$sql = $wpdb->prepare("
304
$res = $this->mysqlQuery('rows', $sql, 'ChartReads '.__LINE__);
305
if ($res)
306
foreach ($res as $row)
307
+ $data[date('Y,n,j', strtotime($row->date))][0] = $row->count;
308
309
// visitors
310
$sql = $wpdb->prepare("
319
$res = $this->mysqlQuery('rows', $sql, 'ChartVisitors '.__LINE__);
320
if ($res)
321
foreach ($res as $row)
322
+ $data[date('Y,n,j', strtotime($row->date))][1] = $row->count;
323
+
324
// fill data array
325
$reads = array();
326
$visitors = array();
327
foreach ( $data as $day => $values )
328
{
329
+ $reads[] = '[gd('.$day.'),'.$values[0].']';
330
+ $visitors[] = '[gd('.$day.'),'.$values[1].']';
331
}
332
$reads_line = '['.implode(',', $reads).']';
333
$visitors_line = '['.implode(',', $visitors).']';
423
});
424
}
425
426
+ function gd(year, month, day) {
427
+ return new Date(year, month - 1, day).getTime();
428
+ }
429
+
430
plotAccordingToChoices();
431
});
432
//]]>
439
*/
440
function getUserOnline( $frontend = false, $country = false, $return = false )
441
{
442
+ global $wpdb, $cpd_geoip, $cpd_path, $cpd_geoip_dir;
443
$c = '';
444
445
$oc = get_option('count_per_day_online');
448
{
449
// map link
450
if ( !$frontend && file_exists($cpd_path.'map/map.php') )
451
+ $c .= '<div style="margin: 5px 0 10px 0;"><a href="?page=cpd_map&amp;map=online'
452
.'&amp;KeepThis=true&amp;TB_iframe=true" title="Count per Day - '.__('Map', 'cpd').'" class="thickbox button">'.__('Map', 'cpd').'</a></div>';
453
454
// countries list
455
+ $geoip = new GeoIP();
456
+ $gi = geoip_open($cpd_geoip_dir.'GeoIP.dat', GEOIP_STANDARD);
457
458
$vo = array();
459
foreach ( $oc as $ip=>$x )
460
{
461
if ( strpos($ip,'.') !== false && strpos($ip,':') === false)
462
// IPv4
463
+ $country = strtolower(geoip_country_code_by_addr_v6($gi, '::'.$ip));
464
else
465
// IPv6
466
+ $country = strtolower(geoip_country_code_by_addr_v6($gi, $ip));
467
$id = $geoip->GEOIP_COUNTRY_CODE_TO_NUMBER[strtoupper($country)];
468
if ( empty($id) )
469
{
906
<input name="daytoshow" value="'.$date.'" size="11" />
907
<input type="submit" name="showday" value="'.__('Show').'" class="button" />';
908
if ( $show_notes )
909
+ echo ' <a href="?page=cpd_notes&amp;KeepThis=true&amp;TB_iframe=true" title="Count per Day - '.__('Notes', 'cpd').'" class="button thickbox">'.__('Notes', 'cpd').'</a> ';
910
echo '</form>';
911
}
912
if (isset($note))
963
{
964
$c = trim($c);
965
$sql = "SELECT COUNT(*) FROM $wpdb->cpd_counter WHERE client LIKE '%%".$c."%%'";
966
+ if ( strtolower($c) == 'safari' ) // don't count chrome and egde too while counting safari
967
+ $sql .= " AND client NOT LIKE '%%chrome%%'
968
+ AND client NOT LIKE '%%edge%%'";
969
+ if ( strtolower($c) == 'chrome' ) // don't count edge too while counting chrome
970
+ $sql .= " AND client NOT LIKE '%%edge%%'";
971
$count = $this->mysqlQuery('var', $sql, 'getClients_'.$c.'_ '.__LINE__);
972
$percent = number_format(100 * $count / $all, 0);
973
$rest -= $percent;
1140
return;
1141
}
1142
1143
$r = '<ul class="cpd_front_list">';
1144
foreach ( $m as $row )
1145
{
1146
$r .= '<li>';
1147
// link only for editors in backend
1148
+ if ( current_user_can('edit_others_posts') && !$frontend )
1149
{
1150
if ( $row->post_id > 0 )
1151
$r .= '<a href="post.php?action=edit&amp;post='.$row->post_id.'"><img src="'.$this->img('cpd_pen.png').'" alt="[e]" title="'.__('Edit Post').'" style="width:9px;height:12px;" /></a> '
1152
+ .'<a href="?page=cpd_userperspan&amp;cpage='.$row->post_id.'&amp;KeepThis=true&amp;TB_iframe=true" class="thickbox" title="Count per Day"><img src="'.$this->img('cpd_calendar.png').'" alt="[v]" style="width:12px;height:12px;" /></a> ';
1153
else
1154
$r .= '<img src="'.$this->img('cpd_trans.png').'" alt="" style="width:25px;height:12px;" />';
1155
}
1175
return $r;
1176
}
1177
1178
/**
1179
* shows searchstrings
1180
*/
1243
*/
1244
function getCountries( $limit = 0, $frontend = false, $visitors = false, $return = false )
1245
{
1246
+ global $wpdb, $cpd_path, $c, $cpd_geoip;
1247
$c = '';
1248
1249
// with GeoIP addon only
1250
if ( $cpd_geoip )
1251
{
1252
+ $geoip = new GeoIP();
1253
if ( $limit == 0 )
1254
$limit = max( 0, $this->options['countries'] );
1255
1256
// map link
1257
if (!$frontend && file_exists($cpd_path.'map/map.php') )
1258
{
1259
+ $c .= '<div style="margin: 5px 0 10px 0;"><a href="?page=cpd_map&amp;map=';
1260
if ( $visitors )
1261
$c .= 'visitors';
1262
else
1294
* @param string $what visitors|reads|online
1295
* @param int $width size
1296
* @param int $height size
1297
*/
1298
+ function getMap( $what = 'visitors', $width = 500, $height = 430 )
1299
{
1300
+ global $cpd_geoip, $cpd_geoip_dir, $cpd_data;
1301
+
1302
+ if ( !$cpd_geoip || !in_array($what, array('visitors','reads','online')) )
1303
+ return;
1304
+
1305
+ $cpd_data = array('-' => 0);
1306
+ if ( $what == 'online' )
1307
+ {
1308
+ require_once(WP_PLUGIN_DIR.'/count-per-day/geoip.php');
1309
+ $oc = get_option('count_per_day_online', array());
1310
+ $gi = geoip_open($cpd_geoip_dir.'GeoIP.dat', GEOIP_STANDARD);
1311
+ $vo = array();
1312
+ foreach ($oc as $ip => $x)
1313
+ {
1314
+ if ( strpos($ip,'.') !== false && strpos($ip,':') === false)
1315
+ // IPv4 -> IPv6
1316
+ $ip = '::'.$ip;
1317
+ $country = strtoupper(geoip_country_code_by_addr_v6($gi, $ip));
1318
+ $cpd_data[$country] = (isset($cpd_data[$country])) ? $cpd_data[$country] + 1 : 1;
1319
+ }
1320
+ }
1321
+ else
1322
+ {
1323
+ $temp = $this->addCollectionToCountries( ($what == 'visitors') );
1324
+ foreach ($temp as $country => $value)
1325
+ if ($country != '-')
1326
+ $cpd_data[strtoupper($country)] = $value;
1327
+ }
1328
+ ?>
1329
+ <div id="mapdiv" class="cpdmap-frontend" style="width:<?php echo $width ?>px;height:<?php echo $height ?>px;"></div>
1330
+ <?php
1331
+ wp_enqueue_script( 'cpd_ammap', $this->dir.'/map/ammap.js', false );
1332
+ wp_enqueue_script( 'cpd_worldLow', $this->dir.'/map/worldLow.js', false );
1333
+ add_action('wp_footer', array(&$this,'addMapScript'), 100);
1334
+ }
1335
+
1336
+
1337
+ function addMapScript()
1338
+ {
1339
+ global $cpd_dir, $cpd_data;
1340
+ var_dump($cpd_data);
1341
?>
1342
<script type="text/javascript">
1343
+ AmCharts.ready(function() {
1344
+ var map = new AmCharts.AmMap();
1345
+ map.pathToImages = "<?php echo WP_PLUGIN_URL ?>/count-per-day/map/images/";
1346
+ map.addTitle("Your Visitors all over the World", 14);
1347
+ map.mouseWheelZoomEnabled = true;
1348
+ var c = "#38E";
1349
+ map.dataProvider = {
1350
+ mapVar: AmCharts.maps.worldLow,
1351
+ getAreasFromMap:true,
1352
+ areas: [
1353
+ {id:"AE",value:0,color:c},{id:"AF",value:0,color:c},{id:"AL",value:0,color:c},{id:"AM",value:0,color:c},{id:"AO",value:0,color:c},{id:"AR",value:0,color:c},{id:"AT",value:0,color:c},{id:"AU",value:0,color:c},{id:"AZ",value:0,color:c},{id:"BA",value:0,color:c},{id:"BD",value:0,color:c},{id:"BE",value:0,color:c},{id:"BF",value:0,color:c},{id:"BG",value:0,color:c},{id:"BI",value:0,color:c},{id:"BJ",value:0,color:c},{id:"BN",value:0,color:c},{id:"BO",value:0,color:c},{id:"BR",value:0,color:c},{id:"BS",value:0,color:c},{id:"BT",value:0,color:c},{id:"BW",value:0,color:c},{id:"BY",value:0,color:c},{id:"BZ",value:0,color:c},{id:"CA",value:0,color:c},{id:"CD",value:0,color:c},{id:"CF",value:0,color:c},{id:"CG",value:0,color:c},{id:"CH",value:0,color:c},{id:"CI",value:0,color:c},{id:"CL",value:0,color:c},{id:"CM",value:0,color:c},{id:"CN",value:0,color:c},{id:"CO",value:0,color:c},{id:"CR",value:0,color:c},{id:"CU",value:0,color:c},{id:"CY",value:0,color:c},{id:"CZ",value:0,color:c},{id:"DE",value:0,color:c},{id:"DJ",value:0,color:c},{id:"DK",value:0,color:c},{id:"DO",value:0,color:c},{id:"DZ",value:0,color:c},{id:"EC",value:0,color:c},{id:"EE",value:0,color:c},{id:"EG",value:0,color:c},{id:"EH",value:0,color:c},{id:"ER",value:0,color:c},{id:"ES",value:0,color:c},{id:"ET",value:0,color:c},{id:"FK",value:0,color:c},{id:"FI",value:0,color:c},{id:"FJ",value:0,color:c},{id:"FR",value:0,color:c},{id:"GA",value:0,color:c},{id:"GB",value:0,color:c},{id:"GE",value:0,color:c},{id:"GF",value:0,color:c},{id:"GH",value:0,color:c},{id:"GL",value:0,color:c},{id:"GM",value:0,color:c},{id:"GN",value:0,color:c},{id:"GQ",value:0,color:c},{id:"GR",value:0,color:c},{id:"GT",value:0,color:c},{id:"GW",value:0,color:c},{id:"GY",value:0,color:c},{id:"HN",value:0,color:c},{id:"HR",value:0,color:c},{id:"HT",value:0,color:c},{id:"HU",value:0,color:c},{id:"ID",value:0,color:c},{id:"IE",value:0,color:c},{id:"IL",value:0,color:c},{id:"IN",value:0,color:c},{id:"IQ",value:0,color:c},{id:"IR",value:0,color:c},{id:"IS",value:0,color:c},{id:"IT",value:0,color:c},{id:"JM",value:0,color:c},{id:"JO",value:0,color:c},{id:"JP",value:0,color:c},{id:"KE",value:0,color:c},{id:"KG",value:0,color:c},{id:"KH",value:0,color:c},{id:"KP",value:0,color:c},{id:"KR",value:0,color:c},{id:"XK",value:0,color:c},{id:"KW",value:0,color:c},{id:"KZ",value:0,color:c},{id:"LA",value:0,color:c},{id:"LB",value:0,color:c},{id:"LK",value:0,color:c},{id:"LR",value:0,color:c},{id:"LS",value:0,color:c},{id:"LT",value:0,color:c},{id:"LU",value:0,color:c},{id:"LV",value:0,color:c},{id:"LY",value:0,color:c},{id:"MA",value:0,color:c},{id:"MD",value:0,color:c},{id:"ME",value:0,color:c},{id:"MG",value:0,color:c},{id:"MK",value:0,color:c},{id:"ML",value:0,color:c},{id:"MM",value:0,color:c},{id:"MN",value:0,color:c},{id:"MR",value:0,color:c},{id:"MW",value:0,color:c},{id:"MX",value:0,color:c},{id:"MY",value:0,color:c},{id:"MZ",value:0,color:c},{id:"NA",value:0,color:c},{id:"NC",value:0,color:c},{id:"NE",value:0,color:c},{id:"NG",value:0,color:c},{id:"NI",value:0,color:c},{id:"NL",value:0,color:c},{id:"NO",value:0,color:c},{id:"NP",value:0,color:c},{id:"NZ",value:0,color:c},{id:"OM",value:0,color:c},{id:"PA",value:0,color:c},{id:"PE",value:0,color:c},{id:"PG",value:0,color:c},{id:"PH",value:0,color:c},{id:"PL",value:0,color:c},{id:"PK",value:0,color:c},{id:"PR",value:0,color:c},{id:"PS",value:0,color:c},{id:"PT",value:0,color:c},{id:"PY",value:0,color:c},{id:"QA",value:0,color:c},{id:"RO",value:0,color:c},{id:"RS",value:0,color:c},{id:"RU",value:0,color:c},{id:"RW",value:0,color:c},{id:"SA",value:0,color:c},{id:"SB",value:0,color:c},{id:"SD",value:0,color:c},{id:"SE",value:0,color:c},{id:"SI",value:0,color:c},{id:"SJ",value:0,color:c},{id:"SK",value:0,color:c},{id:"SL",value:0,color:c},{id:"SN",value:0,color:c},{id:"SO",value:0,color:c},{id:"SR",value:0,color:c},{id:"SS",value:0,color:c},{id:"SV",value:0,color:c},{id:"SY",value:0,color:c},{id:"SZ",value:0,color:c},{id:"TD",value:0,color:c},{id:"TF",value:0,color:c},{id:"TG",value:0,color:c},{id:"TH",value:0,color:c},{id:"TJ",value:0,color:c},{id:"TL",value:0,color:c},{id:"TM",value:0,color:c},{id:"TN",value:0,color:c},{id:"TR",value:0,color:c},{id:"TT",value:0,color:c},{id:"TW",value:0,color:c},{id:"TZ",value:0,color:c},{id:"UA",value:0,color:c},{id:"UG",value:0,color:c},{id:"US",value:0,color:c},{id:"UY",value:0,color:c},{id:"UZ",value:0,color:c},{id:"VE",value:0,color:c},{id:"VN",value:0,color:c},{id:"VU",value:0,color:c},{id:"YE",value:0,color:c},{id:"ZA",value:0,color:c},{id:"ZM",value:0,color:c},{id:"ZW",value:0,color:c},
1354
+ <?php
1355
+ $r = __('Reads','cpd');
1356
+ foreach ( $cpd_data as $k => $v )
1357
+ echo "{id:'$k',value:$v,balloonText:'[[title]]<br><b>[[value]]</b> $r<br>[[percent]]%'},"
1358
+ ?>
1359
+ ]};
1360
+ map.areasSettings = {
1361
+ color: "#FFFFFF",
1362
+ outlineColor: "#CCCCCC",
1363
+ outlineThickness: 0.2,
1364
+ rollOverColor: "#FFFF00"
1365
+ };
1366
+ var legend = new AmCharts.ValueLegend();
1367
+ legend.minValue = <?php echo min($cpd_data) ?>;
1368
+ legend.left = 10;
1369
+ legend.bottom = 25;
1370
+ legend.width = 150;
1371
+ legend.borderThickness = 0;
1372
+ legend.showAsGradient = true;
1373
+ map.valueLegend = legend;
1374
+
1375
+ map.write("mapdiv");
1376
+ });
1377
+ </script>
1378
<?php
1379
}
1380
1381
+
1382
} // class end
1383
1384
1404
var $names;
1405
1406
// constructor
1407
+ function __construct() {
1408
$this->funcs = array_slice( $this->fields, 2, 14);
1409
$this->names = array_slice( $this->fields, 16, 14);
1410
+ parent::__construct('countperday_widget', 'Count per Day',
1411
array('description' => __('Statistics', 'cpd')), array('width' => 270) );
1412
}
1413
download.php CHANGED
@@ -1,8 +1,23 @@
1
<?php
2
/*
3
* f = filename in tempdir
4
* n = download filename
5
*/
6
if ( empty($_GET['f']) || empty($_GET['n']) )
7
die('no way');
8
$file = sys_get_temp_dir().'/'.strip_tags($_GET['f']);
1
<?php
2
/*
3
+ * Download backup files
4
* f = filename in tempdir
5
* n = download filename
6
*/
7
+
8
+ if (!defined('ABSPATH'))
9
+ exit;
10
+
11
+ // check user
12
+ $o = get_option('count_per_day');
13
+ $can_see = str_replace(
14
+ // administrator, editor, author, contributor, subscriber
15
+ array(10, 7, 2, 1, 0),
16
+ array('manage_options', 'moderate_comments', 'edit_published_posts', 'edit_posts', 'read'),
17
+ $o['show_in_lists']);
18
+ if ( !current_user_can($can_see) )
19
+ die('no way');
20
+
21
if ( empty($_GET['f']) || empty($_GET['n']) )
22
die('no way');
23
$file = sys_get_temp_dir().'/'.strip_tags($_GET['f']);
geoip/geoip.php → geoip.php RENAMED
@@ -4,10 +4,11 @@
4
* Count Per Day - GeoIP Addon
5
*/
6
7
- /**
8
- */
9
- if (!class_exists('GeoIpCpD'))
10
- include_once('geoip.inc');
11
12
class CpdGeoIp
13
{
@@ -19,19 +20,18 @@ class CpdGeoIp
19
*/
20
static function getCountry( $ip )
21
{
22
- global $cpd_path;
23
24
// IPv4 > IPv6
25
if ( strpos($ip,'.') !== false && strpos($ip,':') === false)
26
$ip = "::$ip";
27
28
- $gi = cpd_geoip_open($cpd_path.'/geoip/GeoIP.dat', GEOIP_STANDARD);
29
30
- // if ( strpos($ip, 'u') !== false ) // 'unknow...'
31
if (filter_var($ip, FILTER_VALIDATE_IP))
32
{
33
- $c = strtolower(cpd_geoip_country_code_by_addr_v6($gi, $ip));
34
- $cname = cpd_geoip_country_name_by_addr_v6($gi, $ip);
35
}
36
37
if ( empty($c) )
@@ -39,7 +39,7 @@ static function getCountry( $ip )
39
$c = 'unknown';
40
$cname = '';
41
}
42
- cpd_geoip_close($gi);
43
$country = array( $c, '<div class="cpd-flag cpd-flag-'.$c.'" title="'.$cname.'"></div>', $cname );
44
return $country;
45
}
@@ -49,16 +49,11 @@ static function getCountry( $ip )
49
*/
50
static function updateDB()
51
{
52
- global $count_per_day, $cpd_path, $wpdb;
53
-
54
- $count_per_day->mysqlQuery('rows', "SELECT country FROM $wpdb->cpd_counter LIMIT 1", 'GeoIP updateDB Table '.__LINE__);
55
- if ((int) mysql_errno() == 1054)
56
- // add row "country" to table
57
- $count_per_day->mysqlQuery('', "ALTER TABLE $wpdb->cpd_counter ADD `country` CHAR( 2 ) NOT NULL", 'GeoIP updateDB create column '.__LINE__);
58
59
$limit = 20;
60
$res = $count_per_day->mysqlQuery('rows', "SELECT ip, $count_per_day->ntoa(ip) realip FROM $wpdb->cpd_counter WHERE country LIKE '' GROUP BY ip LIMIT $limit", 'GeoIP updateDB '.__LINE__);
61
- $gi = cpd_geoip_open($cpd_path.'/geoip/GeoIP.dat', GEOIP_STANDARD);
62
63
foreach ($res as $r)
64
{
@@ -76,7 +71,7 @@ static function updateDB()
76
$c = '-';
77
else
78
// get country
79
- $c = strtolower(cpd_geoip_country_code_by_addr_v6($gi, '::'.$r->realip));
80
}
81
else
82
{
@@ -88,14 +83,14 @@ static function updateDB()
88
$c = '-';
89
else
90
// get country
91
- $c = strtolower(cpd_geoip_country_code_by_addr_v6($gi, $r->realip));
92
}
93
94
if ( !empty($c) )
95
$count_per_day->mysqlQuery('', "UPDATE $wpdb->cpd_counter SET country = '$c' WHERE ip = '$r->ip'", 'GeoIP updateDB '.__LINE__);
96
}
97
98
- cpd_geoip_close($gi);
99
100
$rest = $count_per_day->mysqlQuery('var', "SELECT COUNT(*) FROM $wpdb->cpd_counter WHERE country like ''", 'GeoIP updateDB '.__LINE__);
101
return (int) $rest;
@@ -103,11 +98,11 @@ static function updateDB()
103
104
/**
105
* updates the GeoIP database file
106
- * works only if directory geoip has rights 777, set it in ftp client
107
*/
108
static function updateGeoIpFile()
109
{
110
- global $cpd_path;
111
112
// function checks
113
if ( !ini_get('allow_url_fopen') )
@@ -116,13 +111,12 @@ static function updateGeoIpFile()
116
if ( !function_exists('gzopen') )
117
return __('Sorry, necessary functions (zlib) not installed or enabled in php.ini.', 'cpd');
118
119
- // $gzfile = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz';
120
$gzfile = 'http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz';
121
- $file = $cpd_path.'/geoip/GeoIP.dat';
122
123
// get remote file
124
$h = gzopen($gzfile, 'rb');
125
- $content = gzread($h, 1500000);
126
fclose($h);
127
128
// delete local file
@@ -141,7 +135,7 @@ static function updateGeoIpFile()
141
if (is_file($file) && $del)
142
return __('New GeoIP database installed.', 'cpd');
143
else
144
- return __('Sorry, an error occurred. Try again or check the access rights of directory "geoip" is 777.', 'cpd');
145
}
146
147
4
* Count Per Day - GeoIP Addon
5
*/
6
7
+ if (!defined('ABSPATH'))
8
+ exit;
9
+
10
+ if (!class_exists('GeoIp'))
11
+ include_once($cpd_geoip_dir.'geoip.inc');
12
13
class CpdGeoIp
14
{
20
*/
21
static function getCountry( $ip )
22
{
23
+ global $cpd_geoip_dir;
24
25
// IPv4 > IPv6
26
if ( strpos($ip,'.') !== false && strpos($ip,':') === false)
27
$ip = "::$ip";
28
29
+ $gi = geoip_open($cpd_geoip_dir.'GeoIP.dat', GEOIP_STANDARD);
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
$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
}
49
*/
50
static function updateDB()
51
{
52
+ global $count_per_day, $cpd_geoip_dir, $wpdb;
53
54
$limit = 20;
55
$res = $count_per_day->mysqlQuery('rows', "SELECT ip, $count_per_day->ntoa(ip) realip FROM $wpdb->cpd_counter WHERE country LIKE '' GROUP BY ip LIMIT $limit", 'GeoIP updateDB '.__LINE__);
56
+ $gi = geoip_open($cpd_geoip_dir.'GeoIP.dat', GEOIP_STANDARD);
57
58
foreach ($res as $r)
59
{
71
$c = '-';
72
else
73
// get country
74
+ $c = strtolower(geoip_country_code_by_addr_v6($gi, '::'.$r->realip));
75
}
76
else
77
{
83
$c = '-';
84
else
85
// get country
86
+ $c = strtolower(geoip_country_code_by_addr_v6($gi, $r->realip));
87
}
88
89
if ( !empty($c) )
90
$count_per_day->mysqlQuery('', "UPDATE $wpdb->cpd_counter SET country = '$c' WHERE ip = '$r->ip'", 'GeoIP updateDB '.__LINE__);
91
}
92
93
+ geoip_close($gi);
94
95
$rest = $count_per_day->mysqlQuery('var', "SELECT COUNT(*) FROM $wpdb->cpd_counter WHERE country like ''", 'GeoIP updateDB '.__LINE__);
96
return (int) $rest;
98
99
/**
100
* updates the GeoIP database file
101
+ * works only if directory wp-content/count-per-day-geoip has correct permissions, set it in ftp client
102
*/
103
static function updateGeoIpFile()
104
{
105
+ global $cpd_geoip_dir;
106
107
// function checks
108
if ( !ini_get('allow_url_fopen') )
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';
116
117
// get remote file
118
$h = gzopen($gzfile, 'rb');
119
+ $content = gzread($h, 2000000);
120
fclose($h);
121
122
// delete local file
135
if (is_file($file) && $del)
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
geoip/GeoIP.dat DELETED
Binary file
geoip/geoip.inc DELETED
@@ -1,753 +0,0 @@
1
- <?php
2
-
3
- /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
4
- /* geoip.inc
5
- *
6
- * Copyright (C) 2007 MaxMind LLC
7
- *
8
- * This library is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU Lesser General Public
10
- * License as published by the Free Software Foundation; either
11
- * version 2.1 of the License, or (at your option) any later version.
12
- *
13
- * This library is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
- * Lesser General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU Lesser General Public
19
- * License along with this library; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
- */
22
-
23
- define("GEOIP_COUNTRY_BEGIN", 16776960);
24
- define("GEOIP_STATE_BEGIN_REV0", 16700000);
25
- define("GEOIP_STATE_BEGIN_REV1", 16000000);
26
- define("GEOIP_STANDARD", 0);
27
- define("GEOIP_MEMORY_CACHE", 1);
28
- define("GEOIP_SHARED_MEMORY", 2);
29
- define("STRUCTURE_INFO_MAX_SIZE", 20);
30
- define("DATABASE_INFO_MAX_SIZE", 100);
31
- define("GEOIP_COUNTRY_EDITION", 106);
32
- define("GEOIP_PROXY_EDITION", 8);
33
- define("GEOIP_ASNUM_EDITION", 9);
34
- define("GEOIP_NETSPEED_EDITION", 10);
35
- define("GEOIP_REGION_EDITION_REV0", 112);
36
- define("GEOIP_REGION_EDITION_REV1", 3);
37
- define("GEOIP_CITY_EDITION_REV0", 111);
38
- define("GEOIP_CITY_EDITION_REV1", 2);
39
- define("GEOIP_ORG_EDITION", 110);
40
- define("GEOIP_ISP_EDITION", 4);
41
- define("SEGMENT_RECORD_LENGTH", 3);
42
- define("STANDARD_RECORD_LENGTH", 3);
43
- define("ORG_RECORD_LENGTH", 4);
44
- define("MAX_RECORD_LENGTH", 4);
45
- define("MAX_ORG_RECORD_LENGTH", 300);
46
- define("GEOIP_SHM_KEY", 0x4f415401);
47
- define("US_OFFSET", 1);
48
- define("CANADA_OFFSET", 677);
49
- define("WORLD_OFFSET", 1353);
50
- define("FIPS_RANGE", 360);
51
- define("GEOIP_UNKNOWN_SPEED", 0);
52
- define("GEOIP_DIALUP_SPEED", 1);
53
- define("GEOIP_CABLEDSL_SPEED", 2);
54
- define("GEOIP_CORPORATE_SPEED", 3);
55
- define("GEOIP_DOMAIN_EDITION", 11);
56
- define("GEOIP_COUNTRY_EDITION_V6", 12);
57
- define("GEOIP_LOCATIONA_EDITION", 13);
58
- define("GEOIP_ACCURACYRADIUS_EDITION", 14);
59
- define("GEOIP_CITYCOMBINED_EDITION", 15);
60
- define("GEOIP_CITY_EDITION_REV1_V6", 30);
61
- define("GEOIP_CITY_EDITION_REV0_V6",31);
62
- define("GEOIP_NETSPEED_EDITION_REV1",32);
63
- define("GEOIP_NETSPEED_EDITION_REV1_V6",33);
64
- define("GEOIP_USERTYPE_EDITION",28);
65
- define("GEOIP_USERTYPE_EDITION_V6",29);
66
- define("GEOIP_ASNUM_EDITION_V6",21);
67
- define("GEOIP_ISP_EDITION_V6",22);
68
- define("GEOIP_ORG_EDITION_V6",23);
69
- define("GEOIP_DOMAIN_EDITION_V6",24);
70
-
71
- define("CITYCOMBINED_FIXED_RECORD", 7 );
72
-
73
- class GeoIPCpd {
74
- var $flags;
75
- var $filehandle;
76
- var $memory_buffer;
77
- var $databaseType;
78
- var $databaseSegments;
79
- var $record_length;
80
- var $shmid;
81
- var $GEOIP_COUNTRY_CODE_TO_NUMBER = array(
82
- "" => 0, "AP" => 1, "EU" => 2, "AD" => 3, "AE" => 4, "AF" => 5,
83
- "AG" => 6, "AI" => 7, "AL" => 8, "AM" => 9, "CW" => 10, "AO" => 11,
84
- "AQ" => 12, "AR" => 13, "AS" => 14, "AT" => 15, "AU" => 16, "AW" => 17,
85
- "AZ" => 18, "BA" => 19, "BB" => 20, "BD" => 21, "BE" => 22, "BF" => 23,
86
- "BG" => 24, "BH" => 25, "BI" => 26, "BJ" => 27, "BM" => 28, "BN" => 29,
87
- "BO" => 30, "BR" => 31, "BS" => 32, "BT" => 33, "BV" => 34, "BW" => 35,
88
- "BY" => 36, "BZ" => 37, "CA" => 38, "CC" => 39, "CD" => 40, "CF" => 41,
89
- "CG" => 42, "CH" => 43, "CI" => 44, "CK" => 45, "CL" => 46, "CM" => 47,
90
- "CN" => 48, "CO" => 49, "CR" => 50, "CU" => 51, "CV" => 52, "CX" => 53,
91
- "CY" => 54, "CZ" => 55, "DE" => 56, "DJ" => 57, "DK" => 58, "DM" => 59,
92
- "DO" => 60, "DZ" => 61, "EC" => 62, "EE" => 63, "EG" => 64, "EH" => 65,
93
- "ER" => 66, "ES" => 67, "ET" => 68, "FI" => 69, "FJ" => 70, "FK" => 71,
94
- "FM" => 72, "FO" => 73, "FR" => 74, "SX" => 75, "GA" => 76, "GB" => 77,
95
- "GD" => 78, "GE" => 79, "GF" => 80, "GH" => 81, "GI" => 82, "GL" => 83,
96
- "GM" => 84, "GN" => 85, "GP" => 86, "GQ" => 87, "GR" => 88, "GS" => 89,
97
- "GT" => 90, "GU" => 91, "GW" => 92, "GY" => 93, "HK" => 94, "HM" => 95,
98
- "HN" => 96, "HR" => 97, "HT" => 98, "HU" => 99, "ID" => 100, "IE" => 101,
99
- "IL" => 102, "IN" => 103, "IO" => 104, "IQ" => 105, "IR" => 106, "IS" => 107,
100
- "IT" => 108, "JM" => 109, "JO" => 110, "JP" => 111, "KE" => 112, "KG" => 113,
101
- "KH" => 114, "KI" => 115, "KM" => 116, "KN" => 117, "KP" => 118, "KR" => 119,
102
- "KW" => 120, "KY" => 121, "KZ" => 122, "LA" => 123, "LB" => 124, "LC" => 125,
103
- "LI" => 126, "LK" => 127, "LR" => 128, "LS" => 129, "LT" => 130, "LU" => 131,
104
- "LV" => 132, "LY" => 133, "MA" => 134, "MC" => 135, "MD" => 136, "MG" => 137,
105
- "MH" => 138, "MK" => 139, "ML" => 140, "MM" => 141, "MN" => 142, "MO" => 143,
106
- "MP" => 144, "MQ" => 145, "MR" => 146, "MS" => 147, "MT" => 148, "MU" => 149,
107
- "MV" => 150, "MW" => 151, "MX" => 152, "MY" => 153, "MZ" => 154, "NA" => 155,
108
- "NC" => 156, "NE" => 157, "NF" => 158, "NG" => 159, "NI" => 160, "NL" => 161,
109
- "NO" => 162, "NP" => 163, "NR" => 164, "NU" => 165, "NZ" => 166, "OM" => 167,
110
- "PA" => 168, "PE" => 169, "PF" => 170, "PG" => 171, "PH" => 172, "PK" => 173,
111
- "PL" => 174, "PM" => 175, "PN" => 176, "PR" => 177, "PS" => 178, "PT" => 179,
112
- "PW" => 180, "PY" => 181, "QA" => 182, "RE" => 183, "RO" => 184, "RU" => 185,
113
- "RW" => 186, "SA" => 187, "SB" => 188, "SC" => 189, "SD" => 190, "SE" => 191,
114
- "SG" => 192, "SH" => 193, "SI" => 194, "SJ" => 195, "SK" => 196, "SL" => 197,
115
- "SM" => 198, "SN" => 199, "SO" => 200, "SR" => 201, "ST" => 202, "SV" => 203,
116
- "SY" => 204, "SZ" => 205, "TC" => 206, "TD" => 207, "TF" => 208, "TG" => 209,
117
- "TH" => 210, "TJ" => 211, "TK" => 212, "TM" => 213, "TN" => 214, "TO" => 215,
118
- "TL" => 216, "TR" => 217, "TT" => 218, "TV" => 219, "TW" => 220, "TZ" => 221,
119
- "UA" => 222, "UG" => 223, "UM" => 224, "US" => 225, "UY" => 226, "UZ" => 227,
120
- "VA" => 228, "VC" => 229, "VE" => 230, "VG" => 231, "VI" => 232, "VN" => 233,
121
- "VU" => 234, "WF" => 235, "WS" => 236, "YE" => 237, "YT" => 238, "RS" => 239,
122
- "ZA" => 240, "ZM" => 241, "ME" => 242, "ZW" => 243, "A1" => 244, "A2" => 245,
123
- "O1" => 246, "AX" => 247, "GG" => 248, "IM" => 249, "JE" => 250, "BL" => 251,
124
- "MF" => 252, "BQ" => 253, "SS" => 254
125
- );
126
- var $GEOIP_COUNTRY_CODES = array(
127
- "","AP","EU","AD","AE","AF","AG","AI","AL","AM","CW",
128
- "AO","AQ","AR","AS","AT","AU","AW","AZ","BA","BB",
129
- "BD","BE","BF","BG","BH","BI","BJ","BM","BN","BO",
130
- "BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD",
131
- "CF","CG","CH","CI","CK","CL","CM","CN","CO","CR",
132
- "CU","CV","CX","CY","CZ","DE","DJ","DK","DM","DO",
133
- "DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ",
134
- "FK","FM","FO","FR","SX","GA","GB","GD","GE","GF",
135
- "GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT",
136
- "GU","GW","GY","HK","HM","HN","HR","HT","HU","ID",
137
- "IE","IL","IN","IO","IQ","IR","IS","IT","JM","JO",
138
- "JP","KE","KG","KH","KI","KM","KN","KP","KR","KW",
139
- "KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT",
140
- "LU","LV","LY","MA","MC","MD","MG","MH","MK","ML",
141
- "MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV",
142
- "MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI",
143
- "NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF",
144
- "PG","PH","PK","PL","PM","PN","PR","PS","PT","PW",
145
- "PY","QA","RE","RO","RU","RW","SA","SB","SC","SD",
146
- "SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO",
147
- "SR","ST","SV","SY","SZ","TC","TD","TF","TG","TH",
148
- "TJ","TK","TM","TN","TO","TL","TR","TT","TV","TW",
149
- "TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE",
150
- "VG","VI","VN","VU","WF","WS","YE","YT","RS","ZA",
151
- "ZM","ME","ZW","A1","A2","O1","AX","GG","IM","JE",
152
- "BL","MF", "BQ", "SS", "O1" );
153
- var $GEOIP_COUNTRY_CODES3 = array(
154
- "","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","CUW",
155
- "AGO","ATA","ARG","ASM","AUT","AUS","ABW","AZE","BIH","BRB",
156
- "BGD","BEL","BFA","BGR","BHR","BDI","BEN","BMU","BRN","BOL",
157
- "BRA","BHS","BTN","BVT","BWA","BLR","BLZ","CAN","CCK","COD",
158
- "CAF","COG","CHE","CIV","COK","CHL","CMR","CHN","COL","CRI",
159
- "CUB","CPV","CXR","CYP","CZE","DEU","DJI","DNK","DMA","DOM",
160
- "DZA","ECU","EST","EGY","ESH","ERI","ESP","ETH","FIN","FJI",
161
- "FLK","FSM","FRO","FRA","SXM","GAB","GBR","GRD","GEO","GUF",
162
- "GHA","GIB","GRL","GMB","GIN","GLP","GNQ","GRC","SGS","GTM",
163
- "GUM","GNB","GUY","HKG","HMD","HND","HRV","HTI","HUN","IDN",
164
- "IRL","ISR","IND","IOT","IRQ","IRN","ISL","ITA","JAM","JOR",
165
- "JPN","KEN","KGZ","KHM","KIR","COM","KNA","PRK","KOR","KWT",
166
- "CYM","KAZ","LAO","LBN","LCA","LIE","LKA","LBR","LSO","LTU",
167
- "LUX","LVA","LBY","MAR","MCO","MDA","MDG","MHL","MKD","MLI",
168
- "MMR","MNG","MAC","MNP","MTQ","MRT","MSR","MLT","MUS","MDV",
169
- "MWI","MEX","MYS","MOZ","NAM","NCL","NER","NFK","NGA","NIC",
170
- "NLD","NOR","NPL","NRU","NIU","NZL","OMN","PAN","PER","PYF",
171
- "PNG","PHL","PAK","POL","SPM","PCN","PRI","PSE","PRT","PLW",
172
- "PRY","QAT","REU","ROU","RUS","RWA","SAU","SLB","SYC","SDN",
173
- "SWE","SGP","SHN","SVN","SJM","SVK","SLE","SMR","SEN","SOM",
174
- "SUR","STP","SLV","SYR","SWZ","TCA","TCD","ATF","TGO","THA",
175
- "TJK","TKL","TKM","TUN","TON","TLS","TUR","TTO","TUV","TWN",
176
- "TZA","UKR","UGA","UMI","USA","URY","UZB","VAT","VCT","VEN",
177
- "VGB","VIR","VNM","VUT","WLF","WSM","YEM","MYT","SRB","ZAF",
178
- "ZMB","MNE","ZWE","A1","A2","O1","ALA","GGY","IMN","JEY",
179
- "BLM","MAF", "BES", "SSD", "O1"
180
- );
181
- var $GEOIP_COUNTRY_NAMES = array(
182
- "","Asia/Pacific Region","Europe","Andorra","United Arab Emirates","Afghanistan","Antigua and Barbuda","Anguilla","Albania","Armenia","Curacao",
183
- "Angola","Antarctica","Argentina","American Samoa","Austria","Australia","Aruba","Azerbaijan","Bosnia and Herzegovina","Barbados",
184
- "Bangladesh","Belgium","Burkina Faso","Bulgaria","Bahrain","Burundi","Benin","Bermuda","Brunei Darussalam","Bolivia",
185
- "Brazil","Bahamas","Bhutan","Bouvet Island","Botswana","Belarus","Belize","Canada","Cocos (Keeling) Islands","Congo, The Democratic Republic of the",
186
- "Central African Republic","Congo","Switzerland","Cote D'Ivoire","Cook Islands","Chile","Cameroon","China","Colombia","Costa Rica",
187
- "Cuba","Cape Verde","Christmas Island","Cyprus","Czech Republic","Germany","Djibouti","Denmark","Dominica","Dominican Republic",
188
- "Algeria","Ecuador","Estonia","Egypt","Western Sahara","Eritrea","Spain","Ethiopia","Finland","Fiji",
189
- "Falkland Islands (Malvinas)","Micronesia, Federated States of","Faroe Islands","France","Sint Maarten (Dutch part)","Gabon","United Kingdom","Grenada","Georgia","French Guiana",
190
- "Ghana","Gibraltar","Greenland","Gambia","Guinea","Guadeloupe","Equatorial Guinea","Greece","South Georgia and the South Sandwich Islands","Guatemala",
191
- "Guam","Guinea-Bissau","Guyana","Hong Kong","Heard Island and McDonald Islands","Honduras","Croatia","Haiti","Hungary","Indonesia",
192
- "Ireland","Israel","India","British Indian Ocean Territory","Iraq","Iran, Islamic Republic of","Iceland","Italy","Jamaica","Jordan",
193
- "Japan","Kenya","Kyrgyzstan","Cambodia","Kiribati","Comoros","Saint Kitts and Nevis","Korea, Democratic People's Republic of","Korea, Republic of","Kuwait",
194
- "Cayman Islands","Kazakhstan","Lao People's Democratic Republic","Lebanon","Saint Lucia","Liechtenstein","Sri Lanka","Liberia","Lesotho","Lithuania",
195
- "Luxembourg","Latvia","Libya","Morocco","Monaco","Moldova, Republic of","Madagascar","Marshall Islands","Macedonia","Mali",
196
- "Myanmar","Mongolia","Macau","Northern Mariana Islands","Martinique","Mauritania","Montserrat","Malta","Mauritius","Maldives",
197
- "Malawi","Mexico","Malaysia","Mozambique","Namibia","New Caledonia","Niger","Norfolk Island","Nigeria","Nicaragua",
198
- "Netherlands","Norway","Nepal","Nauru","Niue","New Zealand","Oman","Panama","Peru","French Polynesia",
199
- "Papua New Guinea","Philippines","Pakistan","Poland","Saint Pierre and Miquelon","Pitcairn Islands","Puerto Rico","Palestinian Territory","Portugal","Palau",
200
- "Paraguay","Qatar","Reunion","Romania","Russian Federation","Rwanda","Saudi Arabia","Solomon Islands","Seychelles","Sudan",
201
- "Sweden","Singapore","Saint Helena","Slovenia","Svalbard and Jan Mayen","Slovakia","Sierra Leone","San Marino","Senegal","Somalia","Suriname",
202
- "Sao Tome and Principe","El Salvador","Syrian Arab Republic","Swaziland","Turks and Caicos Islands","Chad","French Southern Territories","Togo","Thailand",
203
- "Tajikistan","Tokelau","Turkmenistan","Tunisia","Tonga","Timor-Leste","Turkey","Trinidad and Tobago","Tuvalu","Taiwan",
204
- "Tanzania, United Republic of","Ukraine","Uganda","United States Minor Outlying Islands","United States","Uruguay","Uzbekistan","Holy See (Vatican City State)","Saint Vincent and the Grenadines","Venezuela",
205
- "Virgin Islands, British","Virgin Islands, U.S.","Vietnam","Vanuatu","Wallis and Futuna","Samoa","Yemen","Mayotte","Serbia","South Africa",
206
- "Zambia","Montenegro","Zimbabwe","Anonymous Proxy","Satellite Provider","Other","Aland Islands","Guernsey","Isle of Man","Jersey",
207
- "Saint Barthelemy","Saint Martin", "Bonaire, Saint Eustatius and Saba",
208
- "South Sudan", "Other"
209
- );
210
-
211
- var $GEOIP_CONTINENT_CODES = array(
212
- "--", "AS","EU","EU","AS","AS","NA","NA","EU","AS","NA",
213
- "AF","AN","SA","OC","EU","OC","NA","AS","EU","NA",
214
- "AS","EU","AF","EU","AS","AF","AF","NA","AS","SA",
215
- "SA","NA","AS","AN","AF","EU","NA","NA","AS","AF",
216
- "AF","AF","EU","AF","OC","SA","AF","AS","SA","NA",
217
- "NA","AF","AS","AS","EU","EU","AF","EU","NA","NA",
218
- "AF","SA","EU","AF","AF","AF","EU","AF","EU","OC",
219
- "SA","OC","EU","EU","NA","AF","EU","NA","AS","SA",
220
- "AF","EU","NA","AF","AF","NA","AF","EU","AN","NA",
221
- "OC","AF","SA","AS","AN","NA","EU","NA","EU","AS",
222
- "EU","AS","AS","AS","AS","AS","EU","EU","NA","AS",
223
- "AS","AF","AS","AS","OC","AF","NA","AS","AS","AS",
224
- "NA","AS","AS","AS","NA","EU","AS","AF","AF","EU",
225
- "EU","EU","AF","AF","EU","EU","AF","OC","EU","AF",
226
- "AS","AS","AS","OC","NA","AF","NA","EU","AF","AS",
227
- "AF","NA","AS","AF","AF","OC","AF","OC","AF","NA",
228
- "EU","EU","AS","OC","OC","OC","AS","NA","SA","OC",
229
- "OC","AS","AS","EU","NA","OC","NA","AS","EU","OC",
230
- "SA","AS","AF","EU","EU","AF","AS","OC","AF","AF",
231
- "EU","AS","AF","EU","EU","EU","AF","EU","AF","AF",
232
- "SA","AF","NA","AS","AF","NA","AF","AN","AF","AS",
233
- "AS","OC","AS","AF","OC","AS","EU","NA","OC","AS",
234
- "AF","EU","AF","OC","NA","SA","AS","EU","NA","SA",
235
- "NA","NA","AS","OC","OC","OC","AS","AF","EU","AF",
236
- "AF","EU","AF","--","--","--","EU","EU","EU","EU",
237
- "NA","NA","NA", "AF", "--"
238
- );
239
-
240
- }
241
- function cpd_geoip_load_shared_mem ($file) {
242
-
243
- $fp = fopen($file, "rb");
244
- if (!$fp) {
245
- print "error opening $file: $php_errormsg\n";
246
- exit;
247
- }
248
- $s_array = fstat($fp);
249
- $size = $s_array['size'];
250
- if ($shmid = @shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) {
251
- shmop_delete ($shmid);
252
- shmop_close ($shmid);
253
- }
254
- $shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size);
255
- shmop_write ($shmid, fread($fp, $size), 0);
256
- shmop_close ($shmid);
257
- }
258
-
259
- function _cpd_setup_segments($gi){
260
- $gi->databaseType = GEOIP_COUNTRY_EDITION;
261
- $gi->record_length = STANDARD_RECORD_LENGTH;
262
- if ($gi->flags & GEOIP_SHARED_MEMORY) {
263
- $offset = @shmop_size ($gi->shmid) - 3;
264
- for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
265
- $delim = @shmop_read ($gi->shmid, $offset, 3);
266
- $offset += 3;
267
- if ($delim == (chr(255).chr(255).chr(255))) {
268
- $gi->databaseType = ord(@shmop_read ($gi->shmid, $offset, 1));
269
- $offset++;
270
-
271
- if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
272
- $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
273
- } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){
274
- $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
275
- } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)||
276
- ($gi->databaseType == GEOIP_CITY_EDITION_REV1)
277
- || ($gi->databaseType == GEOIP_ORG_EDITION)
278
- || ($gi->databaseType == GEOIP_ORG_EDITION_V6)
279
- || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
280
- || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
281
- || ($gi->databaseType == GEOIP_ISP_EDITION)
282
- || ($gi->databaseType == GEOIP_ISP_EDITION_V6)
283
- || ($gi->databaseType == GEOIP_USERTYPE_EDITION)
284
- || ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6)
285
- || ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
286
- || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
287
- || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
288
- || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
289
- || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1)
290
- || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6)
291
- || ($gi->databaseType == GEOIP_ASNUM_EDITION)
292
- || ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)){
293
- $gi->databaseSegments = 0;
294
- $buf = @shmop_read ($gi->shmid, $offset, SEGMENT_RECORD_LENGTH);
295
- for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){
296
- $gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
297
- }
298
- if (($gi->databaseType == GEOIP_ORG_EDITION)
299
- || ($gi->databaseType == GEOIP_ORG_EDITION_V6)
300
- || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
301
- || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
302
- || ($gi->databaseType == GEOIP_ISP_EDITION)
303
- || ($gi->databaseType == GEOIP_ISP_EDITION_V6)) {
304
- $gi->record_length = ORG_RECORD_LENGTH;
305
- }
306
- }
307
- break;
308
- } else {
309
- $offset -= 4;
310
- }
311
- }
312
- if (($gi->databaseType == GEOIP_COUNTRY_EDITION)||
313
- ($gi->databaseType == GEOIP_COUNTRY_EDITION_V6)||
314
- ($gi->databaseType == GEOIP_PROXY_EDITION)||
315
- ($gi->databaseType == GEOIP_NETSPEED_EDITION)){
316
- $gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
317
- }
318
- } else {
319
- $filepos = ftell($gi->filehandle);
320
- fseek($gi->filehandle, -3, SEEK_END);
321
- for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
322
- $delim = fread($gi->filehandle,3);
323
- if ($delim == (chr(255).chr(255).chr(255))){
324
- $gi->databaseType = ord(fread($gi->filehandle,1));
325
- if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
326
- $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
327
- }
328
- else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){
329
- $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
330
- } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)
331
- || ($gi->databaseType == GEOIP_CITY_EDITION_REV1)
332
- || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
333
- || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
334
- || ($gi->databaseType == GEOIP_ORG_EDITION)
335
- || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
336
- || ($gi->databaseType == GEOIP_ISP_EDITION)
337
- || ($gi->databaseType == GEOIP_ORG_EDITION_V6)
338
- || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
339
- || ($gi->databaseType == GEOIP_ISP_EDITION_V6)
340
- || ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
341
- || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
342
- || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
343
- || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
344
- || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1)
345
- || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6)
346
- || ($gi->databaseType == GEOIP_USERTYPE_EDITION)
347
- || ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6)
348
- || ($gi->databaseType == GEOIP_ASNUM_EDITION)
349
- || ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)){
350
- $gi->databaseSegments = 0;
351
- $buf = fread($gi->filehandle,SEGMENT_RECORD_LENGTH);
352
- for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){
353
- $gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
354
- }
355
- if ( ( $gi->databaseType == GEOIP_ORG_EDITION )
356
- || ( $gi->databaseType == GEOIP_DOMAIN_EDITION )
357
- || ( $gi->databaseType == GEOIP_ISP_EDITION )
358
- || ( $gi->databaseType == GEOIP_ORG_EDITION_V6 )
359
- || ( $gi->databaseType == GEOIP_DOMAIN_EDITION_V6 )
360
- || ( $gi->databaseType == GEOIP_ISP_EDITION_V6 )) {
361
- $gi->record_length = ORG_RECORD_LENGTH;
362
- }
363
- }
364
- break;
365
- } else {
366
- fseek($gi->filehandle, -4, SEEK_CUR);
367
- }
368
- }
369
- if (($gi->databaseType == GEOIP_COUNTRY_EDITION)||
370
- ($gi->databaseType == GEOIP_COUNTRY_EDITION_V6)||
371
- ($gi->databaseType == GEOIP_PROXY_EDITION)||
372
- ($gi->databaseType == GEOIP_NETSPEED_EDITION)){
373
- $gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
374
- }
375
- fseek($gi->filehandle,$filepos,SEEK_SET);
376
- }
377
- return $gi;
378
- }
379
-
380
- function cpd_geoip_open($filename, $flags) {
381
- $gi = new GeoIPCpd;
382
- $gi->flags = $flags;
383
- if ($gi->flags & GEOIP_SHARED_MEMORY) {
384
- $gi->shmid = @shmop_open (GEOIP_SHM_KEY, "a", 0, 0);
385
- } else {
386
- $gi->filehandle = fopen($filename,"rb") or die( "Can not open $filename\n" );
387
- if ($gi->flags & GEOIP_MEMORY_CACHE) {
388
- $s_array = fstat($gi->filehandle);
389
- $gi->memory_buffer = fread($gi->filehandle, $s_array['size']);
390
- }
391
- }
392
-
393
- $gi = _cpd_setup_segments($gi);
394
- return $gi;
395
- }
396
-
397
- function cpd_geoip_close($gi) {
398
- if ($gi->flags & GEOIP_SHARED_MEMORY) {
399
- return true;
400
- }
401
-
402
- return fclose($gi->filehandle);
403
- }
404
-
405
- function cpd_geoip_country_id_by_name_v6($gi, $name) {
406
- $rec = dns_get_record($name, DNS_AAAA);
407
- if ( !$rec ) {
408
- return false;
409
- }
410
- $addr = $rec[0]["ipv6"];
411
- if (!$addr || $addr == $name) {
412
- return false;
413
- }
414
- return cpd_geoip_country_id_by_addr_v6($gi, $addr);
415
- }
416
-
417
- function cpd_geoip_country_id_by_name($gi, $name) {
418
- $addr = gethostbyname($name);
419
- if (!$addr || $addr == $name) {
420
- return false;
421
- }
422
- return cpd_geoip_country_id_by_addr($gi, $addr);
423
- }
424
-
425
- function cpd_geoip_country_code_by_name_v6($gi, $name) {
426
- $country_id = cpd_geoip_country_id_by_name_v6($gi,$name);
427
- if ($country_id !== false) {
428
- return $gi->GEOIP_COUNTRY_CODES[$country_id];
429
- }
430
- return false;
431
- }
432
-
433
- function cpd_geoip_country_code_by_name($gi, $name) {
434
- $country_id = cpd_geoip_country_id_by_name($gi,$name);
435
- if ($country_id !== false) {
436
- return $gi->GEOIP_COUNTRY_CODES[$country_id];
437
- }
438
- return false;
439
- }
440
-
441
- function cpd_geoip_country_name_by_name_v6($gi, $name) {
442
- $country_id = cpd_geoip_country_id_by_name_v6($gi,$name);
443
- if ($country_id !== false) {
444
- return $gi->GEOIP_COUNTRY_NAMES[$country_id];
445
- }
446
- return false;
447
- }
448
-
449
- function cpd_geoip_country_name_by_name($gi, $name) {
450
- $country_id = cpd_geoip_country_id_by_name($gi,$name);
451
- if ($country_id !== false) {
452
- return $gi->GEOIP_COUNTRY_NAMES[$country_id];
453
- }
454
- return false;
455
- }
456
-
457
- function cpd_geoip_country_id_by_addr_v6($gi, $addr) {
458
- $ipnum = cpd_inet_pton($addr);
459
- return _cpd_geoip_seek_country_v6($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
460
- }
461
-
462
- function cpd_geoip_country_id_by_addr($gi, $addr) {
463
- $ipnum = ip2long($addr);
464
- return _cpd_geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
465
- }
466
-
467
- function cpd_geoip_country_code_by_addr_v6($gi, $addr) {
468
- $country_id = cpd_geoip_country_id_by_addr_v6($gi,$addr);
469
- if ($country_id !== false) {
470
- return $gi->GEOIP_COUNTRY_CODES[$country_id];
471
- }
472
- return false;
473
- }
474
-
475
- function cpd_geoip_country_code_by_addr($gi, $addr) {
476
- if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
477
- $record = cpd_geoip_record_by_addr($gi,$addr);
478
- if ( $record !== false ) {
479
- return $record->country_code;
480
- }
481
- } else {
482
- $country_id = cpd_geoip_country_id_by_addr($gi,$addr);
483
- if ($country_id !== false) {
484
- return $gi->GEOIP_COUNTRY_CODES[$country_id];
485
- }
486
- }
487
- return false;
488
- }
489
-
490
- function cpd_geoip_country_name_by_addr_v6($gi, $addr) {
491
- $country_id = cpd_geoip_country_id_by_addr_v6($gi,$addr);
492
- if ($country_id !== false) {
493
- return $gi->GEOIP_COUNTRY_NAMES[$country_id];
494
- }
495
- return false;
496
- }
497
-
498
- function cpd_geoip_country_name_by_addr($gi, $addr) {
499
- if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
500
- $record = cpd_geoip_record_by_addr($gi,$addr);
501
- return $record->country_name;
502
- } else {
503
- $country_id = cpd_geoip_country_id_by_addr($gi,$addr);
504
- if ($country_id !== false) {
505
- return $gi->GEOIP_COUNTRY_NAMES[$country_id];
506
- }
507
- }
508
- return false;
509
- }
510
-
511
- function _cpd_geoip_seek_country_v6($gi, $ipnum) {
512
-
513
- # arrays from unpack start with offset 1
514
- # yet another php mystery. array_merge work around
515
- # this broken behaviour
516
- if (strlen($ipnum) === 4) // IPv4
517
- $v6vec = array_pad(unpack( "C4", $ipnum), -16, 0);
518
- else
519
- $v6vec = array_merge(unpack( "C16", $ipnum));
520
-
521
- $offset = 0;
522
- for ($depth = 127; $depth >= 0; --$depth) {
523
- if ($gi->flags & GEOIP_MEMORY_CACHE) {
524
- // workaround php's broken substr, strpos, etc handling with
525
- // mbstring.func_overload and mbstring.internal_encoding
526
- $enc = mb_internal_encoding();
527
- mb_internal_encoding('ISO-8859-1');
528
-
529
- $buf = substr($gi->memory_buffer,
530
- 2 * $gi->record_length * $offset,
531
- 2 * $gi->record_length);
532
-
533
- mb_internal_encoding($enc);
534
- } elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
535
- $buf = @shmop_read ($gi->shmid,
536
- 2 * $gi->record_length * $offset,
537
- 2 * $gi->record_length );
538
- } else {
539
- fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
540
- or die("fseek failed");
541
- $buf = fread($gi->filehandle, 2 * $gi->record_length);
542
- }
543
- $x = array(0,0);
544
- for ($i = 0; $i < 2; ++$i) {
545
- for ($j = 0; $j < $gi->record_length; ++$j) {
546
- $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
547
- }
548
- }
549
-
550
- $bnum = 127 - $depth;
551
- $idx = $bnum >> 3;
552
- $b_mask = 1 << ( $bnum & 7 ^ 7 );
553
- if (($v6vec[$idx] & $b_mask) > 0) {
554
- if ($x[1] >= $gi->databaseSegments) {
555
- return $x[1];
556
- }
557
- $offset = $x[1];
558
- } else {
559
- if ($x[0] >= $gi->databaseSegments) {
560
- return $x[0];
561
- }
562
- $offset = $x[0];
563
- }
564
- }
565
- trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR);
566
- return false;
567
- }
568
-
569
- function _cpd_geoip_seek_country($gi, $ipnum) {
570
- $offset = 0;
571
- for ($depth = 31; $depth >= 0; --$depth) {
572
- if ($gi->flags & GEOIP_MEMORY_CACHE) {
573
- // workaround php's broken substr, strpos, etc handling with
574
- // mbstring.func_overload and mbstring.internal_encoding
575
- $enc = mb_internal_encoding();
576
- mb_internal_encoding('ISO-8859-1');
577
-
578
- $buf = substr($gi->memory_buffer,
579
- 2 * $gi->record_length * $offset,
580
- 2 * $gi->record_length);
581
-
582
- mb_internal_encoding($enc);
583
- } elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
584
- $buf = @shmop_read ($gi->shmid,
585
- 2 * $gi->record_length * $offset,
586
- 2 * $gi->record_length );
587
- } else {
588
- fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
589
- or die("fseek failed");
590
- $buf = fread($gi->filehandle, 2 * $gi->record_length);
591
- }
592
- $x = array(0,0);
593
- for ($i = 0; $i < 2; ++$i) {
594
- for ($j = 0; $j < $gi->record_length; ++$j) {
595
- $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
596
- }
597
- }
598
- if ($ipnum & (1 << $depth)) {
599
- if ($x[1] >= $gi->databaseSegments) {
600
- return $x[1];
601
- }
602
- $offset = $x[1];
603
- } else {
604
- if ($x[0] >= $gi->databaseSegments) {
605
- return $x[0];
606
- }
607
- $offset = $x[0];
608
- }
609
- }
610
- trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR);
611
- return false;
612
- }
613
-
614
- function _cpd_common_get_org($gi, $seek_org){
615
- $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments;
616
- if ($gi->flags & GEOIP_SHARED_MEMORY) {
617
- $org_buf = @shmop_read ($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH);
618
- } else {
619
- fseek($gi->filehandle, $record_pointer, SEEK_SET);
620
- $org_buf = fread($gi->filehandle,MAX_ORG_RECORD_LENGTH);
621
- }
622
- // workaround php's broken substr, strpos, etc handling with
623
- // mbstring.func_overload and mbstring.internal_encoding
624
- $enc = mb_internal_encoding();
625
- mb_internal_encoding('ISO-8859-1');
626
- $org_buf = substr($org_buf, 0, strpos($org_buf, "\0"));
627
- mb_internal_encoding($enc);
628
- return $org_buf;
629
- }
630
-
631
- function _cpd_get_org_v6($gi,$ipnum){
632
- $seek_org = _cpd_geoip_seek_country_v6($gi,$ipnum);
633
- if ($seek_org == $gi->databaseSegments) {
634
- return NULL;
635
- }
636
- return _cpd_common_get_org($gi, $seek_org);
637
- }
638
-
639
- function _cpd_get_org($gi,$ipnum){
640
- $seek_org = _cpd_geoip_seek_country($gi,$ipnum);
641
- if ($seek_org == $gi->databaseSegments) {
642
- return NULL;
643
- }
644
- return _cpd_common_get_org($gi, $seek_org);
645
- }
646
-
647
-
648
-
649
- function cpd_geoip_name_by_addr_v6 ($gi,$addr) {
650
- if ($addr == NULL) {
651
- return 0;
652
- }
653
- $ipnum = cpd_inet_pton($addr);
654
- return _cpd_get_org_v6($gi, $ipnum);
655
- }
656
-
657
- function cpd_geoip_name_by_addr ($gi,$addr) {
658
- if ($addr == NULL) {
659
- return 0;
660
- }
661
- $ipnum = ip2long($addr);
662
- return _cpd_get_org($gi, $ipnum);
663
- }
664
-
665
- function cpd_geoip_org_by_addr ($gi,$addr) {
666
- return cpd_geoip_name_by_addr($gi, $addr);
667
- }
668
-
669
- function _cpd_get_region($gi,$ipnum){
670
- if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
671
- $seek_region = _cpd_geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0;
672
- if ($seek_region >= 1000){
673
- $country_code = "US";
674
- $region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65);
675
- } else {
676
- $country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region];
677
- $region = "";
678
- }
679
- return array ($country_code,$region);
680
- } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
681
- $seek_region = _cpd_geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV1;
682
- //print $seek_region;
683
- if ($seek_region < US_OFFSET){
684
- $country_code = "";
685
- $region = "";
686
- } else if ($seek_region < CANADA_OFFSET) {
687
- $country_code = "US";
688
- $region = chr(($seek_region - US_OFFSET)/26 + 65) . chr(($seek_region - US_OFFSET)%26 + 65);
689
- } else if ($seek_region < WORLD_OFFSET) {
690
- $country_code = "CA";
691
- $region = chr(($seek_region - CANADA_OFFSET)/26 + 65) . chr(($seek_region - CANADA_OFFSET)%26 + 65);
692
- } else {
693
- $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE];
694
- $region = "";
695
- }
696
- return array ($country_code,$region);
697
- }
698
- }
699
-
700
- function cpd_geoip_region_by_addr ($gi,$addr) {
701
- if ($addr == NULL) {
702
- return 0;
703
- }
704
- $ipnum = ip2long($addr);
705
- return _cpd_get_region($gi, $ipnum);
706
- }
707
-
708
- function cpd_getdnsattributes ($l,$ip){
709
- $r = new Net_DNS_Resolver();
710
- $r->nameservers = array("ws1.maxmind.com");
711
- $p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN");
712
- $str = is_object($p->answer[0])?$p->answer[0]->string():'';
713
- $str = substr( $str, 1, -1 );
714
- return $str;
715
- }
716
-
717
- // Windows server < PHP 5.3
718
- // PHP without IPv6 support
719
- function cpd_inet_pton($ip)
720
- {
721
- # ipv4
722
- if (strpos($ip, '.') !== FALSE)
723
- {
724
- if (strpos($ip, ':') === FALSE)
725
- $ip = pack('N',ip2long($ip));
726
- else
727
- {
728
- $ip = explode(':',$ip);
729
- $ip = pack('N',ip2long($ip[count($ip)-1]));
730
- }
731
- }
732
- # ipv6
733
- elseif (strpos($ip, ':') !== FALSE)
734
- {
735
- $ip = explode(':', $ip);
736
- $parts=8-count($ip);
737
- $res='';$replaced=0;
738
- foreach ($ip as $seg)
739
- {
740
- if ($seg!='')
741
- $res .= str_pad($seg, 4, '0', STR_PAD_LEFT);
742
- elseif ($replaced==0)
743
- {
744
- for ($i=0;$i<=$parts;$i++)
745
- $res.='0000';
746
- $replaced=1;
747
- } elseif ($replaced==1)
748
- $res.='0000';
749
- }
750
- $ip = pack('H'.strlen($res), $res);
751
- }
752
- return $ip;
753
- }
locale/cpd-de_DE.mo CHANGED
Binary file
locale/cpd-de_DE.po CHANGED
@@ -1,9 +1,9 @@
1
msgid ""
2
msgstr ""
3
- "Project-Id-Version: Count Per Day v3.3\n"
4
"Report-Msgid-Bugs-To: \n"
5
"POT-Creation-Date: 2008-11-02 12:13+0100\n"
6
- "PO-Revision-Date: 2015-02-13 08:17:28+0000\n"
7
"Last-Translator: Tom Braider <post@tomsdimension.de>\n"
8
"Language-Team: \n"
9
"MIME-Version: 1.0\n"
@@ -25,301 +25,301 @@ msgstr ""
25
msgid "Options updated"
26
msgstr "Einstellungen aktualisiert"
27
28
- #: counter-options.php:121
29
#, php-format
30
#@ cpd
31
msgid "Database cleaned. %s rows deleted."
32
msgstr "Datenbank aufger&auml;umt. %s Datens&auml;tze gel&ouml;scht."
33
34
- #: counter-options.php:136
35
- #: counter-options.php:806
36
#@ cpd
37