Count per Day - Version 2.15.1

Version Description

  • Bugifx: error in "Visitors per month" counter
Download this release

Release Info

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

Code changes from version 3.0 to 2.15.1

Files changed (71) hide show
  1. ajax.php +13 -7
  2. counter-core.php +0 -1233
  3. counter-options.php +317 -647
  4. counter.css +139 -239
  5. counter.php +1418 -757
  6. geoip/GeoIP.dat +0 -0
  7. geoip/geoip.inc +91 -91
  8. geoip/geoip.php +47 -32
  9. img/cpd_calendar.png +0 -0
  10. img/cpd_flags.png +0 -0
  11. img/cpd_pen.png +0 -0
  12. img/cpd_sprites.png +0 -0
  13. js/excanvas.min.js +0 -1
  14. js/jquery.flot.min.js +0 -6
  15. locale/cpd-az_AZ.mo +0 -0
  16. locale/cpd-az_AZ.po +0 -972
  17. locale/cpd-be_BY.mo +0 -0
  18. locale/cpd-be_BY.po +0 -784
  19. locale/cpd-bg_BG.mo +0 -0
  20. locale/cpd-bg_BG.po +0 -972
  21. locale/cpd-by_BY.mo +0 -0
  22. locale/cpd-by_BY.po +740 -0
  23. locale/cpd-da_DK-2.mo +0 -0
  24. locale/cpd-da_DK-2.po +742 -0
  25. locale/cpd-da_DK.mo +0 -0
  26. locale/cpd-da_DK.po +215 -447
  27. locale/cpd-de_DE.mo +0 -0
  28. locale/cpd-de_DE.po +197 -429
  29. locale/cpd-el.mo +0 -0
  30. locale/cpd-el.po +0 -973
  31. locale/cpd-es_ES.mo +0 -0
  32. locale/cpd-es_ES.po +195 -427
  33. locale/cpd-fr_FR.mo +0 -0
  34. locale/cpd-fr_FR.po +221 -452
  35. locale/cpd-it_IT.mo +0 -0
  36. locale/cpd-it_IT.po +207 -438
  37. locale/cpd-ja.mo +0 -0
  38. locale/cpd-ja.po +0 -972
  39. locale/cpd-lt_LT.mo +0 -0
  40. locale/cpd-lt_LT.po +0 -784
  41. locale/cpd-nb_NO.mo +0 -0
  42. locale/cpd-nb_NO.po +0 -972
  43. locale/cpd-nl_NL.mo +0 -0
  44. locale/cpd-nl_NL.po +232 -463
  45. locale/cpd-pl_PL.mo +0 -0
  46. locale/cpd-pl_PL.po +739 -972
  47. locale/cpd-pt_BR.mo +0 -0
  48. locale/cpd-pt_BR.po +220 -451
  49. locale/cpd-pt_PT.mo +0 -0
  50. locale/cpd-pt_PT.po +0 -971
  51. locale/cpd-ru_RU.mo +0 -0
  52. locale/cpd-ru_RU.po +198 -431
  53. locale/cpd-sv_SE.mo +0 -0
  54. locale/cpd-sv_SE.po +222 -454
  55. locale/cpd-tr_TR.mo +0 -0
  56. locale/cpd-tr_TR.po +0 -971
  57. locale/cpd-ua_UA.mo +0 -0
  58. locale/cpd-ua_UA.po +0 -972
  59. locale/cpd-uz_UZ.mo +0 -0
  60. locale/cpd-uz_UZ.po +740 -0
  61. map/ammap.swf +0 -0
  62. map/data.xml.php +39 -44
  63. map/map.php +1 -1
  64. map/settings.xml.php +7 -9
  65. massbots.php +33 -30
  66. notes.php +37 -27
  67. readme.txt +88 -173
  68. screenshot-1.png +0 -0
  69. screenshot-2.png +0 -0
  70. screenshot-3.png +0 -0
  71. userperspan.php +26 -20
ajax.php CHANGED
@@ -1,16 +1,21 @@
1
<?php
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 );
@@ -30,3 +35,4 @@ if ( $_GET['f'] == 'count' )
30
}
31
}
32
}
1
<?php
2
+ // windows junction patch
3
+ $dir = dirname($_SERVER['DOCUMENT_ROOT'].$_SERVER['SCRIPT_NAME']);
4
+ for ( $x = 1; $x <= 5; $x++ )
5
{
6
+ $dir = dirname($dir.'x');
7
+ if ( is_file($dir.'/wp-load.php') )
8
+ require_once($dir.'/wp-load.php');
9
+ }
10
11
+ $cpd_funcs = array ( 'show',
12
'getReadsAll', 'getReadsToday', 'getReadsYesterday', 'getReadsLastWeek', 'getReadsThisMonth',
13
'getUserAll', 'getUserToday', 'getUserYesterday', 'getUserLastWeek', 'getUserThisMonth',
14
'getUserPerDay', 'getUserOnline', 'getFirstCount' );
15
+
16
+ if ( $_GET['f'] == 'count' )
17
+ {
18
+ $page = intval($_GET['page']);
19
if ( is_numeric($page) )
20
{
21
$count_per_day->count( '', $page );
35
}
36
}
37
}
38
+ ?>
counter-core.php DELETED
@@ -1,1233 +0,0 @@
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,279 +31,114 @@ 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['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';
44
45
if ( isset($_POST['cpd_countries']) )
46
$count_per_day->options['countries'] = $_POST['cpd_countries'];
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
- $count_per_day->flush_buffers();
174
175
- $sql = "
176
- SELECT LEFT(date,7) month, COUNT(*) c, country
177
- FROM $wpdb->cpd_counter
178
- WHERE date < DATE_SUB( DATE_FORMAT(CURDATE(), '%%Y-%%m-01'), INTERVAL $keep MONTH )
179
- GROUP BY date, country, ip
180
- ORDER BY LEFT(date,7), country";
181
- $res = $count_per_day->mysqlQuery('rows', $sql, 'getReadsPerMonthsCompress '.__LINE__);
182
-
183
- foreach ($res as $r)
184
- {
185
- $reads = (int) $r->c;
186
- $s['reads'] += $reads;
187
- $s['users'] += 1;
188
- $country = ($r->country) ? $r->country : '-';
189
190
- if ( $r->month != $mold )
191
{
192
- // new month row
193
- $month = str_replace('-','',$r->month);
194
- $d[$month]['reads'] = $reads;
195
- $d[$month]['users'] = 1;
196
- $t[$month][$country]['reads'] = $reads;
197
- $t[$month][$country]['users'] = 1;
198
- $mold = $r->month;
199
- echo "| ";
200
- $count_per_day->flush_buffers();
201
}
202
- else if ( $country != $countryold )
203
- {
204
- // new country
205
- $d[$month]['reads'] += $reads;
206
- $d[$month]['users'] += 1;
207
- $t[$month][$country]['reads'] = $reads;
208
- $t[$month][$country]['users'] = 1;
209
- $countryold = $country;
210
- }
211
- else
212
- {
213
- // new visitor/ip
214
- $d[$month]['reads'] += $reads;
215
- $d[$month]['users'] += 1;
216
- $t[$month][$country]['reads'] += $reads;
217
- $t[$month][$country]['users'] += 1;
218
- }
219
- }
220
-
221
- // format country data as "country:reads|visitors;"
222
- foreach ($t as $month => $cdata)
223
- {
224
- $d[$month]['country'] = '';
225
- foreach ($cdata as $country => $c)
226
- $d[$month]['country'] .= $country.':'.$c['reads'].'|'.$c['users'].';';
227
- $d[$month]['country'] = substr($d[$month]['country'], 0, -1);
228
- }
229
- unset($t);
230
-
231
- // add new to collected data
232
- $d = get_option('count_per_day_collected', array()) + $d;
233
-
234
- // summaries
235
- $last = max(array_keys($d));
236
- $s['lastcollectedmonth'] = substr($last, 0, 4).'-'.substr($last, 4, 2);
237
- $s['mostreads'] = $count_per_day->getDayWithMostReads(0, 1);
238
- $s['mostusers'] = $count_per_day->getDayWithMostUsers(0, 1);
239
- $s['firstcount'] = $count_per_day->updateFirstCount();
240
-
241
- // visitors per post
242
- echo "<br />".__('Get Visitors per Post...', 'cpd')."\n";
243
- $count_per_day->flush_buffers();
244
-
245
- $sql = "
246
- SELECT COUNT(*) count, page
247
- FROM $wpdb->cpd_counter
248
- WHERE date < DATE_SUB( DATE_FORMAT(CURDATE(), '%%Y-%%m-01'), INTERVAL $keep MONTH )
249
- AND page
250
- GROUP BY page";
251
- $res = $count_per_day->mysqlQuery('rows', $sql, 'getUsersPerPostCompress '.__LINE__);
252
-
253
- $p = get_option('count_per_day_posts',array());
254
- foreach ($res as $r)
255
- {
256
- if (isset($p['p'.$r->page]))
257
- $p['p'.$r->page] += (int) $r->count;
258
- else
259
- $p['p'.$r->page] = (int) $r->count;
260
- }
261
-
262
- // save collection
263
- echo "<br />".__('Delete old data...', 'cpd')."\n";
264
- $count_per_day->flush_buffers();
265
-
266
- update_option('count_per_day_summary', $s);
267
- update_option('count_per_day_collected', $d);
268
- update_option('count_per_day_posts', $p);
269
- unset($s);
270
- unset($d);
271
- unset($p);
272
-
273
- // delete entries
274
- $sizeold = $count_per_day->getTableSize($wpdb->cpd_counter);
275
- $sql = "
276
- DELETE FROM $wpdb->cpd_counter
277
- WHERE date < DATE_SUB( DATE_FORMAT(CURDATE(), '%%Y-%%m-01'), INTERVAL $keep MONTH )";
278
- $count_per_day->mysqlQuery('', $sql, 'deleteAfterCollection '.__LINE__);
279
- $count_per_day->mysqlQuery('', "REPAIR TABLE `$wpdb->cpd_counter`", 'repairTable '.__LINE__);
280
- $sizenew = $count_per_day->getTableSize($wpdb->cpd_counter);
281
-
282
- // hide progress
283
- echo "</p></div>\n";
284
- echo '<script type="text/javascript">document.getElementById("cpd_progress_collection").style.display="none";</script>'."\n";
285
-
286
- echo '<div class="updated"><p>'
287
- .sprintf(__('Counter entries until %s collected and counter table %s optimized (size before = %s &gt; size after = %s).', 'cpd'),
288
- $count_per_day->getLastCollectedMonth(), "<code>$wpdb->cpd_counter</code>", $sizeold, $sizenew)
289
- .'</p></div>';
290
- $count_per_day->flush_buffers();
291
- break;
292
-
293
- // reactivation
294
- case 'cpd_activate' :
295
- $count_per_day->checkVersion();
296
- echo '<div class="updated"><p>'.__('Installation of "Count per Day" checked', 'cpd').'</p></div>';
297
- break;
298
-
299
- default:
300
- break;
301
}
302
}
303
304
// delete one massbots per click on X
305
if ( isset($_GET['dmbip']) && isset($_GET['dmbdate']) )
306
- $count_per_day->mysqlQuery('', "DELETE FROM $wpdb->cpd_counter WHERE ip = '".$_GET['dmbip']."' AND date = '".$_GET['dmbdate']."'", 'deleteMassbot '.__LINE__);
307
308
if ( empty($mode) )
309
$mode = '';
@@ -321,8 +156,7 @@ switch($mode) {
321
break;
322
323
default:
324
-
325
- // show options page
326
327
$o = $count_per_day->options;
328
@@ -333,248 +167,210 @@ switch($mode) {
333
update_option('count_per_day', $o);
334
}
335
?>
336
- <div id="cpdsettings" class="wrap">
337
- <h2><img src="<?php echo $count_per_day->img('cpd_menu.gif') ?>" alt="" style="width:24px;height:24px" /> Count per Day</h2>
338
339
- <div id="poststuff" class="cpd_settings">
340
341
- <div class="postbox">
342
- <h3>
343
- <span class="cpd_icon cpd_settings"></span> <?php _e('Settings') ?> |
344
- <span class="cpd_icon cpd_tools"></span> <a href="#cpdtools"><?php _e('Tools') ?></a>
345
- </h3>
346
</div>
347
348
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
349
350
- <?php // counter ?>
351
- <fieldset>
352
- <legend><span class="cpd_icon cpd_settings"></span> <?php _e('Counter', 'cpd') ?></legend>
353
-
354
- <table class="form-table">
355
- <tr>
356
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Online time', 'cpd') ?>:</th>
357
- <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>
358
- </tr>
359
- <tr>
360
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Logged on Users', 'cpd') ?>:</th>
361
- <td>
362
- <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>
363
- - <?php _e('until User Level', 'cpd') ?>
364
- <select name="cpd_user_level">
365
- <option value="10" <?php selected($o['user_level'], 10) ?>><?php echo translate_user_role('Administrator') ?> (10)</option>
366
- <option value="7" <?php selected($o['user_level'], 7) ?>><?php echo translate_user_role('Editor') ?> (7)</option>
367
- <option value="2" <?php selected($o['user_level'], 2) ?>><?php echo translate_user_role('Author') ?> (2)</option>
368
- <option value="1" <?php selected($o['user_level'], 1) ?>><?php echo translate_user_role('Contributor') ?> (1)</option>
369
- <option value="0" <?php selected($o['user_level'], 0) ?>><?php echo translate_user_role('Subscriber') ?> (0)</option>
370
- </select>
371
- </td>
372
- </tr>
373
- <tr>
374
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Auto counter', 'cpd') ?>:</th>
375
- <td><label for="cpd_autocount"><input type="checkbox" name="cpd_autocount" id="cpd_autocount" <?php checked($o['autocount'], 1) ?> /> <?php _e('Counts automatically single-posts and pages, no changes on template needed.', 'cpd') ?></label></td>
376
- </tr>
377
- <tr>
378
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Bots to ignore', 'cpd') ?>:</th>
379
- <td><textarea name="cpd_bots" cols="50" rows="10"><?php echo $o['bots']; ?></textarea></td>
380
- </tr>
381
- <tr>
382
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Anonymous IP', 'cpd') ?>:</th>
383
- <td><label for="cpd_anoip"><input type="checkbox" name="cpd_anoip" id="cpd_anoip" <?php checked($o['anoip'], 1) ?> /> a.b.c.d &gt; a.b.c.x</label></td>
384
- </tr>
385
- <tr>
386
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Cache', 'cpd') ?> (beta):</th>
387
- <td><label for="cpd_ajax"><input type="checkbox" name="cpd_ajax" id="cpd_ajax" <?php checked($o['ajax'], 1) ?> /> <?php _e('I use a cache plugin. Count these visits with ajax.', 'cpd') ?></label></td>
388
- </tr>
389
- <tr>
390
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Clients and referrers', 'cpd') ?>:</th>
391
- <td>
392
- <label for="cpd_referers"><input type="checkbox" name="cpd_referers" id="cpd_referers" <?php checked($o['referers'], 1) ?> />
393
- <?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><br/>
394
- <label for="cpd_referers_cut"><input type="checkbox" name="cpd_referers_cut" id="cpd_referers_cut" <?php checked($o['referers_cut'], 1) ?> />
395
- <?php _e('Save URL only, no query string.', 'cpd') ?> <code>http://example.com/webhp?hl=de#sclient=psy&amp;hl=de...</code> &gt; <code>http://example.com/webhp</code></label>
396
- </td>
397
- </tr>
398
- </table>
399
- </fieldset>
400
-
401
- <?php // dashboard ?>
402
- <fieldset>
403
- <legend><span class="cpd_icon cpd_settings"></span> <?php _e('Dashboard') ?></legend>
404
-
405
- <script type="text/javascript">
406
- function checkcustom()
407
- {
408
- var b = document.getElementById('cpd_whocansee');
409
- var i = document.getElementById('cpd_whocansee_custom_div');
410
- if ( b.value == 'custom' )
411
- i.style.display = 'block';
412
- else
413
- i.style.display = 'none';
414
- }
415
- </script>
416
-
417
- <table class="form-table">
418
- <tr>
419
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Who can see it', 'cpd') ?>:</th>
420
- <td>
421
- <?php $cus = (in_array($o['whocansee'], array('manage_options','manage_links','publish_posts','edit_posts','read'))) ? 0 : 1 ?>
422
- <select id="cpd_whocansee" name="cpd_whocansee" onchange="checkcustom()">
423
- <option value="manage_options" <?php selected($o['whocansee'], 'manage_options') ?>><?php echo translate_user_role('Administrator') ?> </option>
424
- <option value="manage_links" <?php selected($o['whocansee'], 'manage_links') ?>><?php echo translate_user_role('Editor') ?></option>
425
- <option value="publish_posts" <?php selected($o['whocansee'], 'publish_posts') ?>><?php echo translate_user_role('Author') ?></option>
426
- <option value="edit_posts" <?php selected($o['whocansee'], 'edit_posts') ?>><?php echo translate_user_role('Contributor') ?></option>
427
- <option value="read" <?php selected($o['whocansee'], 'read') ?>><?php echo translate_user_role('Subscriber') ?></option>
428
- <option value="custom" <?php selected($cus) ?>>- <?php echo _e('custom', 'cpd') ?> -</option>
429
- </select>
430
- <?php _e('and higher are allowed to see the statistics page.', 'cpd') ?>
431
- <div id="cpd_whocansee_custom_div" <?php if (!$cus) echo 'style="display:none"' ?>>
432
- <?php printf(__('Set the %s capability %s a user need:', 'cpd'), '<a href="https://codex.wordpress.org/Roles_and_Capabilities">', '</a>'); ?>
433
- <input type="text" name="cpd_whocansee_custom" value="<?php echo $o['whocansee'] ?>" />
434
- </div>
435
- </td>
436
- </tr>
437
- <tr>
438
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Visitors per post', 'cpd') ?>:</th>
439
- <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>
440
- </tr>
441
- <tr>
442
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Latest Counts - Posts', 'cpd') ?>:</th>
443
- <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>
444
- </tr>
445
- <tr>
446
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Latest Counts - Days', 'cpd') ?>:</th>
447
- <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>
448
- </tr>
449
- <tr>
450
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Chart - Days', 'cpd') ?>:</th>
451
- <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>
452
- </tr>
453
- <tr>
454
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Chart - Height', 'cpd') ?>:</th>
455
- <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>
456
- </tr>
457
- <?php if ($cpd_geoip) { ?>
458
- <tr>
459
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Countries', 'cpd') ?>:</th>
460
- <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>
461
- </tr>
462
- <?php } ?>
463
- <tr>
464
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Browsers', 'cpd') ?>:</th>
465
- <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>
466
- </tr>
467
- <tr>
468
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Referrers - Entries', 'cpd') ?>:</th>
469
- <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>
470
- </tr>
471
- <tr>
472
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Referrers - Days', 'cpd') ?>:</th>
473
- <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>
474
- </tr>
475
- <tr>
476
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Local URLs', 'cpd') ?>:</th>
477
- <td><label for="cpd_localref"><input type="checkbox" name="cpd_localref" id="cpd_localref" <?php checked($o['localref'], 1) ?> /> <?php _e('Show local referrers too.', 'cpd') ?> (<?php echo bloginfo('url') ?>/...)</label></td>
478
- </tr>
479
- </table>
480
- </fieldset>
481
-
482
- <?php // lists ?>
483
- <fieldset>
484
- <legend><span class="cpd_icon cpd_settings"></span> <?php _e('Posts') ?> / <?php _e('Pages') ?></legend>
485
- <table class="form-table">
486
- <tr>
487
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Show in lists', 'cpd') ?>:</th>
488
- <td><label for="cpd_show_in_lists"><input type="checkbox" name="cpd_show_in_lists" id="cpd_show_in_lists" <?php checked($o['show_in_lists'], 1) ?> /> <?php _e('Show "Reads per Post" in a new column in post management views.', 'cpd') ?></label></td>
489
- </tr>
490
- </table>
491
- </fieldset>
492
-
493
- <?php // start values ?>
494
- <fieldset>
495
- <legend><span class="cpd_icon cpd_settings"></span> <?php _e('Start Values', 'cpd') ?></legend>
496
- <table class="form-table">
497
- <tr>
498
- <th colspan="2">
499
- <?php _e('Here you can change the date of first count and add a start count.', 'cpd')?>
500
- </th>
501
- </tr>
502
- <tr>
503
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Start date', 'cpd') ?>:</th>
504
- <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>
505
- </tr>
506
- <tr>
507
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Start count', 'cpd') ?>:</th>
508
- <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>
509
- </tr>
510
- <tr>
511
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Start count', 'cpd') ?>:</th>
512
- <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>
513
- </tr>
514
- </table>
515
- </fieldset>
516
-
517
- <?php // stylesheet ?>
518
- <fieldset>
519
- <legend><span class="cpd_icon cpd_settings"></span> <?php _e('Stylesheet', 'cpd') ?></legend>
520
- <table class="form-table">
521
- <tr>
522
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('NO Stylesheet in Frontend', 'cpd') ?>:</th>
523
- <td><label for="cpd_no_front_css"><input type="checkbox" name="cpd_no_front_css" id="cpd_no_front_css" <?php checked($o['no_front_css'], 1) ?> /> <?php _e('Do not load the stylesheet "counter.css" in frontend.', 'cpd') ?></label></td>
524
- </tr>
525
- </table>
526
- </fieldset>
527
-
528
- <?php // backup ?>
529
- <fieldset>
530
- <legend><span class="cpd_icon cpd_settings"></span> <?php _e('Backup', 'cpd') ?></legend>
531
- <table class="form-table">
532
- <tr>
533
- <th nowrap="nowrap" scope="row" style="vertical-align:middle;"><?php _e('Entries per pass', 'cpd') ?>:</th>
534
- <td>
535
- <input class="code" type="text" name="cpd_backup_part" size="10" value="<?php echo $o['backup_part']; ?>" />
536
- <?php _e('How many entries should be saved per pass? Default: 10000', 'cpd') ?><br/>
537
- </td>
538
- </tr>
539
- <tr>
540
- <td colspan="2">
541
- <?php _e('If your PHP memory limit less then 50 MB and you get a white page or error messages try a smaller value.', 'cpd') ?>
542
- </td>
543
- </tr>
544
- </table>
545
- </fieldset>
546
547
- <?php // debug ?>
548
- <fieldset>
549
- <legend style="color:red"><span class="cpd_icon cpd_settings"></span> <?php _e('Debug mode', 'cpd') ?></legend>
550
- <p style="margin-top:15px;margin-left:10px">
551
- <label for="cpd_debug"><input type="checkbox" name="cpd_debug" id="cpd_debug" <?php checked($o['debug'], 1) ?> /> <?php _e('Show debug informations at the bottom of all pages.', 'cpd') ?></label>
552
</p>
553
- </fieldset>
554
-
555
- <input type="hidden" name="do" value="cpd_update" />
556
- <input type="submit" name="update" value="<?php _e('Update options', 'cpd') ?>" class="button-primary" style="margin-left: 5px;" />
557
- </form>
558
-
559
- <div id="cpdtools" class="postbox" style="margin-top:40px">
560
- <h3><span class="cpd_icon cpd_settings"></span> <a href="#cpdsettings"><?php _e('Settings') ?></a> |
561
- <span class="cpd_icon cpd_tools"></span> <?php _e('Tools') ?></h3>
562
</div>
563
564
- <?php // mass bots ?>
565
<div class="postbox">
566
<?php
567
$limit = (isset($o['massbotlimit'])) ? $o['massbotlimit'] : 25;
568
$limit = (isset($_POST['limit'])) ? $_POST['limit'] : $limit;
569
$limit_input = '<input type="text" size="3" name="limit" value="'.$limit.'" />';
570
-
571
- if ( $limit == 0 )
572
- $limit = 50;
573
- $bots = $count_per_day->getMassBots( $limit );
574
?>
575
- <h3><span class="cpd_icon cpd_massbots"></span> <?php _e('Mass Bots', 'cpd') ?></h3>
576
<div class="inside">
577
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>#cpdtools">
578
<p>
579
<?php printf(__('Show all IPs with more than %s page views per day', 'cpd'), $limit_input) ?>
580
<input type="submit" name="showmassbots" value="<?php _e('show', 'cpd') ?>" class="button" />
@@ -588,35 +384,37 @@ switch($mode) {
588
<th><?php _e('IP', 'cpd') ?></th>
589
<th><?php _e('Date', 'cpd') ?></th>
590
<th><?php _e('Client', 'cpd') ?></th>
591
- <th style="text-align:right"><?php _e('Views', 'cpd') ?></th>
592
</tr>
593
</thead>
594
<?php
595
$sum = 0;
596
- foreach ($bots as $row)
597
- {
598
- $ip = $row->ip;
599
- echo '<tr><td style="white-space:nowrap">';
600
- if ( $cpd_geoip )
601
{
602
- $c = CpdGeoIp::getCountry($ip);
603
- echo $c[1].' &nbsp;';
604
}
605
- echo '<a href="?page=count-per-day/counter-options.php&amp;dmbip='.$row->longip.'&amp;dmbdate='.$row->date.'"
606
- title="'.sprintf(__('Delete these %s counts', 'cpd'), $row->posts).'"
607
- style="color:red; font-weight: bold;">X</a> &nbsp;';
608
- echo '<a href="http://www.utrace.de/?query='.$ip.'">'.$ip.'</a></td>'
609
- .'<td style="white-space:nowrap;">'.mysql2date(get_option('date_format'), $row->date).'</td>'
610
- .'<td>'.htmlentities($row->client).'</td>'
611
- .'<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">'
612
- .$row->posts.'</a></td>'
613
- .'</tr>';
614
- $sum += $row->posts;
615
- }
616
?>
617
</table>
618
<?php if ( $sum ) { ?>
619
- <p>
620
<input type="hidden" name="do" value="cpd_delete_massbots" />
621
<input type="hidden" name="limit" value="<?php echo $limit ?>" />
622
<input type="submit" name="clean" value="<?php printf(__('Delete these %s counts', 'cpd'), $sum) ?>" class="button" />
@@ -625,49 +423,18 @@ switch($mode) {
625
</form>
626
</div>
627
</div>
628
-
629
- <!-- left column -->
630
- <div class="cpd_halfsize" style="margin-right: 2%;">
631
-
632
- <!-- Backup -->
633
- <div class="postbox">
634
- <h3><span class="cpd_icon cpd_backup"></span> <?php _e('Backup', 'cpd') ?></h3>
635
- <div class="inside">
636
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
637
- <p>
638
- <?php printf(__('Create a backup of the counter table %s in your wp-content directory (if writable).', 'cpd'), '<code>'.$wpdb->cpd_counter.'</code>') ?>
639
- </p>
640
- <p>
641
- <input type="hidden" name="do" value="cpd_backup" />
642
- <input type="submit" name="backup" value="<?php _e('Backup the database', 'cpd') ?>" class="button" />
643
- </p>
644
- </form>
645
- <p>
646
- <?php
647
- if ( is_writable(WP_CONTENT_DIR) )
648
- {
649
- $d = dir(WP_CONTENT_DIR);
650
- while ( ($entry = $d->read()) !== false )
651
- if ( preg_match('/count_per_day|cpd_counter/i', $entry) )
652
- echo '<a href="'.content_url().'/'.$entry.'">'.$entry.'</a> - '.$count_per_day->formatbytes(filesize(WP_CONTENT_DIR.'/'.$entry)).'<br/>';
653
- $d->close();
654
- }
655
- ?>
656
- </p>
657
- </div>
658
- </div>
659
-
660
<!-- Cleaner -->
661
<?php if ( $count_per_day->options['referers'] ) : ?>
662
<div class="postbox">
663
- <h3><span class="cpd_icon cpd_clean"></span> <?php _e('Clean the database', 'cpd') ?></h3>
664
<div class="inside">
665
<p>
666
<?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') ?>
667
</p>
668
669
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
670
- <p>
671
<input type="hidden" name="do" value="cpd_clean" />
672
<input type="submit" name="clean" value="<?php _e('Clean the database', 'cpd') ?>" class="button" />
673
</p>
@@ -675,132 +442,28 @@ switch($mode) {
675
</div>
676
</div>
677
<?php endif; ?>
678
-
679
- <!-- Collect -->
680
- <div class="postbox">
681
- <h3><span class="cpd_icon cpd_collection"></span> <?php _e('Collect old data', 'cpd') ?></h3>
682
- <div class="inside">
683
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
684
- <p>
685
- <?php
686
- printf(__('Current size of your counter table %s is %s.', 'cpd'), '<code>'.$wpdb->cpd_counter.'</code>', $count_per_day->getTableSize($wpdb->cpd_counter));
687
- echo '<br/>';
688
- _e('You can collect old data and clean up the counter table.<br/>Reads and visitors will be saved per month, per country and per post.<br/>Clients and referrers will deleted.', 'cpd');
689
- echo '<br/>';
690
- $x = $count_per_day->getLastCollectedMonth();
691
- $m = __(date( 'F', strtotime($x.'-01'))).' '.substr($x, 0, 4);
692
- if ($x && $m)
693
- printf(__('Currently your collection contains data until %s.', 'cpd'), $m);
694
- ?>
695
- </p>
696
- <p>
697
- <?php _e('Normally new data will be added to the collection.', 'cpd') ?>
698
- </p>
699
- <?php if ($m) { ?>
700
- <p style="color:red">
701
- <input type="checkbox" name="cpd_new_collection" value="1" />
702
- <?php
703
- echo __('Delete old collection and create a new one which contains only the data currently in counter table.', 'cpd')
704
- .' '.sprintf(__('All collected data until %s will deleted.', 'cpd'), $m);
705
- ?>
706
- </p>
707
- <?php } ?>
708
- <p>
709
- <?php printf(__('Keep entries of last %s full months + current month in counter table.', 'cpd'), '<input type="text" size="2" name="cpd_keep_month" value="6" class="code" />') ?>
710
- </p>
711
- <p>
712
- <input type="hidden" name="do" value="cpd_collect" />
713
- <input type="submit" name="collect" value="<?php _e('Collect old data', 'cpd') ?>" class="button" />
714
- </p>
715
- </form>
716
- </div>
717
- </div>
718
-
719
- <!-- Plugin page -->
720
- <div class="postbox">
721
- <h3><span class="cpd_icon cpd_help"></span> <?php _e('Support', 'cpd') ?></h3>
722
- <div class="inside">
723
- <?php $count_per_day->cpdInfo() ?>
724
- </div>
725
- </div>
726
-
727
- </div> <!-- left column -->
728
-
729
- <!-- right column -->
730
- <div class="cpd_halfsize">
731
-
732
- <!-- Countries -->
733
- <div class="postbox">
734
- <h3><span class="cpd_icon cpd_geoip"></span> <?php _e('GeoIP - Countries', 'cpd') ?></h3>
735
- <div class="inside">
736
- <p>
737
- <?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') ?>
738
- </p>
739
- <?php if ( $cpd_geoip ) { ?>
740
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
741
- <p>
742
- <input type="hidden" name="do" value="cpd_countries" />
743
- <input type="submit" name="updcon" value="<?php _e('Update old counter data', 'cpd') ?>" class="button" />
744
- </p>
745
- </form>
746
- <?php } ?>
747
-
748
- <?php if ( class_exists('CpdGeoIp') && ini_get('allow_url_fopen') && function_exists('gzopen') ) {
749
- // install or update database
750
- echo '<p>'.__('Download a new version of GeoIP.dat file.', 'cpd').'</p>';
751
- ?>
752
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
753
- <p>
754
- <input type="hidden" name="do" value="cpd_countrydb" />
755
- <input type="submit" name="updcondb" value="<?php _e('Update GeoIP database', 'cpd') ?>" class="button" />
756
- </p>
757
- </form>
758
- <?php } ?>
759
- <p>
760
- <span class="cpd-r"><?php _e('More informations about GeoIP', 'cpd') ?>:
761
- <a href="http://www.maxmind.com/app/geoip_country">www.maxmind.com</a></span>&nbsp;
762
- </p>
763
- </div>
764
- </div>
765
766
- <!-- ReActivation -->
767
- <div class="postbox">
768
- <h3><span class="cpd_icon cpd_update"></span> <?php _e('ReActivation', 'cpd') ?></h3>
769
- <div class="inside">
770
- <p>
771
- <?php _e('Here you can start the installation functions manually.<br/>Same as deactivate and reactivate the plugin.', 'cpd') ?>
772
- </p>
773
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
774
- <p>
775
- <input type="hidden" name="do" value="cpd_activate" />
776
- <input type="submit" name="activate" value="<?php _e('ReActivate the plugin', 'cpd') ?>" class="button" />
777
- </p>
778
- </form>
779
- </div>
780
- </div>
781
-
782
<!-- Reset DBs -->
783
<div class="postbox">
784
- <h3><span class="cpd_icon cpd_reset"></span> <?php _e('Reset the counter', 'cpd') ?></h3>
785
<div class="inside">
786
<p style="color: red">
787
<?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') ?>
788
</p>
789
790
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
791
- <p>
792
<input type="hidden" name="do" value="cpd_reset" />
793
- <input type="checkbox" name="reset_cpd_yes" value="yes" />&nbsp;<?php _e('Yes', 'cpd'); ?> &nbsp;
794
- <input type="submit" name="clean" value="<?php _e('Reset the counter', 'cpd') ?>" class="button cpd_red" />
795
</p>
796
</form>
797
</div>
798
</div>
799
-
800
<!-- Uninstall -->
801
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
802
<div class="postbox">
803
- <h3><span class="cpd_icon cpd_uninstall"></span> <?php _e('Uninstall', 'cpd') ?></h3>
804
<div class="inside">
805
<p>
806
<?php _e('If "Count per Day" only disabled the tables in the database will be preserved.', 'cpd') ?><br/>
@@ -809,21 +472,28 @@ switch($mode) {
809
<p style="color: red">
810
<strong><?php _e('WARNING', 'cpd') ?>:</strong><br />
811
<?php _e('These tables (with ALL counter data) will be deleted.', 'cpd') ?><br />
812
- <b><?php echo $wpdb->cpd_counter ?></b><br />
813
<?php _e('If "Count per Day" re-installed, the counter starts at 0.', 'cpd') ?>
814
</p>
815
- <p>
816
- <input type="checkbox" name="uninstall_cpd_yes" value="yes" />&nbsp;<?php _e('Yes', 'cpd'); ?> &nbsp;
817
- <input type="submit" name="do" value="<?php _e('UNINSTALL Count per Day', 'cpd') ?>" class="button cpd_red" onclick="return confirm('<?php _e('You are sure to disable Count per Day and delete all data?', 'cpd') ?>')" />
818
</p>
819
</div>
820
</div>
821
</form>
822
823
- </div> <!-- right column -->
824
- <div class="clear"></div>
825
826
</div><!-- poststuff -->
827
</div><!-- wrap -->
828
829
- <?php } // End switch($mode)
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
35
if (empty($count_per_day->options['clients']))
36
+ $count_per_day->options['clients'] = 'Firefox, MSIE, Chrome, AppleWebKit, Opera';
37
38
if ( isset($_POST['cpd_countries']) )
39
$count_per_day->options['countries'] = $_POST['cpd_countries'];
40
41
update_option('count_per_day', $count_per_day->options);
42
43
+ echo '<div id="message" class="updated fade"><p>'.__('Options updated', 'cpd').'</p></div>';
44
break;
45
46
+ // update countries
47
+ case 'cpd_countries' :
48
+ if ( class_exists('CpdGeoIp') )
49
{
50
+ $count_per_day->queries[] = 'cpd_countries - class "CpdGeoIp" exists';
51
+ $rest = CpdGeoIp::updateDB();
52
+ echo '<div id="message" class="updated fade">
53
+ <form name="cpdcountries" method="post" action="'.$_SERVER['REQUEST_URI'].'">
54
+ <p>'.sprintf(__('Countries updated. <b>%s</b> entries in %s without country left', 'cpd'), $rest, CPD_C_TABLE);
55
+ if ( $rest > 100 )
56
+ {
57
+ // reload page per javascript until less than 100 entries without country
58
+ echo '<input type="hidden" name="do" value="cpd_countries" />
59
+ <input type="submit" name="updcon" value="'.__('update next', 'cpd').'" class="button" />';
60