Version Description
- Bugfix regarding tracking code changes in proxy mode, see http://wordpress.org/support/topic/problem-with-https-in-proxy-mode
- Feature: Change text "WP-Piwik" in menu items and dashboard widgets
- Code cleanup ("new" first step)
- Debugging: Logger added
- Avoid double slash (//) in tracking code
Download this release
Release Info
Developer | Braekling |
Plugin | WP-Matomo (WP-Piwik) |
Version | 0.9.9.2 |
Comparing to | |
See all releases |
Code changes from version 0.9.9.1 to 0.9.9.2
- cache/.htaccess +1 -0
- cache/index.php +2 -0
- classes/.htaccess +1 -0
- classes/WP_Piwik_Logger.php +45 -0
- classes/WP_Piwik_Logger_Dummy.php +9 -0
- classes/WP_Piwik_Logger_File.php +48 -0
- classes/WP_Piwik_Settings.php +136 -0
- classes/index.php +2 -0
- config.php +9 -0
- dashboard/index.php +2 -0
- dashboard/overview.php +2 -2
- debug/testscript.php +5 -5
- languages/index.php +2 -0
- logs/.htaccess +1 -0
- logs/index.php +2 -0
- readme.txt +9 -2
- settings/credits.php +1 -1
- settings/homepage.php +2 -2
- settings/index.php +2 -0
- settings/piwik.php +20 -20
- settings/sitebrowser.php +2 -1
- settings/support.php +2 -2
- settings/tracking.php +17 -17
- settings/views.php +18 -14
- shortcodes/index.php +2 -0
- update/80403.php +5 -3
- update/80502.php +1 -1
- update/80602.php +1 -1
- update/80800.php +1 -1
- update/90001.php +9 -8
- update/90206.php +1 -1
- update/90405.php +4 -4
- update/90601.php +2 -2
- update/90700.php +1 -1
- update/90801.php +5 -8
- update/90821.php +1 -1
- update/90910.php +2 -2
- update/90920.php +2 -0
- update/index.php +2 -0
- wp-piwik.php +232 -387
cache/.htaccess
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
Deny from all
|
cache/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Nothing to see...
|
classes/.htaccess
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
Deny from all
|
classes/WP_Piwik_Logger.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
abstract class WP_Piwik_Logger {
|
4 |
+
|
5 |
+
private $loggerName = 'unnamed';
|
6 |
+
private $loggerContent = array();
|
7 |
+
private $startMicrotime = null;
|
8 |
+
|
9 |
+
abstract function loggerOutput($loggerTime, $loggerMessage);
|
10 |
+
|
11 |
+
public function __construct($loggerName) {
|
12 |
+
$this->setName($loggerName);
|
13 |
+
$this->setStartMicrotime(microtime(true));
|
14 |
+
$this->log('Logging started -------------------------------');
|
15 |
+
}
|
16 |
+
|
17 |
+
public function __destruct() {
|
18 |
+
$this->log('Logging finished ------------------------------');
|
19 |
+
}
|
20 |
+
|
21 |
+
public function log($loggerMessage) {
|
22 |
+
$this->loggerOutput($this->getElapsedMicrotime(), $loggerMessage);
|
23 |
+
}
|
24 |
+
|
25 |
+
private function setName($loggerName) {
|
26 |
+
$this->loggerName = $loggerName;
|
27 |
+
}
|
28 |
+
|
29 |
+
public function getName() {
|
30 |
+
return $this->loggerName;
|
31 |
+
}
|
32 |
+
|
33 |
+
private function setStartMicrotime($startMicrotime) {
|
34 |
+
$this->startMicrotime = $startMicrotime;
|
35 |
+
}
|
36 |
+
|
37 |
+
public function getStartMicrotime() {
|
38 |
+
return $this->startMicrotime;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function getElapsedMicrotime() {
|
42 |
+
return microtime(true) - $this->getStartMicrotime();
|
43 |
+
}
|
44 |
+
|
45 |
+
}
|
classes/WP_Piwik_Logger_Dummy.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once('WP_Piwik_Logger.php');
|
4 |
+
|
5 |
+
class WP_Piwik_Logger_Dummy extends WP_Piwik_Logger {
|
6 |
+
|
7 |
+
public function loggerOutput($loggerTime, $loggerMessage) {}
|
8 |
+
|
9 |
+
}
|
classes/WP_Piwik_Logger_File.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once('WP_Piwik_Logger.php');
|
4 |
+
|
5 |
+
class WP_Piwik_Logger_File extends WP_Piwik_Logger {
|
6 |
+
|
7 |
+
private $loggerFile = null;
|
8 |
+
|
9 |
+
private function encodeFilename($fileName) {
|
10 |
+
$fileName = str_replace (' ', '_', $fileName);
|
11 |
+
preg_replace('/[^0-9^a-z^_^.]/', '', $fileName);
|
12 |
+
return $fileName;
|
13 |
+
}
|
14 |
+
|
15 |
+
private function setFilename() {
|
16 |
+
$this->loggerFile = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'logs'.DIRECTORY_SEPARATOR.
|
17 |
+
date('Ymd').'_'.$this->encodeFilename($this->getName()).'.log';
|
18 |
+
}
|
19 |
+
|
20 |
+
private function getFilename() {
|
21 |
+
return $this->loggerFile;
|
22 |
+
}
|
23 |
+
|
24 |
+
private function openFile() {
|
25 |
+
if (!$this->loggerFile)
|
26 |
+
$this->setFilename();
|
27 |
+
return fopen($this->getFilename(), 'a');
|
28 |
+
}
|
29 |
+
|
30 |
+
private function closeFile($fileHandle) {
|
31 |
+
fclose($fileHandle);
|
32 |
+
}
|
33 |
+
|
34 |
+
private function writeFile($fileHandle, $fileContent) {
|
35 |
+
fwrite($fileHandle, $fileContent."\n");
|
36 |
+
}
|
37 |
+
|
38 |
+
private function formatMicrotime($loggerTime) {
|
39 |
+
return sprintf('[%6s sec]',number_format($loggerTime,3));
|
40 |
+
}
|
41 |
+
|
42 |
+
public function loggerOutput($loggerTime, $loggerMessage) {
|
43 |
+
if ($fileHandle = $this->openFile()) {
|
44 |
+
$this->writeFile($fileHandle, $this->formatMicrotime($loggerTime).' '.$loggerMessage);
|
45 |
+
$this->closeFile($fileHandle);
|
46 |
+
}
|
47 |
+
}
|
48 |
+
}
|
classes/WP_Piwik_Settings.php
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WP_Piwik_Settings {
|
4 |
+
|
5 |
+
private static $logger, $defaultSettings;
|
6 |
+
|
7 |
+
private $globalSettings = array(
|
8 |
+
'revision' => 90921,
|
9 |
+
'plugin_display_name' => 'WP-Piwik',
|
10 |
+
'add_tracking_code' => false,
|
11 |
+
'last_settings_update' => 0,
|
12 |
+
'piwik_token' => '',
|
13 |
+
'piwik_url' => '',
|
14 |
+
'piwik_path' => '',
|
15 |
+
'piwik_mode' => 'http',
|
16 |
+
'piwik_useragent' => 'php',
|
17 |
+
'piwik_useragent_string' => 'WP-Piwik',
|
18 |
+
'connection_timeout' => 5,
|
19 |
+
'dashboard_widget' => false,
|
20 |
+
'dashboard_chart' => false,
|
21 |
+
'dashboard_seo' => false,
|
22 |
+
'stats_seo' => false,
|
23 |
+
'capability_stealth' => array(),
|
24 |
+
'capability_read_stats' => array('administrator' => true),
|
25 |
+
'piwik_shortcut' => false,
|
26 |
+
'default_date' => 'yesterday',
|
27 |
+
'auto_site_config' => true,
|
28 |
+
'track_404' => false,
|
29 |
+
'track_search' => false,
|
30 |
+
'track_mode' => 0,
|
31 |
+
'track_post' => false,
|
32 |
+
'track_proxy' => false,
|
33 |
+
'track_cdnurlssl' => '',
|
34 |
+
'track_noscript' => false,
|
35 |
+
'disable_timelimit' => false,
|
36 |
+
'disable_ssl_verify' => false,
|
37 |
+
'disable_cookies' => false,
|
38 |
+
'toolbar' => false,
|
39 |
+
'shortcodes' => false
|
40 |
+
),
|
41 |
+
$settings = array(
|
42 |
+
'name' => '',
|
43 |
+
'tracking_code' => '',
|
44 |
+
'site_id' => NULL,
|
45 |
+
'last_tracking_code_update' => 0,
|
46 |
+
'dashboard_revision' => 0,
|
47 |
+
'noscript_code' => ''
|
48 |
+
),
|
49 |
+
$settingsChanged = false;
|
50 |
+
|
51 |
+
public function __construct($objLogger) {
|
52 |
+
self::$logger = $objLogger;
|
53 |
+
self::$logger->log('Store default settings');
|
54 |
+
self::$defaultSettings = array('globalSettings' => $this->globalSettings, 'settings' => $this->settings);
|
55 |
+
self::$logger->log('Load settings');
|
56 |
+
$this->globalSettings = (is_plugin_active_for_network('wp-piwik/wp-piwik.php')?
|
57 |
+
get_site_option('wp-piwik_global-settings', $this->globalSettings):
|
58 |
+
get_option('wp-piwik_global-settings', $this->globalSettings)
|
59 |
+
);
|
60 |
+
$this->settings = get_option('wp-piwik_settings',$this->settings);
|
61 |
+
}
|
62 |
+
|
63 |
+
public function save() {
|
64 |
+
if (!$this->settingsChanged) {
|
65 |
+
self::$logger->log('No settings changed yet');
|
66 |
+
return;
|
67 |
+
}
|
68 |
+
self::$logger->log('Save settings');
|
69 |
+
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php'))
|
70 |
+
update_site_option('wp-piwik_global-settings', $this->globalSettings);
|
71 |
+
else
|
72 |
+
update_option('wp-piwik_global-settings', $this->globalSettings);
|
73 |
+
update_option('wp-piwik_settings', $this->settings);
|
74 |
+
global $wp_roles;
|
75 |
+
if (!is_object($wp_roles))
|
76 |
+
$wp_roles = new WP_Roles();
|
77 |
+
if (!is_object($wp_roles)) die("STILL NO OBJECT");
|
78 |
+
foreach($wp_roles->role_names as $strKey => $strName) {
|
79 |
+
$objRole = get_role($strKey);
|
80 |
+
foreach (array('stealth', 'read_stats') as $strCap)
|
81 |
+
if (isset($this->getGlobalOption('capability_'.$strCap)[$strKey]) && $this->getGlobalOption('capability_'.$strCap)[$strKey])
|
82 |
+
$objRole->add_cap('wp-piwik_'.$strCap);
|
83 |
+
else $objRole->remove_cap('wp-piwik_'.$strCap);
|
84 |
+
}
|
85 |
+
$this->settingsChanges = false;
|
86 |
+
}
|
87 |
+
|
88 |
+
public function getGlobalOption($key) {
|
89 |
+
return isset($this->globalSettings[$key])?$this->globalSettings[$key]:null;
|
90 |
+
}
|
91 |
+
|
92 |
+
public function getOption($key) {
|
93 |
+
return isset($this->settings[$key])?$this->settings[$key]:null;
|
94 |
+
}
|
95 |
+
|
96 |
+
public function setGlobalOption($key, $value) {
|
97 |
+
$this->settingsChanged = true;
|
98 |
+
self::$logger->log('Changed global option '.$key.': '.(is_array($value)?serialize($value):$value));
|
99 |
+
$this->globalSettings[$key] = $value;
|
100 |
+
}
|
101 |
+
|
102 |
+
public function setOption($key, $value) {
|
103 |
+
$this->settingsChanged = true;
|
104 |
+
self::$logger->log('Changed option '.$key.': '.$value);
|
105 |
+
$this->settings[$key] = $value;
|
106 |
+
}
|
107 |
+
|
108 |
+
public function resetSettings($bolFull = false) {
|
109 |
+
self::$logger->log('Reset WP-Piwik settings');
|
110 |
+
global $wpdb;
|
111 |
+
$keepSettings = array(
|
112 |
+
'piwik_token' => $this->getGlobalOption('piwik_token'),
|
113 |
+
'piwik_url' => $this->getGlobalOption('piwik_url'),
|
114 |
+
'piwik_path' => $this->getGlobalOption('piwik_path'),
|
115 |
+
'piwik_mode' => $this->getGlobalOption('piwik_mode')
|
116 |
+
);
|
117 |
+
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php')) {
|
118 |
+
delete_site_option('wp-piwik_global-settings');
|
119 |
+
$aryBlogs = $wpdb->get_results('SELECT blog_id FROM '.$wpdb->blogs.' ORDER BY blog_id');
|
120 |
+
foreach ($aryBlogs as $aryBlog)
|
121 |
+
delete_blog_option($aryBlog->blog_id, 'wp-piwik_settings');
|
122 |
+
if (!$bolFull) update_site_option('wp-piwik_global-settings', $keepSettings);
|
123 |
+
} else {
|
124 |
+
delete_option('wp-piwik_global-settings');
|
125 |
+
delete_option('wp-piwik_settings');
|
126 |
+
}
|
127 |
+
$this->globalSettings = self::$defaultSettings['globalSettings'];
|
128 |
+
$this->settings = self::$defaultSettings['settings'];
|
129 |
+
if (!$bolFull) {
|
130 |
+
self::$logger->log('Restore connection settings');
|
131 |
+
foreach ($keepSettings as $key => $value)
|
132 |
+
$this->setGlobalOption($key, $value);
|
133 |
+
}
|
134 |
+
$this->save();
|
135 |
+
}
|
136 |
+
}
|
classes/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Nothing to see...
|
config.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
Configure WP-Piwik Logger
|
5 |
+
0: Logger disabled
|
6 |
+
1: Log to screen (available soon)
|
7 |
+
2: Log to file (logs/YYYYMMDD_wp-piwik.log)
|
8 |
+
*/
|
9 |
+
const WP_PIWIK_ACTIVATE_LOGGER = 0;
|
dashboard/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Nothing to see...
|
dashboard/overview.php
CHANGED
@@ -60,8 +60,8 @@
|
|
60 |
echo '<tr><td>'.__('Total time spent', 'wp-piwik').':</td><td>'.$strTime.'</td></tr>';
|
61 |
echo '<tr><td>'.__('Time/visit', 'wp-piwik').':</td><td>'.$strAvgTime.'</td></tr>';
|
62 |
echo '<tr><td>'.__('Bounce count', 'wp-piwik').':</td><td>'.$aryConf['data']['bounce_count'].' ('.$aryConf['data']['bounce_rate'].')</td></tr>';
|
63 |
-
if (self::$
|
64 |
-
echo '<tr><td>'.__('Shortcut', 'wp-piwik').':</td><td><a href="'.self::$
|
65 |
/***************************************************************************/ ?>
|
66 |
</tbody>
|
67 |
</table>
|
60 |
echo '<tr><td>'.__('Total time spent', 'wp-piwik').':</td><td>'.$strTime.'</td></tr>';
|
61 |
echo '<tr><td>'.__('Time/visit', 'wp-piwik').':</td><td>'.$strAvgTime.'</td></tr>';
|
62 |
echo '<tr><td>'.__('Bounce count', 'wp-piwik').':</td><td>'.$aryConf['data']['bounce_count'].' ('.$aryConf['data']['bounce_rate'].')</td></tr>';
|
63 |
+
if (self::$settings->getGlobalOption('piwik_shortcut'))
|
64 |
+
echo '<tr><td>'.__('Shortcut', 'wp-piwik').':</td><td><a href="'.self::$settings->getGlobalOption('piwik_url').'">Piwik</a>'.(isset($aryConf['inline']) && $aryConf['inline']?' - <a href="?page=wp-piwik_stats">WP-Piwik</a>':'').'</td></tr>';
|
65 |
/***************************************************************************/ ?>
|
66 |
</tbody>
|
67 |
</table>
|
debug/testscript.php
CHANGED
@@ -9,13 +9,13 @@
|
|
9 |
*****************/
|
10 |
|
11 |
// PIWIK URL, e.g. http://www.website.example/piwik
|
12 |
-
$strPiwikURL = self::$
|
13 |
// PIWIK AUTH TOKEN, e.g. 1234a5cd6789e0a12345b678cd9012ef
|
14 |
-
$strPiwikAuthToken = self::$
|
15 |
// YOUR BLOG'S URL, e.g. http://www.website.example
|
16 |
$strPiwikYourBlogURL = get_bloginfo('url');
|
17 |
// User agent
|
18 |
-
$strUA = self::$
|
19 |
|
20 |
/* That's all, stop editing! */
|
21 |
|
@@ -72,11 +72,11 @@ foreach ($aryURLs as $strMethod => $strURL) {
|
|
72 |
$intTest++;
|
73 |
echo '*** Test '.$intTest.'/'.count($aryURLs).': '.$strMethod.' ***'."\n";
|
74 |
echo 'Using: '.(function_exists('curl_init')?'cURL':'fopen')."\n";
|
75 |
-
echo 'SSL peer verification: '.(function_exists('curl_init') && !self::$
|
76 |
echo 'User Agent: '.$strUA."\n";
|
77 |
echo 'Call: '.$strURL.'&token_auth= + TOKEN'."\n";
|
78 |
$x = microtime(true);
|
79 |
-
$strResult = getRemoteFile($strURL,$strToken,!self::$
|
80 |
$x = microtime(true) - $x;
|
81 |
echo 'Result:'."\n";
|
82 |
echo htmlentities($strResult)."\n";
|
9 |
*****************/
|
10 |
|
11 |
// PIWIK URL, e.g. http://www.website.example/piwik
|
12 |
+
$strPiwikURL = self::$settings->getGlobalOption('piwik_url');
|
13 |
// PIWIK AUTH TOKEN, e.g. 1234a5cd6789e0a12345b678cd9012ef
|
14 |
+
$strPiwikAuthToken = self::$settings->getGlobalOption('piwik_token');
|
15 |
// YOUR BLOG'S URL, e.g. http://www.website.example
|
16 |
$strPiwikYourBlogURL = get_bloginfo('url');
|
17 |
// User agent
|
18 |
+
$strUA = self::$settings->getGlobalOption('piwik_useragent')=='php'?ini_get('user_agent'):self::$settings->getGlobalOption('piwik_useragent_string');
|
19 |
|
20 |
/* That's all, stop editing! */
|
21 |
|
72 |
$intTest++;
|
73 |
echo '*** Test '.$intTest.'/'.count($aryURLs).': '.$strMethod.' ***'."\n";
|
74 |
echo 'Using: '.(function_exists('curl_init')?'cURL':'fopen')."\n";
|
75 |
+
echo 'SSL peer verification: '.(function_exists('curl_init') && !self::$settings->getGlobalOption('disable_ssl_verify')?'enabled':'disabled')."\n";
|
76 |
echo 'User Agent: '.$strUA."\n";
|
77 |
echo 'Call: '.$strURL.'&token_auth= + TOKEN'."\n";
|
78 |
$x = microtime(true);
|
79 |
+
$strResult = getRemoteFile($strURL,$strToken,!self::$settings->getGlobalOption('disable_ssl_verify'),$strUA);
|
80 |
$x = microtime(true) - $x;
|
81 |
echo 'Result:'."\n";
|
82 |
echo htmlentities($strResult)."\n";
|
languages/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Nothing to see...
|
logs/.htaccess
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
Deny from all
|
logs/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Nothing to see...
|
readme.txt
CHANGED
@@ -19,7 +19,7 @@ Look at the [Piwik website](http://piwik.org/) to get further information about
|
|
19 |
|
20 |
*This plugin is not created or provided by the Piwik project team.*
|
21 |
|
22 |
-
Languages: English, German, Albanian, Azerbaijani, Belorussian, Dutch, French, Greek, Lithuanian, Norwegian, Persian, Romanian, Russian, Spanish, Swedish, Ukrainian
|
23 |
|
24 |
*Note: If you vote "It's broken", please tell me about your problem. It's hard to fix a bug I don't know about! ;-)*
|
25 |
|
@@ -46,7 +46,7 @@ See section "Installation".
|
|
46 |
* Graphs powered by [jqPlot](http://www.jqplot.com/) (GPL 2.0 and MIT) and and [jQuery Sparklines](http://omnipotent.net/jquery.sparkline/) (New BSD License).
|
47 |
* Metabox support inspired by [Heiko Rabe's metabox demo plugin](http://www.code-styling.de/english/how-to-use-wordpress-metaboxes-at-own-plugins).
|
48 |
* Translation credits see plugin settings
|
49 |
-
* Donations: Marco L., Rolf W., Tobias U., Lars K., Donna F., Kevin D., Ramos S, Thomas M., John C., Andreas G., Ben M., the Piwik team itself, and all people flattering this.
|
50 |
* All users who send me mails containing criticism, commendation, feature requests and bug reports - you help me to make WP-Piwik much better!
|
51 |
|
52 |
Thank you all!
|
@@ -114,6 +114,13 @@ Please update Piwik if not done yet (Piwik 1.11 or higher is recommended)!
|
|
114 |
|
115 |
== Changelog ==
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
= 0.9.9.1 =
|
118 |
* CDN support: http and https separated, see http://wordpress.org/support/topic/request-cdn-support-1
|
119 |
* Made <noscript> code optional. Move <noscript> code to site footer.
|
19 |
|
20 |
*This plugin is not created or provided by the Piwik project team.*
|
21 |
|
22 |
+
Languages: English, German, Albanian, Azerbaijani, Belorussian, Dutch, French, Greek, Italian, Lithuanian, Norwegian, Persian, Romanian, Russian, Spanish, Swedish, Ukrainian
|
23 |
|
24 |
*Note: If you vote "It's broken", please tell me about your problem. It's hard to fix a bug I don't know about! ;-)*
|
25 |
|
46 |
* Graphs powered by [jqPlot](http://www.jqplot.com/) (GPL 2.0 and MIT) and and [jQuery Sparklines](http://omnipotent.net/jquery.sparkline/) (New BSD License).
|
47 |
* Metabox support inspired by [Heiko Rabe's metabox demo plugin](http://www.code-styling.de/english/how-to-use-wordpress-metaboxes-at-own-plugins).
|
48 |
* Translation credits see plugin settings
|
49 |
+
* Donations: Marco L., Rolf W., Tobias U., Lars K., Donna F., Kevin D., Ramos S, Thomas M., John C., Andreas G., Ben M., Myra R. I., Carlos U. R.-S., the Piwik team itself, and all people flattering this.
|
50 |
* All users who send me mails containing criticism, commendation, feature requests and bug reports - you help me to make WP-Piwik much better!
|
51 |
|
52 |
Thank you all!
|
114 |
|
115 |
== Changelog ==
|
116 |
|
117 |
+
= 0.9.9.2 =
|
118 |
+
* Bugfix regarding tracking code changes in proxy mode, see http://wordpress.org/support/topic/problem-with-https-in-proxy-mode
|
119 |
+
* Feature: Change text "WP-Piwik" in menu items and dashboard widgets
|
120 |
+
* Code cleanup ("new" first step)
|
121 |
+
* Debugging: Logger added
|
122 |
+
* Avoid double slash (//) in tracking code
|
123 |
+
|
124 |
= 0.9.9.1 =
|
125 |
* CDN support: http and https separated, see http://wordpress.org/support/topic/request-cdn-support-1
|
126 |
* Made <noscript> code optional. Move <noscript> code to site footer.
|
settings/credits.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<tr>
|
2 |
<td>
|
3 |
-
<strong><?php _e('Thank you very much for your donation', 'wp-piwik'); ?>:</strong> Marco L., Rolf W., Tobias U., Lars K., Donna F., Kevin D., Ramos S., Thomas M., John C., Andreas G., Ben M., <?php _e('the Piwik team itself','wp-piwik');?><?php _e(', and all people flattering this','wp-piwik'); ?>!
|
4 |
</td>
|
5 |
</tr>
|
6 |
<tr>
|
1 |
<tr>
|
2 |
<td>
|
3 |
+
<strong><?php _e('Thank you very much for your donation', 'wp-piwik'); ?>:</strong> Marco L., Rolf W., Tobias U., Lars K., Donna F., Kevin D., Ramos S., Thomas M., John C., Andreas G., Ben M., Myra R. I., Carlos U. R.-S., <?php _e('the Piwik team itself','wp-piwik');?><?php _e(', and all people flattering this','wp-piwik'); ?>!
|
4 |
</td>
|
5 |
</tr>
|
6 |
<tr>
|
settings/homepage.php
CHANGED
@@ -7,5 +7,5 @@ if (is_array($strVersion) && $strVersion['result'] == 'error') self::showErrorMe
|
|
7 |
elseif (empty($strVersion)) self::showErrorMessage('Piwik did not answer. Please check your entered Piwik URL.');
|
8 |
else echo __('You are using Piwik','wp-piwik').' '.$strVersion.' '.__('and', 'wp-piwik').' WP-Piwik '.self::$strVersion.(is_plugin_active_for_network('wp-piwik/wp-piwik.php')?' '.__('in network mode'):'').'.';
|
9 |
?></td></tr>
|
10 |
-
<tr><td><?php _e('Auto site configuration is','wp-piwik'); ?> <strong><?php echo (self::$
|
11 |
-
<tr><td><?php _e('Tracking code insertion is','wp-piwik'); ?> <strong><?php echo (self::$
|
7 |
elseif (empty($strVersion)) self::showErrorMessage('Piwik did not answer. Please check your entered Piwik URL.');
|
8 |
else echo __('You are using Piwik','wp-piwik').' '.$strVersion.' '.__('and', 'wp-piwik').' WP-Piwik '.self::$strVersion.(is_plugin_active_for_network('wp-piwik/wp-piwik.php')?' '.__('in network mode'):'').'.';
|
9 |
?></td></tr>
|
10 |
+
<tr><td><?php _e('Auto site configuration is','wp-piwik'); ?> <strong><?php echo (self::$settings->getGlobalOption('auto_site_config')?__('enabled','wp-piwik'):__('disabled','wp-piwik')); ?>.</strong></td></tr>
|
11 |
+
<tr><td><?php _e('Tracking code insertion is','wp-piwik'); ?> <strong><?php echo (self::$settings->getGlobalOption('add_tracking_code')?__('enabled','wp-piwik'):__('disabled','wp-piwik')); ?>.</strong></td></tr>
|
settings/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Nothing to see...
|
settings/piwik.php
CHANGED
@@ -21,16 +21,16 @@ if (!$bolFOpen && !$bolCURL) {
|
|
21 |
</tr><tr>
|
22 |
<th><?php _e('Piwik URL', 'wp-piwik'); ?> (REST API):</th>
|
23 |
<td>
|
24 |
-
<input type="radio" name="wp-piwik_mode" onchange="javascript:$j('#wp-piwik_path,#wp-piwik_path-label').toggleClass('wp-piwik-input-hide');" value="http" <?php echo (self::$
|
25 |
-
<input id="wp-piwik_url" name="wp-piwik_url" type="text" value="<?php echo self::$
|
26 |
<label for="wp-piwik_url"></label>
|
27 |
</td>
|
28 |
</tr><tr>
|
29 |
<th><?php _e('Piwik path', 'wp-piwik'); ?> (PHP API, beta):</th>
|
30 |
<td>
|
31 |
-
<input type="radio" name="wp-piwik_mode" onchange="javascript:$j('#wp-piwik_path,#wp-piwik_path-label').toggleClass('wp-piwik-input-hide');" value="php" <?php echo (self::$
|
32 |
-
<input <?php echo (self::$
|
33 |
-
<label <?php echo (self::$
|
34 |
<?php
|
35 |
if (isset($_POST['wp-piwik_path']) && !empty($_POST['wp-piwik_path']) && realpath($_POST['wp-piwik_path']) === false)
|
36 |
echo '<p class="wp-piwik-eyecatcher">'.__('Invalid path. Please enter the file path to Piwik.', 'wp-piwik').'</p>';
|
@@ -39,18 +39,18 @@ if (!$bolFOpen && !$bolCURL) {
|
|
39 |
</tr><tr>
|
40 |
<th><?php _e('Auth token', 'wp-piwik'); ?>:</th>
|
41 |
<td>
|
42 |
-
<input name="wp-piwik_token" id="wp-piwik_token" type="text" value="<?php echo self::$
|
43 |
<label for="wp-piwik_token"></label>
|
44 |
</td>
|
45 |
</tr><?php if (!is_plugin_active_for_network('wp-piwik/wp-piwik.php')) { ?><tr>
|
46 |
<th><?php _e('Auto config', 'wp-piwik'); ?>:</th>
|
47 |
<td>
|
48 |
-
<input name="wp-piwik_auto_site_config" id="wp-piwik_auto_site_config" value="1" type="checkbox"<?php echo (self::$
|
49 |
<label for="wp-piwik_auto_site_config"><?php _e('Check this to automatically choose your blog from your Piwik sites by URL. If your blog is not added to Piwik yet, WP-Piwik will add a new site.', 'wp-piwik') ?></label>
|
50 |
</td>
|
51 |
</tr>
|
52 |
<?php
|
53 |
-
if (
|
54 |
$aryData = $this->callPiwikAPI('SitesManager.getSitesWithAtLeastViewAccess');
|
55 |
if (empty($aryData)) {
|
56 |
echo '<tr><td colspan="2">';
|
@@ -61,28 +61,28 @@ if (!empty(self::$aryGlobalSettings['piwik_url']) && !empty(self::$aryGlobalSett
|
|
61 |
echo '<tr><td colspan="2">';
|
62 |
self::showErrorMessage($aryData['message']);
|
63 |
echo '</td></tr>';
|
64 |
-
} else if (!self::$
|
65 |
echo '<tr><th>'.__('Choose site', 'wp-piwik').':</th><td>';
|
66 |
echo '<select name="wp-piwik_siteid" id="wp-piwik_siteid">';
|
67 |
$aryOptions = array();
|
68 |
foreach ($aryData as $arySite)
|
69 |
$aryOptions[$arySite['name'].'#'.$arySite['idsite']] = '<option value="'.$arySite['idsite'].
|
70 |
-
'"'.($arySite['idsite']==self::$
|
71 |
'>'.htmlentities($arySite['name'], ENT_QUOTES, 'utf-8').
|
72 |
'</option>';
|
73 |
ksort($aryOptions);
|
74 |
foreach ($aryOptions as $strOption) echo $strOption;
|
75 |
echo '</select></td></tr>';
|
76 |
} else {
|
77 |
-
if (
|
78 |
$this->addPiwikSite();
|
79 |
echo '<tr><th>'.__('Determined site', 'wp-piwik').':</th><td>';
|
80 |
echo '<div class="input-text-wrap">';
|
81 |
-
if (is_array(self::$
|
82 |
-
self::showErrorMessage(self::$
|
83 |
else foreach ($aryData as $arySite)
|
84 |
-
if ($arySite['idsite'] == self::$
|
85 |
-
echo '<input type="hidden" name="wp-piwik_siteid" id="wp-piwik_siteid" value="'.(int)self::$
|
86 |
}
|
87 |
}
|
88 |
}}
|
@@ -92,24 +92,24 @@ if (!empty(self::$aryGlobalSettings['piwik_url']) && !empty(self::$aryGlobalSett
|
|
92 |
</tr><tr>
|
93 |
<th><label><?php _e('Connection timeout', 'wp-piwik'); ?>:</label></th>
|
94 |
<td>
|
95 |
-
<input style="width:50px;" type="text" name="wp-piwik_timeout" value="<?php echo self::$
|
96 |
</td>
|
97 |
</tr>
|
98 |
<?php if (function_exists('curl_init')) { ?>
|
99 |
<tr>
|
100 |
-
<th><label <?php echo (self::$
|
101 |
<td>
|
102 |
-
<input <?php echo (self::$
|
103 |
</td>
|
104 |
</tr><tr>
|
105 |
<th><label><?php _e('User agent', 'wp-piwik'); ?>:</label></th>
|
106 |
<td>
|
107 |
-
<input type="radio" onchange="javascript:$j('#wp-piwik-useragent').toggleClass('readonly="readonly"');" name="wp-piwik_useragent" value="php" <?php echo (self::$
|
108 |
</td>
|
109 |
</tr><tr>
|
110 |
<th></th>
|
111 |
<td>
|
112 |
-
<input type="radio" onchange="javascript:$j('#wp-piwik-useragent').toggleClass('wp-piwik-useragent-disable');" name="wp-piwik_useragent" value="own" <?php echo (self::$
|
113 |
</td>
|
114 |
</tr>
|
115 |
<?php } else { ?>
|
21 |
</tr><tr>
|
22 |
<th><?php _e('Piwik URL', 'wp-piwik'); ?> (REST API):</th>
|
23 |
<td>
|
24 |
+
<input type="radio" name="wp-piwik_mode" onchange="javascript:$j('#wp-piwik_path,#wp-piwik_path-label').toggleClass('wp-piwik-input-hide');" value="http" <?php echo (self::$settings->getGlobalOption('piwik_mode')=='http'?'checked="checked" ':''); ?>/>
|
25 |
+
<input id="wp-piwik_url" name="wp-piwik_url" type="text" value="<?php echo self::$settings->getGlobalOption('piwik_url'); ?>" />
|
26 |
<label for="wp-piwik_url"></label>
|
27 |
</td>
|
28 |
</tr><tr>
|
29 |
<th><?php _e('Piwik path', 'wp-piwik'); ?> (PHP API, beta):</th>
|
30 |
<td>
|
31 |
+
<input type="radio" name="wp-piwik_mode" onchange="javascript:$j('#wp-piwik_path,#wp-piwik_path-label').toggleClass('wp-piwik-input-hide');" value="php" <?php echo (self::$settings->getGlobalOption('piwik_mode')=='php'?'checked="checked" ':''); ?>/>
|
32 |
+
<input <?php echo (self::$settings->getGlobalOption('piwik_mode')!='php'?'class="wp-piwik-input-hide" ':''); ?>id="wp-piwik_path" name="wp-piwik_path" type="text" value="<?php echo self::$settings->getGlobalOption('piwik_path'); ?>" />
|
33 |
+
<label <?php echo (self::$settings->getGlobalOption('piwik_mode')!='php'?'class="wp-piwik-input-hide" ':''); ?>id="wp-piwik_path-label" for="wp-piwik_path"><?php _e('If you like to use the PHP API and also to enable tracking by WP-Piwik, please enter your Piwik URL, too. Otherwise your tracking code may be erroneous.','wp-piwik'); ?> [<a href="http://dev.piwik.org/trac/ticket/3220">Details</a>]</label>
|
34 |
<?php
|
35 |
if (isset($_POST['wp-piwik_path']) && !empty($_POST['wp-piwik_path']) && realpath($_POST['wp-piwik_path']) === false)
|
36 |
echo '<p class="wp-piwik-eyecatcher">'.__('Invalid path. Please enter the file path to Piwik.', 'wp-piwik').'</p>';
|
39 |
</tr><tr>
|
40 |
<th><?php _e('Auth token', 'wp-piwik'); ?>:</th>
|
41 |
<td>
|
42 |
+
<input name="wp-piwik_token" id="wp-piwik_token" type="text" value="<?php echo self::$settings->getGlobalOption('piwik_token'); ?>" />
|
43 |
<label for="wp-piwik_token"></label>
|
44 |
</td>
|
45 |
</tr><?php if (!is_plugin_active_for_network('wp-piwik/wp-piwik.php')) { ?><tr>
|
46 |
<th><?php _e('Auto config', 'wp-piwik'); ?>:</th>
|
47 |
<td>
|
48 |
+
<input name="wp-piwik_auto_site_config" id="wp-piwik_auto_site_config" value="1" type="checkbox"<?php echo (self::$settings->getGlobalOption('auto_site_config')?' checked="checked"':'') ?>/>
|
49 |
<label for="wp-piwik_auto_site_config"><?php _e('Check this to automatically choose your blog from your Piwik sites by URL. If your blog is not added to Piwik yet, WP-Piwik will add a new site.', 'wp-piwik') ?></label>
|
50 |
</td>
|
51 |
</tr>
|
52 |
<?php
|
53 |
+
if (self::$settings->getGlobalOption('piwik_url') && self::$settings->getGlobalOption('piwik_token')) {
|
54 |
$aryData = $this->callPiwikAPI('SitesManager.getSitesWithAtLeastViewAccess');
|
55 |
if (empty($aryData)) {
|
56 |
echo '<tr><td colspan="2">';
|
61 |
echo '<tr><td colspan="2">';
|
62 |
self::showErrorMessage($aryData['message']);
|
63 |
echo '</td></tr>';
|
64 |
+
} else if (!self::$settings->getGlobalOption('auto_site_config')) {
|
65 |
echo '<tr><th>'.__('Choose site', 'wp-piwik').':</th><td>';
|
66 |
echo '<select name="wp-piwik_siteid" id="wp-piwik_siteid">';
|
67 |
$aryOptions = array();
|
68 |
foreach ($aryData as $arySite)
|
69 |
$aryOptions[$arySite['name'].'#'.$arySite['idsite']] = '<option value="'.$arySite['idsite'].
|
70 |
+
'"'.($arySite['idsite']==self::$settings->getOption('site_id')?' selected="selected"':'').
|
71 |
'>'.htmlentities($arySite['name'], ENT_QUOTES, 'utf-8').
|
72 |
'</option>';
|
73 |
ksort($aryOptions);
|
74 |
foreach ($aryOptions as $strOption) echo $strOption;
|
75 |
echo '</select></td></tr>';
|
76 |
} else {
|
77 |
+
if (self::$settings->getOption('site_id'))
|
78 |
$this->addPiwikSite();
|
79 |
echo '<tr><th>'.__('Determined site', 'wp-piwik').':</th><td>';
|
80 |
echo '<div class="input-text-wrap">';
|
81 |
+
if (is_array(self::$settings->getOption('site_id')) && self::$settings->getOption('site_id')['result'] == 'error')
|
82 |
+
self::showErrorMessage(self::$settings->getOption('site_id')['message']);
|
83 |
else foreach ($aryData as $arySite)
|
84 |
+
if ($arySite['idsite'] == self::$settings->getOption('site_id')) {echo '<em>'.htmlentities($arySite['name'], ENT_QUOTES, 'utf-8').'</em>'; break;}
|
85 |
+
echo '<input type="hidden" name="wp-piwik_siteid" id="wp-piwik_siteid" value="'.(int)self::$settings->getOption('site_id').'" /></td></tr>';
|
86 |
}
|
87 |
}
|
88 |
}}
|
92 |
</tr><tr>
|
93 |
<th><label><?php _e('Connection timeout', 'wp-piwik'); ?>:</label></th>
|
94 |
<td>
|
95 |
+
<input style="width:50px;" type="text" name="wp-piwik_timeout" value="<?php echo self::$settings->getGlobalOption('connection_timeout'); ?>" />
|
96 |
</td>
|
97 |
</tr>
|
98 |
<?php if (function_exists('curl_init')) { ?>
|
99 |
<tr>
|
100 |
+
<th><label <?php echo (self::$settings->getGlobalOption('piwik_mode')=='php'?'class="wp-piwik-input-hide" ':''); ?>id="wp-piwik_disable_ssl_verify-label"><?php _e('Disable SSL peer verification', 'wp-piwik'); ?>:</label></th>
|
101 |
<td>
|
102 |
+
<input <?php echo (self::$settings->getGlobalOption('piwik_mode')=='php'?'class="wp-piwik-input-hide" ':''); ?>id="wp-piwik_disable_ssl_verify" name="wp-piwik_disable_ssl_verify" type="checkbox"<?php echo (self::$settings->getGlobalOption('disable_ssl_verify')?'checked="checked"':''); ?> /> (<?php _e('not recommended','wp-piwik'); ?>)
|
103 |
</td>
|
104 |
</tr><tr>
|
105 |
<th><label><?php _e('User agent', 'wp-piwik'); ?>:</label></th>
|
106 |
<td>
|
107 |
+
<input type="radio" onchange="javascript:$j('#wp-piwik-useragent').toggleClass('readonly="readonly"');" name="wp-piwik_useragent" value="php" <?php echo (self::$settings->getGlobalOption('piwik_useragent')=='php'?'checked="checked" ':''); ?>/> PHP default (<?php echo ini_get('user_agent'); ?>)
|
108 |
</td>
|
109 |
</tr><tr>
|
110 |
<th></th>
|
111 |
<td>
|
112 |
+
<input type="radio" onchange="javascript:$j('#wp-piwik-useragent').toggleClass('wp-piwik-useragent-disable');" name="wp-piwik_useragent" value="own" <?php echo (self::$settings->getGlobalOption('piwik_useragent')=='own'?'checked="checked" ':''); ?>/> <input type="text" id="wp-piwik-useragent" name="wp-piwik_useragent_string" value="<?php echo self::$settings->getGlobalOption('piwik_useragent_string'); ?>" />
|
113 |
</td>
|
114 |
</tr>
|
115 |
<?php } else { ?>
|
settings/sitebrowser.php
CHANGED
@@ -12,8 +12,9 @@ if (!$bolFOpen && !$bolCURL) {
|
|
12 |
if (!class_exists('WP_List_Table'))
|
13 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
14 |
|
15 |
-
if (isset($_GET['wpmu_show_stats']) && ($_GET['wpmu_show_stats'] == (int) $_GET['wpmu_show_stats']))
|
16 |
$this->addPiwikSite();
|
|
|
17 |
|
18 |
// See wpengineer.com/2426/wp_list_table-a-step-by-step-guide/
|
19 |
class SiteBrowser extends WP_List_Table {
|
12 |
if (!class_exists('WP_List_Table'))
|
13 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
14 |
|
15 |
+
if (isset($_GET['wpmu_show_stats']) && ($_GET['wpmu_show_stats'] == (int) $_GET['wpmu_show_stats'])) {
|
16 |
$this->addPiwikSite();
|
17 |
+
}
|
18 |
|
19 |
// See wpengineer.com/2426/wp_list_table-a-step-by-step-guide/
|
20 |
class SiteBrowser extends WP_List_Table {
|
settings/support.php
CHANGED
@@ -23,7 +23,7 @@
|
|
23 |
_e('enabled','wp-piwik');
|
24 |
?></strong>.</li>
|
25 |
</ol>
|
26 |
-
<?php if (
|
27 |
<?php
|
28 |
if (isset($_GET['mode'])) {
|
29 |
switch ($_GET['mode']) {
|
@@ -37,7 +37,7 @@
|
|
37 |
case 'resetconfirmed':
|
38 |
// Increase time limit before resetting
|
39 |
set_time_limit(0);
|
40 |
-
self
|
41 |
echo '<p class="wp-piwik-eyecatcher"><strong>'.__('WP-Piwik reset done','wp-piwik').'</strong></p>';
|
42 |
default:
|
43 |
}
|
23 |
_e('enabled','wp-piwik');
|
24 |
?></strong>.</li>
|
25 |
</ol>
|
26 |
+
<?php if (self::$settings->getGlobalOption('piwik_token') && self::$settings->getGlobalOption('piwik_url')) { ?>
|
27 |
<?php
|
28 |
if (isset($_GET['mode'])) {
|
29 |
switch ($_GET['mode']) {
|
37 |
case 'resetconfirmed':
|
38 |
// Increase time limit before resetting
|
39 |
set_time_limit(0);
|
40 |
+
self::$settings->resetSettings((isset($_GET['full']) && $_GET['full']));
|
41 |
echo '<p class="wp-piwik-eyecatcher"><strong>'.__('WP-Piwik reset done','wp-piwik').'</strong></p>';
|
42 |
default:
|
43 |
}
|
settings/tracking.php
CHANGED
@@ -10,85 +10,85 @@ if (!$bolFOpen && !$bolCURL) {
|
|
10 |
<tr><td colspan="2"><?php _e('Add tracking code', 'wp-piwik'); ?>:
|
11 |
<input
|
12 |
onchange="javascript:$j('#wp-piwik-tracking-settings').toggleClass('wp-piwik-form-table-hide');"
|
13 |
-
type="checkbox" value="1" id="wp-piwik_addjs" name="wp-piwik_addjs"<?php echo (self::$
|
14 |
<label for="wp-piwik_addjs"><?php _e('If your template uses wp_footer(), WP-Piwik can automatically add the Piwik javascript code to your blog.', 'wp-piwik'); ?></label>
|
15 |
</td></tr>
|
16 |
</table>
|
17 |
<?php
|
18 |
-
if (self::$
|
19 |
$strJavaScript = $this->callPiwikAPI('SitesManager.getJavascriptTag');
|
20 |
if (is_array($strJavaScript)) {
|
21 |
if (isset($strJavaScript['result']) && $strJavaScript['result'] == 'error')
|
22 |
self::showErrorMessage(__($strJavaScript['message'],'wp-piwik'));
|
23 |
} else {
|
24 |
// Save javascript code
|
25 |
-
self::$
|
26 |
}
|
27 |
-
self
|
28 |
}
|
29 |
?>
|
30 |
-
<table id="wp-piwik-tracking-settings" class="wp-piwik-form-table form-table<?php echo (!self::$
|
31 |
<tr><th><?php _e('Tracking code preview', 'wp-piwik'); ?>:</th><td>
|
32 |
<textarea id="wp-piwik_jscode" name="wp-piwik_jscode" readonly="readonly" rows="13" cols="80">
|
33 |
-
<?php echo (is_plugin_active_for_network('wp-piwik/wp-piwik.php')?'*** SITE SPECIFIC EXAMPLE CODE ***'."\n":'').htmlentities(self::$
|
34 |
</textarea>
|
35 |
</td></tr>
|
36 |
|
37 |
<tr><th><?php _e('<noscript> code preview', 'wp-piwik'); ?>:</th><td>
|
38 |
<textarea id="wp-piwik_nocode" name="wp-piwik_nocode" readonly="readonly" rows="2" cols="80">
|
39 |
-
<?php echo (is_plugin_active_for_network('wp-piwik/wp-piwik.php')?'*** SITE SPECIFIC EXAMPLE CODE ***'."\n":'').htmlentities(self::$
|
40 |
</textarea>
|
41 |
</td></tr>
|
42 |
|
43 |
<tr><th><?php _e('Default tracking', 'wp-piwik'); ?>:</th><td>
|
44 |
-
<input type="radio" value="0" id="wp-piwik_default" name="wp-piwik_trackingmode"<?php echo (self::$
|
45 |
<label for="wp-piwik_compress"><?php _e('WP-Piwik uses the Piwik default tracking code.', 'wp-piwik'); ?> <a href="http://demo.piwik.org/js/README">js/README</a>.</label>
|
46 |
</td></tr>
|
47 |
|
48 |
<tr><th><?php _e('Use js/index.php', 'wp-piwik'); ?>:</th><td>
|
49 |
-
<input type="radio" value="1" id="wp-piwik_compress" name="wp-piwik_trackingmode"<?php echo (self::$
|
50 |
<label for="wp-piwik_compress"><?php _e('WP-Piwik can automatically use js/index.php instead of piwik.js and piwik.php. See', 'wp-piwik'); ?> <a href="http://demo.piwik.org/js/README">js/README</a>.</label>
|
51 |
</td></tr>
|
52 |
|
53 |
<tr><th><?php _e('Use proxy script', 'wp-piwik'); ?>:</th><td>
|
54 |
-
<input type="radio" value="2" id="wp-piwik_proxy" name="wp-piwik_trackingmode"<?php echo (self::$
|
55 |
<label for="wp-piwik_compress"><?php _e('WP-Piwik will use the piwik.php proxy script. See', 'wp-piwik'); ?> <a href="http://piwik.org/faq/how-to/#faq_132">Piwik FAQ</a>.</label>
|
56 |
</td></tr>
|
57 |
|
58 |
|
59 |
<tr><th><?php _e('Add <noscript>', 'wp-piwik'); ?>:</th><td>
|
60 |
-
<input type="checkbox" value="1" id="wp-piwik_noscript" name="wp-piwik_noscript"<?php echo (self::$
|
61 |
<label for="wp-piwik_noscript"><?php echo _e('Adds the <noscript> code to your footer.', 'wp-piwik'); ?> <?php _e('Disabled in proxy mode.', 'wp-piwik'); ?></label>
|
62 |
</td></tr>
|
63 |
|
64 |
<tr><th><?php _e('Disable cookies', 'wp-piwik'); ?>:</th><td>
|
65 |
-
<input type="checkbox" value="1" id="wp-piwik_disable_cookies" name="wp-piwik_disable_cookies"<?php echo (self::$
|
66 |
<label for="wp-piwik_disable_cookies"><?php echo _e('Disable all tracking cookies for a visitor.', 'wp-piwik'); ?></label>
|
67 |
</td></tr>
|
68 |
|
69 |
<tr><th><?php _e('Track search', 'wp-piwik'); ?>:</th><td>
|
70 |
-
<input type="checkbox" value="1" id="wp-piwik_search" name="wp-piwik_search"<?php echo (self::$
|
71 |
<label for="wp-piwik_search"><?php echo _e('Use Piwik\'s advanced Site Search Analytics feature. See', 'wp-piwik'); ?> <a href="http://piwik.org/docs/javascript-tracking/#toc-tracking-internal-search-keywords-categories-and-no-result-search-keywords">Piwik documentation</a>.</label>
|
72 |
</td></tr>
|
73 |
|
74 |
<tr><th><?php _e('Track 404', 'wp-piwik'); ?>:</th><td>
|
75 |
-
<input type="checkbox" value="1" id="wp-piwik_404" name="wp-piwik_404"<?php echo (self::$
|
76 |
<label for="wp-piwik_404"><?php echo _e('WP-Piwik can automatically add a 404-category to track 404-page-visits.', 'wp-piwik'); ?></label>
|
77 |
</td></tr>
|
78 |
<tr><th><?php _e('Avoid mod_security', 'wp-piwik'); ?>:</th><td>
|
79 |
-
<input type="checkbox" value="1" id="wp-piwik_reqpost" name="wp-piwik_reqpost"<?php echo (self::$
|
80 |
<label for="wp-piwik_reqpost"><?php _e('WP-Piwik can automatically force the Tracking Code to sent data in POST. See', 'wp-piwik'); ?> <a href="http://piwik.org/faq/troubleshooting/#faq_100">Piwik FAQ</a>. <?php _e('Disabled in proxy mode.', 'wp-piwik'); ?></label>
|
81 |
</td></tr>
|
82 |
|
83 |
<tr><th><?php _e('CDN URL', 'wp-piwik'); ?>:</th><td>
|
84 |
-
http://<input type="text" value="<?php echo self::$
|
85 |
<label for="wp-piwik_reqpost"><?php _e('Leave blank if you do not want to define a CDN URL or you do not know what this is.', 'wp-piwik'); ?></label>
|
86 |
</td></tr>
|
87 |
|
88 |
<tr><th><?php _e('Tracking filter', 'wp-piwik'); ?>:</th><td>
|
89 |
<?php
|
90 |
global $wp_roles;
|
91 |
-
$aryFilter = self::$
|
92 |
foreach($wp_roles->role_names as $strKey => $strName) {
|
93 |
echo '<input type="checkbox" '.(isset($aryFilter[$strKey]) && $aryFilter[$strKey]?'checked="checked" ':'').'value="1" name="wp-piwik_filter['.$strKey.']" /> '.$strName.' ';
|
94 |
}
|
10 |
<tr><td colspan="2"><?php _e('Add tracking code', 'wp-piwik'); ?>:
|
11 |
<input
|
12 |
onchange="javascript:$j('#wp-piwik-tracking-settings').toggleClass('wp-piwik-form-table-hide');"
|
13 |
+
type="checkbox" value="1" id="wp-piwik_addjs" name="wp-piwik_addjs"<?php echo (self::$settings->getGlobalOption('add_tracking_code')?' checked="checked"':''); ?> />
|
14 |
<label for="wp-piwik_addjs"><?php _e('If your template uses wp_footer(), WP-Piwik can automatically add the Piwik javascript code to your blog.', 'wp-piwik'); ?></label>
|
15 |
</td></tr>
|
16 |
</table>
|
17 |
<?php
|
18 |
+
if (self::$settings->getGlobalOption('add_tracking_code')) {
|
19 |
$strJavaScript = $this->callPiwikAPI('SitesManager.getJavascriptTag');
|
20 |
if (is_array($strJavaScript)) {
|
21 |
if (isset($strJavaScript['result']) && $strJavaScript['result'] == 'error')
|
22 |
self::showErrorMessage(__($strJavaScript['message'],'wp-piwik'));
|
23 |
} else {
|
24 |
// Save javascript code
|
25 |
+
self::$settings->setOption('tracking_code', $strJavaScript);
|
26 |
}
|
27 |
+
self::$settings->save();
|
28 |
}
|
29 |
?>
|
30 |
+
<table id="wp-piwik-tracking-settings" class="wp-piwik-form-table form-table<?php echo (!self::$settings->getGlobalOption('add_tracking_code')?' wp-piwik-form-table-hide':''); ?>">
|
31 |
<tr><th><?php _e('Tracking code preview', 'wp-piwik'); ?>:</th><td>
|
32 |
<textarea id="wp-piwik_jscode" name="wp-piwik_jscode" readonly="readonly" rows="13" cols="80">
|
33 |
+
<?php echo (is_plugin_active_for_network('wp-piwik/wp-piwik.php')?'*** SITE SPECIFIC EXAMPLE CODE ***'."\n":'').htmlentities(self::$settings->getOption('tracking_code')); ?>
|
34 |
</textarea>
|
35 |
</td></tr>
|
36 |
|
37 |
<tr><th><?php _e('<noscript> code preview', 'wp-piwik'); ?>:</th><td>
|
38 |
<textarea id="wp-piwik_nocode" name="wp-piwik_nocode" readonly="readonly" rows="2" cols="80">
|
39 |
+
<?php echo (is_plugin_active_for_network('wp-piwik/wp-piwik.php')?'*** SITE SPECIFIC EXAMPLE CODE ***'."\n":'').htmlentities(self::$settings->getOption('noscript_code')); ?>
|
40 |
</textarea>
|
41 |
</td></tr>
|
42 |
|
43 |
<tr><th><?php _e('Default tracking', 'wp-piwik'); ?>:</th><td>
|
44 |
+
<input type="radio" value="0" id="wp-piwik_default" name="wp-piwik_trackingmode"<?php echo (self::$settings->getGlobalOption('track_mode')==0?' checked="checked"':''); ?> />
|
45 |
<label for="wp-piwik_compress"><?php _e('WP-Piwik uses the Piwik default tracking code.', 'wp-piwik'); ?> <a href="http://demo.piwik.org/js/README">js/README</a>.</label>
|
46 |
</td></tr>
|
47 |
|
48 |
<tr><th><?php _e('Use js/index.php', 'wp-piwik'); ?>:</th><td>
|
49 |
+
<input type="radio" value="1" id="wp-piwik_compress" name="wp-piwik_trackingmode"<?php echo (self::$settings->getGlobalOption('track_mode')==1?' checked="checked"':''); ?> />
|
50 |
<label for="wp-piwik_compress"><?php _e('WP-Piwik can automatically use js/index.php instead of piwik.js and piwik.php. See', 'wp-piwik'); ?> <a href="http://demo.piwik.org/js/README">js/README</a>.</label>
|
51 |
</td></tr>
|
52 |
|
53 |
<tr><th><?php _e('Use proxy script', 'wp-piwik'); ?>:</th><td>
|
54 |
+
<input type="radio" value="2" id="wp-piwik_proxy" name="wp-piwik_trackingmode"<?php echo (self::$settings->getGlobalOption('track_mode')==2?' checked="checked"':''); ?> />
|
55 |
<label for="wp-piwik_compress"><?php _e('WP-Piwik will use the piwik.php proxy script. See', 'wp-piwik'); ?> <a href="http://piwik.org/faq/how-to/#faq_132">Piwik FAQ</a>.</label>
|
56 |
</td></tr>
|
57 |
|
58 |
|
59 |
<tr><th><?php _e('Add <noscript>', 'wp-piwik'); ?>:</th><td>
|
60 |
+
<input type="checkbox" value="1" id="wp-piwik_noscript" name="wp-piwik_noscript"<?php echo (self::$settings->getGlobalOption('track_noscript')?' checked="checked"':''); ?> />
|
61 |
<label for="wp-piwik_noscript"><?php echo _e('Adds the <noscript> code to your footer.', 'wp-piwik'); ?> <?php _e('Disabled in proxy mode.', 'wp-piwik'); ?></label>
|
62 |
</td></tr>
|
63 |
|
64 |
<tr><th><?php _e('Disable cookies', 'wp-piwik'); ?>:</th><td>
|
65 |
+
<input type="checkbox" value="1" id="wp-piwik_disable_cookies" name="wp-piwik_disable_cookies"<?php echo (self::$settings->getGlobalOption('disable_cookies')?' checked="checked"':''); ?> />
|
66 |
<label for="wp-piwik_disable_cookies"><?php echo _e('Disable all tracking cookies for a visitor.', 'wp-piwik'); ?></label>
|
67 |
</td></tr>
|
68 |
|
69 |
<tr><th><?php _e('Track search', 'wp-piwik'); ?>:</th><td>
|
70 |
+
<input type="checkbox" value="1" id="wp-piwik_search" name="wp-piwik_search"<?php echo (self::$settings->getGlobalOption('track_search')?' checked="checked"':''); ?> />
|
71 |
<label for="wp-piwik_search"><?php echo _e('Use Piwik\'s advanced Site Search Analytics feature. See', 'wp-piwik'); ?> <a href="http://piwik.org/docs/javascript-tracking/#toc-tracking-internal-search-keywords-categories-and-no-result-search-keywords">Piwik documentation</a>.</label>
|
72 |
</td></tr>
|
73 |
|
74 |
<tr><th><?php _e('Track 404', 'wp-piwik'); ?>:</th><td>
|
75 |
+
<input type="checkbox" value="1" id="wp-piwik_404" name="wp-piwik_404"<?php echo (self::$settings->getGlobalOption('track_404')?' checked="checked"':''); ?> />
|
76 |
<label for="wp-piwik_404"><?php echo _e('WP-Piwik can automatically add a 404-category to track 404-page-visits.', 'wp-piwik'); ?></label>
|
77 |
</td></tr>
|
78 |
<tr><th><?php _e('Avoid mod_security', 'wp-piwik'); ?>:</th><td>
|
79 |
+
<input type="checkbox" value="1" id="wp-piwik_reqpost" name="wp-piwik_reqpost"<?php echo (self::$settings->getGlobalOption('track_post')?' checked="checked"':''); ?> />
|
80 |
<label for="wp-piwik_reqpost"><?php _e('WP-Piwik can automatically force the Tracking Code to sent data in POST. See', 'wp-piwik'); ?> <a href="http://piwik.org/faq/troubleshooting/#faq_100">Piwik FAQ</a>. <?php _e('Disabled in proxy mode.', 'wp-piwik'); ?></label>
|
81 |
</td></tr>
|
82 |
|
83 |
<tr><th><?php _e('CDN URL', 'wp-piwik'); ?>:</th><td>
|
84 |
+
http://<input type="text" value="<?php echo self::$settings->getGlobalOption('track_cdnurl'); ?>" id="wp-piwik_cdnurl" name="wp-piwik_cdnurl" /> https://<input type="text" value="<?php echo self::$settings->getGlobalOption('track_cdnurlssl'); ?>" id="wp-piwik_cdnurlssl" name="wp-piwik_cdnurlssl" /><br />
|
85 |
<label for="wp-piwik_reqpost"><?php _e('Leave blank if you do not want to define a CDN URL or you do not know what this is.', 'wp-piwik'); ?></label>
|
86 |
</td></tr>
|
87 |
|
88 |
<tr><th><?php _e('Tracking filter', 'wp-piwik'); ?>:</th><td>
|
89 |
<?php
|
90 |
global $wp_roles;
|
91 |
+
$aryFilter = self::$settings->getGlobalOption('capability_stealth');
|
92 |
foreach($wp_roles->role_names as $strKey => $strName) {
|
93 |
echo '<input type="checkbox" '.(isset($aryFilter[$strKey]) && $aryFilter[$strKey]?'checked="checked" ':'').'value="1" name="wp-piwik_filter['.$strKey.']" /> '.$strName.' ';
|
94 |
}
|
settings/views.php
CHANGED
@@ -7,50 +7,54 @@ if (!$bolFOpen && !$bolCURL) {
|
|
7 |
<strong><?php _e('Error: cURL is not enabled and fopen is not allowed to open URLs. WP-Piwik won\'t be able to connect to Piwik.'); ?></strong>
|
8 |
</td>
|
9 |
</tr><?php } else { ?>
|
|
|
|
|
|
|
|
|
10 |
<tr><th>Piwik <?php _e('Default date', 'wp-piwik'); ?>:</th><td>
|
11 |
<select id="wp-piwik_default_date" name="wp-piwik_default_date">
|
12 |
-
<option value="yesterday"<?php echo (self::$
|
13 |
-
<option value="today"<?php echo (self::$
|
14 |
</select>
|
15 |
<label for="wp-piwik_default_date"><?php echo _e('Default date shown on statistics page.', 'wp-piwik'); ?></label>
|
16 |
</td></tr>
|
17 |
<tr><th><?php _e('Home Dashboard', 'wp-piwik'); ?>:</th><td>
|
18 |
<select id="wp-piwik_dbwidget" name="wp-piwik_dbwidget">
|
19 |
-
<option value="0"'<?php echo (!self::$
|
20 |
-
<option value="yesterday"<?php echo (self::$
|
21 |
-
<option value="today"<?php echo (self::$
|
22 |
-
<option value="last30"<?php echo (self::$
|
23 |
</select>
|
24 |
-
<input type="checkbox" value="1" name="wp-piwik_dbchart" id="wp-piwik_dbchart"<?php echo (self::$
|
25 |
-
<input type="checkbox" value="1" name="wp-piwik_dbseo" id="wp-piwik_dbseo"<?php echo (self::$
|
26 |
<br><?php _e('Configure WP-Piwik widgets to be shown on your WordPress Home Dashboard.', 'wp-piwik'); ?>
|
27 |
</td></tr>
|
28 |
<tr><th><?php _e('Show graph on WordPress Toolbar', 'wp-piwik'); ?>:</th><td>
|
29 |
-
<input type="checkbox" value="1" id="wp-piwik_toolbar" name="wp-piwik_toolbar"<?php echo (self::$
|
30 |
<label for="wp-piwik_toolbar"><?php echo _e('Display the last 30 days visitor stats on WordPress Toolbar.', 'wp-piwik'); ?></label>
|
31 |
</td></tr>
|
32 |
<tr><th><?php _e('SEO data', 'wp-piwik'); ?>:</th><td>
|
33 |
-
<input type="checkbox" value="1" id="wp-piwik_statsseo" name="wp-piwik_statsseo"<?php echo (self::$
|
34 |
<label for="wp-piwik_statsseo"><?php echo _e('Display SEO ranking data on statistics page. <em>(Slow!)</em>', 'wp-piwik'); ?></label>
|
35 |
</td></tr>
|
36 |
<tr><th>Piwik <?php _e('Shortcut', 'wp-piwik'); ?>:</th><td>
|
37 |
-
<input type="checkbox" value="1" id="wp-piwik_piwiklink" name="wp-piwik_piwiklink"<?php echo (self::$
|
38 |
<label for="wp-piwik_piwiklink"><?php echo _e('Display a shortcut to Piwik itself.', 'wp-piwik'); ?></label>
|
39 |
</td></tr>
|
40 |
<tr><th>Piwik <?php _e('Display to', 'wp-piwik'); ?>:</th><td>
|
41 |
<?php
|
42 |
global $wp_roles;
|
43 |
foreach($wp_roles->role_names as $strKey => $strName)
|
44 |
-
echo '<input name="wp-piwik_displayto['.$strKey.']" type="checkbox" value="1"'.(isset(self::$
|
45 |
?>
|
46 |
<br><?php echo _e('Choose user roles allowed to see the statistics page.', 'wp-piwik'); ?>
|
47 |
</td></tr>
|
48 |
<tr><th><?php _e('Disable time limit', 'wp-piwik'); ?>:</th><td>
|
49 |
-
<input type="checkbox" value="1" id="wp-piwik_disabletimelimit" name="wp-piwik_disabletimelimit"<?php echo (self::$
|
50 |
<label for="wp-piwik_disabletimelimit"><?php echo _e('Use set_time_limit(0) if stats page causes a time out.', 'wp-piwik'); ?></label>
|
51 |
</td></tr>
|
52 |
<tr><th><?php _e('Enable shortcodes', 'wp-piwik'); ?>:</th><td>
|
53 |
-
<input type="checkbox" value="1" id="wp-piwik_shortcodes" name="wp-piwik_shortcodes"<?php echo (self::$
|
54 |
<label for="wp-piwik_shortcodes"><?php echo _e('Enable shortcodes in post or page content.', 'wp-piwik'); ?></label>
|
55 |
</td></tr>
|
56 |
<?php } ?>
|
7 |
<strong><?php _e('Error: cURL is not enabled and fopen is not allowed to open URLs. WP-Piwik won\'t be able to connect to Piwik.'); ?></strong>
|
8 |
</td>
|
9 |
</tr><?php } else { ?>
|
10 |
+
<tr><th><?php _e('WP-Piwik display name', 'wp-piwik'); ?>:</th><td>
|
11 |
+
<input type="text" id="wp-piwik_displayname" name="wp-piwik_displayname" value="<?php echo self::$settings->getGlobalOption('plugin_display_name'); ?>" />
|
12 |
+
<label for="wp-piwik_displayname"><?php echo _e('Plugin name shown in WordPress.', 'wp-piwik'); ?></label>
|
13 |
+
</td></tr>
|
14 |
<tr><th>Piwik <?php _e('Default date', 'wp-piwik'); ?>:</th><td>
|
15 |
<select id="wp-piwik_default_date" name="wp-piwik_default_date">
|
16 |
+
<option value="yesterday"<?php echo (self::$settings->getGlobalOption('default_date') == 'yesterday'?' selected="selected"':'');?>> <?php _e('yesterday', 'wp-piwik');?></option>
|
17 |
+
<option value="today"<?php echo (self::$settings->getGlobalOption('default_date') == 'today'?' selected="selected"':'');?>> <?php _e('today', 'wp-piwik');?></option>
|
18 |
</select>
|
19 |
<label for="wp-piwik_default_date"><?php echo _e('Default date shown on statistics page.', 'wp-piwik'); ?></label>
|
20 |
</td></tr>
|
21 |
<tr><th><?php _e('Home Dashboard', 'wp-piwik'); ?>:</th><td>
|
22 |
<select id="wp-piwik_dbwidget" name="wp-piwik_dbwidget">
|
23 |
+
<option value="0"'<?php echo (!self::$settings->getGlobalOption('dashboard_widget')?' selected="selected"':''); ?>><?php _e('Hide overview', 'wp-piwik'); ?></option>
|
24 |
+
<option value="yesterday"<?php echo (self::$settings->getGlobalOption('dashboard_widget') == 'yesterday'?' selected="selected"':''); ?>><?php echo __('Show overview','wp-piwik').' ('.__('yesterday', 'wp-piwik').')'; ?></option>
|
25 |
+
<option value="today"<?php echo (self::$settings->getGlobalOption('dashboard_widget') == 'today'?' selected="selected"':''); ?>><?php echo __('Show overview','wp-piwik').' ('.__('today', 'wp-piwik').')'; ?></option>
|
26 |
+
<option value="last30"<?php echo (self::$settings->getGlobalOption('dashboard_widget') == 'last30'?' selected="selected"':''); ?>><?php echo __('Show overview','wp-piwik').' ('.__('last 30 days','wp-piwik').')'; ?></option>
|
27 |
</select>
|
28 |
+
<input type="checkbox" value="1" name="wp-piwik_dbchart" id="wp-piwik_dbchart"<?php echo (self::$settings->getGlobalOption('dashboard_chart')?' checked="checked"':""); ?>/> <?php _e('Chart', 'wp-piwik'); ?>
|
29 |
+
<input type="checkbox" value="1" name="wp-piwik_dbseo" id="wp-piwik_dbseo"<?php echo (self::$settings->getGlobalOption('dashboard_seo')?' checked="checked"':""); ?>/> <?php _e('SEO <em>(slow!)</em>', 'wp-piwik'); ?>
|
30 |
<br><?php _e('Configure WP-Piwik widgets to be shown on your WordPress Home Dashboard.', 'wp-piwik'); ?>
|
31 |
</td></tr>
|
32 |
<tr><th><?php _e('Show graph on WordPress Toolbar', 'wp-piwik'); ?>:</th><td>
|
33 |
+
<input type="checkbox" value="1" id="wp-piwik_toolbar" name="wp-piwik_toolbar"<?php echo (self::$settings->getGlobalOption('toolbar')?' checked="checked"':''); ?> />
|
34 |
<label for="wp-piwik_toolbar"><?php echo _e('Display the last 30 days visitor stats on WordPress Toolbar.', 'wp-piwik'); ?></label>
|
35 |
</td></tr>
|
36 |
<tr><th><?php _e('SEO data', 'wp-piwik'); ?>:</th><td>
|
37 |
+
<input type="checkbox" value="1" id="wp-piwik_statsseo" name="wp-piwik_statsseo"<?php echo (self::$settings->getGlobalOption('stats_seo')?' checked="checked"':''); ?> />
|
38 |
<label for="wp-piwik_statsseo"><?php echo _e('Display SEO ranking data on statistics page. <em>(Slow!)</em>', 'wp-piwik'); ?></label>
|
39 |
</td></tr>
|
40 |
<tr><th>Piwik <?php _e('Shortcut', 'wp-piwik'); ?>:</th><td>
|
41 |
+
<input type="checkbox" value="1" id="wp-piwik_piwiklink" name="wp-piwik_piwiklink"<?php echo (self::$settings->getGlobalOption('piwik_shortcut')?' checked="checked"':''); ?> />
|
42 |
<label for="wp-piwik_piwiklink"><?php echo _e('Display a shortcut to Piwik itself.', 'wp-piwik'); ?></label>
|
43 |
</td></tr>
|
44 |
<tr><th>Piwik <?php _e('Display to', 'wp-piwik'); ?>:</th><td>
|
45 |
<?php
|
46 |
global $wp_roles;
|
47 |
foreach($wp_roles->role_names as $strKey => $strName)
|
48 |
+
echo '<input name="wp-piwik_displayto['.$strKey.']" type="checkbox" value="1"'.(isset(self::$settings->getGlobalOption('capability_read_stats')[$strKey]) && self::$settings->getGlobalOption('capability_read_stats')[$strKey]?' checked="checked"':'').'/> '.$strName.' ';
|
49 |
?>
|
50 |
<br><?php echo _e('Choose user roles allowed to see the statistics page.', 'wp-piwik'); ?>
|
51 |
</td></tr>
|
52 |
<tr><th><?php _e('Disable time limit', 'wp-piwik'); ?>:</th><td>
|
53 |
+
<input type="checkbox" value="1" id="wp-piwik_disabletimelimit" name="wp-piwik_disabletimelimit"<?php echo (self::$settings->getGlobalOption('disable_timelimit')?' checked="checked"':''); ?> />
|
54 |
<label for="wp-piwik_disabletimelimit"><?php echo _e('Use set_time_limit(0) if stats page causes a time out.', 'wp-piwik'); ?></label>
|
55 |
</td></tr>
|
56 |
<tr><th><?php _e('Enable shortcodes', 'wp-piwik'); ?>:</th><td>
|
57 |
+
<input type="checkbox" value="1" id="wp-piwik_shortcodes" name="wp-piwik_shortcodes"<?php echo (self::$settings->getGlobalOption('shortcodes')?' checked="checked"':''); ?> />
|
58 |
<label for="wp-piwik_shortcodes"><?php echo _e('Enable shortcodes in post or page content.', 'wp-piwik'); ?></label>
|
59 |
</td></tr>
|
60 |
<?php } ?>
|
shortcodes/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Nothing to see...
|
update/80403.php
CHANGED
@@ -12,7 +12,7 @@ if (!is_array($strDisplayToLevel) && isset($aryTranslate[$strDisplayToLevel])) $
|
|
12 |
else $aryDisplayToCap = array('administrator' => true);
|
13 |
// Build settings arrays
|
14 |
$aryDashboardWidgetRange = array(0 => false, 1 => 'yesterday', 2 => 'today', 3 => 'last30');
|
15 |
-
if (self::$bolWPMU)
|
16 |
'revision' => get_site_option('wpmu-piwik_revision', 0),
|
17 |
'add_tracking_code' => true,
|
18 |
'last_settings_update' => get_site_option('wpmu-piwik_settingsupdate', time()),
|
@@ -23,7 +23,7 @@ if (self::$bolWPMU) self::$aryGlobalSettings = array(
|
|
23 |
'capability_read_stats' => $aryDisplayToCap,
|
24 |
'piwik_shortcut' => false,
|
25 |
);
|
26 |
-
else
|
27 |
'revision' => get_option('wp-piwik_revision',0),
|
28 |
'add_tracking_code' => get_option('wp-piwik_addjs'),
|
29 |
'last_settings_update' => get_option('wp-piwik_settingsupdate', time()),
|
@@ -44,4 +44,6 @@ $aryRemoveOptions = array(
|
|
44 |
foreach ($aryRemoveOptions as $strRemoveOption) {
|
45 |
if (self::$bolWPMU) delete_site_option($strRemoveOption);
|
46 |
else delete_option($strRemoveOption);
|
47 |
-
}
|
|
|
|
12 |
else $aryDisplayToCap = array('administrator' => true);
|
13 |
// Build settings arrays
|
14 |
$aryDashboardWidgetRange = array(0 => false, 1 => 'yesterday', 2 => 'today', 3 => 'last30');
|
15 |
+
if (self::$bolWPMU) $aryGlobal = array(
|
16 |
'revision' => get_site_option('wpmu-piwik_revision', 0),
|
17 |
'add_tracking_code' => true,
|
18 |
'last_settings_update' => get_site_option('wpmu-piwik_settingsupdate', time()),
|
23 |
'capability_read_stats' => $aryDisplayToCap,
|
24 |
'piwik_shortcut' => false,
|
25 |
);
|
26 |
+
else $aryGlobal = array(
|
27 |
'revision' => get_option('wp-piwik_revision',0),
|
28 |
'add_tracking_code' => get_option('wp-piwik_addjs'),
|
29 |
'last_settings_update' => get_option('wp-piwik_settingsupdate', time()),
|
44 |
foreach ($aryRemoveOptions as $strRemoveOption) {
|
45 |
if (self::$bolWPMU) delete_site_option($strRemoveOption);
|
46 |
else delete_option($strRemoveOption);
|
47 |
+
}
|
48 |
+
foreach ($aryGlobal as $key => $value)
|
49 |
+
self::$settings->setGlobalOption($key, $value);
|
update/80502.php
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
<?php
|
2 |
-
self::$
|
1 |
<?php
|
2 |
+
self::$settings->setGlobalOption('default_date', 'yesterday');
|
update/80602.php
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
<?php
|
2 |
-
self::$
|
1 |
<?php
|
2 |
+
self::$settings->setGlobalOption('dashboard_chart', false);
|
update/80800.php
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
<?php
|
2 |
-
self::$
|
1 |
<?php
|
2 |
+
self::$settings->setGlobalOption('piwik_url', self::checkURL(self::$settings->getGlobalOption('piwik_url')));
|
update/90001.php
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
<?php
|
2 |
$aryWPMUConfig = get_site_option('wpmu-piwik_global-settings',false);
|
3 |
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && $aryWPMUConfig) {
|
4 |
-
|
|
|
5 |
delete_site_option('wpmu-piwik_global-settings');
|
6 |
-
self::$
|
7 |
-
} else self::$
|
8 |
-
self::$
|
9 |
-
self::$
|
10 |
-
self::$
|
11 |
-
self::$
|
12 |
-
self::$
|
1 |
<?php
|
2 |
$aryWPMUConfig = get_site_option('wpmu-piwik_global-settings',false);
|
3 |
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && $aryWPMUConfig) {
|
4 |
+
foreach ($aryWPMUConfig as $key => $value)
|
5 |
+
self::$settings->setGlobalOption($key, $value);
|
6 |
delete_site_option('wpmu-piwik_global-settings');
|
7 |
+
self::$settings->setGlobalOption('auto_site_config', true);
|
8 |
+
} else self::$settings->setGlobalOption('auto_site_config', false);
|
9 |
+
self::$settings->setGlobalOption('dashboard_seo' = false);
|
10 |
+
self::$settings->setGlobalOption('stats_seo', false);
|
11 |
+
self::$settings->setGlobalOption('track_404', self::$settings->getOption('track_404'));
|
12 |
+
self::$settings->setGlobalOption('track_compress', false);
|
13 |
+
self::$settings->setGlobalOption('track_post', false);
|
update/90206.php
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
<?php
|
2 |
-
self::$
|
1 |
<?php
|
2 |
+
self::$settings->setGlobalOption('disable_timelimit', false);
|
update/90405.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<?php
|
2 |
-
self::$
|
3 |
-
self::$
|
4 |
-
self::$
|
5 |
-
self::$
|
1 |
<?php
|
2 |
+
self::$settings->setGlobalOption('piwik_mode', 'http');
|
3 |
+
self::$settings->setGlobalOption('piwik_path', '');
|
4 |
+
self::$settings->setGlobalOption('toolbar', false);
|
5 |
+
self::$settings->setGlobalOption('disable_cookies', false);
|
update/90601.php
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
<?php
|
2 |
-
self::$
|
3 |
-
self::$
|
1 |
<?php
|
2 |
+
self::$settings->setGlobalOption('piwik_useragent', 'php');
|
3 |
+
self::$settings->setGlobalOption('piwik_useragent_string', 'WP-Piwik');
|
update/90700.php
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
<?php
|
2 |
-
self::$
|
1 |
<?php
|
2 |
+
self::$settings->setGlobalOption('shortcodes', false);
|
update/90801.php
CHANGED
@@ -1,10 +1,7 @@
|
|
1 |
<?php
|
2 |
-
self::$
|
3 |
-
self::$
|
4 |
-
if (
|
5 |
-
self::$
|
6 |
else
|
7 |
-
self::$
|
8 |
-
|
9 |
-
if (isset(self::$aryGlobalSettings['track_compress']))
|
10 |
-
unset(self::$aryGlobalSettings['track_compress']);
|
1 |
<?php
|
2 |
+
self::$settings->setGlobalOption('track_search', false);
|
3 |
+
self::$settings->setGlobalOption('connection_timeout', 5);
|
4 |
+
if (self::$settings->getGlobalOption('track_compress'))
|
5 |
+
self::$settings->setGlobalOption('track_mode', 1);
|
6 |
else
|
7 |
+
self::$settings->setGlobalOption('track_mode', 0);
|
|
|
|
|
|
update/90821.php
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
<?php
|
2 |
-
self::$
|
1 |
<?php
|
2 |
+
self::$settings->setGlobalOption('track_cdnurl', '');
|
update/90910.php
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
<?php
|
2 |
-
self::$
|
3 |
-
self::$
|
1 |
<?php
|
2 |
+
self::$settings->setGlobalOption('track_cdnurlssl', self::$settings->getGlobalOption('track_cdnurl'));
|
3 |
+
self::$settings->setGlobalOption('track_noscript', false);
|
update/90920.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
self::$settings->setGlobalOption('plugin_display_name', 'WP-Piwik');
|
update/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Nothing to see...
|
wp-piwik.php
CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://wordpress.org/extend/plugins/wp-piwik/
|
|
6 |
|
7 |
Description: Adds Piwik stats to your dashboard menu and Piwik code to your wordpress header.
|
8 |
|
9 |
-
Version: 0.9.9.
|
10 |
Author: André Bräkling
|
11 |
Author URI: http://www.braekling.de
|
12 |
|
@@ -27,144 +27,51 @@ Author URI: http://www.braekling.de
|
|
27 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
28 |
*******************************************************************************************/
|
29 |
|
30 |
-
|
31 |
-
* Avoid direct calls to this file if wp core files not present
|
32 |
-
* seen (as some other parts) in Heiko Rabe's metabox demo plugin
|
33 |
-
*
|
34 |
-
* @see http://tinyurl.com/5r5vnzs
|
35 |
-
*/
|
36 |
if (!function_exists ('add_action')) {
|
37 |
header('Status: 403 Forbidden');
|
38 |
header('HTTP/1.1 403 Forbidden');
|
39 |
exit();
|
40 |
}
|
41 |
|
42 |
-
|
43 |
-
* Makes sure all required include files are loaded before trying to use it
|
44 |
-
*
|
45 |
-
* @see http://codex.wordpress.org/Function_Reference/is_plugin_active_for_network
|
46 |
-
* @see http://codex.wordpress.org/Function_Reference/get_current_screen
|
47 |
-
*/
|
48 |
if (!function_exists('is_plugin_active_for_network'))
|
49 |
require_once(ABSPATH.'/wp-admin/includes/plugin.php');
|
50 |
|
51 |
class wp_piwik {
|
52 |
|
53 |
private static
|
54 |
-
$intRevisionId =
|
55 |
-
$strVersion = '0.9.9.
|
|
|
56 |
$intDashboardID = 30,
|
57 |
$strPluginBasename = NULL,
|
58 |
$bolJustActivated = false,
|
59 |
-
$
|
60 |
-
|
61 |
-
|
62 |
-
'last_settings_update' => 0,
|
63 |
-
'piwik_token' => '',
|
64 |
-
'piwik_url' => '',
|
65 |
-
'piwik_path' => '',
|
66 |
-
'piwik_mode' => 'http',
|
67 |
-
'piwik_useragent' => 'php',
|
68 |
-
'piwik_useragent_string' => 'WP-Piwik',
|
69 |
-
'connection_timeout' => 5,
|
70 |
-
'dashboard_widget' => false,
|
71 |
-
'dashboard_chart' => false,
|
72 |
-
'dashboard_seo' => false,
|
73 |
-
'stats_seo' => false,
|
74 |
-
'capability_stealth' => array(),
|
75 |
-
'capability_read_stats' => array('administrator' => true),
|
76 |
-
'piwik_shortcut' => false,
|
77 |
-
'default_date' => 'yesterday',
|
78 |
-
'auto_site_config' => true,
|
79 |
-
'track_404' => false,
|
80 |
-
'track_search' => false,
|
81 |
-
'track_mode' => 0,
|
82 |
-
'track_post' => false,
|
83 |
-
'track_proxy' => false,
|
84 |
-
'track_cdnurlssl' => '',
|
85 |
-
'track_noscript' => false,
|
86 |
-
'disable_timelimit' => false,
|
87 |
-
'disable_ssl_verify' => false,
|
88 |
-
'disable_cookies' => false,
|
89 |
-
'toolbar' => false,
|
90 |
-
'shortcodes' => false
|
91 |
-
),
|
92 |
-
$arySettings = array(
|
93 |
-
'name' => '',
|
94 |
-
'tracking_code' => '',
|
95 |
-
'site_id' => NULL,
|
96 |
-
'last_tracking_code_update' => 0,
|
97 |
-
'dashboard_revision' => 0,
|
98 |
-
'noscript_code' => ''
|
99 |
-
);
|
100 |
-
|
101 |
private
|
102 |
$intStatsPage = NULL,
|
103 |
$bolNetwork = false,
|
104 |
$aryAttributes = array(),
|
105 |
$strResult = '';
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
self::$aryGlobalSettings = (is_plugin_active_for_network('wp-piwik/wp-piwik.php')?
|
113 |
-
get_site_option('wp-piwik_global-settings',self::$aryGlobalSettings):
|
114 |
-
get_option('wp-piwik_global-settings',self::$aryGlobalSettings)
|
115 |
-
);
|
116 |
-
// Get site settings
|
117 |
-
self::$arySettings = get_option('wp-piwik_settings',self::$arySettings);
|
118 |
-
|
119 |
-
return array(
|
120 |
-
'global' => self::$aryGlobalSettings,
|
121 |
-
'specific' => self::$arySettings
|
122 |
-
);
|
123 |
-
}
|
124 |
-
|
125 |
-
/**
|
126 |
-
* Save plugin settings
|
127 |
-
*/
|
128 |
-
static function saveSettings() {
|
129 |
-
// Save global settings
|
130 |
-
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php'))
|
131 |
-
update_site_option('wp-piwik_global-settings',self::$aryGlobalSettings);
|
132 |
-
else
|
133 |
-
update_option('wp-piwik_global-settings',self::$aryGlobalSettings);
|
134 |
-
// Save blog settings
|
135 |
-
update_option('wp-piwik_settings',self::$arySettings);
|
136 |
-
// Load WP_Roles class
|
137 |
-
global $wp_roles;
|
138 |
-
if (!is_object($wp_roles))
|
139 |
-
$wp_roles = new WP_Roles();
|
140 |
-
if (!is_object($wp_roles)) die("STILL NO OBJECT");
|
141 |
-
// Assign capabilities to roles
|
142 |
-
foreach($wp_roles->role_names as $strKey => $strName) {
|
143 |
-
$objRole = get_role($strKey);
|
144 |
-
foreach (array('stealth', 'read_stats') as $strCap)
|
145 |
-
if (isset(self::$aryGlobalSettings['capability_'.$strCap][$strKey]) && self::$aryGlobalSettings['capability_'.$strCap][$strKey])
|
146 |
-
$objRole->add_cap('wp-piwik_'.$strCap);
|
147 |
-
else $objRole->remove_cap('wp-piwik_'.$strCap);
|
148 |
-
}
|
149 |
-
}
|
150 |
-
|
151 |
-
/**
|
152 |
-
* Constructor
|
153 |
-
*/
|
154 |
-
function __construct() {
|
155 |
// Call install function on activation
|
156 |
register_activation_hook(__FILE__, array($this, 'installPlugin'));
|
157 |
// Store plugin basename
|
158 |
self::$strPluginBasename = plugin_basename(__FILE__);
|
159 |
-
// Load current settings
|
160 |
-
self::loadSettings();
|
161 |
// Upgrade?
|
162 |
-
if (self::$
|
163 |
// Settings changed?
|
164 |
if (isset($_POST['action']) && $_POST['action'] == 'save_wp-piwik_settings')
|
165 |
$this->applySettings();
|
166 |
// Set Piwik globals if PHP API is used
|
167 |
-
elseif (
|
168 |
self::definePiwikConstants();
|
169 |
// Load language file
|
170 |
load_plugin_textdomain('wp-piwik', false, dirname(self::$strPluginBasename)."/languages/");
|
@@ -184,148 +91,122 @@ class wp_piwik {
|
|
184 |
add_action('load-post-new.php', array(&$this, 'postMetaboxes'));
|
185 |
// Add dashboard widget if enabled
|
186 |
/* TODO: Use bitmask here */
|
187 |
-
if (self::$
|
188 |
add_action('wp_dashboard_setup', array($this, 'extendWordPressDashboard'));
|
189 |
// Add Toolbar graph if enabled
|
190 |
-
if (self::$
|
191 |
add_action(is_admin()?'admin_head':'wp_head', array($this, 'loadToolbarRequirements'));
|
192 |
add_action('admin_bar_menu', array(&$this, 'extendWordPressToolbar'), 1000);
|
193 |
}
|
194 |
// Enable shortcodes if enabled
|
195 |
-
if (self::$
|
196 |
add_shortcode( 'wp-piwik', array(&$this, 'shortcode'));
|
197 |
|
198 |
// Add tracking code to header if enabled
|
199 |
-
if (self::$
|
200 |
add_action('wp_head', array($this, 'site_header'));
|
201 |
// Add <noscript> code if enabled
|
202 |
-
if (self::$
|
203 |
}
|
|
|
204 |
}
|
205 |
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
/**
|
212 |
-
* Include WP-Piwik files
|
213 |
-
*/
|
214 |
private function includeFile($strFile) {
|
|
|
215 |
if (file_exists(dirname(__FILE__).DIRECTORY_SEPARATOR.$strFile.'.php'))
|
216 |
include(dirname(__FILE__).DIRECTORY_SEPARATOR.$strFile.'.php');
|
217 |
}
|
218 |
|
219 |
-
/**
|
220 |
-
* Install
|
221 |
-
*/
|
222 |
function installPlugin() {
|
223 |
-
|
224 |
-
self::$bolJustActivated = true;
|
225 |
-
// Show an info message after upgrade/install
|
226 |
add_action('admin_notices', array($this, 'updateMessage'));
|
227 |
-
|
228 |
-
self::$
|
229 |
-
self::$
|
230 |
-
// Save upgraded or default settings
|
231 |
-
self::saveSettings();
|
232 |
-
// Reload settings
|
233 |
-
self::loadSettings();
|
234 |
}
|
235 |
|
236 |
-
/**
|
237 |
-
* Uninstall
|
238 |
-
*/
|
239 |
static function uninstallPlugin() {
|
|
|
240 |
// Check if uninstall call is valid
|
241 |
if (!defined('WP_UNINSTALL_PLUGIN'))
|
242 |
exit();
|
243 |
-
self
|
244 |
}
|
245 |
|
246 |
-
/**
|
247 |
-
* Upgrade
|
248 |
-
*/
|
249 |
function upgradePlugin() {
|
|
|
250 |
add_action('admin_notices', array($this, 'updateMessage'));
|
251 |
// Update: Translate options
|
252 |
-
if (self::$
|
253 |
self::includeFile('update/80403');
|
254 |
-
if (self::$
|
255 |
self::includeFile('update/80502');
|
256 |
-
if (self::$
|
257 |
self::includeFile('update/80602');
|
258 |
-
if (self::$
|
259 |
self::includeFile('update/80800');
|
260 |
-
if (self::$
|
261 |
self::includeFile('update/90001');
|
262 |
-
if (self::$
|
263 |
self::includeFile('update/90206');
|
264 |
-
if (self::$
|
265 |
self::includeFile('update/90405');
|
266 |
-
if (self::$
|
267 |
self::includeFile('update/90601');
|
268 |
-
if (self::$
|
269 |
self::includeFile('update/90700');
|
270 |
-
if (self::$
|
271 |
self::includeFile('update/90801');
|
272 |
-
if (self::$
|
273 |
self::includeFile('update/90821');
|
274 |
-
if (self::$
|
275 |
self::includeFile('update/90910');
|
|
|
|
|
276 |
|
277 |
// Install new version
|
278 |
$this->installPlugin();
|
279 |
}
|
280 |
|
281 |
-
/**
|
282 |
-
* Upgrade outdated site settings
|
283 |
-
*/
|
284 |
function updateSite() {
|
|
|
285 |
self::$arySettings = array(
|
286 |
'tracking_code' => '',
|
287 |
'site_id' => get_option('wp-piwik_siteid', NULL),
|
288 |
'last_tracking_code_update' => 0,
|
289 |
'dashboard_revision' => get_option('wp-piwik_dashboardid', 0)
|
290 |
);
|
291 |
-
self::$
|
292 |
// Remove deprecated option values
|
293 |
$aryRemoveOptions = array('wp-piwik_siteid','wp-piwik_404','wp-piwik_scriptupdate','wp-piwik_dashboardid','wp-piwik_jscode');
|
294 |
foreach ($aryRemoveOptions as $strRemoveOption) delete_option($strRemoveOption);
|
295 |
// Save upgraded or default settings
|
296 |
self::saveSettings();
|
297 |
-
// Reload settings
|
298 |
-
self::loadSettings();
|
299 |
}
|
300 |
|
301 |
-
/**
|
302 |
-
* Send a message after installing/updating
|
303 |
-
*/
|
304 |
function updateMessage() {
|
305 |
-
|
306 |
-
$
|
307 |
-
// Next step information
|
308 |
-
$strSettings = (!self::isConfigured()?
|
309 |
-
__('Next you should connect to Piwik','wp-piwik'):
|
310 |
-
__('Please validate your configuration','wp-piwik')
|
311 |
-
);
|
312 |
-
// Create settings Link
|
313 |
$strLink = sprintf('<a href="'.(is_plugin_active_for_network('wp-piwik/wp-piwik.php')?'settings':'options-general').'.php?page=%s">%s</a>', self::$strPluginBasename, __('Settings', 'wp-piwik'));
|
314 |
-
|
315 |
-
echo '<div class="updated fade"><p>'.$strText.' <strong>'.__('Important', 'wp-piwik').':</strong> '.$strSettings.': '.$strLink.'.</p></div>';
|
316 |
}
|
317 |
|
318 |
-
/**
|
319 |
-
* Add tracking code
|
320 |
-
*/
|
321 |
function site_header() {
|
|
|
322 |
// Hotfix: Custom capability problem with WP multisite
|
323 |
if (is_multisite()) {
|
324 |
-
foreach (self::$
|
325 |
-
if ($strVal && current_user_can($strKey))
|
|
|
326 |
return;
|
|
|
327 |
// Don't add tracking code?
|
328 |
} elseif (current_user_can('wp-piwik_stealth')) {
|
|
|
329 |
echo '<!-- *** WP-Piwik - see http://wordpress.org/extend/plugins/wp-piwik/ ******** -->'."\n";
|
330 |
echo '<!-- Current user should not be tracked. -->'."\n";
|
331 |
echo '<!-- *** /WP-Piwik *********************************************************** -->'."\n";
|
@@ -334,25 +215,29 @@ class wp_piwik {
|
|
334 |
// Hotfix: Update network site if not done yet
|
335 |
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && get_option('wp-piwik_siteid', false)) $this->updateSite();
|
336 |
// Autohandle site if no tracking code available
|
337 |
-
if (
|
338 |
$aryReturn = $this->addPiwikSite();
|
339 |
// Update/get code if outdated/unknown
|
340 |
-
if (self::$
|
341 |
-
self::$
|
342 |
-
self
|
343 |
}
|
344 |
// Change code if 404
|
345 |
-
if (is_404() && self::$
|
346 |
-
|
|
|
|
|
347 |
// Change code if search result
|
348 |
-
elseif (is_search() && self::$
|
|
|
349 |
$objSearch = new WP_Query("s=" . get_search_query() . '&showposts=-1');
|
350 |
$intResultCount = $objSearch->post_count;
|
351 |
-
$strTrackingCode = str_replace("_paq.push(['trackPageView']);", "_paq.push(['trackSiteSearch','".get_search_query()."', false, ".$intResultCount."]);\n_paq.push(['trackPageView']);", self::$
|
352 |
// Use default tracking code
|
353 |
} else
|
354 |
-
$strTrackingCode = self::$
|
355 |
// Send tracking code
|
|
|
356 |
echo '<!-- *** WP-Piwik - see http://wordpress.org/extend/plugins/wp-piwik/ ******** -->'."\n";
|
357 |
// Add custom variables if set:
|
358 |
if (is_single()) {
|
@@ -372,7 +257,7 @@ class wp_piwik {
|
|
372 |
echo $strTrackingCode;
|
373 |
echo '<!-- *** /WP-Piwik *********************************************************** -->'."\n";
|
374 |
$strName = get_bloginfo('name');
|
375 |
-
if (
|
376 |
$this->updatePiwikSite();
|
377 |
}
|
378 |
|
@@ -382,14 +267,15 @@ class wp_piwik {
|
|
382 |
function site_footer() {
|
383 |
// Hotfix: Custom capability problem with WP multisite
|
384 |
if (is_multisite()) {
|
385 |
-
foreach (self::$
|
386 |
if ($strVal && current_user_can($strKey))
|
387 |
return;
|
388 |
// Don't add tracking code?
|
389 |
} elseif (current_user_can('wp-piwik_stealth')) return;
|
390 |
// Send tracking code
|
|
|
391 |
echo '<!-- *** WP-Piwik - see http://wordpress.org/extend/plugins/wp-piwik/ ******** -->'."\n";
|
392 |
-
echo self::$
|
393 |
echo '<!-- *** /WP-Piwik *********************************************************** -->'."\n";
|
394 |
}
|
395 |
|
@@ -411,7 +297,7 @@ class wp_piwik {
|
|
411 |
), $aryAttributes);
|
412 |
switch ($this->aryAttributes['module']) {
|
413 |
case 'opt-out':
|
414 |
-
$this->strResult = '<iframe frameborder="no" width="'.$this->aryAttributes['width'].'" height="'.$this->aryAttributes['height'].'" src="'.self::$
|
415 |
break;
|
416 |
case 'overview':
|
417 |
default:
|
@@ -503,7 +389,7 @@ class wp_piwik {
|
|
503 |
// Add dashboard page
|
504 |
$this->intStatsPage = add_dashboard_page(
|
505 |
__('Piwik Statistics', 'wp-piwik'),
|
506 |
-
|
507 |
'wp-piwik_read_stats',
|
508 |
'wp-piwik_stats',
|
509 |
array($this, 'showStats')
|
@@ -520,8 +406,8 @@ class wp_piwik {
|
|
520 |
if (!is_plugin_active_for_network('wp-piwik/wp-piwik.php')) {
|
521 |
// Add options page
|
522 |
$intOptionsPage = add_options_page(
|
523 |
-
|
524 |
-
|
525 |
'activate_plugins',
|
526 |
__FILE__,
|
527 |
array($this, 'showSettings')
|
@@ -544,7 +430,7 @@ class wp_piwik {
|
|
544 |
// Add dashboard page
|
545 |
$this->intStatsPage = add_dashboard_page(
|
546 |
__('Piwik Statistics', 'wp-piwik'),
|
547 |
-
|
548 |
'manage_sites',
|
549 |
'wp-piwik_stats',
|
550 |
array($this, 'showStatsNetwork')
|
@@ -560,8 +446,8 @@ class wp_piwik {
|
|
560 |
}
|
561 |
$intOptionsPage = add_submenu_page(
|
562 |
'settings.php',
|
563 |
-
|
564 |
-
|
565 |
'manage_sites',
|
566 |
__FILE__,
|
567 |
array($this, 'showSettings')
|
@@ -592,10 +478,10 @@ class wp_piwik {
|
|
592 |
if (current_user_can('wp-piwik_read_stats')) {
|
593 |
// TODO: Use bitmask here
|
594 |
// Add data widget if enabled
|
595 |
-
if (self::$
|
596 |
$this->addWordPressDashboardWidget();
|
597 |
// Add chart widget if enabled
|
598 |
-
if (self::$
|
599 |
// Add required scripts
|
600 |
add_action('admin_print_scripts-index.php', array($this, 'loadStatsScripts'));
|
601 |
// Add required styles
|
@@ -605,7 +491,7 @@ class wp_piwik {
|
|
605 |
$this->addWordPressDashboardChart();
|
606 |
}
|
607 |
// Add SEO widget if enabled
|
608 |
-
if (self::$
|
609 |
$this->addWordPressDashboardSEO();
|
610 |
}
|
611 |
}
|
@@ -635,13 +521,13 @@ class wp_piwik {
|
|
635 |
*/
|
636 |
function addWordPressDashboardWidget() {
|
637 |
$aryConfig = array(
|
638 |
-
'params' => array('period' => 'day','date' => self::$
|
639 |
'inline' => true,
|
640 |
);
|
641 |
$strFile = 'overview';
|
642 |
add_meta_box(
|
643 |
'wp-piwik_stats-dashboard-overview',
|
644 |
-
|
645 |
array(&$this, 'createDashboardWidget'),
|
646 |
'dashboard',
|
647 |
'side',
|
@@ -661,7 +547,7 @@ class wp_piwik {
|
|
661 |
$strFile = 'visitors';
|
662 |
add_meta_box(
|
663 |
'wp-piwik_stats-dashboard-chart',
|
664 |
-
|
665 |
array(&$this, 'createDashboardWidget'),
|
666 |
'dashboard',
|
667 |
'side',
|
@@ -681,7 +567,7 @@ class wp_piwik {
|
|
681 |
$strFile = 'seo';
|
682 |
add_meta_box(
|
683 |
'wp-piwik_stats-dashboard-seo',
|
684 |
-
|
685 |
array(&$this, 'createDashboardWidget'),
|
686 |
'dashboard',
|
687 |
'side',
|
@@ -780,7 +666,7 @@ class wp_piwik {
|
|
780 |
* @param $strURL Remote file URL
|
781 |
*/
|
782 |
function callREST($strURL) {
|
783 |
-
$strPiwikURL = self::$
|
784 |
if (substr($strPiwikURL, -1, 1) != '/') $strPiwikURL .= '/';
|
785 |
$strURL = $strPiwikURL.'?module=API'.$strURL;
|
786 |
// Use cURL if available
|
@@ -788,15 +674,15 @@ class wp_piwik {
|
|
788 |
// Init cURL
|
789 |
$c = curl_init($strURL);
|
790 |
// Disable SSL peer verification if asked to
|
791 |
-
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, !self::$
|
792 |
// Set user agent
|
793 |
-
curl_setopt($c, CURLOPT_USERAGENT, self::$
|
794 |
// Configure cURL CURLOPT_RETURNTRANSFER = 1
|
795 |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
|
796 |
// Configure cURL CURLOPT_HEADER = 0
|
797 |
curl_setopt($c, CURLOPT_HEADER, 0);
|
798 |
// Set cURL timeout
|
799 |
-
curl_setopt($c, CURLOPT_TIMEOUT, self::$
|
800 |
if (WP_HTTP_Proxy::is_enabled() && WP_HTTP_Proxy::send_through_proxy($strURL)) {
|
801 |
curl_setopt($c, CURLOPT_PROXY, WP_HTTP_Proxy::host());
|
802 |
curl_setopt($c, CURLOPT_PROXYPORT, WP_HTTP_Proxy::port());
|
@@ -810,7 +696,7 @@ class wp_piwik {
|
|
810 |
// cURL not available but url fopen allowed
|
811 |
} elseif (ini_get('allow_url_fopen')) {
|
812 |
// Set timeout
|
813 |
-
$resContext = stream_context_create(array('http'=>array('timeout' => self::$
|
814 |
// Get file using file_get_contents
|
815 |
$strResult = @file_get_contents($strURL, false, $strContext);
|
816 |
// Error: Not possible to get remote file
|
@@ -829,7 +715,7 @@ class wp_piwik {
|
|
829 |
*/
|
830 |
function callPHP($strParams) {
|
831 |
if (PIWIK_INCLUDE_PATH === FALSE)
|
832 |
-
return serialize(array('result' => 'error', 'message' => __('Could not resolve','wp-piwik').' "'.htmlentities(self::$
|
833 |
if (file_exists(PIWIK_INCLUDE_PATH . "/index.php"))
|
834 |
require_once PIWIK_INCLUDE_PATH . "/index.php";
|
835 |
if (file_exists(PIWIK_INCLUDE_PATH . "/core/API/Request.php"))
|
@@ -837,7 +723,7 @@ class wp_piwik {
|
|
837 |
if (class_exists('Piwik_FrontController'))
|
838 |
Piwik_FrontController::getInstance()->init();
|
839 |
// Add Piwik URL to params
|
840 |
-
$strParams .= '&piwikUrl='.urlencode(self::$
|
841 |
// This inits the API Request with the specified parameters
|
842 |
if (class_exists('Piwik_API_Request'))
|
843 |
$objRequest = new Piwik_API_Request($strParams);
|
@@ -852,7 +738,7 @@ class wp_piwik {
|
|
852 |
* @param String $strURL Remote file URL
|
853 |
*/
|
854 |
function getRemoteFile($strURL) {
|
855 |
-
if (self::$
|
856 |
return $this->callPHP($strURL);
|
857 |
else
|
858 |
return $this->callREST($strURL);
|
@@ -864,39 +750,42 @@ class wp_piwik {
|
|
864 |
*/
|
865 |
function addPiwikSite() {
|
866 |
if (isset($_GET['wpmu_show_stats']) && is_plugin_active_for_network('wp-piwik/wp-piwik.php')) {
|
|
|
867 |
switch_to_blog((int) $_GET['wpmu_show_stats']);
|
868 |
-
self::loadSettings();
|
869 |
}
|
870 |
-
|
871 |
// Check if blog URL already known
|
872 |
$strURL = '&method=SitesManager.getSitesIdFromSiteUrl';
|
873 |
-
$strURL .= '&url='.urlencode(
|
874 |
$strURL .= '&format=PHP';
|
875 |
-
$strURL .= '&token_auth='.self::$
|
876 |
$aryResult = unserialize($this->getRemoteFile($strURL));
|
877 |
if (!empty($aryResult) && isset($aryResult[0]['idsite'])) {
|
878 |
-
self::$
|
879 |
-
self::$arySettings['last_tracking_code_update'] = time();
|
880 |
// Otherwise create new site
|
881 |
} elseif (self::isConfigured() && !empty($strURL)) {
|
|
|
882 |
$strName = get_bloginfo('name');
|
883 |
-
if (empty($strName)) $strName =
|
884 |
-
self::$
|
885 |
$strURL .= '&method=SitesManager.addSite';
|
886 |
-
$strURL .= '&siteName='.urlencode($strName).'&urls='.urlencode(
|
887 |
$strURL .= '&format=PHP';
|
888 |
-
$strURL .= '&token_auth='.self::$
|
889 |
$strResult = unserialize($this->getRemoteFile($strURL));
|
890 |
-
if (!empty($strResult)) self::$
|
891 |
}
|
892 |
// Store new data if site created
|
893 |
-
if (
|
894 |
-
self::$
|
895 |
-
self
|
896 |
-
} else self::$
|
897 |
-
|
|
|
|
|
898 |
restore_current_blog();
|
899 |
-
|
|
|
900 |
}
|
901 |
|
902 |
/**
|
@@ -907,49 +796,53 @@ class wp_piwik {
|
|
907 |
// Check if blog URL already known
|
908 |
$strName = get_bloginfo('name');
|
909 |
if (empty($strName)) $strName = $strBlogURL;
|
910 |
-
self::$
|
911 |
$strURL = '&method=SitesManager.updateSite';
|
912 |
-
$strURL .= '&idSite='.self::$
|
913 |
$strURL .= '&siteName='.urlencode($strName).'&urls='.urlencode($strBlogURL);
|
914 |
$strURL .= '&format=PHP';
|
915 |
-
$strURL .= '&token_auth='.self::$
|
916 |
$strResult = unserialize($this->getRemoteFile($strURL));
|
917 |
// Store new data
|
918 |
-
self::$
|
919 |
-
self
|
920 |
}
|
921 |
|
922 |
/**
|
923 |
* Apply configured Tracking Code changes
|
924 |
*/
|
925 |
function applyJSCodeChanges($strCode) {
|
|
|
|
|
|
|
926 |
// Change code if js/index.php should be used
|
927 |
-
if (self::$
|
928 |
$strCode = str_replace('piwik.js', 'js/', $strCode);
|
929 |
$strCode = str_replace('piwik.php', 'js/', $strCode);
|
930 |
-
} elseif (self::$
|
931 |
$strCode = str_replace('piwik.js', 'piwik.php', $strCode);
|
932 |
-
$strURL = str_replace('https://', '://', self::$
|
933 |
-
$strURL = str_replace('http://', '://',
|
934 |
-
$strProxy = str_replace('https://', '://', plugins_url('wp-piwik
|
935 |
-
$strProxy = str_replace('http://', '://',
|
936 |
$strCode = str_replace($strURL, $strProxy, $strCode);
|
937 |
}
|
938 |
-
|
939 |
-
|
|
|
940 |
$strCode = str_replace("g.src=u+", "g.src=ucdn+", $strCode);
|
941 |
}
|
942 |
// Change code if POST is forced to be used
|
943 |
-
if (self::$
|
944 |
// Change code if cookies are disabled
|
945 |
-
if (self::$
|
946 |
// Store <noscript> code
|
947 |
$aryNoscript = array();
|
948 |
-
preg_match('
|
949 |
if (isset($aryNoscript[0]))
|
950 |
-
self::$
|
951 |
// Remove <noscript> code
|
952 |
-
$strCode = preg_replace('
|
953 |
// Return code without empty lines
|
954 |
return preg_replace('/\s+(\r\n|\r|\n)/', '$1', $strCode);
|
955 |
}
|
@@ -985,19 +878,20 @@ class wp_piwik {
|
|
985 |
$strKey = $strMethod.'_'.$strPeriod.'_'.$strDate.'_'.$intLimit;
|
986 |
// Call API if data not cached
|
987 |
if (empty($this->aryCache[$strKey])) {
|
988 |
-
$strToken = self::$
|
989 |
// If multisite stats are shown, maybe the super admin wants to show other blog's stats.
|
990 |
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && function_exists('is_super_admin') && function_exists('wp_get_current_user') && is_super_admin() && isset($_GET['wpmu_show_stats'])) {
|
991 |
$aryOptions = get_blog_option((int) $_GET['wpmu_show_stats'], 'wp-piwik_settings' , array());
|
992 |
if (!empty($aryOptions) && isset($aryOptions['site_id']))
|
993 |
$intSite = $aryOptions['site_id'];
|
994 |
-
else $intSite = self::$
|
995 |
// Otherwise use the current site's id.
|
996 |
} else {
|
997 |
-
if (
|
998 |
-
|
999 |
-
$intSite = self::$
|
1000 |
}
|
|
|
1001 |
// Create error message if WP-Piwik isn't configured
|
1002 |
if (!self::isConfigured()) {
|
1003 |
$this->aryCache[$strKey] = array(
|
@@ -1013,15 +907,15 @@ class wp_piwik {
|
|
1013 |
$strURL .= '&token_auth='.$strToken;
|
1014 |
$strURL .= '&expanded='.$bolExpanded;
|
1015 |
$strURL .= '&url='.urlencode(get_bloginfo('url'));
|
1016 |
-
$strURL .= '&format='.$strFormat;
|
1017 |
// Fetch data if site exists
|
1018 |
if (!empty($intSite) || $strMethod='SitesManager.getSitesWithAtLeastViewAccess') {
|
|
|
1019 |
$strResult = (string) $this->getRemoteFile($strURL);
|
1020 |
$this->aryCache[$strKey] = ($strFormat == 'PHP'?unserialize($strResult):$strResult);
|
1021 |
// Apply tracking code changes if configured
|
1022 |
-
if ($strMethod == 'SitesManager.getJavascriptTag') {
|
1023 |
-
$this->aryCache[$strKey] =
|
1024 |
-
self::$arySettings['last_tracking_code_update'] = time();
|
1025 |
}
|
1026 |
// Otherwise return error message
|
1027 |
} else $this->aryCache[$strKey] = array('result' => 'error', 'message' => 'Unknown site/blog.');
|
@@ -1045,8 +939,8 @@ class wp_piwik {
|
|
1045 |
wp_enqueue_script('common');
|
1046 |
wp_enqueue_script('wp-lists');
|
1047 |
wp_enqueue_script('postbox');
|
1048 |
-
$strToken = self::$
|
1049 |
-
$strPiwikURL = self::$
|
1050 |
$aryDashboard = array();
|
1051 |
// Set default configuration
|
1052 |
$arySortOrder = array(
|
@@ -1069,7 +963,7 @@ class wp_piwik {
|
|
1069 |
)
|
1070 |
);
|
1071 |
// Don't show SEO stats if disabled
|
1072 |
-
if (!self::$
|
1073 |
unset($arySortOrder['side']['seo']);
|
1074 |
|
1075 |
foreach ($arySortOrder as $strCol => $aryWidgets) {
|
@@ -1085,7 +979,7 @@ class wp_piwik {
|
|
1085 |
if (isset($_GET['date']) && preg_match('/^[0-9]{8}$/', $_GET['date']) && $strFile != 'visitors')
|
1086 |
$aryDashboard[$strCol][$strFile]['params']['date'] = $_GET['date'];
|
1087 |
elseif ($strFile != 'visitors')
|
1088 |
-
$aryDashboard[$strCol][$strFile]['params']['date'] = self::$
|
1089 |
}
|
1090 |
}
|
1091 |
$intSideBoxCnt = $intContentBox = 0;
|
@@ -1129,7 +1023,7 @@ class wp_piwik {
|
|
1129 |
|
1130 |
function showStats() {
|
1131 |
// Disabled time limit if required
|
1132 |
-
if (
|
1133 |
set_time_limit(0);
|
1134 |
//we need the global screen column value to be able to have a sidebar in WordPress 2.8
|
1135 |
global $screen_layout_columns;
|
@@ -1137,32 +1031,12 @@ class wp_piwik {
|
|
1137 |
/***************************************************************************/ ?>
|
1138 |
<div id="wp-piwik-stats-general" class="wrap">
|
1139 |
<?php screen_icon('options-general'); ?>
|
1140 |
-
<h2><?php
|
1141 |
<?php /************************************************************************/
|
1142 |
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && function_exists('is_super_admin') && is_super_admin() && $this->bolNetwork) {
|
1143 |
-
/* global $blog_id;
|
1144 |
-
global $wpdb;
|
1145 |
-
$aryBlogs = $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM '.$wpdb->blogs.' ORDER BY blog_id'));
|
1146 |
if (isset($_GET['wpmu_show_stats'])) {
|
1147 |
switch_to_blog((int) $_GET['wpmu_show_stats']);
|
1148 |
-
|
1149 |
-
}
|
1150 |
-
echo '<form method="GET" action="">'."\n";
|
1151 |
-
echo '<input type="hidden" name="page" value="wp-piwik_stats" />';
|
1152 |
-
echo '<input type="hidden" name="date" value="'.(isset($_GET['date']) && preg_match('/^[0-9]{8}$/', $_GET['date'])?$_GET['date']:'').'" />';
|
1153 |
-
echo '<select name="wpmu_show_stats">'."\n";
|
1154 |
-
$aryOptions = array();
|
1155 |
-
foreach ($aryBlogs as $aryBlog) {
|
1156 |
-
$objBlog = get_blog_details($aryBlog->blog_id, true);
|
1157 |
-
$aryOptions[$objBlog->blogname.'#'.$objBlog->blog_id] = '<option value="'.$objBlog->blog_id.'"'.($blog_id == $objBlog->blog_id?' selected="selected"':'').'>'.$objBlog->blog_id.' - '.$objBlog->blogname.'</option>'."\n";
|
1158 |
-
}
|
1159 |
-
// Show blogs in alphabetical order
|
1160 |
-
ksort($aryOptions);
|
1161 |
-
foreach ($aryOptions as $strOption) echo $strOption;
|
1162 |
-
echo '</select><input type="submit" value="'.__('Change').'" />'."\n "; */
|
1163 |
-
if (isset($_GET['wpmu_show_stats'])) {
|
1164 |
-
switch_to_blog((int) $_GET['wpmu_show_stats']);
|
1165 |
-
self::loadSettings();
|
1166 |
} else {
|
1167 |
$this->includeFile('settings/sitebrowser');
|
1168 |
return;
|
@@ -1203,7 +1077,7 @@ class wp_piwik {
|
|
1203 |
//]]>
|
1204 |
</script>
|
1205 |
<?php /************************************************************************/
|
1206 |
-
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && function_exists('is_super_admin') && is_super_admin()
|
1207 |
restore_current_blog();
|
1208 |
}
|
1209 |
}
|
@@ -1256,57 +1130,59 @@ class wp_piwik {
|
|
1256 |
*/
|
1257 |
function applySettings() {
|
1258 |
$strTab = (isset($_GET['tab'])?$_GET['tab']:'homepage');
|
1259 |
-
self::$
|
1260 |
switch ($strTab) {
|
1261 |
case 'views':
|
1262 |
-
self::$
|
1263 |
-
self::$
|
1264 |
-
self::$
|
1265 |
-
self::$
|
1266 |
-
self::$
|
1267 |
-
self::$
|
1268 |
-
self::$
|
1269 |
-
self::$
|
1270 |
-
self::$
|
1271 |
-
self::$
|
|
|
1272 |
break;
|
1273 |
case 'tracking':
|
1274 |
-
self::$
|
1275 |
-
self::$
|
1276 |
-
self::$
|
1277 |
-
self::$
|
1278 |
-
self::$
|
1279 |
-
self::$
|
1280 |
-
self::$
|
1281 |
-
self::$
|
1282 |
-
self::$
|
1283 |
-
self::$
|
1284 |
-
self::$
|
|
|
1285 |
break;
|
1286 |
case 'piwik':
|
1287 |
-
self::$
|
1288 |
-
self::$
|
1289 |
-
self::$
|
1290 |
-
self::$
|
1291 |
-
self::$
|
1292 |
-
self::$
|
1293 |
-
self::$
|
1294 |
-
self::$
|
1295 |
if (!is_plugin_active_for_network('wp-piwik/wp-piwik.php')) {
|
1296 |
-
self::$
|
1297 |
-
if (!self::$
|
1298 |
-
self::$
|
1299 |
-
} else self::$
|
1300 |
break;
|
1301 |
}
|
1302 |
-
if (self::$
|
1303 |
-
if (self::$
|
1304 |
self::definePiwikConstants();
|
1305 |
$aryReturn = $this->addPiwikSite();
|
1306 |
-
self::$
|
1307 |
-
self::$
|
1308 |
}
|
1309 |
-
self
|
1310 |
}
|
1311 |
|
1312 |
/**
|
@@ -1330,7 +1206,7 @@ class wp_piwik {
|
|
1330 |
if (isset($_POST['wp-piwik_settings_submit']) && $_POST['wp-piwik_settings_submit'] == 'Y')
|
1331 |
echo '<div id="message" class="updated fade"><p>'.__('Changes saved','wp-piwik').'</p></div>';
|
1332 |
// Show settings page title
|
1333 |
-
echo '<div class="wrap"><h2>'.__('
|
1334 |
// Show tabs
|
1335 |
$strTab = $this->showSettingsTabs(self::isConfigured(), $strTab);
|
1336 |
if ($strTab != 'sitebrowser') {
|
@@ -1415,71 +1291,16 @@ class wp_piwik {
|
|
1415 |
private static function loadTestscript() {
|
1416 |
require_once('debug/testscript.php');
|
1417 |
}
|
1418 |
-
|
1419 |
-
/**
|
1420 |
-
* Reset all WP-Piwik settings
|
1421 |
-
*/
|
1422 |
-
private static function resetSettings($bolFull = false) {
|
1423 |
-
global $wpdb;
|
1424 |
-
// Backup auth data
|
1425 |
-
$aryKeep = array(
|
1426 |
-
'revision' => self::$intRevisionId,
|
1427 |
-
'add_tracking_code' => false,
|
1428 |
-
'last_settings_update' => 0,
|
1429 |
-
'piwik_token' => self::$aryGlobalSettings['piwik_token'],
|
1430 |
-
'piwik_url' => self::$aryGlobalSettings['piwik_url'],
|
1431 |
-
'piwik_path' => self::$aryGlobalSettings['piwik_path'],
|
1432 |
-
'piwik_mode' => self::$aryGlobalSettings['piwik_mode'],
|
1433 |
-
'dashboard_widget' => false,
|
1434 |
-
'dashboard_chart' => false,
|
1435 |
-
'dashboard_seo' => false,
|
1436 |
-
'stats_seo' => false,
|
1437 |
-
'capability_stealth' => array(),
|
1438 |
-
'capability_read_stats' => array('administrator' => true),
|
1439 |
-
'piwik_shortcut' => false,
|
1440 |
-
'default_date' => 'yesterday',
|
1441 |
-
'auto_site_config' => true,
|
1442 |
-
'track_404' => false,
|
1443 |
-
'track_search' => false,
|
1444 |
-
'track_mode' => 0,
|
1445 |
-
'track_post' => false,
|
1446 |
-
'track_proxy' => false,
|
1447 |
-
'track_cdnurl' => '',
|
1448 |
-
'track_cdnurlssl' => '',
|
1449 |
-
'track_noscript' => false,
|
1450 |
-
'disable_timelimit' => false,
|
1451 |
-
'disable_cookies' => false,
|
1452 |
-
'toolbar' => false,
|
1453 |
-
'piwik_useragent' => 'php',
|
1454 |
-
'connection_timeout' => 5,
|
1455 |
-
'piwik_useragent_string' => 'WP-Piwik',
|
1456 |
-
'disable_ssl_verify' => false,
|
1457 |
-
'shortcodes' => false
|
1458 |
-
);
|
1459 |
-
// Reset network settings
|
1460 |
-
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php')) {
|
1461 |
-
delete_site_option('wp-piwik_global-settings');
|
1462 |
-
$aryBlogs = $wpdb->get_results('SELECT blog_id FROM '.$wpdb->blogs.' ORDER BY blog_id');
|
1463 |
-
foreach ($aryBlogs as $aryBlog)
|
1464 |
-
delete_blog_option($aryBlog->blog_id, 'wp-piwik_settings');
|
1465 |
-
if (!$bolFull) update_site_option('wp-piwik_global-settings', $aryKeep);
|
1466 |
-
// Reset simple settings
|
1467 |
-
} else {
|
1468 |
-
delete_option('wp-piwik_global-settings');
|
1469 |
-
delete_option('wp-piwik_settings');
|
1470 |
-
if (!$bolFull) update_option('wp-piwik_global-settings', $aryKeep);
|
1471 |
-
}
|
1472 |
-
}
|
1473 |
|
1474 |
/**
|
1475 |
* Get a blog's piwik ID
|
1476 |
*/
|
1477 |
public static function getSiteID($intBlogID = null) {
|
1478 |
-
$intResult = self::$
|
1479 |
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && !empty($intBlogID)) {
|
1480 |
$aryResult = get_blog_option($intBlogID, 'wp-piwik_settings');
|
1481 |
$intResult = $aryResult['site_id'];
|
1482 |
-
}
|
1483 |
return (is_int($intResult)?$intResult:'n/a');
|
1484 |
}
|
1485 |
|
@@ -1488,12 +1309,12 @@ class wp_piwik {
|
|
1488 |
*/
|
1489 |
public static function isConfigured() {
|
1490 |
return (
|
1491 |
-
|
1492 |
&& (
|
1493 |
(
|
1494 |
-
(self::$
|
1495 |
) || (
|
1496 |
-
(self::$
|
1497 |
)
|
1498 |
)
|
1499 |
);
|
@@ -1503,14 +1324,38 @@ class wp_piwik {
|
|
1503 |
* Set Piwik PHP API constants
|
1504 |
*/
|
1505 |
private static function definePiwikConstants() {
|
1506 |
-
define('PIWIK_INCLUDE_PATH', self::$
|
1507 |
-
define('PIWIK_USER_PATH', self::$
|
1508 |
define('PIWIK_ENABLE_DISPATCH', false);
|
1509 |
define('PIWIK_ENABLE_ERROR_HANDLER', false);
|
1510 |
define('PIWIK_ENABLE_SESSION_START', false);
|
1511 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1512 |
}
|
1513 |
|
|
|
|
|
1514 |
if (class_exists('wp_piwik'))
|
1515 |
$GLOBALS['wp_piwik'] = new wp_piwik();
|
1516 |
|
6 |
|
7 |
Description: Adds Piwik stats to your dashboard menu and Piwik code to your wordpress header.
|
8 |
|
9 |
+
Version: 0.9.9.2
|
10 |
Author: André Bräkling
|
11 |
Author URI: http://www.braekling.de
|
12 |
|
27 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
28 |
*******************************************************************************************/
|
29 |
|
30 |
+
// Avoid direct calls to this file if wp core files not present
|
|
|
|
|
|
|
|
|
|
|
31 |
if (!function_exists ('add_action')) {
|
32 |
header('Status: 403 Forbidden');
|
33 |
header('HTTP/1.1 403 Forbidden');
|
34 |
exit();
|
35 |
}
|
36 |
|
37 |
+
// Makes sure all required include files are loaded before trying to use it
|
|
|
|
|
|
|
|
|
|
|
38 |
if (!function_exists('is_plugin_active_for_network'))
|
39 |
require_once(ABSPATH.'/wp-admin/includes/plugin.php');
|
40 |
|
41 |
class wp_piwik {
|
42 |
|
43 |
private static
|
44 |
+
$intRevisionId = 90921,
|
45 |
+
$strVersion = '0.9.9.2',
|
46 |
+
$blog_id,
|
47 |
$intDashboardID = 30,
|
48 |
$strPluginBasename = NULL,
|
49 |
$bolJustActivated = false,
|
50 |
+
$logger,
|
51 |
+
$settings;
|
52 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
private
|
54 |
$intStatsPage = NULL,
|
55 |
$bolNetwork = false,
|
56 |
$aryAttributes = array(),
|
57 |
$strResult = '';
|
58 |
|
59 |
+
public function __construct() {
|
60 |
+
global $blog_id;
|
61 |
+
self::$blog_id = (isset($blog_id)?$blog_id:'n/a');
|
62 |
+
$this->openLogger();
|
63 |
+
$this->openSettings();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
// Call install function on activation
|
65 |
register_activation_hook(__FILE__, array($this, 'installPlugin'));
|
66 |
// Store plugin basename
|
67 |
self::$strPluginBasename = plugin_basename(__FILE__);
|
|
|
|
|
68 |
// Upgrade?
|
69 |
+
if (self::$settings->getGlobalOption('revision') && self::$settings->getGlobalOption('revision') < self::$intRevisionId) $this->upgradePlugin();
|
70 |
// Settings changed?
|
71 |
if (isset($_POST['action']) && $_POST['action'] == 'save_wp-piwik_settings')
|
72 |
$this->applySettings();
|
73 |
// Set Piwik globals if PHP API is used
|
74 |
+
elseif (self::$settings->getGlobalOption('piwik_mode') && self::$settings->getGlobalOption('piwik_mode') == 'php')
|
75 |
self::definePiwikConstants();
|
76 |
// Load language file
|
77 |
load_plugin_textdomain('wp-piwik', false, dirname(self::$strPluginBasename)."/languages/");
|
91 |
add_action('load-post-new.php', array(&$this, 'postMetaboxes'));
|
92 |
// Add dashboard widget if enabled
|
93 |
/* TODO: Use bitmask here */
|
94 |
+
if (self::$settings->getGlobalOption('dashboard_widget') || self::$settings->getGlobalOption('dashboard_chart') || self::$settings->getGlobalOption('dashboard_seo'))
|
95 |
add_action('wp_dashboard_setup', array($this, 'extendWordPressDashboard'));
|
96 |
// Add Toolbar graph if enabled
|
97 |
+
if (self::$settings->getGlobalOption('toolbar')) {
|
98 |
add_action(is_admin()?'admin_head':'wp_head', array($this, 'loadToolbarRequirements'));
|
99 |
add_action('admin_bar_menu', array(&$this, 'extendWordPressToolbar'), 1000);
|
100 |
}
|
101 |
// Enable shortcodes if enabled
|
102 |
+
if (self::$settings->getGlobalOption('shortcodes'))
|
103 |
add_shortcode( 'wp-piwik', array(&$this, 'shortcode'));
|
104 |
|
105 |
// Add tracking code to header if enabled
|
106 |
+
if (self::$settings->getGlobalOption('add_tracking_code')) {
|
107 |
add_action('wp_head', array($this, 'site_header'));
|
108 |
// Add <noscript> code if enabled
|
109 |
+
if (self::$settings->getGlobalOption('track_noscript')) add_action('wp_footer', array($this, 'site_footer'));
|
110 |
}
|
111 |
+
self::$settings->save();
|
112 |
}
|
113 |
|
114 |
+
function __destruct() {
|
115 |
+
$this->closeLogger();
|
116 |
+
}
|
117 |
+
|
|
|
|
|
|
|
|
|
118 |
private function includeFile($strFile) {
|
119 |
+
self::$logger->log('Include '.$strFile.'.php');
|
120 |
if (file_exists(dirname(__FILE__).DIRECTORY_SEPARATOR.$strFile.'.php'))
|
121 |
include(dirname(__FILE__).DIRECTORY_SEPARATOR.$strFile.'.php');
|
122 |
}
|
123 |
|
|
|
|
|
|
|
124 |
function installPlugin() {
|
125 |
+
self::$logger->log('Running WP-Piwik installation');
|
|
|
|
|
126 |
add_action('admin_notices', array($this, 'updateMessage'));
|
127 |
+
self::$bolJustActivated = true;
|
128 |
+
self::$settings->setGlobalOption('revision', self::$intRevisionId);
|
129 |
+
self::$settings->setGlobalOption('last_settings_update', time());
|
|
|
|
|
|
|
|
|
130 |
}
|
131 |
|
|
|
|
|
|
|
132 |
static function uninstallPlugin() {
|
133 |
+
self::$logger->log('Running WP-Piwik uninstallation');
|
134 |
// Check if uninstall call is valid
|
135 |
if (!defined('WP_UNINSTALL_PLUGIN'))
|
136 |
exit();
|
137 |
+
self::$settings->resetSettings(true);
|
138 |
}
|
139 |
|
|
|
|
|
|
|
140 |
function upgradePlugin() {
|
141 |
+
self::$logger->log('Upgrade WP-Piwik to '.self::$strVersion);
|
142 |
add_action('admin_notices', array($this, 'updateMessage'));
|
143 |
// Update: Translate options
|
144 |
+
if (self::$settings->getGlobalOption('revision') < 80403)
|
145 |
self::includeFile('update/80403');
|
146 |
+
if (self::$settings->getGlobalOption('revision') < 80502)
|
147 |
self::includeFile('update/80502');
|
148 |
+
if (self::$settings->getGlobalOption('revision') < 80602)
|
149 |
self::includeFile('update/80602');
|
150 |
+
if (self::$settings->getGlobalOption('revision') < 80800)
|
151 |
self::includeFile('update/80800');
|
152 |
+
if (self::$settings->getGlobalOption('revision') < 90001)
|
153 |
self::includeFile('update/90001');
|
154 |
+
if (self::$settings->getGlobalOption('revision') < 90206)
|
155 |
self::includeFile('update/90206');
|
156 |
+
if (self::$settings->getGlobalOption('revision') < 90405)
|
157 |
self::includeFile('update/90405');
|
158 |
+
if (self::$settings->getGlobalOption('revision') < 90601)
|
159 |
self::includeFile('update/90601');
|
160 |
+
if (self::$settings->getGlobalOption('revision') < 90700)
|
161 |
self::includeFile('update/90700');
|
162 |
+
if (self::$settings->getGlobalOption('revision') < 90805)
|
163 |
self::includeFile('update/90801');
|
164 |
+
if (self::$settings->getGlobalOption('revision') < 90821)
|
165 |
self::includeFile('update/90821');
|
166 |
+
if (self::$settings->getGlobalOption('revision') < 90910)
|
167 |
self::includeFile('update/90910');
|
168 |
+
if (self::$settings->getGlobalOption('revision') < 90921)
|
169 |
+
self::includeFile('update/90920');
|
170 |
|
171 |
// Install new version
|
172 |
$this->installPlugin();
|
173 |
}
|
174 |
|
|
|
|
|
|
|
175 |
function updateSite() {
|
176 |
+
self::$logger->log('Reset site settings to force a site setting update. Blog ID: '.self::$blog_id.' Site ID: '.self::$settings->getOption('site_id'));
|
177 |
self::$arySettings = array(
|
178 |
'tracking_code' => '',
|
179 |
'site_id' => get_option('wp-piwik_siteid', NULL),
|
180 |
'last_tracking_code_update' => 0,
|
181 |
'dashboard_revision' => get_option('wp-piwik_dashboardid', 0)
|
182 |
);
|
183 |
+
self::$settings->setGlobalOption('last_settings_update', time());
|
184 |
// Remove deprecated option values
|
185 |
$aryRemoveOptions = array('wp-piwik_siteid','wp-piwik_404','wp-piwik_scriptupdate','wp-piwik_dashboardid','wp-piwik_jscode');
|
186 |
foreach ($aryRemoveOptions as $strRemoveOption) delete_option($strRemoveOption);
|
187 |
// Save upgraded or default settings
|
188 |
self::saveSettings();
|
|
|
|
|
189 |
}
|
190 |
|
|
|
|
|
|
|
191 |
function updateMessage() {
|
192 |
+
$strText = self::$settings->getGlobalOption('plugin_display_name').' '.self::$strVersion.' '.__('installed','wp-piwik').'.';
|
193 |
+
$strNotice = (!self::isConfigured()?__('Next you should connect to Piwik','wp-piwik'):__('Please validate your configuration','wp-piwik'));
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
$strLink = sprintf('<a href="'.(is_plugin_active_for_network('wp-piwik/wp-piwik.php')?'settings':'options-general').'.php?page=%s">%s</a>', self::$strPluginBasename, __('Settings', 'wp-piwik'));
|
195 |
+
echo '<div class="updated fade"><p>'.$strText.' <strong>'.__('Important', 'wp-piwik').':</strong> '.$strNotice.': '.$strLink.'.</p></div>';
|
|
|
196 |
}
|
197 |
|
|
|
|
|
|
|
198 |
function site_header() {
|
199 |
+
global $blod_id;
|
200 |
// Hotfix: Custom capability problem with WP multisite
|
201 |
if (is_multisite()) {
|
202 |
+
foreach (self::$settings->getGlobalOption('capability_stealth') as $strKey => $strVal)
|
203 |
+
if ($strVal && current_user_can($strKey)) {
|
204 |
+
self::$logger->log('Do not add tracking code to site header (user should not be tracked) Blog ID: '.self::$blog_id.' Site ID: '.self::$settings->getOption('site_id'));
|
205 |
return;
|
206 |
+
}
|
207 |
// Don't add tracking code?
|
208 |
} elseif (current_user_can('wp-piwik_stealth')) {
|
209 |
+
self::$logger->log('Do not add tracking code to site header (user should not be tracked) Blog ID: '.self::$blog_id.' Site ID: '.self::$settings->getOption('site_id'));
|
210 |
echo '<!-- *** WP-Piwik - see http://wordpress.org/extend/plugins/wp-piwik/ ******** -->'."\n";
|
211 |
echo '<!-- Current user should not be tracked. -->'."\n";
|
212 |
echo '<!-- *** /WP-Piwik *********************************************************** -->'."\n";
|
215 |
// Hotfix: Update network site if not done yet
|
216 |
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && get_option('wp-piwik_siteid', false)) $this->updateSite();
|
217 |
// Autohandle site if no tracking code available
|
218 |
+
if (!self::$settings->getOption('tracking_code'))
|
219 |
$aryReturn = $this->addPiwikSite();
|
220 |
// Update/get code if outdated/unknown
|
221 |
+
if (self::$settings->getOption('last_tracking_code_update') < self::$settings->getGlobalOption('last_settings_update') || !self::$settings->getOption('tracking_code')) {
|
222 |
+
self::$settings->setOption('tracking_code', $this->callPiwikAPI('SitesManager.getJavascriptTag'));
|
223 |
+
self::$settings->save();
|
224 |
}
|
225 |
// Change code if 404
|
226 |
+
if (is_404() && self::$settings->getGlobalOption('track_404')) {
|
227 |
+
self::$logger->log('Apply 404 changes. Blog ID: '.self::$blog_id.' Site ID: '.self::$settings->getOption('site_id'));
|
228 |
+
$strTrackingCode = str_replace("_paq.push(['trackPageView']);", "_paq.push(['setDocumentTitle', '404/URL = '+String(document.location.pathname+document.location.search).replace(/\//g,'%2f') + '/From = ' + String(document.referrer).replace(/\//g,'%2f')]);\n_paq.push(['trackPageView']);", self::$settings->getOption('tracking_code'));
|
229 |
+
}
|
230 |
// Change code if search result
|
231 |
+
elseif (is_search() && self::$settings->getGlobalOption('track_search')) {
|
232 |
+
self::$logger->log('Apply search tracking changes. Blog ID: '.self::$blog_id.' Site ID: '.self::$settings->getOption('site_id'));
|
233 |
$objSearch = new WP_Query("s=" . get_search_query() . '&showposts=-1');
|
234 |
$intResultCount = $objSearch->post_count;
|
235 |
+
$strTrackingCode = str_replace("_paq.push(['trackPageView']);", "_paq.push(['trackSiteSearch','".get_search_query()."', false, ".$intResultCount."]);\n_paq.push(['trackPageView']);", self::$settings->getOption('tracking_code'));
|
236 |
// Use default tracking code
|
237 |
} else
|
238 |
+
$strTrackingCode = self::$settings->getOption('tracking_code');
|
239 |
// Send tracking code
|
240 |
+
self::$logger->log('Add tracking code. Blog ID: '.self::$blog_id.' Site ID: '.self::$settings->getOption('site_id'));
|
241 |
echo '<!-- *** WP-Piwik - see http://wordpress.org/extend/plugins/wp-piwik/ ******** -->'."\n";
|
242 |
// Add custom variables if set:
|
243 |
if (is_single()) {
|
257 |
echo $strTrackingCode;
|
258 |
echo '<!-- *** /WP-Piwik *********************************************************** -->'."\n";
|
259 |
$strName = get_bloginfo('name');
|
260 |
+
if (self::$settings->getOption('name') != $strName)
|
261 |
$this->updatePiwikSite();
|
262 |
}
|
263 |
|
267 |
function site_footer() {
|
268 |
// Hotfix: Custom capability problem with WP multisite
|
269 |
if (is_multisite()) {
|
270 |
+
foreach (self::$settings->getGlobalOption('capability_stealth') as $strKey => $strVal)
|
271 |
if ($strVal && current_user_can($strKey))
|
272 |
return;
|
273 |
// Don't add tracking code?
|
274 |
} elseif (current_user_can('wp-piwik_stealth')) return;
|
275 |
// Send tracking code
|
276 |
+
self::$logger->log('Add noscript code. Blog ID: '.self::$blog_id.' Site ID: '.self::$settings->getOption('site_id'));
|
277 |
echo '<!-- *** WP-Piwik - see http://wordpress.org/extend/plugins/wp-piwik/ ******** -->'."\n";
|
278 |
+
echo self::$settings->getOption('noscript_code')."\n";
|
279 |
echo '<!-- *** /WP-Piwik *********************************************************** -->'."\n";
|
280 |
}
|
281 |
|
297 |
), $aryAttributes);
|
298 |
switch ($this->aryAttributes['module']) {
|
299 |
case 'opt-out':
|
300 |
+
$this->strResult = '<iframe frameborder="no" width="'.$this->aryAttributes['width'].'" height="'.$this->aryAttributes['height'].'" src="'.self::$settings->getGlobalOption('piwik_url').'index.php?module=CoreAdminHome&action=optOut&language='.$this->aryAttributes['language'].'"></iframe>';
|
301 |
break;
|
302 |
case 'overview':
|
303 |
default:
|
389 |
// Add dashboard page
|
390 |
$this->intStatsPage = add_dashboard_page(
|
391 |
__('Piwik Statistics', 'wp-piwik'),
|
392 |
+
self::$settings->getGlobalOption('plugin_display_name'),
|
393 |
'wp-piwik_read_stats',
|
394 |
'wp-piwik_stats',
|
395 |
array($this, 'showStats')
|
406 |
if (!is_plugin_active_for_network('wp-piwik/wp-piwik.php')) {
|
407 |
// Add options page
|
408 |
$intOptionsPage = add_options_page(
|
409 |
+
self::$settings->getGlobalOption('plugin_display_name'),
|
410 |
+
self::$settings->getGlobalOption('plugin_display_name'),
|
411 |
'activate_plugins',
|
412 |
__FILE__,
|
413 |
array($this, 'showSettings')
|
430 |
// Add dashboard page
|
431 |
$this->intStatsPage = add_dashboard_page(
|
432 |
__('Piwik Statistics', 'wp-piwik'),
|
433 |
+
self::$settings->getGlobalOption('plugin_display_name'),
|
434 |
'manage_sites',
|
435 |
'wp-piwik_stats',
|
436 |
array($this, 'showStatsNetwork')
|
446 |
}
|
447 |
$intOptionsPage = add_submenu_page(
|
448 |
'settings.php',
|
449 |
+
self::$settings->getGlobalOption('plugin_display_name'),
|
450 |
+
self::$settings->getGlobalOption('plugin_display_name'),
|
451 |
'manage_sites',
|
452 |
__FILE__,
|
453 |
array($this, 'showSettings')
|
478 |
if (current_user_can('wp-piwik_read_stats')) {
|
479 |
// TODO: Use bitmask here
|
480 |
// Add data widget if enabled
|
481 |
+
if (self::$settings->getGlobalOption('dashboard_widget'))
|
482 |
$this->addWordPressDashboardWidget();
|
483 |
// Add chart widget if enabled
|
484 |
+
if (self::$settings->getGlobalOption('dashboard_chart')) {
|
485 |
// Add required scripts
|
486 |
add_action('admin_print_scripts-index.php', array($this, 'loadStatsScripts'));
|
487 |
// Add required styles
|
491 |
$this->addWordPressDashboardChart();
|
492 |
}
|
493 |
// Add SEO widget if enabled
|
494 |
+
if (self::$settings->getGlobalOption('dashboard_seo'))
|
495 |
$this->addWordPressDashboardSEO();
|
496 |
}
|
497 |
}
|
521 |
*/
|
522 |
function addWordPressDashboardWidget() {
|
523 |
$aryConfig = array(
|
524 |
+
'params' => array('period' => 'day','date' => self::$settings->getGlobalOption('dashboard_widget'),'limit' => null),
|
525 |
'inline' => true,
|
526 |
);
|
527 |
$strFile = 'overview';
|
528 |
add_meta_box(
|
529 |
'wp-piwik_stats-dashboard-overview',
|
530 |
+
self::$settings->getGlobalOption('plugin_display_name').' - '.__(self::$settings->getGlobalOption('dashboard_widget'), 'wp-piwik'),
|
531 |
array(&$this, 'createDashboardWidget'),
|
532 |
'dashboard',
|
533 |
'side',
|
547 |
$strFile = 'visitors';
|
548 |
add_meta_box(
|
549 |
'wp-piwik_stats-dashboard-chart',
|
550 |
+
self::$settings->getGlobalOption('plugin_display_name').' - '.__('Visitors', 'wp-piwik'),
|
551 |
array(&$this, 'createDashboardWidget'),
|
552 |
'dashboard',
|
553 |
'side',
|
567 |
$strFile = 'seo';
|
568 |
add_meta_box(
|
569 |
'wp-piwik_stats-dashboard-seo',
|
570 |
+
self::$settings->getGlobalOption('plugin_display_name').' - '.__('SEO', 'wp-piwik'),
|
571 |
array(&$this, 'createDashboardWidget'),
|
572 |
'dashboard',
|
573 |
'side',
|
666 |
* @param $strURL Remote file URL
|
667 |
*/
|
668 |
function callREST($strURL) {
|
669 |
+
$strPiwikURL = self::$settings->getGlobalOption('piwik_url');
|
670 |
if (substr($strPiwikURL, -1, 1) != '/') $strPiwikURL .= '/';
|
671 |
$strURL = $strPiwikURL.'?module=API'.$strURL;
|
672 |
// Use cURL if available
|
674 |
// Init cURL
|
675 |
$c = curl_init($strURL);
|
676 |
// Disable SSL peer verification if asked to
|
677 |
+
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, !self::$settings->getGlobalOption('disable_ssl_verify'));
|
678 |
// Set user agent
|
679 |
+
curl_setopt($c, CURLOPT_USERAGENT, self::$settings->getGlobalOption('piwik_useragent')=='php'?ini_get('user_agent'):self::$settings->getGlobalOption('piwik_useragent_string'));
|
680 |
// Configure cURL CURLOPT_RETURNTRANSFER = 1
|
681 |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
|
682 |
// Configure cURL CURLOPT_HEADER = 0
|
683 |
curl_setopt($c, CURLOPT_HEADER, 0);
|
684 |
// Set cURL timeout
|
685 |
+
curl_setopt($c, CURLOPT_TIMEOUT, self::$settings->getGlobalOption('connection_timeout'));
|
686 |
if (WP_HTTP_Proxy::is_enabled() && WP_HTTP_Proxy::send_through_proxy($strURL)) {
|
687 |
curl_setopt($c, CURLOPT_PROXY, WP_HTTP_Proxy::host());
|
688 |
curl_setopt($c, CURLOPT_PROXYPORT, WP_HTTP_Proxy::port());
|
696 |
// cURL not available but url fopen allowed
|
697 |
} elseif (ini_get('allow_url_fopen')) {
|
698 |
// Set timeout
|
699 |
+
$resContext = stream_context_create(array('http'=>array('timeout' => self::$settings->getGlobalOption('connection_timeout'))));
|
700 |
// Get file using file_get_contents
|
701 |
$strResult = @file_get_contents($strURL, false, $strContext);
|
702 |
// Error: Not possible to get remote file
|
715 |
*/
|
716 |
function callPHP($strParams) {
|
717 |
if (PIWIK_INCLUDE_PATH === FALSE)
|
718 |
+
return serialize(array('result' => 'error', 'message' => __('Could not resolve','wp-piwik').' "'.htmlentities(self::$settings->getGlobalOption('piwik_path')).'": '.__('realpath() returns false','wp-piwik').'.'));
|
719 |
if (file_exists(PIWIK_INCLUDE_PATH . "/index.php"))
|
720 |
require_once PIWIK_INCLUDE_PATH . "/index.php";
|
721 |
if (file_exists(PIWIK_INCLUDE_PATH . "/core/API/Request.php"))
|
723 |
if (class_exists('Piwik_FrontController'))
|
724 |
Piwik_FrontController::getInstance()->init();
|
725 |
// Add Piwik URL to params
|
726 |
+
$strParams .= '&piwikUrl='.urlencode(self::$settings->getGlobalOption('piwik_url'));
|
727 |
// This inits the API Request with the specified parameters
|
728 |
if (class_exists('Piwik_API_Request'))
|
729 |
$objRequest = new Piwik_API_Request($strParams);
|
738 |
* @param String $strURL Remote file URL
|
739 |
*/
|
740 |
function getRemoteFile($strURL) {
|
741 |
+
if (self::$settings->getGlobalOption('piwik_mode') == 'php')
|
742 |
return $this->callPHP($strURL);
|
743 |
else
|
744 |
return $this->callREST($strURL);
|
750 |
*/
|
751 |
function addPiwikSite() {
|
752 |
if (isset($_GET['wpmu_show_stats']) && is_plugin_active_for_network('wp-piwik/wp-piwik.php')) {
|
753 |
+
self::$logger->log('Switch blog ID: '.(int) $_GET['wpmu_show_stats']);
|
754 |
switch_to_blog((int) $_GET['wpmu_show_stats']);
|
|
|
755 |
}
|
756 |
+
self::$logger->log('Get the blog\'s site ID by URL: '.get_bloginfo('url'));
|
757 |
// Check if blog URL already known
|
758 |
$strURL = '&method=SitesManager.getSitesIdFromSiteUrl';
|
759 |
+
$strURL .= '&url='.urlencode(get_bloginfo('url'));
|
760 |
$strURL .= '&format=PHP';
|
761 |
+
$strURL .= '&token_auth='.self::$settings->getGlobalOption('piwik_token');
|
762 |
$aryResult = unserialize($this->getRemoteFile($strURL));
|
763 |
if (!empty($aryResult) && isset($aryResult[0]['idsite'])) {
|
764 |
+
self::$settings->setOption('site_id', (int) $aryResult[0]['idsite']);
|
|
|
765 |
// Otherwise create new site
|
766 |
} elseif (self::isConfigured() && !empty($strURL)) {
|
767 |
+
self::$logger->log('Blog not known yet - create new site');
|
768 |
$strName = get_bloginfo('name');
|
769 |
+
if (empty($strName)) $strName = get_bloginfo('url');
|
770 |
+
self::$settings->setOption('name', $strName);
|
771 |
$strURL .= '&method=SitesManager.addSite';
|
772 |
+
$strURL .= '&siteName='.urlencode($strName).'&urls='.urlencode(get_bloginfo('url'));
|
773 |
$strURL .= '&format=PHP';
|
774 |
+
$strURL .= '&token_auth='.self::$settings->getGlobalOption('piwik_token');
|
775 |
$strResult = unserialize($this->getRemoteFile($strURL));
|
776 |
+
if (!empty($strResult)) self::$settings->setOption('site_id', (int) $strResult);
|
777 |
}
|
778 |
// Store new data if site created
|
779 |
+
if (self::$settings->getOption('site_id')) {
|
780 |
+
self::$logger->log('Get the site\'s tracking code');
|
781 |
+
self::$settings->setOption('tracking_code', $this->callPiwikAPI('SitesManager.getJavascriptTag'));
|
782 |
+
} else self::$settings->getOption('tracking_code', '');
|
783 |
+
self::$settings->save();
|
784 |
+
if (isset($_GET['wpmu_show_stats']) && is_plugin_active_for_network('wp-piwik/wp-piwik.php')) {
|
785 |
+
self::$logger->log('Back to current blog');
|
786 |
restore_current_blog();
|
787 |
+
}
|
788 |
+
return array('js' => self::$settings->getOption('tracking_code'), 'id' => self::$settings->getOption('site_id'));
|
789 |
}
|
790 |
|
791 |
/**
|
796 |
// Check if blog URL already known
|
797 |
$strName = get_bloginfo('name');
|
798 |
if (empty($strName)) $strName = $strBlogURL;
|
799 |
+
self::$settings->setOption('name', $strName);
|
800 |
$strURL = '&method=SitesManager.updateSite';
|
801 |
+
$strURL .= '&idSite='.self::$settings->getOption('site_id');
|
802 |
$strURL .= '&siteName='.urlencode($strName).'&urls='.urlencode($strBlogURL);
|
803 |
$strURL .= '&format=PHP';
|
804 |
+
$strURL .= '&token_auth='.self::$settings->getGlobalOption('piwik_token');
|
805 |
$strResult = unserialize($this->getRemoteFile($strURL));
|
806 |
// Store new data
|
807 |
+
self::$settings->getOption('tracking_code', $this->callPiwikAPI('SitesManager.getJavascriptTag'));
|
808 |
+
self::$settings->save();
|
809 |
}
|
810 |
|
811 |
/**
|
812 |
* Apply configured Tracking Code changes
|
813 |
*/
|
814 |
function applyJSCodeChanges($strCode) {
|
815 |
+
self::$logger->log('Apply tracking code changes.');
|
816 |
+
self::$settings->setOption('last_tracking_code_update', time());
|
817 |
+
$strCode = html_entity_decode($strCode);
|
818 |
// Change code if js/index.php should be used
|
819 |
+
if (self::$settings->getGlobalOption('track_mode') == 1) {
|
820 |
$strCode = str_replace('piwik.js', 'js/', $strCode);
|
821 |
$strCode = str_replace('piwik.php', 'js/', $strCode);
|
822 |
+
} elseif (self::$settings->getGlobalOption('track_mode') == 2) {
|
823 |
$strCode = str_replace('piwik.js', 'piwik.php', $strCode);
|
824 |
+
$strURL = str_replace('https://', '://', self::$settings->getGlobalOption('piwik_url'));
|
825 |
+
$strURL = str_replace('http://', '://', $strURL);
|
826 |
+
$strProxy = str_replace('https://', '://', plugins_url('wp-piwik'));
|
827 |
+
$strProxy = str_replace('http://', '://', $strProxy);
|
828 |
$strCode = str_replace($strURL, $strProxy, $strCode);
|
829 |
}
|
830 |
+
$strCode = str_replace('//";','/"',$strCode);
|
831 |
+
if (self::$settings->getGlobalOption('track_cdnurl')||self::$settings->getGlobalOption('track_cdnurlssl')) {
|
832 |
+
$strCode = str_replace("var d=doc", "var ucdn=(('https:' == document.location.protocol) ? 'https://".(self::$settings->getGlobalOption('track_cdnurlssl')?self::$settings->getGlobalOption('track_cdnurlssl'):self::$settings->getGlobalOption('track_cdnurl'))."/' : 'http://".(self::$settings->getGlobalOption('track_cdnurl')?self::$settings->getGlobalOption('track_cdnurl'):self::$settings->getGlobalOption('track_cdnurlssl'))."/');\nvar d=doc", $strCode);
|
833 |
$strCode = str_replace("g.src=u+", "g.src=ucdn+", $strCode);
|
834 |
}
|
835 |
// Change code if POST is forced to be used
|
836 |
+
if (self::$settings->getGlobalOption('track_post') && self::$settings->getGlobalOption('track_mode') != 2) $strCode = str_replace("_paq.push(['trackPageView']);", "_paq.push(['setRequestMethod', 'POST']);\n_paq.push(['trackPageView']);", $strCode);
|
837 |
// Change code if cookies are disabled
|
838 |
+
if (self::$settings->getGlobalOption('disable_cookies')) $strCode = str_replace("_paq.push(['trackPageView']);", "_paq.push(['disableCookies']);\n_paq.push(['trackPageView']);", $strCode);
|
839 |
// Store <noscript> code
|
840 |
$aryNoscript = array();
|
841 |
+
preg_match('/<noscript>(.*)<\/noscript>/', $strCode, $aryNoscript);
|
842 |
if (isset($aryNoscript[0]))
|
843 |
+
self::$settings->setOption('noscript_code', $aryNoscript[0]);
|
844 |
// Remove <noscript> code
|
845 |
+
$strCode = preg_replace('/<noscript>(.*)<\/noscript>/', '', $strCode);
|
846 |
// Return code without empty lines
|
847 |
return preg_replace('/\s+(\r\n|\r|\n)/', '$1', $strCode);
|
848 |
}
|
878 |
$strKey = $strMethod.'_'.$strPeriod.'_'.$strDate.'_'.$intLimit;
|
879 |
// Call API if data not cached
|
880 |
if (empty($this->aryCache[$strKey])) {
|
881 |
+
$strToken = self::$settings->getGlobalOption('piwik_token');
|
882 |
// If multisite stats are shown, maybe the super admin wants to show other blog's stats.
|
883 |
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && function_exists('is_super_admin') && function_exists('wp_get_current_user') && is_super_admin() && isset($_GET['wpmu_show_stats'])) {
|
884 |
$aryOptions = get_blog_option((int) $_GET['wpmu_show_stats'], 'wp-piwik_settings' , array());
|
885 |
if (!empty($aryOptions) && isset($aryOptions['site_id']))
|
886 |
$intSite = $aryOptions['site_id'];
|
887 |
+
else $intSite = self::$settings->getOption('site_id');
|
888 |
// Otherwise use the current site's id.
|
889 |
} else {
|
890 |
+
if (!self::$settings->getOption('site_id'))
|
891 |
+
self::addPiwikSite();
|
892 |
+
$intSite = self::$settings->getOption('site_id');
|
893 |
}
|
894 |
+
//die($intSite);
|
895 |
// Create error message if WP-Piwik isn't configured
|
896 |
if (!self::isConfigured()) {
|
897 |
$this->aryCache[$strKey] = array(
|
907 |
$strURL .= '&token_auth='.$strToken;
|
908 |
$strURL .= '&expanded='.$bolExpanded;
|
909 |
$strURL .= '&url='.urlencode(get_bloginfo('url'));
|
910 |
+
$strURL .= '&format='.$strFormat;
|
911 |
// Fetch data if site exists
|
912 |
if (!empty($intSite) || $strMethod='SitesManager.getSitesWithAtLeastViewAccess') {
|
913 |
+
self::$logger->log('API method: '.$strMethod.' API call: '.$strURL);
|
914 |
$strResult = (string) $this->getRemoteFile($strURL);
|
915 |
$this->aryCache[$strKey] = ($strFormat == 'PHP'?unserialize($strResult):$strResult);
|
916 |
// Apply tracking code changes if configured
|
917 |
+
if ($strMethod == 'SitesManager.getJavascriptTag' && !empty($this->aryCache[$strKey])) {
|
918 |
+
$this->aryCache[$strKey] = is_string($this->aryCache[$strKey])?$this->applyJSCodeChanges($this->aryCache[$strKey]):'<!-- WP-Piwik ERROR: Tracking code not availbale -->'."\n";
|
|
|
919 |
}
|
920 |
// Otherwise return error message
|
921 |
} else $this->aryCache[$strKey] = array('result' => 'error', 'message' => 'Unknown site/blog.');
|
939 |
wp_enqueue_script('common');
|
940 |
wp_enqueue_script('wp-lists');
|
941 |
wp_enqueue_script('postbox');
|
942 |
+
$strToken = self::$settings->getGlobalOption('piwik_token');
|
943 |
+
$strPiwikURL = self::$settings->getGlobalOption('piwik_url');
|
944 |
$aryDashboard = array();
|
945 |
// Set default configuration
|
946 |
$arySortOrder = array(
|
963 |
)
|
964 |
);
|
965 |
// Don't show SEO stats if disabled
|
966 |
+
if (!self::$settings->getGlobalOption('stats_seo'))
|
967 |
unset($arySortOrder['side']['seo']);
|
968 |
|
969 |
foreach ($arySortOrder as $strCol => $aryWidgets) {
|
979 |
if (isset($_GET['date']) && preg_match('/^[0-9]{8}$/', $_GET['date']) && $strFile != 'visitors')
|
980 |
$aryDashboard[$strCol][$strFile]['params']['date'] = $_GET['date'];
|
981 |
elseif ($strFile != 'visitors')
|
982 |
+
$aryDashboard[$strCol][$strFile]['params']['date'] = self::$settings->getGlobalOption('default_date');
|
983 |
}
|
984 |
}
|
985 |
$intSideBoxCnt = $intContentBox = 0;
|
1023 |
|
1024 |
function showStats() {
|
1025 |
// Disabled time limit if required
|
1026 |
+
if (self::$settings->getGlobalOption('disable_timelimit') && self::$settings->getGlobalOption('disable_timelimit'))
|
1027 |
set_time_limit(0);
|
1028 |
//we need the global screen column value to be able to have a sidebar in WordPress 2.8
|
1029 |
global $screen_layout_columns;
|
1031 |
/***************************************************************************/ ?>
|
1032 |
<div id="wp-piwik-stats-general" class="wrap">
|
1033 |
<?php screen_icon('options-general'); ?>
|
1034 |
+
<h2><?php echo (self::$settings->getGlobalOption('plugin_display_name') == 'WP-Piwik'?'Piwik '.__('Statistics', 'wp-piwik'):self::$settings->getGlobalOption('plugin_display_name')); ?></h2>
|
1035 |
<?php /************************************************************************/
|
1036 |
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && function_exists('is_super_admin') && is_super_admin() && $this->bolNetwork) {
|
|
|
|
|
|
|
1037 |
if (isset($_GET['wpmu_show_stats'])) {
|
1038 |
switch_to_blog((int) $_GET['wpmu_show_stats']);
|
1039 |
+
// TODO OPTIMIZE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1040 |
} else {
|
1041 |
$this->includeFile('settings/sitebrowser');
|
1042 |
return;
|
1077 |
//]]>
|
1078 |
</script>
|
1079 |
<?php /************************************************************************/
|
1080 |
+
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && function_exists('is_super_admin') && is_super_admin()) {
|
1081 |
restore_current_blog();
|
1082 |
}
|
1083 |
}
|
1130 |
*/
|
1131 |
function applySettings() {
|
1132 |
$strTab = (isset($_GET['tab'])?$_GET['tab']:'homepage');
|
1133 |
+
self::$logger->log('Apply changes: '.$strTab);
|
1134 |
switch ($strTab) {
|
1135 |
case 'views':
|
1136 |
+
self::$settings->setGlobalOption('plugin_display_name', (!empty($_POST['wp-piwik_displayname'])?htmlentities($_POST['wp-piwik_displayname']):'WP-Piwk'));
|
1137 |
+
self::$settings->setGlobalOption('dashboard_widget',(isset($_POST['wp-piwik_dbwidget'])?$_POST['wp-piwik_dbwidget']:0));
|
1138 |
+
self::$settings->setGlobalOption('dashboard_chart',(isset($_POST['wp-piwik_dbchart'])?$_POST['wp-piwik_dbchart']:false));
|
1139 |
+
self::$settings->setGlobalOption('dashboard_seo',(isset($_POST['wp-piwik_dbseo'])?$_POST['wp-piwik_dbseo']:false));
|
1140 |
+
self::$settings->setGlobalOption('stats_seo',(isset($_POST['wp-piwik_statsseo'])?$_POST['wp-piwik_statsseo']:false));
|
1141 |
+
self::$settings->setGlobalOption('piwik_shortcut', (isset($_POST['wp-piwik_piwiklink'])?$_POST['wp-piwik_piwiklink']:false));
|
1142 |
+
self::$settings->setGlobalOption('default_date', (isset($_POST['wp-piwik_default_date'])?$_POST['wp-piwik_default_date']:'yesterday'));
|
1143 |
+
self::$settings->setGlobalOption('capability_read_stats', (isset($_POST['wp-piwik_displayto'])?$_POST['wp-piwik_displayto']:array()));
|
1144 |
+
self::$settings->setGlobalOption('disable_timelimit', (isset($_POST['wp-piwik_disabletimelimit'])?$_POST['wp-piwik_disabletimelimit']:false));
|
1145 |
+
self::$settings->setGlobalOption('toolbar', (isset($_POST['wp-piwik_toolbar'])?$_POST['wp-piwik_toolbar']:false));
|
1146 |
+
self::$settings->setGlobalOption('shortcodes', (isset($_POST['wp-piwik_shortcodes'])?$_POST['wp-piwik_shortcodes']:false));
|
1147 |
break;
|
1148 |
case 'tracking':
|
1149 |
+
self::$settings->setGlobalOption('add_tracking_code', (isset($_POST['wp-piwik_addjs'])?$_POST['wp-piwik_addjs']:false));
|
1150 |
+
self::$settings->setGlobalOption('track_404', (isset($_POST['wp-piwik_404'])?$_POST['wp-piwik_404']:false));
|
1151 |
+
self::$settings->setGlobalOption('track_search', (isset($_POST['wp-piwik_search'])?$_POST['wp-piwik_search']:false));
|
1152 |
+
self::$settings->setGlobalOption('track_mode', (isset($_POST['wp-piwik_trackingmode'])?(int)$_POST['wp-piwik_trackingmode']:0));
|
1153 |
+
self::$settings->setGlobalOption('track_post', (isset($_POST['wp-piwik_reqpost'])?$_POST['wp-piwik_reqpost']:false));
|
1154 |
+
self::$settings->setGlobalOption('track_proxy', (isset($_POST['wp-piwik_proxy'])?$_POST['wp-piwik_proxy']:false));
|
1155 |
+
self::$settings->setGlobalOption('track_cdnurl', trim(isset($_POST['wp-piwik_cdnurl'])?$_POST['wp-piwik_cdnurl']:''));
|
1156 |
+
self::$settings->setGlobalOption('track_cdnurlssl', trim(isset($_POST['wp-piwik_cdnurlssl'])?$_POST['wp-piwik_cdnurlssl']:self::$settings->getGlobalOption('track_cdnurl')));
|
1157 |
+
self::$settings->setGlobalOption('track_noscript', (isset($_POST['wp-piwik_noscript'])?$_POST['wp-piwik_noscript']:false));
|
1158 |
+
self::$settings->setGlobalOption('capability_stealth', (isset($_POST['wp-piwik_filter'])?$_POST['wp-piwik_filter']:array()));
|
1159 |
+
self::$settings->setGlobalOption('disable_cookies', (isset($_POST['wp-piwik_disable_cookies'])?$_POST['wp-piwik_disable_cookies']:false));
|
1160 |
+
self::$settings->setOption('tracking_code', $this->callPiwikAPI('SitesManager.getJavascriptTag'));
|
1161 |
break;
|
1162 |
case 'piwik':
|
1163 |
+
self::$settings->setGlobalOption('piwik_token', (isset($_POST['wp-piwik_token'])?$_POST['wp-piwik_token']:''));
|
1164 |
+
self::$settings->setGlobalOption('piwik_url', self::checkURL((isset($_POST['wp-piwik_url'])?$_POST['wp-piwik_url']:'')));
|
1165 |
+
self::$settings->setGlobalOption('piwik_path', (isset($_POST['wp-piwik_path']) && !empty($_POST['wp-piwik_path'])?realpath($_POST['wp-piwik_path']):''));
|
1166 |
+
self::$settings->setGlobalOption('piwik_mode', (isset($_POST['wp-piwik_mode'])?$_POST['wp-piwik_mode']:'http'));
|
1167 |
+
self::$settings->setGlobalOption('piwik_useragent', (isset($_POST['wp-piwik_useragent'])?$_POST['wp-piwik_useragent']:'php'));
|
1168 |
+
self::$settings->setGlobalOption('connection_timeout', (isset($_POST['wp-piwik_timeout'])?(int)$_POST['wp-piwik_timeout']:5));
|
1169 |
+
self::$settings->setGlobalOption('piwik_useragent_string', (isset($_POST['wp-piwik_useragent_string'])?$_POST['wp-piwik_useragent_string']:'WP-Piwik'));
|
1170 |
+
self::$settings->setGlobalOption('disable_ssl_verify', (isset($_POST['wp-piwik_disable_ssl_verify'])?$_POST['wp-piwik_disable_ssl_verify']:false));
|
1171 |
if (!is_plugin_active_for_network('wp-piwik/wp-piwik.php')) {
|
1172 |
+
self::$settings->setGlobalOption('auto_site_config', (isset($_POST['wp-piwik_auto_site_config'])?$_POST['wp-piwik_auto_site_config']:false));
|
1173 |
+
if (!self::$settings->getGlobalOption('auto_site_config'))
|
1174 |
+
self::$settings->setOption('site_id', (isset($_POST['wp-piwik_siteid'])?$_POST['wp-piwik_siteid']:self::$settings->getOption('site_id')));
|
1175 |
+
} else self::$settings->setGlobalOption('auto_site_config', true);
|
1176 |
break;
|
1177 |
}
|
1178 |
+
if (self::$settings->getGlobalOption('auto_site_config') && self::isConfigured()) {
|
1179 |
+
if (self::$settings->getGlobalOption('piwik_mode') == 'php' && !defined('PIWIK_INCLUDE_PATH'))
|
1180 |
self::definePiwikConstants();
|
1181 |
$aryReturn = $this->addPiwikSite();
|
1182 |
+
self::$settings->getOption('tracking_code', $aryReturn['js']);
|
1183 |
+
self::$settings->getOption('site_id', $aryReturn['id']);
|
1184 |
}
|
1185 |
+
self::$settings->setGlobalOption('last_settings_update', time());
|
1186 |
}
|
1187 |
|
1188 |
/**
|
1206 |
if (isset($_POST['wp-piwik_settings_submit']) && $_POST['wp-piwik_settings_submit'] == 'Y')
|
1207 |
echo '<div id="message" class="updated fade"><p>'.__('Changes saved','wp-piwik').'</p></div>';
|
1208 |
// Show settings page title
|
1209 |
+
echo '<div class="wrap"><h2>'.self::$settings->getGlobalOption('plugin_display_name').' '.__('Settings', 'wp-piwik').'</h2>';
|
1210 |
// Show tabs
|
1211 |
$strTab = $this->showSettingsTabs(self::isConfigured(), $strTab);
|
1212 |
if ($strTab != 'sitebrowser') {
|
1291 |
private static function loadTestscript() {
|
1292 |
require_once('debug/testscript.php');
|
1293 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1294 |
|
1295 |
/**
|
1296 |
* Get a blog's piwik ID
|
1297 |
*/
|
1298 |
public static function getSiteID($intBlogID = null) {
|
1299 |
+
$intResult = self::$settings->getOption('site_id');
|
1300 |
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php') && !empty($intBlogID)) {
|
1301 |
$aryResult = get_blog_option($intBlogID, 'wp-piwik_settings');
|
1302 |
$intResult = $aryResult['site_id'];
|
1303 |
+
}
|
1304 |
return (is_int($intResult)?$intResult:'n/a');
|
1305 |
}
|
1306 |
|
1309 |
*/
|
1310 |
public static function isConfigured() {
|
1311 |
return (
|
1312 |
+
self::$settings->getGlobalOption('piwik_token')
|
1313 |
&& (
|
1314 |
(
|
1315 |
+
(self::$settings->getGlobalOption('piwik_mode') == 'http') && (self::$settings->getGlobalOption('piwik_url'))
|
1316 |
) || (
|
1317 |
+
(self::$settings->getGlobalOption('piwik_mode') == 'php') && (self::$settings->getGlobalOption('piwik_path'))
|
1318 |
)
|
1319 |
)
|
1320 |
);
|
1324 |
* Set Piwik PHP API constants
|
1325 |
*/
|
1326 |
private static function definePiwikConstants() {
|
1327 |
+
define('PIWIK_INCLUDE_PATH', self::$settings->getGlobalOption('piwik_path'));
|
1328 |
+
define('PIWIK_USER_PATH', self::$settings->getGlobalOption('piwik_path'));
|
1329 |
define('PIWIK_ENABLE_DISPATCH', false);
|
1330 |
define('PIWIK_ENABLE_ERROR_HANDLER', false);
|
1331 |
define('PIWIK_ENABLE_SESSION_START', false);
|
1332 |
+
}
|
1333 |
+
|
1334 |
+
private function openLogger() {
|
1335 |
+
switch (WP_PIWIK_ACTIVATE_LOGGER) {
|
1336 |
+
case 2:
|
1337 |
+
require_once('classes/WP_Piwik_Logger_File.php');
|
1338 |
+
self::$logger = new WP_Piwik_Logger_File(__CLASS__);
|
1339 |
+
break;
|
1340 |
+
default:
|
1341 |
+
require_once('classes/WP_Piwik_Logger_Dummy.php');
|
1342 |
+
self::$logger = new WP_Piwik_Logger_Dummy(__CLASS__);
|
1343 |
+
}
|
1344 |
+
}
|
1345 |
+
|
1346 |
+
private function closeLogger() {
|
1347 |
+
self::$logger = null;
|
1348 |
+
}
|
1349 |
+
|
1350 |
+
private function openSettings() {
|
1351 |
+
$this->includeFile('classes/WP_Piwik_Settings');
|
1352 |
+
self::$settings = new WP_Piwik_Settings(self::$logger);
|
1353 |
+
}
|
1354 |
+
|
1355 |
}
|
1356 |
|
1357 |
+
require_once('config.php');
|
1358 |
+
|
1359 |
if (class_exists('wp_piwik'))
|
1360 |
$GLOBALS['wp_piwik'] = new wp_piwik();
|
1361 |
|