updated plugin WP-Matomo Integration version 1.0.24

This commit is contained in:
KawaiiPunk 2020-09-25 14:44:13 +00:00 committed by Gitium
parent 62ddc64fea
commit 4f3d745449
27 changed files with 3321 additions and 3304 deletions

View File

@ -0,0 +1,2 @@
.idea/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,112 +1,112 @@
<?php
namespace WP_Piwik\Admin;
if (! class_exists ( 'WP_List_Table' ))
require_once (ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
class Sitebrowser extends \WP_List_Table {
private $data = array (), $wpPiwik;
public function __construct($wpPiwik) {
$this->wpPiwik = $wpPiwik;
if( isset($_POST['s']) ){
$cnt = $this->prepare_items ($_POST['s']);
} else {
$cnt = $this->prepare_items ();
}
global $status, $page;
$this->showSearchForm();
parent::__construct ( array (
'singular' => __ ( 'site', 'wp-piwik' ),
'plural' => __ ( 'sites', 'wp-piwik' ),
'ajax' => false
) );
if ($cnt > 0)
$this->display ();
else
echo '<p>' . __ ( 'No site configured yet.', 'wp-piwik' ) . '</p>';
}
public function get_columns() {
$columns = array (
'id' => __ ( 'Blog ID', 'wp-piwik' ),
'name' => __ ( 'Title', 'wp-piwik' ),
'siteurl' => __ ( 'URL', 'wp-piwik' ),
'piwikid' => __ ( 'Site ID (Piwik)', 'wp-piwik' )
);
return $columns;
}
public function prepare_items($search = '') {
$current_page = $this->get_pagenum ();
$per_page = 10;
global $blog_id;
global $wpdb;
global $pagenow;
if (is_plugin_active_for_network ( 'wp-piwik/wp-piwik.php' )) {
$total_items = $wpdb->get_var ( $wpdb->prepare('SELECT COUNT(*) FROM ' . $wpdb->blogs . ' WHERE CONCAT(domain, path) LIKE "%%%s%%" AND spam = 0 AND deleted = 0', $search));
$blogs = \WP_Piwik\Settings::getBlogList($per_page, $current_page, $search);
foreach ( $blogs as $blog ) {
$blogDetails = get_blog_details ( $blog['blog_id'], true );
$this->data [] = array (
'name' => $blogDetails->blogname,
'id' => $blogDetails->blog_id,
'siteurl' => $blogDetails->siteurl,
'piwikid' => $this->wpPiwik->getPiwikSiteId ( $blogDetails->blog_id )
);
}
} else {
$blogDetails = get_bloginfo ();
$this->data [] = array (
'name' => get_bloginfo ( 'name' ),
'id' => '-',
'siteurl' => get_bloginfo ( 'url' ),
'piwikid' => $this->wpPiwik->getPiwikSiteId ()
);
$total_items = 1;
}
$columns = $this->get_columns ();
$hidden = array ();
$sortable = array ();
$this->_column_headers = array (
$columns,
$hidden,
$sortable
);
$this->set_pagination_args ( array (
'total_items' => $total_items,
'per_page' => $per_page
) );
foreach ( $this->data as $key => $dataset ) {
if (empty ( $dataset ['piwikid'] ) || $dataset ['piwikid'] == 'n/a')
$this->data [$key] ['piwikid'] = __ ( 'Site not created yet.', 'wp-piwik' );
if ($this->wpPiwik->isNetworkMode ())
$this->data [$key] ['name'] = '<a href="index.php?page=wp-piwik_stats&wpmu_show_stats=' . $dataset ['id'] . '">' . $dataset ['name'] . '</a>';
}
$this->items = $this->data;
return count ( $this->items );
}
public function column_default($item, $column_name) {
switch ($column_name) {
case 'id' :
case 'name' :
case 'siteurl' :
case 'piwikid' :
return $item [$column_name];
default :
return print_r ( $item, true );
}
}
private function showSearchForm() {
?>
<form method="post">
<input type="hidden" name="page" value="<?php echo filter_var($_REQUEST['page'], FILTER_SANITIZE_STRING) ?>" />
<?php $this->search_box('Search domain and path', 'wpPiwikSiteSearch'); ?>
</form>
<?php
}
<?php
namespace WP_Piwik\Admin;
if (! class_exists ( 'WP_List_Table' ))
require_once (ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
class Sitebrowser extends \WP_List_Table {
private $data = array (), $wpPiwik;
public function __construct($wpPiwik) {
$this->wpPiwik = $wpPiwik;
if( isset($_POST['s']) ){
$cnt = $this->prepare_items ($_POST['s']);
} else {
$cnt = $this->prepare_items ();
}
global $status, $page;
$this->showSearchForm();
parent::__construct ( array (
'singular' => __ ( 'site', 'wp-piwik' ),
'plural' => __ ( 'sites', 'wp-piwik' ),
'ajax' => false
) );
if ($cnt > 0)
$this->display ();
else
echo '<p>' . __ ( 'No site configured yet.', 'wp-piwik' ) . '</p>';
}
public function get_columns() {
$columns = array (
'id' => __ ( 'Blog ID', 'wp-piwik' ),
'name' => __ ( 'Title', 'wp-piwik' ),
'siteurl' => __ ( 'URL', 'wp-piwik' ),
'piwikid' => __ ( 'Site ID (Piwik)', 'wp-piwik' )
);
return $columns;
}
public function prepare_items($search = '') {
$current_page = $this->get_pagenum ();
$per_page = 10;
global $blog_id;
global $wpdb;
global $pagenow;
if (is_plugin_active_for_network ( 'wp-piwik/wp-piwik.php' )) {
$total_items = $wpdb->get_var ( $wpdb->prepare('SELECT COUNT(*) FROM ' . $wpdb->blogs . ' WHERE CONCAT(domain, path) LIKE "%%%s%%" AND spam = 0 AND deleted = 0', $search));
$blogs = \WP_Piwik\Settings::getBlogList($per_page, $current_page, $search);
foreach ( $blogs as $blog ) {
$blogDetails = get_blog_details ( $blog['blog_id'], true );
$this->data [] = array (
'name' => $blogDetails->blogname,
'id' => $blogDetails->blog_id,
'siteurl' => $blogDetails->siteurl,
'piwikid' => $this->wpPiwik->getPiwikSiteId ( $blogDetails->blog_id )
);
}
} else {
$blogDetails = get_bloginfo ();
$this->data [] = array (
'name' => get_bloginfo ( 'name' ),
'id' => '-',
'siteurl' => get_bloginfo ( 'url' ),
'piwikid' => $this->wpPiwik->getPiwikSiteId ()
);
$total_items = 1;
}
$columns = $this->get_columns ();
$hidden = array ();
$sortable = array ();
$this->_column_headers = array (
$columns,
$hidden,
$sortable
);
$this->set_pagination_args ( array (
'total_items' => $total_items,
'per_page' => $per_page
) );
foreach ( $this->data as $key => $dataset ) {
if (empty ( $dataset ['piwikid'] ) || $dataset ['piwikid'] == 'n/a')
$this->data [$key] ['piwikid'] = __ ( 'Site not created yet.', 'wp-piwik' );
if ($this->wpPiwik->isNetworkMode ())
$this->data [$key] ['name'] = '<a href="index.php?page=wp-piwik_stats&wpmu_show_stats=' . $dataset ['id'] . '">' . $dataset ['name'] . '</a>';
}
$this->items = $this->data;
return count ( $this->items );
}
public function column_default($item, $column_name) {
switch ($column_name) {
case 'id' :
case 'name' :
case 'siteurl' :
case 'piwikid' :
return $item [$column_name];
default :
return print_r ( $item, true );
}
}
private function showSearchForm() {
?>
<form method="post">
<input type="hidden" name="page" value="<?php echo filter_var($_REQUEST['page'], FILTER_SANITIZE_STRING) ?>" />
<?php $this->search_box('Search domain and path', 'wpPiwikSiteSearch'); ?>
</form>
<?php
}
}

View File

@ -1,408 +1,408 @@
<?php
namespace WP_Piwik;
/**
* Manage WP-Piwik settings
*
* @author Andr&eacute; Br&auml;kling
* @package WP_Piwik
*/
class Settings {
/**
*
* @var Environment variables and default settings container
*/
private static $wpPiwik, $defaultSettings;
/**
*
* @var Define callback functions for changed settings
*/
private $checkSettings = array (
'piwik_url' => 'checkPiwikUrl',
'piwik_token' => 'checkPiwikToken',
'site_id' => 'requestPiwikSiteID',
'tracking_code' => 'prepareTrackingCode',
'noscript_code' => 'prepareNocscriptCode'
);
/**
*
* @var Register default configuration set
*/
private $globalSettings = array (
// Plugin settings
'revision' => 0,
'last_settings_update' => 0,
// User settings: Piwik configuration
'piwik_mode' => 'http',
'piwik_url' => '',
'piwik_path' => '',
'piwik_user' => '',
'matomo_user' => '',
'piwik_token' => '',
'auto_site_config' => true,
// User settings: Stats configuration
'default_date' => 'yesterday',
'stats_seo' => false,
'stats_ecommerce' => false,
'dashboard_widget' => false,
'dashboard_ecommerce' => false,
'dashboard_chart' => false,
'dashboard_seo' => false,
'toolbar' => false,
'capability_read_stats' => array (
'administrator' => true
),
'perpost_stats' => false,
'plugin_display_name' => 'WP-Piwik',
'piwik_shortcut' => false,
'shortcodes' => false,
// User settings: Tracking configuration
'track_mode' => 'disabled',
'track_codeposition' => 'footer',
'track_noscript' => false,
'track_nojavascript' => false,
'proxy_url' => '',
'track_content' => 'disabled',
'track_search' => false,
'track_404' => false,
'add_post_annotations' => array(),
'add_customvars_box' => false,
'add_download_extensions' => '',
'set_download_extensions' => '',
'set_link_classes' => '',
'set_download_classes' => '',
'disable_cookies' => false,
'limit_cookies' => false,
'limit_cookies_visitor' => 34186669, // Piwik default 13 months
'limit_cookies_session' => 1800, // Piwik default 30 minutes
'limit_cookies_referral' => 15778463, // Piwik default 6 months
'track_admin' => false,
'capability_stealth' => array (),
'track_across' => false,
'track_across_alias' => false,
'track_crossdomain_linking' => false,
'track_feed' => false,
'track_feed_addcampaign' => false,
'track_feed_campaign' => 'feed',
'track_heartbeat' => 0,
'track_user_id' => 'disabled',
// User settings: Expert configuration
'cache' => true,
'http_connection' => 'curl',
'http_method' => 'post',
'disable_timelimit' => false,
'filter_limit' => '',
'connection_timeout' => 5,
'disable_ssl_verify' => false,
'disable_ssl_verify_host' => false,
'piwik_useragent' => 'php',
'piwik_useragent_string' => 'WP-Piwik',
'dnsprefetch' => false,
'track_datacfasync' => false,
'track_cdnurl' => '',
'track_cdnurlssl' => '',
'force_protocol' => 'disabled',
'update_notice' => 'enabled'
), $settings = array (
'name' => '',
'site_id' => NULL,
'noscript_code' => '',
'tracking_code' => '',
'last_tracking_code_update' => 0,
'dashboard_revision' => 0
), $settingsChanged = false;
/**
* Constructor class to prepare settings manager
*
* @param WP_Piwik $wpPiwik
* active WP-Piwik instance
*/
public function __construct($wpPiwik) {
self::$wpPiwik = $wpPiwik;
self::$wpPiwik->log ( 'Store default settings' );
self::$defaultSettings = array (
'globalSettings' => $this->globalSettings,
'settings' => $this->settings
);
self::$wpPiwik->log ( 'Load settings' );
foreach ( $this->globalSettings as $key => $default ) {
$this->globalSettings [$key] = ($this->checkNetworkActivation () ? get_site_option ( 'wp-piwik_global-' . $key, $default ) : get_option ( 'wp-piwik_global-' . $key, $default ));
}
foreach ( $this->settings as $key => $default )
$this->settings [$key] = get_option ( 'wp-piwik-' . $key, $default );
}
/**
* Save all settings as WordPress options
*/
public function save() {
if (! $this->settingsChanged) {
self::$wpPiwik->log ( 'No settings changed yet' );
return;
}
self::$wpPiwik->log ( 'Save settings' );
foreach ( $this->globalSettings as $key => $value ) {
if ( $this->checkNetworkActivation() )
update_site_option ( 'wp-piwik_global-' . $key, $value );
else
update_option ( 'wp-piwik_global-' . $key, $value );
}
foreach ( $this->settings as $key => $value ) {
update_option ( 'wp-piwik-' . $key, $value );
}
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])
$wp_roles->add_cap ( $strKey, 'wp-piwik_' . $strCap );
else $wp_roles->remove_cap ( $strKey, 'wp-piwik_' . $strCap );
}
}
$this->settingsChanged = false;
}
/**
* Get a global option's value
*
* @param string $key
* option key
* @return string option value
*/
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
*
* @param string $key
* option key
* @param int $blogID
* blog ID (default: current blog)
* @return \WP_Piwik\Register
*/
public function getOption($key, $blogID = null) {
if ($this->checkNetworkActivation () && ! empty ( $blogID )) {
return get_blog_option ( $blogID, 'wp-piwik-'.$key );
}
return isset ( $this->settings [$key] ) ? $this->settings [$key] : self::$defaultSettings ['settings'] [$key];
}
/**
* Set a global option's value
*
* @param string $key
* option key
* @param string $value
* new option value
*/
public function setGlobalOption($key, $value) {
$this->settingsChanged = true;
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
*
* @param string $key
* option key
* @param int $blogID
* blog ID (default: current blog)
* @param string $value
* new option value
*/
public function setOption($key, $value, $blogID = null) {
$this->settingsChanged = true;
self::$wpPiwik->log ( 'Changed option ' . $key . ': ' . $value );
if ($this->checkNetworkActivation () && ! empty ( $blogID )) {
add_blog_option ( $blogID, 'wp-piwik-'.$key, $value );
} else
$this->settings [$key] = $value;
}
/**
* Reset settings to default
*/
public function resetSettings() {
self::$wpPiwik->log ( 'Reset WP-Piwik settings' );
global $wpdb;
if ( $this->checkNetworkActivation() ) {
$aryBlogs = self::getBlogList();
if (is_array($aryBlogs))
foreach ($aryBlogs as $aryBlog) {
switch_to_blog($aryBlog['blog_id']);
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'wp-piwik-%'");
restore_current_blog();
}
$wpdb->query("DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE 'wp-piwik_global-%'");
}
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, $search = '') {
if ($limit && $page)
$queryLimit = ' LIMIT '.(int) (($page - 1) * $limit).','.(int) $limit;
global $wpdb;
return $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM '.$wpdb->blogs.' WHERE CONCAT(domain, path) LIKE "%%%s%%" AND spam = 0 AND deleted = 0 ORDER BY blog_id'.$queryLimit, $search), ARRAY_A);
}
/**
* Check if plugin is network activated
*
* @return boolean Is network activated?
*/
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' );
}
/**
* Apply new configuration
*
* @param array $in
* new configuration set
*/
public function applyChanges($in) {
if (!self::$wpPiwik->isValidOptionsPost())
die("Invalid config changes.");
$in = $this->checkSettings ( $in );
self::$wpPiwik->log ( 'Apply changed settings:' );
foreach ( self::$defaultSettings ['globalSettings'] as $key => $val )
$this->setGlobalOption ( $key, isset ( $in [$key] ) ? $in [$key] : $val );
foreach ( self::$defaultSettings ['settings'] as $key => $val )
$this->setOption ( $key, isset ( $in [$key] ) ? $in [$key] : $val );
$this->setGlobalOption ( 'last_settings_update', time () );
$this->save ();
}
/**
* Apply callback function on new settings
*
* @param array $in
* new configuration set
* @return array configuration set after callback functions were applied
*/
private function checkSettings($in) {
foreach ( $this->checkSettings as $key => $value )
if (isset ( $in [$key] ))
$in [$key] = call_user_func_array ( array (
$this,
$value
), array (
$in [$key],
$in
) );
return $in;
}
/**
* Add slash to Piwik URL if necessary
*
* @param string $value
* Piwik URL
* @param array $in
* configuration set
* @return string Piwik URL
*/
private function checkPiwikUrl($value, $in) {
return substr ( $value, - 1, 1 ) != '/' ? $value . '/' : $value;
}
/**
* Remove &amp;token_auth= from auth token
*
* @param string $value
* Piwik auth token
* @param array $in
* configuration set
* @return string Piwik auth token
*/
private function checkPiwikToken($value, $in) {
return str_replace ( '&token_auth=', '', $value );
}
/**
* Request the site ID (if not set before)
*
* @param string $value
* tracking code
* @param array $in
* configuration set
* @return int Piwik site ID
*/
private function requestPiwikSiteID($value, $in) {
if ($in ['auto_site_config'] && ! $value)
return self::$wpPiwik->getPiwikSiteId();
return $value;
}
/**
* Prepare the tracking code
*
* @param string $value
* tracking code
* @param array $in
* configuration set
* @return string tracking code
*/
private function prepareTrackingCode($value, $in) {
if ($in ['track_mode'] == 'manually' || $in ['track_mode'] == 'disabled') {
$value = stripslashes ( $value );
if ($this->checkNetworkActivation ())
add_site_option ( 'wp-piwik-manually', $value );
return $value;
}
/*$result = self::$wpPiwik->updateTrackingCode ();
echo '<pre>'; print_r($result); echo '</pre>';
$this->setOption ( 'noscript_code', $result ['noscript'] );*/
return; // $result ['script'];
}
/**
* Prepare the nocscript code
*
* @param string $value
* noscript code
* @param array $in
* configuration set
* @return string noscript code
*/
private function prepareNocscriptCode($value, $in) {
if ($in ['track_mode'] == 'manually')
return stripslashes ( $value );
return $this->getOption ( 'noscript_code' );
}
/**
* Get debug data
*
* @return array WP-Piwik settings for debug output
*/
public function getDebugData() {
$debug = array(
'global_settings' => $this->globalSettings,
'settings' => $this->settings
);
$debug['global_settings']['piwik_token'] = !empty($debug['global_settings']['piwik_token'])?'set':'not set';
return $debug;
}
}
<?php
namespace WP_Piwik;
/**
* Manage WP-Piwik settings
*
* @author Andr&eacute; Br&auml;kling
* @package WP_Piwik
*/
class Settings {
/**
*
* @var Environment variables and default settings container
*/
private static $wpPiwik, $defaultSettings;
/**
*
* @var Define callback functions for changed settings
*/
private $checkSettings = array (
'piwik_url' => 'checkPiwikUrl',
'piwik_token' => 'checkPiwikToken',
'site_id' => 'requestPiwikSiteID',
'tracking_code' => 'prepareTrackingCode',
'noscript_code' => 'prepareNocscriptCode'
);
/**
*
* @var Register default configuration set
*/
private $globalSettings = array (
// Plugin settings
'revision' => 0,
'last_settings_update' => 0,
// User settings: Piwik configuration
'piwik_mode' => 'http',
'piwik_url' => '',
'piwik_path' => '',
'piwik_user' => '',
'matomo_user' => '',
'piwik_token' => '',
'auto_site_config' => true,
// User settings: Stats configuration
'default_date' => 'yesterday',
'stats_seo' => false,
'stats_ecommerce' => false,
'dashboard_widget' => false,
'dashboard_ecommerce' => false,
'dashboard_chart' => false,
'dashboard_seo' => false,
'toolbar' => false,
'capability_read_stats' => array (
'administrator' => true
),
'perpost_stats' => false,
'plugin_display_name' => 'WP-Piwik',
'piwik_shortcut' => false,
'shortcodes' => false,
// User settings: Tracking configuration
'track_mode' => 'disabled',
'track_codeposition' => 'footer',
'track_noscript' => false,
'track_nojavascript' => false,
'proxy_url' => '',
'track_content' => 'disabled',
'track_search' => false,
'track_404' => false,
'add_post_annotations' => array(),
'add_customvars_box' => false,
'add_download_extensions' => '',
'set_download_extensions' => '',
'set_link_classes' => '',
'set_download_classes' => '',
'disable_cookies' => false,
'limit_cookies' => false,
'limit_cookies_visitor' => 34186669, // Piwik default 13 months
'limit_cookies_session' => 1800, // Piwik default 30 minutes
'limit_cookies_referral' => 15778463, // Piwik default 6 months
'track_admin' => false,
'capability_stealth' => array (),
'track_across' => false,
'track_across_alias' => false,
'track_crossdomain_linking' => false,
'track_feed' => false,
'track_feed_addcampaign' => false,
'track_feed_campaign' => 'feed',
'track_heartbeat' => 0,
'track_user_id' => 'disabled',
// User settings: Expert configuration
'cache' => true,
'http_connection' => 'curl',
'http_method' => 'post',
'disable_timelimit' => false,
'filter_limit' => '',
'connection_timeout' => 5,
'disable_ssl_verify' => false,
'disable_ssl_verify_host' => false,
'piwik_useragent' => 'php',
'piwik_useragent_string' => 'WP-Piwik',
'dnsprefetch' => false,
'track_datacfasync' => false,
'track_cdnurl' => '',
'track_cdnurlssl' => '',
'force_protocol' => 'disabled',
'update_notice' => 'enabled'
), $settings = array (
'name' => '',
'site_id' => NULL,
'noscript_code' => '',
'tracking_code' => '',
'last_tracking_code_update' => 0,
'dashboard_revision' => 0
), $settingsChanged = false;
/**
* Constructor class to prepare settings manager
*
* @param WP_Piwik $wpPiwik
* active WP-Piwik instance
*/
public function __construct($wpPiwik) {
self::$wpPiwik = $wpPiwik;
self::$wpPiwik->log ( 'Store default settings' );
self::$defaultSettings = array (
'globalSettings' => $this->globalSettings,
'settings' => $this->settings
);
self::$wpPiwik->log ( 'Load settings' );
foreach ( $this->globalSettings as $key => $default ) {
$this->globalSettings [$key] = ($this->checkNetworkActivation () ? get_site_option ( 'wp-piwik_global-' . $key, $default ) : get_option ( 'wp-piwik_global-' . $key, $default ));
}
foreach ( $this->settings as $key => $default )
$this->settings [$key] = get_option ( 'wp-piwik-' . $key, $default );
}
/**
* Save all settings as WordPress options
*/
public function save() {
if (! $this->settingsChanged) {
self::$wpPiwik->log ( 'No settings changed yet' );
return;
}
self::$wpPiwik->log ( 'Save settings' );
foreach ( $this->globalSettings as $key => $value ) {
if ( $this->checkNetworkActivation() )
update_site_option ( 'wp-piwik_global-' . $key, $value );
else
update_option ( 'wp-piwik_global-' . $key, $value );
}
foreach ( $this->settings as $key => $value ) {
update_option ( 'wp-piwik-' . $key, $value );
}
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])
$wp_roles->add_cap ( $strKey, 'wp-piwik_' . $strCap );
else $wp_roles->remove_cap ( $strKey, 'wp-piwik_' . $strCap );
}
}
$this->settingsChanged = false;
}
/**
* Get a global option's value
*
* @param string $key
* option key
* @return string option value
*/
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
*
* @param string $key
* option key
* @param int $blogID
* blog ID (default: current blog)
* @return \WP_Piwik\Register
*/
public function getOption($key, $blogID = null) {
if ($this->checkNetworkActivation () && ! empty ( $blogID )) {
return get_blog_option ( $blogID, 'wp-piwik-'.$key );
}
return isset ( $this->settings [$key] ) ? $this->settings [$key] : self::$defaultSettings ['settings'] [$key];
}
/**
* Set a global option's value
*
* @param string $key
* option key
* @param string $value
* new option value
*/
public function setGlobalOption($key, $value) {
$this->settingsChanged = true;
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
*
* @param string $key
* option key
* @param int $blogID
* blog ID (default: current blog)
* @param string $value
* new option value
*/
public function setOption($key, $value, $blogID = null) {
$this->settingsChanged = true;
self::$wpPiwik->log ( 'Changed option ' . $key . ': ' . $value );
if ($this->checkNetworkActivation () && ! empty ( $blogID )) {
add_blog_option ( $blogID, 'wp-piwik-'.$key, $value );
} else
$this->settings [$key] = $value;
}
/**
* Reset settings to default
*/
public function resetSettings() {
self::$wpPiwik->log ( 'Reset WP-Piwik settings' );
global $wpdb;
if ( $this->checkNetworkActivation() ) {
$aryBlogs = self::getBlogList();
if (is_array($aryBlogs))
foreach ($aryBlogs as $aryBlog) {
switch_to_blog($aryBlog['blog_id']);
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'wp-piwik-%'");
restore_current_blog();
}
$wpdb->query("DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE 'wp-piwik_global-%'");
}
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, $search = '') {
if ($limit && $page)
$queryLimit = ' LIMIT '.(int) (($page - 1) * $limit).','.(int) $limit;
global $wpdb;
return $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM '.$wpdb->blogs.' WHERE CONCAT(domain, path) LIKE "%%%s%%" AND spam = 0 AND deleted = 0 ORDER BY blog_id'.$queryLimit, $search), ARRAY_A);
}
/**
* Check if plugin is network activated
*
* @return boolean Is network activated?
*/
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' );
}
/**
* Apply new configuration
*
* @param array $in
* new configuration set
*/
public function applyChanges($in) {
if (!self::$wpPiwik->isValidOptionsPost())
die("Invalid config changes.");
$in = $this->checkSettings ( $in );
self::$wpPiwik->log ( 'Apply changed settings:' );
foreach ( self::$defaultSettings ['globalSettings'] as $key => $val )
$this->setGlobalOption ( $key, isset ( $in [$key] ) ? $in [$key] : $val );
foreach ( self::$defaultSettings ['settings'] as $key => $val )
$this->setOption ( $key, isset ( $in [$key] ) ? $in [$key] : $val );
$this->setGlobalOption ( 'last_settings_update', time () );
$this->save ();
}
/**
* Apply callback function on new settings
*
* @param array $in
* new configuration set
* @return array configuration set after callback functions were applied
*/
private function checkSettings($in) {
foreach ( $this->checkSettings as $key => $value )
if (isset ( $in [$key] ))
$in [$key] = call_user_func_array ( array (
$this,
$value
), array (
$in [$key],
$in
) );
return $in;
}
/**
* Add slash to Piwik URL if necessary
*
* @param string $value
* Piwik URL
* @param array $in
* configuration set
* @return string Piwik URL
*/
private function checkPiwikUrl($value, $in) {
return substr ( $value, - 1, 1 ) != '/' ? $value . '/' : $value;
}
/**
* Remove &amp;token_auth= from auth token
*
* @param string $value
* Piwik auth token
* @param array $in
* configuration set
* @return string Piwik auth token
*/
private function checkPiwikToken($value, $in) {
return str_replace ( '&token_auth=', '', $value );
}
/**
* Request the site ID (if not set before)
*
* @param string $value
* tracking code
* @param array $in
* configuration set
* @return int Piwik site ID
*/
private function requestPiwikSiteID($value, $in) {
if ($in ['auto_site_config'] && ! $value)
return self::$wpPiwik->getPiwikSiteId();
return $value;
}
/**
* Prepare the tracking code
*
* @param string $value
* tracking code
* @param array $in
* configuration set
* @return string tracking code
*/
private function prepareTrackingCode($value, $in) {
if ($in ['track_mode'] == 'manually' || $in ['track_mode'] == 'disabled') {
$value = stripslashes ( $value );
if ($this->checkNetworkActivation ())
add_site_option ( 'wp-piwik-manually', $value );
return $value;
}
/*$result = self::$wpPiwik->updateTrackingCode ();
echo '<pre>'; print_r($result); echo '</pre>';
$this->setOption ( 'noscript_code', $result ['noscript'] );*/
return; // $result ['script'];
}
/**
* Prepare the nocscript code
*
* @param string $value
* noscript code
* @param array $in
* configuration set
* @return string noscript code
*/
private function prepareNocscriptCode($value, $in) {
if ($in ['track_mode'] == 'manually')
return stripslashes ( $value );
return $this->getOption ( 'noscript_code' );
}
/**
* Get debug data
*
* @return array WP-Piwik settings for debug output
*/
public function getDebugData() {
$debug = array(
'global_settings' => $this->globalSettings,
'settings' => $this->settings
);
$debug['global_settings']['piwik_token'] = !empty($debug['global_settings']['piwik_token'])?'set':'not set';
return $debug;
}
}

View File

@ -1,150 +1,154 @@
<?php
namespace WP_Piwik;
class TrackingCode {
private static $wpPiwik, $piwikUrl = false;
private $trackingCode;
public $is404 = false, $isSearch = false, $isUsertracking = false;
public function __construct($wpPiwik) {
self::$wpPiwik = $wpPiwik;
if (! self::$wpPiwik->isCurrentTrackingCode () || ! self::$wpPiwik->getOption ( 'tracking_code' ) || strpos( self::$wpPiwik->getOption ( 'tracking_code' ), '{"result":"error",' ) !== false )
self::$wpPiwik->updateTrackingCode ();
$this->trackingCode = (self::$wpPiwik->isNetworkMode () && self::$wpPiwik->getGlobalOption ( 'track_mode' ) == 'manually') ? get_site_option ( 'wp-piwik-manually' ) : self::$wpPiwik->getOption ( 'tracking_code' );
}
public function getTrackingCode() {
if ($this->isUsertracking)
$this->applyUserTracking ();
if ($this->is404)
$this->apply404Changes ();
if ($this->isSearch)
$this->applySearchChanges ();
if (is_single () || is_page())
$this->addCustomValues ();
$this->trackingCode = apply_filters('wp-piwik_tracking_code', $this->trackingCode);
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 (preg_match ( '/var u="([^"]*)";/', $code, $hits )) {
$fetchedProxyUrl = $hits [1];
} else $fetchedProxyUrl = '';
if ($settings->getGlobalOption ( 'track_mode' ) == 'js')
$code = str_replace ( array (
'piwik.js',
'piwik.php'
), 'js/index.php', $code );
elseif ($settings->getGlobalOption ( 'track_mode' ) == 'proxy') {
$code = str_replace ( 'piwik.js', 'piwik.php', $code );
$proxy = str_replace ( array (
'https://',
'http://'
), '//', plugins_url ( 'wp-piwik' ) . '/proxy' ) . '/';
$code = preg_replace ( '/var u="([^"]*)";/', 'var u="' . $proxy . '"', $code );
$code = preg_replace ( '/img src="([^"]*)piwik.php/', 'img src="' . $proxy . 'piwik.php', $code );
}
if ($settings->getGlobalOption ( 'track_cdnurl' ) || $settings->getGlobalOption ( 'track_cdnurlssl' ))
$code = str_replace ( array (
"var d=doc",
"g.src=u+"
), array (
"var ucdn=(('https:' == document.location.protocol) ? 'https://" . ($settings->getGlobalOption ( 'track_cdnurlssl' ) ? $settings->getGlobalOption ( 'track_cdnurlssl' ) : $settings->getGlobalOption ( 'track_cdnurl' )) . "/' : 'http://" . ($settings->getGlobalOption ( 'track_cdnurl' ) ? $settings->getGlobalOption ( 'track_cdnurl' ) : $settings->getGlobalOption ( 'track_cdnurlssl' )) . "/');\nvar d=doc",
"g.src=ucdn+"
), $code );
if ($settings->getGlobalOption ( 'track_datacfasync' ))
$code = str_replace ( '<script type', '<script data-cfasync="false" type', $code );
if ($settings->getGlobalOption ( 'set_download_extensions' ))
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setDownloadExtensions', '" . ($settings->getGlobalOption ( 'set_download_extensions' )) . "']);\n_paq.push(['trackPageView']);", $code );
if ($settings->getGlobalOption ( 'add_download_extensions' ))
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['addDownloadExtensions', '" . ($settings->getGlobalOption ( 'add_download_extensions' )) . "']);\n_paq.push(['trackPageView']);", $code );
if ($settings->getGlobalOption ( 'set_download_classes' ))
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setDownloadClasses', '" . ($settings->getGlobalOption ( 'set_download_classes' )) . "']);\n_paq.push(['trackPageView']);", $code );
if ($settings->getGlobalOption ( 'set_link_classes' ))
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setLinkClasses', '" . ($settings->getGlobalOption ( 'set_link_classes' )) . "']);\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')
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['trackAllContentImpressions']);", $code );
elseif ($settings->getGlobalOption ( 'track_content' ) == 'visible')
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['trackVisibleContentImpressions']);", $code );
if ((int) $settings->getGlobalOption ( 'track_heartbeat' ) > 0)
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['enableHeartBeatTimer', ".(int) $settings->getGlobalOption ( 'track_heartbeat' )."]);", $code );
$noScript = array ();
preg_match ( '/<noscript>(.*)<\/noscript>/', $code, $noScript );
if (isset ( $noScript [0] )) {
if ($settings->getGlobalOption ( 'track_nojavascript' ))
$noScript [0] = str_replace ( '?idsite', '?rec=1&idsite', $noScript [0] );
$noScript = $noScript [0];
} else
$noScript = '';
$script = preg_replace ( '/<noscript>(.*)<\/noscript>/', '', $code );
$script = preg_replace ( '/\s+(\r\n|\r|\n)/', '$1', $script );
$logger->log ( 'Finished tracking code: ' . $script );
$logger->log ( 'Finished noscript code: ' . $noScript );
return array (
'script' => $script,
'noscript' => $noScript,
'proxy' => $fetchedProxyUrl
);
}
private function apply404Changes() {
self::$wpPiwik->log ( 'Apply 404 changes. Blog ID: ' . get_current_blog_id () . ' Site ID: ' . self::$wpPiwik->getOption ( 'site_id' ) );
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setDocumentTitle', '404/URL = '+String(document.location.pathname+document.location.search).replace(/\//g,'%2f') + '/From = ' + String(document.referrer).replace(/\//g,'%2f')]);\n_paq.push(['trackPageView']);", $this->trackingCode );
}
private function applySearchChanges() {
self::$wpPiwik->log ( 'Apply search tracking changes. Blog ID: ' . get_current_blog_id () . ' Site ID: ' . self::$wpPiwik->getOption ( 'site_id' ) );
$objSearch = new \WP_Query ( "s=" . get_search_query () . '&showposts=-1' );
$intResultCount = $objSearch->post_count;
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackSiteSearch','" . get_search_query () . "', false, " . $intResultCount . "]);\n_paq.push(['trackPageView']);", $this->trackingCode );
}
private function applyUserTracking() {
$pkUserId = null;
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;
}
}
$pkUserId = apply_filters('wp-piwik_tracking_user_id', $pkUserId);
// 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 ++) {
$postId = get_the_ID ();
$metaKey = get_post_meta ( $postId, 'wp-piwik_custom_cat' . $i, true );
$metaVal = get_post_meta ( $postId, 'wp-piwik_custom_val' . $i, true );
if (! empty ( $metaKey ) && ! empty ( $metaVal ))
$customVars .= "_paq.push(['setCustomVariable'," . $i . ", '" . $metaKey . "', '" . $metaVal . "', 'page']);\n";
}
if (! empty ( $customVars ))
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", $customVars . "_paq.push(['trackPageView']);", $this->trackingCode );
}
}
<?php
namespace WP_Piwik;
class TrackingCode {
private static $wpPiwik, $piwikUrl = false;
private $trackingCode;
public $is404 = false, $isSearch = false, $isUsertracking = false;
public function __construct($wpPiwik) {
self::$wpPiwik = $wpPiwik;
if (! self::$wpPiwik->isCurrentTrackingCode () || ! self::$wpPiwik->getOption ( 'tracking_code' ) || strpos( self::$wpPiwik->getOption ( 'tracking_code' ), '{"result":"error",' ) !== false )
self::$wpPiwik->updateTrackingCode ();
$this->trackingCode = (self::$wpPiwik->isNetworkMode () && self::$wpPiwik->getGlobalOption ( 'track_mode' ) == 'manually') ? get_site_option ( 'wp-piwik-manually' ) : self::$wpPiwik->getOption ( 'tracking_code' );
}
public function getTrackingCode() {
if ($this->isUsertracking)
$this->applyUserTracking ();
if ($this->is404)
$this->apply404Changes ();
if ($this->isSearch)
$this->applySearchChanges ();
if (is_single () || is_page())
$this->addCustomValues ();
$this->trackingCode = apply_filters('wp-piwik_tracking_code', $this->trackingCode);
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 (preg_match ( '/var u="([^"]*)";/', $code, $hits )) {
$fetchedProxyUrl = $hits [1];
} else $fetchedProxyUrl = '';
if ($settings->getGlobalOption ( 'track_mode' ) == 'js')
$code = str_replace ( array (
'piwik.js',
'piwik.php',
'matomo.js',
'matomo.php'
), 'js/index.php', $code );
elseif ($settings->getGlobalOption ( 'track_mode' ) == 'proxy') {
$code = str_replace ( 'piwik.js', 'piwik.php', $code );
$code = str_replace ( 'matomo.js', 'matomo.php', $code );
$proxy = str_replace ( array (
'https://',
'http://'
), '//', plugins_url ( 'wp-piwik' ) . '/proxy' ) . '/';
$code = preg_replace ( '/var u="([^"]*)";/', 'var u="' . $proxy . '"', $code );
$code = preg_replace ( '/img src="([^"]*)piwik.php/', 'img src="' . $proxy . 'piwik.php', $code );
$code = preg_replace ( '/img src="([^"]*)matomo.php/', 'img src="' . $proxy . 'matomo.php', $code );
}
if ($settings->getGlobalOption ( 'track_cdnurl' ) || $settings->getGlobalOption ( 'track_cdnurlssl' ))
$code = str_replace ( array (
"var d=doc",
"g.src=u+"
), array (
"var ucdn=(('https:' == document.location.protocol) ? 'https://" . ($settings->getGlobalOption ( 'track_cdnurlssl' ) ? $settings->getGlobalOption ( 'track_cdnurlssl' ) : $settings->getGlobalOption ( 'track_cdnurl' )) . "/' : 'http://" . ($settings->getGlobalOption ( 'track_cdnurl' ) ? $settings->getGlobalOption ( 'track_cdnurl' ) : $settings->getGlobalOption ( 'track_cdnurlssl' )) . "/');\nvar d=doc",
"g.src=ucdn+"
), $code );
if ($settings->getGlobalOption ( 'track_datacfasync' ))
$code = str_replace ( '<script type', '<script data-cfasync="false" type', $code );
if ($settings->getGlobalOption ( 'set_download_extensions' ))
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setDownloadExtensions', '" . ($settings->getGlobalOption ( 'set_download_extensions' )) . "']);\n_paq.push(['trackPageView']);", $code );
if ($settings->getGlobalOption ( 'add_download_extensions' ))
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['addDownloadExtensions', '" . ($settings->getGlobalOption ( 'add_download_extensions' )) . "']);\n_paq.push(['trackPageView']);", $code );
if ($settings->getGlobalOption ( 'set_download_classes' ))
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setDownloadClasses', '" . ($settings->getGlobalOption ( 'set_download_classes' )) . "']);\n_paq.push(['trackPageView']);", $code );
if ($settings->getGlobalOption ( 'set_link_classes' ))
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setLinkClasses', '" . ($settings->getGlobalOption ( 'set_link_classes' )) . "']);\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')
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['trackAllContentImpressions']);", $code );
elseif ($settings->getGlobalOption ( 'track_content' ) == 'visible')
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['trackVisibleContentImpressions']);", $code );
if ((int) $settings->getGlobalOption ( 'track_heartbeat' ) > 0)
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['enableHeartBeatTimer', ".(int) $settings->getGlobalOption ( 'track_heartbeat' )."]);", $code );
$noScript = array ();
preg_match ( '/<noscript>(.*)<\/noscript>/', $code, $noScript );
if (isset ( $noScript [0] )) {
if ($settings->getGlobalOption ( 'track_nojavascript' ))
$noScript [0] = str_replace ( '?idsite', '?rec=1&idsite', $noScript [0] );
$noScript = $noScript [0];
} else
$noScript = '';
$script = preg_replace ( '/<noscript>(.*)<\/noscript>/', '', $code );
$script = preg_replace ( '/\s+(\r\n|\r|\n)/', '$1', $script );
$logger->log ( 'Finished tracking code: ' . $script );
$logger->log ( 'Finished noscript code: ' . $noScript );
return array (
'script' => $script,
'noscript' => $noScript,
'proxy' => $fetchedProxyUrl
);
}
private function apply404Changes() {
self::$wpPiwik->log ( 'Apply 404 changes. Blog ID: ' . get_current_blog_id () . ' Site ID: ' . self::$wpPiwik->getOption ( 'site_id' ) );
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setDocumentTitle', '404/URL = '+String(document.location.pathname+document.location.search).replace(/\//g,'%2f') + '/From = ' + String(document.referrer).replace(/\//g,'%2f')]);\n_paq.push(['trackPageView']);", $this->trackingCode );
}
private function applySearchChanges() {
self::$wpPiwik->log ( 'Apply search tracking changes. Blog ID: ' . get_current_blog_id () . ' Site ID: ' . self::$wpPiwik->getOption ( 'site_id' ) );
$objSearch = new \WP_Query ( "s=" . get_search_query () . '&showposts=-1' );
$intResultCount = $objSearch->post_count;
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackSiteSearch','" . get_search_query () . "', false, " . $intResultCount . "]);\n_paq.push(['trackPageView']);", $this->trackingCode );
}
private function applyUserTracking() {
$pkUserId = null;
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;
}
}
$pkUserId = apply_filters('wp-piwik_tracking_user_id', $pkUserId);
// 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 ++) {
$postId = get_the_ID ();
$metaKey = get_post_meta ( $postId, 'wp-piwik_custom_cat' . $i, true );
$metaVal = get_post_meta ( $postId, 'wp-piwik_custom_val' . $i, true );
if (! empty ( $metaKey ) && ! empty ( $metaVal ))
$customVars .= "_paq.push(['setCustomVariable'," . $i . ", '" . $metaKey . "', '" . $metaVal . "', 'page']);\n";
}
if (! empty ( $customVars ))
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", $customVars . "_paq.push(['trackPageView']);", $this->trackingCode );
}
}

View File

@ -1,376 +1,376 @@
<?php
namespace WP_Piwik;
/**
* Abstract widget class
*
* @author Andr&eacute; Br&auml;kling
* @package WP_Piwik
*/
abstract class Widget {
/**
*
* @var Environment variables
*/
protected static $wpPiwik, $settings;
/**
*
* @var Configuration parameters
*/
protected $isShortcode = false, $method = '', $title = '', $context = 'side', $priority = 'core', $parameter = array (), $apiID = array (), $pageId = 'dashboard', $blogId = null, $name = 'Value', $limit = 10, $content = '', $output = '';
/**
* Widget constructor
*
* @param WP_Piwik $wpPiwik
* current WP-Piwik object
* @param WP_Piwik\Settings $settings
* current WP-Piwik settings
* @param string $pageId
* WordPress page ID (default: dashboard)
* @param string $context
* WordPress meta box context (defualt: side)
* @param string $priority
* WordPress meta box priority (default: default)
* @param array $params
* widget parameters (default: empty array)
* @param boolean $isShortcode
* is the widget shown inline? (default: false)
*/
public function __construct($wpPiwik, $settings, $pageId = 'dashboard', $context = 'side', $priority = 'default', $params = array(), $isShortcode = false) {
self::$wpPiwik = $wpPiwik;
self::$settings = $settings;
$this->pageId = $pageId;
$this->context = $context;
$this->priority = $priority;
if (self::$settings->checkNetworkActivation () && function_exists ( 'is_super_admin' ) && is_super_admin () && isset ( $_GET ['wpmu_show_stats'] )) {
switch_to_blog ( ( int ) $_GET ['wpmu_show_stats'] );
$this->blogId = get_current_blog_id ();
restore_current_blog ();
}
$this->isShortcode = $isShortcode;
$prefix = ($this->pageId == 'dashboard' ? self::$settings->getGlobalOption ( 'plugin_display_name' ) . ' - ' : '');
$this->configure ( $prefix, $params );
if (is_array ( $this->method ))
foreach ( $this->method as $method ) {
$this->apiID [$method] = \WP_Piwik\Request::register ( $method, $this->parameter );
self::$wpPiwik->log ( "Register request: " . $this->apiID [$method] );
}
else {
$this->apiID [$this->method] = \WP_Piwik\Request::register ( $this->method, $this->parameter );
self::$wpPiwik->log ( "Register request: " . $this->apiID [$this->method] );
}
if ($this->isShortcode)
return;
add_meta_box ( $this->getName (), $this->title, array (
$this,
'show'
), $pageId, $this->context, $this->priority );
}
/**
* Conifguration dummy method
*
* @param string $prefix
* metabox title prefix (default: empty)
* @param array $params
* widget parameters (default: empty array)
*/
protected function configure($prefix = '', $params = array()) {
}
/**
* Default show widget method, handles default Piwik output
*/
public function show() {
$response = self::$wpPiwik->request ( $this->apiID [$this->method] );
if (! empty ( $response ['result'] ) && $response ['result'] == 'error')
$this->out( '<strong>' . __ ( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . htmlentities ( $response ['message'], ENT_QUOTES, 'utf-8' ) );
else {
if (isset ( $response [0] ['nb_uniq_visitors'] ))
$unique = 'nb_uniq_visitors';
else
$unique = 'sum_daily_nb_uniq_visitors';
$tableHead = array (
'label' => __ ( $this->name, 'wp-piwik' )
);
$tableHead [$unique] = __ ( 'Unique', 'wp-piwik' );
if (isset ( $response [0] ['nb_visits'] ))
$tableHead ['nb_visits'] = __ ( 'Visits', 'wp-piwik' );
if (isset ( $response [0] ['nb_hits'] ))
$tableHead ['nb_hits'] = __ ( 'Hits', 'wp-piwik' );
if (isset ( $response [0] ['nb_actions'] ))
$tableHead ['nb_actions'] = __ ( 'Actions', 'wp-piwik' );
$tableBody = array ();
$count = 0;
if (is_array($response))
foreach ( $response as $rowKey => $row ) {
$count ++;
$tableBody [$rowKey] = array ();
foreach ( $tableHead as $key => $value )
$tableBody [$rowKey] [] = isset ( $row [$key] ) ? $row [$key] : '-';
if ($count == 10)
break;
}
$this->table ( $tableHead, $tableBody, null );
}
}
/**
* Display or store shortcode output
*/
protected function out($output) {
if ($this->isShortcode)
$this->output .= $output;
else echo $output;
}
/**
* Return shortcode output
*/
public function get() {
return $this->output;
}
/**
* Display a HTML table
*
* @param array $thead
* table header content (array of cells)
* @param array $tbody
* table body content (array of rows)
* @param array $tfoot
* table footer content (array of cells)
* @param string $class
* CSSclass name to apply on table sections
* @param string $javaScript
* array of javascript code to apply on body rows
*/
protected function table($thead, $tbody = array(), $tfoot = array(), $class = false, $javaScript = array(), $classes = array()) {
$this->out( '<div class="table"><table class="widefat wp-piwik-table">' );
if ($this->isShortcode && $this->title) {
$colspan = !empty ( $tbody ) ? count( $tbody[0] ) : 2 ;
$this->out( '<tr><th colspan="'.$colspan.'">' . $this->title . '</th></tr>' );
}
if (! empty ( $thead ))
$this->tabHead ( $thead, $class );
if (! empty ( $tbody ))
$this->tabBody ( $tbody, $class, $javaScript, $classes );
else
$this->out( '<tr><td colspan="10">' . __ ( 'No data available.', 'wp-piwik' ) . '</td></tr>' );
if (! empty ( $tfoot ))
$this->tabFoot ( $tfoot, $class );
$this->out( '</table></div>' );
}
/**
* Display a HTML table header
*
* @param array $thead
* array of cells
* @param string $class
* CSS class to apply
*/
private function tabHead($thead, $class = false) {
$this->out( '<thead' . ($class ? ' class="' . $class . '"' : '') . '><tr>' );
$count = 0;
foreach ( $thead as $value )
$this->out( '<th' . ($count ++ ? ' class="right"' : '') . '>' . $value . '</th>' );
$this->out( '</tr></thead>' );
}
/**
* Display a HTML table body
*
* @param array $tbody
* array of rows, each row containing an array of cells
* @param string $class
* CSS class to apply
* @param unknown $javaScript
* array of javascript code to apply (one item per row)
*/
private function tabBody($tbody, $class = false, $javaScript = array(), $classes = array()) {
$this->out( '<tbody' . ($class ? ' class="' . $class . '"' : '') . '>' );
foreach ( $tbody as $key => $trow )
$this->tabRow ( $trow, isset( $javaScript [$key] ) ?$javaScript [$key] : '', isset ( $classes [$key] ) ?$classes [$key] : '');
$this->out( '</tbody>' );
}
/**
* Display a HTML table footer
*
* @param array $tfoor
* array of cells
* @param string $class
* CSS class to apply
*/
private function tabFoot($tfoot, $class = false) {
$this->out( '<tfoot' . ($class ? ' class="' . $class . '"' : '') . '><tr>' );
$count = 0;
foreach ( $tfoot as $value )
$this->out( '<td' . ($count ++ ? ' class="right"' : '') . '>' . $value . '</td>' );
$this->out( '</tr></tfoot>' );
}
/**
* Display a HTML table row
*
* @param array $trow
* array of cells
* @param string $javaScript
* javascript code to apply
*/
private function tabRow($trow, $javaScript = '', $class = '') {
$this->out( '<tr' . (! empty ( $javaScript ) ? ' onclick="' . $javaScript . '"' : '') . (! empty ( $class ) ? ' class="' . $class . '"' : '') . '>' );
$count = 0;
foreach ( $trow as $tcell )
$this->out( '<td' . ($count ++ ? ' class="right"' : '') . '>' . $tcell . '</td>' );
$this->out( '</tr>' );
}
/**
* Get the current request's Piwik time settings
*
* @return array time settings: period => Piwik period, date => requested date, description => time description to show in widget title
*/
protected function getTimeSettings() {
switch (self::$settings->getGlobalOption ( 'default_date' )) {
case 'today' :
$period = 'day';
$date = 'today';
$description = __('today', 'wp-piwik' );
break;
case 'current_month' :
$period = 'month';
$date = 'today';
$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', 'wp-piwik' );
break;
case 'current_week' :
$period = 'week';
$date = 'today';
$description = __('current week', 'wp-piwik' );
break;
case 'last_week' :
$period = 'week';
$date = date ( "Y-m-d", strtotime ( "-1 week" ) );
$description = __('last week', 'wp-piwik' );
break;
case 'yesterday' :
$period = 'day';
$date = 'yesterday';
$description = __('yesterday', 'wp-piwik' );
break;
default :
break;
}
return array (
'period' => $period,
'date' => isset ( $_GET ['date'] ) ? ( int ) $_GET ['date'] : $date,
'description' => isset ( $_GET ['date'] ) ? $this->dateFormat ( $_GET ['date'], $period ) : $description
);
}
/**
* Format a date to show in widget
*
* @param string $date
* date string
* @param string $period
* Piwik period
* @return string formatted date
*/
protected function dateFormat($date, $period = 'day') {
$prefix = '';
switch ($period) {
case 'week' :
$prefix = __ ( 'week', 'wp-piwik' ) . ' ';
$format = 'W/Y';
break;
case 'short_week' :
$format = 'W';
break;
case 'month' :
$format = 'F Y';
$date = date ( 'Y-m-d', strtotime ( $date ) );
break;
default :
$format = get_option ( 'date_format' );
}
return $prefix . date_i18n ( $format, strtotime ( $date ) );
}
/**
* Format time to show in widget
*
* @param int $time
* time in seconds
* @return string formatted time
*/
protected function timeFormat($time) {
return floor ( $time / 3600 ) . 'h ' . floor ( ($time % 3600) / 60 ) . 'm ' . floor ( ($time % 3600) % 60 ) . 's';
}
/**
* Convert Piwik range into meaningful text
*
* @return string range description
*/
public function rangeName() {
switch ($this->parameter ['date']) {
case 'last30' :
return __('last 30 days', 'wp-piwik' );
case 'last12' :
return __('last 12 ' . $this->parameter ['period'] . 's', 'wp-piwik' );
default :
return $this->parameter ['date'];
}
}
/**
* Get the widget name
*
* @return string widget name
*/
public function getName() {
return str_replace ( '\\', '-', get_called_class () );
}
/**
* Display a pie chart
*
* @param
* array chart data array(array(0 => name, 1 => value))
*/
public function pieChart($data) {
$this->out( '<div id="wp-piwik_stats_' . $this->getName () . '_graph" style="height:310px;width:100%"></div>' );
$this->out( '<script type="text/javascript">$plotBrowsers = $j.jqplot("wp-piwik_stats_' . $this->getName () . '_graph", [[' );
$list = '';
foreach ( $data as $key => $dataSet ) {
$list .= '["' . $dataSet [0] . '", ' . $dataSet [1] . '],';
if ($key == 'Others') break;
}
$this->out( substr ( $list, 0, - 1 ) );
$this->out( ']], {seriesDefaults:{renderer:$j.jqplot.PieRenderer, rendererOptions:{sliceMargin:8}},legend:{show:true}});</script>' );
}
/**
* Return an array value by key, return '-' if not set
*
* @param array $array
* array to get a value from
* @param string $key
* key of the value to get from array
* @return string found value or '-' as a placeholder
*/
protected function value($array, $key) {
return (isset ( $array [$key] ) ? $array [$key] : '-');
}
<?php
namespace WP_Piwik;
/**
* Abstract widget class
*
* @author Andr&eacute; Br&auml;kling
* @package WP_Piwik
*/
abstract class Widget {
/**
*
* @var Environment variables
*/
protected static $wpPiwik, $settings;
/**
*
* @var Configuration parameters
*/
protected $isShortcode = false, $method = '', $title = '', $context = 'side', $priority = 'core', $parameter = array (), $apiID = array (), $pageId = 'dashboard', $blogId = null, $name = 'Value', $limit = 10, $content = '', $output = '';
/**
* Widget constructor
*
* @param WP_Piwik $wpPiwik
* current WP-Piwik object
* @param WP_Piwik\Settings $settings
* current WP-Piwik settings
* @param string $pageId
* WordPress page ID (default: dashboard)
* @param string $context
* WordPress meta box context (defualt: side)
* @param string $priority
* WordPress meta box priority (default: default)
* @param array $params
* widget parameters (default: empty array)
* @param boolean $isShortcode
* is the widget shown inline? (default: false)
*/
public function __construct($wpPiwik, $settings, $pageId = 'dashboard', $context = 'side', $priority = 'default', $params = array(), $isShortcode = false) {
self::$wpPiwik = $wpPiwik;
self::$settings = $settings;
$this->pageId = $pageId;
$this->context = $context;
$this->priority = $priority;
if (self::$settings->checkNetworkActivation () && function_exists ( 'is_super_admin' ) && is_super_admin () && isset ( $_GET ['wpmu_show_stats'] )) {
switch_to_blog ( ( int ) $_GET ['wpmu_show_stats'] );
$this->blogId = get_current_blog_id ();
restore_current_blog ();
}
$this->isShortcode = $isShortcode;
$prefix = ($this->pageId == 'dashboard' ? self::$settings->getGlobalOption ( 'plugin_display_name' ) . ' - ' : '');
$this->configure ( $prefix, $params );
if (is_array ( $this->method ))
foreach ( $this->method as $method ) {
$this->apiID [$method] = \WP_Piwik\Request::register ( $method, $this->parameter );
self::$wpPiwik->log ( "Register request: " . $this->apiID [$method] );
}
else {
$this->apiID [$this->method] = \WP_Piwik\Request::register ( $this->method, $this->parameter );
self::$wpPiwik->log ( "Register request: " . $this->apiID [$this->method] );
}
if ($this->isShortcode)
return;
add_meta_box ( $this->getName (), $this->title, array (
$this,
'show'
), $pageId, $this->context, $this->priority );
}
/**
* Conifguration dummy method
*
* @param string $prefix
* metabox title prefix (default: empty)
* @param array $params
* widget parameters (default: empty array)
*/
protected function configure($prefix = '', $params = array()) {
}
/**
* Default show widget method, handles default Piwik output
*/
public function show() {
$response = self::$wpPiwik->request ( $this->apiID [$this->method] );
if (! empty ( $response ['result'] ) && $response ['result'] == 'error')
$this->out( '<strong>' . __ ( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . htmlentities ( $response ['message'], ENT_QUOTES, 'utf-8' ) );
else {
if (isset ( $response [0] ['nb_uniq_visitors'] ))
$unique = 'nb_uniq_visitors';
else
$unique = 'sum_daily_nb_uniq_visitors';
$tableHead = array (
'label' => __ ( $this->name, 'wp-piwik' )
);
$tableHead [$unique] = __ ( 'Unique', 'wp-piwik' );
if (isset ( $response [0] ['nb_visits'] ))
$tableHead ['nb_visits'] = __ ( 'Visits', 'wp-piwik' );
if (isset ( $response [0] ['nb_hits'] ))
$tableHead ['nb_hits'] = __ ( 'Hits', 'wp-piwik' );
if (isset ( $response [0] ['nb_actions'] ))
$tableHead ['nb_actions'] = __ ( 'Actions', 'wp-piwik' );
$tableBody = array ();
$count = 0;
if (is_array($response))
foreach ( $response as $rowKey => $row ) {
$count ++;
$tableBody [$rowKey] = array ();
foreach ( $tableHead as $key => $value )
$tableBody [$rowKey] [] = isset ( $row [$key] ) ? $row [$key] : '-';
if ($count == 10)
break;
}
$this->table ( $tableHead, $tableBody, null );
}
}
/**
* Display or store shortcode output
*/
protected function out($output) {
if ($this->isShortcode)
$this->output .= $output;
else echo $output;
}
/**
* Return shortcode output
*/
public function get() {
return $this->output;
}
/**
* Display a HTML table
*
* @param array $thead
* table header content (array of cells)
* @param array $tbody
* table body content (array of rows)
* @param array $tfoot
* table footer content (array of cells)
* @param string $class
* CSSclass name to apply on table sections
* @param string $javaScript
* array of javascript code to apply on body rows
*/
protected function table($thead, $tbody = array(), $tfoot = array(), $class = false, $javaScript = array(), $classes = array()) {
$this->out( '<div class="table"><table class="widefat wp-piwik-table">' );
if ($this->isShortcode && $this->title) {
$colspan = !empty ( $tbody ) ? count( $tbody[0] ) : 2 ;
$this->out( '<tr><th colspan="'.$colspan.'">' . $this->title . '</th></tr>' );
}
if (! empty ( $thead ))
$this->tabHead ( $thead, $class );
if (! empty ( $tbody ))
$this->tabBody ( $tbody, $class, $javaScript, $classes );
else
$this->out( '<tr><td colspan="10">' . __ ( 'No data available.', 'wp-piwik' ) . '</td></tr>' );
if (! empty ( $tfoot ))
$this->tabFoot ( $tfoot, $class );
$this->out( '</table></div>' );
}
/**
* Display a HTML table header
*
* @param array $thead
* array of cells
* @param string $class
* CSS class to apply
*/
private function tabHead($thead, $class = false) {
$this->out( '<thead' . ($class ? ' class="' . $class . '"' : '') . '><tr>' );
$count = 0;
foreach ( $thead as $value )
$this->out( '<th' . ($count ++ ? ' class="right"' : '') . '>' . $value . '</th>' );
$this->out( '</tr></thead>' );
}
/**
* Display a HTML table body
*
* @param array $tbody
* array of rows, each row containing an array of cells
* @param string $class
* CSS class to apply
* @param unknown $javaScript
* array of javascript code to apply (one item per row)
*/
private function tabBody($tbody, $class = false, $javaScript = array(), $classes = array()) {
$this->out( '<tbody' . ($class ? ' class="' . $class . '"' : '') . '>' );
foreach ( $tbody as $key => $trow )
$this->tabRow ( $trow, isset( $javaScript [$key] ) ?$javaScript [$key] : '', isset ( $classes [$key] ) ?$classes [$key] : '');
$this->out( '</tbody>' );
}
/**
* Display a HTML table footer
*
* @param array $tfoor
* array of cells
* @param string $class
* CSS class to apply
*/
private function tabFoot($tfoot, $class = false) {
$this->out( '<tfoot' . ($class ? ' class="' . $class . '"' : '') . '><tr>' );
$count = 0;
foreach ( $tfoot as $value )
$this->out( '<td' . ($count ++ ? ' class="right"' : '') . '>' . $value . '</td>' );
$this->out( '</tr></tfoot>' );
}
/**
* Display a HTML table row
*
* @param array $trow
* array of cells
* @param string $javaScript
* javascript code to apply
*/
private function tabRow($trow, $javaScript = '', $class = '') {
$this->out( '<tr' . (! empty ( $javaScript ) ? ' onclick="' . $javaScript . '"' : '') . (! empty ( $class ) ? ' class="' . $class . '"' : '') . '>' );
$count = 0;
foreach ( $trow as $tcell )
$this->out( '<td' . ($count ++ ? ' class="right"' : '') . '>' . $tcell . '</td>' );
$this->out( '</tr>' );
}
/**
* Get the current request's Piwik time settings
*
* @return array time settings: period => Piwik period, date => requested date, description => time description to show in widget title
*/
protected function getTimeSettings() {
switch (self::$settings->getGlobalOption ( 'default_date' )) {
case 'today' :
$period = 'day';
$date = 'today';
$description = __('today', 'wp-piwik' );
break;
case 'current_month' :
$period = 'month';
$date = 'today';
$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', 'wp-piwik' );
break;
case 'current_week' :
$period = 'week';
$date = 'today';
$description = __('current week', 'wp-piwik' );
break;
case 'last_week' :
$period = 'week';
$date = date ( "Y-m-d", strtotime ( "-1 week" ) );
$description = __('last week', 'wp-piwik' );
break;
case 'yesterday' :
$period = 'day';
$date = 'yesterday';
$description = __('yesterday', 'wp-piwik' );
break;
default :
break;
}
return array (
'period' => $period,
'date' => isset ( $_GET ['date'] ) ? ( int ) $_GET ['date'] : $date,
'description' => isset ( $_GET ['date'] ) ? $this->dateFormat ( $_GET ['date'], $period ) : $description
);
}
/**
* Format a date to show in widget
*
* @param string $date
* date string
* @param string $period
* Piwik period
* @return string formatted date
*/
protected function dateFormat($date, $period = 'day') {
$prefix = '';
switch ($period) {
case 'week' :
$prefix = __ ( 'week', 'wp-piwik' ) . ' ';
$format = 'W/Y';
break;
case 'short_week' :
$format = 'W';
break;
case 'month' :
$format = 'F Y';
$date = date ( 'Y-m-d', strtotime ( $date ) );
break;
default :
$format = get_option ( 'date_format' );
}
return $prefix . date_i18n ( $format, strtotime ( $date ) );
}
/**
* Format time to show in widget
*
* @param int $time
* time in seconds
* @return string formatted time
*/
protected function timeFormat($time) {
return floor ( $time / 3600 ) . 'h ' . floor ( ($time % 3600) / 60 ) . 'm ' . floor ( ($time % 3600) % 60 ) . 's';
}
/**
* Convert Piwik range into meaningful text
*
* @return string range description
*/
public function rangeName() {
switch ($this->parameter ['date']) {
case 'last30' :
return __('last 30 days', 'wp-piwik' );
case 'last12' :
return __('last 12 ' . $this->parameter ['period'] . 's', 'wp-piwik' );
default :
return $this->parameter ['date'];
}
}
/**
* Get the widget name
*
* @return string widget name
*/
public function getName() {
return str_replace ( '\\', '-', get_called_class () );
}
/**
* Display a pie chart
*
* @param
* array chart data array(array(0 => name, 1 => value))
*/
public function pieChart($data) {
$this->out( '<div id="wp-piwik_stats_' . $this->getName () . '_graph" style="height:310px;width:100%"></div>' );
$this->out( '<script type="text/javascript">$plotBrowsers = $j.jqplot("wp-piwik_stats_' . $this->getName () . '_graph", [[' );
$list = '';
foreach ( $data as $key => $dataSet ) {
$list .= '["' . $dataSet [0] . '", ' . $dataSet [1] . '],';
if ($key == 'Others') break;
}
$this->out( substr ( $list, 0, - 1 ) );
$this->out( ']], {seriesDefaults:{renderer:$j.jqplot.PieRenderer, rendererOptions:{sliceMargin:8}},legend:{show:true}});</script>' );
}
/**
* Return an array value by key, return '-' if not set
*
* @param array $array
* array to get a value from
* @param string $key
* key of the value to get from array
* @return string found value or '-' as a placeholder
*/
protected function value($array, $key) {
return (isset ( $array [$key] ) ? $array [$key] : '-');
}
}

View File

@ -1,9 +1,9 @@
<?php
/******************************************************
* Configure WP-Piwik Logger
* 0: Logger disabled
* 1: Log to screen
* 2: Log to file (logs/YYYYMMDD_wp-piwik.log)
******************************************************/
<?php
/******************************************************
* Configure WP-Piwik Logger
* 0: Logger disabled
* 1: Log to screen
* 2: Log to file (logs/YYYYMMDD_wp-piwik.log)
******************************************************/
define ( 'WP_PIWIK_ACTIVATE_LOGGER', 0 );

View File

@ -1,2 +1,2 @@
<?php
<?php
// Nothing to see...

View File

@ -1,3 +1,3 @@
.wp-piwik_dynbar canvas {
padding-top: 5px !important
.wp-piwik_dynbar canvas {
padding-top: 5px !important
}

View File

@ -1,2 +1,2 @@
<?php
<?php
// Nothing to see...

View File

@ -1,2 +1,2 @@
<?php
<?php
// Nothing to see...

File diff suppressed because one or more lines are too long

View File

@ -1,2 +1,2 @@
<?php
<?php
// Nothing to see...

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,3 @@
/* jqPlot 1.0.8r1250 | (c) 2009-2013 Chris Leonello | jplot.com
jsDate | (c) 2010-2013 Chris Leonello
/* jqPlot 1.0.8r1250 | (c) 2009-2013 Chris Leonello | jplot.com
jsDate | (c) 2010-2013 Chris Leonello
*/(function(f){f.jqplot.Trendline=function(){this.show=f.jqplot.config.enablePlugins;this.color="#666666";this.renderer=new f.jqplot.LineRenderer();this.rendererOptions={marker:{show:false}};this.label="";this.type="linear";this.shadow=true;this.markerRenderer={show:false};this.lineWidth=1.5;this.shadowAngle=45;this.shadowOffset=1;this.shadowAlpha=0.07;this.shadowDepth=3;this.isTrendline=true};f.jqplot.postSeriesInitHooks.push(e);f.jqplot.postDrawSeriesHooks.push(g);f.jqplot.addLegendRowHooks.push(a);function a(k){var j=null;if(k.trendline&&k.trendline.show){var i=k.trendline.label.toString();if(i){j={label:i,color:k.trendline.color}}}return j}function e(m,k,j,i,l){if(this._type&&(this._type==="line"||this._type=="bar")){this.trendline=new f.jqplot.Trendline();i=i||{};f.extend(true,this.trendline,{color:this.color},j.trendline,i.trendline);this.trendline.renderer.init.call(this.trendline,null)}}function g(m,i){i=f.extend(true,{},this.trendline,i);if(this.trendline&&i.show){var k;var l=i.data||this.data;k=c(l,this.trendline.type);var j=i.gridData||this.renderer.makeGridData.call(this,k.data);this.trendline.renderer.draw.call(this.trendline,m,j,{showLine:true,shadow:this.trendline.shadow})}}function b(w,v,n){var u=(n==null)?"linear":n;var s=w.length;var t;var z;var o=0;var m=0;var r=0;var q=0;var l=0;var j=[];var k=[];if(u=="linear"){k=w;j=v}else{if(u=="exp"||u=="exponential"){for(var p=0;p<v.length;p++){if(v[p]<=0){s--}else{k.push(w[p]);j.push(Math.log(v[p]))}}}}for(var p=0;p<s;p++){o=o+k[p];m=m+j[p];q=q+k[p]*j[p];r=r+k[p]*k[p];l=l+j[p]*j[p]}t=(s*q-o*m)/(s*r-o*o);z=(m-t*o)/s;return[t,z]}function h(k,j){var i;i=b(k,j,"linear");return[i[0],i[1]]}function d(o,m){var k;var i=o;var n=m;k=b(i,n,"exp");var l=Math.exp(k[0]);var j=Math.exp(k[1]);return[l,j]}function c(l,j){var p=(j==null)?"linear":j;var n;var o;var r=[];var q=[];var m=[];for(k=0;k<l.length;k++){if(l[k]!=null&&l[k][0]!=null&&l[k][1]!=null){r.push(l[k][0]);q.push(l[k][1])}}if(p=="linear"){n=h(r,q);for(var k=0;k<r.length;k++){o=n[0]*r[k]+n[1];m.push([r[k],o])}}else{if(p=="exp"||p=="exponential"){n=d(r,q);for(var k=0;k<r.length;k++){o=n[1]*Math.pow(n[0],r[k]);m.push([r[k],o])}}}return{data:m,slope:n[0],intercept:n[1]}}})(jQuery);

File diff suppressed because one or more lines are too long

View File

@ -1,2 +1,2 @@
<?php
<?php
// Nothing to see...

View File

@ -1,39 +1,39 @@
<?php
$wpRootDir = isset($wpRootDir)?$wpRootDir:'../../../../';
require ($wpRootDir.'wp-load.php');
require_once ('../classes/WP_Piwik/Settings.php');
require_once ('../classes/WP_Piwik/Logger.php');
require_once ('../classes/WP_Piwik/Logger/Dummy.php');
$logger = new WP_Piwik\Logger\Dummy ( __CLASS__ );
$settings = new WP_Piwik\Settings ( $logger );
$protocol = (isset ( $_SERVER ['HTTPS'] ) && $_SERVER ['HTTPS'] != 'off') ? 'https' : 'http';
switch ($settings->getGlobalOption ( 'piwik_mode' )) {
case 'php' :
$PIWIK_URL = $protocol . ':' . $settings->getGlobalOption ( 'proxy_url' );
break;
case 'cloud' :
$PIWIK_URL = 'https://' . $settings->getGlobalOption ( 'piwik_user' ) . '.innocraft.cloud/';
break;
case 'cloud-matomo' :
$PIWIK_URL = 'https://' . $settings->getGlobalOption ( 'matomo_user' ) . '.matomo.cloud/';
break;
default :
$PIWIK_URL = $settings->getGlobalOption ( 'piwik_url' );
}
if (substr ( $PIWIK_URL, 0, 2 ) == '//')
$PIWIK_URL = (isset ( $_SERVER ['HTTPS'] ) ? 'https:' : 'http:') . $PIWIK_URL;
$TOKEN_AUTH = $settings->getGlobalOption ( 'piwik_token' );
$timeout = $settings->getGlobalOption ( 'connection_timeout' );
$useCurl = (
(function_exists('curl_init') && ini_get('allow_url_fopen') && $settings->getGlobalOption('http_connection') == 'curl') || (function_exists('curl_init') && !ini_get('allow_url_fopen'))
);
$settings->getGlobalOption ( 'http_connection' );
<?php
$wpRootDir = isset($wpRootDir)?$wpRootDir:'../../../../';
require ($wpRootDir.'wp-load.php');
require_once ('../classes/WP_Piwik/Settings.php');
require_once ('../classes/WP_Piwik/Logger.php');
require_once ('../classes/WP_Piwik/Logger/Dummy.php');
$logger = new WP_Piwik\Logger\Dummy ( __CLASS__ );
$settings = new WP_Piwik\Settings ( $logger );
$protocol = (isset ( $_SERVER ['HTTPS'] ) && $_SERVER ['HTTPS'] != 'off') ? 'https' : 'http';
switch ($settings->getGlobalOption ( 'piwik_mode' )) {
case 'php' :
$PIWIK_URL = $protocol . ':' . $settings->getGlobalOption ( 'proxy_url' );
break;
case 'cloud' :
$PIWIK_URL = 'https://' . $settings->getGlobalOption ( 'piwik_user' ) . '.innocraft.cloud/';
break;
case 'cloud-matomo' :
$PIWIK_URL = 'https://' . $settings->getGlobalOption ( 'matomo_user' ) . '.matomo.cloud/';
break;
default :
$PIWIK_URL = $settings->getGlobalOption ( 'piwik_url' );
}
if (substr ( $PIWIK_URL, 0, 2 ) == '//')
$PIWIK_URL = (isset ( $_SERVER ['HTTPS'] ) ? 'https:' : 'http:') . $PIWIK_URL;
$TOKEN_AUTH = $settings->getGlobalOption ( 'piwik_token' );
$timeout = $settings->getGlobalOption ( 'connection_timeout' );
$useCurl = (
(function_exists('curl_init') && ini_get('allow_url_fopen') && $settings->getGlobalOption('http_connection') == 'curl') || (function_exists('curl_init') && !ini_get('allow_url_fopen'))
);
$settings->getGlobalOption ( 'http_connection' );
ini_set ( 'display_errors', 0 );

View File

@ -1,2 +1,2 @@
<?php
<?php
// Nothing to see...

View File

@ -1,9 +1,9 @@
=== WP-Matomo (WP-Piwik) ===
=== WP-Matomo Integration (WP-Piwik) ===
Contributors: Braekling
Requires at least: 4.0
Tested up to: 5.2.2
Stable tag: 1.0.22
Requires at least: 5.0
Tested up to: 5.5.1
Stable tag: 1.0.24
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
Tags: matomo, tracking, statistics, stats, analytics
@ -11,6 +11,8 @@ Adds Matomo (former Piwik) statistics to your WordPress dashboard and is also ab
== Description ==
If you are not yet using Matomo On-Premise, Matomo Cloud or hosting your own instance of Matomo, please use the [Matomo for WordPress plugin](https://wordpress.org/plugins/matomo/).
This plugin uses the Matomo API to show your Matomo statistics in your WordPress dashboard. It's also able to add the Matomo tracking code to your blog and to do some modifications to the tracking code. Additionally, WP-Matomo supports WordPress networks and manages multiple sites and their tracking codes.
To use this plugin the Matomo web analytics application is required. If you do not already have a Matomo setup (e.g., provided by your web hosting service), you have two simple options: use either a [self-hosted Matomo](http://matomo.org/) or a [cloud-hosted Matomo by InnoCraft](https://www.innocraft.cloud/?pk_campaign=WP-Piwik).
@ -48,7 +50,7 @@ is equal to *[wp-piwik module="overview" title="" period="day" date="yesterday"]
* 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).
* All translators at Transifex and WordPress.
* 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., Addy K., Hans-Georg E.-B., Yvonne K., Andrew D., Nicolas J., Andre M., Steve J., Jakub P., ditho.berlin, Robert R., Simon B., Grzegorz O., Bjarne O., the Matomo team itself, and all people flattering this.
* 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., Addy K., Hans-Georg E.-B., Yvonne K., Andrew D., Nicolas J., Andre M., Steve J., Jakub P., ditho.berlin, Robert R., Simon B., Grzegorz O., Bjarne O., Georg H., Tino S., Carola H., Bo K. C., Timothy T., Heinz L., the Matomo team itself, and all people flattering this.
* All users who send me mails containing criticism, commendation, feature requests and bug reports - you help me to make WP-Matomo much better!
Thank you all!
@ -141,6 +143,14 @@ Add WP-Matomo to your /wp-content/plugins folder and enable it as [Network Plugi
== Changelog ==
= 1.0.24 =
* Hotfix to avoid deprecated jQuery.support.boxModel in jqPlot (https://github.com/jqPlot/jqPlot/issues/123)
* Enabling metaboxes on particular Custom Post Types (thanks to goaround, https://github.com/braekling/WP-Matomo/pull/83)
= 1.0.23 =
* Handle tracking codes containing matomo.js/.php instead of piwik.js/.php
* Fixed target="_BLANK" property (thanks to tsteur)
= 1.0.22 =
* Bugfix: Innocraft cloud URL *.matomo.cloud will work
* Option to configure filter_limit parameter (see expert settings)

View File

@ -1,41 +1,41 @@
<?php
// Get & delete old version's options
if (self::$settings->checkNetworkActivation ()) {
$oldGlobalOptions = get_site_option ( 'wp-piwik_global-settings', array () );
delete_site_option('wp-piwik_global-settings');
} else {
$oldGlobalOptions = get_option ( 'wp-piwik_global-settings', array () );
delete_option('wp-piwik_global-settings');
}
$oldOptions = get_option ( 'wp-piwik_settings', array () );
delete_option('wp-piwik_settings');
if (self::$settings->checkNetworkActivation ()) {
global $wpdb;
$aryBlogs = \WP_Piwik\Settings::getBlogList();
if (is_array($aryBlogs))
foreach ($aryBlogs as $aryBlog) {
$oldOptions = get_blog_option ( $aryBlog['blog_id'], 'wp-piwik_settings', array () );
if (!$this->isConfigured())
foreach ( $oldOptions as $key => $value )
self::$settings->setOption ( $key, $value, $aryBlog['blog_id'] );
delete_blog_option($aryBlog['blog_id'], 'wp-piwik_settings');
}
}
if (!$this->isConfigured()) {
if (!$oldGlobalOptions['add_tracking_code']) $oldGlobalOptions['track_mode'] = 'disabled';
elseif (!$oldGlobalOptions['track_mode']) $oldGlobalOptions['track_mode'] = 'default';
elseif ($oldGlobalOptions['track_mode'] == 1) $oldGlobalOptions['track_mode'] = 'js';
elseif ($oldGlobalOptions['track_mode'] == 2) $oldGlobalOptions['track_mode'] = 'proxy';
// Store old values in new settings
foreach ( $oldGlobalOptions as $key => $value )
self::$settings->setGlobalOption ( $key, $value );
foreach ( $oldOptions as $key => $value )
self::$settings->setOption ( $key, $value );
}
<?php
// Get & delete old version's options
if (self::$settings->checkNetworkActivation ()) {
$oldGlobalOptions = get_site_option ( 'wp-piwik_global-settings', array () );
delete_site_option('wp-piwik_global-settings');
} else {
$oldGlobalOptions = get_option ( 'wp-piwik_global-settings', array () );
delete_option('wp-piwik_global-settings');
}
$oldOptions = get_option ( 'wp-piwik_settings', array () );
delete_option('wp-piwik_settings');
if (self::$settings->checkNetworkActivation ()) {
global $wpdb;
$aryBlogs = \WP_Piwik\Settings::getBlogList();
if (is_array($aryBlogs))
foreach ($aryBlogs as $aryBlog) {
$oldOptions = get_blog_option ( $aryBlog['blog_id'], 'wp-piwik_settings', array () );
if (!$this->isConfigured())
foreach ( $oldOptions as $key => $value )
self::$settings->setOption ( $key, $value, $aryBlog['blog_id'] );
delete_blog_option($aryBlog['blog_id'], 'wp-piwik_settings');
}
}
if (!$this->isConfigured()) {
if (!$oldGlobalOptions['add_tracking_code']) $oldGlobalOptions['track_mode'] = 'disabled';
elseif (!$oldGlobalOptions['track_mode']) $oldGlobalOptions['track_mode'] = 'default';
elseif ($oldGlobalOptions['track_mode'] == 1) $oldGlobalOptions['track_mode'] = 'js';
elseif ($oldGlobalOptions['track_mode'] == 2) $oldGlobalOptions['track_mode'] = 'proxy';
// Store old values in new settings
foreach ( $oldGlobalOptions as $key => $value )
self::$settings->setGlobalOption ( $key, $value );
foreach ( $oldOptions as $key => $value )
self::$settings->setOption ( $key, $value );
}
self::$settings->save ();

View File

@ -1,9 +1,9 @@
<?php
$aryWPMUConfig = get_site_option ( 'wpmu-piwik_global-settings', false );
if (self::$settings->checkNetworkActivation () && $aryWPMUConfig) {
foreach ( $aryWPMUConfig as $key => $value )
self::$settings->setGlobalOption ( $key, $value );
delete_site_option ( 'wpmu-piwik_global-settings' );
self::$settings->setGlobalOption ( 'auto_site_config', true );
} else
<?php
$aryWPMUConfig = get_site_option ( 'wpmu-piwik_global-settings', false );
if (self::$settings->checkNetworkActivation () && $aryWPMUConfig) {
foreach ( $aryWPMUConfig as $key => $value )
self::$settings->setGlobalOption ( $key, $value );
delete_site_option ( 'wpmu-piwik_global-settings' );
self::$settings->setGlobalOption ( 'auto_site_config', true );
} else
self::$settings->setGlobalOption ( 'auto_site_config', false );

View File

@ -1,5 +1,5 @@
<?php
if (self::$settings->getGlobalOption ( 'track_compress' ))
self::$settings->setGlobalOption ( 'track_mode', 1 );
else
<?php
if (self::$settings->getGlobalOption ( 'track_compress' ))
self::$settings->setGlobalOption ( 'track_mode', 1 );
else
self::$settings->setGlobalOption ( 'track_mode', 0 );

View File

@ -1,10 +1,10 @@
<?php
$aryRemoveOptions = array (
'wp-piwik_siteid',
'wp-piwik_404',
'wp-piwik_scriptupdate',
'wp-piwik_dashboardid',
'wp-piwik_jscode'
);
foreach ( $aryRemoveOptions as $strRemoveOption )
<?php
$aryRemoveOptions = array (
'wp-piwik_siteid',
'wp-piwik_404',
'wp-piwik_scriptupdate',
'wp-piwik_dashboardid',
'wp-piwik_jscode'
);
foreach ( $aryRemoveOptions as $strRemoveOption )
delete_option ( $strRemoveOption );

View File

@ -1,83 +1,83 @@
<?php
/*
Plugin Name: WP-Matomo
Plugin URI: http://wordpress.org/extend/plugins/wp-piwik/
Description: Adds Matomo statistics to your WordPress dashboard and is also able to add the Matomo Tracking Code to your blog.
Version: 1.0.22
Author: Andr&eacute; Br&auml;kling
Author URI: https://www.braekling.de
Text Domain: wp-piwik
Domain Path: /languages
License: GPL3
******************************************************************************************
Copyright (C) 2009-today Andre Braekling (email: webmaster@braekling.de)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************************/
if (! function_exists ( 'add_action' )) {
header ( 'Status: 403 Forbidden' );
header ( 'HTTP/1.1 403 Forbidden' );
exit ();
}
if (! defined ( 'NAMESPACE_SEPARATOR' ))
define ( 'NAMESPACE_SEPARATOR', '\\' );
/**
* Define WP-Piwik autoloader
*
* @param string $class
* class name
*/
function wp_piwik_autoloader($class) {
if (substr ( $class, 0, 9 ) == 'WP_Piwik' . NAMESPACE_SEPARATOR) {
$class = str_replace ( '.', '', str_replace ( NAMESPACE_SEPARATOR, DIRECTORY_SEPARATOR, substr ( $class, 9 ) ) );
require_once ('classes' . DIRECTORY_SEPARATOR . 'WP_Piwik' . DIRECTORY_SEPARATOR . $class . '.php');
}
}
/**
* Show notice about outdated PHP version
*/
function wp_piwik_phperror() {
echo '<div class="error"><p>';
printf ( __ ( 'WP-Piwik requires at least PHP 5.3. You are using the deprecated version %s. Please update PHP to use WP-Piwik.', 'wp-piwik' ), PHP_VERSION );
echo '</p></div>';
}
function wp_piwik_load_textdomain() {
load_plugin_textdomain( 'wp-piwik', false, plugin_basename( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR );
}
add_action( 'plugins_loaded', 'wp_piwik_load_textdomain' );
if (version_compare ( PHP_VERSION, '5.3.0', '<' ))
add_action ( 'admin_notices', 'wp_piwik_phperror' );
else {
define ( 'WP_PIWIK_PATH', dirname ( __FILE__ ) . DIRECTORY_SEPARATOR );
require_once (WP_PIWIK_PATH . 'config.php');
require_once (WP_PIWIK_PATH . 'classes' . DIRECTORY_SEPARATOR . 'WP_Piwik.php');
spl_autoload_register ( 'wp_piwik_autoloader' );
$GLOBALS ['wp-piwik_debug'] = false;
if (class_exists ( 'WP_Piwik' ))
add_action( 'init', 'wp_piwik_loader' );
}
function wp_piwik_loader() {
$GLOBALS ['wp-piwik'] = new WP_Piwik ();
}
<?php
/*
Plugin Name: WP-Matomo Integration
Plugin URI: http://wordpress.org/extend/plugins/wp-piwik/
Description: Adds Matomo statistics to your WordPress dashboard and is also able to add the Matomo Tracking Code to your blog.
Version: 1.0.24
Author: Andr&eacute; Br&auml;kling
Author URI: https://www.braekling.de
Text Domain: wp-piwik
Domain Path: /languages
License: GPL3
******************************************************************************************
Copyright (C) 2009-today Andre Braekling (email: webmaster@braekling.de)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************************/
if (! function_exists ( 'add_action' )) {
header ( 'Status: 403 Forbidden' );
header ( 'HTTP/1.1 403 Forbidden' );
exit ();
}
if (! defined ( 'NAMESPACE_SEPARATOR' ))
define ( 'NAMESPACE_SEPARATOR', '\\' );
/**
* Define WP-Piwik autoloader
*
* @param string $class
* class name
*/
function wp_piwik_autoloader($class) {
if (substr ( $class, 0, 9 ) == 'WP_Piwik' . NAMESPACE_SEPARATOR) {
$class = str_replace ( '.', '', str_replace ( NAMESPACE_SEPARATOR, DIRECTORY_SEPARATOR, substr ( $class, 9 ) ) );
require_once ('classes' . DIRECTORY_SEPARATOR . 'WP_Piwik' . DIRECTORY_SEPARATOR . $class . '.php');
}
}
/**
* Show notice about outdated PHP version
*/
function wp_piwik_phperror() {
echo '<div class="error"><p>';
printf ( __ ( 'WP-Piwik requires at least PHP 5.3. You are using the deprecated version %s. Please update PHP to use WP-Piwik.', 'wp-piwik' ), PHP_VERSION );
echo '</p></div>';
}
function wp_piwik_load_textdomain() {
load_plugin_textdomain( 'wp-piwik', false, plugin_basename( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR );
}
add_action( 'plugins_loaded', 'wp_piwik_load_textdomain' );
if (version_compare ( PHP_VERSION, '5.3.0', '<' ))
add_action ( 'admin_notices', 'wp_piwik_phperror' );
else {
define ( 'WP_PIWIK_PATH', dirname ( __FILE__ ) . DIRECTORY_SEPARATOR );
require_once (WP_PIWIK_PATH . 'config.php');
require_once (WP_PIWIK_PATH . 'classes' . DIRECTORY_SEPARATOR . 'WP_Piwik.php');
spl_autoload_register ( 'wp_piwik_autoloader' );
$GLOBALS ['wp-piwik_debug'] = false;
if (class_exists ( 'WP_Piwik' ))
add_action( 'init', 'wp_piwik_loader' );
}
function wp_piwik_loader() {
$GLOBALS ['wp-piwik'] = new WP_Piwik ();
}