Version Description
- Bugfix: mysql systax error
- Bugfix: no country data was stored (GeoIP), use "Update old counter data" on options page
Download this release
Release Info
Developer | Tom Braider |
Plugin | ![]() |
Version | 2.4.2 |
Comparing to | |
See all releases |
Code changes from version 3.0 to 2.4.2
- ajax.php +0 -32
- counter-core.php +0 -1233
- counter-options.php +175 -708
- counter-rtl.css +0 -20
- counter.css +0 -369
- counter.php +807 -1018
- geoip/GeoIP.dat +0 -0
- geoip/geoip.inc +91 -92
- geoip/geoip.php +110 -123
- img/cpd_blau.png +0 -0
- img/cpd_calendar.png +0 -0
- img/cpd_clients.png +0 -0
- img/cpd_flags.png +0 -0
- img/cpd_menu.gif +0 -0
- img/cpd_pen.png +0 -0
- img/cpd_rot.png +0 -0
- img/cpd_sprites.png +0 -0
- img/cpd_trans.png +0 -0
- js/excanvas.min.js +0 -1
- js/jquery.flot.min.js +0 -6
- locale/cpd-az_AZ.mo +0 -0
- locale/cpd-az_AZ.po +0 -972
- locale/cpd-be_BY.mo +0 -0
- locale/cpd-be_BY.po +0 -784
- locale/cpd-bg_BG.mo +0 -0
- locale/cpd-bg_BG.po +0 -972
- locale/cpd-by_BY.mo +0 -0
- locale/cpd-by_BY.po +284 -0
- locale/cpd-da_DK.mo +0 -0
- locale/cpd-da_DK.po +0 -973
- locale/cpd-de_DE.mo +0 -0
- locale/cpd-de_DE.po +124 -685
- locale/cpd-el.mo +0 -0
- locale/cpd-el.po +0 -973
- locale/cpd-es_ES.mo +0 -0
- locale/cpd-es_ES.po +0 -972
- locale/cpd-fr_FR.mo +0 -0
- locale/cpd-fr_FR.po +0 -971
- locale/cpd-it_IT.mo +0 -0
- locale/cpd-it_IT.po +142 -757
- locale/cpd-ja.mo +0 -0
- locale/cpd-ja.po +0 -972
- locale/cpd-lt_LT.mo +0 -0
- locale/cpd-lt_LT.po +0 -784
- locale/cpd-nb_NO.mo +0 -0
- locale/cpd-nb_NO.po +0 -972
- locale/cpd-nl_NL.mo +0 -0
- locale/cpd-nl_NL.po +0 -971
- locale/cpd-pl_PL.mo +0 -0
- locale/cpd-pl_PL.po +0 -972
- locale/cpd-pt_BR.mo +0 -0
- locale/cpd-pt_BR.po +54 -850
- locale/cpd-pt_PT.mo +0 -0
- locale/cpd-pt_PT.po +0 -971
- locale/cpd-ru_RU.mo +0 -0
- locale/cpd-ru_RU.po +0 -972
- locale/cpd-sv_SE.mo +0 -0
- locale/cpd-sv_SE.po +0 -972
- locale/cpd-tr_TR.mo +0 -0
- locale/cpd-tr_TR.po +0 -971
- locale/cpd-ua_UA.mo +0 -0
- locale/cpd-ua_UA.po +0 -972
- locale/cpd-uz_UZ.mo +0 -0
- locale/cpd-uz_UZ.po +411 -0
- map/ammap.swf +0 -0
- map/data.xml.php +0 -68
- map/map.php +0 -25
- map/settings.xml.php +0 -63
- map/swfobject.js +0 -8
- map/world.swf +0 -0
- massbots.php +0 -70
- notes.php +0 -121
- readme.txt +52 -344
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- screenshot-3.png +0 -0
- userperspan.php +0 -105
ajax.php
DELETED
@@ -1,32 +0,0 @@
|
|
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 );
|
17 |
-
foreach ( $cpd_funcs as $f )
|
18 |
-
{
|
19 |
-
if ( ($f == 'show' && $page) || $f != 'show' )
|
20 |
-
{
|
21 |
-
echo $f.'===';
|
22 |
-
if ( $f == 'getUserPerDay' )
|
23 |
-
eval('echo $count_per_day->getUserPerDay('.$count_per_day->options['dashboard_last_days'].');');
|
24 |
-
else if ( $f == 'show' )
|
25 |
-
eval('echo $count_per_day->show("", "", false, false, '.$page.');');
|
26 |
-
else
|
27 |
-
eval('echo $count_per_day->'.$f.'();');
|
28 |
-
echo '|';
|
29 |
-
}
|
30 |
-
}
|
31 |
-
}
|
32 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.' ';
|
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&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"> </span> '.__('Total visitors', 'cpd'), array(&$this,'dashboardReadsAtAll'), $this->pagehook, 'cpdrow1', 'core');
|
739 |
-
add_meta_box('user_online', '<span class="cpd_icon cpd_online"> </span> '.__('Visitors online', 'cpd'), array(&$this,'getUserOnlineMeta'), $this->pagehook, 'cpdrow1', 'default');
|
740 |
-
add_meta_box('user_per_month', '<span class="cpd_icon cpd_user"> </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"> </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"> </span> '.__('Visitors per post', 'cpd'), array(&$this,'getUserPerPostMeta'), $this->pagehook, 'cpdrow3', 'default');
|
743 |
-
add_meta_box('last_reads', '<span class="cpd_icon cpd_calendar"> </span> '.__('Latest Counts', 'cpd'), array(&$this,'getMostVisitedPostsMeta'), $this->pagehook, 'cpdrow4', 'default');
|
744 |
-
add_meta_box('day_reads', '<span class="cpd_icon cpd_day"> </span> '.__('Visitors per day', 'cpd'), array(&$this,'getVisitedPostsOnDayMeta'), $this->pagehook, 'cpdrow4', 'default');
|
745 |
-
add_meta_box('cpd_info', '<span class="cpd_icon cpd_help"> </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"> </span> '.__('Browsers', 'cpd'), array(&$this,'getClients'), $this->pagehook, 'cpdrow2', 'default');
|
749 |
-
add_meta_box('referers', '<span class="cpd_icon cpd_referrer"> </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"> </span> '.__('Reads per Country', 'cpd'), array(&$this,'getCountriesMeta'), $this->pagehook, 'cpdrow2', 'default');
|
754 |
-
add_meta_box('countries2', '<span class="cpd_icon cpd_user"> </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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
counter-options.php
CHANGED
@@ -13,7 +13,6 @@ if(!empty($_POST['do']))
|
|
13 |
case 'cpd_update' :
|
14 |
$count_per_day->options['onlinetime'] = $_POST['cpd_onlinetime'];
|
15 |
$count_per_day->options['user'] = empty( $_POST['cpd_user'] ) ? 0 : 1 ;
|
16 |
-
$count_per_day->options['user_level'] = $_POST['cpd_user_level'];
|
17 |
$count_per_day->options['autocount'] = empty( $_POST['cpd_autocount'] ) ? 0 : 1 ;
|
18 |
$count_per_day->options['bots'] = $_POST['cpd_bots'];
|
19 |
$count_per_day->options['dashboard_posts'] = $_POST['cpd_dashboard_posts'];
|
@@ -22,298 +21,93 @@ if(!empty($_POST['do']))
|
|
22 |
$count_per_day->options['show_in_lists'] = empty( $_POST['cpd_show_in_lists'] ) ? 0 : 1 ;
|
23 |
$count_per_day->options['chart_days'] = $_POST['cpd_chart_days'];
|
24 |
$count_per_day->options['chart_height'] = $_POST['cpd_chart_height'];
|
25 |
-
$count_per_day->options['startdate'] = $_POST['cpd_startdate'];
|
26 |
-
$count_per_day->options['startcount'] = $_POST['cpd_startcount'];
|
27 |
-
$count_per_day->options['startreads'] = $_POST['cpd_startreads'];
|
28 |
-
$count_per_day->options['anoip'] = empty( $_POST['cpd_anoip'] ) ? 0 : 1 ;
|
29 |
-
$count_per_day->options['clients'] = $_POST['cpd_clients'];
|
30 |
-
$count_per_day->options['ajax'] = empty( $_POST['cpd_ajax'] ) ? 0 : 1 ;
|
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 |
-
|
54 |
-
|
55 |
-
|
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 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
}
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
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 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
}
|
103 |
-
|
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 |
|