Version Description
- New stats in overview box
- WP 3.x compability fixes (capability and deprecated function warnings)
- Some minor bugfixes
- New config handling
- Code clean up (not finished)
Download this release
Release Info
Developer | Braekling |
Plugin | WP-Matomo (WP-Piwik) |
Version | 0.8.4 |
Comparing to | |
See all releases |
Code changes from version 0.8.3 to 0.8.4
- dashboard/overview.php +14 -6
- dashboard/plugins.php +4 -1
- dashboard/visitors.php +1 -1
- js/wp-piwik.js +2 -2
- languages/wp-piwik-de_DE.mo +0 -0
- languages/wp-piwik-de_DE.po +46 -7
- readme.txt +11 -4
- wp-piwik.php +412 -241
dashboard/overview.php
CHANGED
@@ -20,14 +20,17 @@
|
|
20 |
'nb_uniq_visitors' => 0,
|
21 |
'nb_visits' => 0,
|
22 |
'nb_visits_converted' => 0,
|
23 |
-
'sum_visit_length' => 0
|
|
|
|
|
|
|
24 |
);
|
25 |
foreach ($aryConf['data'] as $aryDay)
|
26 |
foreach ($aryDay as $strKey => $strValue)
|
27 |
-
if ($strKey
|
28 |
$aryTmp[$strKey] += $strValue;
|
29 |
-
elseif ($aryTmp[
|
30 |
-
$aryTmp[
|
31 |
$aryConf['data'] = $aryTmp;
|
32 |
}
|
33 |
/***************************************************************************/ ?>
|
@@ -39,12 +42,17 @@
|
|
39 |
floor($aryConf['data']['sum_visit_length']/3600).'h '.
|
40 |
floor(($aryConf['data']['sum_visit_length'] % 3600)/60).'m '.
|
41 |
floor(($aryConf['data']['sum_visit_length'] % 3600) % 60).'s';
|
|
|
|
|
|
|
|
|
42 |
echo '<tr><td>'.__('Visitors', 'wp-piwik').':</td><td>'.$aryConf['data']['nb_visits'].'</td></tr>';
|
43 |
echo '<tr><td>'.__('Unique visitors', 'wp-piwik').':</td><td>'.$aryConf['data']['nb_uniq_visitors'].'</td></tr>';
|
44 |
-
echo '<tr><td>'.__('Page views', 'wp-piwik').':</td><td>'.$aryConf['data']['nb_actions'].'</td></tr>';
|
45 |
echo '<tr><td>'.__('Max. page views in one visit', 'wp-piwik').':</td><td>'.$aryConf['data']['max_actions'].'</td></tr>';
|
46 |
echo '<tr><td>'.__('Total time spent by visitors', 'wp-piwik').':</td><td>'.$strTime.'</td></tr>';
|
47 |
-
echo '<tr><td>'.__('
|
|
|
48 |
if (get_option('wp-piwik_piwiklink', 0))
|
49 |
echo '<tr><td>'.__('Shortcut', 'wp-piwik').':</td><td><a href="'.get_option('wp-piwik_url').'">Piwik</a>'.(isset($aryConf['inline']) && $aryConf['inline']?' - <a href="?page=wp-piwik/wp-piwik.php">WP-Piwik</a>':'').'</td></tr>';
|
50 |
|
20 |
'nb_uniq_visitors' => 0,
|
21 |
'nb_visits' => 0,
|
22 |
'nb_visits_converted' => 0,
|
23 |
+
'sum_visit_length' => 0,
|
24 |
+
'bounce_rate' => 0,
|
25 |
+
'nb_actions_per_visit' => 0,
|
26 |
+
'avg_time_on_site' => 0
|
27 |
);
|
28 |
foreach ($aryConf['data'] as $aryDay)
|
29 |
foreach ($aryDay as $strKey => $strValue)
|
30 |
+
if (!in_array($strKey, array('max_actions','bounce_rate','nb_actions_per_visit','avg_time_on_site')))
|
31 |
$aryTmp[$strKey] += $strValue;
|
32 |
+
elseif ($aryTmp[$strKey] < $strValue)
|
33 |
+
$aryTmp[$strKey] = $strValue;
|
34 |
$aryConf['data'] = $aryTmp;
|
35 |
}
|
36 |
/***************************************************************************/ ?>
|
42 |
floor($aryConf['data']['sum_visit_length']/3600).'h '.
|
43 |
floor(($aryConf['data']['sum_visit_length'] % 3600)/60).'m '.
|
44 |
floor(($aryConf['data']['sum_visit_length'] % 3600) % 60).'s';
|
45 |
+
$strAvgTime =
|
46 |
+
floor($aryConf['data']['avg_time_on_site']/3600).'h '.
|
47 |
+
floor(($aryConf['data']['avg_time_on_site'] % 3600)/60).'m '.
|
48 |
+
floor(($aryConf['data']['avg_time_on_site'] % 3600) % 60).'s';
|
49 |
echo '<tr><td>'.__('Visitors', 'wp-piwik').':</td><td>'.$aryConf['data']['nb_visits'].'</td></tr>';
|
50 |
echo '<tr><td>'.__('Unique visitors', 'wp-piwik').':</td><td>'.$aryConf['data']['nb_uniq_visitors'].'</td></tr>';
|
51 |
+
echo '<tr><td>'.__('Page views', 'wp-piwik').':</td><td>'.$aryConf['data']['nb_actions'].' (⌀ '.$aryConf['data']['nb_actions_per_visit'].')</td></tr>';
|
52 |
echo '<tr><td>'.__('Max. page views in one visit', 'wp-piwik').':</td><td>'.$aryConf['data']['max_actions'].'</td></tr>';
|
53 |
echo '<tr><td>'.__('Total time spent by visitors', 'wp-piwik').':</td><td>'.$strTime.'</td></tr>';
|
54 |
+
echo '<tr><td>'.__('Average time spent by visitors', 'wp-piwik').':</td><td>'.$strAvgTime.'</td></tr>';
|
55 |
+
echo '<tr><td>'.__('Bounce count', 'wp-piwik').':</td><td>'.$aryConf['data']['bounce_count'].' ('.$aryConf['data']['bounce_rate'].')</td></tr>';
|
56 |
if (get_option('wp-piwik_piwiklink', 0))
|
57 |
echo '<tr><td>'.__('Shortcut', 'wp-piwik').':</td><td><a href="'.get_option('wp-piwik_url').'">Piwik</a>'.(isset($aryConf['inline']) && $aryConf['inline']?' - <a href="?page=wp-piwik/wp-piwik.php">WP-Piwik</a>':'').'</td></tr>';
|
58 |
|
dashboard/plugins.php
CHANGED
@@ -41,7 +41,10 @@
|
|
41 |
'</td><td class="n">'.
|
42 |
$aryValues['nb_visits'].
|
43 |
'</td><td class="n">'.
|
44 |
-
|
|
|
|
|
|
|
45 |
'%</td></tr>';
|
46 |
unset($aryTmp);
|
47 |
/***************************************************************************/ ?>
|
41 |
'</td><td class="n">'.
|
42 |
$aryValues['nb_visits'].
|
43 |
'</td><td class="n">'.
|
44 |
+
($intTotalVisits != 0?
|
45 |
+
number_format(($aryValues['nb_visits']/$intTotalVisits*100),2):
|
46 |
+
'0.00%'
|
47 |
+
).
|
48 |
'%</td></tr>';
|
49 |
unset($aryTmp);
|
50 |
/***************************************************************************/ ?>
|
dashboard/visitors.php
CHANGED
@@ -58,7 +58,7 @@
|
|
58 |
<?php /************************************************************************/
|
59 |
$aryTmp = array_reverse($aryConf['data']['Visitors']);
|
60 |
foreach ($aryTmp as $strDate => $intValue)
|
61 |
-
echo '<tr onclick="javascript:datelink(\''.str_replace('-', '', $strDate).'\');"><td>'.$strDate.'</td><td class="n">'.
|
62 |
$intValue.'</td><td class="n">'.
|
63 |
$aryConf['data']['Unique'][$strDate].
|
64 |
'</td><td class="n">'.
|
58 |
<?php /************************************************************************/
|
59 |
$aryTmp = array_reverse($aryConf['data']['Visitors']);
|
60 |
foreach ($aryTmp as $strDate => $intValue)
|
61 |
+
echo '<tr onclick="javascript:datelink(\''.urlencode(self::$strPluginBasename).'\',\''.str_replace('-', '', $strDate).'\');"><td>'.$strDate.'</td><td class="n">'.
|
62 |
$intValue.'</td><td class="n">'.
|
63 |
$aryConf['data']['Unique'][$strDate].
|
64 |
'</td><td class="n">'.
|
js/wp-piwik.js
CHANGED
@@ -4,6 +4,6 @@ jQuery( function($) {
|
|
4 |
postboxes.add_postbox_toggles('wppiwik');
|
5 |
} );
|
6 |
|
7 |
-
function datelink(strDate) {
|
8 |
-
window.location.href='index.php?page=
|
9 |
}
|
4 |
postboxes.add_postbox_toggles('wppiwik');
|
5 |
} );
|
6 |
|
7 |
+
function datelink(strPage,strDate) {
|
8 |
+
window.location.href='index.php?page='+strPage+'&date='+strDate;
|
9 |
}
|
languages/wp-piwik-de_DE.mo
CHANGED
Binary file
|
languages/wp-piwik-de_DE.po
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
# Translation of the WordPress plugin WP-Piwik 0.8.0 by André Bräkling.
|
2 |
# Copyright (C) 2010 André Bräkling
|
3 |
# This file is distributed under the same license as the WP-Piwik package.
|
4 |
-
#
|
5 |
#
|
6 |
#, fuzzy
|
7 |
msgid ""
|
8 |
msgstr ""
|
9 |
-
"Project-Id-Version: WP-Piwik 0.8.
|
10 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-piwik\n"
|
11 |
"POT-Creation-Date: 2010-07-19 18:06+0000\n"
|
12 |
"PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
|
@@ -243,10 +243,12 @@ msgstr "Wenn Du den Piwik-Code per wp_footer() in Dein Blog einbindest, kann WP-
|
|
243 |
msgid "Tracking filter"
|
244 |
msgstr "Tracking-Filter"
|
245 |
|
246 |
-
#: wp-piwik.php:544 wp-piwik.php:651
|
247 |
msgid "Choose users by user role you do <strong>not</strong> want to track."
|
248 |
msgstr "Wähle diejenigen Nutzerrollen, die Du <strong>nicht</strong> erfassen willst."
|
249 |
|
|
|
|
|
|
|
250 |
#: wp-piwik.php:551
|
251 |
msgid "Statistic view settings"
|
252 |
msgstr "Statistik-Einstellungen"
|
@@ -276,10 +278,8 @@ msgid "Display to"
|
|
276 |
msgstr "Anzeigen für"
|
277 |
|
278 |
#: wp-piwik.php:579
|
279 |
-
msgid ""
|
280 |
-
"
|
281 |
-
"<strong>not</strong> affect the dashboard widget.)"
|
282 |
-
msgstr "Wähle die Nutzerrolle, die mindestens notwendig ist, um die Statistiken zu sehen. (Diese Einstellung hat <strong>keinen</strong> Einfluss auf das Dashboard-Widget.)"
|
283 |
|
284 |
#: wp-piwik.php:612
|
285 |
msgid "WPMU-Piwik Settings"
|
@@ -326,3 +326,42 @@ msgstr "André Bräkling"
|
|
326 |
#. Author URI of the plugin/theme
|
327 |
msgid "http://www.braekling.de"
|
328 |
msgstr "http://www.braekling.de"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Translation of the WordPress plugin WP-Piwik 0.8.0 by André Bräkling.
|
2 |
# Copyright (C) 2010 André Bräkling
|
3 |
# This file is distributed under the same license as the WP-Piwik package.
|
4 |
+
# André Bräkling <webmaster@braekling.de>, 2011.
|
5 |
#
|
6 |
#, fuzzy
|
7 |
msgid ""
|
8 |
msgstr ""
|
9 |
+
"Project-Id-Version: WP-Piwik 0.8.4\n"
|
10 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-piwik\n"
|
11 |
"POT-Creation-Date: 2010-07-19 18:06+0000\n"
|
12 |
"PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
|
243 |
msgid "Tracking filter"
|
244 |
msgstr "Tracking-Filter"
|
245 |
|
|
|
246 |
msgid "Choose users by user role you do <strong>not</strong> want to track."
|
247 |
msgstr "Wähle diejenigen Nutzerrollen, die Du <strong>nicht</strong> erfassen willst."
|
248 |
|
249 |
+
msgid "Choose users by user role you do <strong>not</strong> want to track. Requires enabled "Add script"-functionality."
|
250 |
+
msgstr "Wähle diejenigen Nutzerrollen, die Du <strong>nicht</strong> erfassen willst. Dazu muss die "Tracking"-Funktion aktiviert sein."
|
251 |
+
|
252 |
#: wp-piwik.php:551
|
253 |
msgid "Statistic view settings"
|
254 |
msgstr "Statistik-Einstellungen"
|
278 |
msgstr "Anzeigen für"
|
279 |
|
280 |
#: wp-piwik.php:579
|
281 |
+
msgid "Choose user roles allowed to see the statistics page."
|
282 |
+
msgstr "Wähle diejenigen Nutzerrollen, die sich die Statistiken ansehen dürfen."
|
|
|
|
|
283 |
|
284 |
#: wp-piwik.php:612
|
285 |
msgid "WPMU-Piwik Settings"
|
326 |
#. Author URI of the plugin/theme
|
327 |
msgid "http://www.braekling.de"
|
328 |
msgstr "http://www.braekling.de"
|
329 |
+
|
330 |
+
msgid "Credits"
|
331 |
+
msgstr "Danksagungen"
|
332 |
+
|
333 |
+
msgid "Thank you very much for your donation"
|
334 |
+
msgstr "Vielen Dank für eure Spenden"
|
335 |
+
|
336 |
+
msgid "and all people flattering this"
|
337 |
+
msgstr "und allen Nutzern, die bei Flatter klicken"
|
338 |
+
|
339 |
+
msgid "Graphs powered by <a href=\"http://www.jqplot.com/\">jqPlot</a>, an open source project by Chris Leonello. Give it a try! (License: GPL 2.0 and MIT)"
|
340 |
+
msgstr "Die Graphen werden mit <a href=\"http://www.jqplot.com/\">jqPlot</a> erstellt, einem Open-Source-Projekt von Chris Leonello. Probiere es mal aus! (Lizenz: GPL 2.0 und MIT)"
|
341 |
+
|
342 |
+
msgid "Thank you very much"
|
343 |
+
msgstr "Vielen Dank"
|
344 |
+
|
345 |
+
msgid ", and"
|
346 |
+
msgstr " und"
|
347 |
+
|
348 |
+
msgid "for your translation work"
|
349 |
+
msgstr "f&uur; eure Übersetzungsarbeit"
|
350 |
+
|
351 |
+
msgid "Thank you very much, all users who send me mails containing criticism, commendation, feature requests and bug reports! You help me to make WP-Piwik much better."
|
352 |
+
msgstr "Vielen Dank an alle Nutzer, die mir Mails mit Kritik, Lob, Featurewünsche und Bugmeldungen senden. Ihr helft mir dabei, WP-Piwik viel besser zu machen."
|
353 |
+
|
354 |
+
msgid "Thank <strong>you</strong> for using my plugin. It is the best commendation if my piece of code is really used!"
|
355 |
+
msgstr "Vielen Dank an <strong>Dich</strong> für die Nutzung meines Plugins. Es ist das größte Lob, wenn mein Code tatsächlich benutzt wird!"
|
356 |
+
|
357 |
+
msgid "Changes saved"
|
358 |
+
msgstr "Änderungen gespeichert"
|
359 |
+
|
360 |
+
msgid "installed"
|
361 |
+
msgstr "installiert"
|
362 |
+
|
363 |
+
msgid "Next you should connect to Piwik"
|
364 |
+
msgstr "Als nächstes solltest Du eine Verbindung zu Piwik herstellen"
|
365 |
+
|
366 |
+
msgid "Please validate your configuration"
|
367 |
+
msgstr "Bitte überprüfe Deine Konfiguration"
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== WP-Piwik ===
|
2 |
|
3 |
Contributors: Braekling
|
4 |
-
Requires at least: 3.0
|
5 |
-
Tested up to: 3.
|
6 |
-
Stable tag: 0.8.
|
7 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
|
8 |
Tags: statistics, stats, analytics, piwik, wpmu
|
9 |
|
@@ -13,7 +13,7 @@ This plugin adds a piwik stats site to your WordPress or WordPress multisite das
|
|
13 |
|
14 |
This plugin adds a Piwik stats site to your WordPress dashboard. It's also able to add the Piwik tracking code to your blog using wp_footer.
|
15 |
|
16 |
-
You need a running Piwik installation and at least view access to your stats. Also PHP 5 or higher is strictly required.
|
17 |
|
18 |
|
19 |
Look at the [Piwik website](http://piwik.org/) to get further information about Piwik.
|
@@ -75,6 +75,13 @@ Thank you, guys!
|
|
75 |
|
76 |
== Changelog ==
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
= 0.8.3 =
|
79 |
* Piwik 1.1+ compatibility fix
|
80 |
|
1 |
=== WP-Piwik ===
|
2 |
|
3 |
Contributors: Braekling
|
4 |
+
Requires at least: 3.0.1
|
5 |
+
Tested up to: 3.1
|
6 |
+
Stable tag: 0.8.4
|
7 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
|
8 |
Tags: statistics, stats, analytics, piwik, wpmu
|
9 |
|
13 |
|
14 |
This plugin adds a Piwik stats site to your WordPress dashboard. It's also able to add the Piwik tracking code to your blog using wp_footer.
|
15 |
|
16 |
+
**You need a running Piwik installation** and at least view access to your stats. Also PHP 5 or higher is strictly required.
|
17 |
|
18 |
|
19 |
Look at the [Piwik website](http://piwik.org/) to get further information about Piwik.
|
75 |
|
76 |
== Changelog ==
|
77 |
|
78 |
+
= 0.8.4 =
|
79 |
+
* New stats in overview box
|
80 |
+
* WP 3.x compability fixes (capability and deprecated function warnings)
|
81 |
+
* Some minor bugfixes
|
82 |
+
* New config handling
|
83 |
+
* Code clean up (not finished)
|
84 |
+
|
85 |
= 0.8.3 =
|
86 |
* Piwik 1.1+ compatibility fix
|
87 |
|
wp-piwik.php
CHANGED
@@ -6,12 +6,12 @@ Plugin URI: http://www.braekling.de/wp-piwik-wpmu-piwik-wordpress/
|
|
6 |
|
7 |
Description: Adds Piwik stats to your dashboard menu and Piwik code to your wordpress footer.
|
8 |
|
9 |
-
Version: 0.8.
|
10 |
Author: André Bräkling
|
11 |
Author URI: http://www.braekling.de
|
12 |
|
13 |
******************************************************************************************
|
14 |
-
Copyright (C) 2009-
|
15 |
|
16 |
This program is free software: you can redistribute it and/or modify
|
17 |
it under the terms of the GNU General Public License as published by
|
@@ -27,150 +27,289 @@ Author URI: http://www.braekling.de
|
|
27 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
28 |
*******************************************************************************************/
|
29 |
|
|
|
30 |
$GLOBALS['wp-piwik_wpmu'] = false;
|
31 |
|
32 |
class wp_piwik {
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
function __construct() {
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
register_activation_hook(__FILE__, array($this, 'install'));
|
48 |
-
|
49 |
-
if (!self::$bolWPMU)
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
add_action('wp_footer', array($this, 'footer'));
|
54 |
-
|
55 |
add_action('admin_menu', array($this, 'build_menu'));
|
56 |
-
|
57 |
-
|
58 |
-
if ($intDashboardWidget > 0)
|
59 |
-
add_action('wp_dashboard_setup', array($this, 'extend_wp_dashboard_setup'));
|
60 |
}
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
function install() {
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
}
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
function footer() {
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
}
|
84 |
-
$strJSCode = get_option('wp-piwik_jscode', '');
|
85 |
-
if (self::$bolWPMU && empty($strJSCode)) {
|
86 |
$aryReturn = $this->create_wpmu_site();
|
87 |
-
|
|
|
88 |
} elseif (self::$bolWPMU) {
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
update_option('wp-piwik_jscode', $strJSCode);
|
94 |
-
update_option('wp-piwik_scriptupdate', time());
|
95 |
}
|
|
|
96 |
} elseif (empty($strJSCode)) {
|
97 |
-
|
98 |
-
|
99 |
}
|
100 |
-
|
101 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
102 |
}
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
$intDisplayTo = 'administrator';
|
112 |
-
$strToken = get_site_option('wpmu-piwik_token');
|
113 |
-
$strPiwikURL = get_site_option('wpmu-piwik_url');
|
114 |
-
$bolDashboardWidget = false;
|
115 |
-
}
|
116 |
-
if (!empty($strToken) && !empty($strPiwikURL)) {
|
117 |
$intStatsPage = add_dashboard_page(
|
118 |
__('Piwik Statistics', 'wp-piwik'),
|
119 |
__('WP-Piwik', 'wp-piwik'),
|
120 |
-
|
121 |
__FILE__,
|
122 |
array($this, 'show_stats')
|
123 |
);
|
|
|
124 |
add_action('admin_print_scripts-'.$intStatsPage, array($this, 'load_scripts'));
|
|
|
125 |
add_action('admin_print_styles-'.$intStatsPage, array($this, 'add_admin_style'));
|
|
|
126 |
add_action('admin_head-'.$intStatsPage, array($this, 'add_admin_header'));
|
127 |
}
|
|
|
128 |
if (!self::$bolWPMU)
|
|
|
129 |
$intOptionsPage = add_options_page(
|
130 |
__('WP-Piwik', 'wp-piwik'),
|
131 |
__('WP-Piwik', 'wp-piwik'),
|
132 |
-
'
|
133 |
__FILE__,
|
134 |
array($this, 'show_settings')
|
135 |
);
|
136 |
-
|
|
|
|
|
137 |
$intOptionsPage = add_options_page(
|
138 |
__('WPMU-Piwik', 'wpmu-piwik'),
|
139 |
__('WPMU-Piwik', 'wpmu-piwik'),
|
140 |
-
'
|
141 |
__FILE__,
|
142 |
array($this, 'show_mu_settings')
|
143 |
);
|
144 |
-
|
|
|
|
|
|
|
145 |
}
|
146 |
|
147 |
function extend_wp_dashboard_setup() {
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
$strTitle = __('WP-Piwik', 'wp-piwik').' - '.$arySub[$intDashboardWidget];
|
155 |
-
|
156 |
-
wp_add_dashboard_widget(
|
157 |
-
'wp-piwik_dashboard_widget',
|
158 |
-
$strTitle,
|
159 |
-
array (&$this, 'add_wp_dashboard_widget')
|
160 |
-
);
|
161 |
}
|
162 |
|
163 |
function add_wp_dashboard_widget() {
|
164 |
-
$intDashboardWidget = get_option('wp-piwik_dbwidget');
|
165 |
-
$aryDate = array (
|
166 |
-
1 => 'yesterday',
|
167 |
-
2 => 'today',
|
168 |
-
3 => 'last30'
|
169 |
-
);
|
170 |
$arySetup = array(
|
171 |
'params' => array(
|
172 |
-
|
173 |
-
|
174 |
'limit' => null
|
175 |
),
|
176 |
'inline' => true,
|
@@ -178,71 +317,99 @@ class wp_piwik {
|
|
178 |
$this->create_dashboard_widget('overview', $arySetup);
|
179 |
}
|
180 |
|
|
|
|
|
|
|
|
|
|
|
181 |
function set_plugin_meta($strLinks, $strFile) {
|
|
|
182 |
$strPlugin = plugin_basename(__FILE__);
|
183 |
-
|
|
|
184 |
return array_merge(
|
185 |
$strLinks,
|
186 |
array(
|
187 |
-
sprintf('<a href="options-general.php?page=%s">%s</a>',
|
188 |
)
|
189 |
-
);
|
|
|
190 |
return $strLinks;
|
191 |
}
|
192 |
|
|
|
|
|
|
|
193 |
function load_scripts() {
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
);
|
199 |
-
wp_enqueue_script(
|
200 |
-
'wp-piwik-jqplot',
|
201 |
-
$this->get_plugin_url().'js/jqplot/wp-piwik.jqplot.js',
|
202 |
-
array('jquery')
|
203 |
-
);
|
204 |
}
|
205 |
|
|
|
|
|
|
|
206 |
function add_admin_style() {
|
|
|
207 |
wp_enqueue_style('wp-piwik', $this->get_plugin_url().'css/wp-piwik.css', array('dashboard'));
|
208 |
}
|
209 |
|
210 |
-
|
|
|
|
|
|
|
|
|
211 |
echo '<!--[if IE]><script language="javascript" type="text/javascript" src="'.$this->get_plugin_url().(self::$bolWPMU?'wp-piwik/':'').'js/jqplot/excanvas.min.js"></script><![endif]-->';
|
|
|
212 |
echo '<link rel="stylesheet" href="'.$this->get_plugin_url().'js/jqplot/jquery.jqplot.min.css" type="text/css"/>';
|
213 |
}
|
214 |
|
|
|
|
|
|
|
215 |
function get_plugin_url() {
|
|
|
216 |
return trailingslashit(plugins_url().'/wp-piwik/');
|
217 |
}
|
218 |
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
if (function_exists('curl_init')) {
|
|
|
221 |
$c = curl_init($strURL);
|
|
|
222 |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
|
|
|
223 |
curl_setopt($c, CURLOPT_HEADER, 0);
|
|
|
224 |
$strResult = curl_exec($c);
|
|
|
225 |
curl_close($c);
|
|
|
226 |
} elseif (ini_get('allow_url_fopen'))
|
|
|
227 |
$strResult = file_get_contents($strURL);
|
|
|
228 |
else $strResult = serialize(array(
|
229 |
'result' => 'error',
|
230 |
'message' => 'Remote access to Piwik not possible. Enable allow_url_fopen or CURL.'
|
231 |
));
|
|
|
232 |
return $strResult;
|
233 |
}
|
234 |
|
235 |
function call_API($strMethod, $strPeriod='', $strDate='', $intLimit='',$bolExpanded=false) {
|
236 |
$strKey = $strMethod.'_'.$strPeriod.'_'.$strDate.'_'.$intLimit;
|
237 |
if (empty($this->aryCache[$strKey])) {
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
} else {
|
242 |
-
$strToken = get_option('wp-piwik_token');
|
243 |
-
$strURL = get_option('wp-piwik_url');
|
244 |
-
}
|
245 |
-
$intSite = get_option('wp-piwik_siteid');
|
246 |
if (self::$bolWPMU && empty($intSite)) {
|
247 |
$aryReturn = $this->create_wpmu_site();
|
248 |
$intSite = $aryReturn['id'];
|
@@ -268,30 +435,28 @@ class wp_piwik {
|
|
268 |
}
|
269 |
|
270 |
function create_wpmu_site() {
|
271 |
-
$
|
272 |
-
$strURL = get_site_option('wpmu-piwik_url');
|
273 |
$strJavaScript = '';
|
274 |
-
$
|
275 |
-
|
276 |
-
$intSite = get_option('wp-piwik_siteid');
|
277 |
-
if (empty($intSite)) {
|
278 |
$strName = get_bloginfo('name');
|
279 |
$strBlogURL = get_bloginfo('url');
|
280 |
if (substr($strURL, -1, 1) != '/') $strURL .= '/';
|
281 |
$strURL .= '?module=API&method=SitesManager.addSite';
|
282 |
$strURL .= '&siteName='.urlencode('WPMU: '.$strName).'&urls='.urlencode($strBlogURL);
|
283 |
$strURL .= '&format=PHP';
|
284 |
-
$strURL .= '&token_auth='
|
285 |
$strResult = unserialize($this->get_remote_file($strURL));
|
286 |
if (!empty($strResult)) {
|
287 |
-
|
288 |
-
|
289 |
$strJavaScript = html_entity_decode($this->call_API('SitesManager.getJavascriptTag'));
|
290 |
}
|
291 |
} else $strJavaScript = html_entity_decode($this->call_API('SitesManager.getJavascriptTag'));
|
292 |
-
|
|
|
293 |
}
|
294 |
-
return array('js' => $strJavaScript, 'id' =>
|
295 |
}
|
296 |
|
297 |
function create_dashboard_widget($strFile, $aryConfig) {
|
@@ -321,13 +486,13 @@ class wp_piwik {
|
|
321 |
}
|
322 |
|
323 |
function show_stats() {
|
324 |
-
$strToken =
|
325 |
-
$strPiwikURL =
|
326 |
$arySortOrder = get_user_option('meta-box-order_wppiwik');
|
327 |
$aryClosed = get_user_option('closedpostboxes_wppiwik');
|
328 |
if (empty($aryClosed)) $aryClosed = array();
|
329 |
$aryDashboard = array();
|
330 |
-
$intCurrentDashboard =
|
331 |
if (!$arySortOrder) {
|
332 |
// Set default configuration
|
333 |
$arySortOrder = array(
|
@@ -337,7 +502,8 @@ class wp_piwik {
|
|
337 |
global $current_user;
|
338 |
get_currentuserinfo();
|
339 |
update_user_option($current_user->ID, 'meta-box-order_wppiwik', $arySortOrder);
|
340 |
-
|
|
|
341 |
} elseif ($intCurrentDashboard < self::$intDashboardID) {
|
342 |
if ($intCurrentDashboard < 5) {
|
343 |
$arySortOrder['normal'] .= ',screens_day_yesterday,systems_day_yesterday';
|
@@ -349,7 +515,8 @@ class wp_piwik {
|
|
349 |
global $current_user;
|
350 |
get_currentuserinfo();
|
351 |
update_user_option($current_user->ID, 'meta-box-order_wppiwik', $arySortOrder);
|
352 |
-
|
|
|
353 |
}
|
354 |
foreach ($arySortOrder as $strCol => $strWidgets) {
|
355 |
$aryWidgets = explode(',', $strWidgets);
|
@@ -374,17 +541,17 @@ class wp_piwik {
|
|
374 |
<h2><?php _e('Piwik Statistics', 'wp-piwik'); ?></h2>
|
375 |
<?php /************************************************************************/
|
376 |
|
377 |
-
if (self::$bolWPMU && function_exists('
|
378 |
if (isset($_POST['wpmu_show_stats']))
|
379 |
/*if ($_POST['wpmu_show_stats'] == 'all') self::$bolOverall = true;
|
380 |
else*/ switch_to_blog((int) $_POST['wpmu_show_stats']);
|
381 |
global $blog_id;
|
382 |
-
$
|
|
|
383 |
echo '<form method="POST" action="">'."\n";
|
384 |
echo '<select name="wpmu_show_stats">'."\n";
|
385 |
-
// echo '<option value="all">Overall stats</option>';
|
386 |
foreach ($aryBlogs as $aryBlog) {
|
387 |
-
$objBlog = get_blog_details($aryBlog
|
388 |
echo '<option value="'.$objBlog->blog_id.'"'.($blog_id == $objBlog->blog_id?' selected="selected"':'').'>'.$objBlog->blogname.'</option>'."\n";
|
389 |
}
|
390 |
echo '</select><input type="submit" value="'.__('Change').'" />'."\n ";
|
@@ -421,37 +588,33 @@ class wp_piwik {
|
|
421 |
</div>
|
422 |
</div>
|
423 |
<?php /************************************************************************/
|
424 |
-
if (self::$bolWPMU && function_exists('
|
425 |
restore_current_blog(); self::$bolOverall = false;
|
426 |
}
|
427 |
}
|
428 |
|
429 |
-
function
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
update_option('wp-piwik_piwiklink', $_POST['wp-piwik_piwiklink'], 0);
|
444 |
-
update_option('wp-piwik_404', $_POST['wp-piwik_404'], 0);
|
445 |
}
|
446 |
|
447 |
-
function show_settings() {
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
$strURL = get_option('wp-piwik_url');
|
454 |
-
$intSite = get_option('wp-piwik_siteid');
|
455 |
/***************************************************************************/ ?>
|
456 |
<div class="wrap">
|
457 |
<h2><?php _e('WP-Piwik Settings', 'wp-piwik') ?></h2>
|
@@ -506,16 +669,20 @@ class wp_piwik {
|
|
506 |
'>'.htmlentities($arySite['name'], ENT_QUOTES, 'utf-8').
|
507 |
'</option>';
|
508 |
echo '</select></div>';
|
509 |
-
if (empty($intSite))
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
$
|
514 |
-
$
|
515 |
-
$
|
|
|
|
|
516 |
$strJavaScript = html_entity_decode($this->call_API('SitesManager.getJavascriptTag'));
|
517 |
-
if ($intAddJS)
|
518 |
-
|
|
|
|
|
519 |
/***************************************************************************/ ?>
|
520 |
<div><input type="submit" name="Submit" value="<?php _e('Save settings', 'wp-piwik') ?>" /></div>
|
521 |
</div>
|
@@ -544,14 +711,14 @@ class wp_piwik {
|
|
544 |
global $wp_roles;
|
545 |
echo '<h4><label>'.__('Tracking filter', 'wp-piwik').':</label></h4>';
|
546 |
echo '<div class="input-wrap">';
|
547 |
-
$aryFilter =
|
548 |
foreach($wp_roles->role_names as $strKey => $strName) {
|
549 |
echo '<input type="checkbox" '.(isset($aryFilter[$strKey]) && $aryFilter[$strKey]?'checked="checked" ':'').'value="1" name="wp-piwik_filter['.$strKey.']" /> '.$strName.' ';
|
550 |
}
|
551 |
echo '</div>';
|
552 |
echo '<div class="wp-piwik_desc">'.
|
553 |
__('Choose users by user role you do <strong>not</strong> want to track.'.
|
554 |
-
' Requires enabled "Add script
|
555 |
/***************************************************************************/ ?>
|
556 |
<div><input type="submit" name="Submit" value="<?php _e('Save settings', 'wp-piwik') ?>" /></div>
|
557 |
</div>
|
@@ -562,10 +729,10 @@ class wp_piwik {
|
|
562 |
<?php
|
563 |
echo '<h4><label for="wp-piwik_dbwidget">'.__('Dashboard', 'wp-piwik').':</label></h4>'.
|
564 |
'<div class="input-wrap"><select id="wp-piwik_dbwidget" name="wp-piwik_dbwidget">'.
|
565 |
-
'<option value="0"'.(
|
566 |
-
'<option value="
|
567 |
-
'<option value="
|
568 |
-
'<option value="
|
569 |
'</select></div>';
|
570 |
echo '<div class="wp-piwik_desc">'.
|
571 |
__('Display a dashboard widget to your WordPress dashboard.', 'wp-piwik').'</div>';
|
@@ -576,16 +743,13 @@ class wp_piwik {
|
|
576 |
__('Display a shortcut to Piwik itself.', 'wp-piwik').'</div>';
|
577 |
echo '<h4><label>'.__('Display to', 'wp-piwik').':</label></h4>';
|
578 |
echo '<div class="input-wrap">';
|
579 |
-
|
580 |
-
$intDisplayTo = get_option('wp-piwik_displayto', 'level_8');
|
581 |
foreach($wp_roles->role_names as $strKey => $strName) {
|
582 |
-
$role = get_role($strKey);
|
583 |
-
|
584 |
-
echo '<option value="level_'.$intLevel.'"'.($intDisplayTo == 'level_'.$intLevel?' selected="selected"':'').'>'.$strName.'</option>';
|
585 |
}
|
586 |
-
echo '</select>';
|
587 |
echo '</div><div class="wp-piwik_desc">'.
|
588 |
-
__('Choose
|
589 |
'</div>';
|
590 |
}
|
591 |
}
|
@@ -603,71 +767,77 @@ class wp_piwik {
|
|
603 |
<?php /************************************************************************/
|
604 |
}
|
605 |
|
606 |
-
function save_mu_settings() {
|
607 |
-
update_site_option('wpmu-piwik_token', $_POST['wp-piwik_token'],'');
|
608 |
-
update_site_option('wpmu-piwik_url', $_POST['wp-piwik_url'],'');
|
609 |
-
update_site_option('wpmu-piwik_filter', $_POST['wp-piwik_filter'],'');
|
610 |
-
update_site_option('wpmu-piwik_settingsupdate', time(),0);
|
611 |
-
}
|
612 |
-
|
613 |
function show_mu_settings() {
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
$strToken = get_site_option('wpmu-piwik_token');
|
619 |
-
$strURL = get_site_option('wpmu-piwik_url');
|
620 |
/***************************************************************************/ ?>
|
621 |
<div class="wrap">
|
622 |
<h2><?php _e('WPMU-Piwik Settings', 'wp-piwik') ?></h2>
|
623 |
<?php $this->donate(); ?>
|
624 |
-
<div class="inside">
|
625 |
<form method="post" action="">
|
626 |
-
|
627 |
-
|
628 |
-
<
|
629 |
-
<
|
630 |
-
<
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
649 |
<?php /************************************************************************/
|
650 |
-
if (!empty($strToken) && !empty($strURL)) {
|
651 |
global $wp_roles;
|
652 |
-
|
653 |
-
echo '<
|
654 |
-
$aryFilter =
|
655 |
foreach($wp_roles->role_names as $strKey => $strName) {
|
656 |
echo '<input type="checkbox" '.(isset($aryFilter[$strKey]) && $aryFilter[$strKey]?'checked="checked" ':'').'value="1" name="wp-piwik_filter['.$strKey.']" /> '.$strName.' ';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
657 |
}
|
658 |
-
echo '</
|
659 |
-
|
660 |
-
|
661 |
-
'</span></td></tr>';
|
662 |
}
|
663 |
/***************************************************************************/ ?>
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
|
|
669 |
</form>
|
670 |
-
</div>
|
671 |
<?php $this->credits(); ?>
|
672 |
</div>
|
673 |
<?php /************************************************************************/
|
@@ -701,12 +871,13 @@ class wp_piwik {
|
|
701 |
|
702 |
function credits() {
|
703 |
/***************************************************************************/ ?>
|
704 |
-
<h2 style="clear:left;"
|
705 |
<div class="inside">
|
706 |
-
<p
|
707 |
-
<p
|
708 |
-
<p
|
709 |
-
<p
|
|
|
710 |
</div>
|
711 |
<?php /************************************************************************/
|
712 |
}
|
@@ -715,4 +886,4 @@ class wp_piwik {
|
|
715 |
if (class_exists('wp_piwik'))
|
716 |
$GLOBALS['wp_piwik'] = new wp_piwik();
|
717 |
|
718 |
-
/* EOF */
|
6 |
|
7 |
Description: Adds Piwik stats to your dashboard menu and Piwik code to your wordpress footer.
|
8 |
|
9 |
+
Version: 0.8.4
|
10 |
Author: André Bräkling
|
11 |
Author URI: http://www.braekling.de
|
12 |
|
13 |
******************************************************************************************
|
14 |
+
Copyright (C) 2009-2011 Andre Braekling (email: webmaster@braekling.de)
|
15 |
|
16 |
This program is free software: you can redistribute it and/or modify
|
17 |
it under the terms of the GNU General Public License as published by
|
27 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
28 |
*******************************************************************************************/
|
29 |
|
30 |
+
// Change this to enable *experimental* multisite-mode
|
31 |
$GLOBALS['wp-piwik_wpmu'] = false;
|
32 |
|
33 |
class wp_piwik {
|
34 |
|
35 |
+
private static
|
36 |
+
$intRevisionId = 80406,
|
37 |
+
$strVersion = '0.8.4',
|
38 |
+
$intDashboardID = 6,
|
39 |
+
$bolWPMU = false,
|
40 |
+
$bolOverall = false,
|
41 |
+
$strPluginBasename = NULL,
|
42 |
+
$aryGlobalSettings = array(
|
43 |
+
'revision' => 0,
|
44 |
+
'add_tracking_code' => false,
|
45 |
+
'last_settings_update' => 0,
|
46 |
+
'piwik_token' => '',
|
47 |
+
'piwik_url' => '',
|
48 |
+
'dashboard_widget' => false,
|
49 |
+
'capability_stealth' => array(),
|
50 |
+
'capability_read_stats' => array('administrator' => true),
|
51 |
+
'piwik_shortcut' => false
|
52 |
+
),
|
53 |
+
$arySettings = array(
|
54 |
+
'tracking_code' => '',
|
55 |
+
'site_id' => NULL,
|
56 |
+
'track_404' => false,
|
57 |
+
'last_tracking_code_update' => 0,
|
58 |
+
'dashboard_revision' => 0
|
59 |
+
);
|
60 |
|
61 |
+
/**
|
62 |
+
* Load plugin settings
|
63 |
+
*/
|
64 |
+
static function loadSettings() {
|
65 |
+
// Running as multisite?
|
66 |
+
if (isset($GLOBALS['wp-piwik_wpmu']) && $GLOBALS['wp-piwik_wpmu']) self::$bolWPMU = true;
|
67 |
+
// Get global settings depending on mode
|
68 |
+
self::$aryGlobalSettings =
|
69 |
+
(self::$bolWPMU?
|
70 |
+
get_site_option('wpmu-piwik_global-settings',self::$aryGlobalSettings):
|
71 |
+
get_option('wp-piwik_global-settings',self::$aryGlobalSettings)
|
72 |
+
);
|
73 |
+
// Get mode-independent settings
|
74 |
+
self::$arySettings = get_option('wp-piwik_settings',self::$arySettings);
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Save plugin settings
|
79 |
+
*/
|
80 |
+
static function saveSettings() {
|
81 |
+
// Save global settings depending on mode
|
82 |
+
if (self::$bolWPMU) update_site_option('wpmu-piwik_global-settings',self::$aryGlobalSettings);
|
83 |
+
else update_option('wp-piwik_global-settings',self::$aryGlobalSettings);
|
84 |
+
// Save mode-independent settings
|
85 |
+
update_option('wp-piwik_settings',self::$arySettings);
|
86 |
+
// Assign capabilities to roles
|
87 |
+
global $wp_roles;
|
88 |
+
if (is_object($wp_roles))
|
89 |
+
foreach($wp_roles->role_names as $strKey => $strName) {
|
90 |
+
$objRole = get_role($strKey);
|
91 |
+
foreach (array('stealth', 'read_stats') as $strCap)
|
92 |
+
if (isset(self::$aryGlobalSettings['capability_'.$strCap][$strKey]) && self::$aryGlobalSettings['capability_'.$strCap][$strKey])
|
93 |
+
$objRole->add_cap('wp-piwik_'.$strCap);
|
94 |
+
else
|
95 |
+
$objRole->remove_cap('wp-piwik_'.$strCap);
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Constructor
|
101 |
+
*/
|
102 |
function __construct() {
|
103 |
+
// Store plugin basename
|
104 |
+
self::$strPluginBasename = plugin_basename(__FILE__);
|
105 |
+
// Load current settings
|
106 |
+
self::loadSettings();
|
107 |
+
// Upgrade?
|
108 |
+
if (self::$aryGlobalSettings['revision'] < self::$intRevisionId) $this->install();
|
109 |
+
// Settings changed?
|
110 |
+
if (isset($_POST['action']) && $_POST['action'] == 'save_settings')
|
111 |
+
$this->applySettings();
|
112 |
+
// Load language file
|
113 |
+
load_plugin_textdomain('wp-piwik', false, dirname(self::$strPluginBasename)."/languages/");
|
114 |
+
// Call install function on activation
|
115 |
register_activation_hook(__FILE__, array($this, 'install'));
|
116 |
+
// Add meta links to plugin details
|
117 |
+
if (!self::$bolWPMU) add_filter('plugin_row_meta', array($this, 'set_plugin_meta'), 10, 2);
|
118 |
+
// Add tracking code to footer if enabled
|
119 |
+
if (self::$aryGlobalSettings['add_tracking_code']) add_action('wp_footer', array($this, 'footer'));
|
120 |
+
// Add admin menu
|
|
|
|
|
121 |
add_action('admin_menu', array($this, 'build_menu'));
|
122 |
+
// Add dashboard widget if enabled
|
123 |
+
if (self::$aryGlobalSettings['dashboard_widget']) add_action('wp_dashboard_setup', array($this, 'extend_wp_dashboard_setup'));
|
|
|
|
|
124 |
}
|
125 |
|
126 |
+
/**
|
127 |
+
* Destructor
|
128 |
+
*/
|
129 |
+
function __destruct() {}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Install or upgrade
|
133 |
+
*/
|
134 |
function install() {
|
135 |
+
|
136 |
+
// Update: Translate options
|
137 |
+
if (self::$aryGlobalSettings['revision'] < 80403) {
|
138 |
+
// Capability read stats: Translate level to role
|
139 |
+
$aryTranslate = array(
|
140 |
+
'level_10' => array('administrator' => true),
|
141 |
+
'level_7' => array('editor' => true, 'administrator' => true),
|
142 |
+
'level_2' => array('author' => true, 'editor' => true, 'administrator' => true),
|
143 |
+
'level_1' => array('contributor' => true, 'author' => true, 'editor' => true, 'administrator' => true),
|
144 |
+
'level_0' => array('subscriber' => true, 'contributor' => true, 'author' => true, 'editor' => true, 'administrator' => true)
|
145 |
+
);
|
146 |
+
$strDisplayToLevel = get_option('wp-piwik_displayto','level_10');
|
147 |
+
if (!is_array($strDisplayToLevel) && isset($aryTranslate[$strDisplayToLevel])) $aryDisplayToCap = $aryTranslate[$strDisplayToLevel];
|
148 |
+
else $aryDisplayToCap = array('administrator' => true);
|
149 |
+
// Build settings arrays
|
150 |
+
$aryDashboardWidgetRange = array(0 => false, 1 => 'yesterday', 2 => 'today', 3 => 'last30');
|
151 |
+
if (self::$bolWPMU) self::$aryGlobalSettings = array(
|
152 |
+
'revision' => get_site_option('wpmu-piwik_revision', 0),
|
153 |
+
'add_tracking_code' => true,
|
154 |
+
'last_settings_update' => get_site_option('wpmu-piwik_settingsupdate', time()),
|
155 |
+
'piwik_token' => get_site_option('wpmu-piwik_token', ''),
|
156 |
+
'piwik_url' => get_site_option('wpmu-piwik_url', ''),
|
157 |
+
'dashboard_widget' => false,
|
158 |
+
'capability_stealth' => get_site_option('wpmu-piwik_filter', array()),
|
159 |
+
'capability_read_stats' => $aryDisplayToCap,
|
160 |
+
'piwik_shortcut' => false
|
161 |
+
);
|
162 |
+
else self::$aryGlobalSettings = array(
|
163 |
+
'revision' => get_option('wp-piwik_revision',0),
|
164 |
+
'add_tracking_code' => get_option('wp-piwik_addjs'),
|
165 |
+
'last_settings_update' => get_option('wp-piwik_settingsupdate', time()),
|
166 |
+
'piwik_token' => get_option('wp-piwik_token', ''),
|
167 |
+
'piwik_url' => get_option('wp-piwik_url', ''),
|
168 |
+
'dashboard_widget' => $aryDashboardWidgetRange[get_option('wp-piwik_dbwidget', 0)],
|
169 |
+
'capability_stealth' => get_option('wp-piwik_filter', array()),
|
170 |
+
'capability_read_stats' => $aryDisplayToCap,
|
171 |
+
'piwik_shortcut' => get_option('wp-piwik_piwiklink',false)
|
172 |
+
);
|
173 |
+
self::$arySettings = array(
|
174 |
+
'tracking_code' => '',
|
175 |
+
'site_id' => get_option('wp-piwik_siteid', NULL),
|
176 |
+
'track_404' => get_option('wp-piwik_404', false),
|
177 |
+
'last_tracking_code_update' => get_option('wp-piwik_scriptupdate', 0),
|
178 |
+
'dashboard_revision' => get_option('wp-piwik_dashboardid', 0)
|
179 |
+
);
|
180 |
+
|
181 |
+
// Remove deprecated option values
|
182 |
+
$aryRemoveOptions = array(
|
183 |
+
'wp-piwik_disable_gapi','wp-piwik_displayto','wp-piwik_siteid','wp-piwik_404','wp-piwik_scriptupdate',
|
184 |
+
'wp-piwik_dashboardid','wp-piwik_revision','wp-piwik_addjs','wp-piwik_settingsupdate','wp-piwik_token',
|
185 |
+
'wp-piwik_url','wp-piwik_dbwidget','wp-piwik_filter','wp-piwik_piwiklink','wp-piwik_jscode'
|
186 |
+
);
|
187 |
+
foreach ($aryRemoveOptions as $strRemoveOption) {
|
188 |
+
delete_option($strRemoveOption);
|
189 |
+
if (self::$bolWPMU) delete_site_option($strRemoveOption);
|
190 |
+
}
|
191 |
+
add_action('admin_footer', array($this, 'updateMessage'));
|
192 |
+
};add_action('admin_footer', array($this, 'updateMessage'));
|
193 |
+
// Set current revision ID
|
194 |
+
self::$aryGlobalSettings['revision'] = self::$intRevisionId;
|
195 |
+
self::$aryGlobalSettings['last_settings_update'] = time();
|
196 |
+
|
197 |
+
// Save upgraded or default settings
|
198 |
+
self::saveSettings();
|
199 |
+
// Reload settings
|
200 |
+
self::loadSettings();
|
201 |
}
|
202 |
|
203 |
+
/**
|
204 |
+
* Send a message after installing/updating
|
205 |
+
*/
|
206 |
+
function updateMessage() {
|
207 |
+
$strText = 'WP-Piwik '.self::$strVersion.' '.__('installed','wp-piwik').'.';
|
208 |
+
$strSettings = (empty(self::$aryGlobalSettings['piwik_token']) && empty(self::$aryGlobalSettings['piwik_url'])?
|
209 |
+
__('Next you should connect to Piwik','wp-piwik'):
|
210 |
+
__('Please validate your configuration','wp-piwik')
|
211 |
+
);
|
212 |
+
$strLink = sprintf('<a href="options-general.php?page=%s">%s</a>', self::$strPluginBasename, __('Settings', 'wp-piwik'));
|
213 |
+
echo '<div id="message" class="updated fade"><p>'.$strText.' '.$strSettings.': '.$strLink.'.</p></div>';
|
214 |
+
}
|
215 |
+
|
216 |
+
/**
|
217 |
+
* Add tracking code
|
218 |
+
*/
|
219 |
function footer() {
|
220 |
+
// Hotfix: Custom capability problem with WP multisite
|
221 |
+
if (self::$bolWPMU) {
|
222 |
+
foreach (self::$aryGlobalSettings['capability_stealth'] as $strKey => $strVal)
|
223 |
+
if ($strVal && current_user_can($strKey))
|
224 |
+
return;
|
225 |
+
// Add tracking code?
|
226 |
+
} elseif (current_user_can('wp-piwik_stealth')) return;
|
227 |
+
// Handle new WPMU site
|
228 |
+
if (self::$bolWPMU && empty(self::$arySettings['tracking_code'])) {
|
|
|
|
|
|
|
229 |
$aryReturn = $this->create_wpmu_site();
|
230 |
+
self::$arySettings['tracking_code'] = $aryReturn['js'];
|
231 |
+
// Handle existing WPMU site
|
232 |
} elseif (self::$bolWPMU) {
|
233 |
+
if (self::$arySettings['last_tracking_code_update'] < self::$aryGlobalSettings['last_settings_update']) {
|
234 |
+
self::$arySettings['tracking_code'] = html_entity_decode($this->call_API('SitesManager.getJavascriptTag'));
|
235 |
+
self::$arySettings['last_tracking_code_update'] = time();
|
236 |
+
self::saveSettings();
|
|
|
|
|
237 |
}
|
238 |
+
// Get code if not known
|
239 |
} elseif (empty($strJSCode)) {
|
240 |
+
self::$arySettings['tracking_code'] = html_entity_decode($this->call_API('SitesManager.getJavascriptTag'));
|
241 |
+
self::saveSettings();
|
242 |
}
|
243 |
+
// Change code if 404
|
244 |
+
if (is_404() and self::$arySettings['track_404']) $strTrackingCode = str_replace('piwikTracker.trackPageView();', 'piwikTracker.setDocumentTitle(\'404/URL = \'+encodeURIComponent(document.location.pathname+document.location.search) + \'/From = \' + encodeURIComponent(document.referrer));piwikTracker.trackPageView();', self::$arySettings['tracking_code']);
|
245 |
+
else $strTrackingCode = self::$arySettings['tracking_code'];
|
246 |
+
// Send tracking code
|
247 |
+
echo '<!-- *** WP-Piwik - see http://www.braekling.de/wp-piwik-wpmu-piwik-wordpress/ -->'."\n";
|
248 |
+
echo $strTrackingCode;
|
249 |
+
echo '<!-- *** /WP-Piwik *********************************************************** -->'."\n";
|
250 |
}
|
251 |
|
252 |
+
/**
|
253 |
+
* Add pages to admin menu
|
254 |
+
*/
|
255 |
+
function build_menu() {
|
256 |
+
// Show stats dashboard page if WP-Piwik is configured
|
257 |
+
if (!empty(self::$aryGlobalSettings['piwik_token']) && !empty(self::$aryGlobalSettings['piwik_url'])) {
|
258 |
+
// Add dashboard page
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
$intStatsPage = add_dashboard_page(
|
260 |
__('Piwik Statistics', 'wp-piwik'),
|
261 |
__('WP-Piwik', 'wp-piwik'),
|
262 |
+
(!self::$bolWPMU?'wp-piwik_read_stats':'administrator'),
|
263 |
__FILE__,
|
264 |
array($this, 'show_stats')
|
265 |
);
|
266 |
+
// Add required scripts
|
267 |
add_action('admin_print_scripts-'.$intStatsPage, array($this, 'load_scripts'));
|
268 |
+
// Add required styles
|
269 |
add_action('admin_print_styles-'.$intStatsPage, array($this, 'add_admin_style'));
|
270 |
+
// Add required header tags
|
271 |
add_action('admin_head-'.$intStatsPage, array($this, 'add_admin_header'));
|
272 |
}
|
273 |
+
// Add options page if not multi-user
|
274 |
if (!self::$bolWPMU)
|
275 |
+
// Add options page
|
276 |
$intOptionsPage = add_options_page(
|
277 |
__('WP-Piwik', 'wp-piwik'),
|
278 |
__('WP-Piwik', 'wp-piwik'),
|
279 |
+
'activate_plugins',
|
280 |
__FILE__,
|
281 |
array($this, 'show_settings')
|
282 |
);
|
283 |
+
// Add options page if multi-user and current user is site admin
|
284 |
+
elseif (function_exists('is_super_admin') && is_super_admin())
|
285 |
+
// Add options page
|
286 |
$intOptionsPage = add_options_page(
|
287 |
__('WPMU-Piwik', 'wpmu-piwik'),
|
288 |
__('WPMU-Piwik', 'wpmu-piwik'),
|
289 |
+
'manage_sites',
|
290 |
__FILE__,
|
291 |
array($this, 'show_mu_settings')
|
292 |
);
|
293 |
+
else $intOptionsPage = false;
|
294 |
+
// Add styles required by options page
|
295 |
+
if ($intOptionsPage)
|
296 |
+
add_action('admin_print_styles-'.$intOptionsPage, array($this, 'add_admin_style'));
|
297 |
}
|
298 |
|
299 |
function extend_wp_dashboard_setup() {
|
300 |
+
if (current_user_can('wp-piwik_read_stats'))
|
301 |
+
wp_add_dashboard_widget(
|
302 |
+
'wp-piwik_dashboard_widget',
|
303 |
+
__('WP-Piwik', 'wp-piwik').' - '.__(self::$aryGlobalSettings['dashboard_widget'], 'wp-piwik'),
|
304 |
+
array (&$this, 'add_wp_dashboard_widget')
|
305 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
}
|
307 |
|
308 |
function add_wp_dashboard_widget() {
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
$arySetup = array(
|
310 |
'params' => array(
|
311 |
+
'period' => 'day',
|
312 |
+
'date' => self::$aryGlobalSettings['dashboard_widget'],
|
313 |
'limit' => null
|
314 |
),
|
315 |
'inline' => true,
|
317 |
$this->create_dashboard_widget('overview', $arySetup);
|
318 |
}
|
319 |
|
320 |
+
/**
|
321 |
+
* Add plugin meta links to plugin details
|
322 |
+
*
|
323 |
+
* @see http://wpengineer.com/1295/meta-links-for-wordpress-plugins/
|
324 |
+
*/
|
325 |
function set_plugin_meta($strLinks, $strFile) {
|
326 |
+
// Get plugin basename
|
327 |
$strPlugin = plugin_basename(__FILE__);
|
328 |
+
// Add link just to this plugin's details
|
329 |
+
if ($strFile == self::$strPluginBasename)
|
330 |
return array_merge(
|
331 |
$strLinks,
|
332 |
array(
|
333 |
+
sprintf('<a href="options-general.php?page=%s">%s</a>', self::$strPluginBasename, __('Settings', 'wp-piwik'))
|
334 |
)
|
335 |
+
);
|
336 |
+
// Don't affect other plugins details
|
337 |
return $strLinks;
|
338 |
}
|
339 |
|
340 |
+
/**
|
341 |
+
* Load required scripts to admin pages
|
342 |
+
*/
|
343 |
function load_scripts() {
|
344 |
+
// Load WP-Piwik script
|
345 |
+
wp_enqueue_script('wp-piwik', $this->get_plugin_url().'js/wp-piwik.js', array('jquery', 'admin-comments', 'postbox'));
|
346 |
+
// Load jqPlot
|
347 |
+
wp_enqueue_script('wp-piwik-jqplot',$this->get_plugin_url().'js/jqplot/wp-piwik.jqplot.js',array('jquery'));
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
}
|
349 |
|
350 |
+
/**
|
351 |
+
* Load required styles to admin pages
|
352 |
+
*/
|
353 |
function add_admin_style() {
|
354 |
+
// Load WP-Piwik styles
|
355 |
wp_enqueue_style('wp-piwik', $this->get_plugin_url().'css/wp-piwik.css', array('dashboard'));
|
356 |
}
|
357 |
|
358 |
+
/**
|
359 |
+
* Add required header tags to admin pages
|
360 |
+
*/
|
361 |
+
function add_admin_header() {
|
362 |
+
// Load jqPlot IE compatibility script
|
363 |
echo '<!--[if IE]><script language="javascript" type="text/javascript" src="'.$this->get_plugin_url().(self::$bolWPMU?'wp-piwik/':'').'js/jqplot/excanvas.min.js"></script><![endif]-->';
|
364 |
+
// Load jqPlot styles
|
365 |
echo '<link rel="stylesheet" href="'.$this->get_plugin_url().'js/jqplot/jquery.jqplot.min.css" type="text/css"/>';
|
366 |
}
|
367 |
|
368 |
+
/**
|
369 |
+
* Get this plugin's URL
|
370 |
+
*/
|
371 |
function get_plugin_url() {
|
372 |
+
// Return plugins URL + /wp-piwik/
|
373 |
return trailingslashit(plugins_url().'/wp-piwik/');
|
374 |
}
|
375 |
|
376 |
+
/**
|
377 |
+
* Get remote file
|
378 |
+
*
|
379 |
+
* @param String $strURL Remote file URL
|
380 |
+
*/
|
381 |
+
function get_remote_file($strURL) {
|
382 |
+
// Use cURL if available
|
383 |
if (function_exists('curl_init')) {
|
384 |
+
// Init cURL
|
385 |
$c = curl_init($strURL);
|
386 |
+
// Configure cURL CURLOPT_RETURNTRANSFER = 1
|
387 |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
|
388 |
+
// Configure cURL CURLOPT_HEADER = 0
|
389 |
curl_setopt($c, CURLOPT_HEADER, 0);
|
390 |
+
// Get result
|
391 |
$strResult = curl_exec($c);
|
392 |
+
// Close connection
|
393 |
curl_close($c);
|
394 |
+
// cURL not available but url fopen allowed
|
395 |
} elseif (ini_get('allow_url_fopen'))
|
396 |
+
// Get file using file_get_contents
|
397 |
$strResult = file_get_contents($strURL);
|
398 |
+
// Error: Not possible to get remote file
|
399 |
else $strResult = serialize(array(
|
400 |
'result' => 'error',
|
401 |
'message' => 'Remote access to Piwik not possible. Enable allow_url_fopen or CURL.'
|
402 |
));
|
403 |
+
// Return result
|
404 |
return $strResult;
|
405 |
}
|
406 |
|
407 |
function call_API($strMethod, $strPeriod='', $strDate='', $intLimit='',$bolExpanded=false) {
|
408 |
$strKey = $strMethod.'_'.$strPeriod.'_'.$strDate.'_'.$intLimit;
|
409 |
if (empty($this->aryCache[$strKey])) {
|
410 |
+
$strToken = self::$aryGlobalSettings['piwik_token'];
|
411 |
+
$strURL = self::$aryGlobalSettings['piwik_url'];
|
412 |
+
$intSite = self::$arySettings['site_id'];
|
|
|
|
|
|
|
|
|
|
|
413 |
if (self::$bolWPMU && empty($intSite)) {
|
414 |
$aryReturn = $this->create_wpmu_site();
|
415 |
$intSite = $aryReturn['id'];
|
435 |
}
|
436 |
|
437 |
function create_wpmu_site() {
|
438 |
+
$strURL = self::$aryGlobalSettings['piwik_url'];
|
|
|
439 |
$strJavaScript = '';
|
440 |
+
if (!empty(self::$aryGlobalSettings['piwik_token']) && !empty($strURL)) {
|
441 |
+
if (empty(self::$arySettings['site_id'])) {
|
|
|
|
|
442 |
$strName = get_bloginfo('name');
|
443 |
$strBlogURL = get_bloginfo('url');
|
444 |
if (substr($strURL, -1, 1) != '/') $strURL .= '/';
|
445 |
$strURL .= '?module=API&method=SitesManager.addSite';
|
446 |
$strURL .= '&siteName='.urlencode('WPMU: '.$strName).'&urls='.urlencode($strBlogURL);
|
447 |
$strURL .= '&format=PHP';
|
448 |
+
$strURL .= '&token_auth='.self::$aryGlobalSettings['piwik_token'];
|
449 |
$strResult = unserialize($this->get_remote_file($strURL));
|
450 |
if (!empty($strResult)) {
|
451 |
+
self::$arySettings['site_id'] = $strResult;
|
452 |
+
self::$arySettings['last_tracking_code_update'] = time();
|
453 |
$strJavaScript = html_entity_decode($this->call_API('SitesManager.getJavascriptTag'));
|
454 |
}
|
455 |
} else $strJavaScript = html_entity_decode($this->call_API('SitesManager.getJavascriptTag'));
|
456 |
+
self::$arySettings['tracking_code'] = $strJavaScript;
|
457 |
+
self::saveSettings();
|
458 |
}
|
459 |
+
return array('js' => $strJavaScript, 'id' => self::$arySettings['site_id']);
|
460 |
}
|
461 |
|
462 |
function create_dashboard_widget($strFile, $aryConfig) {
|
486 |
}
|
487 |
|
488 |
function show_stats() {
|
489 |
+
$strToken = self::$aryGlobalSettings['piwik_token'];
|
490 |
+
$strPiwikURL = self::$aryGlobalSettings['piwik_url'];
|
491 |
$arySortOrder = get_user_option('meta-box-order_wppiwik');
|
492 |
$aryClosed = get_user_option('closedpostboxes_wppiwik');
|
493 |
if (empty($aryClosed)) $aryClosed = array();
|
494 |
$aryDashboard = array();
|
495 |
+
$intCurrentDashboard = self::$arySettings['dashboard_revision'];
|
496 |
if (!$arySortOrder) {
|
497 |
// Set default configuration
|
498 |
$arySortOrder = array(
|
502 |
global $current_user;
|
503 |
get_currentuserinfo();
|
504 |
update_user_option($current_user->ID, 'meta-box-order_wppiwik', $arySortOrder);
|
505 |
+
self::$arySettings['dashboard_revision'] = self::$intDashboardID;
|
506 |
+
self::saveSettings();
|
507 |
} elseif ($intCurrentDashboard < self::$intDashboardID) {
|
508 |
if ($intCurrentDashboard < 5) {
|
509 |
$arySortOrder['normal'] .= ',screens_day_yesterday,systems_day_yesterday';
|
515 |
global $current_user;
|
516 |
get_currentuserinfo();
|
517 |
update_user_option($current_user->ID, 'meta-box-order_wppiwik', $arySortOrder);
|
518 |
+
self::$arySettings['dashboard_revision'] = self::$intDashboardID;
|
519 |
+
self::saveSettings();
|
520 |
}
|
521 |
foreach ($arySortOrder as $strCol => $strWidgets) {
|
522 |
$aryWidgets = explode(',', $strWidgets);
|
541 |
<h2><?php _e('Piwik Statistics', 'wp-piwik'); ?></h2>
|
542 |
<?php /************************************************************************/
|
543 |
|
544 |
+
if (self::$bolWPMU && function_exists('is_super_admin') && is_super_admin()) {
|
545 |
if (isset($_POST['wpmu_show_stats']))
|
546 |
/*if ($_POST['wpmu_show_stats'] == 'all') self::$bolOverall = true;
|
547 |
else*/ switch_to_blog((int) $_POST['wpmu_show_stats']);
|
548 |
global $blog_id;
|
549 |
+
global $wpdb;
|
550 |
+
$aryBlogs = $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM wp_blogs ORDER BY blog_id'));
|
551 |
echo '<form method="POST" action="">'."\n";
|
552 |
echo '<select name="wpmu_show_stats">'."\n";
|
|
|
553 |
foreach ($aryBlogs as $aryBlog) {
|
554 |
+
$objBlog = get_blog_details($aryBlog->blog_id, true);
|
555 |
echo '<option value="'.$objBlog->blog_id.'"'.($blog_id == $objBlog->blog_id?' selected="selected"':'').'>'.$objBlog->blogname.'</option>'."\n";
|
556 |
}
|
557 |
echo '</select><input type="submit" value="'.__('Change').'" />'."\n ";
|
588 |
</div>
|
589 |
</div>
|
590 |
<?php /************************************************************************/
|
591 |
+
if (self::$bolWPMU && function_exists('is_super_admin') && is_super_admin()) {
|
592 |
restore_current_blog(); self::$bolOverall = false;
|
593 |
}
|
594 |
}
|
595 |
|
596 |
+
function applySettings() {
|
597 |
+
if (!self::$bolWPMU) {
|
598 |
+
self::$aryGlobalSettings['add_tracking_code'] = (isset($_POST['wp-piwik_addjs'])?$_POST['wp-piwik_addjs']:'');
|
599 |
+
self::$aryGlobalSettings['dashboard_widget'] = (isset($_POST['wp-piwik_dbwidget'])?$_POST['wp-piwik_dbwidget']:false);
|
600 |
+
self::$aryGlobalSettings['piwik_shortcut'] = (isset($_POST['wp-piwik_piwiklink'])?$_POST['wp-piwik_piwiklink']:false);
|
601 |
+
self::$arySettings['site_id'] = (isset($_POST['wp-piwik_siteid'])?$_POST['wp-piwik_siteid']:NULL);
|
602 |
+
self::$arySettings['track_404'] = (isset($_POST['wp-piwik_404'])?$_POST['wp-piwik_404']:false);
|
603 |
+
}
|
604 |
+
self::$aryGlobalSettings['piwik_token'] = (isset($_POST['wp-piwik_token'])?$_POST['wp-piwik_token']:'');
|
605 |
+
self::$aryGlobalSettings['piwik_url'] = (isset($_POST['wp-piwik_url'])?$_POST['wp-piwik_url']:'');
|
606 |
+
self::$aryGlobalSettings['capability_stealth'] = (isset($_POST['wp-piwik_filter'])?$_POST['wp-piwik_filter']:array());
|
607 |
+
self::$aryGlobalSettings['capability_read_stats'] = (isset($_POST['wp-piwik_displayto'])?$_POST['wp-piwik_displayto']:array());
|
608 |
+
self::$aryGlobalSettings['last_settings_update'] = time();
|
609 |
+
self::saveSettings();
|
|
|
|
|
610 |
}
|
611 |
|
612 |
+
function show_settings() {
|
613 |
+
$strToken = self::$aryGlobalSettings['piwik_token'];
|
614 |
+
$strURL = self::$aryGlobalSettings['piwik_url'];
|
615 |
+
$intSite = self::$arySettings['site_id'];
|
616 |
+
if (isset($_POST['action']) && $_POST['action'] == 'save_settings')
|
617 |
+
echo '<div id="message" class="updated fade"><p>'.__('Changes saved','wp-piwik').'</p></div>';
|
|
|
|
|
618 |
/***************************************************************************/ ?>
|
619 |
<div class="wrap">
|
620 |
<h2><?php _e('WP-Piwik Settings', 'wp-piwik') ?></h2>
|
669 |
'>'.htmlentities($arySite['name'], ENT_QUOTES, 'utf-8').
|
670 |
'</option>';
|
671 |
echo '</select></div>';
|
672 |
+
if (empty($intSite)) {
|
673 |
+
self::$arySettings['site_id'] = $aryData[0]['idsite'];
|
674 |
+
self::saveSettings();
|
675 |
+
}
|
676 |
+
$intSite = self::$arySettings['site_id'];
|
677 |
+
$int404 = self::$arySettings['track_404'];
|
678 |
+
$intAddJS = self::$aryGlobalSettings['add_tracking_code'];
|
679 |
+
$intDashboardWidget = self::$aryGlobalSettings['dashboard_widget'];
|
680 |
+
$intShowLink = self::$aryGlobalSettings['piwik_shortcut'];
|
681 |
$strJavaScript = html_entity_decode($this->call_API('SitesManager.getJavascriptTag'));
|
682 |
+
if ($intAddJS) {
|
683 |
+
self::$arySettings['tracking_code'] = $strJavaScript;
|
684 |
+
self::saveSettings();
|
685 |
+
}
|
686 |
/***************************************************************************/ ?>
|
687 |
<div><input type="submit" name="Submit" value="<?php _e('Save settings', 'wp-piwik') ?>" /></div>
|
688 |
</div>
|
711 |
global $wp_roles;
|
712 |
echo '<h4><label>'.__('Tracking filter', 'wp-piwik').':</label></h4>';
|
713 |
echo '<div class="input-wrap">';
|
714 |
+
$aryFilter = self::$aryGlobalSettings['capability_stealth'];
|
715 |
foreach($wp_roles->role_names as $strKey => $strName) {
|
716 |
echo '<input type="checkbox" '.(isset($aryFilter[$strKey]) && $aryFilter[$strKey]?'checked="checked" ':'').'value="1" name="wp-piwik_filter['.$strKey.']" /> '.$strName.' ';
|
717 |
}
|
718 |
echo '</div>';
|
719 |
echo '<div class="wp-piwik_desc">'.
|
720 |
__('Choose users by user role you do <strong>not</strong> want to track.'.
|
721 |
+
' Requires enabled "Add script"-functionality.','wp-piwik').'</div>';
|
722 |
/***************************************************************************/ ?>
|
723 |
<div><input type="submit" name="Submit" value="<?php _e('Save settings', 'wp-piwik') ?>" /></div>
|
724 |
</div>
|
729 |
<?php
|
730 |
echo '<h4><label for="wp-piwik_dbwidget">'.__('Dashboard', 'wp-piwik').':</label></h4>'.
|
731 |
'<div class="input-wrap"><select id="wp-piwik_dbwidget" name="wp-piwik_dbwidget">'.
|
732 |
+
'<option value="0"'.(!$intDashboardWidget?' selected="selected"':'').'>'.__('No', 'wp-piwik').'</option>'.
|
733 |
+
'<option value="yesterday"'.($intDashboardWidget == 'yesterday'?' selected="selected"':'').'>'.__('Yes','wp-piwik').' ('.__('yesterday', 'wp-piwik').').</option>'.
|
734 |
+
'<option value="today"'.($intDashboardWidget == 'today'?' selected="selected"':'').'>'.__('Yes','wp-piwik').' ('.__('today', 'wp-piwik').').</option>'.
|
735 |
+
'<option value="last30"'.($intDashboardWidget == 'last30'?' selected="selected"':'').'>'.__('Yes','wp-piwik').' ('.__('last 30 days','wp-piwik').').</option>'.
|
736 |
'</select></div>';
|
737 |
echo '<div class="wp-piwik_desc">'.
|
738 |
__('Display a dashboard widget to your WordPress dashboard.', 'wp-piwik').'</div>';
|
743 |
__('Display a shortcut to Piwik itself.', 'wp-piwik').'</div>';
|
744 |
echo '<h4><label>'.__('Display to', 'wp-piwik').':</label></h4>';
|
745 |
echo '<div class="input-wrap">';
|
746 |
+
$intDisplayTo = self::$aryGlobalSettings['capability_read_stats'];
|
|
|
747 |
foreach($wp_roles->role_names as $strKey => $strName) {
|
748 |
+
$role = get_role($strKey);
|
749 |
+
echo '<input name="wp-piwik_displayto['.$strKey.']" type="checkbox" value="1"'.(isset(self::$aryGlobalSettings['capability_read_stats'][$strKey]) && self::$aryGlobalSettings['capability_read_stats'][$strKey]?' checked="checked"':'').'/> '.$strName.' ';
|
|
|
750 |
}
|
|
|
751 |
echo '</div><div class="wp-piwik_desc">'.
|
752 |
+
__('Choose user roles allowed to see the statistics page.', 'wp-piwik').
|
753 |
'</div>';
|
754 |
}
|
755 |
}
|
767 |
<?php /************************************************************************/
|
768 |
}
|
769 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
770 |
function show_mu_settings() {
|
771 |
+
$strToken = self::$aryGlobalSettings['piwik_token'];
|
772 |
+
$strURL = self::$aryGlobalSettings['piwik_url'];
|
773 |
+
if (isset($_POST['action']) && $_POST['action'] == 'save_settings')
|
774 |
+
echo '<div id="message" class="updated fade"><p>'.__('Changes saved','wp-piwik').'</p></div>';
|
|
|
|
|
775 |
/***************************************************************************/ ?>
|
776 |
<div class="wrap">
|
777 |
<h2><?php _e('WPMU-Piwik Settings', 'wp-piwik') ?></h2>
|
778 |
<?php $this->donate(); ?>
|
|
|
779 |
<form method="post" action="">
|
780 |
+
<div id="dashboard-widgets-wrap">
|
781 |
+
<div id="dashboard-widgets" class="metabox-holder">
|
782 |
+
<div class="wp-piwik-settings-container" id="postbox-container">
|
783 |
+
<div class="postbox wp-piwik-settings" >
|
784 |
+
<h3 class='hndle'><span><?php _e('Account settings', 'wp-piwik'); ?></span></h3>
|
785 |
+
<div class="inside">
|
786 |
+
<h4><label for="wp-piwik_url"><?php _e('Piwik URL', 'wp-piwik'); ?>:</label></h4>
|
787 |
+
<div class="input-text-wrap">
|
788 |
+
<input type="text" name="wp-piwik_url" id="wp-piwik_url" value="<?php echo $strURL; ?>" />
|
789 |
+
</div>
|
790 |
+
<h4><label for="wp-piwik_token"><?php _e('Auth token', 'wp-piwik'); ?>:</label></h4>
|
791 |
+
<div class="input-text-wrap">
|
792 |
+
<input type="text" name="wp-piwik_token" id="wp-piwik_token" value="<?php echo $strToken; ?>" />
|
793 |
+
</div>
|
794 |
+
<div class="wp-piwik_desc">
|
795 |
+
<?php _e(
|
796 |
+
'To enable Piwik statistics, please enter your Piwik'.
|
797 |
+
' base URL (like http://mydomain.com/piwik) and your'.
|
798 |
+
' personal authentification token. You can get the token'.
|
799 |
+
' on the API page inside your Piwik interface. It looks'.
|
800 |
+
' like "1234a5cd6789e0a12345b678cd9012ef".'
|
801 |
+
, 'wp-piwik'
|
802 |
+
); ?>
|
803 |
+
</div>
|
804 |
+
<div class="wp-piwik_desc">
|
805 |
+
<?php _e(
|
806 |
+
'<strong>Important note:</strong> You have to choose a token which provides administration access. WPMU-Piwik will create new Piwik sites for each blog if it is shown the first time and it is not added yet. All users can access their own statistics only, while site admins can access all statistics. To avoid conflicts, you should use a clean Piwik installation without other sites added. The provided themes should use wp_footer, because it adds the Piwik javascript code to each page.', 'wp-piwik');
|
807 |
+
?>
|
808 |
+
</div>
|
809 |
<?php /************************************************************************/
|
810 |
+
if (!empty($strToken) && !empty($strURL)) {
|
811 |
global $wp_roles;
|
812 |
+
echo '<h4><label>'.__('Tracking filter', 'wp-piwik').':</label></h4>';
|
813 |
+
echo '<div class="input-wrap">';
|
814 |
+
$aryFilter = self::$aryGlobalSettings['capability_stealth'];
|
815 |
foreach($wp_roles->role_names as $strKey => $strName) {
|
816 |
echo '<input type="checkbox" '.(isset($aryFilter[$strKey]) && $aryFilter[$strKey]?'checked="checked" ':'').'value="1" name="wp-piwik_filter['.$strKey.']" /> '.$strName.' ';
|
817 |
+
};
|
818 |
+
echo '</div>';
|
819 |
+
echo '<div class="wp-piwik_desc">'.
|
820 |
+
__('Choose users by user role you do <strong>not</strong> want to track.', 'wp-piwik').'</div>';
|
821 |
+
|
822 |
+
/*echo '<h4><label>'.__('Display to', 'wp-piwik').':</label></h4>';
|
823 |
+
echo '<div class="input-wrap">';
|
824 |
+
$intDisplayTo = self::$aryGlobalSettings['capability_read_stats'];
|
825 |
+
foreach($wp_roles->role_names as $strKey => $strName) {
|
826 |
+
$role = get_role($strKey);
|
827 |
+
echo '<input name="wp-piwik_displayto['.$strKey.']" type="checkbox" value="1"'.(isset(self::$aryGlobalSettings['capability_read_stats'][$strKey]) && self::$aryGlobalSettings['capability_read_stats'][$strKey]?' checked="checked"':'').'/> '.$strName.' ';
|
828 |
}
|
829 |
+
echo '</div><div class="wp-piwik_desc">'.
|
830 |
+
__('Choose user roles allowed to see the statistics page.', 'wp-piwik').
|
831 |
+
'</div>';*/
|
|
|
832 |
}
|
833 |
/***************************************************************************/ ?>
|
834 |
+
<div><input type="submit" name="Submit" value="<?php _e('Save settings', 'wp-piwik') ?>" /></div>
|
835 |
+
</div>
|
836 |
+
</div>
|
837 |
+
</div>
|
838 |
+
<input type="hidden" name="action" value="save_settings" />
|
839 |
+
</div></div>
|
840 |
</form>
|
|
|
841 |
<?php $this->credits(); ?>
|
842 |
</div>
|
843 |
<?php /************************************************************************/
|
871 |
|
872 |
function credits() {
|
873 |
/***************************************************************************/ ?>
|
874 |
+
<h2 style="clear:left;"><?php _e('Credits', 'wp-piwik'); ?></h2>
|
875 |
<div class="inside">
|
876 |
+
<p><strong><?php _e('Thank you very much for your donation', 'wp-piwik'); ?>:</strong> Marco L., Rolf W., Tobias U., Lars K., Donna F. <?php _e('and all people flattering this','wp-piwik'); ?>!</p>
|
877 |
+
<p><?php _e('Graphs powered by <a href="http://www.jqplot.com/">jqPlot</a>, an open source project by Chris Leonello. Give it a try! (License: GPL 2.0 and MIT)','wp-piwik'); ?></p>
|
878 |
+
<p><?php _e('Thank you very much','wp-piwik'); ?>, <a href="http://blogu.programeshqip.org/">Besnik Bleta</a>, <a href="http://www.fatcow.com/">FatCow</a>, <a href="http://www.pamukkaleturkey.com/">Rene</a>, Fab, <a href="http://ezbizniz.com/">EzBizNiz</a><?php _e(', and', 'wp-piwik'); ?> Gormer <?php _e('for your translation work','wp-piwik'); ?>!</p>
|
879 |
+
<p><?php _e('Thank you very much, all users who send me mails containing criticism, commendation, feature requests and bug reports! You help me to make WP-Piwik much better.','wp-piwik'); ?></p>
|
880 |
+
<p><?php _e('Thank <strong>you</strong> for using my plugin. It is the best commendation if my piece of code is really used!','wp-piwik'); ?></p>
|
881 |
</div>
|
882 |
<?php /************************************************************************/
|
883 |
}
|
886 |
if (class_exists('wp_piwik'))
|
887 |
$GLOBALS['wp_piwik'] = new wp_piwik();
|
888 |
|
889 |
+
/* EOF */
|