Version Description
Download this release
Release Info
Developer | Tom Braider |
Plugin | Count per Day |
Version | 1.5 |
Comparing to | |
See all releases |
Code changes from version 1.4 to 1.5
- counter-options.php +5 -4
- counter.css +8 -11
- counter.php +165 -80
- readme.txt +27 -23
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
counter-options.php
CHANGED
@@ -83,9 +83,9 @@ switch($mode) {
|
|
83 |
<td><textarea name="cpd_bots" cols="50" rows="10"><?php echo get_option('cpd_bots'); ?></textarea></td>
|
84 |
</tr>
|
85 |
</table>
|
86 |
-
<p>
|
87 |
<input type="hidden" name="do" value="cpd_update" />
|
88 |
-
<input type="submit" name="update" value="<?php _e('Update options', 'cpd') ?>" class="button" />
|
89 |
</p>
|
90 |
</form>
|
91 |
</div>
|
@@ -100,7 +100,7 @@ switch($mode) {
|
|
100 |
</p>
|
101 |
|
102 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
|
103 |
-
<p>
|
104 |
<input type="hidden" name="do" value="cpd_clean" />
|
105 |
<input type="submit" name="clean" value="<?php _e('Clean the database', 'cpd') ?>" class="button" />
|
106 |
</p>
|
@@ -113,6 +113,7 @@ switch($mode) {
|
|
113 |
<div class="wrap" style="margin-top: 100px;">
|
114 |
<h2>Count per Day - <?php _e('Uninstall', 'cpd') ?></h2>
|
115 |
<p>
|
|
|
116 |
<?php _e('If "Count per Day" only disabled the tables in the database will be preserved.', 'cpd') ?><br/>
|
117 |
<?php _e('Here you can delete the tables and disable "Count per Day".', 'cpd') ?>
|
118 |
</p>
|
@@ -123,7 +124,7 @@ switch($mode) {
|
|
123 |
<?php _e('If "Count per Day" re-installed, the counter starts at 0.', 'cpd') ?>
|
124 |
</p>
|
125 |
<p> </p>
|
126 |
-
<p style="text-align: center;">
|
127 |
<input type="checkbox" name="uninstall_cpd_yes" value="yes" /> <?php _e('Yes', 'cpd'); ?><br /><br />
|
128 |
<input type="submit" name="do" value="<?php _e('UNINSTALL Count per Day', 'cpd') ?>" class="button" onclick="return confirm('<?php _e('You are sure to disable Count per Day and delete all data?', 'cpd') ?>')" />
|
129 |
</p>
|
83 |
<td><textarea name="cpd_bots" cols="50" rows="10"><?php echo get_option('cpd_bots'); ?></textarea></td>
|
84 |
</tr>
|
85 |
</table>
|
86 |
+
<p class="submit">
|
87 |
<input type="hidden" name="do" value="cpd_update" />
|
88 |
+
<input type="submit" name="update" value="<?php _e('Update options', 'cpd') ?>" class="button-primary" />
|
89 |
</p>
|
90 |
</form>
|
91 |
</div>
|
100 |
</p>
|
101 |
|
102 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
|
103 |
+
<p class="submit">
|
104 |
<input type="hidden" name="do" value="cpd_clean" />
|
105 |
<input type="submit" name="clean" value="<?php _e('Clean the database', 'cpd') ?>" class="button" />
|
106 |
</p>
|
113 |
<div class="wrap" style="margin-top: 100px;">
|
114 |
<h2>Count per Day - <?php _e('Uninstall', 'cpd') ?></h2>
|
115 |
<p>
|
116 |
+
<b><?php _e('Since WP 2.7 you can delete the plugin directly after deactivation on the plugins page.', 'cpd') ?></b><br />
|
117 |
<?php _e('If "Count per Day" only disabled the tables in the database will be preserved.', 'cpd') ?><br/>
|
118 |
<?php _e('Here you can delete the tables and disable "Count per Day".', 'cpd') ?>
|
119 |
</p>
|
124 |
<?php _e('If "Count per Day" re-installed, the counter starts at 0.', 'cpd') ?>
|
125 |
</p>
|
126 |
<p> </p>
|
127 |
+
<p class="submit" style="text-align: center;">
|
128 |
<input type="checkbox" name="uninstall_cpd_yes" value="yes" /> <?php _e('Yes', 'cpd'); ?><br /><br />
|
129 |
<input type="submit" name="do" value="<?php _e('UNINSTALL Count per Day', 'cpd') ?>" class="button" onclick="return confirm('<?php _e('You are sure to disable Count per Day and delete all data?', 'cpd') ?>')" />
|
130 |
</p>
|
counter.css
CHANGED
@@ -3,27 +3,24 @@
|
|
3 |
}
|
4 |
|
5 |
.cpd_table td {
|
6 |
-
padding:
|
7 |
vertical-align: top;
|
8 |
}
|
9 |
|
10 |
-
.cpd_table
|
11 |
-
|
12 |
-
border: 1px #ccc solid;
|
13 |
}
|
14 |
|
15 |
-
.cpd_table
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
}
|
20 |
|
21 |
-
.cpd_table span {
|
22 |
-
font-size: larger;
|
23 |
color: #f00;
|
24 |
}
|
25 |
|
26 |
.cpd_table ul {
|
27 |
-
padding-left: 10px;
|
28 |
list-style: none;
|
29 |
}
|
3 |
}
|
4 |
|
5 |
.cpd_table td {
|
6 |
+
padding-right: 10px;
|
7 |
vertical-align: top;
|
8 |
}
|
9 |
|
10 |
+
.cpd_table li {
|
11 |
+
color: #777;
|
|
|
12 |
}
|
13 |
|
14 |
+
.cpd_table li b {
|
15 |
+
font-family: Georgia,"Times New Roman",Times,serif;
|
16 |
+
color: #2583ad;
|
17 |
+
font-size: 18px;
|
18 |
}
|
19 |
|
20 |
+
.cpd_table li span {
|
|
|
21 |
color: #f00;
|
22 |
}
|
23 |
|
24 |
.cpd_table ul {
|
|
|
25 |
list-style: none;
|
26 |
}
|
counter.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Count Per Day
|
4 |
Plugin URI: http://www.tomsdimension.de/wp-plugins/count-per-day
|
5 |
Description: Counter, shows reads per page; today, yesterday, last week, last months ... on dashboard.
|
6 |
-
Version: 1.
|
7 |
License: GPL
|
8 |
Author: Tom Braider
|
9 |
Author URI: http://www.tomsdimension.de
|
@@ -29,7 +29,7 @@ function cpdShow( $before='', $after=' reads', $show = true, $count = true )
|
|
29 |
{
|
30 |
global $wpdb;
|
31 |
$page = get_the_ID();
|
32 |
-
//
|
33 |
if ( $count == true && get_option('cpd_autocount') == 0 )
|
34 |
cpdCount();
|
35 |
$visits = $wpdb->get_results("SELECT page FROM ".CPD_C_TABLE." WHERE page='$page';");
|
@@ -41,14 +41,14 @@ function cpdShow( $before='', $after=' reads', $show = true, $count = true )
|
|
41 |
}
|
42 |
|
43 |
/**
|
44 |
-
*
|
45 |
*/
|
46 |
function cpdCount()
|
47 |
{
|
48 |
global $wpdb;
|
49 |
-
cpdCreateTables(); //
|
50 |
|
51 |
-
//
|
52 |
if ( get_option('cpd_autocount') == 1 )
|
53 |
{
|
54 |
if (have_posts()) : while ( have_posts() && $page == 0 ) : the_post();
|
@@ -63,13 +63,13 @@ function cpdCount()
|
|
63 |
|
64 |
$countUser = ( get_option('cpd_user') == 0 && is_user_logged_in() == true ) ? 0 : 1;
|
65 |
|
66 |
-
//
|
67 |
if ( cpdIsBot() == false && !empty($page) && $countUser == 1 )
|
68 |
{
|
69 |
$userip = $_SERVER['REMOTE_ADDR'];
|
70 |
$client = $_SERVER['HTTP_USER_AGENT'];
|
71 |
$date = date('ymd');
|
72 |
-
// UserIP
|
73 |
$user_ip = $wpdb->get_results("SELECT * FROM ".CPD_C_TABLE." WHERE ip='$userip' AND date='$date' AND page='$page';");
|
74 |
if ( count($user_ip) == 0 )
|
75 |
$wpdb->query("INSERT INTO ".CPD_C_TABLE." (page, ip, client, date) VALUES ('"
|
@@ -85,13 +85,15 @@ function cpdCount()
|
|
85 |
}
|
86 |
|
87 |
/**
|
88 |
-
*
|
89 |
-
* @param string $client
|
|
|
90 |
*/
|
91 |
-
function cpdIsBot( $client = '' )
|
92 |
{
|
93 |
-
|
94 |
-
|
|
|
95 |
$isBot = false;
|
96 |
foreach ( $bots as $bot )
|
97 |
{
|
@@ -113,8 +115,9 @@ function cpdIsBot( $client = '' )
|
|
113 |
return $isBot;
|
114 |
}
|
115 |
|
|
|
116 |
/**
|
117 |
-
*
|
118 |
*/
|
119 |
function cpdCreateTables() {
|
120 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
@@ -122,7 +125,7 @@ function cpdCreateTables() {
|
|
122 |
|
123 |
if ( $wpdb->get_var( "SHOW TABLES LIKE '".CPD_C_TABLE."'" ) != CPD_C_TABLE )
|
124 |
{
|
125 |
-
//
|
126 |
$sql ="CREATE TABLE IF NOT EXISTS `".CPD_C_TABLE."` (
|
127 |
`id` int(10) NOT NULL auto_increment,
|
128 |
`ip` varchar(15) NOT NULL,
|
@@ -137,7 +140,7 @@ function cpdCreateTables() {
|
|
137 |
|
138 |
if ( $wpdb->get_var( "SHOW TABLES LIKE '".CPD_CO_TABLE."'" ) != CPD_CO_TABLE )
|
139 |
{
|
140 |
-
//
|
141 |
$sql ="CREATE TABLE IF NOT EXISTS `".CPD_CO_TABLE."` (
|
142 |
`timestamp` int(15) NOT NULL default '0',
|
143 |
`ip` varchar(15) NOT NULL default '',
|
@@ -155,46 +158,56 @@ function cpdCreateTables() {
|
|
155 |
"suchen.de\nsuchbaer.de\nshelob\nsemager\nxenu\nsuch_de\nia_archiver\nMicrosoft URL Control\nnetluchs" );
|
156 |
}
|
157 |
|
|
|
|
|
|
|
158 |
/**
|
159 |
-
*
|
160 |
*/
|
161 |
function cpdDashbord()
|
162 |
{
|
163 |
?>
|
164 |
<div class="wrap">
|
165 |
<h2>Count per Day - <?php _e('Statistics', 'cpd') ?></h2>
|
166 |
-
<table class="cpd_table">
|
167 |
-
<tr>
|
168 |
<td>
|
169 |
-
<
|
170 |
-
<
|
171 |
-
<
|
172 |
-
<
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
181 |
</td>
|
182 |
<td>
|
183 |
-
<
|
|
|
|
|
|
|
184 |
</td>
|
185 |
<td>
|
186 |
-
<
|
|
|
|
|
|
|
187 |
</td>
|
188 |
-
</tr>
|
189 |
-
|
190 |
</div>
|
191 |
<?php
|
192 |
}
|
193 |
|
194 |
-
//
|
195 |
|
196 |
/**
|
197 |
-
*
|
198 |
*/
|
199 |
function cpdGetUserOnline()
|
200 |
{
|
@@ -204,7 +217,7 @@ function cpdGetUserOnline()
|
|
204 |
}
|
205 |
|
206 |
/**
|
207 |
-
*
|
208 |
*/
|
209 |
function cpdGetUserAll()
|
210 |
{
|
@@ -214,7 +227,7 @@ function cpdGetUserAll()
|
|
214 |
}
|
215 |
|
216 |
/**
|
217 |
-
*
|
218 |
*/
|
219 |
function cpdGetUserToday()
|
220 |
{
|
@@ -225,7 +238,7 @@ function cpdGetUserToday()
|
|
225 |
}
|
226 |
|
227 |
/**
|
228 |
-
*
|
229 |
*/
|
230 |
function cpdGetUserYesterday()
|
231 |
{
|
@@ -236,7 +249,7 @@ function cpdGetUserYesterday()
|
|
236 |
}
|
237 |
|
238 |
/**
|
239 |
-
*
|
240 |
*/
|
241 |
function cpdGetUserLastWeek()
|
242 |
{
|
@@ -247,7 +260,7 @@ function cpdGetUserLastWeek()
|
|
247 |
}
|
248 |
|
249 |
/**
|
250 |
-
*
|
251 |
*/
|
252 |
function cpdGetUserPerMonth()
|
253 |
{
|
@@ -263,7 +276,7 @@ function cpdGetUserPerMonth()
|
|
263 |
}
|
264 |
|
265 |
/**
|
266 |
-
*
|
267 |
*
|
268 |
* @param integer $limit Sql-Limit, 0 = kein Limit
|
269 |
*/
|
@@ -284,12 +297,12 @@ function cpdGetUserPerPost( $limit = 0 )
|
|
284 |
$m = $wpdb->get_results($sql);
|
285 |
echo '<ul>';
|
286 |
foreach ( $m as $row )
|
287 |
-
echo '<li><a href="'.get_bloginfo('
|
288 |
echo '</ul>';
|
289 |
}
|
290 |
|
291 |
/**
|
292 |
-
*
|
293 |
*/
|
294 |
function cpdGetFirstCount()
|
295 |
{
|
@@ -301,7 +314,7 @@ function cpdGetFirstCount()
|
|
301 |
}
|
302 |
|
303 |
/**
|
304 |
-
*
|
305 |
*/
|
306 |
function cpdGetUserPerDay()
|
307 |
{
|
@@ -313,7 +326,7 @@ function cpdGetUserPerDay()
|
|
313 |
$max = strtotime( '20'.substr($row->max,0,2).'-'.substr($row->max,2,2).'-'.substr($row->max,4,2) );
|
314 |
$tage = (($max - $min) / 86400 + 1);
|
315 |
}
|
316 |
-
$v = $wpdb->get_results(
|
317 |
$count = count($v) / $tage;
|
318 |
if ( $count < 5 )
|
319 |
echo number_format($count, 2);
|
@@ -322,19 +335,20 @@ function cpdGetUserPerDay()
|
|
322 |
}
|
323 |
|
324 |
/**
|
325 |
-
*
|
326 |
*/
|
327 |
function cpdCleanDB()
|
328 |
{
|
329 |
global $wpdb;
|
330 |
|
|
|
331 |
$rows = 0;
|
332 |
-
$v = $wpdb->get_results(
|
333 |
foreach ($v as $row)
|
334 |
{
|
335 |
-
if ( cpdIsBot($row->client) )
|
336 |
{
|
337 |
-
$wpdb->query(
|
338 |
$rows++;
|
339 |
}
|
340 |
}
|
@@ -342,30 +356,65 @@ function cpdCleanDB()
|
|
342 |
}
|
343 |
|
344 |
/**
|
345 |
-
*
|
346 |
-
*
|
347 |
*/
|
348 |
function cpdAddCSS() {
|
349 |
-
|
|
|
|
|
350 |
}
|
351 |
|
|
|
|
|
|
|
|
|
352 |
/**
|
353 |
-
*
|
354 |
* @param string $content WP-"Content"
|
355 |
*/
|
356 |
function cpdMenu($content)
|
357 |
{
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
}
|
363 |
}
|
364 |
|
|
|
|
|
|
|
|
|
365 |
/**
|
366 |
-
*
|
367 |
*/
|
368 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
{
|
370 |
$locale = get_locale();
|
371 |
$mofile = dirname(__FILE__) . "/locale/".$locale.".mo";
|
@@ -373,25 +422,30 @@ function cpd_init_locale()
|
|
373 |
load_plugin_textdomain('cpd', dirname(__FILE__));
|
374 |
}
|
375 |
|
|
|
|
|
|
|
376 |
/**
|
377 |
-
*
|
378 |
-
* Zum reinen Z�hlen ist kein Eingriff ins Template mehr notwendig.
|
379 |
*/
|
380 |
-
function
|
381 |
{
|
382 |
if ( is_single() || is_page() )
|
383 |
cpdCount();
|
384 |
}
|
385 |
|
|
|
|
|
|
|
386 |
|
387 |
/**
|
388 |
-
*
|
389 |
*/
|
390 |
-
function
|
391 |
{
|
392 |
global $wpdb;
|
393 |
-
$wpdb->query(
|
394 |
-
$wpdb->query(
|
395 |
delete_option('cpd_cdb_version');
|
396 |
delete_option('cpd_codb_version');
|
397 |
delete_option('cpd_onlinetime');
|
@@ -400,21 +454,52 @@ function cpd_uninstall()
|
|
400 |
delete_option('cpd_bots');
|
401 |
}
|
402 |
|
403 |
-
// Funktionen adden
|
404 |
-
add_action('init', 'cpd_init_locale', 98);
|
405 |
-
add_action('admin_menu', 'cpdMenu');
|
406 |
-
register_activation_hook(__FILE__,'cpdCreateTables');
|
407 |
|
408 |
-
|
409 |
-
|
410 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
411 |
|
412 |
-
// Stylesheet nur bei Statistik-Seite laden
|
413 |
-
if ( eregi( "count-per-day", $_REQUEST['page']) )
|
414 |
-
add_action( 'admin_head', 'cpdAddCSS', 100 );
|
415 |
|
416 |
-
|
417 |
-
|
418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
|
420 |
?>
|
3 |
Plugin Name: Count Per Day
|
4 |
Plugin URI: http://www.tomsdimension.de/wp-plugins/count-per-day
|
5 |
Description: Counter, shows reads per page; today, yesterday, last week, last months ... on dashboard.
|
6 |
+
Version: 1.5
|
7 |
License: GPL
|
8 |
Author: Tom Braider
|
9 |
Author URI: http://www.tomsdimension.de
|
29 |
{
|
30 |
global $wpdb;
|
31 |
$page = get_the_ID();
|
32 |
+
// only count once
|
33 |
if ( $count == true && get_option('cpd_autocount') == 0 )
|
34 |
cpdCount();
|
35 |
$visits = $wpdb->get_results("SELECT page FROM ".CPD_C_TABLE." WHERE page='$page';");
|
41 |
}
|
42 |
|
43 |
/**
|
44 |
+
* shows visits (without counting)
|
45 |
*/
|
46 |
function cpdCount()
|
47 |
{
|
48 |
global $wpdb;
|
49 |
+
cpdCreateTables(); // create tables if necessary
|
50 |
|
51 |
+
// find PostID
|
52 |
if ( get_option('cpd_autocount') == 1 )
|
53 |
{
|
54 |
if (have_posts()) : while ( have_posts() && $page == 0 ) : the_post();
|
63 |
|
64 |
$countUser = ( get_option('cpd_user') == 0 && is_user_logged_in() == true ) ? 0 : 1;
|
65 |
|
66 |
+
// only count if: non bot, PostID exists, Logon is ok
|
67 |
if ( cpdIsBot() == false && !empty($page) && $countUser == 1 )
|
68 |
{
|
69 |
$userip = $_SERVER['REMOTE_ADDR'];
|
70 |
$client = $_SERVER['HTTP_USER_AGENT'];
|
71 |
$date = date('ymd');
|
72 |
+
// memorize UserIP
|
73 |
$user_ip = $wpdb->get_results("SELECT * FROM ".CPD_C_TABLE." WHERE ip='$userip' AND date='$date' AND page='$page';");
|
74 |
if ( count($user_ip) == 0 )
|
75 |
$wpdb->query("INSERT INTO ".CPD_C_TABLE." (page, ip, client, date) VALUES ('"
|
85 |
}
|
86 |
|
87 |
/**
|
88 |
+
* bot or human?
|
89 |
+
* @param string $client USER_AGENT
|
90 |
+
* @param array $bots strings to check
|
91 |
*/
|
92 |
+
function cpdIsBot( $client = '', $bots = '' )
|
93 |
{
|
94 |
+
if ( empty($bots) )
|
95 |
+
// load pattern
|
96 |
+
$bots = explode( "\n", get_option('cpd_bots') );
|
97 |
$isBot = false;
|
98 |
foreach ( $bots as $bot )
|
99 |
{
|
115 |
return $isBot;
|
116 |
}
|
117 |
|
118 |
+
|
119 |
/**
|
120 |
+
* create tables if not exists
|
121 |
*/
|
122 |
function cpdCreateTables() {
|
123 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
125 |
|
126 |
if ( $wpdb->get_var( "SHOW TABLES LIKE '".CPD_C_TABLE."'" ) != CPD_C_TABLE )
|
127 |
{
|
128 |
+
// table "counter" is not exists
|
129 |
$sql ="CREATE TABLE IF NOT EXISTS `".CPD_C_TABLE."` (
|
130 |
`id` int(10) NOT NULL auto_increment,
|
131 |
`ip` varchar(15) NOT NULL,
|
140 |
|
141 |
if ( $wpdb->get_var( "SHOW TABLES LIKE '".CPD_CO_TABLE."'" ) != CPD_CO_TABLE )
|
142 |
{
|
143 |
+
// table "counter-online" is not exists
|
144 |
$sql ="CREATE TABLE IF NOT EXISTS `".CPD_CO_TABLE."` (
|
145 |
`timestamp` int(15) NOT NULL default '0',
|
146 |
`ip` varchar(15) NOT NULL default '',
|
158 |
"suchen.de\nsuchbaer.de\nshelob\nsemager\nxenu\nsuch_de\nia_archiver\nMicrosoft URL Control\nnetluchs" );
|
159 |
}
|
160 |
|
161 |
+
register_activation_hook(__FILE__,'cpdCreateTables');
|
162 |
+
|
163 |
+
|
164 |
/**
|
165 |
+
* statistics page
|
166 |
*/
|
167 |
function cpdDashbord()
|
168 |
{
|
169 |
?>
|
170 |
<div class="wrap">
|
171 |
<h2>Count per Day - <?php _e('Statistics', 'cpd') ?></h2>
|
172 |
+
<table class="cpd_table"><tr>
|
|
|
173 |
<td>
|
174 |
+
<table class="widefat">
|
175 |
+
<thead><tr><th><?php _e('Reads at all', 'cpd') ?></th></tr></thead>
|
176 |
+
<tbody><tr><td>
|
177 |
+
<ul>
|
178 |
+
<li><?php _e('Reads at all', 'cpd') ?>: <b><span><?php cpdGetUserAll(); ?></span></b></li>
|
179 |
+
<li><?php _e('Visitors currently online', 'cpd') ?>: <b><span><?php cpdGetUserOnline(); ?></span></b></li>
|
180 |
+
<li><?php _e('Reads today', 'cpd') ?>: <b><?php cpdGetUserToday(); ?></b></li>
|
181 |
+
<li><?php _e('Reads yesterday', 'cpd') ?>: <b><?php cpdGetUserYesterday(); ?></b></li>
|
182 |
+
<li><?php _e('Reads last week', 'cpd') ?>: <b><?php cpdGetUserLastWeek(); ?></b></li>
|
183 |
+
<li><?php _e('Counter starts at', 'cpd') ?>: <b><?php cpdGetFirstCount(); ?></b></li>
|
184 |
+
<li>Ø <?php _e('Reads per day', 'cpd') ?>: <b><?php cpdGetUserPerDay(); ?></b></li>
|
185 |
+
</ul>
|
186 |
+
</td></tr></tbody>
|
187 |
+
</table>
|
188 |
</td>
|
189 |
<td>
|
190 |
+
<table class="widefat">
|
191 |
+
<thead><tr><th><?php _e('Reads per month', 'cpd') ?></th></tr></thead>
|
192 |
+
<tbody><tr><td><?php cpdGetUserPerMonth(); ?></td></tr></tbody>
|
193 |
+
</table>
|
194 |
</td>
|
195 |
<td>
|
196 |
+
<table class="widefat">
|
197 |
+
<thead><tr><th><?php _e('Reads per post', 'cpd') ?></th></tr></thead>
|
198 |
+
<tbody><tr><td><?php cpdGetUserPerPost(50); ?></td></tr></tbody>
|
199 |
+
</table>
|
200 |
</td>
|
201 |
+
</tr></table>
|
202 |
+
|
203 |
</div>
|
204 |
<?php
|
205 |
}
|
206 |
|
207 |
+
// statistic functions, you can use is in your template too
|
208 |
|
209 |
/**
|
210 |
+
* shows current visitors
|
211 |
*/
|
212 |
function cpdGetUserOnline()
|
213 |
{
|
217 |
}
|
218 |
|
219 |
/**
|
220 |
+
* shows all visitors
|
221 |
*/
|
222 |
function cpdGetUserAll()
|
223 |
{
|
227 |
}
|
228 |
|
229 |
/**
|
230 |
+
* shows today visitors
|
231 |
*/
|
232 |
function cpdGetUserToday()
|
233 |
{
|
238 |
}
|
239 |
|
240 |
/**
|
241 |
+
* shows yesterday visitors
|
242 |
*/
|
243 |
function cpdGetUserYesterday()
|
244 |
{
|
249 |
}
|
250 |
|
251 |
/**
|
252 |
+
* shows last week visitors (last 7 days)
|
253 |
*/
|
254 |
function cpdGetUserLastWeek()
|
255 |
{
|
260 |
}
|
261 |
|
262 |
/**
|
263 |
+
* shows visitors per month
|
264 |
*/
|
265 |
function cpdGetUserPerMonth()
|
266 |
{
|
276 |
}
|
277 |
|
278 |
/**
|
279 |
+
* shows visitors per post
|
280 |
*
|
281 |
* @param integer $limit Sql-Limit, 0 = kein Limit
|
282 |
*/
|
297 |
$m = $wpdb->get_results($sql);
|
298 |
echo '<ul>';
|
299 |
foreach ( $m as $row )
|
300 |
+
echo '<li><a href="'.get_bloginfo('url').'?p='.$row->post_id.'">'.$row->post.'</a>: <b>'.$row->count.'</b></li>'."\n";
|
301 |
echo '</ul>';
|
302 |
}
|
303 |
|
304 |
/**
|
305 |
+
* shows counter start, first day
|
306 |
*/
|
307 |
function cpdGetFirstCount()
|
308 |
{
|
314 |
}
|
315 |
|
316 |
/**
|
317 |
+
* shows averaged visitors per day
|
318 |
*/
|
319 |
function cpdGetUserPerDay()
|
320 |
{
|
326 |
$max = strtotime( '20'.substr($row->max,0,2).'-'.substr($row->max,2,2).'-'.substr($row->max,4,2) );
|
327 |
$tage = (($max - $min) / 86400 + 1);
|
328 |
}
|
329 |
+
$v = $wpdb->get_results('SELECT page FROM '.CPD_C_TABLE.' GROUP BY ip, date');
|
330 |
$count = count($v) / $tage;
|
331 |
if ( $count < 5 )
|
332 |
echo number_format($count, 2);
|
335 |
}
|
336 |
|
337 |
/**
|
338 |
+
* deletes spam in table, if you add new bot pattern you can clean the db
|
339 |
*/
|
340 |
function cpdCleanDB()
|
341 |
{
|
342 |
global $wpdb;
|
343 |
|
344 |
+
$bots = explode( "\n", get_option('cpd_bots') );
|
345 |
$rows = 0;
|
346 |
+
$v = $wpdb->get_results('SELECT * FROM '.CPD_C_TABLE);
|
347 |
foreach ($v as $row)
|
348 |
{
|
349 |
+
if ( cpdIsBot($row->client, $bots) )
|
350 |
{
|
351 |
+
$wpdb->query('DELETE FROM '.CPD_C_TABLE.' WHERE id = '.$row->id);
|
352 |
$rows++;
|
353 |
}
|
354 |
}
|
356 |
}
|
357 |
|
358 |
/**
|
359 |
+
* adds stylesheet
|
|
|
360 |
*/
|
361 |
function cpdAddCSS() {
|
362 |
+
$this_dir = get_bloginfo('wpurl').'/'.PLUGINDIR.'/'.dirname(plugin_basename(__FILE__));
|
363 |
+
wp_enqueue_style('cpd_css', $this_dir.'/counter.css', array());
|
364 |
+
wp_print_styles('cpd_css');
|
365 |
}
|
366 |
|
367 |
+
// only on statistics page
|
368 |
+
if ( eregi( 'count-per-day', $_REQUEST['page']) )
|
369 |
+
add_action( 'admin_head', 'cpdAddCSS', 100 );
|
370 |
+
|
371 |
/**
|
372 |
+
* adss menu
|
373 |
* @param string $content WP-"Content"
|
374 |
*/
|
375 |
function cpdMenu($content)
|
376 |
{
|
377 |
+
global $wp_version;
|
378 |
+
if (function_exists('add_options_page'))
|
379 |
+
{
|
380 |
+
$menutitle = '';
|
381 |
+
if ( version_compare( $wp_version, '2.6.999', '>' ) )
|
382 |
+
$menutitle = '<img src="'.cpdGetResource('cpd_menu_2.gif').'" alt="" /> ';
|
383 |
+
$menutitle .= 'Count per Day';
|
384 |
+
|
385 |
+
add_options_page('CountPerDay', $menutitle, 'manage_options', dirname(plugin_basename(__FILE__)).'/counter-options.php') ;
|
386 |
+
add_submenu_page('index.php','CountPerDay',$menutitle,1,__FILE__,'cpdDashbord');
|
387 |
+
|
388 |
+
// $plugin = plugin_basename(__FILE__);
|
389 |
+
// add_filter( 'plugin_action_links_' . $plugin, 'cpd_plugin_actions' );
|
390 |
+
|
391 |
}
|
392 |
}
|
393 |
|
394 |
+
if ( is_admin() )
|
395 |
+
add_action('admin_menu', 'cpdMenu');
|
396 |
+
|
397 |
+
|
398 |
/**
|
399 |
+
* adds an action link to the plugins page
|
400 |
*/
|
401 |
+
function cpdPluginActions($links, $file)
|
402 |
+
{
|
403 |
+
if( $file == plugin_basename(__FILE__) )
|
404 |
+
{
|
405 |
+
$link = '<a href="options-general.php?page='.dirname(plugin_basename(__FILE__)).'/counter-options.php">'.__('Settings').'</a>';
|
406 |
+
array_unshift( $links, $link );
|
407 |
+
}
|
408 |
+
return $links;
|
409 |
+
}
|
410 |
+
|
411 |
+
add_filter('plugin_action_links', 'cpdPluginActions', 10, 2);
|
412 |
+
|
413 |
+
|
414 |
+
/**
|
415 |
+
* adds locale support
|
416 |
+
*/
|
417 |
+
function cpdInitLocale()
|
418 |
{
|
419 |
$locale = get_locale();
|
420 |
$mofile = dirname(__FILE__) . "/locale/".$locale.".mo";
|
422 |
load_plugin_textdomain('cpd', dirname(__FILE__));
|
423 |
}
|
424 |
|
425 |
+
add_action('init', 'cpdInitLocale', 98);
|
426 |
+
|
427 |
+
|
428 |
/**
|
429 |
+
* loads automatic counter
|
|
|
430 |
*/
|
431 |
+
function cpdAutocount( )
|
432 |
{
|
433 |
if ( is_single() || is_page() )
|
434 |
cpdCount();
|
435 |
}
|
436 |
|
437 |
+
if ( get_option('cpd_autocount') == 1 )
|
438 |
+
add_action('wp', 'cpdAutocount');
|
439 |
+
|
440 |
|
441 |
/**
|
442 |
+
* uninstall functions, deletes tables and options
|
443 |
*/
|
444 |
+
function cpdUninstall()
|
445 |
{
|
446 |
global $wpdb;
|
447 |
+
$wpdb->query('DROP TABLE IF EXISTS '.CPD_C_TABLE);
|
448 |
+
$wpdb->query('DROP TABLE IF EXISTS '.CPD_CO_TABLE);
|
449 |
delete_option('cpd_cdb_version');
|
450 |
delete_option('cpd_codb_version');
|
451 |
delete_option('cpd_onlinetime');
|
454 |
delete_option('cpd_bots');
|
455 |
}
|
456 |
|
|
|
|
|
|
|
|
|
457 |
|
458 |
+
/**
|
459 |
+
* defines base64 encoded image recources
|
460 |
+
*/
|
461 |
+
if( isset($_GET['resource']) && !empty($_GET['resource'])) {
|
462 |
+
# base64 encoding
|
463 |
+
$resources = array(
|
464 |
+
'cpd_menu.gif' =>
|
465 |
+
'R0lGODlhDAAMAJECAHFxcUNDQ////wAAACH5BAEAAAIALAAAAA'.
|
466 |
+
'AMAAwAAAIdjI4ppsqNngA0PYDwZDrjUEGLGJGHBKFNwLYuWwAA'.
|
467 |
+
'Ow==',
|
468 |
+
'cpd_menu_2.gif' =>
|
469 |
+
'R0lGODlhDAAMAJECAP8AAAAAAP///wAAACH5BAEAAAIALAAAAA'.
|
470 |
+
'AMAAwAAAIdjI4ppsqNngA0PYDwZDrjUEGLGJGHBKFNwLYuWwAA'.
|
471 |
+
'Ow==');
|
472 |
+
|
473 |
+
if(array_key_exists($_GET['resource'], $resources)) {
|
474 |
+
|
475 |
+
$content = base64_decode($resources[ $_GET['resource'] ]);
|
476 |
+
|
477 |
+
$lastMod = filemtime(__FILE__);
|
478 |
+
$client = ( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false );
|
479 |
+
if (isset($client) && (strtotime($client) == $lastMod)) {
|
480 |
+
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $lastMod).' GMT', true, 304);
|
481 |
+
exit;
|
482 |
+
} else {
|
483 |
+
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $lastMod).' GMT', true, 200);
|
484 |
+
header('Content-Length: '.strlen($content));
|
485 |
+
header('Content-Type: image/' . substr(strrchr($_GET['resource'], '.'), 1) );
|
486 |
+
echo $content;
|
487 |
+
exit;
|
488 |
+
}
|
489 |
+
}
|
490 |
+
}
|
491 |
|
|
|
|
|
|
|
492 |
|
493 |
+
/**
|
494 |
+
* gets image recource with given name
|
495 |
+
*/
|
496 |
+
function cpdGetResource( $resourceID ) {
|
497 |
+
return trailingslashit( get_bloginfo('url') ) . '?resource=' . $resourceID;
|
498 |
+
}
|
499 |
+
|
500 |
+
// since WP 2.7
|
501 |
+
if ( function_exists('register_uninstall_hook') )
|
502 |
+
register_uninstall_hook(__FILE__, 'cpdUninstall');
|
503 |
+
|
504 |
|
505 |
?>
|
readme.txt
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
Contributors: Tom Braider
|
3 |
Donate link: http://www.unicef.org
|
4 |
Tags: counter, count, posts, visits, reads
|
5 |
-
Requires at least: 2.
|
6 |
-
Tested up to: 2.
|
7 |
-
Stable tag: 1.
|
8 |
|
9 |
Visit Counter, shows reads per page, visitors today, yesterday, last week, last months and other statistics.
|
10 |
|
@@ -14,6 +14,7 @@ Visit Counter, shows reads per page, visitors today, yesterday, last week, last
|
|
14 |
* shows reads per page
|
15 |
* shows visitors today, yesterday, last week, last months and other statistics on dashboard
|
16 |
* you can show these statistics on frontend (e.g. on sidebar) too
|
|
|
17 |
|
18 |
It counts 1 visit per IP per day. So any reload of the page don't increment the counter.
|
19 |
|
@@ -21,7 +22,7 @@ Languages: english, german, italian, portuguese
|
|
21 |
|
22 |
== Installation ==
|
23 |
|
24 |
-
1. unzip plugin directory into the
|
25 |
1. activate the plugin through the 'Plugins' menu in WordPress
|
26 |
|
27 |
First activation will create the 2 tables wp _ cpd _ counter and wp _ cpd _ counter _ useronline.
|
@@ -32,15 +33,14 @@ See the Options Page. It's easy. :)
|
|
32 |
|
33 |
If "Auto counter" is on reads on single-posts and pages will count without any changes on template.<br>
|
34 |
|
35 |
-
* place functions within post-loop (e.g. in single.php)<br
|
36 |
-
<?php if(function_exists(
|
37 |
* for more informations see "Other Notes"
|
38 |
|
39 |
== Frequently Asked Questions ==
|
40 |
|
41 |
-
=
|
42 |
-
|
43 |
-
no answers
|
44 |
|
45 |
== Screenshots ==
|
46 |
|
@@ -53,51 +53,51 @@ no answers
|
|
53 |
|
54 |
You can place these functions in your template.
|
55 |
|
56 |
-
|
57 |
|
58 |
-
* $before = text before number e.g.
|
59 |
-
* $after = text after number e.g.
|
60 |
* $show = true/false, "echo" complete string or "return" number only (standard true)
|
61 |
* $count = true/false, false will not count the reads (standard true)
|
62 |
|
63 |
-
|
64 |
|
65 |
* only count reads, without any output
|
66 |
* cpdShow call it
|
67 |
|
68 |
-
|
69 |
|
70 |
* shows date of first count
|
71 |
|
72 |
-
|
73 |
|
74 |
* shows average number of visitors per day
|
75 |
|
76 |
-
|
77 |
|
78 |
* shows number of total visitors
|
79 |
|
80 |
-
|
81 |
|
82 |
* shows number of visitors just online
|
83 |
|
84 |
-
|
85 |
|
86 |
* shows number of visitors today
|
87 |
|
88 |
-
|
89 |
|
90 |
* shows number of visitors yesterday
|
91 |
|
92 |
-
|
93 |
|
94 |
* shows number of visitors last week (7 days)
|
95 |
|
96 |
-
|
97 |
|
98 |
* lists number of visitors per month
|
99 |
|
100 |
-
|
101 |
|
102 |
* lists _$limit_ posts with number of visits
|
103 |
|
@@ -115,6 +115,10 @@ _cpdGetUserPerPost( $limit = 0 )_
|
|
115 |
|
116 |
**Changelog**
|
117 |
|
|
|
|
|
|
|
|
|
118 |
_Version 1.4_
|
119 |
|
120 |
+ NEW: uninstall function of WP 2.7 implemented
|
@@ -167,4 +171,4 @@ Functions:
|
|
167 |
+ cpdGetUserToday
|
168 |
+ cpdGetUserYesterday
|
169 |
+ cpdGetUserLastWeek
|
170 |
-
+ cpdGetUserPerMonth
|
2 |
Contributors: Tom Braider
|
3 |
Donate link: http://www.unicef.org
|
4 |
Tags: counter, count, posts, visits, reads
|
5 |
+
Requires at least: 2.7
|
6 |
+
Tested up to: 2.7
|
7 |
+
Stable tag: 1.5
|
8 |
|
9 |
Visit Counter, shows reads per page, visitors today, yesterday, last week, last months and other statistics.
|
10 |
|
14 |
* shows reads per page
|
15 |
* shows visitors today, yesterday, last week, last months and other statistics on dashboard
|
16 |
* you can show these statistics on frontend (e.g. on sidebar) too
|
17 |
+
* if you use Wordpress < 2.7 please use Count-per-Day v1.4
|
18 |
|
19 |
It counts 1 visit per IP per day. So any reload of the page don't increment the counter.
|
20 |
|
22 |
|
23 |
== Installation ==
|
24 |
|
25 |
+
1. unzip plugin directory into the '/wp-content/plugins/' directory
|
26 |
1. activate the plugin through the 'Plugins' menu in WordPress
|
27 |
|
28 |
First activation will create the 2 tables wp _ cpd _ counter and wp _ cpd _ counter _ useronline.
|
33 |
|
34 |
If "Auto counter" is on reads on single-posts and pages will count without any changes on template.<br>
|
35 |
|
36 |
+
* place functions within post-loop (e.g. in single.php)<br/>
|
37 |
+
'<?php if(function_exists("cpdShow")) { cpdShow(); } ?>'
|
38 |
* for more informations see "Other Notes"
|
39 |
|
40 |
== Frequently Asked Questions ==
|
41 |
|
42 |
+
= Need Help? Find Bug? =
|
43 |
+
read and write comments on <a href="http://www.tomsdimension.de/wp-plugins/count-per-day">plugin page</a>
|
|
|
44 |
|
45 |
== Screenshots ==
|
46 |
|
53 |
|
54 |
You can place these functions in your template.
|
55 |
|
56 |
+
'cpdShow( $before, $after, $show, $count )'
|
57 |
|
58 |
+
* $before = text before number e.g. '<p>' (standard "")
|
59 |
+
* $after = text after number e.g. 'reads</p>' (standard " reads")
|
60 |
* $show = true/false, "echo" complete string or "return" number only (standard true)
|
61 |
* $count = true/false, false will not count the reads (standard true)
|
62 |
|
63 |
+
'cpdCount()'
|
64 |
|
65 |
* only count reads, without any output
|
66 |
* cpdShow call it
|
67 |
|
68 |
+
'cpdGetFirstCount()'
|
69 |
|
70 |
* shows date of first count
|
71 |
|
72 |
+
'cpdGetUserPerDay()'
|
73 |
|
74 |
* shows average number of visitors per day
|
75 |
|
76 |
+
'cpdGetUserAll()'
|
77 |
|
78 |
* shows number of total visitors
|
79 |
|
80 |
+
'cpdGetUserOnline()'
|
81 |
|
82 |
* shows number of visitors just online
|
83 |
|
84 |
+
'cpdGetUserToday()'
|
85 |
|
86 |
* shows number of visitors today
|
87 |
|
88 |
+
'cpdGetUserYesterday()'
|
89 |
|
90 |
* shows number of visitors yesterday
|
91 |
|
92 |
+
'cpdGetUserLastWeek()'
|
93 |
|
94 |
* shows number of visitors last week (7 days)
|
95 |
|
96 |
+
'cpdGetUserPerMonth()'
|
97 |
|
98 |
* lists number of visitors per month
|
99 |
|
100 |
+
'cpdGetUserPerPost( $limit = 0 )'
|
101 |
|
102 |
* lists _$limit_ posts with number of visits
|
103 |
|
115 |
|
116 |
**Changelog**
|
117 |
|
118 |
+
_Version 1.5_
|
119 |
+
|
120 |
+
+ WP 2.7 optimized, for WP<2.7 please use CPD 1.4
|
121 |
+
|
122 |
_Version 1.4_
|
123 |
|
124 |
+ NEW: uninstall function of WP 2.7 implemented
|
171 |
+ cpdGetUserToday
|
172 |
+ cpdGetUserYesterday
|
173 |
+ cpdGetUserLastWeek
|
174 |
+
+ cpdGetUserPerMonth
|
screenshot-1.png
CHANGED
Binary file
|
screenshot-2.png
CHANGED
Binary file
|