Commit bb3b1b58 authored by lechuck's avatar lechuck Committed by lucha

[auto] Plugin: wp-piwik 1.0.9

parent 922f3a41
......@@ -12,7 +12,7 @@ class WP_Piwik {
*
* @var Runtime environment variables
*/
private static $revisionId = 2015101201, $version = '1.0.5', $blog_id, $pluginBasename = NULL, $logger, $settings, $request;
private static $revisionId = 2016052901, $version = '1.0.9', $blog_id, $pluginBasename = NULL, $logger, $settings, $request;
/**
* Constructor class to configure and register all WP-Piwik components
......@@ -287,6 +287,7 @@ class WP_Piwik {
}
$trackingCode = new WP_Piwik\TrackingCode ( $this );
$trackingCode->is404 = (is_404 () && self::$settings->getGlobalOption ( 'track_404' ));
$trackingCode->isUsertracking = self::$settings->getGlobalOption ( 'track_user_id' ) != 'disabled';
$trackingCode->isSearch = (is_search () && self::$settings->getGlobalOption ( 'track_search' ));
self::$logger->log ( 'Add tracking code. Blog ID: ' . self::$blog_id . ' Site ID: ' . self::$settings->getOption ( 'site_id' ) );
if ($this->isNetworkMode () && self::$settings->getGlobalOption ( 'track_mode' ) == 'manually') {
......@@ -966,6 +967,7 @@ class WP_Piwik {
'limit' => 10,
'width' => '100%',
'height' => '200px',
'idsite' => '',
'language' => 'en',
'range' => false,
'key' => 'sum_daily_nb_uniq_visitors'
......@@ -1117,7 +1119,7 @@ class WP_Piwik {
* @param string $newValue
* new blog name
*/
public function onBlogNameChange($oldValue, $newValue) {
public function onBlogNameChange($oldValue, $newValue = null) {
$this->updatePiwikSite ( self::$settings->getOption ( 'site_id' ) );
}
......@@ -1129,7 +1131,7 @@ class WP_Piwik {
* @param string $newValue
* new blog URL
*/
public function onSiteUrlChange($oldValue, $newValue) {
public function onSiteUrlChange($oldValue, $newValue = null) {
$this->updatePiwikSite ( self::$settings->getOption ( 'site_id' ) );
}
......@@ -1179,7 +1181,7 @@ class WP_Piwik {
$postUrl = get_permalink ( $post->ID );
$this->log ( 'Load per post statistics: ' . $postUrl );
array (
new \WP_Piwik\Widget\Post ( $this, self::$settings, 'post', 'side', 'default', array (
new \WP_Piwik\Widget\Post ( $this, self::$settings, array('post', 'page', 'custom_post_type'), 'side', 'default', array (
'url' => $postUrl
) ),
'show'
......@@ -1232,4 +1234,4 @@ class WP_Piwik {
else
update_option ( $option, $value );
}
}
\ No newline at end of file
}
......@@ -21,7 +21,7 @@ class Settings extends \WP_Piwik\Admin {
if (isset($_GET['clear']) && $_GET['clear']) {
$this->clear($_GET['clear'] == 2);
self::$wpPiwik->resetRequest();
echo '<form method="post" action="?page='.$_GET['page'].'"><input type="submit" value="'.__('Reload', 'wp-piwik').'" /></form>';
echo '<form method="post" action="?page='.htmlentities($_GET['page']).'"><input type="submit" value="'.__('Reload', 'wp-piwik').'" /></form>';
return;
} elseif (isset ( $_POST ) && isset ( $_POST ['wp-piwik'] )) {
$this->showBox ( 'updated', 'yes', __ ( 'Changes saved.' ) );
......@@ -45,7 +45,7 @@ class Settings extends \WP_Piwik\Admin {
$this->showDonation();
}
?>
<form method="post" action="?page=<?php echo $_GET['page']; ?>">
<form method="post" action="?page=<?php echo htmlentities($_GET['page']); ?>">
<input type="hidden" name="wp-piwik[revision]" value="<?php echo self::$settings->getGlobalOption('revision'); ?>" />
<?php wp_nonce_field('wp-piwik_settings'); ?>
<table class="wp-piwik-form">
......@@ -57,7 +57,11 @@ class Settings extends \WP_Piwik\Admin {
if (! empty ( $piwikVersion ) && !is_array( $piwikVersion )) {
$this->showText ( sprintf ( __ ( 'WP-Piwik %s is successfully connected to Piwik %s.', 'wp-piwik' ), self::$wpPiwik->getPluginVersion (), $piwikVersion ) . ' ' . (! self::$wpPiwik->isNetworkMode () ? sprintf ( __ ( 'You are running WordPress %s.', 'wp-piwik' ), get_bloginfo ( 'version' ) ) : sprintf ( __ ( 'You are running a WordPress %s blog network (WPMU). WP-Piwik will handle your sites as different websites.', 'wp-piwik' ), get_bloginfo ( 'version' ) )) );
} else {
$this->showBox ( 'error', 'no', sprintf ( __ ( 'WP-Piwik %s was not able to connect to Piwik using your configuration. Check the &raquo;Connect to Piwik&laquo; section below.', 'wp-piwik' ), self::$wpPiwik->getPluginVersion () ) );
$errorMessage = \WP_Piwik\Request::getLastError();
if ( empty( $errorMessage ) )
$this->showBox ( 'error', 'no', sprintf ( __ ( 'WP-Piwik %s was not able to connect to Piwik using your configuration. Check the &raquo;Connect to Piwik&laquo; section below.', 'wp-piwik' ), self::$wpPiwik->getPluginVersion () ) );
else
$this->showBox ( 'error', 'no', sprintf ( __ ( 'WP-Piwik %s was not able to connect to Piwik using your configuration. During connection the following error occured: <br /><code>%s</code>', 'wp-piwik' ), self::$wpPiwik->getPluginVersion (), $errorMessage ) );
}
} else
$this->showBox ( 'error', 'no', sprintf ( __ ( 'WP-Piwik %s has to be connected to Piwik first. Check the &raquo;Connect to Piwik&laquo; section below.', 'wp-piwik' ), self::$wpPiwik->getPluginVersion () ) );
......@@ -210,11 +214,11 @@ class Settings extends \WP_Piwik\Admin {
'header' => __ ( 'Header', 'wp-piwik' )
), __ ( 'Choose whether the JavaScript code is added to the footer or the header.', 'wp-piwik' ), '', $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' );
$this->showTextarea ( 'noscript_code', __ ( 'Noscript code', 'wp-piwik' ), 2, 'This is a preview of your &lt;noscript&gt; code which is part of your tracking code.', $isNotGeneratedTracking || self::$settings->getGlobalOption ( 'track_mode' ) == 'proxy', 'wp-piwik-track-option wp-piwik-track-option-default wp-piwik-track-option-js', true, '', true, false );
$this->showTextarea ( 'noscript_code', __ ( 'Noscript code', 'wp-piwik' ), 2, 'This is a preview of your &lt;noscript&gt; code which is part of your tracking code.', 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', true, '', (self::$settings->getGlobalOption ( 'track_mode' ) != 'manually'), false );
$this->showCheckbox ( 'track_noscript', __ ( 'Add &lt;noscript&gt;', 'wp-piwik' ), __ ( 'Adds the &lt;noscript&gt; code to your footer.', 'wp-piwik' ) . ' ' . __ ( 'Disabled in proxy mode.', 'wp-piwik' ), $isNotGeneratedTracking || self::$settings->getGlobalOption ( 'track_mode' ) == 'proxy', 'wp-piwik-track-option wp-piwik-track-option-default wp-piwik-track-option-js' );
$this->showCheckbox ( 'track_noscript', __ ( 'Add &lt;noscript&gt;', 'wp-piwik' ), __ ( 'Adds the &lt;noscript&gt; code to your footer.', 'wp-piwik' ) . ' ' . __ ( 'Disabled in proxy mode.', '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' );
$this->showCheckbox ( 'track_nojavascript', __ ( 'Add rec parameter to noscript code', 'wp-piwik' ), __ ( 'Enable tracking for visitors without JavaScript (not recommended).', 'wp-piwik' ) . ' ' . sprintf ( __ ( 'See %sPiwik FAQ%s.', 'wp-piwik' ), '<a href="http://piwik.org/faq/how-to/#faq_176">', '</a>' ) . ' ' . __ ( 'Disabled in proxy mode.', 'wp-piwik' ), $isNotGeneratedTracking || self::$settings->getGlobalOption ( 'track_mode' ) == 'proxy', 'wp-piwik-track-option wp-piwik-track-option-default wp-piwik-track-option-js' );
$this->showCheckbox ( 'track_nojavascript', __ ( 'Add rec parameter to noscript code', 'wp-piwik' ), __ ( 'Enable tracking for visitors without JavaScript (not recommended).', 'wp-piwik' ) . ' ' . sprintf ( __ ( 'See %sPiwik FAQ%s.', 'wp-piwik' ), '<a href="http://piwik.org/faq/how-to/#faq_176">', '</a>' ) . ' ' . __ ( 'Disabled in proxy mode.', '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' );
$this->showSelect ( 'track_content', __ ( 'Enable content tracking', 'wp-piwik' ), array (
'disabled' => __ ( 'Disabled', 'wp-piwik' ),
......@@ -263,6 +267,14 @@ class Settings extends \WP_Piwik\Admin {
$this->showInput ( 'track_heartbeat', __ ( 'Enable heartbeat timer', 'wp-piwik' ), __ ( 'Enable a heartbeat timer to get more accurate visit lengths by sending periodical HTTP ping requests as long as the site is opened. Enter the time between the pings in seconds (Piwik default: 15) to enable or 0 to disable this feature. <strong>Note:</strong> This will cause a lot of additional HTTP requests on your site.', 'wp-piwik' ), $isNotGeneratedTracking, $fullGeneratedTrackingGroup );
$this->showSelect ( 'track_user_id', __ ( 'User ID Tracking', 'wp-piwik' ), array (
'disabled' => __ ( 'Disabled', 'wp-piwik' ),
'uid' => __ ( 'WP User ID', 'wp-piwik' ),
'email' => __ ( 'Email Address', 'wp-piwik' ),
'username' => __ ( 'Username', 'wp-piwik' ),
'displayname' => __ ( 'Display Name (Not Recommended!)', 'wp-piwik' )
), __ ( 'When a user is logged in to WordPress, track their &quot;User ID&quot;. You can select which field from the User\'s profile is tracked as the &quot;User ID&quot;. When enabled, Tracking based on Email Address is recommended.', 'wp-piwik' ), '', $isNotTracking, $fullGeneratedTrackingGroup );
echo $submitButton;
echo '</tbody></table><table id="expert" class="wp-piwik_menu-tab hidden"><tbody>';
......@@ -312,7 +324,7 @@ class Settings extends \WP_Piwik\Admin {
), __ ( 'Choose if you want to get an update notice if WP-Piwik is updated.', 'wp-piwik' ) );
$this->showInput ( 'set_download_extensions', __ ( 'Define all file types for download tracking', 'wp-piwik' ), __ ( 'Replace Piwik\'s default file extensions for download tracking, divided by a vertical bar (&#124;). Leave blank to keep Piwik\'s default settings.', 'wp-piwik' ) . ' ' . sprintf ( __ ( 'See %sPiwik documentation%s.', 'wp-piwik' ), '<a href="https://developer.piwik.org/guides/tracking-javascript-guide#file-extensions-for-tracking-downloads">', '</a>' ) );
echo $submitButton;
?>
</tbody>
......@@ -406,7 +418,7 @@ class Settings extends \WP_Piwik\Admin {
* @param boolean $wide Create a wide box (default: false)
*/
private function showInput($id, $name, $description, $isHidden = false, $groupName = '', $rowName = false, $hideDescription = true, $wide = false) {
printf ( '<tr class="%s%s"%s><th scope="row"><label for="%5$s">%s:</label></th><td><input '.($wide?'class="wp-piwik-wide" ':'').'name="wp-piwik[%s]" id="%5$s" value="%s" /> %s</td></tr>', $isHidden ? 'hidden ' : '', $groupName ? $groupName : '', $rowName ? ' id="' . $groupName . '-' . $rowName . '"' : '', $name, $id, self::$settings->getGlobalOption ( $id ), !empty($description) ? $this->getDescription ( $id, $description, $hideDescription ) : '' );
printf ( '<tr class="%s%s"%s><th scope="row"><label for="%5$s">%s:</label></th><td><input '.($wide?'class="wp-piwik-wide" ':'').'name="wp-piwik[%s]" id="%5$s" value="%s" /> %s</td></tr>', $isHidden ? 'hidden ' : '', $groupName ? $groupName : '', $rowName ? ' id="' . $groupName . '-' . $rowName . '"' : '', $name, $id, htmlentities(self::$settings->getGlobalOption( $id ), ENT_QUOTES, 'UTF-8', false), !empty($description) ? $this->getDescription ( $id, $description, $hideDescription ) : '' );
}
/**
......@@ -502,14 +514,14 @@ class Settings extends \WP_Piwik\Admin {
</form>
</div>
<div>
<a href="bitcoin:3N8od4UQA3jDpP5KodkxSqENaRSMWEaTHp">Bitcoin<br />
<img style="border:none;" src="<?php echo self::$wpPiwik->getPluginURL(); ?>bitcoin.png" width="100" height="100" alt="Bitcoin Address" title="3N8od4UQA3jDpP5KodkxSqENaRSMWEaTHp" /></a>
<a href="bitcoin:32FMBngRne9wQ7XPFP2CfR25tjp3oa4roN">Bitcoin<br />
<img style="border:none;" src="<?php echo self::$wpPiwik->getPluginURL(); ?>bitcoin.png" width="100" height="100" alt="Bitcoin Address" title="32FMBngRne9wQ7XPFP2CfR25tjp3oa4roN" /></a>
</div>
<div>
<a href="http://www.amazon.de/gp/registry/wishlist/111VUJT4HP1RA?reveal=unpurchased&amp;filter=all&amp;sort=priority&amp;layout=standard&amp;x=12&amp;y=14"><?php _e('My Amazon.de wishlist', 'wp-piwik'); ?></a>
</div>
<div>
<?php _e('Please don\'t forget to vote the compatibility at the','wp-piwik'); ?> <a href="http://wordpress.org/extend/plugins/wp-piwik/">WordPress.org Plugin Directory</a>.
<?php _e('Please don\'t forget to vote the compatibility at the','wp-piwik'); ?> <a href="http://wordpress.org/extend/plugins/wp-piwik/">WordPress.org Plugin Directory</a>.
</div>
</div><?php
}
......@@ -538,7 +550,7 @@ class Settings extends \WP_Piwik\Admin {
*/
public function showCredits() {
?>
<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., <?php _e('the Piwik team itself','wp-piwik');?><?php _e(', and all people flattering this','wp-piwik'); ?>!</p>
<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., <?php _e('the Piwik team itself','wp-piwik');?><?php _e(', and all people flattering this','wp-piwik'); ?>!</p>
<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>
<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>
<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>
......@@ -693,4 +705,4 @@ class Settings extends \WP_Piwik\Admin {
</div>
<?php }
}
\ No newline at end of file
}
......@@ -4,7 +4,7 @@
abstract class Request {
protected static $wpPiwik, $settings, $debug, $requests = array(), $results = array(), $isCacheable = array(), $piwikVersion;
protected static $wpPiwik, $settings, $debug, $lastError = '', $requests = array(), $results = array(), $isCacheable = array(), $piwikVersion;
public function __construct($wpPiwik, $settings) {
self::$wpPiwik = $wpPiwik;
......@@ -85,6 +85,10 @@
self::$wpPiwik->log("Result string: ".$str);
return ($str == json_decode(false, true) || @json_decode($str, true) !== false)?json_decode($str, true):array();
}
public static function getLastError() {
return self::$lastError;
}
abstract protected function request($id);
......
......@@ -42,6 +42,7 @@
curl_setopt($c, CURLOPT_PROXYUSERPWD, $httpProxyClass->username().':'.$httpProxyClass->password());
}
$result = curl_exec($c);
self::$lastError = curl_error($c);
if ($GLOBALS ['wp-piwik_debug']) {
$header_size = curl_getinfo($c, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
......@@ -54,7 +55,9 @@
}
private function fopen($id, $url, $params) {
$contextDefinition = array('http'=>array('timeout' => self::$settings->getGlobalOption('connection_timeout')));
$contextDefinition = array('http'=>array('timeout' => self::$settings->getGlobalOption('connection_timeout')) );
if (self::$settings->getGlobalOption('disable_ssl_verify'))
$contextDefinition['ssl'] = array('allow_self_signed' => true);
if (self::$settings->getGlobalOption('http_method')=='post') {
$fullUrl = $url;
$contextDefinition['http']['method'] = 'POST';
......
......@@ -9,13 +9,13 @@ namespace WP_Piwik;
* @package WP_Piwik
*/
class Settings {
/**
*
* @var Environment variables and default settings container
*/
private static $wpPiwik, $defaultSettings;
/**
*
* @var Define callback functions for changed settings
......@@ -25,9 +25,9 @@ class Settings {
'piwik_token' => 'checkPiwikToken',
'site_id' => 'requestPiwikSiteID',
'tracking_code' => 'prepareTrackingCode',
'noscript_code' => 'prepareNocscriptCode'
'noscript_code' => 'prepareNocscriptCode'
);
/**
*
* @var Register default configuration set
......@@ -51,7 +51,7 @@ class Settings {
'dashboard_seo' => false,
'toolbar' => false,
'capability_read_stats' => array (
'administrator' => true
'administrator' => true
),
'perpost_stats' => false,
'plugin_display_name' => 'WP-Piwik',
......@@ -83,6 +83,7 @@ class Settings {
'track_feed_addcampaign' => false,
'track_feed_campaign' => 'feed',
'track_heartbeat' => 0,
'track_user_id' => 'disabled',
// User settings: Expert configuration
'cache' => true,
'http_connection' => 'curl',
......@@ -103,9 +104,9 @@ class Settings {
'noscript_code' => '',
'tracking_code' => '',
'last_tracking_code_update' => 0,
'dashboard_revision' => 0
'dashboard_revision' => 0
), $settingsChanged = false;
/**
* Constructor class to prepare settings manager
*
......@@ -117,7 +118,7 @@ class Settings {
self::$wpPiwik->log ( 'Store default settings' );
self::$defaultSettings = array (
'globalSettings' => $this->globalSettings,
'settings' => $this->settings
'settings' => $this->settings
);
self::$wpPiwik->log ( 'Load settings' );
foreach ( $this->globalSettings as $key => $default ) {
......@@ -126,7 +127,7 @@ class Settings {
foreach ( $this->settings as $key => $default )
$this->settings [$key] = get_option ( 'wp-piwik-' . $key, $default );
}
/**
* Save all settings as WordPress options
*/
......@@ -154,7 +155,7 @@ class Settings {
$objRole = get_role ( $strKey );
foreach ( array (
'stealth',
'read_stats'
'read_stats'
) as $strCap ) {
$aryCaps = $this->getGlobalOption ( 'capability_' . $strCap );
if (isset ( $aryCaps [$strKey] ) && $aryCaps [$strKey])
......@@ -164,7 +165,7 @@ class Settings {
}
$this->settingsChanged = false;
}
/**
* Get a global option's value
*
......@@ -175,7 +176,7 @@ class Settings {
public function getGlobalOption($key) {
return isset ( $this->globalSettings [$key] ) ? $this->globalSettings [$key] : self::$defaultSettings ['globalSettings'] [$key];
}
/**
* Get an option's value related to a specific blog
*
......@@ -191,7 +192,7 @@ class Settings {
}
return isset ( $this->settings [$key] ) ? $this->settings [$key] : self::$defaultSettings ['settings'] [$key];
}
/**
* Set a global option's value
*
......@@ -205,7 +206,7 @@ class Settings {
self::$wpPiwik->log ( 'Changed global option ' . $key . ': ' . (is_array ( $value ) ? serialize ( $value ) : $value) );
$this->globalSettings [$key] = $value;
}
/**
* Set an option's value related to a specific blog
*
......@@ -224,7 +225,7 @@ class Settings {
} else
$this->settings [$key] = $value;
}
/**
* Reset settings to default
*/
......@@ -243,19 +244,19 @@ class Settings {
}
else $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'wp-piwik_global-%'");
}
/**
* Get blog list
*/
public static function getBlogList($limit = null, $page = null) {
if ( !\wp_is_large_network() )
return \wp_get_sites ( array('limit' => $limit, 'offset' => $page?($page - 1) * $limit:null));
if ($limit && $page)
if ($limit && $page)
$queryLimit = ' LIMIT '.(int) (($page - 1) * $limit).','.(int) $limit;
global $wpdb;
return $wpdb->get_results('SELECT blog_id FROM '.$wpdb->blogs.' ORDER BY blog_id'.$queryLimit, ARRAY_A);
}
/**
* Check if plugin is network activated
*
......@@ -266,7 +267,7 @@ class Settings {
require_once (ABSPATH . 'wp-admin/includes/plugin.php');
return is_plugin_active_for_network ( 'wp-piwik/wp-piwik.php' );
}
/**
* Apply new configuration
*
......@@ -283,7 +284,7 @@ class Settings {
$this->setGlobalOption ( 'last_settings_update', time () );
$this->save ();
}
/**
* Apply callback function on new settings
*
......@@ -296,14 +297,14 @@ class Settings {
if (isset ( $in [$key] ))
$in [$key] = call_user_func_array ( array (
$this,
$value
$value
), array (
$in [$key],
$in
$in
) );
return $in;
}
/**
* Add slash to Piwik URL if necessary
*
......@@ -316,7 +317,7 @@ class Settings {
private function checkPiwikUrl($value, $in) {
return substr ( $value, - 1, 1 ) != '/' ? $value . '/' : $value;
}
/**
* Remove &amp;token_auth= from auth token
*
......@@ -329,7 +330,7 @@ class Settings {
private function checkPiwikToken($value, $in) {
return str_replace ( '&token_auth=', '', $value );
}
/**
* Request the site ID (if not set before)
*
......@@ -344,7 +345,7 @@ class Settings {
return self::$wpPiwik->getPiwikSiteId();
return $value;
}
/**
* Prepare the tracking code
*
......@@ -366,7 +367,7 @@ class Settings {
$this->setOption ( 'noscript_code', $result ['noscript'] );*/
return; // $result ['script'];
}
/**
* Prepare the nocscript code
*
......@@ -381,7 +382,7 @@ class Settings {
return stripslashes ( $value );
return $this->getOption ( 'noscript_code' );
}
/**
* Get debug data
*
......@@ -395,4 +396,4 @@ class Settings {
$debug['global_settings']['piwik_token'] = !empty($debug['global_settings']['piwik_token'])?'set':'not set';
return $debug;
}
}
\ No newline at end of file
}
......@@ -9,7 +9,7 @@
'wp-piwik_post_customvars',
__('Piwik Custom Variables', 'wp-piwik'),
array(&$this, 'showCustomvars'),
'post',
array('post', 'page', 'custom_post_type'),
'side',
'default'
);
......
......@@ -8,7 +8,7 @@ class TrackingCode {
private $trackingCode;
public $is404 = false, $isSearch = false;
public $is404 = false, $isSearch = false, $isUsertracking = false;
public function __construct($wpPiwik) {
self::$wpPiwik = $wpPiwik;
......@@ -18,16 +18,19 @@ class TrackingCode {
}
public function getTrackingCode() {
if ($this->isUsertracking)
$this->applyUserTracking ();
if ($this->is404)
$this->apply404Changes ();
if ($this->isSearch)
$this->applySearchChanges ();
if (is_single ())
if (is_single () || is_page())
$this->addCustomValues ();
return $this->trackingCode;
}
public static function prepareTrackingCode($code, $settings, $logger) {
global $current_user;
$logger->log ( 'Apply tracking code changes:' );
$settings->setOption ( 'last_tracking_code_update', time () );
if ($settings->getGlobalOption ( 'track_mode' ) == 'js')
......@@ -64,6 +67,7 @@ class TrackingCode {
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['addDownloadExtensions', '" . ($settings->getGlobalOption ( 'add_download_extensions' )) . "']);\n_paq.push(['trackPageView']);", $code );
if ($settings->getGlobalOption ( 'limit_cookies' ))
$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 );
if ($settings->getGlobalOption ( 'force_protocol' ) != 'disabled')
$code = str_replace ( '"//', '"' . $settings->getGlobalOption ( 'force_protocol' ) . '://', $code );
if ($settings->getGlobalOption ( 'track_content' ) == 'all')
......@@ -107,6 +111,27 @@ class TrackingCode {
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackSiteSearch','" . get_search_query () . "', false, " . $intResultCount . "]);\n_paq.push(['trackPageView']);", $this->trackingCode );
}
private function applyUserTracking() {
if (\is_user_logged_in()) {
// Get the User ID Admin option, and the current user's data
$uidFrom = self::$wpPiwik->getGlobalOption ( 'track_user_id' );
$current_user = wp_get_current_user(); // current user
// Get the user ID based on the admin setting
if ( $uidFrom == 'uid' ) {
$pkUserId = $current_user->ID;
} elseif ( $uidFrom == 'email' ) {
$pkUserId = $current_user->user_email;
} elseif ( $uidFrom == 'username' ) {
$pkUserId = $current_user->user_login;
} elseif ( $uidFrom == 'displayname' ) {
$pkUserId = $current_user->display_name;
}
// Check we got a User ID to track, and track it
if ( isset( $pkUserId ) && ! empty( $pkUserId ))
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setUserId', '" . esc_js( $pkUserId ) . "']);\n_paq.push(['trackPageView']);", $this->trackingCode );
}
}
private function addCustomValues() {
$customVars = '';
for($i = 1; $i <= 5; $i ++) {
......@@ -119,4 +144,4 @@ class TrackingCode {
if (! empty ( $customVars ))
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", $customVars . "_paq.push(['trackPageView']);", $this->trackingCode );
}
}
\ No newline at end of file
}
......@@ -240,32 +240,32 @@ abstract class Widget {
case 'today' :
$period = 'day';
$date = 'today';
$description = 'today';
$description = __('today', 'wp-piwik' );
break;
case 'current_month' :
$period = 'month';
$date = 'today';
$description = 'current month';
$description = __('current month', 'wp-piwik' );
break;
case 'last_month' :
$period = 'month';
$date = date ( "Y-m-d", strtotime ( "last day of previous month" ) );
$description = 'last month';
$description = __('last month', 'wp-piwik' );
break;
case 'current_week' :
$period = 'week';
$date = 'today';
$description = 'current week';
$description = __('current week', 'wp-piwik' );
break;
case 'last_week' :
$period = 'week';
$date = date ( "Y-m-d", strtotime ( "-1 week" ) );
$description = 'last week';
$description = __('last week', 'wp-piwik' );
break;
case 'yesterday' :
$period = 'day';
$date = 'yesterday';
$description = 'yesterday';
$description = __('yesterday', 'wp-piwik' );
break;
default :
break;
......@@ -325,9 +325,9 @@ abstract class Widget {
public function rangeName() {
switch ($this->parameter ['date']) {
case 'last30' :
return 'last 30 days';
return __('last 30 days', 'wp-piwik' );
case 'last12' :
return 'last 12 ' . $this->parameter ['period'] . 's';