Commit 8c9ddada authored by lucha's avatar lucha

removed leftovers from old versions of wp-piwik plugin

parent 89a67c8a
File mode changed from 100644 to 100755
# WP-Piwik
# WP-Matomo (former WP-Piwik)
This [WordPress](https://wordpress.org) plugin adds a [Piwik](http://piwik.org) stats site to your blog's dashboard. It's also able to add the Piwik tracking code to your blog.
This [WordPress](https://wordpress.org) plugin adds a [Matomo](http://matomo.org) stats site to your blog's dashboard. It's also able to add the Matomo tracking code to your blog.
## How to use this plugin
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/).
To use this plugin you will need your own Matomo instance. If you do not already have a Matomo setup, you have two simple options: use either [self-hosted](http://matomo.org/) or [cloud-hosted](http://matomo.org/hosting/).
This repository was created to develop and maintain WP-Piwik. Please see the WordPress plugin directory if you like to use this plugin: https://wordpress.org/plugins/wp-piwik/
This repository was created to develop and maintain WP-Matomo (WP-Piwik). Please see the WordPress plugin directory if you like to use this plugin: https://wordpress.org/plugins/wp-piwik/
File mode changed from 100644 to 100755
<?php
// Nothing to see...
\ No newline at end of file
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
<?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'
);
}
private function getStats($range = false) {
global $post;
$postURL = get_permalink($post->ID);
$range = ($range?$range:$this->getRangeLast30());
self::$logger->log('Load per post statistics: '.$postURL);
return self::$wpPiwik->callPiwikAPI('Actions.getPageUrl', 'range', $range, null, false, false, 'PHP', $postURL, false);
}
function showStats() {
$data = $this->getStats();
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>';
}
function getValue($range, $key) {
$data = $this->getStats($range);
if (!isset($data[0]) || !isset($data[0][$key])) return '-';
else return $data[0][$key];
}
}
\ 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,
'track_codeposition' => 'footer',
'track_datacfasync' => false,
'track_across' => false,
'track_across_alias' => false,
'limit_cookies' => false,
'limit_cookies_visitor' => 1209600,
'limit_cookies_session' => 0,
'add_post_annotations' => false,
'add_customvars_box' => true,
'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 = ($this->checkNetworkActivation()?
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]:self::$defaultSettings['globalSettings'][$key];
}
public function getOption($key) {
return isset($this->settings[$key])?$this->settings[$key]:self::$defaultSettings['settings'][$key];
}
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();
}
public function checkNetworkActivation() {
if (!function_exists("is_plugin_active_for_network")) {
require_once(ABSPATH.'wp-admin/includes/plugin.php');
}
return is_plugin_active_for_network('wp-piwik/wp-piwik.php');
}
}
\ 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
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
<?php
/*********************************
WP-Piwik::Stats:BrowserDetails
**********************************/
$aryConf['data'] = $this->callPiwikAPI(
'UserSettings.getBrowserVersion',
$aryConf['params']['period'],
$aryConf['params']['date'],
$aryConf['params']['limit']
);
$aryConf['title'] = __('Browser Details', 'wp-piwik');
$strValues = '';
$intCount = 0; $intMore = 0; $intSum = 0;
if (isset($aryConf['data']['result']) && $aryConf['data']['result'] ='error')
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($aryConf['data']['message'], ENT_QUOTES, 'utf-8');
else {
if (is_array($aryConf['data']))
foreach ($aryConf['data'] as $key => $aryValues) {
$intCount++;
if ($intCount <= 9) $strValues .= '["'.$aryValues['label'].'",'.$aryValues['nb_uniq_visitors'].'],';
else $intMore += $aryValues['nb_uniq_visitors'];
$intSum += $aryValues['nb_uniq_visitors'];
}
if ($intMore) $strValues .= '["'.__('Others', 'wp-piwik').'",'.$intMore.'],';
$strValues = substr($strValues, 0, -1);
if ($intSum) {
/***************************************************************************/ ?>
<div class="wp-piwik-graph-wide">
<div id="wp-piwik_stats_browserdetails_graph" style="height:310px;width:100%"></div>
</div>
<?php /************************************************************************/
}
/***************************************************************************/ ?>
<div class="table">
<table class="widefat wp-piwik-table">
<thead>
<tr>
<th><?php _e('Browser', 'wp-piwik'); ?></th>
<th class="n"><?php _e('Unique', 'wp-piwik'); ?></th>
<th class="n"><?php _e('Percent', 'wp-piwik'); ?></th>
</tr>
</thead>
<tbody>
<?php /************************************************************************/
if ($intSum)
foreach ($aryConf['data'] as $aryValues)
echo '<tr><td>'.
$aryValues['label'].
'</td><td class="n">'.
$aryValues['nb_uniq_visitors'].
'</td><td class="n">'.
number_format($aryValues['nb_uniq_visitors']/$intSum*100, 2).
'%</td></tr>';
else echo '<tr><td colspan="3">'.__('No data available.', 'wp-piwik').'</td></tr>';
unset($aryTmp);
/***************************************************************************/ ?>
</tbody>
</table>
</div>
<script type="text/javascript">
$plotBrowsers = $j.jqplot('wp-piwik_stats_browserdetails_graph', [[<?php echo $strValues; ?>]], {
seriesDefaults:{renderer:$j.jqplot.PieRenderer, rendererOptions:{sliceMargin:8}},