Commit eb016eee authored by lechuck's avatar lechuck Committed by lucha
Browse files

Upgraded wp-piwik to 0.9.9.9

parent f558a62c
<?php
// Nothing to see...
\ No newline at end of file
<?php
abstract class WP_Piwik_Logger {
private $loggerName = 'unnamed';
private $loggerContent = array();
private $startMicrotime = null;
abstract function loggerOutput($loggerTime, $loggerMessage);
public function __construct($loggerName) {
$this->setName($loggerName);
$this->setStartMicrotime(microtime(true));
$this->log('Logging started -------------------------------');
}
public function __destruct() {
$this->log('Logging finished ------------------------------');
}
public function log($loggerMessage) {
$this->loggerOutput($this->getElapsedMicrotime(), $loggerMessage);
}
private function setName($loggerName) {
$this->loggerName = $loggerName;
}
public function getName() {
return $this->loggerName;
}
private function setStartMicrotime($startMicrotime) {
$this->startMicrotime = $startMicrotime;
}
public function getStartMicrotime() {
return $this->startMicrotime;
}
public function getElapsedMicrotime() {
return microtime(true) - $this->getStartMicrotime();
}
}
\ No newline at end of file
<?php
require_once('WP_Piwik_Logger.php');
class WP_Piwik_Logger_Dummy extends WP_Piwik_Logger {
public function loggerOutput($loggerTime, $loggerMessage) {}
}
\ No newline at end of file
<?php
require_once('WP_Piwik_Logger.php');
class WP_Piwik_Logger_File extends WP_Piwik_Logger {
private $loggerFile = null;
private function encodeFilename($fileName) {
$fileName = str_replace (' ', '_', $fileName);
preg_replace('/[^0-9^a-z^_^.]/', '', $fileName);
return $fileName;
}
private function setFilename() {
$this->loggerFile = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'logs'.DIRECTORY_SEPARATOR.
date('Ymd').'_'.$this->encodeFilename($this->getName()).'.log';
}
private function getFilename() {
return $this->loggerFile;
}
private function openFile() {
if (!$this->loggerFile)
$this->setFilename();
return fopen($this->getFilename(), 'a');
}
private function closeFile($fileHandle) {
fclose($fileHandle);
}
private function writeFile($fileHandle, $fileContent) {
fwrite($fileHandle, $fileContent."\n");
}
private function formatMicrotime($loggerTime) {
return sprintf('[%6s sec]',number_format($loggerTime,3));
}
public function loggerOutput($loggerTime, $loggerMessage) {
if ($fileHandle = $this->openFile()) {
$this->writeFile($fileHandle, $this->formatMicrotime($loggerTime).' '.$loggerMessage);
$this->closeFile($fileHandle);
}
}
}
\ No newline at end of file
<?php
require_once('WP_Piwik_Template.php');
class WP_Piwik_MetaBox_PerPost_Stats extends WP_Piwik_Template {
function addMetabox() {
add_meta_box(
'wp-piwik_post_perpoststats',
__('Piwik Statistics (last 30 days)', 'wp-piwik'),
array(&$this, 'showStats'),
'post',
'side',
'default'
);
}
function showStats() {
global $post;
$postURL = get_permalink($post->ID);
$range = $this->getRangeLast30();
self::$logger->log('Load per post statistics: '.$postURL);
$data = self::$wpPiwik->callPiwikAPI('Actions.getPageUrl', 'range', $range, null, false, false, 'PHP', $postURL, false);
if (!isset($data[0])) return;
echo '<table>';
$this->tabRow(__('Visitors', 'wp-piwik').':',$data[0]['nb_visits']);
$this->tabRow(__('Unique visitors', 'wp-piwik').':', $data[0]['sum_daily_nb_uniq_visitors']);
$this->tabRow(__('Page views', 'wp-piwik').':', $data[0]['nb_hits']);
$this->tabRow(__('Time/visit', 'wp-piwik').':', $data[0]['avg_time_on_page']);
$this->tabRow(__('Bounce count', 'wp-piwik').':', $this->output($data[0], 'entry_bounce_count', 0).' ('.$data[0]['bounce_rate'].')');
$this->tabRow(__('Exit count', 'wp-piwik').':', $this->output($data[0], 'exit_nb_visits', 0).' ('.$data[0]['exit_rate'].')');
if (isset($data[0]['avg_time_generation']))
$this->tabRow(__('Avg. generation time', 'wp-piwik').':', $data[0]['avg_time_generation']);
echo '</table>';
}
}
\ No newline at end of file
<?php
class WP_Piwik_Settings {
private static $logger, $defaultSettings;
private $globalSettings = array(
'revision' => 90921,
'plugin_display_name' => 'WP-Piwik',
'add_tracking_code' => false,
'last_settings_update' => 0,
'piwik_token' => '',
'piwik_url' => '',
'piwik_path' => '',
'piwik_mode' => 'http',
'piwik_useragent' => 'php',
'piwik_useragent_string' => 'WP-Piwik',
'connection_timeout' => 5,
'dashboard_widget' => false,
'dashboard_chart' => false,
'dashboard_seo' => false,
'stats_seo' => false,
'capability_stealth' => array(),
'capability_read_stats' => array('administrator' => true),
'piwik_shortcut' => false,
'default_date' => 'yesterday',
'auto_site_config' => true,
'track_404' => false,
'track_search' => false,
'track_mode' => 0,
'track_post' => false,
'track_proxy' => false,
'track_admin' => false,
'track_feed' => false,
'track_feed_goal' => '',
'track_feed_revenue' => '',
'track_feed_campaign' => 'feed',
'track_feed_addcampaign' => 'false',
'track_cdnurlssl' => '',
'track_noscript' => false,
'track_nojavascript' => false,
'disable_timelimit' => false,
'disable_ssl_verify' => false,
'disable_cookies' => false,
'toolbar' => false,
'shortcodes' => false,
'cache' => true,
'perpost_stats' => false
),
$settings = array(
'name' => '',
'tracking_code' => '',
'site_id' => NULL,
'last_tracking_code_update' => 0,
'dashboard_revision' => 0,
'noscript_code' => ''
),
$settingsChanged = false;
public function __construct($objLogger) {
self::$logger = $objLogger;
self::$logger->log('Store default settings');
self::$defaultSettings = array('globalSettings' => $this->globalSettings, 'settings' => $this->settings);
self::$logger->log('Load settings');
$this->globalSettings = (is_plugin_active_for_network('wp-piwik/wp-piwik.php')?
get_site_option('wp-piwik_global-settings', $this->globalSettings):
get_option('wp-piwik_global-settings', $this->globalSettings)
);
$this->settings = get_option('wp-piwik_settings',$this->settings);
}
public function save() {
if (!$this->settingsChanged) {
self::$logger->log('No settings changed yet');
return;
}
self::$logger->log('Save settings');
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php'))
update_site_option('wp-piwik_global-settings', $this->globalSettings);
else
update_option('wp-piwik_global-settings', $this->globalSettings);
update_option('wp-piwik_settings', $this->settings);
global $wp_roles;
if (!is_object($wp_roles))
$wp_roles = new WP_Roles();
if (!is_object($wp_roles)) die("STILL NO OBJECT");
foreach($wp_roles->role_names as $strKey => $strName) {
$objRole = get_role($strKey);
foreach (array('stealth', 'read_stats') as $strCap) {
$aryCaps = $this->getGlobalOption('capability_'.$strCap);
if (isset($aryCaps[$strKey]) && $aryCaps[$strKey])
$objRole->add_cap('wp-piwik_'.$strCap);
else $objRole->remove_cap('wp-piwik_'.$strCap);
}
}
$this->settingsChanges = false;
}
public function getGlobalOption($key) {
return isset($this->globalSettings[$key])?$this->globalSettings[$key]:null;
}
public function getOption($key) {
return isset($this->settings[$key])?$this->settings[$key]:null;
}
public function setGlobalOption($key, $value) {
$this->settingsChanged = true;
self::$logger->log('Changed global option '.$key.': '.(is_array($value)?serialize($value):$value));
$this->globalSettings[$key] = $value;
}
public function setOption($key, $value) {
$this->settingsChanged = true;
self::$logger->log('Changed option '.$key.': '.$value);
$this->settings[$key] = $value;
}
public function resetSettings($bolFull = false) {
self::$logger->log('Reset WP-Piwik settings');
global $wpdb;
$keepSettings = array(
'piwik_token' => $this->getGlobalOption('piwik_token'),
'piwik_url' => $this->getGlobalOption('piwik_url'),
'piwik_path' => $this->getGlobalOption('piwik_path'),
'piwik_mode' => $this->getGlobalOption('piwik_mode')
);
if (is_plugin_active_for_network('wp-piwik/wp-piwik.php')) {
delete_site_option('wp-piwik_global-settings');
$aryBlogs = $wpdb->get_results('SELECT blog_id FROM '.$wpdb->blogs.' ORDER BY blog_id');
foreach ($aryBlogs as $aryBlog)
delete_blog_option($aryBlog->blog_id, 'wp-piwik_settings');
if (!$bolFull) update_site_option('wp-piwik_global-settings', $keepSettings);
} else {
delete_option('wp-piwik_global-settings');
delete_option('wp-piwik_settings');
}
$this->globalSettings = self::$defaultSettings['globalSettings'];
$this->settings = self::$defaultSettings['settings'];
if (!$bolFull) {
self::$logger->log('Restore connection settings');
foreach ($keepSettings as $key => $value)
$this->setGlobalOption($key, $value);
}
$this->save();
}
}
\ No newline at end of file
<?php
class WP_Piwik_Template {
public static $logger, $settings, $wpPiwik;
public function __construct($config) {
self::$logger = $config['logger'];
self::$settings = $config['settings'];
self::$wpPiwik = $config['wp_piwik'];
}
public function output($array, $key, $default = '') {
if (isset($array[$key]))
return $array[$key];
else
return $default;
}
public function tabRow($name, $value) {
echo '<tr><td>'.$name.'</td><td>'.$value.'</td></tr>';
}
public function getRangeLast30() {
$diff = (self::$settings->getGlobalOption('default_date') == 'yesterday') ? -86400 : 0;
$end = time() + $diff;
$start = time() - 2592000 + $diff;
return date('Y-m-d', $start).','.date('Y-m-d', $end);
}
}
\ No newline at end of file
<?php
// Nothing to see...
\ No newline at end of file
<?php
/*
Configure WP-Piwik Logger
0: Logger disabled
1: Log to screen (available soon)
2: Log to file (logs/YYYYMMDD_wp-piwik.log)
*/
define('WP_PIWIK_ACTIVATE_LOGGER', 0);
\ No newline at end of file
......@@ -9,6 +9,7 @@
$aryConf['params']['date'],
$aryConf['params']['limit']
);
$aryConf['title'] = __('Browser', 'wp-piwik');
$strValues = '';
$intCount = 0; $intMore = 0; $intSum = 0;
......
<?php
// Nothing to see...
\ No newline at end of file
......@@ -60,8 +60,8 @@
echo '<tr><td>'.__('Total time spent', 'wp-piwik').':</td><td>'.$strTime.'</td></tr>';
echo '<tr><td>'.__('Time/visit', 'wp-piwik').':</td><td>'.$strAvgTime.'</td></tr>';
echo '<tr><td>'.__('Bounce count', 'wp-piwik').':</td><td>'.$aryConf['data']['bounce_count'].' ('.$aryConf['data']['bounce_rate'].')</td></tr>';
if (self::$aryGlobalSettings['piwik_shortcut'])
echo '<tr><td>'.__('Shortcut', 'wp-piwik').':</td><td><a href="'.self::$aryGlobalSettings['piwik_url'].'">Piwik</a>'.(isset($aryConf['inline']) && $aryConf['inline']?' - <a href="?page=wp-piwik_stats">WP-Piwik</a>':'').'</td></tr>';
if (self::$settings->getGlobalOption('piwik_shortcut'))
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>';
/***************************************************************************/ ?>
</tbody>
</table>
......
......@@ -9,13 +9,13 @@
*****************/
// PIWIK URL, e.g. http://www.website.example/piwik
$strPiwikURL = self::$aryGlobalSettings['piwik_url'];
$strPiwikURL = self::$settings->getGlobalOption('piwik_url');
// PIWIK AUTH TOKEN, e.g. 1234a5cd6789e0a12345b678cd9012ef
$strPiwikAuthToken = self::$aryGlobalSettings['piwik_token'];
$strPiwikAuthToken = self::$settings->getGlobalOption('piwik_token');
// YOUR BLOG'S URL, e.g. http://www.website.example
$strPiwikYourBlogURL = get_bloginfo('url');
// User agent
$strUA = self::$aryGlobalSettings['piwik_useragent']=='php'?ini_get('user_agent'):self::$aryGlobalSettings['piwik_useragent_string'];
$strUA = self::$settings->getGlobalOption('piwik_useragent')=='php'?ini_get('user_agent'):self::$settings->getGlobalOption('piwik_useragent_string');
/* That's all, stop editing! */
......@@ -72,11 +72,11 @@ foreach ($aryURLs as $strMethod => $strURL) {
$intTest++;
echo '*** Test '.$intTest.'/'.count($aryURLs).': '.$strMethod.' ***'."\n";
echo 'Using: '.(function_exists('curl_init')?'cURL':'fopen')."\n";
echo 'SSL peer verification: '.(function_exists('curl_init') && !self::$aryGlobalSettings['disable_ssl_verify']?'enabled':'disabled')."\n";
echo 'SSL peer verification: '.(function_exists('curl_init') && !self::$settings->getGlobalOption('disable_ssl_verify')?'enabled':'disabled')."\n";
echo 'User Agent: '.$strUA."\n";
echo 'Call: '.$strURL.'&token_auth= + TOKEN'."\n";
$x = microtime(true);
$strResult = getRemoteFile($strURL,$strToken,!self::$aryGlobalSettings['disable_ssl_verify'],$strUA);
$strResult = getRemoteFile($strURL,$strToken,!self::$settings->getGlobalOption('disable_ssl_verify'),$strUA);
$x = microtime(true) - $x;
echo 'Result:'."\n";
echo htmlentities($strResult)."\n";
......
......@@ -2,7 +2,7 @@
*
* jquery.sparkline.js
*
* v2.0
* v2.1.1
* (c) Splunk, Inc
* Contact: Gareth Watts (gareth@splunk.com)
* http://omnipotent.net/jquery.sparkline/
......@@ -179,7 +179,7 @@
* When set to false you can supply any number of values and the box plot will
* be computed for you. Default is false.
* showOutliers - Set to true (default) to display outliers as circles
* outlierIRQ - Interquartile range used to determine outliers. Default 1.5
* outlierIQR - Interquartile range used to determine outliers. Default 1.5
* boxLineColor - Outline color of the box
* boxFillColor - Fill color for the box
* whiskerColor - Line color used for whiskers
......@@ -202,7 +202,15 @@
/*jslint regexp: true, browser: true, jquery: true, white: true, nomen: false, plusplus: false, maxerr: 500, indent: 4 */
(function ($) {
(function(factory) {
if(typeof define === 'function' && define.amd) {
define(['jquery'], factory);
}
else {
factory(jQuery);
}
}
(function($) {
'use strict';
var UNSET_OPTION = {},
......@@ -210,7 +218,7 @@
remove, isNumber, all, sum, addCSS, ensureArray, formatNumber, RangeMap,
MouseHandler, Tooltip, barHighlightMixin,
line, bar, tristate, discrete, bullet, pie, box, defaultStyles, initStyles,
VShape, VCanvas_base, VCanvas_canvas, VCanvas_vml, pending, shapeCount = 0;
VShape, VCanvas_base, VCanvas_canvas, VCanvas_vml, pending, shapeCount = 0;
/**
* Default configuration settings
......@@ -359,6 +367,7 @@
'white-space: nowrap;' +
'padding: 5px;' +
'border: 1px solid white;' +
'z-index: 10000;' +
'}' +
'.jqsfield { ' +
'color: white;' +
......@@ -366,12 +375,6 @@
'text-align: left;' +
'}';
initStyles = function() {
addCSS(defaultStyles);
};
$(initStyles);
/**
* Utilities
*/
......@@ -476,10 +479,16 @@
var vl;
if (q === 2) {
vl = Math.floor(values.length / 2);
return values.length % 2 ? values[vl] : (values[vl] + values[vl + 1]) / 2;
return values.length % 2 ? values[vl] : (values[vl-1] + values[vl]) / 2;
} else {
vl = Math.floor(values.length / 4);
return values.length % 2 ? (values[vl * q] + values[vl * q + 1]) / 2 : values[vl * q];
if (values.length % 2 ) { // odd
vl = (values.length * q + q) / 4;
return vl % 1 ? (values[Math.floor(vl)] + values[Math.floor(vl) - 1]) / 2 : values[vl-1];
} else { //even
vl = (values.length * q + 2) / 4;
return vl % 1 ? (values[Math.floor(vl)] + values[Math.floor(vl) - 1]) / 2 : values[vl-1];
}
}
};
......@@ -547,7 +556,8 @@
all = function (val, arr, ignoreNull) {
var i;
for (i = arr.length; i--; ) {
if (arr[i] !== val || (!ignoreNull && val === null)) {
if (ignoreNull && arr[i] === null) continue;
if (arr[i] !== val) {
return false;
}
}
......@@ -593,9 +603,9 @@
if (height === undefined) {
height = $(this).innerHeight();
}
if ($.browser.hasCanvas) {
if ($.fn.sparkline.hasCanvas) {
target = new VCanvas_canvas(width, height, this, interact);
} else if ($.browser.msie) {
} else if ($.fn.sparkline.hasVML) {
target = new VCanvas_vml(width, height, this);
} else {
return false;
......@@ -900,6 +910,12 @@
}
});
initStyles = function() {
addCSS(defaultStyles);
};
$(initStyles);
pending = [];
$.fn.sparkline = function (userValues, userOptions) {
return this.each(function () {
......@@ -1484,7 +1500,7 @@
canvasTop, canvasLeft,
vertex, path, paths, x, y, xnext, xpos, xposnext,
last, next, yvalcount, lineShapes, fillShapes, plen,
valueSpots, color, xvalues, yvalues, i;
valueSpots, hlSpotsEnabled, color, xvalues, yvalues, i;
if (!line._super.render.call(this)) {
return;
......@@ -1512,18 +1528,20 @@
}
if (spotRadius) {
// adjust the canvas size as required so that spots will fit
if (options.get('minSpotColor') || (options.get('spotColor') && yvalues[yvallast] === this.miny)) {
hlSpotsEnabled = options.get('highlightSpotColor') && !options.get('disableInteraction');
if (hlSpotsEnabled || options.get('minSpotColor') || (options.get('spotColor') && yvalues[yvallast] === this.miny)) {
canvasHeight -= Math.ceil(spotRadius);
}
if (options.get('maxSpotColor') || (options.get('spotColor') && yvalues[yvallast] === this.maxy)) {
if (hlSpotsEnabled || options.get('maxSpotColor') || (options.get('spotColor') && yvalues[yvallast] === this.maxy)) {
canvasHeight -= Math.ceil(spotRadius);
canvasTop += Math.ceil(spotRadius);
}
if ((options.get('minSpotColor') || options.get('maxSpotColor')) && (yvalues[0] === this.miny || yvalues[0] === this.maxy)) {
if (hlSpotsEnabled ||
((options.get('minSpotColor') || options.get('maxSpotColor')) && (yvalues[0] === this.miny || yvalues[0] === this.maxy))) {
canvasLeft += Math.ceil(spotRadius);
canvasWidth -= Math.ceil(spotRadius);
}
if (options.get('spotColor') ||
if (hlSpotsEnabled || options.get('spotColor') ||
(options.get('minSpotColor') || options.get('maxSpotColor') &&
(yvalues[yvallast] === this.miny || yvalues[yvallast] === this.maxy))) {
canvasWidth -= Math.ceil(spotRadius);
......@@ -1533,7 +1551,7 @@
canvasHeight--;