WP-Matomo (WP-Piwik) - Version 1.0.15

Version Description

  • Allow to modify the tracked user ID using the filter "wp-piwik_tracking_user_id"
  • Bugfix: Output of "post" shortcode was incorrectly placed, see https://wordpress.org/support/topic/post-shortcode-values-are-incorrectly-placed/
  • Bugfix: Usage of WP_PROXY_BYPASS_HOSTS, see https://wordpress.org/support/topic/bug-considering-wp_proxy_bypass_hosts-in-proxy-setups/
  • Bugfix: Proxy script did not work with cURL, see https://github.com/braekling/WP-Piwik/issues/48
  • Bugfix: RSS feed tracking did not use proxy URL
Download this release

Release Info

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

Code changes from version 1.0.14 to 1.0.15

.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
1
+
2
+ .idea/
classes/WP_Piwik.php CHANGED
@@ -12,7 +12,7 @@ class WP_Piwik {
12
  *
13
  * @var Runtime environment variables
14
  */
15
- private static $revisionId = 2016120301, $version = '1.0.14', $blog_id, $pluginBasename = NULL, $logger, $settings, $request, $optionsPageId;
16
 
17
  /**
18
  * Constructor class to configure and register all WP-Piwik components
@@ -166,11 +166,18 @@ class WP_Piwik {
166
  'addFeedTracking'
167
  ) );
168
  }
169
- if ($this->isAddFeedCampaign ())
170
  add_filter ( 'post_link', array (
171
  $this,
172
  'addFeedCampaign'
173
  ) );
 
 
 
 
 
 
 
174
  }
175
  }
176
 
@@ -530,11 +537,15 @@ class WP_Piwik {
530
  $title = the_title ( null, null, false );
531
  $posturl = get_permalink ( $post->ID );
532
  $urlref = get_bloginfo ( 'rss2_url' );
533
- $url = self::$settings->getGlobalOption ( 'piwik_url' );
534
- if (substr ( $url, - 10, 10 ) == '/index.php')
535
- $url = str_replace ( '/index.php', '/piwik.php', $url );
536
- else
537
- $url .= 'piwik.php';
 
 
 
 
538
  $trackingImage = $url . '?idsite=' . self::$settings->getOption ( 'site_id' ) . '&rec=1&url=' . urlencode ( $posturl ) . '&action_name=' . urlencode ( $title ) . '&urlref=' . urlencode ( $urlref );
539
  $content .= '<img src="' . $trackingImage . '" style="border:0;width:0;height:0" width="0" height="0" alt="" />';
540
  }
@@ -558,6 +569,27 @@ class WP_Piwik {
558
  return $permalink;
559
  }
560
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
561
  /**
562
  * Apply settings update
563
  *
@@ -699,6 +731,15 @@ class WP_Piwik {
699
  return self::$settings->getGlobalOption ( 'track_feed_addcampaign' );
700
  }
701
 
 
 
 
 
 
 
 
 
 
702
  /**
703
  * Check if WP-Piwik shortcodes are enabled
704
  *
@@ -1097,7 +1138,8 @@ class WP_Piwik {
1097
  'idSite' => $siteId,
1098
  'mergeSubdomains' => self::$settings->getGlobalOption ( 'track_across' ) ? 1 : 0,
1099
  'mergeAliasUrls' => self::$settings->getGlobalOption ( 'track_across_alias' ) ? 1 : 0,
1100
- 'disableCookies' => self::$settings->getGlobalOption ( 'disable_cookies' ) ? 1 : 0
 
1101
  ) );
1102
  $code = $this->request ( $id );
1103
  if (is_array($code) && isset($code['value']))
12
  *
13
  * @var Runtime environment variables
14
  */
15
+ private static $revisionId = 2017041901, $version = '1.0.15', $blog_id, $pluginBasename = NULL, $logger, $settings, $request, $optionsPageId;
16
 
17
  /**
18
  * Constructor class to configure and register all WP-Piwik components
166
  'addFeedTracking'
167
  ) );
168
  }
169
+ if ($this->isAddFeedCampaign ()) {
170
  add_filter ( 'post_link', array (
171
  $this,
172
  'addFeedCampaign'
173
  ) );
174
+ }
175
+ if ($this->isCrossDomainLinkingEnabled ()) {
176
+ add_filter ( 'wp_redirect', array (
177
+ $this,
178
+ 'forwardCrossDomainVisitorId'
179
+ ) );
180
+ }
181
  }
182
  }
183
 
537
  $title = the_title ( null, null, false );
538
  $posturl = get_permalink ( $post->ID );
539
  $urlref = get_bloginfo ( 'rss2_url' );
540
+ if (self::$settings->getGlobalOption ( 'track_mode' ) == 'proxy')
541
+ $url = plugins_url ( 'wp-piwik' ) . '/proxy/piwik.php';
542
+ else {
543
+ $url = self::$settings->getGlobalOption ( 'piwik_url' );
544
+ if (substr($url, -10, 10) == '/index.php')
545
+ $url = str_replace('/index.php', '/piwik.php', $url);
546
+ else
547
+ $url .= 'piwik.php';
548
+ }
549
  $trackingImage = $url . '?idsite=' . self::$settings->getOption ( 'site_id' ) . '&amp;rec=1&amp;url=' . urlencode ( $posturl ) . '&amp;action_name=' . urlencode ( $title ) . '&amp;urlref=' . urlencode ( $urlref );
550
  $content .= '<img src="' . $trackingImage . '" style="border:0;width:0;height:0" width="0" height="0" alt="" />';
551
  }
569
  return $permalink;
570
  }
571
 
572
+ /**
573
+ * Forwards the cross domain parameter pk_vid if the URL parameter is set and a user is about to be redirected.
574
+ * When another website links to WooCommerce with a pk_vid parameter, and WooCommerce redirects the user to another
575
+ * URL, the pk_vid parameter would get lost and the visitorId would later not be applied by the tracking code
576
+ * due to the lost pk_vid URL parameter. If the URL parameter is set, we make sure to forward this parameter.
577
+ *
578
+ * @param string $location
579
+ *
580
+ * @return string location extended by pk_vid URL parameter if the URL parameter is set
581
+ */
582
+ public function forwardCrossDomainVisitorId($location) {
583
+
584
+ if (!empty($_GET['pk_vid'])
585
+ && preg_match('/^[a-zA-Z0-9]{24,48}$/', $_GET['pk_vid'])) {
586
+ // currently, the pk_vid parameter is 32 characters long, but it may vary over time.
587
+ $location = add_query_arg( 'pk_vid', $_GET['pk_vid'], $location );
588
+ }
589
+
590
+ return $location;
591
+ }
592
+
593
  /**
594
  * Apply settings update
595
  *
731
  return self::$settings->getGlobalOption ( 'track_feed_addcampaign' );
732
  }
733
 
734
+ /**
735
+ * Check if feed permalinks get a campaign parameter
736
+ *
737
+ * @return boolean Add campaign parameter to feed permalinks?
738
+ */
739
+ private function isCrossDomainLinkingEnabled() {
740
+ return self::$settings->getGlobalOption ( 'track_crossdomain_linking' );
741
+ }
742
+
743
  /**
744
  * Check if WP-Piwik shortcodes are enabled
745
  *
1138
  'idSite' => $siteId,
1139
  'mergeSubdomains' => self::$settings->getGlobalOption ( 'track_across' ) ? 1 : 0,
1140
  'mergeAliasUrls' => self::$settings->getGlobalOption ( 'track_across_alias' ) ? 1 : 0,
1141
+ 'disableCookies' => self::$settings->getGlobalOption ( 'disable_cookies' ) ? 1 : 0,
1142
+ 'crossDomain' => self::$settings->getGlobalOption ( 'track_crossdomain_linking' ) ? 1 : 0
1143
  ) );
1144
  $code = $this->request ( $id );
1145
  if (is_array($code) && isset($code['value']))
classes/WP_Piwik/Admin/Settings.php CHANGED
@@ -263,6 +263,8 @@ class Settings extends \WP_Piwik\Admin {
263
 
264
  $this->showCheckbox ( 'track_across_alias', __ ( 'Do not count subdomains as outlink', 'wp-piwik' ), __ ( 'Adds *.-prefix to tracked domain.', 'wp-piwik' ) . ' ' . sprintf ( __ ( 'See %sPiwik documentation%s.', 'wp-piwik' ), '<a href="https://developer.piwik.org/guides/tracking-javascript-guide#outlink-tracking-exclusions">', '</a>' ), $isNotGeneratedTracking, $fullGeneratedTrackingGroup );
265
 
 
 
266
  $this->showCheckbox ( 'track_feed', __ ( 'Track RSS feeds', 'wp-piwik' ), __ ( 'Enable to track posts in feeds via tracking pixel.', 'wp-piwik' ), $isNotTracking, $fullGeneratedTrackingGroup . ' wp-piwik-track-option-manually' );
267
 
268
  $this->showCheckbox ( 'track_feed_addcampaign', __ ( 'Track RSS feed links as campaign', 'wp-piwik' ), __ ( 'This will add Piwik campaign parameters to the RSS feed links.' . ' ' . sprintf ( __ ( 'See %sPiwik documentation%s.', 'wp-piwik' ), '<a href="http://piwik.org/docs/tracking-campaigns/">', '</a>' ), 'wp-piwik' ), $isNotTracking, $fullGeneratedTrackingGroup . ' wp-piwik-track-option-manually', true, '$j(\'tr.wp-piwik-feed_campaign-option\').toggle(\'hidden\');' );
@@ -494,20 +496,8 @@ class Settings extends \WP_Piwik\Admin {
494
  <p>
495
  <?php _e('If you like WP-Piwik, you can support its development by a donation:', 'wp-piwik'); ?>
496
  </p>
497
- <script type="text/javascript">
498
- /* <![CDATA[ */
499
- window.onload = function() {
500
- FlattrLoader.render({
501
- 'uid': 'flattr',
502
- 'url': 'http://wp.local',
503
- 'title': 'Title of the thing',
504
- 'description': 'Description of the thing'
505
- }, 'element_id', 'replace');
506
- }
507
- /* ]]> */
508
- </script>
509
  <div>
510
- <a class="FlattrButton" style="display:none;" title="WordPress Plugin WP-Piwik" rel="flattr;uid:braekling;category:software;tags:wordpress,piwik,plugin,statistics;" href="https://www.braekling.de/wp-piwik-wpmu-piwik-wordpress">This WordPress plugin adds a Piwik stats site to your WordPress dashboard. It's also able to add the Piwik tracking code to your blog using wp_footer. You need a running Piwik installation and at least view access to your stats.</a>
511
  </div>
512
  <div>
513
  Paypal
@@ -547,7 +537,6 @@ class Settings extends \WP_Piwik\Admin {
547
  */
548
  public function extendAdminHeader() {
549
  echo '<script type="text/javascript">var $j = jQuery.noConflict();</script>';
550
- echo '<script type="text/javascript">/* <![CDATA[ */(function() {var s = document.createElement(\'script\');var t = document.getElementsByTagName(\'script\')[0];s.type = \'text/javascript\';s.async = true;s.src = \'//api.flattr.com/js/0.6/load.js?mode=auto\';t.parentNode.insertBefore(s, t);})();/* ]]> */</script>';
551
  }
552
 
553
  /**
@@ -555,7 +544,7 @@ class Settings extends \WP_Piwik\Admin {
555
  */
556
  public function showCredits() {
557
  ?>
558
- <p><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., Oleg I., M. N., Daniel K., James L., Jochen K., Cyril P., Thomas K., Patrik K., Zach, Sebastian W., Peakkom, Patrik K., Kati K., Helmut O., Valerie S., Jochen D., Atlas R., <?php _e('the Piwik team itself','wp-piwik');?><?php _e(', and all people flattering this','wp-piwik'); ?>!</p>
559
  <p><?php _e('Graphs powered by <a href="http://www.jqplot.com/">jqPlot</a> (License: GPL 2.0 and MIT) and <a href="http://omnipotent.net/jquery.sparkline/">jQuery Sparklines</a> (License: New BSD License).','wp-piwik'); ?></p>
560
  <p><?php _e('Thank you very much','wp-piwik'); ?> <a href="https://www.transifex.com/projects/p/wp-piwik/">Transifex Translation Community</a> <?php _e('for your translation work','wp-piwik'); ?>!</p>
561
  <p><?php _e('Thank you very much, all users who send me mails containing criticism, commendation, feature requests and bug reports! You help me to make WP-Piwik much better.','wp-piwik'); ?></p>
263
 
264
  $this->showCheckbox ( 'track_across_alias', __ ( 'Do not count subdomains as outlink', 'wp-piwik' ), __ ( 'Adds *.-prefix to tracked domain.', 'wp-piwik' ) . ' ' . sprintf ( __ ( 'See %sPiwik documentation%s.', 'wp-piwik' ), '<a href="https://developer.piwik.org/guides/tracking-javascript-guide#outlink-tracking-exclusions">', '</a>' ), $isNotGeneratedTracking, $fullGeneratedTrackingGroup );
265
 
266
+ $this->showCheckbox ( 'track_crossdomain_linking', __ ( 'Enable cross domain linking', 'wp-piwik' ), __ ( 'When enabled, it will make sure to use the same visitor ID for the same visitor across several domains. This works only when this feature is enabled because the visitor ID is stored in a cookie and cannot be read on the other domain by default. When this feature is enabled, it will append a URL parameter "pk_vid" that contains the visitor ID when a user clicks on a URL that belongs to one of your domains. For this feature to work, you also have to configure which domains should be treated as local in your Piwik website settings. This feature requires Piwik 3.0.2.', 'wp-piwik' ), self::$settings->getGlobalOption ( 'track_mode' ) == 'proxy', 'wp-piwik-track-option wp-piwik-track-option-default wp-piwik-track-option-js wp-piwik-track-option-manually');
267
+
268
  $this->showCheckbox ( 'track_feed', __ ( 'Track RSS feeds', 'wp-piwik' ), __ ( 'Enable to track posts in feeds via tracking pixel.', 'wp-piwik' ), $isNotTracking, $fullGeneratedTrackingGroup . ' wp-piwik-track-option-manually' );
269
 
270
  $this->showCheckbox ( 'track_feed_addcampaign', __ ( 'Track RSS feed links as campaign', 'wp-piwik' ), __ ( 'This will add Piwik campaign parameters to the RSS feed links.' . ' ' . sprintf ( __ ( 'See %sPiwik documentation%s.', 'wp-piwik' ), '<a href="http://piwik.org/docs/tracking-campaigns/">', '</a>' ), 'wp-piwik' ), $isNotTracking, $fullGeneratedTrackingGroup . ' wp-piwik-track-option-manually', true, '$j(\'tr.wp-piwik-feed_campaign-option\').toggle(\'hidden\');' );
496
  <p>
497
  <?php _e('If you like WP-Piwik, you can support its development by a donation:', 'wp-piwik'); ?>
498
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
499
  <div>
500
+ <script id='fb0ahsp'>(function(i){var f,s=document.getElementById(i);f=document.createElement('iframe');f.src='//button.flattr.com/view/?fid=mkdp7z&url=https%3A%2F%2Fwww.braekling.de%2Fwp-piwik-wpmu-piwik-wordpress';f.title='Flattr';f.height=62;f.width=55;f.style.borderWidth=0;s.parentNode.insertBefore(f,s);})('fb0ahsp');</script>
501
  </div>
502
  <div>
503
  Paypal
537
  */
538
  public function extendAdminHeader() {
539
  echo '<script type="text/javascript">var $j = jQuery.noConflict();</script>';
 
540
  }
541
 
542
  /**
544
  */
545
  public function showCredits() {
546
  ?>
547
+ <p><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., Oleg I., M. N., Daniel K., James L., Jochen K., Cyril P., Thomas K., Patrik K., Zach, Sebastian W., Peakkom, Patrik K., Kati K., Helmut O., Valerie S., Jochen D., Atlas R., Harald W., Jan M., <?php _e('the Piwik team itself','wp-piwik');?><?php _e(', and all people flattering this','wp-piwik'); ?>!</p>
548
  <p><?php _e('Graphs powered by <a href="http://www.jqplot.com/">jqPlot</a> (License: GPL 2.0 and MIT) and <a href="http://omnipotent.net/jquery.sparkline/">jQuery Sparklines</a> (License: New BSD License).','wp-piwik'); ?></p>
549
  <p><?php _e('Thank you very much','wp-piwik'); ?> <a href="https://www.transifex.com/projects/p/wp-piwik/">Transifex Translation Community</a> <?php _e('for your translation work','wp-piwik'); ?>!</p>
550
  <p><?php _e('Thank you very much, all users who send me mails containing criticism, commendation, feature requests and bug reports! You help me to make WP-Piwik much better.','wp-piwik'); ?></p>
classes/WP_Piwik/Request/Rest.php CHANGED
@@ -37,7 +37,7 @@
37
  curl_setopt($c, CURLOPT_HEADER, $GLOBALS ['wp-piwik_debug'] );
38
  curl_setopt($c, CURLOPT_TIMEOUT, self::$settings->getGlobalOption('connection_timeout'));
39
  $httpProxyClass = new \WP_HTTP_Proxy();
40
- if ($httpProxyClass->is_enabled() && $httpProxyClass->send_through_proxy($strURL)) {
41
  curl_setopt($c, CURLOPT_PROXY, $httpProxyClass->host());
42
  curl_setopt($c, CURLOPT_PROXYPORT, $httpProxyClass->port());
43
  if ($httpProxyClass->use_authentication())
37
  curl_setopt($c, CURLOPT_HEADER, $GLOBALS ['wp-piwik_debug'] );
38
  curl_setopt($c, CURLOPT_TIMEOUT, self::$settings->getGlobalOption('connection_timeout'));
39
  $httpProxyClass = new \WP_HTTP_Proxy();
40
+ if ($httpProxyClass->is_enabled() && $httpProxyClass->send_through_proxy($url)) {
41
  curl_setopt($c, CURLOPT_PROXY, $httpProxyClass->host());
42
  curl_setopt($c, CURLOPT_PROXYPORT, $httpProxyClass->port());
43
  if ($httpProxyClass->use_authentication())
classes/WP_Piwik/Settings.php CHANGED
@@ -79,6 +79,7 @@ class Settings {
79
  'capability_stealth' => array (),
80
  'track_across' => false,
81
  'track_across_alias' => false,
 
82
  'track_feed' => false,
83
  'track_feed_addcampaign' => false,
84
  'track_feed_campaign' => 'feed',
79
  'capability_stealth' => array (),
80
  'track_across' => false,
81
  'track_across_alias' => false,
82
+ 'track_crossdomain_linking' => false,
83
  'track_feed' => false,
84
  'track_feed_addcampaign' => false,
85
  'track_feed_campaign' => 'feed',
classes/WP_Piwik/TrackingCode.php CHANGED
@@ -34,6 +34,9 @@ class TrackingCode {
34
  global $current_user;
35
  $logger->log ( 'Apply tracking code changes:' );
36
  $settings->setOption ( 'last_tracking_code_update', time () );
 
 
 
37
  if ($settings->getGlobalOption ( 'track_mode' ) == 'js')
38
  $code = str_replace ( array (
39
  'piwik.js',
@@ -48,9 +51,6 @@ class TrackingCode {
48
  $code = preg_replace ( '/var u="([^"]*)";/', 'var u="' . $proxy . '"', $code );
49
  $code = preg_replace ( '/img src="([^"]*)piwik.php/', 'img src="' . $proxy . 'piwik.php', $code );
50
  }
51
- if (preg_match ( '/var u="([^"]*)";/', $code, $hits )) {
52
- $fetchedProxyUrl = $hits [1];
53
- } else $fetchedProxyUrl = '';
54
  if ($settings->getGlobalOption ( 'track_cdnurl' ) || $settings->getGlobalOption ( 'track_cdnurlssl' ))
55
  $code = str_replace ( array (
56
  "var d=doc",
@@ -68,7 +68,6 @@ class TrackingCode {
68
  $code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['addDownloadExtensions', '" . ($settings->getGlobalOption ( 'add_download_extensions' )) . "']);\n_paq.push(['trackPageView']);", $code );
69
  if ($settings->getGlobalOption ( 'limit_cookies' ))
70
  $code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setVisitorCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_visitor' ) . "']);\n_paq.push(['setSessionCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_session' ) . "']);\n_paq.push(['setReferralCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_referral' ) . "']);\n_paq.push(['trackPageView']);", $code );
71
-
72
  if ($settings->getGlobalOption ( 'force_protocol' ) != 'disabled')
73
  $code = str_replace ( '"//', '"' . $settings->getGlobalOption ( 'force_protocol' ) . '://', $code );
74
  if ($settings->getGlobalOption ( 'track_content' ) == 'all')
@@ -113,6 +112,7 @@ class TrackingCode {
113
  }
114
 
115
  private function applyUserTracking() {
 
116
  if (\is_user_logged_in()) {
117
  // Get the User ID Admin option, and the current user's data
118
  $uidFrom = self::$wpPiwik->getGlobalOption ( 'track_user_id' );
@@ -127,10 +127,11 @@ class TrackingCode {
127
  } elseif ( $uidFrom == 'displayname' ) {
128
  $pkUserId = $current_user->display_name;
129
  }
130
- // Check we got a User ID to track, and track it
131
- if ( isset( $pkUserId ) && ! empty( $pkUserId ))
132
- $this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setUserId', '" . esc_js( $pkUserId ) . "']);\n_paq.push(['trackPageView']);", $this->trackingCode );
133
- }
 
134
  }
135
 
136
  private function addCustomValues() {
34
  global $current_user;
35
  $logger->log ( 'Apply tracking code changes:' );
36
  $settings->setOption ( 'last_tracking_code_update', time () );
37
+ if (preg_match ( '/var u="([^"]*)";/', $code, $hits )) {
38
+ $fetchedProxyUrl = $hits [1];
39
+ } else $fetchedProxyUrl = '';
40
  if ($settings->getGlobalOption ( 'track_mode' ) == 'js')
41
  $code = str_replace ( array (
42
  'piwik.js',
51
  $code = preg_replace ( '/var u="([^"]*)";/', 'var u="' . $proxy . '"', $code );
52
  $code = preg_replace ( '/img src="([^"]*)piwik.php/', 'img src="' . $proxy . 'piwik.php', $code );
53
  }
 
 
 
54
  if ($settings->getGlobalOption ( 'track_cdnurl' ) || $settings->getGlobalOption ( 'track_cdnurlssl' ))
55
  $code = str_replace ( array (
56
  "var d=doc",
68
  $code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['addDownloadExtensions', '" . ($settings->getGlobalOption ( 'add_download_extensions' )) . "']);\n_paq.push(['trackPageView']);", $code );
69
  if ($settings->getGlobalOption ( 'limit_cookies' ))
70
  $code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setVisitorCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_visitor' ) . "']);\n_paq.push(['setSessionCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_session' ) . "']);\n_paq.push(['setReferralCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_referral' ) . "']);\n_paq.push(['trackPageView']);", $code );
 
71
  if ($settings->getGlobalOption ( 'force_protocol' ) != 'disabled')
72
  $code = str_replace ( '"//', '"' . $settings->getGlobalOption ( 'force_protocol' ) . '://', $code );
73
  if ($settings->getGlobalOption ( 'track_content' ) == 'all')
112
  }
113
 
114
  private function applyUserTracking() {
115
+ $pkUserId = null;
116
  if (\is_user_logged_in()) {
117
  // Get the User ID Admin option, and the current user's data
118
  $uidFrom = self::$wpPiwik->getGlobalOption ( 'track_user_id' );
127
  } elseif ( $uidFrom == 'displayname' ) {
128
  $pkUserId = $current_user->display_name;
129
  }
130
+ }
131
+ $pkUserId = apply_filters('wp-piwik_tracking_user_id', $pkUserId);
132
+ // Check we got a User ID to track, and track it
133
+ if ( isset( $pkUserId ) && ! empty( $pkUserId ))
134
+ $this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setUserId', '" . esc_js( $pkUserId ) . "']);\n_paq.push(['trackPageView']);", $this->trackingCode );
135
  }
136
 
137
  private function addCustomValues() {
classes/WP_Piwik/Widget/Post.php CHANGED
@@ -27,7 +27,7 @@
27
  if (isset($response[0]))
28
  $response = $response[0];
29
  if ($this->parameter['key']) {
30
- echo isset($response[$this->parameter['key']])?$response[$this->parameter['key']]:'<em>not defined</em>';
31
  return;
32
  }
33
  $time = isset($response['entry_sum_visit_length'])?$this->timeFormat($response['entry_sum_visit_length']):'-';
27
  if (isset($response[0]))
28
  $response = $response[0];
29
  if ($this->parameter['key']) {
30
+ $this->out(isset($response[$this->parameter['key']])?$response[$this->parameter['key']]:'<em>not defined</em>');
31
  return;
32
  }
33
  $time = isset($response['entry_sum_visit_length'])?$this->timeFormat($response['entry_sum_visit_length']):'-';
proxy/piwik.php CHANGED
@@ -42,7 +42,7 @@ function arrayValue($array, $key, $value = null)
42
  }
43
  return $value;
44
  }
45
- function getContents($url, $options = false)
46
  {
47
  if (!$useCurl && ini_get('allow_url_fopen')) {
48
  $ctx = ($options?stream_context_create($options):NULL);
@@ -87,7 +87,7 @@ if (empty($_GET)) {
87
  } else {
88
  sendHeader('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
89
  sendHeader('Content-Type: application/javascript; charset=UTF-8');
90
- if ($piwikJs = getContents($PIWIK_URL . 'piwik.js')) {
91
  echo $piwikJs;
92
  } else {
93
  sendHeader($_SERVER['SERVER_PROTOCOL'] . '505 Internal server error');
@@ -109,10 +109,10 @@ $stream_options = array('http' => array(
109
  ));
110
  if (version_compare(PHP_VERSION, '5.3.0', '<')) {
111
  // PHP 5.2 breaks with the new 204 status code so we force returning the image every time
112
- echo getContents($url . '&send_image=1', $stream_options);
113
  } else {
114
  // PHP 5.3 and above
115
- $content = getContents($url, $stream_options);
116
  // Forward the HTTP response code
117
  if (!headers_sent() && isset($http_response_header[0])) {
118
  header($http_response_header[0]);
42
  }
43
  return $value;
44
  }
45
+ function getContents($useCurl, $url, $options = false)
46
  {
47
  if (!$useCurl && ini_get('allow_url_fopen')) {
48
  $ctx = ($options?stream_context_create($options):NULL);
87
  } else {
88
  sendHeader('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
89
  sendHeader('Content-Type: application/javascript; charset=UTF-8');
90
+ if ($piwikJs = getContents($useCurl, $PIWIK_URL . 'piwik.js')) {
91
  echo $piwikJs;
92
  } else {
93
  sendHeader($_SERVER['SERVER_PROTOCOL'] . '505 Internal server error');
109
  ));
110
  if (version_compare(PHP_VERSION, '5.3.0', '<')) {
111
  // PHP 5.2 breaks with the new 204 status code so we force returning the image every time
112
+ echo getContents($useCurl, $url . '&send_image=1', $stream_options);
113
  } else {
114
  // PHP 5.3 and above
115
+ $content = getContents($useCurl, $url, $stream_options);
116
  // Forward the HTTP response code
117
  if (!headers_sent() && isset($http_response_header[0])) {
118
  header($http_response_header[0]);
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
- === WP-Piwik ===
2
 
3
  Contributors: Braekling
4
  Requires at least: 4.0
5
- Tested up to: 4.7
6
- Stable tag: 1.0.14
7
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
8
  Tags: piwik, tracking, statistics, stats, analytics
9
 
@@ -11,16 +11,26 @@ This plugin adds a Piwik stats site to your WordPress or WordPress multisite das
11
 
12
  == Description ==
13
 
14
- This plugin adds a Piwik stats site to your WordPress dashboard. It's also able to add the Piwik tracking code to your blog.
15
 
16
  To use this plugin you will need your own Piwik instance. If you do not already have a Piwik setup, you have two simple options: use either [Self-hosted](http://piwik.org/) or [Cloud-hosted](http://piwik.org/hosting/).
17
 
18
- **Requirements:** PHP 5.4 (or higher)/PHP 7.0 (or higher), WordPress 4.0 (or higher), Piwik 2.16 (or higher)
19
 
20
  **Languages:** English, Albanian, Chinese, Dutch, French, German, Greek, Hungarian, Italian, Polish, Portuguese (Brazil). Partially supported: Azerbaijani, Belarusian, Hindi, Lithuanian, Luxembourgish, Norwegian, Persian, Romanian, Russian, Spanish, Swedish, Turkish, Ukrainian
21
 
22
  **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! ;-)
23
 
 
 
 
 
 
 
 
 
 
 
24
  = Shortcodes =
25
  You can use following shortcodes if activated:
26
 
@@ -30,46 +40,17 @@ Shows overview table like WP-Piwik's overview dashboard. See Piwik API documenta
30
  [wp-piwik module="opt-out" language="en" width="100%" height="200px"]
31
  Shows the Piwik opt-out Iframe. You can change the Iframe's language by the language attribute (e.g. de for German language) and its width and height using the corresponding attributes.
32
 
33
- [wp-piwik module="post" range="last30" key="sum_daily_nb_uniq_visitors"]
34
  Shows the chosen keys value related to the current post. You can define a range (format: lastN, previousN or YYYY-MM-DD,YYYY-MM-DD) and the desired value's key (e.g., sum_daily_nb_uniq_visitors, nb_visits or nb_hits - for details see Piwik's API method Actions.getPageUrl using a range).
35
 
36
- [wp-piwik]
37
  is equal to *[wp-piwik module="overview" title="" period="day" date="yesterday"]*.
38
 
39
- = Installation =
40
-
41
- * First, you have to set up a running Piwik instance. You can get Piwik [here](http://piwik.org/) and its documentation [here](http://piwik.org/docs/).
42
- * If you want to update your Piwik instance, you should set your WordPress blog to maintenance while the update process is running.
43
-
44
- *Install WP-Piwik on a simple WordPress blog*
45
-
46
- 1. Upload the full `wp-piwik` directory into your `wp-content/plugins` directory.
47
- 2. Activate the plugin through the 'Plugins' menu in WordPress.
48
- 3. Open the new 'Settings/WP-Piwik Settings' menu and follow the instructions to configure your Piwik connection. Save settings.
49
- 4. If you have view access to multiple site stats and did not enable "auto config", choose your blog and save settings again.
50
- 5. Look at 'Dashboard/WP-Piwik' to see your site stats.
51
-
52
- *Install WP-Piwik on a WordPress blog network (WPMU/WP multisite)*
53
-
54
- There are two differents methods to use WP-Piwik in a multisite environment:
55
- * As a Site Specific Plugin it behaves like a plugin installed on a simple WordPress blog. Each user can enable, configure and use WP-Piwik on his own. Users can even use their own Piwik instances (and accordingly they have to).
56
- * Using WP-Piwik as a Network Plugin equates to a central approach. A single Piwik instance is used and the site admin configures the plugin completely. Users are just allowed to see their own statistics, site admins can see each blog's stats.
57
-
58
- a) Site Specific Plugin
59
-
60
- Just add WP-Piwik to your /wp-content/plugins folder and enable the Plugins page for individual site administrators. Each user has to enable and configure WP-Piwik on his own if he want to use the plugin.
61
-
62
- b) Network Plugin
63
-
64
- The Network Plugin support is still experimental. Please test it on your own (e.g. using a local copy of your WP multisite) before you use it in an user context.
65
-
66
- Add WP-Piwik to your /wp-content/plugins folder and enable it as [Network Plugin](http://codex.wordpress.org/Create_A_Network#WordPress_Plugins). Users can access their own statistics, site admins can access each blog's statistics and the plugin's configuration.
67
-
68
  = Credits =
69
 
70
  * 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).
71
  * All translators at the [Transifex translation community](https://www.transifex.com/projects/p/wp-piwik/).
72
- * 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., Oleg I., M. N., Daniel K., James L., Jochen K., Cyril P., Thomas K., Patrik K., Zach, Sebastian W., Peakkom, Patrik K., Kati K., Helmut O., Valerie S., Jochen D., Atlas R., the Piwik team itself, and all people flattering this.
73
  * All users who send me mails containing criticism, commendation, feature requests and bug reports - you help me to make WP-Piwik much better!
74
 
75
  Thank you all!
@@ -80,7 +61,7 @@ Thank you all!
80
 
81
  To use this plugin you will need your own Piwik instance. If you do not already have a Piwik setup, you have two simple options: use either [Self-hosted](http://piwik.org/) or [Cloud-hosted](http://piwik.org/hosting/).
82
 
83
- As soon as Piwik works, you'll be able to configure WP-Piwik: The Piwik URL is the same URL you use to access your Piwik, e.g. for the demo site: http://demo.piwik.org. The auth token is some kind of a secret password, which allows WP-Piwik to get the necessary data from Piwik. To get your auth token, log in to Piwik, click at your user name (top right) and click at "API" (left sidebar menu).
84
 
85
  You can get a more detailed description here: https://piwik.org/blog/2015/05/wordpress-integration-wp-piwik-1-0/
86
 
@@ -93,6 +74,14 @@ The response output contains...
93
  * **bool(false)** and **HTTP/1.1 404 Not Found**: The Piwik URL is wrong. Try to copy & paste the URL you use to access Piwik itself via browser.
94
  * **bool(false)** and no further HTTP response code: The Piwik server does not respond. Very often, this is caused by firewall or mod_security settings. Check your server logfiles to get further information. If you aren’t sure about this, please contact your web hoster for support.
95
 
 
 
 
 
 
 
 
 
96
  = Can I contribute to WP-Piwik as a translator? =
97
 
98
  You like to contribute to WP-Piwik translations? Please use the [Transifex translation community](https://www.transifex.com/projects/p/wp-piwik/).
@@ -103,17 +92,35 @@ If you can't (or don not want to) use transifex, you can also translate language
103
 
104
  Thank you very much! :-)
105
 
106
- = Why does WP-Piwik require a newer PHP version than WordPress? =
107
 
108
- WP-Piwik requires a working Piwik instance which requires a higher PHP version, too. Furthermore, please have a look at the [official PHP Unsupported Branches page](http://php.net/eol.php). Even if your software still works with PHP 5.2, the PHP team stopped to deliver **security** patches in January 2011. Even PHP 5.3 does not get security patches anymore (end of life date was August 2014).
 
 
109
 
110
- = Tracking does not work on HostGator! =
111
 
112
- Try to enable the "avoid mod_security" option (WP-Piwik settings, Tracking tab) or create a mod_security whitelist.
 
 
 
 
113
 
114
- = Overview shortcode shows no unique visitors using a yearly range. =
115
 
116
- See [Piwik FAQ](http://piwik.org/faq/how-to/#faq_113).
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
  == Screenshots ==
119
 
@@ -125,6 +132,13 @@ See [Piwik FAQ](http://piwik.org/faq/how-to/#faq_113).
125
 
126
  == Changelog ==
127
 
 
 
 
 
 
 
 
128
  = 1.0.14 =
129
  * Action "wp-piwik_site_created" was extended by a site ID parameter, so it will deliver the Piwik site ID of the created site
130
  * Bugfix: Fixed an issue with Piwik site creation
1
+ === WP-Piwik ===
2
 
3
  Contributors: Braekling
4
  Requires at least: 4.0
5
+ Tested up to: 4.7.3
6
+ Stable tag: 1.0.15
7
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
8
  Tags: piwik, tracking, statistics, stats, analytics
9
 
11
 
12
  == Description ==
13
 
14
+ This plugin uses the Piwik API to show your Piwik statistics in your WordPress dashboard. It's also able to add the Piwik tracking code to your blog and to do some modifications to the tracking code. Additionally, WP-Piwik supports WordPress networks and manages multiple sites and their tracking codes.
15
 
16
  To use this plugin you will need your own Piwik instance. If you do not already have a Piwik setup, you have two simple options: use either [Self-hosted](http://piwik.org/) or [Cloud-hosted](http://piwik.org/hosting/).
17
 
18
+ **Requirements:** PHP 7.0 (or higher), WordPress 4.0 (or higher), Piwik 3.0 (or higher)
19
 
20
  **Languages:** English, Albanian, Chinese, Dutch, French, German, Greek, Hungarian, Italian, Polish, Portuguese (Brazil). Partially supported: Azerbaijani, Belarusian, Hindi, Lithuanian, Luxembourgish, Norwegian, Persian, Romanian, Russian, Spanish, Swedish, Turkish, Ukrainian
21
 
22
  **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! ;-)
23
 
24
+ = What is Piwik? =
25
+
26
+ [youtube https://youtu.be/OslfF_EH81g]
27
+ [Learn more.](https://piwik.org/what-is-piwik/)
28
+
29
+ = First steps =
30
+ - Learn how to install your own Piwik instance: [Requirements](https://piwik.org/docs/requirements/), [Installation](https://piwik.org/docs/installation-optimization/).
31
+ - If you need support about Piwik, please have a look at the [Piwik forums](https://forum.piwik.org/).
32
+ - Finally, you can start [setting up WP-Piwik](https://piwik.org/blog/2015/05/wordpress-integration-wp-piwik-1-0/).
33
+
34
  = Shortcodes =
35
  You can use following shortcodes if activated:
36
 
40
  [wp-piwik module="opt-out" language="en" width="100%" height="200px"]
41
  Shows the Piwik opt-out Iframe. You can change the Iframe's language by the language attribute (e.g. de for German language) and its width and height using the corresponding attributes.
42
 
43
+ [wp-piwik module="post" range="last30" key="sum_daily_nb_uniq_visitors"]
44
  Shows the chosen keys value related to the current post. You can define a range (format: lastN, previousN or YYYY-MM-DD,YYYY-MM-DD) and the desired value's key (e.g., sum_daily_nb_uniq_visitors, nb_visits or nb_hits - for details see Piwik's API method Actions.getPageUrl using a range).
45
 
46
+ [wp-piwik]
47
  is equal to *[wp-piwik module="overview" title="" period="day" date="yesterday"]*.
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  = Credits =
50
 
51
  * 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).
52
  * All translators at the [Transifex translation community](https://www.transifex.com/projects/p/wp-piwik/).
53
+ * 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., Oleg I., M. N., Daniel K., James L., Jochen K., Cyril P., Thomas K., Patrik K., Zach, Sebastian W., Peakkom, Patrik K., Kati K., Helmut O., Valerie S., Jochen D., Atlas R., Harald W., Jan M., the Piwik team itself, and all people flattering this.
54
  * All users who send me mails containing criticism, commendation, feature requests and bug reports - you help me to make WP-Piwik much better!
55
 
56
  Thank you all!
61
 
62
  To use this plugin you will need your own Piwik instance. If you do not already have a Piwik setup, you have two simple options: use either [Self-hosted](http://piwik.org/) or [Cloud-hosted](http://piwik.org/hosting/).
63
 
64
+ As soon as Piwik works, you'll be able to configure WP-Piwik: The Piwik URL is the same URL you use to access your Piwik, e.g. for the demo site: http://demo.piwik.org. The auth token is some kind of a secret password, which allows WP-Piwik to get the necessary data from Piwik. To get your auth token, log in to Piwik, click at the preferences gear icon (top right) and click at "API" (left sidebar menu, near the bottom).
65
 
66
  You can get a more detailed description here: https://piwik.org/blog/2015/05/wordpress-integration-wp-piwik-1-0/
67
 
74
  * **bool(false)** and **HTTP/1.1 404 Not Found**: The Piwik URL is wrong. Try to copy & paste the URL you use to access Piwik itself via browser.
75
  * **bool(false)** and no further HTTP response code: The Piwik server does not respond. Very often, this is caused by firewall or mod_security settings. Check your server logfiles to get further information. If you aren’t sure about this, please contact your web hoster for support.
76
 
77
+ = Overview shortcode shows no unique visitors using a yearly range. =
78
+
79
+ See [Piwik FAQ](http://piwik.org/faq/how-to/#faq_113).
80
+
81
+ = Tracking does not work on HostGator! =
82
+
83
+ Try to enable the "avoid mod_security" option (WP-Piwik settings, Tracking tab) or create a mod_security whitelist.
84
+
85
  = Can I contribute to WP-Piwik as a translator? =
86
 
87
  You like to contribute to WP-Piwik translations? Please use the [Transifex translation community](https://www.transifex.com/projects/p/wp-piwik/).
92
 
93
  Thank you very much! :-)
94
 
95
+ == Installation ==
96
 
97
+ = General Notes =
98
+ * First, you have to set up a running Piwik instance. You can get Piwik [here](http://piwik.org/) and its documentation [here](http://piwik.org/docs/).
99
+ * If you want to update your Piwik instance, you should set your WordPress blog to maintenance while the update process is running.
100
 
101
+ = Install WP-Piwik on a simple WordPress blog =
102
 
103
+ 1. Upload the full `wp-piwik` directory into your `wp-content/plugins` directory.
104
+ 2. Activate the plugin through the 'Plugins' menu in WordPress.
105
+ 3. Open the new 'Settings/WP-Piwik Settings' menu and follow the instructions to configure your Piwik connection. Save settings.
106
+ 4. If you have view access to multiple site stats and did not enable "auto config", choose your blog and save settings again.
107
+ 5. Look at 'Dashboard/WP-Piwik' to see your site stats.
108
 
109
+ = Install WP-Piwik on a WordPress blog network (WPMU/WP multisite) =
110
 
111
+ There are two differents methods to use WP-Piwik in a multisite environment:
112
+ * As a Site Specific Plugin it behaves like a plugin installed on a simple WordPress blog. Each user can enable, configure and use WP-Piwik on his own. Users can even use their own Piwik instances (and accordingly they have to).
113
+ * Using WP-Piwik as a Network Plugin equates to a central approach. A single Piwik instance is used and the site admin configures the plugin completely. Users are just allowed to see their own statistics, site admins can see each blog's stats.
114
+
115
+ *Site Specific Plugin*
116
+
117
+ Just add WP-Piwik to your /wp-content/plugins folder and enable the Plugins page for individual site administrators. Each user has to enable and configure WP-Piwik on his own if he want to use the plugin.
118
+
119
+ *Network Plugin*
120
+
121
+ The Network Plugin support is still experimental. Please test it on your own (e.g. using a local copy of your WP multisite) before you use it in an user context.
122
+
123
+ Add WP-Piwik to your /wp-content/plugins folder and enable it as [Network Plugin](http://codex.wordpress.org/Create_A_Network#WordPress_Plugins). Users can access their own statistics, site admins can access each blog's statistics and the plugin's configuration.
124
 
125
  == Screenshots ==
126
 
132
 
133
  == Changelog ==
134
 
135
+ = 1.0.15 =
136
+ * Allow to modify the tracked user ID using the filter "wp-piwik_tracking_user_id"
137
+ * Bugfix: Output of "post" shortcode was incorrectly placed, see https://wordpress.org/support/topic/post-shortcode-values-are-incorrectly-placed/
138
+ * Bugfix: Usage of WP_PROXY_BYPASS_HOSTS, see https://wordpress.org/support/topic/bug-considering-wp_proxy_bypass_hosts-in-proxy-setups/
139
+ * Bugfix: Proxy script did not work with cURL, see https://github.com/braekling/WP-Piwik/issues/48
140
+ * Bugfix: RSS feed tracking did not use proxy URL
141
+
142
  = 1.0.14 =
143
  * Action "wp-piwik_site_created" was extended by a site ID parameter, so it will deliver the Piwik site ID of the created site
144
  * Bugfix: Fixed an issue with Piwik site creation
uninstall.php CHANGED
@@ -44,6 +44,7 @@ $globalSettings = array(
44
  'capability_stealth',
45
  'track_across',
46
  'track_across_alias',
 
47
  'track_feed',
48
  'track_feed_addcampaign',
49
  'track_feed_campaign',
44
  'capability_stealth',
45
  'track_across',
46
  'track_across_alias',
47
+ 'track_crossdomain_linking',
48
  'track_feed',
49
  'track_feed_addcampaign',
50
  'track_feed_campaign',
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: 1.0.14
10
  Author: Andr&eacute; Br&auml;kling
11
  Author URI: http://www.braekling.de
12
  Text Domain: wp-piwik
@@ -78,4 +78,4 @@ else {
78
 
79
  function wp_piwik_loader() {
80
  $GLOBALS ['wp-piwik'] = new WP_Piwik ();
81
- }
6
 
7
  Description: Adds Piwik stats to your dashboard menu and Piwik code to your wordpress header.
8
 
9
+ Version: 1.0.15
10
  Author: Andr&eacute; Br&auml;kling
11
  Author URI: http://www.braekling.de
12
  Text Domain: wp-piwik
78
 
79
  function wp_piwik_loader() {
80
  $GLOBALS ['wp-piwik'] = new WP_Piwik ();
81
+ }