Statify - Version 0.8

Version Description

  • Untersttzung fr WordPress 3.3
  • Anzeige des Dashboard-Widgets auch fr Autoren
  • Direkter Link zu den Einstellungen auf dem Dashboard
  • Filterung der Ziele/Referrer auf den aktuellen Tag
Download this release

Release Info

Developer sergej.mueller
Plugin Icon 128x128 Statify
Version 0.8
Comparing to
See all releases

Version 0.8

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