Count per Day - Version 3.0

Version Description

  • New: use now default WordPress database functions to be compatible to e.g. multi-db plugins
  • New: backup your counter data
  • New: collect entries of counter table per month and per post to reduce the database and speed up the statistics
  • New: functions and shortcodes [CPD_DAY_MOST_READS] [CPD_DAY_MOST_USERS] to shows days with most reads/visitors
  • New: option to cut referrer on "?" to not store query strings
  • New: parameter '$postsonly' for 'getMostVisitedPosts' function to list single posts and pages only
  • New: flags for Moldavia and Nepal
  • New language: Norwegian, thanks to Stein Ivar Johnsen and Tore Johnny Brtveit
  • New language: Azerbaijani, thanks to Bohdan Zograf
  • New language: Japanese, thanks to Juno Hayami
  • Bugfix: visitors per month list
  • Change: some function parameters
  • Change: little memory optimizing
  • Change: visitors currently online and notes will now managed per option, without seperate tables in database
  • Change: design updated
  • Change: old bar charts deleted
Download this release

Release Info

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

Code changes from version 2.17 to 3.0

Files changed (60) hide show
  1. ajax.php +3 -3
  2. counter-core.php +1233 -0
  3. counter-options.php +640 -371
  4. counter.css +174 -137
  5. counter.php +472 -1528
  6. geoip/GeoIP.dat +0 -0
  7. geoip/geoip.php +26 -41
  8. img/cpd_calendar.png +0 -0
  9. img/cpd_flags.png +0 -0
  10. img/cpd_pen.png +0 -0
  11. img/cpd_sprites.png +0 -0
  12. js/jquery.flot.min.js +6 -1
  13. locale/cpd-az_AZ.mo +0 -0
  14. locale/cpd-az_AZ.po +972 -0
  15. locale/cpd-be_BY.mo +0 -0
  16. locale/cpd-be_BY.po +784 -0
  17. locale/cpd-bg_BG.mo +0 -0
  18. locale/cpd-bg_BG.po +398 -211
  19. locale/cpd-da_DK.mo +0 -0
  20. locale/cpd-da_DK.po +414 -226
  21. locale/cpd-de_DE.mo +0 -0
  22. locale/cpd-de_DE.po +389 -217
  23. locale/cpd-el.mo +0 -0
  24. locale/cpd-el.po +398 -211
  25. locale/cpd-es_ES.mo +0 -0
  26. locale/cpd-es_ES.po +398 -211
  27. locale/cpd-fr_FR.mo +0 -0
  28. locale/cpd-fr_FR.po +399 -212
  29. locale/cpd-it_IT.mo +0 -0
  30. locale/cpd-it_IT.po +399 -212
  31. locale/cpd-ja.mo +0 -0
  32. locale/cpd-ja.po +972 -0
  33. locale/cpd-lt_LT.mo +0 -0
  34. locale/cpd-lt_LT.po +784 -0
  35. locale/cpd-nb_NO.mo +0 -0
  36. locale/cpd-nb_NO.po +972 -0
  37. locale/cpd-nl_NL.mo +0 -0
  38. locale/cpd-nl_NL.po +411 -224
  39. locale/cpd-pl_PL.mo +0 -0
  40. locale/cpd-pl_PL.po +398 -211
  41. locale/cpd-pt_BR.mo +0 -0
  42. locale/cpd-pt_BR.po +430 -244
  43. locale/cpd-pt_PT.mo +0 -0
  44. locale/cpd-pt_PT.po +971 -0
  45. locale/cpd-ru_RU.mo +0 -0
  46. locale/cpd-ru_RU.po +402 -214
  47. locale/cpd-sv_SE.mo +0 -0
  48. locale/cpd-sv_SE.po +538 -350
  49. locale/cpd-tr_TR.mo +0 -0
  50. locale/cpd-tr_TR.po +401 -214
  51. locale/cpd-ua_UA.mo +0 -0
  52. locale/cpd-ua_UA.po +972 -0
  53. map/ammap.swf +0 -0
  54. map/data.xml.php +26 -39
  55. map/map.php +1 -1
  56. map/settings.xml.php +3 -0
  57. massbots.php +29 -26
  58. notes.php +22 -26
  59. readme.txt +118 -71
  60. userperspan.php +18 -18
ajax.php CHANGED
@@ -2,15 +2,15 @@
2
if ( $_GET['f'] == 'count' )
3
{
4
if (!session_id()) session_start();
5
- require_once($_SESSION['cpd_wp'].'wp-load.php');
6
7
- // $cpd_funcs = CountPerDay_Widget::getWidgetFuncs();
8
$cpd_funcs = array ( 'show',
9
'getReadsAll', 'getReadsToday', 'getReadsYesterday', 'getReadsLastWeek', 'getReadsThisMonth',
10
'getUserAll', 'getUserToday', 'getUserYesterday', 'getUserLastWeek', 'getUserThisMonth',
11
'getUserPerDay', 'getUserOnline', 'getFirstCount' );
12
13
- $page = intval($_GET['page']);
14
if ( is_numeric($page) )
15
{
16
$count_per_day->count( '', $page );
2
if ( $_GET['f'] == 'count' )
3
{
4
if (!session_id()) session_start();
5
+ $cpd_wp = (!empty($_SESSION['cpd_wp'])) ? $_SESSION['cpd_wp'] : '../../../';
6
+ require_once($cpd_wp.'wp-load.php');
7
8
$cpd_funcs = array ( 'show',
9
'getReadsAll', 'getReadsToday', 'getReadsYesterday', 'getReadsLastWeek', 'getReadsThisMonth',
10
'getUserAll', 'getUserToday', 'getUserYesterday', 'getUserLastWeek', 'getUserThisMonth',
11
'getUserPerDay', 'getUserOnline', 'getFirstCount' );
12
13
+ $page = (int) $_GET['page'];
14
if ( is_numeric($page) )
15
{
16
$count_per_day->count( '', $page );
counter-core.php ADDED
@@ -0,0 +1,1233 @@
1
+ <?php
2
+ /**
3
+ * Filename: counter-core.php
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
16
+ */
17
+ class CountPerDayCore
18
+ {
19
+
20
+ var $options; // options array
21
+ var $dir; // this plugin dir
22
+ var $dbcon; // database connection
23
+ var $queries = array(); // queries times for debug
24
+ var $page; // Post/Page-ID
25
+ var $installed = false; // CpD installed in subblogs?
26
+
27
+ /**
28
+ * Constructor
29
+ */
30
+ function init()
31
+ {
32
+ // variables
33
+ global $wpdb, $cpd_path, $cpd_dir_name;
34
+
35
+ define('CPD_METABOX', 'cpd_metaboxes');
36
+
37
+ // multisite table names
38
+ foreach ( array('cpd_counter','cpd_counter_useronline','cpd_notes') as $t )
39
+ {
40
+ $wpdb->tables[] = $t;
41
+ $wpdb->$t = $wpdb->get_blog_prefix().$t;
42
+ }
43
+
44
+ // use local time, not UTC
45
+ get_option('gmt_offset');
46
+
47
+ $this->options = get_option('count_per_day');
48
+
49
+ // manual debug mode
50
+ if (!empty($_GET['debug']) && WP_DEBUG )
51
+ $this->options['debug'] = 1;
52
+
53
+ $this->dir = get_bloginfo('wpurl').'/'.PLUGINDIR.'/'.$cpd_dir_name;
54
+ $this->queries[0] = 0;
55
+
56
+ // update online counter
57
+ add_action('wp', array(&$this,'deleteOnlineCounter'));
58
+
59
+ // settings link on plugin page
60
+ add_filter('plugin_action_links', array(&$this,'pluginActions'), 10, 2);
61
+
62
+ // auto counter
63
+ if ($this->options['autocount'])
64
+ add_action('wp', array(&$this,'count'));
65
+
66
+ // javascript to count cached posts
67
+ if ($this->options['ajax'])
68
+ {
69
+ wp_enqueue_script('jquery');
70
+ add_action('wp_footer', array(&$this,'addAjaxScript'));
71
+ }
72
+
73
+ if (is_admin())
74
+ {
75
+ // admin menu
76
+ add_action('admin_menu', array(&$this,'menu'));
77
+ // widget on dashboard page
78
+ add_action('wp_dashboard_setup', array(&$this,'dashboardWidgetSetup'));
79
+ // CpD dashboard page
80
+ add_filter('screen_layout_columns', array(&$this,'screenLayoutColumns'), 10, 2);
81
+ // CpD dashboard
82
+ add_action('admin_menu', array(&$this,'setAdminMenu'));
83
+ // column page list
84
+ add_action('manage_pages_custom_column', array(&$this,'cpdColumnContent'), 10, 2);
85
+ add_filter('manage_pages_columns', array(&$this,'cpdColumn'));
86
+ // column post list
87
+ add_action('manage_posts_custom_column', array(&$this,'cpdColumnContent'), 10, 2);
88
+ add_filter('manage_posts_columns', array(&$this,'cpdColumn'));
89
+ // adds javascript
90
+ add_action('admin_head', array(&$this,'addJS'));
91
+ // check version
92
+ add_action('admin_head', array(&$this,'checkInstalledVersion'));
93
+ }
94
+
95
+ // locale support
96
+ if (defined('WPLANG') && function_exists('load_plugin_textdomain'))
97
+ load_plugin_textdomain('cpd', false, $cpd_dir_name.'/locale');
98
+
99
+ // adds stylesheet
100
+ if (is_admin())
101
+ add_action('admin_head', array(&$this,'addCss'));
102
+ if ( empty($this->options['no_front_css']) )
103
+ add_action('wp_head', array(&$this,'addCss'));
104
+
105
+ // widget setup
106
+ add_action('widgets_init', array( &$this,'register_widgets'));
107
+
108
+ // activation hook
109
+ register_activation_hook(ABSPATH.PLUGINDIR.'/count-per-day/counter.php', array(&$this,'checkVersion'));
110
+
111
+ // update hook
112
+ if (function_exists('register_update_hook'))
113
+ register_update_hook(ABSPATH.PLUGINDIR.'/count-per-day/counter.php', array(&$this,'checkVersion'));
114
+
115
+ // uninstall hook
116
+ register_uninstall_hook($cpd_path.'counter.php', 'count_per_day_uninstall');
117
+
118
+ // query times debug
119
+ if ($this->options['debug'])
120
+ {
121
+ add_action('wp_footer', array(&$this,'showQueries'));
122
+ add_action('admin_footer', array(&$this,'showQueries'));
123
+ }
124
+
125
+ // add shortcode support
126
+ $this->addShortcodes();
127
+
128
+ // thickbox in backend only
129
+ if (strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/') !== false )
130
+ {
131
+ wp_enqueue_script('thickbox');
132
+ wp_enqueue_script('cpd_flot', $this->dir.'/js/jquery.flot.min.js', 'jQuery');
133
+ }
134
+
135
+ // Session
136
+ add_action('init', array(&$this,'startSession'), 1);
137
+ }
138
+
139
+ /**
140
+ * starts session to provide WP variables to "addons"
141
+ */
142
+ function startSession()
143
+ {
144
+ if (!session_id())
145
+ session_start();
146
+ $_SESSION['cpd_wp'] = ABSPATH;
147
+ }
148
+
149
+ /**
150
+ * get result from database
151
+ * @param string $kind kind of result
152
+ * @param string $sql sql query
153
+ * @param string $func name for debug info
154
+ */
155
+ function mysqlQuery( $kind = '', $sql, $func = '' )
156
+ {
157
+ global $wpdb;
158
+ $t = microtime(true);
159
+ $con = $wpdb->dbh;
160
+
161
+ $preparedSql = $wpdb->prepare($sql);
162
+
163
+ if ($kind == 'var')
164
+ $r = $wpdb->get_var( $preparedSql );
165
+ else if ($kind == 'count')
166
+ {
167
+ $sql = 'SELECT COUNT(*) FROM ('.trim($sql,';').') t';
168
+ $r = $wpdb->get_var( $wpdb->prepare($sql) );
169
+ }
170
+ else if ($kind = 'rows')
171
+ $r = $wpdb->get_results( $preparedSql );
172
+ else
173
+ $wpdb->query( $preparedSql );
174
+
175
+ if ( $this->options['debug'] )
176
+ {
177
+ $d = number_format( microtime(true) - $t , 5);
178
+ $m = sprintf("%.2f", memory_get_usage()/1048576).' MB';
179
+ $error = (!$r && mysql_errno($con)) ? '<b style="color:red">ERROR:</b> '.mysql_errno($con).' - '.mysql_error($con).' - ' : '';
180
+ $this->queries[] = $func." : <b>$d</b> - $m<br/><code>$preparedSql</code><br/>$error";
181
+ $this->queries[0] += $d;
182
+ }
183
+
184
+ return $r;
185
+ }
186
+
187
+ /**
188
+ * update DB if neccessary
189
+ */
190
+ function checkInstalledVersion()
191
+ {
192
+ global $cpd_version, $cpd_dir_name;
193
+ if ( $this->options['version'] != $cpd_version )
194
+ {
195
+ $this->checkVersion();
196
+ echo '<div class="updated"><p>'.sprintf(__('"Count per Day" updated to version %s.', 'cpd'), $cpd_version).'</p></div>';
197
+ }
198
+ }
199
+
200
+ /**
201
+ * anonymize IP address (last bit) if option is set
202
+ * @param $ip real IP address
203
+ * @return new IP address
204
+ */
205
+ function anonymize_ip( $ip )
206
+ {
207
+ if ( $this->options['debug'] )
208
+ $this->queries[] = 'called Function: <b style="color:blue">anonymize_ip</b> IP: <code>'.$ip.'</code>';
209
+ if ($this->options['anoip'])
210
+ {
211
+ $i = explode('.', $ip);
212
+ $i[3] += round( array_sum($i) / 4 + date_i18n('d') );
213
+ if ( $i[3] > 255 )
214
+ $i[3] -= 255;
215
+ return implode('.', $i);
216
+ }
217
+ else
218
+ return $ip;
219
+ }
220
+
221
+ /**
222
+ * gets PostID
223
+ */
224
+ function getPostID()
225
+ {
226
+ global $wp_query;
227
+ // find PostID
228
+ if ( !is_404() ) :
229
+ if ( $this->options['autocount'] && is_singular() )
230
+ {
231
+ // single page with autocount on
232
+ // make loop before regular loop is defined
233
+ if (have_posts()) :
234
+ while ( have_posts() && empty($p) ) :
235
+ the_post();
236
+ $p = get_the_ID();
237
+ endwhile;
238
+ endif;
239
+ rewind_posts();
240
+ }
241
+ else if (is_singular())
242
+ // single page with template tag show() or count()
243
+ $p = get_the_ID();
244
+ // "index" pages only with autocount
245
+ else if ( is_category() || is_tag() )
246
+ // category or tag => negativ ID in CpD DB
247
+ $p = 0 - $wp_query->get_queried_object_id();
248
+ else
249
+ // index, date, search and other "list" pages will count only once
250
+ $p = 0;
251
+ $this->page = $p;
252
+ if ( $this->options['debug'] )
253
+ $this->queries[] = 'called Function: <b style="color:blue">getPostID</b> page ID: <code>'.$p.'</code>';
254
+ return $p;
255
+ endif;
256
+
257
+ return false;
258
+ }
259
+
260
+ /**
261
+ * bot or human?
262
+ * @param string $client USER_AGENT
263
+ * @param array $bots strings to check
264
+ * @param string $ip IP adress
265
+ */
266
+ function isBot( $client = '', $bots = '', $ip = '' )
267
+ {
268
+ if (empty($client))
269
+ $client = $_SERVER['HTTP_USER_AGENT'];
270
+ if (empty($ip))
271
+ $ip = $_SERVER['REMOTE_ADDR'];
272
+
273
+ // empty/short client -> not normal browser -> bot
274
+ if ( empty($client) || strlen($client) < 20 )
275
+ return true;
276
+
277
+ if (empty($bots))
278
+ $bots = explode( "\n", $this->options['bots'] );
279
+
280
+ $isBot = false;
281
+ foreach ( $bots as $bot )
282
+ {
283
+ if (!$isBot) // loop until first bot was found only
284
+ {
285
+ $b = trim($bot);
286
+ if ( !empty($b) && ( $ip == $b || strpos( strtolower($client), strtolower($b) ) !== false ) )
287
+ $isBot = true;
288
+ }
289
+ }
290
+ return $isBot;
291
+ }
292
+
293
+ /**
294
+ * checks installation in sub blogs
295
+ */
296
+ function checkVersion()
297
+ {
298
+ global $wpdb;
299
+ if ( function_exists('is_multisite') && is_multisite() )
300
+ {
301
+ // check if it is a network activation
302
+ if (!empty($_GET['networkwide']))
303
+ {
304
+ $old_blog = $wpdb->blogid;
305
+ $blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs"));
306
+ foreach ($blogids as $blog_id)
307
+ {
308
+ // create tables in all sub blogs
309
+ switch_to_blog($blog_id);
310
+ $this->createTables();
311
+ }
312
+ switch_to_blog($old_blog);
313
+ return;
314
+ }
315
+ }
316
+ // create tables in main blog
317
+ $this->createTables();
318
+ }
319
+
320
+ /**
321
+ * creates tables if not exists
322
+ */
323
+ function createTables()
324
+ {
325
+ global $wpdb;
326
+ // for plugin activation, creates $wpdb
327
+ require_once(ABSPATH.'wp-admin/includes/upgrade.php');
328
+
329
+ // variables for subblogs
330
+ $cpd_c = $wpdb->cpd_counter;
331
+ $cpd_o = $wpdb->cpd_counter_useronline;
332
+ $cpd_n = $wpdb->cpd_notes;
333
+
334
+ if (!empty ($wpdb->charset))
335
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
336
+ if (!empty ($wpdb->collate))
337
+ $charset_collate .= " COLLATE $wpdb->collate";
338
+
339
+ // table "counter"
340
+ $sql = "CREATE TABLE IF NOT EXISTS `$cpd_c` (
341
+ `id` int(10) NOT NULL auto_increment,
342
+ `ip` int(10) unsigned NOT NULL,
343
+ `client` varchar(150) NOT NULL,
344
+ `date` date NOT NULL,
345
+ `page` mediumint(9) NOT NULL,
346
+ `referer` varchar(100) NOT NULL,
347
+ PRIMARY KEY (`id`),
348
+ KEY `idx_page` (`page`),
349
+ KEY `idx_dateip` (`date`,`ip`) )
350
+ $charset_collate;";
351
+ $this->mysqlQuery('', $sql, 'createTables '.__LINE__);
352
+
353
+ // update fields in old table
354
+ $field = $this->mysqlQuery('rows', "SHOW FIELDS FROM `$cpd_c` LIKE 'ip'", 'createTables '.__LINE__);
355
+ $row = $field[0];
356
+ if ( strpos(strtolower($row->Type), 'int') === false )
357
+ {
358
+ $queries = array (
359
+ "ALTER TABLE `$cpd_c` ADD `ip2` INT(10) UNSIGNED NOT NULL AFTER `ip`",
360
+ "UPDATE `$cpd_c` SET ip2 = INET_ATON(ip)",
361
+ "ALTER TABLE `$cpd_c` DROP `ip`",
362
+ "ALTER TABLE `$cpd_c` CHANGE `ip2` `ip` INT( 10 ) UNSIGNED NOT NULL",
363
+ "ALTER TABLE `$cpd_c` CHANGE `date` `date` date NOT NULL",
364
+ "ALTER TABLE `$cpd_c` CHANGE `page` `page` mediumint(9) NOT NULL");
365
+ foreach ($queries as $sql)
366
+ $this->mysqlQuery('', $sql, 'update old fields '.__LINE__);
367
+ }
368
+
369
+ // make new keys
370
+ $keys = $this->mysqlQuery('rows', "SHOW KEYS FROM `$cpd_c`", 'make keys '.__LINE__);
371
+ $s = array();
372
+ foreach ($keys as $row)
373
+ if ( $row->Key_name != 'PRIMARY' )
374
+ $s[] = "DROP INDEX `$row->Key_name`";
375
+ $s = array_unique($s);
376
+
377
+ $sql = "ALTER TABLE `$cpd_c` ";
378
+ if (sizeof($s))
379
+ $sql .= implode(',', $s).', ';
380
+ $sql .= 'ADD KEY `idx_dateip` (`date`,`ip`), ADD KEY `idx_page` (`page`)';
381
+ $this->mysqlQuery('', $sql, 'make keys '.__LINE__);
382
+
383
+ // if GeoIP installed we need row "country"
384
+ if ( class_exists('CpdGeoIp') )
385
+ {
386
+ $this->mysqlQuery('', "SELECT country FROM `$cpd_c` LIMIT 1", 'check country '.__LINE__);
387
+ if ((int) mysql_errno() == 1054)
388
+ $this->mysqlQuery('', "ALTER TABLE `$cpd_c` ADD `country` CHAR(2) NOT NULL", 'make country '.__LINE__);
389
+ }
390
+
391
+ // referrer
392
+ $this->mysqlQuery('', "SELECT referer FROM `$cpd_c` LIMIT 1", 'check referer '.__LINE__);
393
+ if ((int) mysql_errno() == 1054)
394
+ $this->mysqlQuery('', "ALTER TABLE `$cpd_c` ADD `referer` VARCHAR(100) NOT NULL", 'make referer '.__LINE__);
395
+
396
+ // delete table "counter-online", since v3.0
397
+ $this->mysqlQuery('', "DROP TABLE IF EXISTS `$cpd_o`", 'table online '.__LINE__);
398
+
399
+ // delete table "notes", since v3.0
400
+ if (!get_option('count_per_day_notes'))
401
+ {
402
+ $table = $this->mysqlQuery('rows', "SHOW TABLES LIKE '$cpd_n'", 'table notes '.__LINE__);
403
+ if (!empty($table))
404
+ {
405
+ $ndb = $this->mysqlQuery('rows', "SELECT * FROM $cpd_n", 'table notes '.__LINE__);
406
+ $n = array();
407
+ foreach ($ndb as $note)
408
+ $n[] = array( $note->date, $note->note );
409
+ update_option('count_per_day_notes', $n);
410
+ }
411
+ }
412
+ $this->mysqlQuery('', "DROP TABLE IF EXISTS `$cpd_n`", 'table notes '.__LINE__);
413
+
414
+ // update options to array
415
+ $this->UpdateOptions();
416
+
417
+ // set directory mode
418
+ @chmod(ABSPATH.PLUGINDIR.'/count-per-day/geoip', 0777);
419
+ }
420
+
421
+ /**
422
+ * calls widget class
423
+ */
424
+ function register_widgets()
425
+ {
426
+ register_widget('CountPerDay_Widget');
427
+ }
428
+
429
+ /**
430
+ * shows debug infos
431
+ */
432
+ function showQueries()
433
+ {
434
+ global $wpdb, $cpd_path, $cpd_version;
435
+ echo '<div style="position:absolute;margin:10px;padding:10px;border:1px red solid">
436
+ <b>Count per Day - DEBUG: '.round($this->queries[0], 3).' s</b><ol>'."\n";
437
+ echo '<li>'
438
+ .'<b>Server:</b> '.$_SERVER['SERVER_SOFTWARE'].'<br/>'
439
+ .'<b>PHP:</b> '.phpversion().'<br/>'
440
+ .'<b>mySQL Server:</b> '.mysql_get_server_info($wpdb->dbh).'<br/>'
441
+ .'<b>mySQL Client:</b> '.mysql_get_client_info().'<br/>'
442
+ .'<b>WordPress:</b> '.get_bloginfo('version').'<br/>'
443
+ .'<b>Count per Day:</b> '.$cpd_version.'<br/>'
444
+ .'<b>Time for Count per Day:</b> '.date_i18n('Y-m-d H:i').'<br/>'
445
+ .'<b>URL:</b> '.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'<br/>'
446
+ .'<b>Referrer:</b> '.(isset($_SERVER['HTTP_REFERER']) ? htmlentities($_SERVER['HTTP_REFERER']) : '')
447
+ .'</li>';
448
+ echo "\n<li><b>POST:</b><br/>\n";
449
+ var_dump($_POST);
450
+ echo '</li>';
451
+ echo "\n<li><b>SESSION:</b><br/>\n";
452
+ var_dump($_SESSION);
453
+ echo '</li>';
454
+ echo "\n<li><b>Table:</b><br /><b>$wpdb->cpd_counter</b>:\n";
455
+ $res = $this->mysqlQuery('rows', "SHOW FIELDS FROM `$wpdb->cpd_counter`", 'showFields' );
456
+ foreach ($res as $c)
457
+ echo '<span style="color:blue">'.$c->Field.'</span> = '.$c->Type.' &nbsp; ';
458
+ echo "\n</li>";
459
+ echo "\n<li><b>Options:</b><br />\n";
460
+ foreach ( $this->options as $k=>$v )
461
+ if ( $k != 'bots') // hoster restrictions
462
+ echo "$k = $v<br />\n";
463
+ echo "</li>";
464
+ foreach($this->queries as $q)
465
+ if ($q != $this->queries[0])
466
+ echo "\n<li>$q</li>";
467
+ echo "</ol>\n";
468
+ ?>
469
+ <p>GeoIP:
470
+ d_ir=<?php echo substr(decoct(fileperms($cpd_path.'geoip/')), -3) ?>
471
+ f_ile=<?php echo (is_file($cpd_path.'geoip/GeoIP.dat')) ? substr(decoct(fileperms($cpd_path.'geoip/GeoIP.dat')), -3) : '-'; ?>
472
+ f_open=<?php echo (function_exists('fopen')) ? 'true' : 'false' ?>
473
+ g_zopen=<?php echo (function_exists('gzopen')) ? 'true' : 'false' ?>
474
+ a_llow_url_fopen=<?php echo (ini_get('allow_url_fopen')) ? 'true' : 'false' ?>
475
+ </p>
476
+ <?php
477
+ echo '</div>';
478
+ }
479
+
480
+ /**
481
+ * adds style sheet to admin header
482
+ */
483
+ function addCss()
484
+ {
485
+ global $text_direction;
486
+ echo "\n".'<link rel="stylesheet" href="'.$this->dir.'/counter.css" type="text/css" />'."\n";
487
+ if ( $text_direction == 'rtl' )
488
+ echo "\n".'<link rel="stylesheet" href="'.$this->dir.'/counter-rtl.css" type="text/css" />'."\n";
489
+ // thickbox style here because add_thickbox() breaks RTL in he_IL
490
+ if ( strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/') !== false )
491
+ echo '<link rel="stylesheet" href="'.get_bloginfo('wpurl').'/wp-includes/js/thickbox/thickbox.css" type="text/css" />'."\n";
492
+ }
493
+
494
+ /**
495
+ * adds javascript to admin header
496
+ */
497
+ function addJS()
498
+ {
499
+ echo '<!--[if IE]><script type="text/javascript" src="'.$this->dir.'/js/excanvas.min.js"></script><![endif]-->'."\n";
500
+ }
501
+
502
+ /**
503
+ * adds ajax script to count cached posts
504
+ */
505
+ function addAjaxScript()
506
+ {
507
+ $this->getPostID();
508
+ echo <<< JSEND
509
+ <script type="text/javascript">
510
+ // Count per Day
511
+ //<![CDATA[
512
+ jQuery(document).ready( function($)
513
+ {
514
+ jQuery.get('{$this->dir}/ajax.php?f=count&page={$this->page}', function(text)
515
+ {
516
+ var cpd_funcs = text.split('|');
517
+ for(var i = 0; i < cpd_funcs.length; i++)
518
+ {
519
+ var cpd_daten = cpd_funcs[i].split('===');
520
+ var cpd_fields = document.getElementById('cpd_number_' + cpd_daten[0].toLowerCase());
521
+ cpd_fields.innerHTML = cpd_daten[1];
522
+ }
523
+ });
524
+ } );
525
+ //]]>
526
+ </script>
527
+ JSEND;
528
+
529
+ // name not valide in span or div...
530
+ // var cpd_fields = document.getElementsByName('cpd_number_' + cpd_daten[0].toLowerCase());
531
+ // for(var x = 0; x < cpd_fields.length; x++)
532
+ // {
533
+ // cpd_fields[x].innerHTML = cpd_daten[1];
534
+ // }
535
+ }
536
+
537
+ /**
538
+ * deletes spam in table, if you add new bot pattern you can clean the db
539
+ */
540
+ function cleanDB()
541
+ {
542
+ global $wpdb;
543
+
544
+ // get trimed bot array
545
+ function trim_value(&$value) { $value = trim($value); }
546
+ $bots = explode( "\n", $this->options['bots'] );
547
+ array_walk($bots, 'trim_value');
548
+
549
+ $rows_before = $this->mysqlQuery('count', "SELECT COUNT(*) FROM $wpdb->cpd_counter", 'cleanDB '.__LINE__);
550
+
551
+ // delete by ip
552
+ foreach( $bots as $ip )
553
+ if ( ip2long($ip) !== false )
554
+ $this->mysqlQuery('', "DELETE FROM $wpdb->cpd_counter WHERE INET_NTOA(ip) LIKE '".$ip."%%", 'clenaDB_ip'.__LINE__);
555
+
556
+ // delete by client
557
+ foreach ($bots as $bot)
558
+ $this->mysqlQuery('', "DELETE FROM $wpdb->cpd_counter WHERE client LIKE '%%".$bot."%%'", 'cleanDB_client'.__LINE__);
559
+
560
+ // delete if a previously countered page was deleted
561
+ $this->mysqlQuery('', "DELETE FROM $wpdb->cpd_counter WHERE page NOT IN ( SELECT id FROM $wpdb->posts) AND page > 0", 'cleanDB_delPosts'.__LINE__);
562
+
563
+ $rows_after = $this->mysqlQuery('count', "SELECT COUNT(*) FROM $wpdb->cpd_counter", 'cleanDB '.__LINE__);
564
+ return $rows_before - $rows_after;
565
+ }
566
+
567
+ /**
568
+ * adds menu entry to backend
569
+ * @param string $content WP-"Content"
570
+ */
571
+ function menu($content)
572
+ {
573
+ global $cpd_dir_name;
574
+ if (function_exists('add_options_page'))
575
+ {
576
+ $menutitle = '<img src="'.$this->img('cpd_menu.gif').'" alt="/" style="width:9px;height:12px;" /> Count per Day';
577
+ add_options_page('CountPerDay', $menutitle, 'manage_options', $cpd_dir_name.'/counter-options.php') ;
578
+ }
579
+ }
580
+
581
+ /**
582
+ * adds an "settings" link to the plugins page
583
+ */
584
+ function pluginActions($links, $file)
585
+ {
586
+ global $cpd_dir_name;
587
+ if( $file == $cpd_dir_name.'/counter.php'
588
+ && strpos( $_SERVER['SCRIPT_NAME'], '/network/') === false ) // not on network plugin page
589
+ {
590
+ $link = '<a href="options-general.php?page='.$cpd_dir_name.'/counter-options.php">'.__('Settings').'</a>';
591
+ array_unshift( $links, $link );
592
+ }
593
+ return $links;
594
+ }
595
+
596
+ /**
597
+ * combines the options to one array, update from previous versions
598
+ */
599
+ function updateOptions()
600
+ {
601
+ global $cpd_version;
602
+
603
+ $o = get_option('count_per_day', array());
604
+ $this->options = array('version' => $cpd_version);
605
+ $odefault = array(
606
+ 'onlinetime' => 300,
607
+ 'user' => 0,
608
+ 'user_level' => 0,
609
+ 'autocount' => 1,
610
+ 'bots' => "bot\nspider\nsearch\ncrawler\nask.com\nvalidator\nsnoopy\nsuchen.de\nsuchbaer.de\nshelob\nsemager\nxenu\nsuch_de\nia_archiver\nMicrosoft URL Control\nnetluchs",
611
+ 'dashboard_posts' => 20,
612
+ 'dashboard_last_posts' => 20,
613
+ 'dashboard_last_days' => 7,
614
+ 'show_in_lists' => 1,
615
+ 'chart_days' => 60,
616
+ 'chart_height' => 100,
617
+ 'countries' => 20,
618
+ 'startdate' => '',
619
+ 'startcount' => '',
620
+ 'startreads' => '',
621
+ 'anoip' => 0,
622
+ 'massbotlimit' => 25,
623
+ 'clients' => 'Firefox, MSIE, Chrome, Safari, Opera',
624
+ 'ajax' => 0,
625
+ 'debug' => 0,
626
+ 'referers' => 1,
627
+ 'referers_cut' => 0,
628
+ 'localref' => 1,
629
+ 'dashboard_referers' => 20,
630
+ 'referers_last_days' => 7,
631
+ 'no_front_css' => 0,
632
+ 'whocansee' => 'publish_posts',
633
+ 'backup_part' => 10000
634
+ );
635
+ foreach ($odefault as $k => $v)
636
+ $this->options[$k] = (isset($o[$k])) ? $o[$k] : $v;
637
+ update_option('count_per_day', $this->options);
638
+ }
639
+
640
+ /**
641
+ * adds widget to dashboard page
642
+ */
643
+ function dashboardWidgetSetup()
644
+ {
645
+ wp_add_dashboard_widget( 'cpdDashboardWidget', 'Count per Day', array(&$this,'dashboardWidget') );
646
+ }
647
+
648
+ /**
649
+ * add counter column to page/post lists
650
+ */
651
+ function cpdColumn($defaults)
652
+ {
653
+ if ( $this->options['show_in_lists'] )
654
+ $defaults['cpd_reads'] = '<img src="'.$this->img('cpd_menu.gif').'" alt="'.__('Reads', 'cpd').'" title="'.__('Reads', 'cpd').'" style="width:9px;height:12px;" />';
655
+ return $defaults;
656
+ }
657
+
658
+ /**
659
+ * adds content to the counter column
660
+ */
661
+ function cpdColumnContent($column_name, $id = 0)
662
+ {
663
+ global $wpdb;
664
+ if( $column_name == 'cpd_reads' )
665
+ echo $this->mysqlQuery('count', "SELECT COUNT(*) FROM $wpdb->cpd_counter WHERE page='$id'", 'cpdColumn_'.$id.'_'.__LINE__);
666
+ }
667
+
668
+ /**
669
+ * gets image recource with given name
670
+ */
671
+ function img( $r )
672
+ {
673
+ return trailingslashit( $this->dir ).'img/'.$r;
674
+ }
675
+
676
+ /**
677
+ * sets columns on dashboard page
678
+ */
679
+ function screenLayoutColumns($columns, $screen)
680
+ {
681
+ if ($screen == $this->pagehook)
682
+ $columns[$this->pagehook] = 4;
683
+ return $columns;
684
+ }
685
+
686
+ /**
687
+ * extends the admin menu
688
+ */
689
+ function setAdminMenu()
690
+ {
691
+ $menutitle = '<img src="'.$this->img('cpd_menu.gif').'" alt="" style="width:12px;height:12px;" /> Count per Day';
692
+ $this->pagehook = add_submenu_page('index.php', 'CountPerDay', $menutitle, $this->options['whocansee'], CPD_METABOX, array(&$this, 'onShowPage'));
693
+ add_action('load-'.$this->pagehook, array(&$this, 'onLoadPage'));
694
+ }
695
+
696
+ /**
697
+ * backlink to Plugin homepage
698
+ */
699
+ function cpdInfo()
700
+ {
701
+ global $cpd_version;
702
+ $t = '<span style="white-space:nowrap">'.date_i18n('Y-m-d H:i').'</span>';
703
+ echo '<p style="margin:0">Count per Day: <code>'.$cpd_version.'</code><br/>';
704
+ printf(__('Time for Count per Day: <code>%s</code>.', 'cpd'), $t);
705
+ echo '<br />'.__('Bug? Problem? Question? Hint? Praise?', 'cpd').' ';
706
+ printf(__('Write a comment on the <a href="%s">plugin page</a>.', 'cpd'), 'http://www.tomsdimension.de/wp-plugins/count-per-day');
707
+ echo '<br />'.__('License').': <a href="http://www.tomsdimension.de/postcards">Postcardware :)</a>';
708
+ echo '<br /><a href="'.$this->dir.'/readme.txt?KeepThis=true&amp;TB_iframe=true" title="Count per Day - Readme.txt" class="thickbox"><strong>Readme.txt</strong></a></p>';
709
+ }
710
+
711
+ /**
712
+ * function calls from metabox default parameters
713
+ */
714
+ function getMostVisitedPostsMeta() { $this->getMostVisitedPosts(); }
715
+ function getUserPerPostMeta() { $this->getUserPerPost(); }
716
+ function getVisitedPostsOnDayMeta() { $this->getVisitedPostsOnDay(0, 100); }
717
+ function dashboardChartMeta() { $this->dashboardChart(0, false, false); }
718
+ function dashboardChartVisitorsMeta() { $this->dashboardChartVisitors(0, false, false); }
719
+ function getCountriesMeta() { $this->getCountries(0, false); }
720
+ function getCountriesVisitorsMeta() { $this->getCountries(0, false, true); }
721
+ function getReferersMeta() { $this->getReferers(0, false, 0); }
722
+ function getUserOnlineMeta() { $this->getUserOnline(false, true); }
723
+ function getUserPerMonthMeta() { $this->getUserPerMonth(); }
724
+ function getReadsPerMonthMeta() { $this->getReadsPerMonth(); }
725
+
726
+ /**
727
+ * will be executed if wordpress core detects this page has to be rendered
728
+ */
729
+ function onLoadPage()
730
+ {
731
+ global $cpd_geoip;
732
+ // needed javascripts
733
+ wp_enqueue_script('common');
734
+ wp_enqueue_script('wp-lists');
735
+ wp_enqueue_script('postbox');
736
+
737
+ // add the metaboxes
738
+ add_meta_box('reads_at_all', '<span class="cpd_icon cpd_summary">&nbsp;</span> '.__('Total visitors', 'cpd'), array(&$this,'dashboardReadsAtAll'), $this->pagehook, 'cpdrow1', 'core');
739
+ add_meta_box('user_online', '<span class="cpd_icon cpd_online">&nbsp;</span> '.__('Visitors online', 'cpd'), array(&$this,'getUserOnlineMeta'), $this->pagehook, 'cpdrow1', 'default');
740
+ add_meta_box('user_per_month', '<span class="cpd_icon cpd_user">&nbsp;</span> '.__('Visitors per month', 'cpd'), array(&$this,'getUserPerMonthMeta'), $this->pagehook, 'cpdrow2', 'default');
741
+ add_meta_box('reads_per_month', '<span class="cpd_icon cpd_reads">&nbsp;</span> '.__('Reads per month', 'cpd'), array(&$this,'getReadsPerMonthMeta'), $this->pagehook, 'cpdrow3', 'default');
742
+ add_meta_box('reads_per_post', '<span class="cpd_icon cpd_post">&nbsp;</span> '.__('Visitors per post', 'cpd'), array(&$this,'getUserPerPostMeta'), $this->pagehook, 'cpdrow3', 'default');
743
+ add_meta_box('last_reads', '<span class="cpd_icon cpd_calendar">&nbsp;</span> '.__('Latest Counts', 'cpd'), array(&$this,'getMostVisitedPostsMeta'), $this->pagehook, 'cpdrow4', 'default');
744
+ add_meta_box('day_reads', '<span class="cpd_icon cpd_day">&nbsp;</span> '.__('Visitors per day', 'cpd'), array(&$this,'getVisitedPostsOnDayMeta'), $this->pagehook, 'cpdrow4', 'default');
745
+ add_meta_box('cpd_info', '<span class="cpd_icon cpd_help">&nbsp;</span> '.__('Plugin'), array(&$this,'cpdInfo'), $this->pagehook, 'cpdrow1', 'low');
746
+ if ($this->options['referers'])
747
+ {
748
+ add_meta_box('browsers', '<span class="cpd_icon cpd_computer">&nbsp;</span> '.__('Browsers', 'cpd'), array(&$this,'getClients'), $this->pagehook, 'cpdrow2', 'default');
749
+ add_meta_box('referers', '<span class="cpd_icon cpd_referrer">&nbsp;</span> '.__('Referrer', 'cpd'), array(&$this,'getReferersMeta'), $this->pagehook, 'cpdrow3', 'default');
750
+ }
751
+ if ($cpd_geoip)
752
+ {
753
+ add_meta_box('countries', '<span class="cpd_icon cpd_reads">&nbsp;</span> '.__('Reads per Country', 'cpd'), array(&$this,'getCountriesMeta'), $this->pagehook, 'cpdrow2', 'default');
754
+ add_meta_box('countries2', '<span class="cpd_icon cpd_user">&nbsp;</span> '.__('Visitors per Country', 'cpd'), array(&$this,'getCountriesVisitorsMeta'), $this->pagehook, 'cpdrow2', 'default');
755
+ }
756
+ }
757
+
758
+ /**
759
+ * creates dashboard page
760
+ */
761
+ function onShowPage()
762
+ {
763
+ global $screen_layout_columns, $count_per_day;
764
+ if ( empty($screen_layout_columns) )
765
+ $screen_layout_columns = 4;
766
+ $data = '';
767
+ ?>
768
+ <div id="cpd-metaboxes" class="wrap">
769
+ <h2><img src="<?php echo $this->img('cpd_menu.gif') ?>" alt="" style="width:24px;height:24px" /> Count per Day - <?php _e('Statistics', 'cpd') ?></h2>
770
+ <?php
771
+ wp_nonce_field('cpd-metaboxes');
772
+ wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
773
+ wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
774
+ $css = 'style="width:'.round(98 / $screen_layout_columns, 1).'%;"';
775
+ $this->getFlotChart();
776
+ ?>
777
+ <div id="dashboard-widgets" class="metabox-holder cpd-dashboard">
778
+ <div class="postbox-container" <?php echo $css; ?>><?php do_meta_boxes($this->pagehook, 'cpdrow1', $data); ?></div>
779
+ <div class="postbox-container" <?php echo $css; ?>><?php do_meta_boxes($this->pagehook, 'cpdrow2', $data); ?></div>
780
+ <div class="postbox-container" <?php echo $css; ?>><?php do_meta_boxes($this->pagehook, 'cpdrow3', $data); ?></div>
781
+ <div class="postbox-container" <?php echo $css; ?>><?php do_meta_boxes($this->pagehook, 'cpdrow4', $data); ?></div>
782
+ <br class="clear"/>
783
+ </div>
784
+ </div>
785
+ <script type="text/javascript">
786
+ //<![CDATA[
787
+ jQuery(document).ready( function($) {
788
+ $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
789
+ postboxes.add_postbox_toggles('<?php echo $this->pagehook; ?>');
790
+ });
791
+ //]]>
792
+ </script>
793
+ <?php
794
+ }
795
+
796
+ /**
797
+ * adds some shortcodes to use functions in frontend
798
+ */
799
+ function addShortcodes()
800
+ {
801
+ add_shortcode('CPD_READS_THIS', array(&$this,'shortShow'));
802
+ add_shortcode('CPD_READS_TOTAL', array(&$this,'shortReadsTotal'));
803
+ add_shortcode('CPD_READS_TODAY', array(&$this,'shortReadsToday'));
804
+ add_shortcode('CPD_READS_YESTERDAY', array(&$this,'shortReadsYesterday'));
805
+ add_shortcode('CPD_READS_LAST_WEEK', array(&$this,'shortReadsLastWeek'));
806
+ add_shortcode('CPD_READS_PER_MONTH', array(&$this,'shortReadsPerMonth'));
807
+ add_shortcode('CPD_READS_THIS_MONTH', array(&$this,'shortReadsThisMonth'));
808
+ add_shortcode('CPD_VISITORS_TOTAL', array(&$this,'shortUserAll'));
809
+ add_shortcode('CPD_VISITORS_ONLINE', array(&$this,'shortUserOnline'));
810
+ add_shortcode('CPD_VISITORS_TODAY', array(&$this,'shortUserToday'));
811
+ add_shortcode('CPD_VISITORS_YESTERDAY', array(&$this,'shortUserYesterday'));
812
+ add_shortcode('CPD_VISITORS_LAST_WEEK', array(&$this,'shortUserLastWeek'));
813
+ add_shortcode('CPD_VISITORS_THIS_MONTH', array(&$this,'shortUserThisMonth'));
814
+ add_shortcode('CPD_VISITORS_PER_DAY', array(&$this,'shortUserPerDay'));
815
+ add_shortcode('CPD_FIRST_COUNT', array(&$this,'shortFirstCount'));
816
+ add_shortcode('CPD_CLIENTS', array(&$this,'shortClients'));
817
+ add_shortcode('CPD_VISITORS_PER_MONTH', array(&$this,'shortUserPerMonth'));
818
+ add_shortcode('CPD_VISITORS_PER_POST', array(&$this,'shortUserPerPost'));
819
+ add_shortcode('CPD_COUNTRIES', array(&$this,'shortCountries'));
820
+ add_shortcode('CPD_MOST_VISITED_POSTS', array(&$this,'shortMostVisitedPosts'));
821
+ add_shortcode('CPD_REFERERS', array(&$this,'shortReferers'));
822
+ add_shortcode('CPD_POSTS_ON_DAY', array(&$this,'shortPostsOnDay'));
823
+ add_shortcode('CPD_MAP', array(&$this,'shortShowMap'));
824
+ add_shortcode('CPD_DAY_MOST_READS', array(&$this,'shortDayWithMostReads'));
825
+ add_shortcode('CPD_DAY_MOST_USERS', array(&$this,'shortDayWithMostUsers'));
826
+ }
827
+ function shortShow() { return $this->show('', '', false, false); }
828
+ function shortReadsTotal() { return $this->getReadsAll(true); }
829
+ function shortReadsToday() { return $this->getReadsToday(true); }
830
+ function shortReadsYesterday() { return $this->getReadsYesterday(true); }
831
+ function shortReadsThisMonth() { return $this->getReadsThisMonth(true); }
832
+ function shortReadsLastWeek() { return $this->getReadsLastWeek(true); }
833
+ function shortReadsPerMonth() { return $this->getReadsPerMonth(true, true); }
834
+ function shortUserAll() { return $this->getUserAll(true); }
835
+ function shortUserOnline() { return $this->getUserOnline(false, false, true); }
836
+ function shortUserToday() { return $this->getUserToday(true); }
837
+ function shortUserYesterday() { return $this->getUserYesterday(true); }
838
+ function shortUserLastWeek() { return $this->getUserLastWeek(true); }
839
+ function shortUserThisMonth() { return $this->getUserThisMonth(true); }
840
+ function shortUserPerDay() { return $this->getUserPerDay($this->options['dashboard_last_days'], true); }
841
+ function shortFirstCount() { return $this->getFirstCount(true); }
842
+ function shortClients() { return $this->getClients(true); }
843
+ function shortUserPerMonth() { return $this->getUserPerMonth(true, true); }
844
+ function shortUserPerPost() { return $this->getUserPerPost(0, true, true); }
845
+ function shortCountries() { return $this->getCountries(0, true, false, true); }
846
+ function shortMostVisitedPosts(){ return $this->getMostVisitedPosts(0, 0, true, false, true); }
847
+ function shortReferers() { return $this->getReferers(0, true, 0); }
848
+ function shortDayWithMostReads(){ return $this->getDayWithMostReads(true, true); }
849
+ function shortDayWithMostUsers(){ return $this->getDayWithMostUsers(true, true); }
850
+ function shortPostsOnDay( $atts )
851
+ {
852
+ extract( shortcode_atts( array(
853
+ 'date' => 0,
854
+ 'limit' => 0
855
+ ), $atts) );
856
+ return $this->getVisitedPostsOnDay( $date, $limit, false, false, true, true );
857
+ }
858
+ function shortShowMap( $atts )
859
+ {
860
+ extract( shortcode_atts( array(
861
+ 'width' => 500,
862
+ 'height' => 340,
863
+ 'what' => 'reads',
864
+ 'min' => 0
865
+ ), $atts) );
866
+ return $this->getMap( $what, $width, $height, $min );
867
+ }
868
+
869
+ /**
870
+ * adds charts to lists on dashboard
871
+ * @param string $id HTML-id of the DIV
872
+ * @param array $data data
873
+ * @param string $html given list code to add the chart
874
+ */
875
+ function includeChartJS( $id, $data, $html )
876
+ {
877
+ $d = array_reverse($data);
878
+ $d = '[['.implode(',', $d).']]';
879
+ $code = '<div id="'.$id.'" class="cpd-list-chart" style="width:100%;height:50px"></div>
880
+ <script type="text/javascript">
881
+ //<![CDATA[
882
+ if (jQuery("#'.$id.'").width() > 0)
883
+ jQuery(function(){jQuery.plot(jQuery("#'.$id.'"),'.$d.',{series:{lines:{fill:true,lineWidth:1}},colors:["red"],grid:{show:false}});});
884
+ //]]>
885
+ </script>
886
+ '.$html;
887
+ return $code;
888
+ }
889
+
890
+ /**
891
+ * get mass bots
892
+ */
893
+ function getMassBots( $limit )
894
+ {
895
+ global $wpdb;
896
+ $sql = $wpdb->prepare("
897
+ SELECT t.id, t.ip AS longip, INET_NTOA(t.ip) AS ip, t.date, t.posts, c.client
898
+ FROM ( SELECT id, ip, date, count(*) posts
899
+ FROM $wpdb->cpd_counter
900
+ GROUP BY ip, date
901
+ ORDER BY posts DESC ) AS t
902
+ LEFT JOIN $wpdb->cpd_counter c
903
+ ON c.id = t.id
904
+ WHERE posts > %d", (int) $limit );
905
+ return $this->mysqlQuery('rows', $sql, 'getMassBots '.__LINE__);
906
+ }
907
+
908
+ /**
909
+ * backup the counter table to wp-content dir, gz-compressed if possible
910
+ */
911
+ function backup()
912
+ {
913
+ global $wpdb;
914
+
915
+ $t = $wpdb->cpd_counter;
916
+
917
+ $name = '/'.$t.'_backup_'.date_i18n('Y-m-d_H-i-s').'.sql';
918
+
919
+ $gz = ( function_exists('gzopen') && is_writable(WP_CONTENT_DIR) ) ? 1 : 0;
920
+ if ($gz) $name .= '.gz';
921
+
922
+ // wp-content or tempdir?
923
+ $path = (is_writable(WP_CONTENT_DIR)) ? WP_CONTENT_DIR.$name : tempnam('', $name);
924
+
925
+ // open file
926
+ $f = ($gz) ? gzopen($path,'w9') : fopen($path,'w');
927
+
928
+ if (!$f) :
929
+ echo '<div class="error"><p>'.__('Backup failed! Cannot open file', 'cpd').' '.$path.'.</p></div>';
930
+ else :
931
+ set_time_limit(600);
932
+
933
+ // write backup to file
934
+ $d = "DROP TABLE IF EXISTS `$t`;\n";
935
+ ($gz) ? gzwrite($f, $d) : fwrite($f, $d);
936
+ if ( $res = $this->mysqlQuery('rows', "SHOW CREATE TABLE `$t`", 'backupCollect'.__LINE__) )
937
+ {
938
+ // create table command
939
+ $create = $res[0];
940
+ $create->{'Create Table'} .= ';';
941
+ $line = str_replace("\n", "", $create->{'Create Table'})."\n";
942
+ ($gz) ? gzwrite($f, $line) : fwrite($f, $line);
943
+ $line = false;
944
+
945
+ // number of entries
946
+ $entries = $this->mysqlQuery('count', "SELECT 1 FROM `$t`", 'backupCollect'.__LINE__);
947
+ $part = (int) $this->options['backup_part'];
948
+ if (empty($part))
949
+ $part = 10000;
950
+
951
+ // show progress
952
+ echo '<div id="cpd_progress" class="updated"><p>'.sprintf(__('Backup of %s entries in progress. Every point complies %s entries.', 'cpd'), $entries, $part).'<br />';
953
+ $this->flush_buffers();
954
+
955
+ // get data
956
+ for ($i = 0; $i <= $entries; $i = $i + $part)
957
+ {
958
+ if ( $data = $this->mysqlQuery('rows', "SELECT * FROM `$t` LIMIT $i, $part", 'backupCollect'.__LINE__) )
959
+ {
960
+ foreach ($data as $row)
961
+ {
962
+ $row = (array) $row;
963
+
964
+ // columns names
965
+ if (empty($cols))
966
+ $cols = array_keys($row);
967
+
968
+ // create line
969
+ if (!$line)
970
+ {
971
+ $line = "INSERT INTO `$t` (`".implode('`,`',$cols)."`) VALUES\n";
972
+ if (isset($v))
973
+ $line .= "$v\n";
974
+ }
975
+
976
+ // add values
977
+ $v = '';
978
+ foreach ($row as $val)
979
+ $v .= "'".mysql_real_escape_string($val)."',";
980
+ $v = '('.substr($v,0,-1).'),';
981
+
982
+ if ( strlen($line) < 50000 - strlen($v) )
983
+ $line .= "$v\n";
984
+ else
985
+ {
986
+ $line = substr($line,0,-2).";\n";
987
+ ($gz) ? gzwrite($f, $line) : fwrite($f, $line);
988
+ $line = false;
989
+ }
990
+ }
991
+ }
992
+ echo '| ';
993
+ $this->flush_buffers();
994
+ }
995
+
996
+ // write leftover
997
+ if ($line)
998
+ {
999
+ $line = substr($line,0,-2).";\n";
1000
+ ($gz) ? gzwrite($f, $line) : fwrite($f, $line);
1001
+ }
1002
+
1003
+ // reindex command
1004
+ $line = "REPAIR TABLE `$t`;";
1005
+ ($gz) ? gzwrite($f, $line) : fwrite($f, $line);
1006
+
1007
+ echo '</p></div>';
1008
+
1009
+ // hide progress
1010
+ echo '<script type="text/javascript">'
1011
+ .'document.getElementById("cpd_progress").style.display="none";'
1012
+ .'</script>'."\n";
1013
+ $this->flush_buffers();
1014
+ }
1015
+
1016
+ // close file
1017
+ ($gz) ? gzclose($f) : fclose($f);
1018
+
1019
+ // save collection and options
1020
+ $oname = '/count_per_day_options_'.date_i18n('Y-m-d_H-i-s').'.txt';
1021
+ if ($gz) $oname .= '.gz';
1022
+ $opath = (is_writable(WP_CONTENT_DIR)) ? WP_CONTENT_DIR.$oname : tempnam('', $oname);
1023
+ $f = ($gz) ? gzopen($opath,'w9') : fopen($opath,'w');
1024
+
1025
+ foreach (array('count_per_day', 'count_per_day_summary', 'count_per_day_collected', 'count_per_day_posts', 'count_per_day_notes') as $o)
1026
+ {
1027
+ $c = get_option($o);
1028
+ $line = "=== begin $o ===\n".serialize($c)."\n=== end $o ===\n\n";
1029
+ ($gz) ? gzwrite($f, $line) : fwrite($f, $line);
1030
+ }
1031
+ ($gz) ? gzclose($f) : fclose($f);
1032
+
1033
+ // message
1034
+ echo '<div class="updated"><p>';
1035
+ if ( strpos($path, WP_CONTENT_DIR) === false )
1036
+ {
1037
+ // show tempfile in textarea
1038
+ $content = file_get_contents($path);
1039
+ _e('Your wp-content directory is not writable. But you can copy the content of this box to a plain text file.', 'cpd');
1040
+ echo '<textarea style="width:100%;height:200px">'.$content.'</textarea>';
1041
+ }
1042
+ else
1043
+ {
1044
+ // show link
1045
+ echo sprintf(__('Backup of counter table saved in %s.', 'cpd'),
1046
+ '<a href="'.content_url().$name.'">'.content_url().$name.'</a>').'<br/>';
1047
+ echo sprintf(__('Backup of counter options and collection saved in %s.', 'cpd'),
1048
+ '<a href="'.content_url().$oname.'">'.content_url().$oname.'</a>');
1049
+ }
1050
+ echo '</p></div>';
1051
+ endif;
1052
+ $this->flush_buffers();
1053
+ }
1054
+
1055
+ function addCollectionToCountries( $visitors, $limit = false )
1056
+ {
1057
+ global $wpdb;
1058
+ if ( $visitors )
1059
+ // visitors
1060
+ $sql = "SELECT country, COUNT(*) c
1061
+ FROM ( SELECT country, COUNT(*) c
1062
+ FROM $wpdb->cpd_counter
1063
+ WHERE ip > 0
1064
+ GROUP BY country, date, ip ) as t
1065
+ GROUP BY country
1066
+ ORDER BY c desc";
1067
+ else
1068
+ // reads
1069
+ $sql = "SELECT country, COUNT(*) c
1070
+ FROM $wpdb->cpd_counter
1071
+ WHERE ip > 0
1072
+ GROUP BY country
1073
+ ORDER BY c DESC";
1074
+ $res = $this->mysqlQuery('rows', $sql, 'getCountries '.__LINE__);
1075
+
1076
+ foreach ( $res as $r )
1077
+ $temp[$r->country] = $r->c;
1078
+
1079
+ // add collection values
1080
+ $coll = get_option('count_per_day_collected');
1081
+ if ($coll)
1082
+ {
1083
+ foreach ($coll as $month)
1084
+ {
1085
+ $countries = explode(';', $month['country']);
1086
+ // country:reads|visitors
1087
+ foreach ($countries as $v)
1088
+ {
1089
+ if (!empty($v))
1090
+ {
1091
+ $x = explode(':', $v);
1092
+ $country = $x[0];
1093
+ $y = explode('|', $x[1]);
1094
+ $value = ($visitors) ? $y[1] : $y[0];
1095
+ if (isset($temp[$country]))
1096
+ $temp[$country] += $value;
1097
+ else
1098
+ $temp[$country] = $value;
1099
+ }
1100
+ }
1101
+ }
1102
+ }
1103
+
1104
+ // max $limit biggest values
1105
+ $keys = array_keys($temp);
1106
+ array_multisort($temp, SORT_NUMERIC, SORT_DESC, $keys);
1107
+ if ($limit)
1108
+ $temp = array_slice($temp, 0, $limit);
1109
+
1110
+ return $temp;
1111
+ }
1112
+
1113
+ /**
1114
+ * flush buffers, the hard way ;)
1115
+ */
1116
+ function flush_buffers()
1117
+ {
1118
+ @ob_end_flush();
1119
+ @ob_flush();
1120
+ @flush();
1121
+ @ob_start();
1122
+ }
1123
+
1124
+ /* get collected data */
1125
+
1126
+ function getLastCollectedMonth()
1127
+ {
1128
+ $s = get_option('count_per_day_summary');
1129
+ return (isset($s['lastcollectedmonth'])) ? $s['lastcollectedmonth'] : false;
1130
+ }
1131
+
1132
+ function getCollectedReads()
1133
+ {
1134
+ $s = get_option('count_per_day_summary');
1135
+ return (isset($s['reads'])) ? $s['reads'] : 0;
1136
+ }
1137
+
1138
+ function getCollectedUsers()
1139
+ {
1140
+ $s = get_option('count_per_day_summary');
1141
+ return (isset($s['users'])) ? $s['users'] : 0;
1142
+ }
1143
+
1144
+ function getCollectedDayMostReads()
1145
+ {
1146
+ $s = get_option('count_per_day_summary');
1147
+ return (isset($s['mostreads'])) ? $s['mostreads'] : 0;
1148
+ }
1149
+
1150
+ function getCollectedDayMostUsers()
1151
+ {
1152
+ $s = get_option('count_per_day_summary');
1153
+ return (isset($s['mostusers'])) ? $s['mostusers'] : 0;
1154
+ }
1155
+
1156
+ function getCollectedData( $month ) // YYYYMM
1157
+ {
1158
+ $d = get_option('count_per_day_collected');
1159
+ if ($d)
1160
+ {
1161
+ $m = $d[$month];
1162
+ unset($d);
1163
+ return $m;
1164
+ }
1165
+ }
1166
+
1167
+ /* update if new count is bigger than collected */
1168
+
1169
+ function updateCollectedDayMostReads( $new )
1170
+ {
1171
+ $n = array ($new->date, $new->count);
1172
+ $s = get_option('count_per_day_summary', array());
1173
+ if ( empty($s['mostreads']) || $n[1] > $s['mostreads'][1] )
1174
+ $s['mostreads'] = $n;
1175
+ update_option('count_per_day_summary', $s);
1176
+ return $s['mostreads'];
1177
+ }
1178
+
1179
+ function updateCollectedDayMostUsers( $new )
1180
+ {
1181
+ $n = array ($new->date, $new->count);
1182
+ $s = get_option('count_per_day_summary', array());
1183
+ if ( empty($s['mostusers']) || $n[1] > $s['mostusers'][1] )
1184
+ $s['mostusers'] = $n;
1185
+ update_option('count_per_day_summary', $s);
1186
+ return $s['mostusers'];
1187
+ }
1188
+
1189
+ /**
1190
+ * sets first date in summary
1191
+ */
1192
+ function updateFirstCount()
1193
+ {
1194
+ global $wpdb;
1195
+ // first day in summary
1196
+ $s = get_option('count_per_day_summary', array());
1197
+ if ( empty($s['firstcount']) )
1198
+ {
1199
+ // first day from table ORDER BY date LIMIT 1
1200
+ $res = $this->mysqlQuery('var', "SELECT MIN(date) FROM $wpdb->cpd_counter", 'getFirstCount'.__LINE__);
1201
+ if ($res)
1202
+ {
1203
+ $s['firstcount'] = $res;
1204
+ update_option('count_per_day_summary', $s);
1205
+ }
1206
+ }
1207
+ return $s['firstcount'];
1208
+ }
1209
+
1210
+ /**
1211
+ * returns table size in KB or MB
1212
+ */
1213
+ function getTableSize( $table )
1214
+ {
1215
+ $res = $this->mysqlQuery('rows', "SHOW TABLE STATUS");
1216
+ if ($res)
1217
+ foreach ($res as $row)
1218
+ if ($row->Name == $table)
1219
+ $size = $this->formatBytes( $row->Data_length + $row->Index_length );
1220
+ if ($size)
1221
+ return $size;
1222
+ }
1223
+
1224
+ function formatBytes( $size )
1225
+ {
1226
+ $units = array(' B', ' KB', ' MB', ' GB', ' TB');
1227
+ for ($i = 0; $size >= 1024 && $i < 4; $i++)
1228
+ $size /= 1024;
1229
+ return round($size, 2).$units[$i];
1230
+ }
1231
+
1232
+
1233
+ } // class
counter-options.php CHANGED
@@ -31,11 +31,13 @@ if(!empty($_POST['do']))
31
$count_per_day->options['debug'] = empty( $_POST['cpd_debug'] ) ? 0 : 1 ;
32
$count_per_day->options['localref'] = empty( $_POST['cpd_localref'] ) ? 0 : 1 ;
33
$count_per_day->options['referers'] = empty( $_POST['cpd_referers'] ) ? 0 : 1 ;
34
$count_per_day->options['dashboard_referers'] = $_POST['cpd_dashboard_referers'];
35
$count_per_day->options['referers_last_days'] = $_POST['cpd_referers_last_days'];
36
$count_per_day->options['chart_old'] = empty( $_POST['cpd_chart_old'] ) ? 0 : 1 ;
37
$count_per_day->options['no_front_css'] = empty( $_POST['cpd_no_front_css'] ) ? 0 : 1 ;
38
$count_per_day->options['whocansee'] = ($_POST['cpd_whocansee'] == 'custom') ? $_POST['cpd_whocansee_custom'] : $_POST['cpd_whocansee'];
39
40
if (empty($count_per_day->options['clients']))
41
$count_per_day->options['clients'] = 'Firefox, MSIE, Chrome, Safari, Opera';
@@ -45,105 +47,263 @@ if(!empty($_POST['do']))
45
46
update_option('count_per_day', $count_per_day->options);
47
48
- echo '<div id="message" class="updated fade"><p>'.__('Options updated', 'cpd').'</p></div>';
49
break;
50
51
- // update countries
52
- case 'cpd_countries' :
53
- if ( class_exists('CpdGeoIp') )
54
{
55
- $count_per_day->queries[] = 'cpd_countries - class "CpdGeoIp" exists';
56
- $rest = CpdGeoIp::updateDB();
57
- echo '<div id="message" class="updated fade">
58
- <form name="cpdcountries" method="post" action="'.$_SERVER['REQUEST_URI'].'">
59
- <p>'.sprintf(__('Countries updated. <b>%s</b> entries in %s without country left', 'cpd'), $rest, CPD_C_TABLE);
60
- if ( $rest > 100 )
61
- {
62
- // reload page per javascript until less than 100 entries without country
63
- echo '<input type="hidden" name="do" value="cpd_countries" />
64
- <input type="submit" name="updcon" value="'.__('update next', 'cpd').'" class="button" />';
65
- if ( !$count_per_day->options['debug'] )
66
- echo '<script type="text/javascript">document.cpdcountries.submit();</script>';
67
- }
68
- echo '</p>
69
- </form>
70
- </div>';
71
- if ( $rest > 100 )
72
- while (@ob_end_flush());
73
}
74
- else
75
- $count_per_day->queries[] = '<span style="color:red">cpd_countries - class "CpdGeoIp" NOT exists</span>';
76
- break;
77
-
78
- // download new GeoIP database
79
- case 'cpd_countrydb' :
80
- if ( class_exists('CpdGeoIp') )
81
{
82
- $count_per_day->getQuery("SELECT country FROM ".CPD_C_TABLE, 'geoip_select');
83
- if ((int) mysql_errno() == 1054)
84
- // add row 'country' to counter db
85
- $count_per_day->getQuery("ALTER TABLE `".CPD_C_TABLE."` ADD `country` CHAR(2) NOT NULL", 'geoip_alter');
86
-
87
- $result = CpdGeoIp::updateGeoIpFile();
88
- echo '<div id="message" class="updated fade"><p>'.$result.'</p></div>';
89
- if ( file_exists($cpd_path.'geoip/GeoIP.dat') )
90
- $cpd_geoip = 1;
91
}
92
- break;
93
94
- // delete massbots
95
- case 'cpd_delete_massbots' :
96
- if ( isset($_POST['limit']) )
97
- {
98
- $bots = $count_per_day->getMassBots($_POST['limit']);
99
- $sum = 0;
100
- while ( $row = mysql_fetch_array($bots) )
101
- {
102
- $count_per_day->getQuery("DELETE FROM ".CPD_C_TABLE." WHERE ip = INET_ATON('".$row['ip']."') AND date = '".$row['date']."'", 'deleteMassbots');
103
- $sum += $row['posts'];
104
- }
105
- if ( $sum )
106
- echo '<div id="message" class="updated fade"><p>'.sprintf(__('Mass Bots cleaned. %s counts deleted.', 'cpd'), $sum).'</p></div>';
107
- }
108
- break;
109
-
110
- // clean database
111
- case 'cpd_clean' :
112
- $rows = $count_per_day->cleanDB();
113
- echo '<div id="message" class="updated fade"><p>'.sprintf(__('Database cleaned. %s rows deleted.', 'cpd'), $rows).'</p></div>';
114
- break;
115
116
- // reset counter
117
- case 'cpd_reset' :
118
- $wpdb->query('TRUNCATE TABLE '.CPD_C_TABLE);
119
- echo '<div id="message" class="updated fade"><p>'.sprintf(__('Counter reseted.', 'cpd'), $rows).'</p></div>';
120
- break;
121
122
- // uninstall plugin
123
- case __('UNINSTALL Count per Day', 'cpd') :
124
- if(trim($_POST['uninstall_cpd_yes']) == 'yes')
125
{
126
- count_per_day_uninstall();
127
- echo '<div id="message" class="updated fade"><p>';
128
- printf(__('Table %s deleted', 'cpd'), CPD_C_TABLE);
129
- echo '<br/>';
130
- printf(__('Table %s deleted', 'cpd'), CPD_CO_TABLE);
131
- echo '<br/>';
132
- printf(__('Table %s deleted', 'cpd'), CPD_N_TABLE);
133
- echo '<br/>';
134
- echo __('Options deleted', 'cpd').'</p></div>';
135
- $mode = 'end-UNINSTALL';
136
}
137
- break;
138
-
139
- default:
140
- break;
141
}
142
}
143
144
// delete one massbots per click on X
145
if ( isset($_GET['dmbip']) && isset($_GET['dmbdate']) )
146
- $count_per_day->getQuery("DELETE FROM ".CPD_C_TABLE." WHERE ip = '".$_GET['dmbip']."' AND date = '".$_GET['dmbdate']."'", 'deleteMassbot');
147
148
if ( empty($mode) )
149
$mode = '';
@@ -161,7 +321,8 @@ switch($mode) {
161
break;
162
163
default:
164
- // show options page
165
166
$o = $count_per_day->options;
167
@@ -172,266 +333,248 @@ switch($mode) {
172
update_option('count_per_day', $o);
173
}
174
?>
175
- <div class="wrap">
176
- <h2><img src="<?php echo $count_per_day->getResource('cpd_menu.gif') ?>" alt="" style="width:24px;height:24px" /> Count per Day</h2>
177
178
- <div id="poststuff">
179
180
- <div class="postbox cpd_settings">
181
- <h3><?php _e('Options', 'cpd') ?></h3>
182
- <div class="inside">
183
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
184
-
185
- <!-- counter -->
186
-
187
- <fieldset>
188
- <legend><?php _e('Counter', 'cpd') ?></legend>
189
-
190
- <table class="form-table">
191
- <tr>
192
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Online time', 'cpd') ?>:</th>
193
- <td><input class="code" type="text" name="cpd_onlinetime" size="3" value="<?php echo $o['onlinetime']; ?>" /> <?php _e('Seconds for online counter. Used for "Visitors online" on dashboard page.', 'cpd') ?></td>
194
- </tr>
195
- <tr>
196
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Logged on Users', 'cpd') ?>:</th>
197
- <td>
198
- <label for="cpd_user"><input type="checkbox" name="cpd_user" id="cpd_user" <?php if($o['user']==1) echo 'checked="checked"'; ?> /> <?php _e('count too', 'cpd') ?></label>
199
- - <?php _e('until User Level', 'cpd') ?>
200
- <select name="cpd_user_level">
201
- <option value="10" <?php if ($o['user_level'] == 10) echo 'selected="selected"' ?>><?php echo translate_user_role('Administrator') ?> (10)</option>
202
- <option value="7" <?php if ($o['user_level'] == 7) echo 'selected="selected"' ?>><?php echo translate_user_role('Editor') ?> (7)</option>
203
- <option value="2" <?php if ($o['user_level'] == 2) echo 'selected="selected"' ?>><?php echo translate_user_role('Author') ?> (2)</option>
204
- <option value="1" <?php if ($o['user_level'] == 1) echo 'selected="selected"' ?>><?php echo translate_user_role('Contributor') ?> (1)</option>
205
- <option value="0" <?php if ($o['user_level'] == 0) echo 'selected="selected"' ?>><?php echo translate_user_role('Subscriber') ?> (0)</option>
206
- </select>
207
- </td>
208
- </tr>
209
- <tr>
210
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Auto counter', 'cpd') ?>:</th>
211
- <td><label for="cpd_autocount"><input type="checkbox" name="cpd_autocount" id="cpd_autocount" <?php if($o['autocount']==1) echo 'checked="checked"'; ?> /> <?php _e('Counts automatically single-posts and pages, no changes on template needed.', 'cpd') ?></label></td>
212
- </tr>
213
- <tr>
214
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Bots to ignore', 'cpd') ?>:</th>
215
- <td><textarea name="cpd_bots" cols="50" rows="10"><?php echo $o['bots']; ?></textarea></td>
216
- </tr>
217
- <tr>
218
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Anonymous IP', 'cpd') ?>:</th>
219
- <td><label for="cpd_anoip"><input type="checkbox" name="cpd_anoip" id="cpd_anoip" <?php if($o['anoip']==1) echo 'checked="checked"'; ?> /> a.b.c.d &gt; a.b.c.x</label></td>
220
- </tr>
221
- <tr>
222
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Cache', 'cpd') ?> (beta):</th>
223
- <td><label for="cpd_ajax"><input type="checkbox" name="cpd_ajax" id="cpd_ajax" <?php if($o['ajax']==1) echo 'checked="checked"'; ?> /> <?php _e('I use a cache plugin. Count these visits with ajax.', 'cpd') ?></label></td>
224
- </tr>
225
- <tr>
226
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Clients and referrers', 'cpd') ?>:</th>
227
- <td><label for="cpd_referers"><input type="checkbox" name="cpd_referers" id="cpd_referers" <?php if($o['referers']==1) echo 'checked="checked"'; ?> /> <?php _e('Save and show clients and referrers.<br />Needs a lot of space in the database but gives you more detailed informations of your visitors.', 'cpd') ?> (1000000 <?php _e('Reads', 'cpd') ?> ~ 130 MB)</label></td>
228
- </tr>
229
- </table>
230
- </fieldset>
231
-
232
- <!-- dashboard -->
233
-
234
- <fieldset>
235
- <legend><?php _e('Dashboard') ?></legend>
236
-
237
- <script>
238
- function checkcustom()
239
- {
240
- var b = document.getElementById('cpd_whocansee');
241
- var i = document.getElementById('cpd_whocansee_custom_div');
242
- if ( b.value == 'custom' )
243
- i.style.display = 'block';
244
- else
245
- i.style.display = 'none';
246
- }
247
- </script>
248
-
249
- <table class="form-table">
250
- <tr>
251
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Who can see it', 'cpd') ?>:</th>
252
- <td>
253
- <?php $cus = (in_array($o['whocansee'], array('manage_options','manage_links','publish_posts','edit_posts','read'))) ? 0 : 1 ?>
254
- <select id="cpd_whocansee" name="cpd_whocansee" onchange="checkcustom()">
255
- <option value="manage_options" <?php if ($o['whocansee'] == 'manage_options') echo 'selected="selected"' ?>><?php echo translate_user_role('Administrator') ?> </option>
256
- <option value="manage_links" <?php if ($o['whocansee'] == 'manage_links') echo 'selected="selected"' ?>><?php echo translate_user_role('Editor') ?></option>
257
- <option value="publish_posts" <?php if ($o['whocansee'] == 'publish_posts') echo 'selected="selected"' ?>><?php echo translate_user_role('Author') ?></option>
258
- <option value="edit_posts" <?php if ($o['whocansee'] == 'edit_posts') echo 'selected="selected"' ?>><?php echo translate_user_role('Contributor') ?></option>
259
- <option value="read" <?php if ($o['whocansee'] == 'read') echo 'selected="selected"' ?>><?php echo translate_user_role('Subscriber') ?></option>
260
- <option value="custom" <?php if ($cus) echo 'selected="selected"' ?>>- <?php echo _e('custom', 'cpd') ?> -</option>
261
- </select>
262
- <?php _e('and higher are allowed to see the statistics page.', 'cpd') ?>
263
- <div id="cpd_whocansee_custom_div" <?php if (!$cus) echo 'style="display:none"' ?>>
264
- <?php printf(__('Set the %s capability %s a user need:', 'cpd'), '<a href="https://codex.wordpress.org/Roles_and_Capabilities">', '</a>'); ?>
265
- <input type="text" name="cpd_whocansee_custom" value="<?php echo $o['whocansee'] ?>" />
266
- </div>
267
- </td>
268
- </tr>
269
- <tr>
270
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Visitors per post', 'cpd') ?>:</th>
271
- <td><input class="code" type="text" name="cpd_dashboard_posts" size="3" value="<?php echo $o['dashboard_posts']; ?>" /> <?php _e('How many posts do you want to see on dashboard page?', 'cpd') ?></td>
272
- </tr>
273
- <tr>
274
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Latest Counts - Posts', 'cpd') ?>:</th>
275
- <td><input class="code" type="text" name="cpd_dashboard_last_posts" size="3" value="<?php echo $o['dashboard_last_posts']; ?>" /> <?php _e('How many posts do you want to see on dashboard page?', 'cpd') ?></td>
276
- </tr>
277
- <tr>
278
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Latest Counts - Days', 'cpd') ?>:</th>
279
- <td><input class="code" type="text" name="cpd_dashboard_last_days" size="3" value="<?php echo $o['dashboard_last_days']; ?>" /> <?php _e('How many days do you want look back?', 'cpd') ?></td>
280
- </tr>
281
- <tr>
282
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Chart - Days', 'cpd') ?>:</th>
283
- <td><input class="code" type="text" name="cpd_chart_days" size="3" value="<?php echo $o['chart_days']; ?>" /> <?php _e('How many days do you want look back?', 'cpd') ?></td>
284
- </tr>
285
- <tr>
286
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Chart - Height', 'cpd') ?>:</th>
287
- <td><input class="code" type="text" name="cpd_chart_height" size="3" value="<?php echo $o['chart_height']; ?>" /> px - <?php _e('Height of the biggest bar', 'cpd') ?></td>
288
- </tr>
289
- <tr>
290
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Old Charts', 'cpd') ?>:</th>
291
- <td><label for="cpd_chart_old"><input type="checkbox" name="cpd_chart_old" id="cpd_chart_old" <?php if($o['chart_old']==1) echo 'checked="checked"'; ?> /> <?php _e('Show old bar charts.', 'cpd') ?></label></td>
292
- </tr>
293
- <?php if ($cpd_geoip) { ?>
294
- <tr>
295
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Countries', 'cpd') ?>:</th>
296
- <td><input class="code" type="text" name="cpd_countries" size="3" value="<?php echo $o['countries']; ?>" /> <?php _e('How many countries do you want to see on dashboard page?', 'cpd') ?></td>
297
- </tr>
298
- <?php } ?>
299
- <tr>
300
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Browsers', 'cpd') ?>:</th>
301
- <td><input class="code" type="text" name="cpd_clients" size="50" value="<?php echo $o['clients']; ?>" /> <?php _e('Substring of the user agent, separated by comma', 'cpd') ?></td>
302
- </tr>
303
- <tr>
304
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Referrers - Entries', 'cpd') ?>:</th>
305
- <td><input class="code" type="text" name="cpd_dashboard_referers" size="3" value="<?php echo $o['dashboard_referers']; ?>" /> <?php _e('How many referrers do you want to see on dashboard page?', 'cpd') ?></td>
306
- </tr>
307
- <tr>
308
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Referrers - Days', 'cpd') ?>:</th>
309
- <td><input class="code" type="text" name="cpd_referers_last_days" size="3" value="<?php echo $o['referers_last_days']; ?>" /> <?php _e('How many days do you want look back?', 'cpd') ?></td>
310
- </tr>
311
- <tr>
312
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Local URLs', 'cpd') ?>:</th>
313
- <td><label for="cpd_localref"><input type="checkbox" name="cpd_localref" id="cpd_localref" <?php if($o['localref']==1) echo 'checked="checked"'; ?> /> <?php _e('Show local referrers too.', 'cpd') ?> (<?php echo bloginfo('url') ?>/...)</label></td>
314
- </tr>
315
- </table>
316
- </fieldset>
317
-
318
- <!-- lists -->
319
-
320
- <fieldset>
321
- <legend><?php _e('Posts') ?> / <?php _e('Pages') ?></legend>
322
- <table class="form-table">
323
- <tr>
324
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Show in lists', 'cpd') ?>:</th>
325
- <td><label for="cpd_show_in_lists"><input type="checkbox" name="cpd_show_in_lists" id="cpd_show_in_lists" <?php if($o['show_in_lists']==1) echo 'checked="checked"'; ?> /> <?php _e('Show "Reads per Post" in a new column in post management views.', 'cpd') ?></label></td>
326
- </tr>
327
- </table>
328
- </fieldset>
329
-
330
- <!-- start values -->
331
-
332
- <fieldset>
333
- <legend><?php _e('Start Values', 'cpd') ?></legend>
334
- <table class="form-table">
335
- <tr>
336
- <th colspan="2">
337
- <?php _e('Here you can change the date of first count and add a start count.', 'cpd')?>
338
- </th>
339
- </tr>
340
- <tr>
341
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Start date', 'cpd') ?>:</th>
342
- <td><input class="code" type="text" name="cpd_startdate" size="10" value="<?php echo $o['startdate']; ?>" /> <?php _e('Your old Counter starts at?', 'cpd') ?> [yyyy-mm-dd]</td>
343
- </tr>
344
- <tr>
345
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Start count', 'cpd') ?>:</th>
346
- <td><input class="code" type="text" name="cpd_startcount" size="10" value="<?php echo $o['startcount']; ?>" /> <?php _e('Add this value to "Total visitors".', 'cpd') ?></td>
347
- </tr>
348
- <tr>
349
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Start count', 'cpd') ?>:</th>
350
- <td><input class="code" type="text" name="cpd_startreads" size="10" value="<?php echo $o['startreads']; ?>" /> <?php _e('Add this value to "Total reads".', 'cpd') ?></td>
351
- </tr>
352
- </table>
353
- </fieldset>
354
-
355
- <!-- Stylesheet -->
356
-
357
- <fieldset>
358
- <legend><?php _e('Stylesheet') ?></legend>
359
- <table class="form-table">
360
- <tr>
361
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('NO Stylesheet in Frontend', 'cpd') ?>:</th>
362
- <td><label for="cpd_no_front_css"><input type="checkbox" name="cpd_no_front_css" id="cpd_no_front_css" <?php if($o['no_front_css']==1) echo 'checked="checked"'; ?> /> <?php _e('Do not load the stylesheet "counter.css" in frontend.', 'cpd') ?></label></td>
363
- </tr>
364
- </table>
365
- </fieldset>
366
-
367
- <!-- debug -->
368
-
369
- <fieldset>
370
- <legend style="color:red"><?php _e('Debug mode', 'cpd') ?></legend>
371
- <p style="margin-top:15px;">
372
- <label for="cpd_debug"><input type="checkbox" name="cpd_debug" id="cpd_debug" <?php if($o['debug']==1) echo 'checked="checked"'; ?> /> <?php _e('Show debug informations at the bottom of all pages.', 'cpd') ?></label>
373
- </p>
374
- </fieldset>
375
-
376
- <input type="hidden" name="do" value="cpd_update" />
377
- <input type="submit" name="update" value="<?php _e('Update options', 'cpd') ?>" class="button-primary" style="margin-left: 5px;" />
378
-
379
- </form>
380
-
381
- </div>
382
- </div>
383
-
384
- <!-- Countries -->
385
<div class="postbox">
386
- <h3><?php _e('GeoIP - Countries', 'cpd') ?></h3>
387
- <div class="inside">
388
389
- <table class="form-table">
390
- <?php if ( $cpd_geoip ) { ?>
391
- <tr>
392
- <td>
393
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
394
- <input type="hidden" name="do" value="cpd_countries" />
395
- <input type="submit" name="updcon" value="<?php _e('Update old counter data', 'cpd') ?>" class="button" />
396
- </form>
397
- </td>
398
- <td><?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') ?></td>
399
- </tr>
400
- <?php } ?>
401
402
- <?php if ( class_exists('CpdGeoIp') && ini_get('allow_url_fopen') && function_exists('gzopen') ) {
403
- // install or update database ?>
404
- <tr>
405
- <td width="10">
406
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
407
- <input type="hidden" name="do" value="cpd_countrydb" />
408
- <input type="submit" name="updcondb" value="<?php _e('Update GeoIP database', 'cpd') ?>" class="button" />
409
- </form>
410
- </td>
411
- <td><?php _e('Download a new version of GeoIP.dat file.', 'cpd') ?></td>
412
- </tr>
413
- <?php } ?>
414
- </table>
415
416
- <p>
417
- <span class="cpd-r"><?php _e('More informations about GeoIP', 'cpd') ?>:
418
- <a href="http://www.maxmind.com/app/geoip_country">www.maxmind.com</a></span>&nbsp;
419
</p>
420
-
421
- </div>
422
</div>
423
424
- <!-- Mass Bots -->
425
<div class="postbox">
426
<?php
427
$limit = (isset($o['massbotlimit'])) ? $o['massbotlimit'] : 25;
428
$limit = (isset($_POST['limit'])) ? $_POST['limit'] : $limit;
429
$limit_input = '<input type="text" size="3" name="limit" value="'.$limit.'" />';
430
- $bots = $count_per_day->getMassBots($limit);
431
?>
432
- <h3><?php _e('Mass Bots', 'cpd') ?></h3>
433
<div class="inside">
434
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
435
<p>
436
<?php printf(__('Show all IPs with more than %s page views per day', 'cpd'), $limit_input) ?>
437
<input type="submit" name="showmassbots" value="<?php _e('show', 'cpd') ?>" class="button" />
@@ -445,37 +588,35 @@ switch($mode) {
445
<th><?php _e('IP', 'cpd') ?></th>
446
<th><?php _e('Date', 'cpd') ?></th>
447
<th><?php _e('Client', 'cpd') ?></th>
448
- <th><?php _e('Views', 'cpd') ?></th>
449
</tr>
450
</thead>
451
<?php
452
$sum = 0;
453
- if ( !mysql_errno() ) :
454
- while ( $row = mysql_fetch_assoc($bots) )
455
{
456
- $ip = $row['ip'];
457
- echo '<tr><td style="white-space:nowrap">';
458
- if ( $cpd_geoip )
459
- {
460
- $c = CpdGeoIp::getCountry($ip);
461
- echo $c[1].' &nbsp;';
462
- }
463
- echo '<a href="?page=count-per-day/counter-options.php&amp;dmbip='.$row['longip'].'&amp;dmbdate='.$row['date'].'"
464
- title="'.sprintf(__('Delete these %s counts', 'cpd'), $row['posts']).'"
465
- style="color:red; font-weight: bold;">X</a> &nbsp;';
466
- echo '<a href="http://www.utrace.de/?query='.$ip.'">'.$ip.'</a></td>'
467
- .'<td style="white-space:nowrap;">'.mysql2date(get_option('date_format'), $row['date'] ).'</td>'
468
- .'<td>'.$row['client'].'</td>'
469
- .'<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">'
470
- .$row['posts'].'</a></td>'
471
- .'</tr>';
472
- $sum += $row['posts'];
473
}
474
- endif;
475
?>
476
</table>
477
<?php if ( $sum ) { ?>
478
- <p class="submit">
479
<input type="hidden" name="do" value="cpd_delete_massbots" />
480
<input type="hidden" name="limit" value="<?php echo $limit ?>" />
481
<input type="submit" name="clean" value="<?php printf(__('Delete these %s counts', 'cpd'), $sum) ?>" class="button" />
@@ -484,18 +625,49 @@ switch($mode) {
484
</form>
485
</div>
486
</div>
487
-
488
<!-- Cleaner -->
489
<?php if ( $count_per_day->options['referers'] ) : ?>
490
<div class="postbox">
491
- <h3><?php _e('Clean the database', 'cpd') ?></h3>
492
<div class="inside">
493
<p>
494
<?php _e('You can clean the counter table by delete the "spam data".<br />If you add new bots above the old "spam data" keeps in the database.<br />Here you can run the bot filter again and delete the visits of the bots.', 'cpd') ?>
495
</p>
496
497
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
498
- <p class="submit">
499
<input type="hidden" name="do" value="cpd_clean" />
500
<input type="submit" name="clean" value="<?php _e('Clean the database', 'cpd') ?>" class="button" />
501
</p>
@@ -503,28 +675,132 @@ switch($mode) {
503
</div>
504
</div>
505
<?php endif; ?>
506
507
<!-- Reset DBs -->
508
<div class="postbox">
509
- <h3><?php _e('Reset the counter', 'cpd') ?></h3>
510
<div class="inside">
511
<p style="color: red">
512
<?php _e('You can reset the counter by empty the table. ALL TO 0!<br />Make a backup if you need the current data!', 'cpd') ?>
513
</p>
514
515
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
516
- <p class="submit">
517
<input type="hidden" name="do" value="cpd_reset" />
518
- <input type="submit" name="clean" value="<?php _e('Reset the counter', 'cpd') ?>" class="button" />
519
</p>
520
</form>
521
</div>
522
</div>
523
-
524
<!-- Uninstall -->
525
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
526
<div class="postbox">
527
- <h3><?php _e('Uninstall', 'cpd') ?></h3>
528
<div class="inside">
529
<p>
530
<?php _e('If "Count per Day" only disabled the tables in the database will be preserved.', 'cpd') ?><br/>
@@ -533,26 +809,19 @@ switch($mode) {
533
<p style="color: red">
534
<strong><?php _e('WARNING', 'cpd') ?>:</strong><br />
535
<?php _e('These tables (with ALL counter data) will be deleted.', 'cpd') ?><br />
536
- <b><?php echo CPD_C_TABLE.', '.CPD_CO_TABLE.', '.CPD_N_TABLE; ?></b><br />
537
<?php _e('If "Count per Day" re-installed, the counter starts at 0.', 'cpd') ?>
538
</p>
539
- <p>&nbsp;</p>
540
- <p class="submit">
541
- <input type="checkbox" name="uninstall_cpd_yes" value="yes" />&nbsp;<?php _e('Yes', 'cpd'); ?><br /><br />
542
- <input type="submit" name="do" value="<?php _e('UNINSTALL Count per Day', 'cpd') ?>" class="button" onclick="return confirm('<?php _e('You are sure to disable Count per Day and delete all data?', 'cpd') ?>')" />
543
</p>
544
</div>
545
</div>
546
</form>
547
548
- <!-- Plugin page -->
549
- <div class="postbox">
550
- <h3><?php _e('Support', 'cpd') ?></h3>
551
- <div class="inside">
552
- <?php $count_per_day->cpdInfo() ?>
553
- </div>
554
- </div>
555
-
556
557
</div><!-- poststuff -->
558
</div><!-- wrap -->
31
$count_per_day->options['debug'] = empty( $_POST['cpd_debug'] ) ? 0 : 1 ;
32
$count_per_day->options['localref'] = empty( $_POST['cpd_localref'] ) ? 0 : 1 ;
33
$count_per_day->options['referers'] = empty( $_POST['cpd_referers'] ) ? 0 : 1 ;
34
+ $count_per_day->options['referers_cut'] = empty( $_POST['cpd_referers_cut'] ) ? 0 : 1 ;
35
$count_per_day->options['dashboard_referers'] = $_POST['cpd_dashboard_referers'];
36
$count_per_day->options['referers_last_days'] = $_POST['cpd_referers_last_days'];
37
$count_per_day->options['chart_old'] = empty( $_POST['cpd_chart_old'] ) ? 0 : 1 ;
38
$count_per_day->options['no_front_css'] = empty( $_POST['cpd_no_front_css'] ) ? 0 : 1 ;
39
$count_per_day->options['whocansee'] = ($_POST['cpd_whocansee'] == 'custom') ? $_POST['cpd_whocansee_custom'] : $_POST['cpd_whocansee'];
40
+ $count_per_day->options['backup_part'] = $_POST['cpd_backup_part'];
41
42
if (empty($count_per_day->options['clients']))
43
$count_per_day->options['clients'] = 'Firefox, MSIE, Chrome, Safari, Opera';
47
48
update_option('count_per_day', $count_per_day->options);
49
50
+ echo '<div class="updated"><p>'.__('Options updated', 'cpd').'</p></div>';
51
break;
52
53
+ // update countries
54
+ case 'cpd_countries' :
55
+ if ( class_exists('CpdGeoIp') )
56
+ {
57
+ $count_per_day->queries[] = 'cpd_countries - class "CpdGeoIp" exists';
58
+ $rest = CpdGeoIp::updateDB();
59
+ echo '<div class="updated">
60
+ <form name="cpdcountries" method="post" action="'.$_SERVER['REQUEST_URI'].'">
61
+ <p>'.sprintf(__('Countries updated. <b>%s</b> entries in %s without country left', 'cpd'), $rest, $wpdb->cpd_counter);
62
+ if ( $rest > 0 )
63
+ echo '<input type="hidden" name="do" value="cpd_countries" />
64
+ <input type="submit" name="updcon" value="'.__('update next', 'cpd').'" class="button" />';
65
+ if ( $rest > 20 )
66
{
67
+ // reload page per javascript until less than 100 entries without country
68
+ if ( !$count_per_day->options['debug'] )
69
+ echo '<script type="text/javascript">document.cpdcountries.submit();</script>';
70
}
71
+ echo '</p>
72
+ </form>
73
+ </div>';
74
+ if ( $rest > 20 )
75
+ $count_per_day->flush_buffers();
76
+ }
77
+ else
78
+ $count_per_day->queries[] = '<span style="color:red">cpd_countries - class "CpdGeoIp" NOT exists</span>';
79
+ break;
80
+
81
+ // download new GeoIP database
82
+ case 'cpd_countrydb' :
83
+ if ( class_exists('CpdGeoIp') )
84
+ {
85
+ $result = CpdGeoIp::updateGeoIpFile();
86
+ echo '<div class="updated"><p>'.$result.'</p></div>';
87
+ if ( file_exists($cpd_path.'geoip/GeoIP.dat') )
88
+ $cpd_geoip = 1;
89
+ }
90
+ break;
91
+
92
+ // delete massbots
93
+ case 'cpd_delete_massbots' :
94
+ if ( isset($_POST['limit']) )
95
+ {
96
+ $bots = $count_per_day->getMassBots($_POST['limit']);
97
+ $sum = 0;
98
+ foreach ($bots as $r)
99
{
100
+ $count_per_day->mysqlQuery('', "DELETE FROM $wpdb->cpd_counter WHERE ip = INET_ATON('$r->ip') AND date = '$r->date'", 'deleteMassbots '.__LINE__);
101
+ $sum += $r->posts;
102
}
103
+ if ( $sum )
104
+ echo '<div class="updated"><p>'.sprintf(__('Mass Bots cleaned. %s counts deleted.', 'cpd'), $sum).'</p></div>';
105
+ }
106
+ break;
107
108
+ // clean database
109
+ case 'cpd_clean' :
110
+ $rows = $count_per_day->cleanDB();
111
+ delete_option('count_per_day_summary');
112
+ delete_option('count_per_day_collected');
113
+ delete_option('count_per_day_posts');
114
+ echo '<div class="updated"><p>'.sprintf(__('Database cleaned. %s rows deleted.', 'cpd'), $rows).'</p></div>';
115
+ break;
116
117
+ // reset counter
118
+ case 'cpd_reset' :
119
+ if(trim($_POST['reset_cpd_yes']) == 'yes')
120
+ {
121
+ $wpdb->query('TRUNCATE TABLE '.$wpdb->cpd_counter);
122
+ $wpdb->query('TRUNCATE TABLE '.$wpdb->cpd_counter_useronline);
123
+ $wpdb->query('TRUNCATE TABLE '.$wpdb->cpd_notes);
124
+ echo '<div class="updated"><p>'.sprintf(__('Counter reseted.', 'cpd'), $rows).'</p></div>';
125
+ }
126
+ break;
127
+
128
+ // uninstall plugin
129
+ case __('UNINSTALL Count per Day', 'cpd') :
130
+ if(trim($_POST['uninstall_cpd_yes']) == 'yes')
131
+ {
132
+ count_per_day_uninstall();
133
+ echo '<div class="updated"><p>';
134
+ echo sprintf(__('Table %s deleted', 'cpd'), $wpdb->cpd_counter).'<br/>';
135
+ echo sprintf(__('Table %s deleted', 'cpd'), $wpdb->cpd_counter_useronline).'<br/>';
136
+ echo sprintf(__('Table %s deleted', 'cpd'), $wpdb->cpd_notes).'<br/>';
137
+ echo __('Options deleted', 'cpd').'</p></div>';
138
+ $mode = 'end-UNINSTALL';
139
+ }
140
+ break;
141
+
142
+ // backup counter
143
+ case 'cpd_backup' :
144
+ $count_per_day->backup();
145
+ break;
146
+
147
+ // collect entries
148
+ case 'cpd_collect' :
149
+ // backup first ;)
150
+ $count_per_day->backup();
151
+
152
+ set_time_limit(300);
153
+
154
+ $allnew = (isset($_POST['cpd_new_collection'])) ? 1 : 0;
155
+ if ($allnew)
156
+ {
157
+ delete_option('count_per_day_summary');
158
+ delete_option('count_per_day_collected');
159
+ delete_option('count_per_day_posts');
160
+ }
161
+
162
+ $keep = (isset($_POST['cpd_keep_month'])) ? $_POST['cpd_keep_month'] : 6;
163
+
164
+ $d = array(); // month data
165
+ $t = array(); // temp country data
166
+ $s = array( // summary
167
+ 'reads' => $count_per_day->getCollectedReads(),
168
+ 'users' => $count_per_day->getCollectedUsers() );
169
+ $mold = 0; // current month
170
+ $countryold = '#'; // current country
171
+
172
+ echo '<div id="cpd_progress_collection" class="updated"><p>'.__('Collection in progress...', 'cpd').' ';
173