Version Description
- Umsortierung der Statistiktage
- Umfrbung der Statistikmarkierung
- Ignorierung der XMLRPC-Requests
Download this release
Release Info
Developer | sergej.mueller |
Plugin | Statify |
Version | 0.7 |
Comparing to | |
See all releases |
Version 0.7
- css/dashboard.css +1 -0
- css/dashboard.original.css +71 -0
- js/dashboard.js +3 -0
- js/dashboard.original.js +62 -0
- readme.txt +60 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- statify.original.php +965 -0
- statify.php +529 -0
css/dashboard.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
#statify_chart{height:120px}#statify_dashboard .table{margin:10px 0 0;position:relative}#statify_dashboard .table p.sub{color:#8f8f8f;margin:8px 0;position:absolute;font-size:14px}#statify_dashboard .table div{margin:33px 0 0;overflow:hidden;border-top:1px solid #ececec}#statify_dashboard .table.referrer{float:left;width:35%}#statify_dashboard .table.target{float:right;width:55%}#statify_dashboard .inside{height:1%;margin:10px 0;overflow:hidden;position:relative}#statify_dashboard td.b{font:normal 18px Georgia,"Times New Roman","Bitstream Charter",Times,serif;text-align:right;padding-right:6px}#statify_dashboard table td{padding:1px 0;white-space:nowrap}#statify_dashboard table tr.first td{border-top:0}#statify_dashboard td.first,#statify_dashboard td.last{width:1px}#statify_dashboard .t{color:#777;font-size:12px;padding-top:6px;padding-right:12px}#statify_dashboard td.b a{font-size:18px}#statify_dashboard tr.first td{border:0}#statify_dashboard .form-table{margin:0 0 .5em}
|
css/dashboard.original.css
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* @group Frontend */
|
2 |
+
|
3 |
+
#statify_chart {
|
4 |
+
height: 120px;
|
5 |
+
}
|
6 |
+
|
7 |
+
#statify_dashboard .table {
|
8 |
+
margin: 10px 0 0;
|
9 |
+
position: relative;
|
10 |
+
}
|
11 |
+
#statify_dashboard .table p.sub {
|
12 |
+
color: #8F8F8F;
|
13 |
+
margin: 8px 0;
|
14 |
+
position: absolute;
|
15 |
+
font-size: 14px;
|
16 |
+
}
|
17 |
+
#statify_dashboard .table div {
|
18 |
+
margin: 31px 0 0;
|
19 |
+
overflow: hidden;
|
20 |
+
border-top: 1px solid #ececec;
|
21 |
+
}
|
22 |
+
|
23 |
+
#statify_dashboard .table.referrer {
|
24 |
+
float: left;
|
25 |
+
width: 35%;
|
26 |
+
}
|
27 |
+
#statify_dashboard .table.target {
|
28 |
+
float: right;
|
29 |
+
width: 55%;
|
30 |
+
}
|
31 |
+
#statify_dashboard .inside {
|
32 |
+
height: 1%;
|
33 |
+
margin: 10px 0;
|
34 |
+
overflow: hidden;
|
35 |
+
position: relative;
|
36 |
+
}
|
37 |
+
|
38 |
+
#statify_dashboard td.b {
|
39 |
+
font: normal 18px Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
|
40 |
+
text-align: right;
|
41 |
+
padding-right: 6px;
|
42 |
+
}
|
43 |
+
#statify_dashboard table td {
|
44 |
+
padding: 2px 0;
|
45 |
+
white-space: nowrap;
|
46 |
+
}
|
47 |
+
#statify_dashboard table tr.first td {
|
48 |
+
border-top: none;
|
49 |
+
}
|
50 |
+
#statify_dashboard td.first,
|
51 |
+
#statify_dashboard td.last {
|
52 |
+
width: 1px;
|
53 |
+
}
|
54 |
+
#statify_dashboard .t {
|
55 |
+
color: #777;
|
56 |
+
font-size: 12px;
|
57 |
+
padding-top: 6px;
|
58 |
+
padding-right: 12px;
|
59 |
+
}
|
60 |
+
#statify_dashboard td.b a {
|
61 |
+
font-size: 18px;
|
62 |
+
}
|
63 |
+
#statify_dashboard tr.first td {
|
64 |
+
border: none;
|
65 |
+
}
|
66 |
+
|
67 |
+
#statify_dashboard .form-table {
|
68 |
+
margin: 0 0 0.5em;
|
69 |
+
}
|
70 |
+
|
71 |
+
/* @end group */
|
js/dashboard.js
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
google.load("visualization","1",{packages:["corechart"]});google.setOnLoadCallback(drawChart);
|
2 |
+
function drawChart(){var a,c=[],d=document.getElementById("statify_chart"),b=new google.visualization.DataTable;if(d&&statify.created.length){var e=statify.created.split(","),f=statify.count.split(",");for(a in e)c[a]=[e[a],parseInt(f[a],10)];b.addColumn("string","Datum");b.addColumn("number","Aufrufe");b.addRows(c);(new google.visualization.AreaChart(d)).draw(b,{width:parseInt(jQuery("#statify_chart").parent().width(),10),height:120,legend:"none",pointSize:6,lineWidth:3,gridlineColor:"#ececec",colors:["#3399CC"],
|
3 |
+
reverseCategories:!0,backgroundColor:"transparent",vAxis:{baselineColor:"transparent",textPosition:"in",textStyle:{color:"#8F8F8F",fontSize:10}},hAxis:{textStyle:{color:"#3399CC",fontSize:10}},chartArea:{width:"100%",height:"100%"}})}};
|
js/dashboard.original.js
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
google.load("visualization", "1", {packages:["corechart"]});
|
2 |
+
google.setOnLoadCallback(drawChart);
|
3 |
+
|
4 |
+
function drawChart() {
|
5 |
+
/* Init */
|
6 |
+
var id,
|
7 |
+
rows = [],
|
8 |
+
output = document.getElementById('statify_chart'),
|
9 |
+
data = new google.visualization.DataTable();
|
10 |
+
|
11 |
+
/* Leer? */
|
12 |
+
if ( !output || !statify.created.length ) {
|
13 |
+
return;
|
14 |
+
}
|
15 |
+
|
16 |
+
/* Extrahieren */
|
17 |
+
var created = statify.created.split(','),
|
18 |
+
count = statify.count.split(',');
|
19 |
+
|
20 |
+
/* Loopen */
|
21 |
+
for (id in created) {
|
22 |
+
rows[id] = [created[id], parseInt(count[id], 10)];
|
23 |
+
}
|
24 |
+
|
25 |
+
data.addColumn('string', 'Datum');
|
26 |
+
data.addColumn('number', 'Aufrufe');
|
27 |
+
data.addRows(rows);
|
28 |
+
|
29 |
+
var chart = new google.visualization.AreaChart(output);
|
30 |
+
chart.draw(
|
31 |
+
data,
|
32 |
+
{
|
33 |
+
width: parseInt(jQuery('#statify_chart').parent().width(), 10),
|
34 |
+
height: 120,
|
35 |
+
legend: 'none',
|
36 |
+
pointSize: 6,
|
37 |
+
lineWidth: 3,
|
38 |
+
gridlineColor: '#ececec',
|
39 |
+
colors:['#3399CC'],
|
40 |
+
reverseCategories: true,
|
41 |
+
backgroundColor: 'transparent',
|
42 |
+
vAxis: {
|
43 |
+
baselineColor: 'transparent',
|
44 |
+
textPosition: 'in',
|
45 |
+
textStyle: {
|
46 |
+
color: '#8F8F8F',
|
47 |
+
fontSize: 10
|
48 |
+
}
|
49 |
+
},
|
50 |
+
hAxis: {
|
51 |
+
textStyle: {
|
52 |
+
color: '#3399CC',
|
53 |
+
fontSize: 10
|
54 |
+
}
|
55 |
+
},
|
56 |
+
chartArea: {
|
57 |
+
width: "100%",
|
58 |
+
height: "100%"
|
59 |
+
}
|
60 |
+
}
|
61 |
+
);
|
62 |
+
}
|
readme.txt
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Statify ===
|
2 |
+
Contributors: sergej.mueller
|
3 |
+
Tags: stats, analytics, privacy
|
4 |
+
Requires at least: 3.0
|
5 |
+
Tested up to: 3.3
|
6 |
+
Stable tag: trunk
|
7 |
+
|
8 |
+
Statify - Datenschutz-konformes Statistik-Plugin für WordPress.
|
9 |
+
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
= Kompakt und anonym: Statify Stats =
|
13 |
+
*Statify* konzentriert sich aufs Wesentliche: Auf dem Dashboard präsentiert das Plugin den aktuellen Verlauf der Seitenaufrufe in Form eines interaktiven Diagramms, gefolgt von jeweils einer Liste mit häufigsten Verweisen und meist aufgerufenen Zielseiten innerhalb des Blogs. Der Aufbewahrungs- bzw. Anzeige-Zeitraum sowie die Länge der Listen lassen sich nach Wünschen des WordPress-Nutzers direkt im Widget anpassen.
|
14 |
+
|
15 |
+
Im Vergleich zu anderen Statistik-Diensten wie Google Analytics oder WordPress.com Stats verarbeitet, speichert und überträgt *Statify* keinerlei personenbezogene Daten wie z.B. IP-Adressen der Besucher. Transparente Arbeitsweise: Eine lokal angelegte Datenbanktabelle besteht aus 4 Feldern: ID, Datum, Quelle, Ziel.
|
16 |
+
|
17 |
+
Die technische Seite des *Statify* erfordert keinen Einsatz von Cookies, Pixelgrafiken, JavaScript oder Flash. Das Statistik-Plugin schreibt Aufrufe jeder Blogseite mit, ausgeschlossen sind Preview-, Feed-, Ressourcen-Ansichten und angemeldete Nutzer.
|
18 |
+
|
19 |
+
Einsatzbereit auch auf WordPress Multisite Blogs.
|
20 |
+
Weitere Details und Informationen in der [Dokumentation](http://playground.ebiene.de/2661/statify-wordpress-statistik/ "Statify - WordPress Statistiken").
|
21 |
+
|
22 |
+
|
23 |
+
= Weiterführende Links =
|
24 |
+
* [Blog](http://playground.ebiene.de "Playground Blog")
|
25 |
+
* [Flattr](http://flattr.com/profile/sergej.mueller "Flattr")
|
26 |
+
* [Google+](https://plus.google.com/110569673423509816572 "Google+")
|
27 |
+
* [Portfolio](http://ebiene.de "Portfolio")
|
28 |
+
* [Andere Plugins](http://wpcoder.de "Andere Plugins")
|
29 |
+
|
30 |
+
|
31 |
+
== Changelog ==
|
32 |
+
= 0.7 =
|
33 |
+
* Umsortierung der Statistiktage
|
34 |
+
* Umfärbung der Statistikmarkierung
|
35 |
+
* Ignorierung der XMLRPC-Requests
|
36 |
+
|
37 |
+
= 0.6 =
|
38 |
+
* WordPress 3.2 Unterstützung
|
39 |
+
* Support für WordPress Multisite
|
40 |
+
* Bereinigung überflüssiger URL-Parameter bei Zielseiten
|
41 |
+
* Interaktive Statistik mit weiterführenden Informationen
|
42 |
+
|
43 |
+
= 0.5 =
|
44 |
+
* Fix: Abfrage für fehlende Referrer im Dashboard Widget
|
45 |
+
|
46 |
+
= 0.4 =
|
47 |
+
* Statify geht online
|
48 |
+
|
49 |
+
|
50 |
+
== Screenshots ==
|
51 |
+
|
52 |
+
1. Statify Dashboard Widget
|
53 |
+
2. Statify Dashboard Widget Optionen
|
54 |
+
|
55 |
+
|
56 |
+
== Installation ==
|
57 |
+
1. *Statify* installieren
|
58 |
+
1. [Dokumentation](http://playground.ebiene.de/2661/statify-wordpress-statistik/ "Statify - WordPress Statistiken") beachten
|
59 |
+
1. Dashboard aufrufen
|
60 |
+
1. Einstellungen im *Statify* Widget über *Konfigurieren* vornehmen
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.png
ADDED
Binary file
|
statify.original.php
ADDED
@@ -0,0 +1,965 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Statify
|
4 |
+
Text Domain: statify
|
5 |
+
Domain Path: /lang
|
6 |
+
Description: Kompakte, verständliche und datenschutzkonforme Statistik für WordPress.
|
7 |
+
Author: Sergej Müller
|
8 |
+
Author URI: http://www.wpSEO.org
|
9 |
+
Plugin URI: http://wpcoder.de
|
10 |
+
Version: 0.7
|
11 |
+
*/
|
12 |
+
|
13 |
+
|
14 |
+
/* Sicherheitsabfrage */
|
15 |
+
if ( !class_exists('WP') ) {
|
16 |
+
header('Status: 403 Forbidden');
|
17 |
+
header('HTTP/1.1 403 Forbidden');
|
18 |
+
exit();
|
19 |
+
}
|
20 |
+
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Statify
|
24 |
+
*
|
25 |
+
* @since 0.1
|
26 |
+
*/
|
27 |
+
|
28 |
+
class Statify
|
29 |
+
{
|
30 |
+
|
31 |
+
|
32 |
+
/* Save me */
|
33 |
+
private static $base;
|
34 |
+
private static $stats;
|
35 |
+
private static $limit = 3;
|
36 |
+
private static $days = 14;
|
37 |
+
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Konstruktor der Klasse
|
41 |
+
*
|
42 |
+
* @since 0.1
|
43 |
+
* @change 0.6
|
44 |
+
*/
|
45 |
+
|
46 |
+
public static function init()
|
47 |
+
{
|
48 |
+
/* Filter */
|
49 |
+
if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) or (defined('DOING_CRON') && DOING_CRON) or (defined('DOING_AJAX') && DOING_AJAX) or (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) ) {
|
50 |
+
return;
|
51 |
+
}
|
52 |
+
|
53 |
+
/* Plugin-Base */
|
54 |
+
self::$base = plugin_basename(__FILE__);
|
55 |
+
|
56 |
+
/* Tabelle Init */
|
57 |
+
Statify_Table::init();
|
58 |
+
|
59 |
+
/* BE */
|
60 |
+
if ( is_admin() ) {
|
61 |
+
add_action(
|
62 |
+
'wpmu_new_blog',
|
63 |
+
array(
|
64 |
+
__CLASS__,
|
65 |
+
'install_later'
|
66 |
+
)
|
67 |
+
);
|
68 |
+
add_action(
|
69 |
+
'delete_blog',
|
70 |
+
array(
|
71 |
+
__CLASS__,
|
72 |
+
'uninstall_later'
|
73 |
+
)
|
74 |
+
);
|
75 |
+
add_action(
|
76 |
+
'wp_dashboard_setup',
|
77 |
+
array(
|
78 |
+
__CLASS__,
|
79 |
+
'init_dashboard'
|
80 |
+
)
|
81 |
+
);
|
82 |
+
add_filter(
|
83 |
+
'plugin_row_meta',
|
84 |
+
array(
|
85 |
+
__CLASS__,
|
86 |
+
'init_meta'
|
87 |
+
),
|
88 |
+
10,
|
89 |
+
2
|
90 |
+
);
|
91 |
+
|
92 |
+
/* FE */
|
93 |
+
} else {
|
94 |
+
add_action(
|
95 |
+
'template_redirect',
|
96 |
+
array(
|
97 |
+
__CLASS__,
|
98 |
+
'db_push'
|
99 |
+
)
|
100 |
+
);
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Links in der Plugins-Verwaltung
|
107 |
+
*
|
108 |
+
* @since 0.5
|
109 |
+
* @change 0.6
|
110 |
+
*
|
111 |
+
* @param arr $links Array mit Links
|
112 |
+
* @param str $file Name des Plugins
|
113 |
+
* @return arr $links Array mit erweitertem Link
|
114 |
+
*/
|
115 |
+
|
116 |
+
public static function init_meta($links, $file)
|
117 |
+
{
|
118 |
+
if ( self::$base == $file ) {
|
119 |
+
return array_merge(
|
120 |
+
$links,
|
121 |
+
array(
|
122 |
+
'<a href="http://flattr.com/thing/148966/Statify-Plugin-fur-Datenschutz-konforme-Statistik-in-WordPress" target="_blank">Plugin flattern</a>'
|
123 |
+
)
|
124 |
+
);
|
125 |
+
}
|
126 |
+
|
127 |
+
return $links;
|
128 |
+
}
|
129 |
+
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Anzeige des Dashboard-Widgets
|
133 |
+
*
|
134 |
+
* @since 0.1
|
135 |
+
* @change 0.6
|
136 |
+
*/
|
137 |
+
|
138 |
+
public static function init_dashboard()
|
139 |
+
{
|
140 |
+
/* Filter */
|
141 |
+
if ( !current_user_can('administrator') ) {
|
142 |
+
return;
|
143 |
+
}
|
144 |
+
|
145 |
+
/* Vorbereiten */
|
146 |
+
self::_prepare_stats();
|
147 |
+
|
148 |
+
/* Widget */
|
149 |
+
wp_add_dashboard_widget(
|
150 |
+
'statify_dashboard',
|
151 |
+
'Statify',
|
152 |
+
array(
|
153 |
+
__CLASS__,
|
154 |
+
'front_view'
|
155 |
+
),
|
156 |
+
array(
|
157 |
+
__CLASS__,
|
158 |
+
'back_view'
|
159 |
+
)
|
160 |
+
);
|
161 |
+
|
162 |
+
/* CSS laden */
|
163 |
+
add_action(
|
164 |
+
'admin_head',
|
165 |
+
array(
|
166 |
+
__CLASS__,
|
167 |
+
'add_style'
|
168 |
+
)
|
169 |
+
);
|
170 |
+
|
171 |
+
/* JS laden */
|
172 |
+
add_action(
|
173 |
+
'wp_print_scripts',
|
174 |
+
array(
|
175 |
+
__CLASS__,
|
176 |
+
'add_js'
|
177 |
+
)
|
178 |
+
);
|
179 |
+
}
|
180 |
+
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Ausgabe der Stylesheets
|
184 |
+
*
|
185 |
+
* @since 0.1
|
186 |
+
* @change 0.6
|
187 |
+
*/
|
188 |
+
|
189 |
+
public static function add_style()
|
190 |
+
{
|
191 |
+
/* PLugin-Info */
|
192 |
+
$plugin = get_plugin_data(__FILE__);
|
193 |
+
|
194 |
+
/* CSS registrieren */
|
195 |
+
wp_register_style(
|
196 |
+
'statify',
|
197 |
+
plugins_url('/css/dashboard.css', __FILE__),
|
198 |
+
array(),
|
199 |
+
$plugin['Version']
|
200 |
+
);
|
201 |
+
|
202 |
+
/* CSS ausgeben */
|
203 |
+
wp_print_styles('statify');
|
204 |
+
}
|
205 |
+
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Ausgabe von JavaScript
|
209 |
+
*
|
210 |
+
* @since 0.1
|
211 |
+
* @change 0.6
|
212 |
+
*/
|
213 |
+
|
214 |
+
public static function add_js() {
|
215 |
+
/* Leer? */
|
216 |
+
if ( (!$stats = self::$stats) or empty($stats['visits']) ) {
|
217 |
+
return;
|
218 |
+
}
|
219 |
+
|
220 |
+
/* PLugin-Info */
|
221 |
+
$plugin = get_plugin_data(__FILE__);
|
222 |
+
|
223 |
+
/* Registrieren */
|
224 |
+
wp_register_script(
|
225 |
+
'statify',
|
226 |
+
plugins_url('/js/dashboard.js', __FILE__),
|
227 |
+
array(),
|
228 |
+
$plugin['Version']
|
229 |
+
);
|
230 |
+
wp_register_script(
|
231 |
+
'google_jsapi',
|
232 |
+
'http://www.google.com/jsapi',
|
233 |
+
false
|
234 |
+
);
|
235 |
+
|
236 |
+
/* Einbinden */
|
237 |
+
wp_enqueue_script('google_jsapi');
|
238 |
+
wp_enqueue_script('statify');
|
239 |
+
|
240 |
+
/* Übergeben */
|
241 |
+
wp_localize_script(
|
242 |
+
'statify',
|
243 |
+
'statify',
|
244 |
+
$stats['visits']
|
245 |
+
);
|
246 |
+
}
|
247 |
+
|
248 |
+
|
249 |
+
/**
|
250 |
+
* Rückgabe der Optionen
|
251 |
+
*
|
252 |
+
* @since 0.4
|
253 |
+
* @change 0.6
|
254 |
+
*
|
255 |
+
* @return arr $options Array mit Optionen
|
256 |
+
*/
|
257 |
+
|
258 |
+
private static function get_options()
|
259 |
+
{
|
260 |
+
/* Im Cache */
|
261 |
+
if ( $options = wp_cache_get('statify') ) {
|
262 |
+
return $options;
|
263 |
+
}
|
264 |
+
|
265 |
+
/* Zusammenführen */
|
266 |
+
$options = wp_parse_args(
|
267 |
+
get_option('statify'),
|
268 |
+
array(
|
269 |
+
'days' => self::$days,
|
270 |
+
'limit' => self::$limit
|
271 |
+
)
|
272 |
+
);
|
273 |
+
|
274 |
+
/* Ins Cache */
|
275 |
+
wp_cache_set(
|
276 |
+
'statify',
|
277 |
+
$options
|
278 |
+
);
|
279 |
+
|
280 |
+
return $options;
|
281 |
+
}
|
282 |
+
|
283 |
+
|
284 |
+
/**
|
285 |
+
* Ausgabe der Frontseite
|
286 |
+
*
|
287 |
+
* @since 0.1
|
288 |
+
* @change 0.6
|
289 |
+
*/
|
290 |
+
|
291 |
+
public static function front_view()
|
292 |
+
{
|
293 |
+
/* Leer? */
|
294 |
+
if ( (!$stats = self::$stats) or empty($stats['visits']) ) {
|
295 |
+
echo '<p>Heutige Werte werden erst gesammelt.</p>';
|
296 |
+
return;
|
297 |
+
} ?>
|
298 |
+
|
299 |
+
<div id="statify_chart"></div>
|
300 |
+
|
301 |
+
<?php if ( !empty($stats['target']) ) { ?>
|
302 |
+
<div class="table referrer">
|
303 |
+
<p class="sub">Top Referrer</p>
|
304 |
+
<div>
|
305 |
+
<table>
|
306 |
+
<?php if ( empty($stats['referrer']) ) { ?>
|
307 |
+
<tr>
|
308 |
+
<td>
|
309 |
+
Keine
|
310 |
+
</td>
|
311 |
+
</tr>
|
312 |
+
<?php } else { ?>
|
313 |
+
<?php foreach ($stats['referrer'] as $referrer) { ?>
|
314 |
+
<tr class="first">
|
315 |
+
<td class="first b">
|
316 |
+
<a href="<?php echo esc_url($referrer['url']) ?>" target="_blank"><?php echo intval($referrer['count']) ?></a>
|
317 |
+
</td>
|
318 |
+
<td class="t">
|
319 |
+
<a href="<?php echo esc_url($referrer['url']) ?>" target="_blank"><?php echo esc_url($referrer['host']) ?></a>
|
320 |
+
</td>
|
321 |
+
</tr>
|
322 |
+
<?php } ?>
|
323 |
+
<?php } ?>
|
324 |
+
</table>
|
325 |
+
</div>
|
326 |
+
</div>
|
327 |
+
|
328 |
+
<div class="table target">
|
329 |
+
<p class="sub">Top Ziele</p>
|
330 |
+
<div>
|
331 |
+
<table>
|
332 |
+
<?php foreach ($stats['target'] as $target) { ?>
|
333 |
+
<tr class="first">
|
334 |
+
<td class="b">
|
335 |
+
<a href="<?php echo esc_url($target['url']) ?>" target="_blank"><?php echo intval($target['count']) ?></a>
|
336 |
+
</td>
|
337 |
+
<td class="last t">
|
338 |
+
<a href="<?php echo home_url($target['url']) ?>" target="_blank"><?php echo esc_url($target['url']) ?></a>
|
339 |
+
</td>
|
340 |
+
</tr>
|
341 |
+
<?php } ?>
|
342 |
+
</table>
|
343 |
+
</div>
|
344 |
+
</div>
|
345 |
+
<?php } ?>
|
346 |
+
<?php }
|
347 |
+
|
348 |
+
|
349 |
+
/**
|
350 |
+
* Ausgabe der Backseite
|
351 |
+
*
|
352 |
+
* @since 0.4
|
353 |
+
* @change 0.6
|
354 |
+
*/
|
355 |
+
|
356 |
+
public static function back_view()
|
357 |
+
{
|
358 |
+
/* Speichern */
|
359 |
+
if ( !empty($_POST['statify']) ) {
|
360 |
+
/* Rechte */
|
361 |
+
if (!current_user_can('edit_plugins')) {
|
362 |
+
wp_die(__('Cheatin’ uh?'));
|
363 |
+
}
|
364 |
+
|
365 |
+
/* Formular-Referer */
|
366 |
+
check_admin_referer('_statify');
|
367 |
+
|
368 |
+
/* Save */
|
369 |
+
update_option(
|
370 |
+
'statify',
|
371 |
+
array(
|
372 |
+
'days' => (int)@$_POST['statify']['days'],
|
373 |
+
'limit' => (int)@$_POST['statify']['limit']
|
374 |
+
)
|
375 |
+
);
|
376 |
+
|
377 |
+
/* Entleeren */
|
378 |
+
delete_transient('statify');
|
379 |
+
}
|
380 |
+
|
381 |
+
/* Optionen */
|
382 |
+
$options = self::get_options();
|
383 |
+
|
384 |
+
/* Security */
|
385 |
+
wp_nonce_field('_statify'); ?>
|
386 |
+
|
387 |
+
<table class="form-table">
|
388 |
+
<tr>
|
389 |
+
<td>
|
390 |
+
<select name="statify[days]" id="statify_days">
|
391 |
+
<?php foreach(array(7, 10, 14, 20, 21, 28, 30) as $num) { ?>
|
392 |
+
<option <?php selected($options['days'], $num); ?>><?php echo $num; ?></option>
|
393 |
+
<?php } ?>
|
394 |
+
</select>
|
395 |
+
<label for="statify_days">Anzahl der Tage für Statistiken</label>
|
396 |
+
</td>
|
397 |
+
</tr>
|
398 |
+
<tr>
|
399 |
+
<td>
|
400 |
+
<select name="statify[limit]" id="statify_limit">
|
401 |
+
<?php foreach(range(0, 12) as $num) { ?>
|
402 |
+
<option <?php selected($options['limit'], $num); ?>><?php echo $num; ?></option>
|
403 |
+
<?php } ?>
|
404 |
+
</select>
|
405 |
+
<label for="statify_limit">Anzahl der Einträge in Listen</label>
|
406 |
+
</td>
|
407 |
+
</tr>
|
408 |
+
</table>
|
409 |
+
|
410 |
+
<?php
|
411 |
+
}
|
412 |
+
|
413 |
+
|
414 |
+
/**
|
415 |
+
* Installation des Plugins auch für MU-Blogs
|
416 |
+
*
|
417 |
+
* @since 0.1
|
418 |
+
* @change 0.6
|
419 |
+
*/
|
420 |
+
|
421 |
+
public static function install()
|
422 |
+
{
|
423 |
+
/* Global */
|
424 |
+
global $wpdb;
|
425 |
+
|
426 |
+
/* Multisite & Network */
|
427 |
+
if ( is_multisite() && !empty($_GET['networkwide']) ) {
|
428 |
+
/* Blog-IDs */
|
429 |
+
$ids = $wpdb->get_col(
|
430 |
+
$wpdb->prepare("SELECT blog_id FROM `$wpdb->blogs`")
|
431 |
+
);
|
432 |
+
|
433 |
+
/* Loopen */
|
434 |
+
foreach ($ids as $id) {
|
435 |
+
switch_to_blog( (int)$id );
|
436 |
+
self::_install_backend();
|
437 |
+
}
|
438 |
+
|
439 |
+
/* Wechsel zurück */
|
440 |
+
restore_current_blog();
|
441 |
+
|
442 |
+
} else {
|
443 |
+
self::_install_backend();
|
444 |
+
}
|
445 |
+
}
|
446 |
+
|
447 |
+
|
448 |
+
/**
|
449 |
+
* Installation des Plugins bei einem neuen MU-Blog
|
450 |
+
*
|
451 |
+
* @since 0.6
|
452 |
+
* @change 0.6
|
453 |
+
*/
|
454 |
+
|
455 |
+
public static function install_later($id) {
|
456 |
+
/* Kein Netzwerk-Plugin */
|
457 |
+
if ( !is_plugin_active_for_network(self::$base) ) {
|
458 |
+
return;
|
459 |
+
}
|
460 |
+
|
461 |
+
/* Wechsel */
|
462 |
+
switch_to_blog( (int)$id );
|
463 |
+
|
464 |
+
/* Installieren */
|
465 |
+
self::_install_backend();
|
466 |
+
|
467 |
+
/* Wechsel zurück */
|
468 |
+
restore_current_blog();
|
469 |
+
}
|
470 |
+
|
471 |
+
|
472 |
+
/**
|
473 |
+
* Eigentliche Installation der Option und der Tabelle
|
474 |
+
*
|
475 |
+
* @since 0.6
|
476 |
+
* @change 0.6
|
477 |
+
*/
|
478 |
+
|
479 |
+
private static function _install_backend()
|
480 |
+
{
|
481 |
+
/* Option */
|
482 |
+
add_option(
|
483 |
+
'statify',
|
484 |
+
array(),
|
485 |
+
'',
|
486 |
+
'no'
|
487 |
+
);
|
488 |
+
|
489 |
+
/* Reset */
|
490 |
+
delete_transient('statify');
|
491 |
+
|
492 |
+
/* Tabelle setzen */
|
493 |
+
Statify_Table::init();
|
494 |
+
|
495 |
+
/* Tabelle anlegen */
|
496 |
+
Statify_Table::create();
|
497 |
+
}
|
498 |
+
|
499 |
+
|
500 |
+
/**
|
501 |
+
* Uninstallation des Plugins pro MU-Blog
|
502 |
+
*
|
503 |
+
* @since 0.6
|
504 |
+
* @change 0.6
|
505 |
+
*/
|
506 |
+
|
507 |
+
public static function uninstall()
|
508 |
+
{
|
509 |
+
/* Global */
|
510 |
+
global $wpdb;
|
511 |
+
|
512 |
+
/* Multisite & Network */
|
513 |
+
if ( is_multisite() && !empty($_GET['networkwide']) ) {
|
514 |
+
/* Alter Blog */
|
515 |
+
$old = $wpdb->blogid;
|
516 |
+
|
517 |
+
/* Blog-IDs */
|
518 |
+
$ids = $wpdb->get_col(
|
519 |
+
$wpdb->prepare("SELECT blog_id FROM `$wpdb->blogs`")
|
520 |
+
);
|
521 |
+
|
522 |
+
/* Loopen */
|
523 |
+
foreach ($ids as $id) {
|
524 |
+
switch_to_blog($id);
|
525 |
+
self::_uninstall_backend();
|
526 |
+
}
|
527 |
+
|
528 |
+
/* Wechsel zurück */
|
529 |
+
switch_to_blog($old);
|
530 |
+
} else {
|
531 |
+
self::_uninstall_backend();
|
532 |
+
}
|
533 |
+
}
|
534 |
+
|
535 |
+
|
536 |
+
/**
|
537 |
+
* Uninstallation des Plugins bei MU & Network-Plugin
|
538 |
+
*
|
539 |
+
* @since 0.6
|
540 |
+
* @change 0.6
|
541 |
+
*/
|
542 |
+
|
543 |
+
public static function uninstall_later($id) {
|
544 |
+
/* Global */
|
545 |
+
global $wpdb;
|
546 |
+
|
547 |
+
/* Kein Netzwerk-Plugin */
|
548 |
+
if ( !is_plugin_active_for_network(self::$base) ) {
|
549 |
+
return;
|
550 |
+
}
|
551 |
+
|
552 |
+
/* Wechsel */
|
553 |
+
switch_to_blog( (int)$id );
|
554 |
+
|
555 |
+
/* Installieren */
|
556 |
+
self::_uninstall_backend();
|
557 |
+
|
558 |
+
/* Wechsel zurück */
|
559 |
+
restore_current_blog();
|
560 |
+
}
|
561 |
+
|
562 |
+
|
563 |
+
/**
|
564 |
+
* Eigentliche Deinstallation des Plugins
|
565 |
+
*
|
566 |
+
* @since 0.6
|
567 |
+
* @change 0.6
|
568 |
+
*/
|
569 |
+
|
570 |
+
private static function _uninstall_backend()
|
571 |
+
{
|
572 |
+
/* Option */
|
573 |
+
delete_option('statify');
|
574 |
+
|
575 |
+
/* Transient */
|
576 |
+
delete_transient('statify');
|
577 |
+
|
578 |
+
/* Tabelle setzen */
|
579 |
+
Statify_Table::init();
|
580 |
+
|
581 |
+
/* Tabelle anlegen */
|
582 |
+
Statify_Table::drop();
|
583 |
+
}
|
584 |
+
|
585 |
+
|
586 |
+
/**
|
587 |
+
* Update des Plugins
|
588 |
+
*
|
589 |
+
* @since 0.6
|
590 |
+
* @change 0.6
|
591 |
+
*/
|
592 |
+
|
593 |
+
public static function update()
|
594 |
+
{
|
595 |
+
/* Updaten */
|
596 |
+
self::_update_backend();
|
597 |
+
}
|
598 |
+
|
599 |
+
|
600 |
+
/**
|
601 |
+
* Eigentlicher Update des Plugins
|
602 |
+
*
|
603 |
+
* @since 0.6
|
604 |
+
* @change 0.6
|
605 |
+
*/
|
606 |
+
|
607 |
+
private static function _update_backend()
|
608 |
+
{
|
609 |
+
/* Transient */
|
610 |
+
delete_transient('statify');
|
611 |
+
}
|
612 |
+
|
613 |
+
|
614 |
+
|
615 |
+
/**
|
616 |
+
* Speicherung der Werte in die DB
|
617 |
+
*
|
618 |
+
* @since 0.1
|
619 |
+
* @change 0.6
|
620 |
+
*/
|
621 |
+
|
622 |
+
public static function db_push()
|
623 |
+
{
|
624 |
+
/* Filter */
|
625 |
+
if ( is_feed() or is_trackback() or is_robots() or is_preview() or is_user_logged_in() or is_404() or self::_is_bot() ) {
|
626 |
+
return;
|
627 |
+
}
|
628 |
+
|
629 |
+
/* Global */
|
630 |
+
global $wpdb, $wp_rewrite;
|
631 |
+
|
632 |
+
/* Init */
|
633 |
+
$data = array();
|
634 |
+
$home = home_url();
|
635 |
+
|
636 |
+
/* Timestamp */
|
637 |
+
$data['created'] = strftime('%Y-%m-%d', current_time('timestamp'));
|
638 |
+
|
639 |
+
/* Referrer */
|
640 |
+
if ( !empty($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $home) === false ) {
|
641 |
+
$data['referrer'] = esc_url_raw($_SERVER['HTTP_REFERER']);
|
642 |
+
}
|
643 |
+
|
644 |
+
/* Referrer */
|
645 |
+
$data['target'] = str_replace(
|
646 |
+
$home,
|
647 |
+
'',
|
648 |
+
esc_url_raw(
|
649 |
+
home_url(
|
650 |
+
( empty($_SERVER['REQUEST_URI']) ? '/' : $_SERVER['REQUEST_URI'] )
|
651 |
+
)
|
652 |
+
)
|
653 |
+
);
|
654 |
+
|
655 |
+
/* Parameter entfernen */
|
656 |
+
if ( $wp_rewrite->permalink_structure && !is_search() ) {
|
657 |
+
$data['target'] = preg_replace('/\?.*/', '', $data['target']);
|
658 |
+
}
|
659 |
+
|
660 |
+
/* Insert */
|
661 |
+
$wpdb->insert(
|
662 |
+
$wpdb->statify,
|
663 |
+
$data
|
664 |
+
);
|
665 |
+
}
|
666 |
+
|
667 |
+
|
668 |
+
/**
|
669 |
+
* Prüfung auf Bots
|
670 |
+
*
|
671 |
+
* @since 0.1
|
672 |
+
* @change 0.6
|
673 |
+
*
|
674 |
+
* @return boolean TRUE, wenn Bot
|
675 |
+
*/
|
676 |
+
|
677 |
+
private static function _is_bot()
|
678 |
+
{
|
679 |
+
/* Leer? */
|
680 |
+
if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
|
681 |
+
return true;
|
682 |
+
}
|
683 |
+
|
684 |
+
/* Parsen */
|
685 |
+
if ( !preg_match('/(?:Windows|Mac OS X|Macintosh|Linux)/', $_SERVER['HTTP_USER_AGENT']) ) {
|
686 |
+
return true;
|
687 |
+
}
|
688 |
+
|
689 |
+
return false;
|
690 |
+
}
|
691 |
+
|
692 |
+
|
693 |
+
/**
|
694 |
+
* Bereinigung der veralteten Werte
|
695 |
+
*
|
696 |
+
* @since 0.3
|
697 |
+
* @change 0.6
|
698 |
+
*/
|
699 |
+
|
700 |
+
private static function _clean_data()
|
701 |
+
{
|
702 |
+
/* Überspringen? */
|
703 |
+
if ( get_transient('statify_cron') ) {
|
704 |
+
return;
|
705 |
+
}
|
706 |
+
|
707 |
+
/* Global */
|
708 |
+
global $wpdb;
|
709 |
+
|
710 |
+
/* Optionen */
|
711 |
+
$options = self::get_options();
|
712 |
+
|
713 |
+
/* Löschen */
|
714 |
+
$wpdb->query(
|
715 |
+
$wpdb->prepare(
|
716 |
+
"DELETE FROM `$wpdb->statify` WHERE created <= SUBDATE(CURDATE(), %d)",
|
717 |
+
$options['days']
|
718 |
+
)
|
719 |
+
);
|
720 |
+
|
721 |
+
/* DB optimieren */
|
722 |
+
$wpdb->query(
|
723 |
+
"OPTIMIZE TABLE `$wpdb->statify`"
|
724 |
+
);
|
725 |
+
|
726 |
+
/* Merken */
|
727 |
+
set_transient(
|
728 |
+
'statify_cron',
|
729 |
+
'ilovesweta',
|
730 |
+
60 * 60 * 12
|
731 |
+
);
|
732 |
+
}
|
733 |
+
|
734 |
+
|
735 |
+
/**
|
736 |
+
* Lesevorgang der Datenbank
|
737 |
+
*
|
738 |
+
* @since 0.1
|
739 |
+
* @change 0.7
|
740 |
+
*
|
741 |
+
* @return arr Array mit ausgelesenen Daten
|
742 |
+
*/
|
743 |
+
|
744 |
+
private static function _get_stats()
|
745 |
+
{
|
746 |
+
/* GLobal */
|
747 |
+
global $wpdb;
|
748 |
+
|
749 |
+
/* Optionen */
|
750 |
+
$options = self::get_options();
|
751 |
+
|
752 |
+
return array(
|
753 |
+
'visits' => $wpdb->get_results(
|
754 |
+
$wpdb->prepare(
|
755 |
+
"SELECT DATE_FORMAT(`created`, '%%d.%%m') as `date`, COUNT(`created`) as `count` FROM `$wpdb->statify` GROUP BY `created` ORDER BY `created` DESC LIMIT %d",
|
756 |
+
$options['days']
|
757 |
+
),
|
758 |
+
ARRAY_A
|
759 |
+
),
|
760 |
+
'target' => $wpdb->get_results(
|
761 |
+
$wpdb->prepare(
|
762 |
+
"SELECT COUNT(`target`) as `count`, `target` as `url` FROM `$wpdb->statify` GROUP BY `target` ORDER BY `count` DESC LIMIT %d",
|
763 |
+
$options['limit']
|
764 |
+
),
|
765 |
+
ARRAY_A
|
766 |
+
),
|
767 |
+
'referrer' => $wpdb->get_results(
|
768 |
+
$wpdb->prepare(
|
769 |
+
"SELECT COUNT(`referrer`) as `count`, `referrer` as `url`, SUBSTRING_INDEX(SUBSTRING_INDEX(TRIM(LEADING 'www.' FROM(TRIM(LEADING 'https://' FROM TRIM(LEADING 'http://' FROM TRIM(`referrer`))))), '/', 1), ':', 1) as `host` FROM `$wpdb->statify` WHERE `referrer` != '' GROUP BY `host` ORDER BY `count` DESC LIMIT %d",
|
770 |
+
$options['limit']
|
771 |
+
),
|
772 |
+
ARRAY_A
|
773 |
+
)
|
774 |
+
);
|
775 |
+
}
|
776 |
+
|
777 |
+
|
778 |
+
/**
|
779 |
+
* Verarbeitung und Caching der DB-Werte
|
780 |
+
*
|
781 |
+
* @since 0.1
|
782 |
+
* @change 0.7
|
783 |
+
*/
|
784 |
+
|
785 |
+
private static function _prepare_stats()
|
786 |
+
{
|
787 |
+
/* Im Cache? */
|
788 |
+
if ( ($stats = get_transient('statify')) && self::$stats = $stats ) {
|
789 |
+
return;
|
790 |
+
}
|
791 |
+
|
792 |
+
/* Bereinigen */
|
793 |
+
self::_clean_data();
|
794 |
+
|
795 |
+
/* Daten holen */
|
796 |
+
if ( !$stats = self::_get_stats() ) {
|
797 |
+
return;
|
798 |
+
}
|
799 |
+
|
800 |
+
/* Zwischenspeichern */
|
801 |
+
if ( !$visits = $stats['visits'] ) {
|
802 |
+
return;
|
803 |
+
}
|
804 |
+
|
805 |
+
/* Heute? */
|
806 |
+
if ( $visits[0]['date'] == date('d.m', current_time('timestamp')) ) {
|
807 |
+
$visits[0]['date'] = 'Heute';
|
808 |
+
}
|
809 |
+
|
810 |
+
/* Init */
|
811 |
+
$output = array(
|
812 |
+
'created' => array(),
|
813 |
+
'count' => array()
|
814 |
+
);
|
815 |
+
|
816 |
+
/* Zeilen loopen */
|
817 |
+
foreach($visits as $item) {
|
818 |
+
array_push($output['created'], $item['date']);
|
819 |
+
array_push($output['count'], $item['count']);
|
820 |
+
}
|
821 |
+
|
822 |
+
/* Zusammenfassen */
|
823 |
+
$stats['visits'] = array(
|
824 |
+
'created' => implode(',', $output['created']),
|
825 |
+
'count' => implode(',', $output['count'])
|
826 |
+
);
|
827 |
+
|
828 |
+
/* Cache */
|
829 |
+
set_transient(
|
830 |
+
'statify',
|
831 |
+
$stats,
|
832 |
+
60 * 15 // 15 Minuten
|
833 |
+
);
|
834 |
+
|
835 |
+
/* Lokal speichern */
|
836 |
+
self::$stats = $stats;
|
837 |
+
}
|
838 |
+
}
|
839 |
+
|
840 |
+
|
841 |
+
/**
|
842 |
+
* Statify Table
|
843 |
+
*
|
844 |
+
* @since 0.6
|
845 |
+
*/
|
846 |
+
|
847 |
+
class Statify_Table
|
848 |
+
{
|
849 |
+
|
850 |
+
|
851 |
+
/**
|
852 |
+
* Definition der Tabelle
|
853 |
+
*
|
854 |
+
* @since 0.6
|
855 |
+
* @change 0.6
|
856 |
+
*/
|
857 |
+
|
858 |
+
public function init()
|
859 |
+
{
|
860 |
+
/* Global */
|
861 |
+
global $wpdb;
|
862 |
+
|
863 |
+
/* Name */
|
864 |
+
$table = 'statify';
|
865 |
+
|
866 |
+
/* Als Array */
|
867 |
+
$wpdb->tables[] = $table;
|
868 |
+
|
869 |
+
/* Mit Prefix */
|
870 |
+
$wpdb->$table = $wpdb->get_blog_prefix() . $table;
|
871 |
+
}
|
872 |
+
|
873 |
+
|
874 |
+
/**
|
875 |
+
* Anlegen der Tabelle
|
876 |
+
*
|
877 |
+
* @since 0.6
|
878 |
+
* @change 0.6
|
879 |
+
*/
|
880 |
+
|
881 |
+
public function create()
|
882 |
+
{
|
883 |
+
/* Global */
|
884 |
+
global $wpdb;
|
885 |
+
|
886 |
+
/* Existenz prüfen */
|
887 |
+
if ( $wpdb->get_var("SHOW TABLES LIKE '$wpdb->statify'") == $wpdb->statify ) {
|
888 |
+
return;
|
889 |
+
}
|
890 |
+
|
891 |
+
/* Einbinden */
|
892 |
+
require_once(ABSPATH. 'wp-admin/includes/upgrade.php');
|
893 |
+
|
894 |
+
/* Anlegen */
|
895 |
+
dbDelta(
|
896 |
+
"CREATE TABLE `$wpdb->statify` (
|
897 |
+
`id` bigint(20) unsigned NOT NULL auto_increment,
|
898 |
+
`created` date NOT NULL default '0000-00-00',
|
899 |
+
`referrer` varchar(255) NOT NULL default '',
|
900 |
+
`target` varchar(255) NOT NULL default '',
|
901 |
+
PRIMARY KEY (`id`),
|
902 |
+
KEY `referrer` (`referrer`),
|
903 |
+
KEY `target` (`target`),
|
904 |
+
KEY `created` (`created`)
|
905 |
+
);"
|
906 |
+
);
|
907 |
+
}
|
908 |
+
|
909 |
+
|
910 |
+
/**
|
911 |
+
* Löschung der Tabelle
|
912 |
+
*
|
913 |
+
* @since 0.6
|
914 |
+
* @change 0.6
|
915 |
+
*/
|
916 |
+
|
917 |
+
public function drop()
|
918 |
+
{
|
919 |
+
/* Global */
|
920 |
+
global $wpdb;
|
921 |
+
|
922 |
+
/* Remove */
|
923 |
+
$wpdb->query("DROP TABLE IF EXISTS `$wpdb->statify`");
|
924 |
+
}
|
925 |
+
}
|
926 |
+
|
927 |
+
|
928 |
+
/* Fire */
|
929 |
+
add_action(
|
930 |
+
'plugins_loaded',
|
931 |
+
array(
|
932 |
+
'Statify',
|
933 |
+
'init'
|
934 |
+
)
|
935 |
+
);
|
936 |
+
|
937 |
+
|
938 |
+
/* Install */
|
939 |
+
register_activation_hook(
|
940 |
+
__FILE__,
|
941 |
+
array(
|
942 |
+
'Statify',
|
943 |
+
'install'
|
944 |
+
)
|
945 |
+
);
|
946 |
+
|
947 |
+
/* Uninstall */
|
948 |
+
register_uninstall_hook(
|
949 |
+
__FILE__,
|
950 |
+
array(
|
951 |
+
'Statify',
|
952 |
+
'uninstall'
|
953 |
+
)
|
954 |
+
);
|
955 |
+
|
956 |
+
/* Update */
|
957 |
+
if ( function_exists('register_update_hook') ) {
|
958 |
+
register_update_hook(
|
959 |
+
__FILE__,
|
960 |
+
array(
|
961 |
+
'Statify',
|
962 |
+
'update'
|
963 |
+
)
|
964 |
+
);
|
965 |
+
}
|
statify.php
ADDED
@@ -0,0 +1,529 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Statify
|
4 |
+
Text Domain: statify
|
5 |
+
Domain Path: /lang
|
6 |
+
Description: Kompakte, verständliche und datenschutzkonforme Statistik für WordPress.
|
7 |
+
Author: Sergej Müller
|
8 |
+
Author URI: http://www.wpSEO.org
|
9 |
+
Plugin URI: http://wpcoder.de
|
10 |
+
Version: 0.7
|
11 |
+
*/
|
12 |
+
|
13 |
+
|
14 |
+
if ( !class_exists('WP') ) {
|
15 |
+
header('Status: 403 Forbidden');
|
16 |
+
header('HTTP/1.1 403 Forbidden');
|
17 |
+
exit();
|
18 |
+
}
|
19 |
+
class Statify
|
20 |
+
{
|
21 |
+
private static $base;
|
22 |
+
private static $stats;
|
23 |
+
private static $limit = 3;
|
24 |
+
private static $days = 14;
|
25 |
+
public static function init()
|
26 |
+
{
|
27 |
+
if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) or (defined('DOING_CRON') && DOING_CRON) or (defined('DOING_AJAX') && DOING_AJAX) or (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) ) {
|
28 |
+
return;
|
29 |
+
}
|
30 |
+
self::$base = plugin_basename(__FILE__);
|
31 |
+
Statify_Table::init();
|
32 |
+
if ( is_admin() ) {
|
33 |
+
add_action(
|
34 |
+
'wpmu_new_blog',
|
35 |
+
array(
|
36 |
+
__CLASS__,
|
37 |
+
'install_later'
|
38 |
+
)
|
39 |
+
);
|
40 |
+
add_action(
|
41 |
+
'delete_blog',
|
42 |
+
array(
|
43 |
+
__CLASS__,
|
44 |
+
'uninstall_later'
|
45 |
+
)
|
46 |
+
);
|
47 |
+
add_action(
|
48 |
+
'wp_dashboard_setup',
|
49 |
+
array(
|
50 |
+
__CLASS__,
|
51 |
+
'init_dashboard'
|
52 |
+
)
|
53 |
+
);
|
54 |
+
add_filter(
|
55 |
+
'plugin_row_meta',
|
56 |
+
array(
|
57 |
+
__CLASS__,
|
58 |
+
'init_meta'
|
59 |
+
),
|
60 |
+
10,
|
61 |
+
2
|
62 |
+
);
|
63 |
+
} else {
|
64 |
+
add_action(
|
65 |
+
'template_redirect',
|
66 |
+
array(
|
67 |
+
__CLASS__,
|
68 |
+
'db_push'
|
69 |
+
)
|
70 |
+
);
|
71 |
+
}
|
72 |
+
}
|
73 |
+
public static function init_meta($links, $file)
|
74 |
+
{
|
75 |
+
if ( self::$base == $file ) {
|
76 |
+
return array_merge(
|
77 |
+
$links,
|
78 |
+
array(
|
79 |
+
'<a href="http://flattr.com/thing/148966/Statify-Plugin-fur-Datenschutz-konforme-Statistik-in-WordPress" target="_blank">Plugin flattern</a>'
|
80 |
+
)
|
81 |
+
);
|
82 |
+
}
|
83 |
+
return $links;
|
84 |
+
}
|
85 |
+
public static function init_dashboard()
|
86 |
+
{
|
87 |
+
if ( !current_user_can('administrator') ) {
|
88 |
+
return;
|
89 |
+
}
|
90 |
+
self::_prepare_stats();
|
91 |
+
wp_add_dashboard_widget(
|
92 |
+
'statify_dashboard',
|
93 |
+
'Statify',
|
94 |
+
array(
|
95 |
+
__CLASS__,
|
96 |
+
'front_view'
|
97 |
+
),
|
98 |
+
array(
|
99 |
+
__CLASS__,
|
100 |
+
'back_view'
|
101 |
+
)
|
102 |
+
);
|
103 |
+
add_action(
|
104 |
+
'admin_head',
|
105 |
+
array(
|
106 |
+
__CLASS__,
|
107 |
+
'add_style'
|
108 |
+
)
|
109 |
+
);
|
110 |
+
add_action(
|
111 |
+
'wp_print_scripts',
|
112 |
+
array(
|
113 |
+
__CLASS__,
|
114 |
+
'add_js'
|
115 |
+
)
|
116 |
+
);
|
117 |
+
}
|
118 |
+
public static function add_style()
|
119 |
+
{
|
120 |
+
$plugin = get_plugin_data(__FILE__);
|
121 |
+
wp_register_style(
|
122 |
+
'statify',
|
123 |
+
plugins_url('/css/dashboard.css', __FILE__),
|
124 |
+
array(),
|
125 |
+
$plugin['Version']
|
126 |
+
);
|
127 |
+
wp_print_styles('statify');
|
128 |
+
}
|
129 |
+
public static function add_js() {
|
130 |
+
if ( (!$stats = self::$stats) or empty($stats['visits']) ) {
|
131 |
+
return;
|
132 |
+
}
|
133 |
+
$plugin = get_plugin_data(__FILE__);
|
134 |
+
wp_register_script(
|
135 |
+
'statify',
|
136 |
+
plugins_url('/js/dashboard.js', __FILE__),
|
137 |
+
array(),
|
138 |
+
$plugin['Version']
|
139 |
+
);
|
140 |
+
wp_register_script(
|
141 |
+
'google_jsapi',
|
142 |
+
'http://www.google.com/jsapi',
|
143 |
+
false
|
144 |
+
);
|
145 |
+
wp_enqueue_script('google_jsapi');
|
146 |
+
wp_enqueue_script('statify');
|
147 |
+
wp_localize_script(
|
148 |
+
'statify',
|
149 |
+
'statify',
|
150 |
+
$stats['visits']
|
151 |
+
);
|
152 |
+
}
|
153 |
+
private static function get_options()
|
154 |
+
{
|
155 |
+
if ( $options = wp_cache_get('statify') ) {
|
156 |
+
return $options;
|
157 |
+
}
|
158 |
+
$options = wp_parse_args(
|
159 |
+
get_option('statify'),
|
160 |
+
array(
|
161 |
+
'days'=> self::$days,
|
162 |
+
'limit'=> self::$limit
|
163 |
+
)
|
164 |
+
);
|
165 |
+
wp_cache_set(
|
166 |
+
'statify',
|
167 |
+
$options
|
168 |
+
);
|
169 |
+
return $options;
|
170 |
+
}
|
171 |
+
public static function front_view()
|
172 |
+
{
|
173 |
+
if ( (!$stats = self::$stats) or empty($stats['visits']) ) {
|
174 |
+
echo '<p>Heutige Werte werden erst gesammelt.</p>';
|
175 |
+
return;
|
176 |
+
} ?>
|
177 |
+
<div id="statify_chart"></div>
|
178 |
+
<?php if ( !empty($stats['target']) ) { ?>
|
179 |
+
<div class="table referrer">
|
180 |
+
<p class="sub">Top Referrer</p>
|
181 |
+
<div>
|
182 |
+
<table>
|
183 |
+
<?php if ( empty($stats['referrer']) ) { ?>
|
184 |
+
<tr>
|
185 |
+
<td>
|
186 |
+
Keine
|
187 |
+
</td>
|
188 |
+
</tr>
|
189 |
+
<?php } else { ?>
|
190 |
+
<?php foreach ($stats['referrer'] as $referrer) { ?>
|
191 |
+
<tr class="first">
|
192 |
+
<td class="first b">
|
193 |
+
<a href="<?php echo esc_url($referrer['url']) ?>" target="_blank"><?php echo intval($referrer['count']) ?></a>
|
194 |
+
</td>
|
195 |
+
<td class="t">
|
196 |
+
<a href="<?php echo esc_url($referrer['url']) ?>" target="_blank"><?php echo esc_url($referrer['host']) ?></a>
|
197 |
+
</td>
|
198 |
+
</tr>
|
199 |
+
<?php } ?>
|
200 |
+
<?php } ?>
|
201 |
+
</table>
|
202 |
+
</div>
|
203 |
+
</div>
|
204 |
+
<div class="table target">
|
205 |
+
<p class="sub">Top Ziele</p>
|
206 |
+
<div>
|
207 |
+
<table>
|
208 |
+
<?php foreach ($stats['target'] as $target) { ?>
|
209 |
+
<tr class="first">
|
210 |
+
<td class="b">
|
211 |
+
<a href="<?php echo esc_url($target['url']) ?>" target="_blank"><?php echo intval($target['count']) ?></a>
|
212 |
+
</td>
|
213 |
+
<td class="last t">
|
214 |
+
<a href="<?php echo home_url($target['url']) ?>" target="_blank"><?php echo esc_url($target['url']) ?></a>
|
215 |
+
</td>
|
216 |
+
</tr>
|
217 |
+
<?php } ?>
|
218 |
+
</table>
|
219 |
+
</div>
|
220 |
+
</div>
|
221 |
+
<?php } ?>
|
222 |
+
<?php }
|
223 |
+
public static function back_view()
|
224 |
+
{
|
225 |
+
if ( !empty($_POST['statify']) ) {
|
226 |
+
if (!current_user_can('edit_plugins')) {
|
227 |
+
wp_die(__('Cheatin’ uh?'));
|
228 |
+
}
|
229 |
+
check_admin_referer('_statify');
|
230 |
+
update_option(
|
231 |
+
'statify',
|
232 |
+
array(
|
233 |
+
'days'=> (int)@$_POST['statify']['days'],
|
234 |
+
'limit'=> (int)@$_POST['statify']['limit']
|
235 |
+
)
|
236 |
+
);
|
237 |
+
delete_transient('statify');
|
238 |
+
}
|
239 |
+
$options = self::get_options();
|
240 |
+
wp_nonce_field('_statify'); ?>
|
241 |
+
<table class="form-table">
|
242 |
+
<tr>
|
243 |
+
<td>
|
244 |
+
<select name="statify[days]" id="statify_days">
|
245 |
+
<?php foreach(array(7, 10, 14, 20, 21, 28, 30) as $num) { ?>
|
246 |
+
<option <?php selected($options['days'], $num); ?>><?php echo $num; ?></option>
|
247 |
+
<?php } ?>
|
248 |
+
</select>
|
249 |
+
<label for="statify_days">Anzahl der Tage für Statistiken</label>
|
250 |
+
</td>
|
251 |
+
</tr>
|
252 |
+
<tr>
|
253 |
+
<td>
|
254 |
+
<select name="statify[limit]" id="statify_limit">
|
255 |
+
<?php foreach(range(0, 12) as $num) { ?>
|
256 |
+
<option <?php selected($options['limit'], $num); ?>><?php echo $num; ?></option>
|
257 |
+
<?php } ?>
|
258 |
+
</select>
|
259 |
+
<label for="statify_limit">Anzahl der Einträge in Listen</label>
|
260 |
+
</td>
|
261 |
+
</tr>
|
262 |
+
</table>
|
263 |
+
<?php
|
264 |
+
}
|
265 |
+
public static function install()
|
266 |
+
{
|
267 |
+
global $wpdb;
|
268 |
+
if ( is_multisite() && !empty($_GET['networkwide']) ) {
|
269 |
+
$ids = $wpdb->get_col(
|
270 |
+
$wpdb->prepare("SELECT blog_id FROM `$wpdb->blogs`")
|
271 |
+
);
|
272 |
+
foreach ($ids as $id) {
|
273 |
+
switch_to_blog( (int)$id );
|
274 |
+
self::_install_backend();
|
275 |
+
}
|
276 |
+
restore_current_blog();
|
277 |
+
} else {
|
278 |
+
self::_install_backend();
|
279 |
+
}
|
280 |
+
}
|
281 |
+
public static function install_later($id) {
|
282 |
+
if ( !is_plugin_active_for_network(self::$base) ) {
|
283 |
+
return;
|
284 |
+
}
|
285 |
+
switch_to_blog( (int)$id );
|
286 |
+
self::_install_backend();
|
287 |
+
restore_current_blog();
|
288 |
+
}
|
289 |
+
private static function _install_backend()
|
290 |
+
{
|
291 |
+
add_option(
|
292 |
+
'statify',
|
293 |
+
array(),
|
294 |
+
'',
|
295 |
+
'no'
|
296 |
+
);
|
297 |
+
delete_transient('statify');
|
298 |
+
Statify_Table::init();
|
299 |
+
Statify_Table::create();
|
300 |
+
}
|
301 |
+
public static function uninstall()
|
302 |
+
{
|
303 |
+
global $wpdb;
|
304 |
+
if ( is_multisite() && !empty($_GET['networkwide']) ) {
|
305 |
+
$old = $wpdb->blogid;
|
306 |
+
$ids = $wpdb->get_col(
|
307 |
+
$wpdb->prepare("SELECT blog_id FROM `$wpdb->blogs`")
|
308 |
+
);
|
309 |
+
foreach ($ids as $id) {
|
310 |
+
switch_to_blog($id);
|
311 |
+
self::_uninstall_backend();
|
312 |
+
}
|
313 |
+
switch_to_blog($old);
|
314 |
+
} else {
|
315 |
+
self::_uninstall_backend();
|
316 |
+
}
|
317 |
+
}
|
318 |
+
public static function uninstall_later($id) {
|
319 |
+
global $wpdb;
|
320 |
+
if ( !is_plugin_active_for_network(self::$base) ) {
|
321 |
+
return;
|
322 |
+
}
|
323 |
+
switch_to_blog( (int)$id );
|
324 |
+
self::_uninstall_backend();
|
325 |
+
restore_current_blog();
|
326 |
+
}
|
327 |
+
private static function _uninstall_backend()
|
328 |
+
{
|
329 |
+
delete_option('statify');
|
330 |
+
delete_transient('statify');
|
331 |
+
Statify_Table::init();
|
332 |
+
Statify_Table::drop();
|
333 |
+
}
|
334 |
+
public static function update()
|
335 |
+
{
|
336 |
+
self::_update_backend();
|
337 |
+
}
|
338 |
+
private static function _update_backend()
|
339 |
+
{
|
340 |
+
delete_transient('statify');
|
341 |
+
}
|
342 |
+
public static function db_push()
|
343 |
+
{
|
344 |
+
if ( is_feed() or is_trackback() or is_robots() or is_preview() or is_user_logged_in() or is_404() or self::_is_bot() ) {
|
345 |
+
return;
|
346 |
+
}
|
347 |
+
global $wpdb, $wp_rewrite;
|
348 |
+
$data = array();
|
349 |
+
$home = home_url();
|
350 |
+
$data['created'] = strftime('%Y-%m-%d', current_time('timestamp'));
|
351 |
+
if ( !empty($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $home) === false ) {
|
352 |
+
$data['referrer'] = esc_url_raw($_SERVER['HTTP_REFERER']);
|
353 |
+
}
|
354 |
+
$data['target'] = str_replace(
|
355 |
+
$home,
|
356 |
+
'',
|
357 |
+
esc_url_raw(
|
358 |
+
home_url(
|
359 |
+
( empty($_SERVER['REQUEST_URI']) ? '/' : $_SERVER['REQUEST_URI'] )
|
360 |
+
)
|
361 |
+
)
|
362 |
+
);
|
363 |
+
if ( $wp_rewrite->permalink_structure && !is_search() ) {
|
364 |
+
$data['target'] = preg_replace('/\?.*/', '', $data['target']);
|
365 |
+
}
|
366 |
+
$wpdb->insert(
|
367 |
+
$wpdb->statify,
|
368 |
+
$data
|
369 |
+
);
|
370 |
+
}
|
371 |
+
private static function _is_bot()
|
372 |
+
{
|
373 |
+
if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
|
374 |
+
return true;
|
375 |
+
}
|
376 |
+
if ( !preg_match('/(?:Windows|Mac OS X|Macintosh|Linux)/', $_SERVER['HTTP_USER_AGENT']) ) {
|
377 |
+
return true;
|
378 |
+
}
|
379 |
+
return false;
|
380 |
+
}
|
381 |
+
private static function _clean_data()
|
382 |
+
{
|
383 |
+
if ( get_transient('statify_cron') ) {
|
384 |
+
return;
|
385 |
+
}
|
386 |
+
global $wpdb;
|
387 |
+
$options = self::get_options();
|
388 |
+
$wpdb->query(
|
389 |
+
$wpdb->prepare(
|
390 |
+
"DELETE FROM `$wpdb->statify` WHERE created <= SUBDATE(CURDATE(), %d)",
|
391 |
+
$options['days']
|
392 |
+
)
|
393 |
+
);
|
394 |
+
$wpdb->query(
|
395 |
+
"OPTIMIZE TABLE `$wpdb->statify`"
|
396 |
+
);
|
397 |
+
set_transient(
|
398 |
+
'statify_cron',
|
399 |
+
'ilovesweta',
|
400 |
+
60 * 60 * 12
|
401 |
+
);
|
402 |
+
}
|
403 |
+
private static function _get_stats()
|
404 |
+
{
|
405 |
+
global $wpdb;
|
406 |
+
$options = self::get_options();
|
407 |
+
return array(
|
408 |
+
'visits' => $wpdb->get_results(
|
409 |
+
$wpdb->prepare(
|
410 |
+
"SELECT DATE_FORMAT(`created`, '%%d.%%m') as `date`, COUNT(`created`) as `count` FROM `$wpdb->statify` GROUP BY `created` ORDER BY `created` DESC LIMIT %d",
|
411 |
+
$options['days']
|
412 |
+
),
|
413 |
+
ARRAY_A
|
414 |
+
),
|
415 |
+
'target' => $wpdb->get_results(
|
416 |
+
$wpdb->prepare(
|
417 |
+
"SELECT COUNT(`target`) as `count`, `target` as `url` FROM `$wpdb->statify` GROUP BY `target` ORDER BY `count` DESC LIMIT %d",
|
418 |
+
$options['limit']
|
419 |
+
),
|
420 |
+
ARRAY_A
|
421 |
+
),
|
422 |
+
'referrer' => $wpdb->get_results(
|
423 |
+
$wpdb->prepare(
|
424 |
+
"SELECT COUNT(`referrer`) as `count`, `referrer` as `url`, SUBSTRING_INDEX(SUBSTRING_INDEX(TRIM(LEADING 'www.' FROM(TRIM(LEADING 'https://' FROM TRIM(LEADING 'http://' FROM TRIM(`referrer`))))), '/', 1), ':', 1) as `host` FROM `$wpdb->statify` WHERE `referrer` != '' GROUP BY `host` ORDER BY `count` DESC LIMIT %d",
|
425 |
+
$options['limit']
|
426 |
+
),
|
427 |
+
ARRAY_A
|
428 |
+
)
|
429 |
+
);
|
430 |
+
}
|
431 |
+
private static function _prepare_stats()
|
432 |
+
{
|
433 |
+
if ( ($stats = get_transient('statify')) && self::$stats = $stats ) {
|
434 |
+
return;
|
435 |
+
}
|
436 |
+
self::_clean_data();
|
437 |
+
if ( !$stats = self::_get_stats() ) {
|
438 |
+
return;
|
439 |
+
}
|
440 |
+
if ( !$visits = $stats['visits'] ) {
|
441 |
+
return;
|
442 |
+
}
|
443 |
+
if ( $visits[0]['date'] == date('d.m', current_time('timestamp')) ) {
|
444 |
+
$visits[0]['date'] = 'Heute';
|
445 |
+
}
|
446 |
+
$output = array(
|
447 |
+
'created' => array(),
|
448 |
+
'count' => array()
|
449 |
+
);
|
450 |
+
foreach($visits as $item) {
|
451 |
+
array_push($output['created'], $item['date']);
|
452 |
+
array_push($output['count'], $item['count']);
|
453 |
+
}
|
454 |
+
$stats['visits'] = array(
|
455 |
+
'created' => implode(',', $output['created']),
|
456 |
+
'count' => implode(',', $output['count'])
|
457 |
+
);
|
458 |
+
set_transient(
|
459 |
+
'statify',
|
460 |
+
$stats,
|
461 |
+
60 * 15);
|
462 |
+
self::$stats = $stats;
|
463 |
+
}
|
464 |
+
}
|
465 |
+
class Statify_Table
|
466 |
+
{
|
467 |
+
public function init()
|
468 |
+
{
|
469 |
+
global $wpdb;
|
470 |
+
$table = 'statify';
|
471 |
+
$wpdb->tables[] = $table;
|
472 |
+
$wpdb->$table = $wpdb->get_blog_prefix() . $table;
|
473 |
+
}
|
474 |
+
public function create()
|
475 |
+
{
|
476 |
+
global $wpdb;
|
477 |
+
if ( $wpdb->get_var("SHOW TABLES LIKE '$wpdb->statify'") == $wpdb->statify ) {
|
478 |
+
return;
|
479 |
+
}
|
480 |
+
require_once(ABSPATH. 'wp-admin/includes/upgrade.php');
|
481 |
+
dbDelta(
|
482 |
+
"CREATE TABLE `$wpdb->statify` (
|
483 |
+
`id` bigint(20) unsigned NOT NULL auto_increment,
|
484 |
+
`created` date NOT NULL default '0000-00-00',
|
485 |
+
`referrer` varchar(255) NOT NULL default '',
|
486 |
+
`target` varchar(255) NOT NULL default '',
|
487 |
+
PRIMARY KEY(`id`),
|
488 |
+
KEY `referrer` (`referrer`),
|
489 |
+
KEY `target` (`target`),
|
490 |
+
KEY `created` (`created`)
|
491 |
+
);"
|
492 |
+
);
|
493 |
+
}
|
494 |
+
public function drop()
|
495 |
+
{
|
496 |
+
global $wpdb;
|
497 |
+
$wpdb->query("DROP TABLE IF EXISTS `$wpdb->statify`");
|
498 |
+
}
|
499 |
+
}
|
500 |
+
add_action(
|
501 |
+
'plugins_loaded',
|
502 |
+
array(
|
503 |
+
'Statify',
|
504 |
+
'init'
|
505 |
+
)
|
506 |
+
);
|
507 |
+
register_activation_hook(
|
508 |
+
__FILE__,
|
509 |
+
array(
|
510 |
+
'Statify',
|
511 |
+
'install'
|
512 |
+
)
|
513 |
+
);
|
514 |
+
register_uninstall_hook(
|
515 |
+
__FILE__,
|
516 |
+
array(
|
517 |
+
'Statify',
|
518 |
+
'uninstall'
|
519 |
+
)
|
520 |
+
);
|
521 |
+
if ( function_exists('register_update_hook') ) {
|
522 |
+
register_update_hook(
|
523 |
+
__FILE__,
|
524 |
+
array(
|
525 |
+
'Statify',
|
526 |
+
'update'
|
527 |
+
)
|
528 |
+
);
|
529 |
+
}
|