WP-Matomo (WP-Piwik) - Version 1.0.27

Version Description

  • Fix a CSRF vulnerability
  • Fix JavaScript typos on settings page which broke some interface functionality
  • Fix proxy path on multisite networks (thanks to caveman99, details)
  • Fix array key warnings (thanks to goaround, details)
  • Fixed a bug in proxy config.php to avoid adding the protocol twice to the Matomo URL
  • Proxy script will run proxy/config.local.php before proxy/config.php to set an individual WordPress root directory via $wpRootDir
Download this release

Release Info

Developer Braekling
Plugin Icon 128x128 WP-Matomo (WP-Piwik)
Version 1.0.27
Comparing to
See all releases

Code changes from version 1.0.26 to 1.0.27

.gitignore DELETED
@@ -1,2 +0,0 @@
1
-
2
- .idea/
 
 
classes/WP_Piwik.php CHANGED
@@ -10,7 +10,7 @@ use WP_Piwik\Widget\Post;
10
  */
11
  class WP_Piwik {
12
 
13
- private static $revisionId = 2021082201, $version = '1.0.26', $blog_id, $pluginBasename = NULL, $logger, $settings, $request, $optionsPageId;
14
 
15
  /**
16
  * Constructor class to configure and register all WP-Piwik components
10
  */
11
  class WP_Piwik {
12
 
13
+ private static $revisionId = 2022020701, $version = '1.0.27', $blog_id, $pluginBasename = NULL, $logger, $settings, $request, $optionsPageId;
14
 
15
  /**
16
  * Constructor class to configure and register all WP-Piwik components
classes/WP_Piwik/Admin/Settings.php CHANGED
@@ -18,7 +18,7 @@ class Settings extends \WP_Piwik\Admin {
18
  new \WP_Piwik\Admin\Sitebrowser(self::$wpPiwik);
19
  return;
20
  }
21
- if (isset($_GET['clear']) && $_GET['clear']) {
22
  $this->clear($_GET['clear'] == 2);
23
  self::$wpPiwik->resetRequest();
24
  echo '<form method="post" action="?page='.htmlentities($_GET['page']).'"><input type="submit" value="'.__('Reload', 'wp-piwik').'" /></form>';
@@ -224,7 +224,7 @@ class Settings extends \WP_Piwik\Admin {
224
  'js' => __ ( 'Use js/index.php', 'wp-piwik' ),
225
  'proxy' => __ ( 'Use proxy script', 'wp-piwik' ),
226
  'manually' => __ ( 'Enter manually', 'wp-piwik' )
227
- ), $description, 'jQuery(\'tr.wp-piwik-track-option\').addClass(\'hidden\'); jQUery(\'tr.wp-piwik-track-option-\' + jQUery(\'#track_mode\').val()).removeClass(\'hidden\'); jQUery(\'#tracking_code, #noscript_code\').prop(\'readonly\', jQUery(\'#track_mode\').val() != \'manually\');' );
228
 
229
  $this->showTextarea ( 'tracking_code', __ ( 'Tracking code', 'wp-piwik' ), 15, 'This is a preview of your current tracking code. If you choose to enter your tracking code manually, you can change it here.', $isNotTracking, 'wp-piwik-track-option wp-piwik-track-option-default wp-piwik-track-option-js wp-piwik-track-option-proxy wp-piwik-track-option-manually', true, '', (self::$settings->getGlobalOption ( 'track_mode' ) != 'manually'), false );
230
 
@@ -254,7 +254,7 @@ class Settings extends \WP_Piwik\Admin {
254
  $filter = self::$settings->getGlobalOption ( 'add_post_annotations' );
255
  foreach ( get_post_types(array(), 'objects') as $post_type )
256
  echo '<input type="checkbox" ' . (isset ( $filter [$post_type->name] ) && $filter [$post_type->name] ? 'checked="checked" ' : '') . 'value="1" name="wp-piwik[add_post_annotations][' . $post_type->name . ']" /> ' . $post_type->label . ' &nbsp; ';
257
- echo '<span class="dashicons dashicons-editor-help" onclick="jQUery(\'#add_post_annotations-desc\').toggleClass(\'hidden\');"></span> <p class="description hidden" id="add_post_annotations-desc">' . sprintf ( __ ( 'See %sMatomo documentation%s.', 'wp-piwik' ), '<a href="http://piwik.org/docs/annotations/" target="_BLANK">', '</a>' ) . '</p></td></tr>';
258
 
259
  $this->showCheckbox ( 'add_customvars_box', __ ( 'Show custom variables box', 'wp-piwik' ), __ ( ' Show a &quot;custom variables&quot; edit box on post edit page.', 'wp-piwik' ) . ' ' . sprintf ( __ ( 'See %sMatomo documentation%s.', 'wp-piwik' ), '<a href="http://piwik.org/docs/custom-variables/" target="_BLANK">', '</a>' ), $isNotGeneratedTracking, $fullGeneratedTrackingGroup . ' wp-piwik-track-option-manually' );
260
 
@@ -612,8 +612,8 @@ class Settings extends \WP_Piwik\Admin {
612
  <ol>
613
  <li><a href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&testscript=1' ); ?>"><?php _e('Run testscript', 'wp-piwik'); ?></a></li>
614
  <li><a href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&sitebrowser=1' ); ?>"><?php _e('Sitebrowser', 'wp-piwik'); ?></a></li>
615
- <li><a href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&clear=1' ); ?>"><?php _e('Clear cache', 'wp-piwik'); ?></a></li>
616
- <li><a onclick="return confirm('<?php _e('Are you sure you want to clear all settings?', 'wp-piwik'); ?>')" href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&clear=2' ); ?>"><?php _e('Reset WP-Matomo', 'wp-piwik'); ?></a></li>
617
  </ol>
618
  <h3><?php _e('Latest support threads on WordPress.org', 'wp-piwik'); ?></h3><?php
619
  $supportThreads = $this->readRSSFeed('http://wordpress.org/support/rss/plugin/wp-piwik');
18
  new \WP_Piwik\Admin\Sitebrowser(self::$wpPiwik);
19
  return;
20
  }
21
+ if (isset($_GET['clear']) && $_GET['clear'] && check_admin_referer()) {
22
  $this->clear($_GET['clear'] == 2);
23
  self::$wpPiwik->resetRequest();
24
  echo '<form method="post" action="?page='.htmlentities($_GET['page']).'"><input type="submit" value="'.__('Reload', 'wp-piwik').'" /></form>';
224
  'js' => __ ( 'Use js/index.php', 'wp-piwik' ),
225
  'proxy' => __ ( 'Use proxy script', 'wp-piwik' ),
226
  'manually' => __ ( 'Enter manually', 'wp-piwik' )
227
+ ), $description, 'jQuery(\'tr.wp-piwik-track-option\').addClass(\'hidden\'); jQuery(\'tr.wp-piwik-track-option-\' + jQuery(\'#track_mode\').val()).removeClass(\'hidden\'); jQuery(\'#tracking_code, #noscript_code\').prop(\'readonly\', jQuery(\'#track_mode\').val() != \'manually\');' );
228
 
229
  $this->showTextarea ( 'tracking_code', __ ( 'Tracking code', 'wp-piwik' ), 15, 'This is a preview of your current tracking code. If you choose to enter your tracking code manually, you can change it here.', $isNotTracking, 'wp-piwik-track-option wp-piwik-track-option-default wp-piwik-track-option-js wp-piwik-track-option-proxy wp-piwik-track-option-manually', true, '', (self::$settings->getGlobalOption ( 'track_mode' ) != 'manually'), false );
230
 
254
  $filter = self::$settings->getGlobalOption ( 'add_post_annotations' );
255
  foreach ( get_post_types(array(), 'objects') as $post_type )
256
  echo '<input type="checkbox" ' . (isset ( $filter [$post_type->name] ) && $filter [$post_type->name] ? 'checked="checked" ' : '') . 'value="1" name="wp-piwik[add_post_annotations][' . $post_type->name . ']" /> ' . $post_type->label . ' &nbsp; ';
257
+ echo '<span class="dashicons dashicons-editor-help" onclick="jQuery(\'#add_post_annotations-desc\').toggleClass(\'hidden\');"></span> <p class="description hidden" id="add_post_annotations-desc">' . sprintf ( __ ( 'See %sMatomo documentation%s.', 'wp-piwik' ), '<a href="http://piwik.org/docs/annotations/" target="_BLANK">', '</a>' ) . '</p></td></tr>';
258
 
259
  $this->showCheckbox ( 'add_customvars_box', __ ( 'Show custom variables box', 'wp-piwik' ), __ ( ' Show a &quot;custom variables&quot; edit box on post edit page.', 'wp-piwik' ) . ' ' . sprintf ( __ ( 'See %sMatomo documentation%s.', 'wp-piwik' ), '<a href="http://piwik.org/docs/custom-variables/" target="_BLANK">', '</a>' ), $isNotGeneratedTracking, $fullGeneratedTrackingGroup . ' wp-piwik-track-option-manually' );
260
 
612
  <ol>
613
  <li><a href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&testscript=1' ); ?>"><?php _e('Run testscript', 'wp-piwik'); ?></a></li>
614
  <li><a href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&sitebrowser=1' ); ?>"><?php _e('Sitebrowser', 'wp-piwik'); ?></a></li>
615
+ <li><a href="<?php echo wp_nonce_url( admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&clear=1' ) ); ?>"><?php _e('Clear cache', 'wp-piwik'); ?></a></li>
616
+ <li><a onclick="return confirm('<?php _e('Are you sure you want to clear all settings?', 'wp-piwik'); ?>')" href="<?php echo wp_nonce_url( admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&clear=2' ) ); ?>"><?php _e('Reset WP-Matomo', 'wp-piwik'); ?></a></li>
617
  </ol>
618
  <h3><?php _e('Latest support threads on WordPress.org', 'wp-piwik'); ?></h3><?php
619
  $supportThreads = $this->readRSSFeed('http://wordpress.org/support/rss/plugin/wp-piwik');
classes/WP_Piwik/Widget/Post.php CHANGED
@@ -41,9 +41,9 @@
41
  }
42
  }
43
  if (isset($result['nb_visits']) && $result['nb_visits'] > 0) {
44
- $result['nb_actions_per_visit'] = round($result['nb_actions'] / $result['nb_visits'], 1);
45
- $result['bounce_rate'] = round($result['bounce_count'] / $result['nb_visits'] * 100, 1) . '%';
46
- $result['avg_time_on_site'] = round($result['sum_visit_length'] / $result['nb_visits'], 0);
47
  } else $result['nb_actions_per_visit'] = $result['bounce_rate'] = $result['avg_time_on_site'] = 0;
48
  }
49
  $response = $result;
@@ -79,4 +79,4 @@
79
  }
80
  }
81
 
82
- }
41
  }
42
  }
43
  if (isset($result['nb_visits']) && $result['nb_visits'] > 0) {
44
+ $result['nb_actions_per_visit'] = round((isset( $result['nb_actions'] ) ? $result['nb_actions'] : 0) / $result['nb_visits'], 1);
45
+ $result['bounce_rate'] = round((isset($result['bounce_count']) ? $result['bounce_count'] : 0) / $result['nb_visits'] * 100, 1) . '%';
46
+ $result['avg_time_on_site'] = round((isset($result['sum_visit_length']) ? $result['sum_visit_length'] : 0) / $result['nb_visits'], 0);
47
  } else $result['nb_actions_per_visit'] = $result['bounce_rate'] = $result['avg_time_on_site'] = 0;
48
  }
49
  $response = $result;
79
  }
80
  }
81
 
82
+ }
proxy/config.php CHANGED
@@ -13,7 +13,7 @@ $protocol = (isset ( $_SERVER ['HTTPS'] ) && $_SERVER ['HTTPS'] != 'off') ? 'htt
13
 
14
  switch ($settings->getGlobalOption ( 'piwik_mode' )) {
15
  case 'php' :
16
- $PIWIK_URL = $protocol . ':' . $settings->getGlobalOption ( 'proxy_url' );
17
  break;
18
  case 'cloud' :
19
  $PIWIK_URL = 'https://' . $settings->getGlobalOption ( 'piwik_user' ) . '.innocraft.cloud/';
@@ -26,7 +26,7 @@ switch ($settings->getGlobalOption ( 'piwik_mode' )) {
26
  }
27
 
28
  if (substr ( $PIWIK_URL, 0, 2 ) == '//')
29
- $PIWIK_URL = (isset ( $_SERVER ['HTTPS'] ) ? 'https:' : 'http:') . $PIWIK_URL;
30
 
31
  $TOKEN_AUTH = $settings->getGlobalOption ( 'piwik_token' );
32
  $timeout = $settings->getGlobalOption ( 'connection_timeout' );
13
 
14
  switch ($settings->getGlobalOption ( 'piwik_mode' )) {
15
  case 'php' :
16
+ $PIWIK_URL = $settings->getGlobalOption ( 'proxy_url' );
17
  break;
18
  case 'cloud' :
19
  $PIWIK_URL = 'https://' . $settings->getGlobalOption ( 'piwik_user' ) . '.innocraft.cloud/';
26
  }
27
 
28
  if (substr ( $PIWIK_URL, 0, 2 ) == '//')
29
+ $PIWIK_URL = $protocol . ':' . $PIWIK_URL;
30
 
31
  $TOKEN_AUTH = $settings->getGlobalOption ( 'piwik_token' );
32
  $timeout = $settings->getGlobalOption ( 'connection_timeout' );
proxy/proxy.php CHANGED
@@ -17,10 +17,20 @@ $DEBUG_PROXY = false;
17
  // set to true if the target matomo server has a ssl certificate that will fail verification, like when testing.
18
  $NO_VERIFY_SSL = false;
19
 
 
 
 
 
 
 
 
20
  if (file_exists(__DIR__ . '/config.php')) {
21
  include __DIR__ . '/config.php';
22
  }
23
 
 
 
 
24
  // -----
25
  // Important: read the instructions in README.md or at:
26
  // https://github.com/matomo-org/tracker-proxy#matomo-tracker-proxy
@@ -366,4 +376,4 @@ function arrayValue($array, $key, $value = null)
366
  $value = $array[$key];
367
  }
368
  return $value;
369
- }
17
  // set to true if the target matomo server has a ssl certificate that will fail verification, like when testing.
18
  $NO_VERIFY_SSL = false;
19
 
20
+ if (file_exists(__DIR__ . '/config.local.php')) {
21
+ include __DIR__ . '/config.local.php';
22
+ }
23
+
24
+ // Config calls wp-load.php which on multisite networks redeclares and messes up $path
25
+ $wp_matomo_proxy_path=$path;
26
+
27
  if (file_exists(__DIR__ . '/config.php')) {
28
  include __DIR__ . '/config.php';
29
  }
30
 
31
+ // Restore $path
32
+ $path=$wp_matomo_proxy_path;
33
+
34
  // -----
35
  // Important: read the instructions in README.md or at:
36
  // https://github.com/matomo-org/tracker-proxy#matomo-tracker-proxy
376
  $value = $array[$key];
377
  }
378
  return $value;
379
+ }
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
 
3
  Contributors: Braekling
4
  Requires at least: 5.0
5
- Tested up to: 5.8
6
- Stable tag: 1.0.26
7
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
8
  Tags: matomo, tracking, statistics, stats, analytics
9
 
@@ -143,6 +143,14 @@ Add WP-Matomo to your /wp-content/plugins folder and enable it as [Network Plugi
143
 
144
  == Changelog ==
145
 
 
 
 
 
 
 
 
 
146
  = 1.0.26 =
147
  * Fix feed tracking via proxy script (thanks to nicobilliotte, [details](https://github.com/braekling/WP-Matomo/pull/92))
148
  * Add piwik.php proxy script wrapper to make sure proxy tracking codes continue working if piwik.php is used
2
 
3
  Contributors: Braekling
4
  Requires at least: 5.0
5
+ Tested up to: 5.9
6
+ Stable tag: 1.0.27
7
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
8
  Tags: matomo, tracking, statistics, stats, analytics
9
 
143
 
144
  == Changelog ==
145
 
146
+ = 1.0.27 =
147
+ * Fix a CSRF vulnerability
148
+ * Fix JavaScript typos on settings page which broke some interface functionality
149
+ * Fix proxy path on multisite networks (thanks to caveman99, [details](https://github.com/braekling/WP-Matomo/pull/98))
150
+ * Fix array key warnings (thanks to goaround, [details](https://github.com/braekling/WP-Matomo/pull/102))
151
+ * Fixed a bug in proxy config.php to avoid adding the protocol twice to the Matomo URL
152
+ * Proxy script will run proxy/config.local.php before proxy/config.php to set an individual WordPress root directory via $wpRootDir
153
+
154
  = 1.0.26 =
155
  * Fix feed tracking via proxy script (thanks to nicobilliotte, [details](https://github.com/braekling/WP-Matomo/pull/92))
156
  * Add piwik.php proxy script wrapper to make sure proxy tracking codes continue working if piwik.php is used
wp-piwik.php CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://wordpress.org/extend/plugins/wp-piwik/
6
 
7
  Description: Adds Matomo statistics to your WordPress dashboard and is also able to add the Matomo Tracking Code to your blog.
8
 
9
- Version: 1.0.26
10
  Author: Andr&eacute; Br&auml;kling
11
  Author URI: https://www.braekling.de
12
  Text Domain: wp-piwik
6
 
7
  Description: Adds Matomo statistics to your WordPress dashboard and is also able to add the Matomo Tracking Code to your blog.
8
 
9
+ Version: 1.0.27
10
  Author: Andr&eacute; Br&auml;kling
11
  Author URI: https://www.braekling.de
12
  Text Domain: wp-piwik