updated plugin Connect Matomo version 1.1.5
This commit is contained in:
10
wp-content/plugins/wp-piwik/.editorconfig
Normal file
10
wp-content/plugins/wp-piwik/.editorconfig
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.php]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
||||||
3
wp-content/plugins/wp-piwik/.gitignore
vendored
3
wp-content/plugins/wp-piwik/.gitignore
vendored
@ -1,2 +1,5 @@
|
|||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
node_modules/
|
||||||
|
vendor/
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
234
wp-content/plugins/wp-piwik/classes/WP_Piwik/AIBotTracking.php
Normal file
234
wp-content/plugins/wp-piwik/classes/WP_Piwik/AIBotTracking.php
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Matomo - free/libre analytics platform
|
||||||
|
*
|
||||||
|
* @link https://matomo.org
|
||||||
|
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||||
|
* @package matomo
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace WP_Piwik;
|
||||||
|
|
||||||
|
use LiteSpeed\ESI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs server side tracking for AI bots.
|
||||||
|
*
|
||||||
|
* Normal server side tracking: when no caching plugins or CDNs are being
|
||||||
|
* used, this class will send tracking requests in the wp_footer hook.
|
||||||
|
*
|
||||||
|
* When advanced-cache.php is used: when a caching plugin creates an
|
||||||
|
* advanced-cache.php file that WordPress uses, tracking must be done
|
||||||
|
* through the standalone script in misc/track_ai_bot.php. This script
|
||||||
|
* must be manually added to a user's wp-config.php file, right after
|
||||||
|
* ABSPATH is defined.
|
||||||
|
*
|
||||||
|
* When .htaccess is used: when a caching plugin modifies the .htaccess
|
||||||
|
* to serve cached files directly, AI bot tracking is not possible.
|
||||||
|
*
|
||||||
|
* When a CDN is used: when a CDN is used to serve cached content, AI
|
||||||
|
* bot tracking can be accomplished through the use of ESI (Edge Side Includes).
|
||||||
|
* In this case, this class outputs an `<esi:include>` directive that
|
||||||
|
* loads the misc/track_ai_bot.php script. This technique will only work
|
||||||
|
* for CDNs that support ESI.
|
||||||
|
*
|
||||||
|
* The misc/track_ai_bot.php script uses this class without all of WordPress loaded.
|
||||||
|
* It can also be loaded outside of WordPress. Because of this, it is important
|
||||||
|
* that the script and this class use as few total dependencies as possible. Otherwise,
|
||||||
|
* AI bot tracking reduce the performance of requests to cached content.
|
||||||
|
*/
|
||||||
|
class AIBotTracking {
|
||||||
|
|
||||||
|
private static $ai_bot_tracked = false;
|
||||||
|
|
||||||
|
private static $extensions_to_track = array(
|
||||||
|
'', // no extension
|
||||||
|
|
||||||
|
'htm',
|
||||||
|
'html',
|
||||||
|
'php',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Settings
|
||||||
|
*/
|
||||||
|
private $settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Logger
|
||||||
|
*/
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var AjaxTracker|null
|
||||||
|
*/
|
||||||
|
private $tracker = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Settings $settings
|
||||||
|
* @param Logger $logger
|
||||||
|
*/
|
||||||
|
public function __construct( Settings $settings, Logger $logger ) {
|
||||||
|
$this->settings = $settings;
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function register_hooks() {
|
||||||
|
add_action( 'litespeed_init', array( $this, 'litespeed_init' ) );
|
||||||
|
add_action( 'wp_footer', array( $this, 'do_ai_bot_tracking' ), 999999 );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function litespeed_init() {
|
||||||
|
if ( class_exists( ESI::class )
|
||||||
|
&& $this->settings->is_ai_bot_tracking_enabled_via_esi_includes()
|
||||||
|
) {
|
||||||
|
ESI::set_has_esi();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|null $url
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function do_ai_bot_tracking( $url = null ) {
|
||||||
|
// track AI bots only once per request
|
||||||
|
if ( self::$ai_bot_tracked ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$ai_bot_tracked = true;
|
||||||
|
|
||||||
|
// if using ESI to track, and not within the track_ai_bot.php script, output the appropriate ESI tag
|
||||||
|
$is_using_esi_to_track = $this->settings->is_ai_bot_tracking_enabled_via_esi_includes();
|
||||||
|
if (
|
||||||
|
$is_using_esi_to_track
|
||||||
|
&& empty( $GLOBALS['WP_PIWIK_IN_ESI'] )
|
||||||
|
) {
|
||||||
|
$track_script_url = plugins_url( '/misc/track_ai_bot.php', WP_PIWIK_FILE ) . '?mtm_esi=1&mtm_url=' . rawurlencode( AjaxTracker::getCurrentUrl() );
|
||||||
|
echo '<esi:include src="' . esc_attr( $track_script_url ) . '" cache-control="no-cache" />';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $this->is_doing_ai_bot_tracking_this_request() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response_code = http_response_code();
|
||||||
|
$request_elapsed_ms = null;
|
||||||
|
|
||||||
|
// cannot track request time if executed via an esi:include
|
||||||
|
if (
|
||||||
|
empty( $GLOBALS['WP_PIWIK_IN_ESI'] )
|
||||||
|
&& array_key_exists( 'REQUEST_TIME_FLOAT', $_SERVER )
|
||||||
|
) {
|
||||||
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
|
||||||
|
$request_elapsed_ms = (int) ( ( microtime( true ) - floatval( $_SERVER['REQUEST_TIME_FLOAT'] ) ) * 1000 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $response_code ) ) {
|
||||||
|
$response_code = 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
// phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
|
||||||
|
$source = 'WordPress';
|
||||||
|
|
||||||
|
if ( empty( $url ) ) {
|
||||||
|
$url = AjaxTracker::getCurrentUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
$tracker = $this->get_tracker();
|
||||||
|
|
||||||
|
$tracker->setUrl( $url );
|
||||||
|
|
||||||
|
// cannot count bytes echo'd so no response size tracked
|
||||||
|
$tracker->doTrackPageViewIfAIBot( $response_code, null, $request_elapsed_ms, $source );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function should_track_current_page() {
|
||||||
|
if ( is_admin() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( wp_doing_ajax() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||||
|
$request_path = (string) wp_parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH );
|
||||||
|
|
||||||
|
if ( preg_match( '/matomo\.php$/', $request_path ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $this->is_request_for_file( $request_path ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function is_request_for_file( $request_path ) {
|
||||||
|
if (
|
||||||
|
! empty( $_SERVER['DOCUMENT_ROOT'] )
|
||||||
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||||
|
&& is_dir( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) . $request_path )
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$extension = pathinfo( $request_path, PATHINFO_EXTENSION );
|
||||||
|
return ! in_array( $extension, self::$extensions_to_track, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_js_execution_detected() {
|
||||||
|
return ! empty( $_COOKIE['matomo_has_js'] )
|
||||||
|
&& '1' === $_COOKIE['matomo_has_js'];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function is_doing_ai_bot_tracking_this_request() {
|
||||||
|
if ( ! empty( $GLOBALS['WP_PIWIK_IN_ESI'] ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $this->should_track_current_page() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $this->is_js_execution_detected() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tracker = $this->get_tracker();
|
||||||
|
|
||||||
|
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||||
|
if ( ! AjaxTracker::isUserAgentAIBot( $tracker->userAgent ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
! $this->settings->is_ai_bot_tracking_enabled()
|
||||||
|
|| ! $this->settings->is_tracking_enabled()
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_tracker() {
|
||||||
|
if ( empty( $this->tracker ) ) {
|
||||||
|
$this->tracker = new AjaxTracker( $this->settings, $this->logger );
|
||||||
|
$this->tracker->setRequestTimeout( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->tracker;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,24 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik;
|
namespace WP_Piwik;
|
||||||
|
|
||||||
abstract class Admin {
|
|
||||||
|
|
||||||
protected static $wpPiwik, $pageID, $settings;
|
|
||||||
|
|
||||||
public function __construct($wpPiwik, $settings) {
|
|
||||||
self::$wpPiwik = $wpPiwik;
|
|
||||||
self::$settings = $settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract public function show();
|
abstract class Admin {
|
||||||
|
|
||||||
abstract public function printAdminScripts();
|
|
||||||
|
|
||||||
public function printAdminStyles() {
|
|
||||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css', array(), self::$wpPiwik->getPluginVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onLoad() {}
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @var \WP_Piwik
|
||||||
|
*/
|
||||||
|
protected static $wp_piwik;
|
||||||
|
protected static $page_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Settings
|
||||||
|
*/
|
||||||
|
protected static $settings;
|
||||||
|
|
||||||
|
public function __construct( $wp_piwik, $settings ) {
|
||||||
|
self::$wp_piwik = $wp_piwik;
|
||||||
|
self::$settings = $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function show();
|
||||||
|
|
||||||
|
abstract public function print_admin_scripts();
|
||||||
|
|
||||||
|
public function print_admin_styles() {
|
||||||
|
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), self::$wp_piwik->get_plugin_version() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function on_load() {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,19 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Admin;
|
namespace WP_Piwik\Admin;
|
||||||
|
|
||||||
class Network extends \WP_Piwik\Admin\Statistics {
|
class Network extends \WP_Piwik\Admin\Statistics {
|
||||||
|
|
||||||
public function show() {
|
public function print_admin_scripts() {
|
||||||
parent::show();
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
}
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
public function printAdminScripts() {
|
}
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL() . 'js/chartjs/chart.min.js', "3.4.1" );
|
public function on_load() {
|
||||||
}
|
self::$wp_piwik->onload_stats_page();
|
||||||
|
}
|
||||||
public function onLoad() {
|
}
|
||||||
self::$wpPiwik->onloadStatsPage(self::$pageID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -1,112 +1,132 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Admin;
|
namespace WP_Piwik\Admin;
|
||||||
|
|
||||||
if (! class_exists ( 'WP_List_Table' ))
|
if ( ! class_exists( 'WP_List_Table' ) ) {
|
||||||
require_once (ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
||||||
|
}
|
||||||
class Sitebrowser extends \WP_List_Table {
|
|
||||||
|
/**
|
||||||
private $data = array (), $wpPiwik;
|
* phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
|
||||||
|
* phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
public function __construct($wpPiwik) {
|
*/
|
||||||
$this->wpPiwik = $wpPiwik;
|
class Sitebrowser extends \WP_List_Table {
|
||||||
if( isset($_POST['s']) ){
|
|
||||||
$cnt = $this->prepare_items ($_POST['s']);
|
private $data = array();
|
||||||
} else {
|
|
||||||
$cnt = $this->prepare_items ();
|
/**
|
||||||
}
|
* @var \WP_Piwik
|
||||||
global $status, $page;
|
*/
|
||||||
$this->showSearchForm();
|
private $wp_piwik;
|
||||||
parent::__construct ( array (
|
|
||||||
'singular' => __ ( 'site', 'wp-piwik' ),
|
public function __construct( $wp_piwik ) {
|
||||||
'plural' => __ ( 'sites', 'wp-piwik' ),
|
$this->wp_piwik = $wp_piwik;
|
||||||
'ajax' => false
|
if ( isset( $_REQUEST['s'] ) ) {
|
||||||
) );
|
$cnt = $this->prepare_items( sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) );
|
||||||
if ($cnt > 0)
|
} else {
|
||||||
$this->display ();
|
$cnt = $this->prepare_items();
|
||||||
else
|
}
|
||||||
echo '<p>' . __ ( 'No site configured yet.', 'wp-piwik' ) . '</p>';
|
$this->show_search_form();
|
||||||
}
|
parent::__construct(
|
||||||
|
array(
|
||||||
public function get_columns() {
|
'singular' => __( 'site', 'wp-piwik' ),
|
||||||
$columns = array (
|
'plural' => __( 'sites', 'wp-piwik' ),
|
||||||
'id' => __ ( 'Blog ID', 'wp-piwik' ),
|
'ajax' => false,
|
||||||
'name' => __ ( 'Title', 'wp-piwik' ),
|
)
|
||||||
'siteurl' => __ ( 'URL', 'wp-piwik' ),
|
);
|
||||||
'piwikid' => __ ( 'Site ID (Piwik)', 'wp-piwik' )
|
if ( $cnt > 0 ) {
|
||||||
);
|
$this->display();
|
||||||
return $columns;
|
} else {
|
||||||
}
|
echo '<p>' . esc_html__( 'No site configured yet.', 'wp-piwik' ) . '</p>';
|
||||||
|
}
|
||||||
public function prepare_items($search = '') {
|
}
|
||||||
$current_page = $this->get_pagenum ();
|
|
||||||
$per_page = 10;
|
public function get_columns() {
|
||||||
global $blog_id;
|
$columns = array(
|
||||||
global $wpdb;
|
'id' => __( 'Blog ID', 'wp-piwik' ),
|
||||||
global $pagenow;
|
'name' => __( 'Title', 'wp-piwik' ),
|
||||||
if (is_plugin_active_for_network ( 'wp-piwik/wp-piwik.php' )) {
|
'siteurl' => __( 'URL', 'wp-piwik' ),
|
||||||
$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));
|
'piwikid' => __( 'Site ID (Piwik)', 'wp-piwik' ),
|
||||||
$blogs = \WP_Piwik\Settings::getBlogList($per_page, $current_page, $search);
|
);
|
||||||
foreach ( $blogs as $blog ) {
|
return $columns;
|
||||||
$blogDetails = get_blog_details ( $blog['blog_id'], true );
|
}
|
||||||
$this->data [] = array (
|
|
||||||
'name' => $blogDetails->blogname,
|
public function prepare_items( $search = '' ) {
|
||||||
'id' => $blogDetails->blog_id,
|
global $blog_id;
|
||||||
'siteurl' => $blogDetails->siteurl,
|
global $wpdb;
|
||||||
'piwikid' => $this->wpPiwik->getPiwikSiteId ( $blogDetails->blog_id )
|
global $pagenow;
|
||||||
);
|
|
||||||
}
|
$current_page = $this->get_pagenum();
|
||||||
} else {
|
$per_page = 10;
|
||||||
$blogDetails = get_bloginfo ();
|
|
||||||
$this->data [] = array (
|
if ( is_plugin_active_for_network( 'wp-piwik/wp-piwik.php' ) ) {
|
||||||
'name' => get_bloginfo ( 'name' ),
|
$search = '%' . $wpdb->esc_like( $search ) . '%';
|
||||||
'id' => '-',
|
$total_items = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %s WHERE CONCAT(domain, path) LIKE %s AND spam = 0 AND deleted = 0', $wpdb->blogs, $search ) );
|
||||||
'siteurl' => get_bloginfo ( 'url' ),
|
$blogs = \WP_Piwik\Settings::get_blog_list( $per_page, $current_page, $search );
|
||||||
'piwikid' => $this->wpPiwik->getPiwikSiteId ()
|
foreach ( $blogs as $blog ) {
|
||||||
);
|
$blog_details = get_blog_details( $blog['blog_id'], true );
|
||||||
$total_items = 1;
|
$this->data [] = array(
|
||||||
}
|
'name' => $blog_details->blogname,
|
||||||
$columns = $this->get_columns ();
|
'id' => $blog_details->blog_id,
|
||||||
$hidden = array ();
|
'siteurl' => $blog_details->siteurl,
|
||||||
$sortable = array ();
|
'piwikid' => $this->wp_piwik->get_piwik_site_id( $blog_details->blog_id ),
|
||||||
$this->_column_headers = array (
|
);
|
||||||
$columns,
|
}
|
||||||
$hidden,
|
} else {
|
||||||
$sortable
|
$blog_details = get_bloginfo();
|
||||||
);
|
$this->data [] = array(
|
||||||
$this->set_pagination_args ( array (
|
'name' => get_bloginfo( 'name' ),
|
||||||
'total_items' => $total_items,
|
'id' => '-',
|
||||||
'per_page' => $per_page
|
'siteurl' => get_bloginfo( 'url' ),
|
||||||
) );
|
'piwikid' => $this->wp_piwik->get_piwik_site_id(),
|
||||||
foreach ( $this->data as $key => $dataset ) {
|
);
|
||||||
if (empty ( $dataset ['piwikid'] ) || $dataset ['piwikid'] == 'n/a')
|
$total_items = 1;
|
||||||
$this->data [$key] ['piwikid'] = __ ( 'Site not created yet.', 'wp-piwik' );
|
}
|
||||||
if ($this->wpPiwik->isNetworkMode ())
|
$columns = $this->get_columns();
|
||||||
$this->data [$key] ['name'] = '<a href="index.php?page=wp-piwik_stats&wpmu_show_stats=' . $dataset ['id'] . '">' . $dataset ['name'] . '</a>';
|
$hidden = array();
|
||||||
}
|
$sortable = array();
|
||||||
$this->items = $this->data;
|
$this->_column_headers = array(
|
||||||
return count ( $this->items );
|
$columns,
|
||||||
}
|
$hidden,
|
||||||
|
$sortable,
|
||||||
public function column_default($item, $column_name) {
|
);
|
||||||
switch ($column_name) {
|
$this->set_pagination_args(
|
||||||
case 'id' :
|
array(
|
||||||
case 'name' :
|
'total_items' => $total_items,
|
||||||
case 'siteurl' :
|
'per_page' => $per_page,
|
||||||
case 'piwikid' :
|
)
|
||||||
return $item [$column_name];
|
);
|
||||||
default :
|
foreach ( $this->data as $key => $dataset ) {
|
||||||
return print_r ( $item, true );
|
if ( empty( $dataset['piwikid'] ) || 'n/a' === $dataset['piwikid'] ) {
|
||||||
}
|
$this->data [ $key ] ['piwikid'] = __( 'Site not created yet.', 'wp-piwik' );
|
||||||
}
|
}
|
||||||
|
if ( $this->wp_piwik->is_network_mode() ) {
|
||||||
private function showSearchForm() {
|
$this->data [ $key ] ['name'] = '<a href="index.php?page=wp-piwik_stats&wpmu_show_stats=' . esc_attr( rawurlencode( $dataset['id'] ) ) . '">' . esc_html( $dataset['name'] ) . '</a>';
|
||||||
?>
|
}
|
||||||
<form method="post">
|
}
|
||||||
<input type="hidden" name="page" value="<?php echo filter_var($_REQUEST['page'], FILTER_SANITIZE_STRING) ?>" />
|
$this->items = $this->data;
|
||||||
<?php $this->search_box('Search domain and path', 'wpPiwikSiteSearch'); ?>
|
return count( $this->items );
|
||||||
</form>
|
}
|
||||||
<?php
|
|
||||||
}
|
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 show_search_form() {
|
||||||
|
$page = isset( $_REQUEST['page'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) : '';
|
||||||
|
?>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="page" value="<?php echo esc_attr( $page ); ?>" />
|
||||||
|
<?php $this->search_box( 'Search domain and path', 'wpPiwikSiteSearch' ); ?>
|
||||||
|
</form>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,47 +1,55 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Admin;
|
|
||||||
|
|
||||||
class Statistics extends \WP_Piwik\Admin {
|
namespace WP_Piwik\Admin;
|
||||||
|
|
||||||
public function show() {
|
class Statistics extends \WP_Piwik\Admin {
|
||||||
global $screen_layout_columns;
|
|
||||||
if (empty($screen_layout_columns)) $screen_layout_columns = 2;
|
|
||||||
if (self::$settings->getGlobalOption('disable_timelimit')) set_time_limit(0);
|
|
||||||
echo '<div id="wp-piwik-stats-general" class="wrap">';
|
|
||||||
echo '<h2>'.(self::$settings->getGlobalOption('plugin_display_name') == 'WP-Piwik'?'Piwik '.__('Statistics', 'wp-piwik'):self::$settings->getGlobalOption('plugin_display_name')).'</h2>';
|
|
||||||
if (self::$settings->checkNetworkActivation() && function_exists('is_super_admin') && is_super_admin()) {
|
|
||||||
|
|
||||||
if (isset($_GET['wpmu_show_stats'])) {
|
/**
|
||||||
switch_to_blog((int) $_GET['wpmu_show_stats']);
|
* @return void
|
||||||
} elseif ((isset($_GET['overview']) && $_GET['overview']) || (function_exists('is_network_admin') && is_network_admin())) {
|
* @phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||||
new \WP_Piwik\Admin\Sitebrowser(self::$wpPiwik);
|
*/
|
||||||
return;
|
public function show() {
|
||||||
}
|
global $screen_layout_columns;
|
||||||
echo '<p>'.__('Currently shown stats:').' <a href="'.get_bloginfo('url').'">'.get_bloginfo('name').'</a>.'.' <a href="?page=wp-piwik_stats&overview=1">Show site overview</a>.</p>';
|
if ( empty( $screen_layout_columns ) ) {
|
||||||
}
|
$screen_layout_columns = 2;
|
||||||
echo '<form action="admin-post.php" method="post"><input type="hidden" name="action" value="save_wp-piwik_stats_general" /><div id="dashboard-widgets" class="metabox-holder columns-'.$screen_layout_columns.(2 <= $screen_layout_columns?' has-right-sidebar':'').'">';
|
|
||||||
wp_nonce_field('wp-piwik_stats-general');
|
|
||||||
wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
|
|
||||||
wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
|
|
||||||
$columns = array('normal', 'side', 'column3');
|
|
||||||
for ($i = 0; $i < 3; $i++) {
|
|
||||||
echo '<div id="postbox-container-'.($i+1).'" class="postbox-container">';
|
|
||||||
do_meta_boxes(self::$wpPiwik->statsPageId, $columns[$i], null);
|
|
||||||
echo '</div>';
|
|
||||||
}
|
|
||||||
echo '</div></form></div>';
|
|
||||||
echo '<script>//<![CDATA['."\n";
|
|
||||||
echo 'jQuery(document).ready(function($) {$(".if-js-closed").removeClass("if-js-closed").addClass("closed"); postboxes.add_postbox_toggles("'.self::$wpPiwik->statsPageId.'");});'."\n";
|
|
||||||
echo '//]]></script>'."\n";
|
|
||||||
if (self::$settings->checkNetworkActivation() && function_exists('is_super_admin') && is_super_admin()) {
|
|
||||||
restore_current_blog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if ( self::$settings->get_global_option( 'disable_timelimit' ) ) {
|
||||||
public function printAdminScripts() {
|
set_time_limit( 0 );
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
|
||||||
}
|
}
|
||||||
|
echo '<div id="wp-piwik-stats-general" class="wrap">';
|
||||||
|
echo '<h2>' . esc_html( 'WP-Piwik' === self::$settings->get_global_option( 'plugin_display_name' ) ? 'Piwik ' . esc_html__( 'Statistics', 'wp-piwik' ) : self::$settings->get_global_option( 'plugin_display_name' ) ) . '</h2>';
|
||||||
|
if ( self::$settings->check_network_activation() && function_exists( 'is_super_admin' ) && is_super_admin() ) {
|
||||||
|
if ( isset( $_GET['wpmu_show_stats'] ) ) {
|
||||||
|
switch_to_blog( (int) $_GET['wpmu_show_stats'] );
|
||||||
|
} elseif ( ! empty( $_GET['overview'] ) || ( function_exists( 'is_network_admin' ) && is_network_admin() ) ) {
|
||||||
|
new \WP_Piwik\Admin\Sitebrowser( self::$wp_piwik );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
echo '<p>' . esc_html__( 'Currently shown stats:', 'wp-piwik' ) . ' <a href="' . esc_attr( get_bloginfo( 'url' ) ) . '">' . esc_html( get_bloginfo( 'name' ) ) . '</a>. <a href="?page=wp-piwik_stats&overview=1">Show site overview</a>.</p>';
|
||||||
|
}
|
||||||
|
echo '<form action="admin-post.php" method="post"><input type="hidden" name="action" value="save_wp-piwik_stats_general" /><div id="dashboard-widgets" class="metabox-holder columns-' . esc_attr( $screen_layout_columns ) . esc_attr( 2 <= $screen_layout_columns ? ' has-right-sidebar' : '' ) . '">';
|
||||||
|
wp_nonce_field( 'wp-piwik_stats-general' );
|
||||||
|
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
|
||||||
|
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
|
||||||
|
$columns = array( 'normal', 'side', 'column3' );
|
||||||
|
for ( $i = 0; $i < 3; $i++ ) {
|
||||||
|
// @phpstan-ignore-next-line
|
||||||
|
echo '<div id="postbox-container-' . esc_attr( $i + 1 ) . '" class="postbox-container">';
|
||||||
|
do_meta_boxes( self::$wp_piwik->stats_page_id, $columns[ $i ], null );
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
echo '</div></form></div>';
|
||||||
|
echo '<script>//<![CDATA[' . "\n";
|
||||||
|
echo 'jQuery(document).ready(function($) {$(".if-js-closed").removeClass("if-js-closed").addClass("closed"); postboxes.add_postbox_toggles(' . wp_json_encode( self::$wp_piwik->stats_page_id ) . ');});' . "\n";
|
||||||
|
echo '//]]></script>' . "\n";
|
||||||
|
if ( self::$settings->check_network_activation() && function_exists( 'is_super_admin' ) && is_super_admin() ) {
|
||||||
|
restore_current_blog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public function print_admin_scripts() {
|
||||||
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
175
wp-content/plugins/wp-piwik/classes/WP_Piwik/AjaxTracker.php
Normal file
175
wp-content/plugins/wp-piwik/classes/WP_Piwik/AjaxTracker.php
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Matomo - free/libre analytics platform
|
||||||
|
*
|
||||||
|
* @link https://matomo.org
|
||||||
|
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||||
|
* @package matomo
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace WP_Piwik;
|
||||||
|
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit; // if accessed directly
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! class_exists( '\WP_Piwik\MatomoTracker' ) ) {
|
||||||
|
require_once __DIR__ . '/../../libs/matomo-php-tracker/MatomoTracker.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||||
|
* @phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
|
||||||
|
* @phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod.Found
|
||||||
|
*/
|
||||||
|
class AjaxTracker extends \WP_Piwik\MatomoTracker {
|
||||||
|
|
||||||
|
private $has_cookie = false;
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
public function __construct( Settings $settings, Logger $logger ) {
|
||||||
|
$this->logger = $logger;
|
||||||
|
|
||||||
|
$idsite = $settings->get_option( 'site_id' );
|
||||||
|
if ( ! $idsite ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$api_endpoint = rtrim( $settings->get_matomo_url(), '/' ) . '/matomo.php';
|
||||||
|
|
||||||
|
parent::__construct( (int) $idsite, $api_endpoint );
|
||||||
|
|
||||||
|
$this->ip = false;
|
||||||
|
|
||||||
|
if ( ! $settings->get_global_option( 'disable_cookies' ) ) {
|
||||||
|
$cookie_domain = $this->get_tracking_cookie_domain( $settings );
|
||||||
|
$this->enableCookies( $cookie_domain );
|
||||||
|
} else {
|
||||||
|
$this->disableCookieSupport();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $this->loadVisitorIdCookie() ) {
|
||||||
|
if ( ! empty( $this->cookieVisitorId ) ) {
|
||||||
|
$this->has_cookie = true;
|
||||||
|
$this->set_visitor_id_safe( $this->cookieVisitorId );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_visitor_id_safe( $visitor_id ) {
|
||||||
|
try {
|
||||||
|
$this->setVisitorId( $visitor_id );
|
||||||
|
} catch ( \Exception $ex ) {
|
||||||
|
// do not fatal if the visitor ID is invalid for some reason
|
||||||
|
if ( ! $this->is_invalid_visitor_id_error( $ex ) ) {
|
||||||
|
throw $ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setCookie( $cookieName, $cookieValue, $cookieTTL ) {
|
||||||
|
if ( ! $this->has_cookie ) {
|
||||||
|
// we only set / overwrite cookies if it is a visitor that has eg no JS enabled or ad blocker enabled etc.
|
||||||
|
// this way we will track all cart updates and orders into the same visitor on following requests.
|
||||||
|
// If we recognized the visitor before via cookie we want in our case to make sure to not overwrite
|
||||||
|
// any cookie
|
||||||
|
return parent::setCookie( $cookieName, $cookieValue, $cookieTTL );
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function sendRequest( string $url, string $method = 'GET', $data = null, bool $force = false ): string {
|
||||||
|
if ( ! $this->idSite ) {
|
||||||
|
$this->logger->log( 'ecommerce tracking could not find idSite, cannot send request' );
|
||||||
|
return ''; // not installed or synced yet
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $this->is_prerender() ) {
|
||||||
|
// do not track if for some reason we are prerendering
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'method' => $method,
|
||||||
|
'headers' => array(
|
||||||
|
'User-Agent' => $this->userAgent,
|
||||||
|
),
|
||||||
|
'blocking' => false,
|
||||||
|
);
|
||||||
|
if ( ! empty( $data ) ) {
|
||||||
|
$args['body'] = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = $url . '&bots=1';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->wp_remote_request( $url, $args );
|
||||||
|
} catch ( \Exception $ex ) {
|
||||||
|
$this->logger->log( 'ajax_tracker: ' . $ex->getMessage() );
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( is_wp_error( $response ) ) {
|
||||||
|
$this->logger->log( 'ajax_tracker: ' . new \Exception( $response->get_error_message() ) );
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response['body'];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function is_invalid_visitor_id_error( \Exception $ex ) {
|
||||||
|
return strpos( $ex->getMessage(), 'setVisitorId() expects' ) === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See https://developer.chrome.com/docs/web-platform/prerender-pages
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function is_prerender() {
|
||||||
|
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||||
|
$purpose = strtolower( isset( $_SERVER['HTTP_SEC_PURPOSE'] ) ? wp_unslash( $_SERVER['HTTP_SEC_PURPOSE'] ) : '' );
|
||||||
|
return strpos( $purpose, 'prefetch' ) !== false
|
||||||
|
|| strpos( $purpose, 'prerender' ) !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for tests to override
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @param array $args
|
||||||
|
* @return array|\WP_Error
|
||||||
|
*/
|
||||||
|
protected function wp_remote_request( $url, $args ) {
|
||||||
|
return wp_remote_request( $url, $args );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In Connect Matomo we want to rely entirely on JavaScript tracker
|
||||||
|
* for creating cookies.
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
protected function setFirstPartyCookies() {
|
||||||
|
// disabled
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCurrentUrl(): string {
|
||||||
|
return parent::getCurrentUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_tracking_cookie_domain( Settings $settings ) {
|
||||||
|
if (
|
||||||
|
$settings->get_global_option( 'track_across' )
|
||||||
|
|| $settings->get_global_option( 'track_crossdomain_linking' )
|
||||||
|
) {
|
||||||
|
$host = wp_parse_url( home_url(), PHP_URL_HOST );
|
||||||
|
if ( ! empty( $host ) ) {
|
||||||
|
return '*.' . $host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,47 +1,57 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik;
|
namespace WP_Piwik;
|
||||||
|
|
||||||
abstract class Logger {
|
abstract class Logger {
|
||||||
|
|
||||||
private $loggerName = 'unnamed';
|
|
||||||
private $loggerContent = array();
|
|
||||||
private $startMicrotime = null;
|
|
||||||
|
|
||||||
abstract function loggerOutput($loggerTime, $loggerMessage);
|
|
||||||
|
|
||||||
public function __construct($loggerName) {
|
private $logger_name = 'unnamed';
|
||||||
$this->setName($loggerName);
|
private $start_microtime = null;
|
||||||
$this->setStartMicrotime(microtime(true));
|
|
||||||
$this->log('Logging started -------------------------------');
|
abstract public function logger_output( $logger_time, $logger_message );
|
||||||
|
|
||||||
|
public function __construct( $logger_name ) {
|
||||||
|
$this->set_name( $logger_name );
|
||||||
|
$this->set_start_microtime( microtime( true ) );
|
||||||
|
$this->log( 'Logging started -------------------------------' );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function make_logger() {
|
||||||
|
$logger = defined( 'WP_PIWIK_ACTIVATE_LOGGER' ) ? WP_PIWIK_ACTIVATE_LOGGER : 0;
|
||||||
|
switch ( $logger ) {
|
||||||
|
case 1:
|
||||||
|
return new \WP_Piwik\Logger\Screen( __CLASS__ );
|
||||||
|
case 2:
|
||||||
|
return new \WP_Piwik\Logger\File( __CLASS__ );
|
||||||
|
default:
|
||||||
|
return new \WP_Piwik\Logger\Dummy( __CLASS__ );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public function __destruct() {
|
|
||||||
$this->log('Logging finished ------------------------------');
|
public function __destruct() {
|
||||||
}
|
$this->log( 'Logging finished ------------------------------' );
|
||||||
|
}
|
||||||
public function log($loggerMessage) {
|
|
||||||
$this->loggerOutput($this->getElapsedMicrotime(), $loggerMessage);
|
public function log( $logger_message ) {
|
||||||
}
|
$this->logger_output( $this->get_elapsed_microtime(), $logger_message );
|
||||||
|
}
|
||||||
private function setName($loggerName) {
|
|
||||||
$this->loggerName = $loggerName;
|
private function set_name( $logger_name ) {
|
||||||
}
|
$this->logger_name = $logger_name;
|
||||||
|
}
|
||||||
public function getName() {
|
|
||||||
return $this->loggerName;
|
public function get_name() {
|
||||||
}
|
return $this->logger_name;
|
||||||
|
}
|
||||||
private function setStartMicrotime($startMicrotime) {
|
|
||||||
$this->startMicrotime = $startMicrotime;
|
private function set_start_microtime( $start_microtime ) {
|
||||||
}
|
$this->start_microtime = $start_microtime;
|
||||||
|
}
|
||||||
public function getStartMicrotime() {
|
|
||||||
return $this->startMicrotime;
|
public function get_start_microtime() {
|
||||||
}
|
return $this->start_microtime;
|
||||||
|
}
|
||||||
public function getElapsedMicrotime() {
|
|
||||||
return microtime(true) - $this->getStartMicrotime();
|
public function get_elapsed_microtime() {
|
||||||
}
|
return microtime( true ) - $this->get_start_microtime();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Logger;
|
namespace WP_Piwik\Logger;
|
||||||
|
|
||||||
class Dummy extends \WP_Piwik\Logger {
|
|
||||||
|
|
||||||
public function loggerOutput($loggerTime, $loggerMessage) {}
|
class Dummy extends \WP_Piwik\Logger {
|
||||||
|
|
||||||
}
|
public function logger_output( $logger_time, $logger_message ) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,48 +1,55 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Logger;
|
namespace WP_Piwik\Logger;
|
||||||
|
|
||||||
class File extends \WP_Piwik\Logger {
|
/**
|
||||||
|
* @phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_fopen
|
||||||
private $loggerFile = null;
|
* @phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_fclose
|
||||||
|
* @phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_fwrite
|
||||||
private function encodeFilename($fileName) {
|
*/
|
||||||
$fileName = str_replace (' ', '_', $fileName);
|
class File extends \WP_Piwik\Logger {
|
||||||
preg_replace('/[^0-9^a-z^_^.]/', '', $fileName);
|
|
||||||
return $fileName;
|
private $logger_file = null;
|
||||||
|
|
||||||
|
private function encode_filename( $file_name ) {
|
||||||
|
$file_name = str_replace( ' ', '_', $file_name );
|
||||||
|
preg_replace( '/[^0-9^a-z^_^.]/', '', $file_name );
|
||||||
|
return $file_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_filename() {
|
||||||
|
$this->logger_file = WP_PIWIK_PATH . 'logs' . DIRECTORY_SEPARATOR .
|
||||||
|
gmdate( 'Ymd' ) . '_' . $this->encode_filename( $this->get_name() ) . '.log';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_filename() {
|
||||||
|
return $this->logger_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function open_file() {
|
||||||
|
if ( ! $this->logger_file ) {
|
||||||
|
$this->set_filename();
|
||||||
}
|
}
|
||||||
|
return fopen( $this->get_filename(), 'a' );
|
||||||
private function setFilename() {
|
}
|
||||||
$this->loggerFile = WP_PIWIK_PATH.'logs'.DIRECTORY_SEPARATOR.
|
|
||||||
date('Ymd').'_'.$this->encodeFilename($this->getName()).'.log';
|
private function close_file( $file_handle ) {
|
||||||
|
fclose( $file_handle );
|
||||||
|
}
|
||||||
|
|
||||||
|
private function write_file( $file_handle, $file_content ) {
|
||||||
|
fwrite( $file_handle, $file_content . "\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private function format_microtime( $logger_time ) {
|
||||||
|
return sprintf( '[%6s sec]', number_format( $logger_time, 3 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logger_output( $logger_time, $logger_message ) {
|
||||||
|
$file_handle = $this->open_file();
|
||||||
|
if ( $file_handle ) {
|
||||||
|
$this->write_file( $file_handle, $this->format_microtime( $logger_time ) . ' ' . $logger_message );
|
||||||
|
$this->close_file( $file_handle );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,27 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Logger;
|
|
||||||
|
|
||||||
class Screen extends \WP_Piwik\Logger {
|
namespace WP_Piwik\Logger;
|
||||||
|
|
||||||
private $logs = array();
|
class Screen extends \WP_Piwik\Logger {
|
||||||
|
|
||||||
private function formatMicrotime($loggerTime) {
|
private $logs = array();
|
||||||
return sprintf('[%6s sec]',number_format($loggerTime,3));
|
|
||||||
}
|
private function format_microtime( $logger_time ) {
|
||||||
|
return sprintf( '[%6s sec]', number_format( $logger_time, 3 ) );
|
||||||
public function __construct($loggerName) {
|
}
|
||||||
add_action(is_admin()?'admin_footer':'wp_footer', array($this, 'echoResults'));
|
|
||||||
parent::__construct($loggerName);
|
public function __construct( $logger_name ) {
|
||||||
}
|
add_action( is_admin() ? 'admin_footer' : 'wp_footer', array( $this, 'echo_results' ) );
|
||||||
|
parent::__construct( $logger_name );
|
||||||
public function loggerOutput($loggerTime, $loggerMessage) {
|
}
|
||||||
$this->logs[] = $this->formatMicrotime($loggerTime).' '.$loggerMessage;
|
|
||||||
}
|
public function logger_output( $logger_time, $logger_message ) {
|
||||||
|
$this->logs[] = $this->format_microtime( $logger_time ) . ' ' . $logger_message;
|
||||||
public function echoResults() {
|
}
|
||||||
echo '<pre>';
|
|
||||||
print_r($this->logs);
|
public function echo_results() {
|
||||||
echo '</pre>';
|
echo '<pre>';
|
||||||
}
|
print_r( $this->logs );
|
||||||
}
|
echo '</pre>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,95 +1,132 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik;
|
namespace WP_Piwik;
|
||||||
|
|
||||||
abstract class Request {
|
abstract class Request {
|
||||||
|
|
||||||
protected static $wpPiwik, $settings, $debug, $lastError = '', $requests = array(), $results = array(), $isCacheable = array(), $piwikVersion;
|
|
||||||
|
|
||||||
public function __construct($wpPiwik, $settings) {
|
|
||||||
self::$wpPiwik = $wpPiwik;
|
|
||||||
self::$settings = $settings;
|
|
||||||
self::register('API.getPiwikVersion', array());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function reset() {
|
|
||||||
self::$debug = null;
|
|
||||||
self::$requests = array();
|
|
||||||
self::$results = array();
|
|
||||||
self::$isCacheable = array();
|
|
||||||
self::$piwikVersion = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function register($method, $parameter) {
|
|
||||||
if ($method == 'API.getPiwikVersion')
|
|
||||||
$id = 'global.getPiwikVersion';
|
|
||||||
else
|
|
||||||
$id = 'method='.$method.self::parameterToString($parameter);
|
|
||||||
if (
|
|
||||||
in_array( $method, array( 'API.getPiwikVersion', 'SitesManager.getJavascriptTag', 'SitesManager.getSitesWithAtLeastViewAccess', 'SitesManager.getSitesIdFromSiteUrl', 'SitesManager.addSite', 'SitesManager.updateSite', 'SitesManager.getSitesWithAtLeastViewAccess' ) ) ||
|
|
||||||
!isset( $parameter['date'] ) ||
|
|
||||||
!isset( $parameter['period'] ) ||
|
|
||||||
substr($parameter['date'], 0, 4) == 'last' ||
|
|
||||||
$parameter['date'] == 'today' ||
|
|
||||||
( $parameter['period'] == 'day' && $parameter['date'] == date('Ymd') ) ||
|
|
||||||
( $parameter['period'] == 'month' && $parameter['date'] == date('Ym') ) ||
|
|
||||||
( $parameter['period'] == 'week' && $parameter['date'] == date( 'Ymd', strtotime( "last Monday" ) ) )
|
|
||||||
) self::$isCacheable[$id] = false;
|
|
||||||
else self::$isCacheable[$id] = $method.'-'.serialize($parameter);
|
|
||||||
if (!isset(self::$requests[$id]))
|
|
||||||
self::$requests[$id] = array('method' => $method, 'parameter' => $parameter);
|
|
||||||
return $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function parameterToString($parameter) {
|
/**
|
||||||
$return = '';
|
* @var \WP_Piwik
|
||||||
if (is_array($parameter))
|
*/
|
||||||
foreach ($parameter as $key => $value)
|
protected static $wp_piwik;
|
||||||
$return .= '&'.$key.'='.$value;
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function perform($id) {
|
/**
|
||||||
if ( self::$settings->getGlobalOption('cache') && false !== ( $cached = get_transient( 'wp-piwik_c_'.md5(self::$isCacheable[$id] ) ) ) ) {
|
* @var Settings
|
||||||
if (!empty ( $cached ) && !(! empty ( $cached['result'] ) && $cached['result'] == 'error') ) {
|
*/
|
||||||
self::$wpPiwik->log("Deliver cached data: ".$id);
|
protected static $settings;
|
||||||
return $cached;
|
protected static $debug;
|
||||||
}
|
protected static $last_error = '';
|
||||||
|
protected static $requests = array();
|
||||||
|
protected static $results = array();
|
||||||
|
protected static $is_cacheable = array();
|
||||||
|
protected static $piwik_version;
|
||||||
|
|
||||||
|
public function __construct( $wp_piwik, $settings ) {
|
||||||
|
self::$wp_piwik = $wp_piwik;
|
||||||
|
self::$settings = $settings;
|
||||||
|
self::register( 'API.getPiwikVersion', array() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reset() {
|
||||||
|
self::$debug = null;
|
||||||
|
self::$requests = array();
|
||||||
|
self::$results = array();
|
||||||
|
self::$is_cacheable = array();
|
||||||
|
self::$piwik_version = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function register( $method, $parameter ) {
|
||||||
|
if ( 'API.getPiwikVersion' === $method ) {
|
||||||
|
$id = 'global.getPiwikVersion';
|
||||||
|
} else {
|
||||||
|
$id = 'method=' . $method . self::parameter_to_string( $parameter );
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
in_array( $method, array( 'API.getPiwikVersion', 'SitesManager.getJavascriptTag', 'SitesManager.getSitesWithAtLeastViewAccess', 'SitesManager.getSitesIdFromSiteUrl', 'SitesManager.addSite', 'SitesManager.updateSite', 'SitesManager.getSitesWithAtLeastViewAccess' ), true ) ||
|
||||||
|
! isset( $parameter['date'] ) ||
|
||||||
|
! isset( $parameter['period'] ) ||
|
||||||
|
'last' === substr( $parameter['date'], 0, 4 ) ||
|
||||||
|
'today' === $parameter['date'] ||
|
||||||
|
( 'day' === $parameter['period'] && gmdate( 'Ymd' ) === $parameter['date'] ) ||
|
||||||
|
( 'month' === $parameter['period'] && gmdate( 'Ym' ) === $parameter['date'] ) ||
|
||||||
|
( 'week' === $parameter['period'] && gmdate( 'Ymd', strtotime( 'last Monday' ) ) === $parameter['date'] )
|
||||||
|
) {
|
||||||
|
self::$is_cacheable[ $id ] = false;
|
||||||
|
} else {
|
||||||
|
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
|
||||||
|
self::$is_cacheable[ $id ] = $method . '-' . serialize( $parameter );
|
||||||
|
}
|
||||||
|
if ( ! isset( self::$requests[ $id ] ) ) {
|
||||||
|
self::$requests[ $id ] = array(
|
||||||
|
'method' => $method,
|
||||||
|
'parameter' => $parameter,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function parameter_to_string( $parameter ) {
|
||||||
|
$return = '';
|
||||||
|
if ( is_array( $parameter ) ) {
|
||||||
|
foreach ( $parameter as $key => $value ) {
|
||||||
|
$return .= '&' . $key . '=' . $value;
|
||||||
}
|
}
|
||||||
self::$wpPiwik->log("Perform request: ".$id);
|
|
||||||
if (!isset(self::$requests[$id]))
|
|
||||||
return array('result' => 'error', 'message' => 'Request '.$id.' was not registered.');
|
|
||||||
elseif (!isset(self::$results[$id])) {
|
|
||||||
$this->request($id);
|
|
||||||
}
|
|
||||||
if ( isset ( self::$results[$id] ) ) {
|
|
||||||
if ( self::$settings->getGlobalOption('cache') && self::$isCacheable[$id] ) {
|
|
||||||
set_transient( 'wp-piwik_c_'.md5(self::$isCacheable[$id]) , self::$results[$id], WEEK_IN_SECONDS );
|
|
||||||
}
|
|
||||||
return self::$results[$id];
|
|
||||||
} else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDebug($id) {
|
|
||||||
return isset( self::$debug[$id] )? self::$debug[$id] : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function buildURL($config, $urlDecode = false) {
|
|
||||||
$url = 'method='.($config['method']).'&idSite='.self::$settings->getOption('site_id');
|
|
||||||
foreach ($config['parameter'] as $key => $value)
|
|
||||||
$url .= '&'.$key.'='.($urlDecode?urldecode($value):$value);
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function unserialize($str) {
|
|
||||||
self::$wpPiwik->log("Result string: ".$str);
|
|
||||||
return ($str == json_decode(false, true) || @json_decode($str, true) !== false)?json_decode($str, true):array();
|
|
||||||
}
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
public static function getLastError() {
|
public function perform( $id ) {
|
||||||
return self::$lastError;
|
if ( self::$settings->get_global_option( 'cache' ) ) {
|
||||||
}
|
$cached = get_transient( 'wp-piwik_c_' . md5( self::$is_cacheable[ $id ] ) );
|
||||||
|
if ( ! empty( $cached ) && ! ( ! empty( $cached['result'] ) && 'error' === $cached['result'] ) ) {
|
||||||
abstract protected function request($id);
|
self::$wp_piwik->log( 'Deliver cached data: ' . $id );
|
||||||
|
return $cached;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
self::$wp_piwik->log( 'Perform request: ' . $id );
|
||||||
|
if ( ! isset( self::$requests[ $id ] ) ) {
|
||||||
|
return array(
|
||||||
|
'result' => 'error',
|
||||||
|
'message' => 'Request ' . $id . ' was not registered.',
|
||||||
|
);
|
||||||
|
} elseif ( ! isset( self::$results[ $id ] ) ) {
|
||||||
|
$this->request( $id );
|
||||||
|
}
|
||||||
|
if ( isset( self::$results[ $id ] ) ) {
|
||||||
|
if ( self::$settings->get_global_option( 'cache' ) && self::$is_cacheable[ $id ] ) {
|
||||||
|
set_transient( 'wp-piwik_c_' . md5( self::$is_cacheable[ $id ] ), self::$results[ $id ], WEEK_IN_SECONDS );
|
||||||
|
}
|
||||||
|
return self::$results[ $id ];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_debug( $id ) {
|
||||||
|
return isset( self::$debug[ $id ] ) ? self::$debug[ $id ] : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function build_url( $config ) {
|
||||||
|
return http_build_query( $this->get_url_params( $config ), '', '&' );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function get_url_params( $config ) {
|
||||||
|
$params = [
|
||||||
|
'method' => $config['method'],
|
||||||
|
'idSite' => self::$settings->get_option( 'site_id' ),
|
||||||
|
];
|
||||||
|
$params = array_merge( $params, $config['parameter'] );
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function unserialize( $str ) {
|
||||||
|
self::$wp_piwik->log( 'Result string: ' . $str );
|
||||||
|
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
||||||
|
return ( json_decode( '', true ) === $str || false !== @json_decode( $str, true ) ) ? json_decode( $str, true ) : array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_last_error() {
|
||||||
|
return self::$last_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected function request( $id );
|
||||||
|
}
|
||||||
|
|||||||
@ -1,64 +1,94 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Request;
|
namespace WP_Piwik\Request;
|
||||||
|
|
||||||
class Php extends \WP_Piwik\Request {
|
class Php extends \WP_Piwik\Request {
|
||||||
|
|
||||||
private static $piwikEnvironment = false;
|
/**
|
||||||
|
* @var mixed
|
||||||
|
*/
|
||||||
|
private static $piwik_environment = false;
|
||||||
|
|
||||||
protected function request($id) {
|
protected function request( $id ) {
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$url = self::$settings->getGlobalOption('piwik_url');
|
$url = self::$settings->get_global_option( 'piwik_url' );
|
||||||
foreach (self::$requests as $requestID => $config) {
|
foreach ( self::$requests as $request_id => $config ) {
|
||||||
if (!isset(self::$results[$requestID])) {
|
if ( ! isset( self::$results[ $request_id ] ) ) {
|
||||||
if (self::$settings->getGlobalOption('filter_limit') != "" && self::$settings->getGlobalOption('filter_limit') == (int) self::$settings->getGlobalOption('filter_limit'))
|
if ( '' !== self::$settings->get_global_option( 'filter_limit' ) && is_numeric( self::$settings->get_global_option( 'filter_limit' ) ) ) {
|
||||||
$config['parameter']['filter_limit'] = self::$settings->getGlobalOption('filter_limit');
|
$config['parameter']['filter_limit'] = self::$settings->get_global_option( 'filter_limit' );
|
||||||
$params = 'module=API&format=json&'.$this->buildURL($config, true);
|
|
||||||
$map[$count] = $requestID;
|
|
||||||
$result = $this->call($id, $url, $params);
|
|
||||||
self::$results[$map[$count]] = $result;
|
|
||||||
$count++;
|
|
||||||
}
|
}
|
||||||
|
$params = $this->get_url_params( $config );
|
||||||
|
$params['module'] = 'API';
|
||||||
|
$params['format'] = 'json';
|
||||||
|
$map[ $count ] = $request_id;
|
||||||
|
$result = $this->call( $id, $url, $params );
|
||||||
|
self::$results[ $map[ $count ] ] = $result;
|
||||||
|
++$count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function call($id, $url, $params) {
|
private function call( $id, $url, $params ) {
|
||||||
if (!defined('PIWIK_INCLUDE_PATH'))
|
if ( ! defined( 'PIWIK_INCLUDE_PATH' ) ) {
|
||||||
return false;
|
return false;
|
||||||
if (PIWIK_INCLUDE_PATH === FALSE)
|
}
|
||||||
return array('result' => 'error', 'message' => __('Could not resolve','wp-piwik').' "'.htmlentities(self::$settings->getGlobalOption('piwik_path')).'": '.__('realpath() returns false','wp-piwik').'.');
|
if ( PIWIK_INCLUDE_PATH === false ) {
|
||||||
if (file_exists(PIWIK_INCLUDE_PATH . "/index.php"))
|
return array(
|
||||||
require_once PIWIK_INCLUDE_PATH . "/index.php";
|
'result' => 'error',
|
||||||
if (file_exists(PIWIK_INCLUDE_PATH . "/core/API/Request.php"))
|
'message' => __( 'Could not resolve', 'wp-piwik' ) . ' "' . htmlentities( self::$settings->get_global_option( 'piwik_path' ) ) . '": ' . __( 'realpath() returns false', 'wp-piwik' ) . '.',
|
||||||
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";
|
);
|
||||||
if (class_exists('\Piwik\Application\Environment') && !self::$piwikEnvironment) {
|
}
|
||||||
// Piwik 2.14.* compatibility fix
|
if ( file_exists( PIWIK_INCLUDE_PATH . '/index.php' ) ) {
|
||||||
self::$piwikEnvironment = new \Piwik\Application\Environment(null);
|
require_once PIWIK_INCLUDE_PATH . '/index.php';
|
||||||
self::$piwikEnvironment->init();
|
}
|
||||||
}
|
if ( file_exists( PIWIK_INCLUDE_PATH . '/core/API/Request.php' ) ) {
|
||||||
if (class_exists('Piwik\FrontController'))
|
require_once PIWIK_INCLUDE_PATH . '/core/API/Request.php';
|
||||||
\Piwik\FrontController::getInstance()->init();
|
}
|
||||||
else return array('result' => 'error', 'message' => __('Class Piwik\FrontController does not exists.','wp-piwik'));
|
if ( class_exists( '\Piwik\Application\Environment' ) && ! self::$piwik_environment ) {
|
||||||
if (class_exists('Piwik\API\Request'))
|
// Piwik 2.14.* compatibility fix
|
||||||
$request = new \Piwik\API\Request($params.'&token_auth='.self::$settings->getGlobalOption('piwik_token'));
|
self::$piwik_environment = new \Piwik\Application\Environment( null );
|
||||||
else return array('result' => 'error', 'message' => __('Class Piwik\API\Request does not exists.','wp-piwik'));
|
self::$piwik_environment->init();
|
||||||
if (isset($request))
|
}
|
||||||
$result = $request->process();
|
if ( class_exists( 'Piwik\FrontController' ) ) {
|
||||||
else $result = null;
|
\Piwik\FrontController::getInstance()->init();
|
||||||
if (!headers_sent())
|
} else {
|
||||||
header("Content-Type: text/html", true);
|
return array(
|
||||||
$result = $this->unserialize($result);
|
'result' => 'error',
|
||||||
if ($GLOBALS ['wp-piwik_debug'])
|
'message' => __( 'Class Piwik\FrontController does not exists.', 'wp-piwik' ),
|
||||||
self::$debug[$id] = array ( $params.'&token_auth=...' );
|
);
|
||||||
return $result;
|
}
|
||||||
|
if ( class_exists( 'Piwik\API\Request' ) ) {
|
||||||
|
$params['token_auth'] = self::$settings->get_global_option( 'piwik_token' );
|
||||||
|
$request = new \Piwik\API\Request( $params );
|
||||||
|
} else {
|
||||||
|
return array(
|
||||||
|
'result' => 'error',
|
||||||
|
'message' => __( 'Class Piwik\API\Request does not exists.', 'wp-piwik' ),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset() {
|
$result = $request->process();
|
||||||
if (class_exists('\Piwik\Application\Environment') && !self::$piwikEnvironment) {
|
|
||||||
self::$piwikEnvironment->destroy();
|
if ( ! headers_sent() ) {
|
||||||
}
|
header( 'Content-Type: text/html', true );
|
||||||
if (class_exists('Piwik\FrontController'))
|
}
|
||||||
\Piwik\FrontController::unsetInstance();
|
$result = $this->unserialize( $result );
|
||||||
parent::reset();
|
if ( $GLOBALS ['wp-piwik_debug'] ) {
|
||||||
}
|
self::$debug[ $id ] = array( $params . '&token_auth=...' );
|
||||||
}
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reset() {
|
||||||
|
if (
|
||||||
|
class_exists( '\Piwik\Application\Environment' )
|
||||||
|
&& self::$piwik_environment instanceof \Piwik\Application\Environment
|
||||||
|
) {
|
||||||
|
self::$piwik_environment->destroy();
|
||||||
|
}
|
||||||
|
if ( class_exists( 'Piwik\FrontController' ) ) {
|
||||||
|
\Piwik\FrontController::unsetInstance();
|
||||||
|
}
|
||||||
|
parent::reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,81 +1,124 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Request;
|
namespace WP_Piwik\Request;
|
||||||
|
|
||||||
class Rest extends \WP_Piwik\Request {
|
/**
|
||||||
|
* TODO: switch to wp_remote_get
|
||||||
protected function request($id) {
|
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_close
|
||||||
$count = 0;
|
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_getinfo
|
||||||
if (self::$settings->getGlobalOption('piwik_mode') == 'http')
|
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_error
|
||||||
$url = self::$settings->getGlobalOption('piwik_url');
|
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_init
|
||||||
else if (self::$settings->getGlobalOption('piwik_mode') == 'cloud')
|
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_setopt
|
||||||
$url = 'https://'.self::$settings->getGlobalOption('piwik_user').'.innocraft.cloud/';
|
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_exec
|
||||||
else $url = 'https://'.self::$settings->getGlobalOption('matomo_user').'.matomo.cloud/';
|
* phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
|
||||||
$params = 'module=API&method=API.getBulkRequest&format=json';
|
*/
|
||||||
if (self::$settings->getGlobalOption('filter_limit') != "" && self::$settings->getGlobalOption('filter_limit') == (int) self::$settings->getGlobalOption('filter_limit'))
|
class Rest extends \WP_Piwik\Request {
|
||||||
$params .= '&filter_limit='.self::$settings->getGlobalOption('filter_limit');
|
|
||||||
foreach (self::$requests as $requestID => $config) {
|
protected function request( $id ) {
|
||||||
if (!isset(self::$results[$requestID])) {
|
$count = 0;
|
||||||
$params .= '&urls['.$count.']='.urlencode($this->buildURL($config));
|
$url = self::$settings->get_matomo_url();
|
||||||
$map[$count] = $requestID;
|
$params = 'module=API&method=API.getBulkRequest&format=json';
|
||||||
$count++;
|
|
||||||
|
$filter_limit = self::$settings->get_global_option( 'filter_limit' );
|
||||||
|
if (
|
||||||
|
$filter_limit > 0
|
||||||
|
&& is_numeric( self::$settings->get_global_option( 'filter_limit' ) )
|
||||||
|
) {
|
||||||
|
$params .= '&filter_limit=' . self::$settings->get_global_option( 'filter_limit' );
|
||||||
|
}
|
||||||
|
foreach ( self::$requests as $request_id => $config ) {
|
||||||
|
if ( ! isset( self::$results[ $request_id ] ) ) {
|
||||||
|
$params .= '&urls[' . $count . ']=' . rawurlencode( $this->build_url( $config ) );
|
||||||
|
$map[ $count ] = $request_id;
|
||||||
|
++$count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$use_curl = (
|
||||||
|
function_exists( 'curl_init' )
|
||||||
|
&& ini_get( 'allow_url_fopen' )
|
||||||
|
&& 'curl' === self::$settings->get_global_option( 'http_connection' )
|
||||||
|
) || (
|
||||||
|
function_exists( 'curl_init' )
|
||||||
|
&& ! ini_get( 'allow_url_fopen' )
|
||||||
|
);
|
||||||
|
$results = $use_curl ? $this->curl( $id, $url, $params ) : $this->fopen( $id, $url, $params );
|
||||||
|
if ( is_array( $results ) ) {
|
||||||
|
foreach ( $results as $num => $result ) {
|
||||||
|
if ( isset( $map[ $num ] ) ) {
|
||||||
|
self::$results[ $map[ $num ] ] = $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$results = ((function_exists('curl_init') && ini_get('allow_url_fopen') && self::$settings->getGlobalOption('http_connection') == 'curl') || (function_exists('curl_init') && !ini_get('allow_url_fopen')))?$this->curl($id, $url, $params):$this->fopen($id, $url, $params);
|
|
||||||
if (is_array($results))
|
|
||||||
foreach ($results as $num => $result)
|
|
||||||
if (isset($map[$num]))
|
|
||||||
self::$results[$map[$num]] = $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function curl($id, $url, $params) {
|
|
||||||
if (self::$settings->getGlobalOption('http_method')=='post') {
|
|
||||||
$c = curl_init($url);
|
|
||||||
curl_setopt($c, CURLOPT_POST, 1);
|
|
||||||
curl_setopt($c, CURLOPT_POSTFIELDS, $params.'&token_auth='.self::$settings->getGlobalOption('piwik_token'));
|
|
||||||
} else $c = curl_init($url.'?'.$params.'&token_auth='.self::$settings->getGlobalOption('piwik_token'));
|
|
||||||
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, !self::$settings->getGlobalOption('disable_ssl_verify'));
|
|
||||||
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, !self::$settings->getGlobalOption('disable_ssl_verify_host')?2:0);
|
|
||||||
curl_setopt($c, CURLOPT_USERAGENT, self::$settings->getGlobalOption('piwik_useragent')=='php'?ini_get('user_agent'):self::$settings->getGlobalOption('piwik_useragent_string'));
|
|
||||||
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
curl_setopt($c, CURLOPT_HEADER, $GLOBALS ['wp-piwik_debug'] );
|
|
||||||
curl_setopt($c, CURLOPT_TIMEOUT, self::$settings->getGlobalOption('connection_timeout'));
|
|
||||||
$httpProxyClass = new \WP_HTTP_Proxy();
|
|
||||||
if ($httpProxyClass->is_enabled() && $httpProxyClass->send_through_proxy($url)) {
|
|
||||||
curl_setopt($c, CURLOPT_PROXY, $httpProxyClass->host());
|
|
||||||
curl_setopt($c, CURLOPT_PROXYPORT, $httpProxyClass->port());
|
|
||||||
if ($httpProxyClass->use_authentication())
|
|
||||||
curl_setopt($c, CURLOPT_PROXYUSERPWD, $httpProxyClass->username().':'.$httpProxyClass->password());
|
|
||||||
}
|
|
||||||
$result = curl_exec($c);
|
|
||||||
self::$lastError = curl_error($c);
|
|
||||||
if ($GLOBALS ['wp-piwik_debug']) {
|
|
||||||
$header_size = curl_getinfo($c, CURLINFO_HEADER_SIZE);
|
|
||||||
$header = substr($result, 0, $header_size);
|
|
||||||
$body = substr($result, $header_size);
|
|
||||||
$result = $this->unserialize($body);
|
|
||||||
self::$debug[$id] = array ( $header, $url.'?'.$params.'&token_auth=...' );
|
|
||||||
} else $result = $this->unserialize($result);
|
|
||||||
curl_close($c);
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function fopen($id, $url, $params) {
|
private function curl( $id, $url, $params ) {
|
||||||
$contextDefinition = array('http'=>array('timeout' => self::$settings->getGlobalOption('connection_timeout'), 'header' => "Content-type: application/x-www-form-urlencoded\r\n") );
|
if ( 'post' === self::$settings->get_global_option( 'http_method' ) ) {
|
||||||
$contextDefinition['ssl'] = array();
|
$c = curl_init( $url );
|
||||||
if (self::$settings->getGlobalOption('disable_ssl_verify'))
|
curl_setopt( $c, CURLOPT_POST, 1 );
|
||||||
$contextDefinition['ssl'] = array('allow_self_signed' => true, 'verify_peer' => false );
|
curl_setopt( $c, CURLOPT_POSTFIELDS, $params . '&token_auth=' . self::$settings->get_global_option( 'piwik_token' ) );
|
||||||
if (self::$settings->getGlobalOption('disable_ssl_verify_host'))
|
} else {
|
||||||
$contextDefinition['ssl']['verify_peer_name'] = false;
|
$c = curl_init( $url . '?' . $params . '&token_auth=' . self::$settings->get_global_option( 'piwik_token' ) );
|
||||||
if (self::$settings->getGlobalOption('http_method')=='post') {
|
|
||||||
$fullUrl = $url;
|
|
||||||
$contextDefinition['http']['method'] = 'POST';
|
|
||||||
$contextDefinition['http']['content'] = $params.'&token_auth='.self::$settings->getGlobalOption('piwik_token');
|
|
||||||
} else $fullUrl = $url.'?'.$params.'&token_auth='.self::$settings->getGlobalOption('piwik_token');
|
|
||||||
$context = stream_context_create($contextDefinition);
|
|
||||||
$result = $this->unserialize(@file_get_contents($fullUrl, false, $context));
|
|
||||||
if ($GLOBALS ['wp-piwik_debug'])
|
|
||||||
self::$debug[$id] = array ( get_headers($fullUrl, 1), $url.'?'.$params.'&token_auth=...' );
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
}
|
curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, ! self::$settings->get_global_option( 'disable_ssl_verify' ) );
|
||||||
|
curl_setopt( $c, CURLOPT_SSL_VERIFYHOST, ! self::$settings->get_global_option( 'disable_ssl_verify_host' ) ? 2 : 0 );
|
||||||
|
curl_setopt( $c, CURLOPT_USERAGENT, 'php' === self::$settings->get_global_option( 'piwik_useragent' ) ? ini_get( 'user_agent' ) : self::$settings->get_global_option( 'piwik_useragent_string' ) );
|
||||||
|
curl_setopt( $c, CURLOPT_RETURNTRANSFER, 1 );
|
||||||
|
curl_setopt( $c, CURLOPT_HEADER, $GLOBALS ['wp-piwik_debug'] );
|
||||||
|
curl_setopt( $c, CURLOPT_TIMEOUT, self::$settings->get_global_option( 'connection_timeout' ) );
|
||||||
|
$http_proxy_class = new \WP_HTTP_Proxy();
|
||||||
|
if ( $http_proxy_class->is_enabled() && $http_proxy_class->send_through_proxy( $url ) ) {
|
||||||
|
curl_setopt( $c, CURLOPT_PROXY, $http_proxy_class->host() );
|
||||||
|
curl_setopt( $c, CURLOPT_PROXYPORT, $http_proxy_class->port() );
|
||||||
|
if ( $http_proxy_class->use_authentication() ) {
|
||||||
|
curl_setopt( $c, CURLOPT_PROXYUSERPWD, $http_proxy_class->username() . ':' . $http_proxy_class->password() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = curl_exec( $c );
|
||||||
|
self::$last_error = curl_error( $c );
|
||||||
|
if ( $GLOBALS ['wp-piwik_debug'] ) {
|
||||||
|
$header_size = curl_getinfo( $c, CURLINFO_HEADER_SIZE );
|
||||||
|
$header = substr( $result, 0, $header_size );
|
||||||
|
$body = substr( $result, $header_size );
|
||||||
|
$result = $this->unserialize( $body );
|
||||||
|
self::$debug[ $id ] = array( $header, $url . '?' . $params . '&token_auth=...' );
|
||||||
|
} else {
|
||||||
|
$result = $this->unserialize( $result );
|
||||||
|
}
|
||||||
|
curl_close( $c );
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fopen( $id, $url, $params ) {
|
||||||
|
$context_definition = array(
|
||||||
|
'http' => array(
|
||||||
|
'timeout' => self::$settings->get_global_option( 'connection_timeout' ),
|
||||||
|
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$context_definition['ssl'] = array();
|
||||||
|
if ( self::$settings->get_global_option( 'disable_ssl_verify' ) ) {
|
||||||
|
$context_definition['ssl'] = array(
|
||||||
|
'allow_self_signed' => true,
|
||||||
|
'verify_peer' => false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( self::$settings->get_global_option( 'disable_ssl_verify_host' ) ) {
|
||||||
|
$context_definition['ssl']['verify_peer_name'] = false;
|
||||||
|
}
|
||||||
|
if ( self::$settings->get_global_option( 'http_method' ) === 'post' ) {
|
||||||
|
$full_url = $url;
|
||||||
|
$context_definition['http']['method'] = 'POST';
|
||||||
|
$context_definition['http']['content'] = $params . '&token_auth=' . self::$settings->get_global_option( 'piwik_token' );
|
||||||
|
} else {
|
||||||
|
$full_url = $url . '?' . $params . '&token_auth=' . self::$settings->get_global_option( 'piwik_token' );
|
||||||
|
}
|
||||||
|
$context = stream_context_create( $context_definition );
|
||||||
|
|
||||||
|
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
||||||
|
$result = $this->unserialize( @file_get_contents( $full_url, false, $context ) );
|
||||||
|
if ( $GLOBALS ['wp-piwik_debug'] ) {
|
||||||
|
self::$debug[ $id ] = array( get_headers( $full_url, 1 ), $url . '?' . $params . '&token_auth=...' );
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,427 +1,486 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik;
|
namespace WP_Piwik;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage WP-Piwik settings
|
* Manage WP-Piwik settings
|
||||||
*
|
*
|
||||||
* @author André Bräkling
|
* @author André Bräkling
|
||||||
* @package WP_Piwik
|
* @package WP_Piwik
|
||||||
*/
|
*
|
||||||
class Settings {
|
* TODO: do not disable this at some point
|
||||||
|
* @phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
/**
|
* @phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
|
||||||
*
|
*/
|
||||||
* @var Environment variables and default settings container
|
class Settings {
|
||||||
*/
|
|
||||||
private static $wpPiwik, $defaultSettings;
|
const TRACK_AI_BOTS = 'track_ai_bots';
|
||||||
|
const TRACK_AI_BOTS_USING_ESI = 'track_ai_bots_using_esi';
|
||||||
/**
|
|
||||||
*
|
/**
|
||||||
* @var Define callback functions for changed settings
|
* @var \WP_Piwik variables and default settings container
|
||||||
*/
|
*/
|
||||||
private $checkSettings = array (
|
private static $wp_piwik;
|
||||||
'piwik_url' => 'checkPiwikUrl',
|
|
||||||
'piwik_token' => 'checkPiwikToken',
|
private static $default_settings;
|
||||||
'site_id' => 'requestPiwikSiteID',
|
|
||||||
'tracking_code' => 'prepareTrackingCode',
|
/**
|
||||||
'noscript_code' => 'prepareNocscriptCode'
|
*
|
||||||
);
|
* @var array Define callback functions for changed settings
|
||||||
|
*/
|
||||||
/**
|
private $check_settings = array(
|
||||||
*
|
'piwik_url' => 'check_piwik_url',
|
||||||
* @var Register default configuration set
|
'piwik_token' => 'check_piwik_token',
|
||||||
*/
|
'site_id' => 'request_piwik_site_id',
|
||||||
private $globalSettings = array (
|
'tracking_code' => 'prepare_tracking_code',
|
||||||
// Plugin settings
|
'noscript_code' => 'prepare_nocscript_code',
|
||||||
'revision' => 0,
|
);
|
||||||
'last_settings_update' => 0,
|
|
||||||
// User settings: Piwik configuration
|
/**
|
||||||
'piwik_mode' => 'http',
|
* @var array default configuration set
|
||||||
'piwik_url' => '',
|
*/
|
||||||
'piwik_path' => '',
|
private $global_settings = array(
|
||||||
'piwik_user' => '',
|
// Plugin settings
|
||||||
'matomo_user' => '',
|
'revision' => 0,
|
||||||
'piwik_token' => '',
|
'last_settings_update' => 0,
|
||||||
'auto_site_config' => true,
|
// User settings: Piwik configuration
|
||||||
// User settings: Stats configuration
|
'piwik_mode' => 'http',
|
||||||
'default_date' => 'yesterday',
|
'piwik_url' => '',
|
||||||
'stats_seo' => false,
|
'piwik_path' => '',
|
||||||
'stats_ecommerce' => false,
|
'piwik_user' => '',
|
||||||
'dashboard_widget' => false,
|
'matomo_user' => '',
|
||||||
'dashboard_ecommerce' => false,
|
'piwik_token' => '',
|
||||||
'dashboard_chart' => false,
|
'auto_site_config' => true,
|
||||||
'dashboard_seo' => false,
|
// User settings: Stats configuration
|
||||||
'toolbar' => false,
|
'default_date' => 'yesterday',
|
||||||
'capability_read_stats' => array (
|
'stats_seo' => false,
|
||||||
'administrator' => true
|
'stats_ecommerce' => false,
|
||||||
),
|
'dashboard_widget' => false,
|
||||||
'perpost_stats' => "disabled",
|
'dashboard_ecommerce' => false,
|
||||||
'plugin_display_name' => 'Connect Matomo',
|
'dashboard_chart' => false,
|
||||||
'piwik_shortcut' => false,
|
'dashboard_seo' => false,
|
||||||
'shortcodes' => false,
|
'toolbar' => false,
|
||||||
// User settings: Tracking configuration
|
'capability_read_stats' => array(
|
||||||
'track_mode' => 'disabled',
|
'administrator' => true,
|
||||||
'track_codeposition' => 'footer',
|
),
|
||||||
'track_noscript' => false,
|
'perpost_stats' => 'disabled',
|
||||||
'track_nojavascript' => false,
|
'plugin_display_name' => 'Connect Matomo',
|
||||||
'proxy_url' => '',
|
'piwik_shortcut' => false,
|
||||||
'track_content' => 'disabled',
|
'shortcodes' => false,
|
||||||
'track_search' => false,
|
// User settings: Tracking configuration
|
||||||
'track_404' => false,
|
'track_mode' => 'disabled',
|
||||||
'add_post_annotations' => array(),
|
'track_codeposition' => 'footer',
|
||||||
'add_customvars_box' => false,
|
'track_noscript' => false,
|
||||||
'add_download_extensions' => '',
|
'track_nojavascript' => false,
|
||||||
'set_download_extensions' => '',
|
'proxy_url' => '',
|
||||||
'set_link_classes' => '',
|
'track_content' => 'disabled',
|
||||||
'set_download_classes' => '',
|
'track_search' => false,
|
||||||
'require_consent' => 'disabled',
|
'track_404' => false,
|
||||||
'disable_cookies' => false,
|
'add_post_annotations' => array(),
|
||||||
'limit_cookies' => false,
|
'add_customvars_box' => false,
|
||||||
'limit_cookies_visitor' => 34186669, // Piwik default 13 months
|
'add_download_extensions' => '',
|
||||||
'limit_cookies_session' => 1800, // Piwik default 30 minutes
|
'set_download_extensions' => '',
|
||||||
'limit_cookies_referral' => 15778463, // Piwik default 6 months
|
'set_link_classes' => '',
|
||||||
'track_admin' => false,
|
'set_download_classes' => '',
|
||||||
'capability_stealth' => array (),
|
'require_consent' => 'disabled',
|
||||||
'track_across' => false,
|
'disable_cookies' => false,
|
||||||
'track_across_alias' => false,
|
'limit_cookies' => false,
|
||||||
'track_crossdomain_linking' => false,
|
'limit_cookies_visitor' => 34186669, // Piwik default 13 months
|
||||||
'track_feed' => false,
|
'limit_cookies_session' => 1800, // Piwik default 30 minutes
|
||||||
'track_feed_addcampaign' => false,
|
'limit_cookies_referral' => 15778463, // Piwik default 6 months
|
||||||
'track_feed_campaign' => 'feed',
|
'track_admin' => false,
|
||||||
'track_heartbeat' => 0,
|
'capability_stealth' => array(),
|
||||||
'track_user_id' => 'disabled',
|
'track_across' => false,
|
||||||
// User settings: Expert configuration
|
'track_across_alias' => false,
|
||||||
'cache' => true,
|
'track_crossdomain_linking' => false,
|
||||||
'http_connection' => 'curl',
|
'track_feed' => false,
|
||||||
'http_method' => 'post',
|
'track_feed_addcampaign' => false,
|
||||||
'disable_timelimit' => false,
|
'track_feed_campaign' => 'feed',
|
||||||
'filter_limit' => '',
|
'track_heartbeat' => 0,
|
||||||
'connection_timeout' => 5,
|
'track_user_id' => 'disabled',
|
||||||
'disable_ssl_verify' => false,
|
// User settings: Expert configuration
|
||||||
'disable_ssl_verify_host' => false,
|
'cache' => true,
|
||||||
'piwik_useragent' => 'php',
|
'http_connection' => 'curl',
|
||||||
'piwik_useragent_string' => 'WP-Piwik',
|
'http_method' => 'post',
|
||||||
'dnsprefetch' => false,
|
'disable_timelimit' => false,
|
||||||
'track_datacfasync' => false,
|
'filter_limit' => '',
|
||||||
'track_cdnurl' => '',
|
'connection_timeout' => 5,
|
||||||
'track_cdnurlssl' => '',
|
'disable_ssl_verify' => false,
|
||||||
'force_protocol' => 'disabled',
|
'disable_ssl_verify_host' => false,
|
||||||
'remove_type_attribute' => false,
|
'piwik_useragent' => 'php',
|
||||||
'update_notice' => 'enabled'
|
'piwik_useragent_string' => 'WP-Piwik',
|
||||||
), $settings = array (
|
'dnsprefetch' => false,
|
||||||
'name' => '',
|
'track_datacfasync' => false,
|
||||||
'site_id' => NULL,
|
'track_cdnurl' => '',
|
||||||
'noscript_code' => '',
|
'track_cdnurlssl' => '',
|
||||||
'tracking_code' => '',
|
'force_protocol' => 'disabled',
|
||||||
'last_tracking_code_update' => 0,
|
'remove_type_attribute' => false,
|
||||||
'dashboard_revision' => 0
|
'update_notice' => 'enabled',
|
||||||
), $settingsChanged = false;
|
|
||||||
|
self::TRACK_AI_BOTS => false,
|
||||||
/**
|
self::TRACK_AI_BOTS_USING_ESI => false,
|
||||||
* Constructor class to prepare settings manager
|
);
|
||||||
*
|
|
||||||
* @param WP_Piwik $wpPiwik
|
private $settings = array(
|
||||||
* active WP-Piwik instance
|
'name' => '',
|
||||||
*/
|
'site_id' => null,
|
||||||
public function __construct($wpPiwik) {
|
'noscript_code' => '',
|
||||||
self::$wpPiwik = $wpPiwik;
|
'tracking_code' => '',
|
||||||
self::$wpPiwik->log ( 'Store default settings' );
|
'last_tracking_code_update' => 0,
|
||||||
self::$defaultSettings = array (
|
'dashboard_revision' => 0,
|
||||||
'globalSettings' => $this->globalSettings,
|
);
|
||||||
'settings' => $this->settings
|
|
||||||
);
|
private $settings_changed = false;
|
||||||
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 ));
|
* Constructor class to prepare settings manager
|
||||||
}
|
*
|
||||||
foreach ( $this->settings as $key => $default )
|
* @param \WP_Piwik $wp_piwik
|
||||||
$this->settings [$key] = get_option ( 'wp-piwik-' . $key, $default );
|
* active WP-Piwik instance
|
||||||
}
|
*/
|
||||||
|
public function __construct( $wp_piwik ) {
|
||||||
/**
|
self::$wp_piwik = $wp_piwik;
|
||||||
* Save all settings as WordPress options
|
self::$wp_piwik->log( 'Store default settings' );
|
||||||
*/
|
self::$default_settings = array(
|
||||||
public function save() {
|
'globalSettings' => $this->global_settings,
|
||||||
if (! $this->settingsChanged) {
|
'settings' => $this->settings,
|
||||||
self::$wpPiwik->log ( 'No settings changed yet' );
|
);
|
||||||
return;
|
self::$wp_piwik->log( 'Load settings' );
|
||||||
}
|
foreach ( $this->global_settings as $key => $default ) {
|
||||||
self::$wpPiwik->log ( 'Save settings' );
|
$this->global_settings [ $key ] = ( $this->check_network_activation() ? get_site_option( 'wp-piwik_global-' . $key, $default ) : get_option( 'wp-piwik_global-' . $key, $default ) );
|
||||||
$this->globalSettings['plugin_display_name'] = htmlspecialchars($this->globalSettings['plugin_display_name'], ENT_QUOTES, 'utf-8');
|
}
|
||||||
foreach ( $this->globalSettings as $key => $value ) {
|
foreach ( $this->settings as $key => $default ) {
|
||||||
if ( $this->checkNetworkActivation() )
|
$this->settings [ $key ] = get_option( 'wp-piwik-' . $key, $default );
|
||||||
update_site_option ( 'wp-piwik_global-' . $key, $value );
|
}
|
||||||
else
|
}
|
||||||
update_option ( 'wp-piwik_global-' . $key, $value );
|
|
||||||
}
|
/**
|
||||||
foreach ( $this->settings as $key => $value ) {
|
* Save all settings as WordPress options
|
||||||
update_option ( 'wp-piwik-' . $key, $value );
|
*/
|
||||||
}
|
public function save() {
|
||||||
global $wp_roles;
|
global $wp_roles;
|
||||||
if (! is_object ( $wp_roles ))
|
|
||||||
$wp_roles = new \WP_Roles ();
|
if ( ! $this->settings_changed ) {
|
||||||
if (! is_object ( $wp_roles ))
|
self::$wp_piwik->log( 'No settings changed yet' );
|
||||||
die ( "STILL NO OBJECT" );
|
return;
|
||||||
foreach ( $wp_roles->role_names as $strKey => $strName ) {
|
}
|
||||||
$objRole = get_role ( $strKey );
|
self::$wp_piwik->log( 'Save settings' );
|
||||||
foreach ( array (
|
$this->global_settings['plugin_display_name'] = htmlspecialchars( $this->global_settings['plugin_display_name'], ENT_QUOTES, 'utf-8' );
|
||||||
'stealth',
|
foreach ( $this->global_settings as $key => $value ) {
|
||||||
'read_stats'
|
if ( $this->check_network_activation() ) {
|
||||||
) as $strCap ) {
|
update_site_option( 'wp-piwik_global-' . $key, $value );
|
||||||
$aryCaps = $this->getGlobalOption ( 'capability_' . $strCap );
|
} else {
|
||||||
if (isset ( $aryCaps [$strKey] ) && $aryCaps [$strKey])
|
update_option( 'wp-piwik_global-' . $key, $value );
|
||||||
$wp_roles->add_cap ( $strKey, 'wp-piwik_' . $strCap );
|
}
|
||||||
else $wp_roles->remove_cap ( $strKey, 'wp-piwik_' . $strCap );
|
}
|
||||||
}
|
foreach ( $this->settings as $key => $value ) {
|
||||||
}
|
update_option( 'wp-piwik-' . $key, $value );
|
||||||
$this->settingsChanged = false;
|
}
|
||||||
}
|
foreach ( $wp_roles->role_names as $str_key => $str_name ) {
|
||||||
|
$obj_role = get_role( $str_key );
|
||||||
/**
|
$caps = array( 'stealth', 'read_stats' );
|
||||||
* Get a global option's value which should not be empty
|
foreach ( $caps as $str_cap ) {
|
||||||
*
|
$ary_caps = $this->get_global_option( 'capability_' . $str_cap );
|
||||||
* @param string $key
|
if ( isset( $ary_caps [ $str_key ] ) && $ary_caps [ $str_key ] ) {
|
||||||
* option key
|
$wp_roles->add_cap( $str_key, 'wp-piwik_' . $str_cap );
|
||||||
* @return string option value
|
} else {
|
||||||
*/
|
$wp_roles->remove_cap( $str_key, 'wp-piwik_' . $str_cap );
|
||||||
public function getNotEmptyGlobalOption($key) {
|
}
|
||||||
return isset ( $this->globalSettings [$key] ) && !empty($this->globalSettings [$key]) ? $this->globalSettings [$key] : self::$defaultSettings ['globalSettings'] [$key];
|
}
|
||||||
}
|
}
|
||||||
|
$this->settings_changed = false;
|
||||||
/**
|
}
|
||||||
* Get a global option's value
|
|
||||||
*
|
/**
|
||||||
* @param string $key
|
* Get a global option's value which should not be empty
|
||||||
* option key
|
*
|
||||||
* @return string option value
|
* @param string $key
|
||||||
*/
|
* option key
|
||||||
public function getGlobalOption($key) {
|
* @return string option value
|
||||||
return isset ( $this->globalSettings [$key] ) ? $this->globalSettings [$key] : self::$defaultSettings ['globalSettings'] [$key];
|
*/
|
||||||
}
|
public function get_not_empty_global_option( $key ) {
|
||||||
|
return isset( $this->global_settings [ $key ] ) && ! empty( $this->global_settings [ $key ] ) ? $this->global_settings [ $key ] : self::$default_settings ['globalSettings'] [ $key ];
|
||||||
/**
|
}
|
||||||
* Get an option's value related to a specific blog
|
|
||||||
*
|
/**
|
||||||
* @param string $key
|
* Get a global option's value
|
||||||
* option key
|
*
|
||||||
* @param int $blogID
|
* @param string $key
|
||||||
* blog ID (default: current blog)
|
* option key
|
||||||
* @return \WP_Piwik\Register
|
* @return mixed option value
|
||||||
*/
|
*/
|
||||||
public function getOption($key, $blogID = null) {
|
public function get_global_option( $key ) {
|
||||||
if ($this->checkNetworkActivation () && ! empty ( $blogID )) {
|
return isset( $this->global_settings [ $key ] ) ? $this->global_settings [ $key ] : self::$default_settings ['globalSettings'] [ $key ];
|
||||||
return get_blog_option ( $blogID, 'wp-piwik-'.$key );
|
}
|
||||||
}
|
|
||||||
return isset ( $this->settings [$key] ) ? $this->settings [$key] : self::$defaultSettings ['settings'] [$key];
|
/**
|
||||||
}
|
* Get an option's value related to a specific blog
|
||||||
|
*
|
||||||
/**
|
* @param string $key
|
||||||
* Set a global option's value
|
* option key
|
||||||
*
|
* @param int $blog_id
|
||||||
* @param string $key
|
* blog ID (default: current blog)
|
||||||
* option key
|
* @return mixed
|
||||||
* @param string $value
|
*/
|
||||||
* new option value
|
public function get_option( $key, $blog_id = null ) {
|
||||||
*/
|
if ( $this->check_network_activation() && ! empty( $blog_id ) ) {
|
||||||
public function setGlobalOption($key, $value) {
|
return get_blog_option( $blog_id, 'wp-piwik-' . $key );
|
||||||
$this->settingsChanged = true;
|
}
|
||||||
self::$wpPiwik->log ( 'Changed global option ' . $key . ': ' . (is_array ( $value ) ? serialize ( $value ) : $value) );
|
return isset( $this->settings [ $key ] ) ? $this->settings [ $key ] : self::$default_settings ['settings'] [ $key ];
|
||||||
$this->globalSettings [$key] = $value;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Set a global option's value
|
||||||
* Set an option's value related to a specific blog
|
*
|
||||||
*
|
* @param string $key
|
||||||
* @param string $key
|
* option key
|
||||||
* option key
|
* @param mixed $value
|
||||||
* @param string $value
|
* new option value
|
||||||
* new option value
|
*/
|
||||||
* @param int $blogID
|
public function set_global_option( $key, $value ) {
|
||||||
* blog ID (default: current blog)
|
$this->settings_changed = true;
|
||||||
*/
|
self::$wp_piwik->log( 'Changed global option ' . $key . ': ' . ( is_array( $value ) ? wp_json_encode( $value ) : $value ) );
|
||||||
public function setOption($key, $value, $blogID = null) {
|
$this->global_settings [ $key ] = $value;
|
||||||
if (empty( $blogID )) {
|
}
|
||||||
$blogID = get_current_blog_id();
|
|
||||||
}
|
/**
|
||||||
$this->settingsChanged = true;
|
* Set an option's value related to a specific blog
|
||||||
self::$wpPiwik->log ( 'Changed option ' . $key . ': ' . $value );
|
*
|
||||||
if ($this->checkNetworkActivation ()) {
|
* @param string $key
|
||||||
update_blog_option ( $blogID, 'wp-piwik-'.$key, $value );
|
* option key
|
||||||
}
|
* @param string $value
|
||||||
if ($blogID == get_current_blog_id()) {
|
* new option value
|
||||||
$this->settings [$key] = $value;
|
* @param int $blog_id
|
||||||
}
|
* blog ID (default: current blog)
|
||||||
}
|
*/
|
||||||
|
public function set_option( $key, $value, $blog_id = null ) {
|
||||||
/**
|
if ( empty( $blog_id ) ) {
|
||||||
* Reset settings to default
|
$blog_id = get_current_blog_id();
|
||||||
*/
|
}
|
||||||
public function resetSettings() {
|
$this->settings_changed = true;
|
||||||
self::$wpPiwik->log ( 'Reset WP-Piwik settings' );
|
self::$wp_piwik->log( 'Changed option ' . $key . ': ' . $value );
|
||||||
global $wpdb;
|
if ( $this->check_network_activation() ) {
|
||||||
if ( $this->checkNetworkActivation() ) {
|
update_blog_option( $blog_id, 'wp-piwik-' . $key, $value );
|
||||||
$aryBlogs = self::getBlogList();
|
}
|
||||||
if (is_array($aryBlogs))
|
if ( get_current_blog_id() === $blog_id ) {
|
||||||
foreach ($aryBlogs as $aryBlog) {
|
$this->settings [ $key ] = $value;
|
||||||
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-%'");
|
* Reset settings to default
|
||||||
}
|
*/
|
||||||
else $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'wp-piwik_global-%'");
|
public function reset_settings() {
|
||||||
}
|
self::$wp_piwik->log( 'Reset WP-Piwik settings' );
|
||||||
|
global $wpdb;
|
||||||
/**
|
if ( $this->check_network_activation() ) {
|
||||||
* Get blog list
|
$ary_blogs = self::get_blog_list();
|
||||||
*/
|
if ( is_array( $ary_blogs ) ) {
|
||||||
public static function getBlogList($limit = null, $page = null, $search = '') {
|
foreach ( $ary_blogs as $ary_blog ) {
|
||||||
if ($limit && $page)
|
switch_to_blog( $ary_blog['blog_id'] );
|
||||||
$queryLimit = ' LIMIT '.(int) (($page - 1) * $limit).','.(int) $limit;
|
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'wp-piwik-%'" );
|
||||||
global $wpdb;
|
restore_current_blog();
|
||||||
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);
|
}
|
||||||
}
|
}
|
||||||
|
$wpdb->query( "DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE 'wp-piwik_global-%'" );
|
||||||
/**
|
} else {
|
||||||
* Check if plugin is network activated
|
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'wp-piwik_global-%'" );
|
||||||
*
|
}
|
||||||
* @return boolean Is network activated?
|
}
|
||||||
*/
|
|
||||||
public function checkNetworkActivation() {
|
/**
|
||||||
if (! function_exists ( "is_plugin_active_for_network" ))
|
* Get blog list
|
||||||
require_once (ABSPATH . 'wp-admin/includes/plugin.php');
|
*/
|
||||||
return is_plugin_active_for_network ( 'wp-piwik/wp-piwik.php' );
|
public static function get_blog_list( $limit = null, $page = null, $search = '' ) {
|
||||||
}
|
global $wpdb;
|
||||||
|
|
||||||
/**
|
$query_limit = '';
|
||||||
* Apply new configuration
|
if ( $limit && $page ) {
|
||||||
*
|
$query_limit = ' LIMIT ' . (int) ( ( $page - 1 ) * $limit ) . ',' . (int) $limit;
|
||||||
* @param array $in
|
}
|
||||||
* new configuration set
|
|
||||||
*/
|
$like = '%' . $wpdb->esc_like( $search ) . '%';
|
||||||
public function applyChanges($in) {
|
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||||
if (!self::$wpPiwik->isValidOptionsPost())
|
return $wpdb->get_results( $wpdb->prepare( 'SELECT blog_id FROM %s WHERE CONCAT(domain, path) LIKE %s AND spam = 0 AND deleted = 0 ORDER BY blog_id' . $query_limit, $wpdb->blogs, $like ), ARRAY_A );
|
||||||
die("Invalid config changes.");
|
}
|
||||||
$in = $this->checkSettings ( $in );
|
|
||||||
self::$wpPiwik->log ( 'Apply changed settings:' );
|
/**
|
||||||
foreach ( self::$defaultSettings ['globalSettings'] as $key => $val )
|
* Check if plugin is network activated
|
||||||
$this->setGlobalOption ( $key, isset ( $in [$key] ) ? $in [$key] : $val );
|
*
|
||||||
foreach ( self::$defaultSettings ['settings'] as $key => $val )
|
* @return boolean Is network activated?
|
||||||
$this->setOption ( $key, isset ( $in [$key] ) ? $in [$key] : $val );
|
*/
|
||||||
$this->setGlobalOption ( 'last_settings_update', time () );
|
public function check_network_activation() {
|
||||||
$this->save ();
|
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 callback function on new settings
|
}
|
||||||
*
|
|
||||||
* @param array $in
|
/**
|
||||||
* new configuration set
|
* Apply new configuration
|
||||||
* @return array configuration set after callback functions were applied
|
*
|
||||||
*/
|
* @param array $in
|
||||||
private function checkSettings($in) {
|
* new configuration set
|
||||||
foreach ( $this->checkSettings as $key => $value )
|
*/
|
||||||
if (isset ( $in [$key] ))
|
public function apply_changes( $in ) {
|
||||||
$in [$key] = call_user_func_array ( array (
|
if ( ! self::$wp_piwik->is_valid_options_post() ) {
|
||||||
$this,
|
die( 'Invalid config changes.' );
|
||||||
$value
|
}
|
||||||
), array (
|
$in = $this->check_settings( $in );
|
||||||
$in [$key],
|
self::$wp_piwik->log( 'Apply changed settings:' );
|
||||||
$in
|
foreach ( self::$default_settings ['globalSettings'] as $key => $val ) {
|
||||||
) );
|
$this->set_global_option( $key, isset( $in [ $key ] ) ? $in [ $key ] : $val );
|
||||||
return $in;
|
}
|
||||||
}
|
foreach ( self::$default_settings ['settings'] as $key => $val ) {
|
||||||
|
$this->set_option( $key, isset( $in [ $key ] ) ? $in [ $key ] : $val );
|
||||||
/**
|
}
|
||||||
* Add slash to Piwik URL if necessary
|
$this->set_global_option( 'last_settings_update', (string) time() );
|
||||||
*
|
$this->save();
|
||||||
* @param string $value
|
}
|
||||||
* Piwik URL
|
|
||||||
* @param array $in
|
/**
|
||||||
* configuration set
|
* Apply callback function on new settings
|
||||||
* @return string Piwik URL
|
*
|
||||||
*/
|
* @param array $in new configuration set
|
||||||
private function checkPiwikUrl($value, $in) {
|
* @return array configuration set after callback functions were applied
|
||||||
return substr ( $value, - 1, 1 ) != '/' ? $value . '/' : $value;
|
*/
|
||||||
}
|
private function check_settings( $in ) {
|
||||||
|
foreach ( $this->check_settings as $key => $value ) {
|
||||||
/**
|
if ( isset( $in [ $key ] ) ) {
|
||||||
* Remove &token_auth= from auth token
|
$in [ $key ] = call_user_func_array(
|
||||||
*
|
array(
|
||||||
* @param string $value
|
$this,
|
||||||
* Piwik auth token
|
$value,
|
||||||
* @param array $in
|
),
|
||||||
* configuration set
|
array(
|
||||||
* @return string Piwik auth token
|
$in [ $key ],
|
||||||
*/
|
$in,
|
||||||
private function checkPiwikToken($value, $in) {
|
)
|
||||||
return str_replace ( '&token_auth=', '', $value );
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
return $in;
|
||||||
* Request the site ID (if not set before)
|
}
|
||||||
*
|
|
||||||
* @param string $value
|
/**
|
||||||
* tracking code
|
* Add slash to Piwik URL if necessary
|
||||||
* @param array $in
|
*
|
||||||
* configuration set
|
* @param string $value
|
||||||
* @return int Piwik site ID
|
* Piwik URL
|
||||||
*/
|
* @return string Piwik URL
|
||||||
private function requestPiwikSiteID($value, $in) {
|
* @phpstan-ignore method.unused
|
||||||
if ($in ['auto_site_config'] && ! $value)
|
*/
|
||||||
return self::$wpPiwik->getPiwikSiteId();
|
private function check_piwik_url( $value ) {
|
||||||
return $value;
|
return substr( $value, - 1, 1 ) !== '/' ? $value . '/' : $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the tracking code
|
* Remove &token_auth= from auth token
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* tracking code
|
* Piwik auth token
|
||||||
* @param array $in
|
* @return string Piwik auth token
|
||||||
* configuration set
|
* @phpstan-ignore method.unused
|
||||||
* @return string tracking code
|
*/
|
||||||
*/
|
private function check_piwik_token( $value ) {
|
||||||
private function prepareTrackingCode($value, $in) {
|
return str_replace( '&token_auth=', '', $value );
|
||||||
if ($in ['track_mode'] == 'manually' || $in ['track_mode'] == 'disabled') {
|
}
|
||||||
$value = stripslashes ( $value );
|
|
||||||
if ($this->checkNetworkActivation ())
|
/**
|
||||||
update_site_option ( 'wp-piwik-manually', $value );
|
* Request the site ID (if not set before)
|
||||||
return $value;
|
*
|
||||||
}
|
* @param string|int $value
|
||||||
/*$result = self::$wpPiwik->updateTrackingCode ();
|
* site ID setting value
|
||||||
echo '<pre>'; print_r($result); echo '</pre>';
|
* @param array $in
|
||||||
$this->setOption ( 'noscript_code', $result ['noscript'] );*/
|
* configuration set
|
||||||
return; // $result ['script'];
|
* @return int Piwik site ID
|
||||||
}
|
* @phpstan-ignore method.unused
|
||||||
|
*/
|
||||||
/**
|
private function request_piwik_site_id( $value, $in ) {
|
||||||
* Prepare the nocscript code
|
if ( $in ['auto_site_config'] && ! $value ) {
|
||||||
*
|
return self::$wp_piwik->get_piwik_site_id();
|
||||||
* @param string $value
|
}
|
||||||
* noscript code
|
return intval( $value );
|
||||||
* @param array $in
|
}
|
||||||
* configuration set
|
|
||||||
* @return string noscript code
|
/**
|
||||||
*/
|
* Prepare the tracking code
|
||||||
private function prepareNocscriptCode($value, $in) {
|
*
|
||||||
if ($in ['track_mode'] == 'manually')
|
* @param string $value
|
||||||
return stripslashes ( $value );
|
* tracking code
|
||||||
return $this->getOption ( 'noscript_code' );
|
* @param array $in
|
||||||
}
|
* configuration set
|
||||||
|
* @return string tracking code
|
||||||
/**
|
* @phpstan-ignore method.unused
|
||||||
* Get debug data
|
*/
|
||||||
*
|
private function prepare_tracking_code( $value, $in ) {
|
||||||
* @return array WP-Piwik settings for debug output
|
if ( 'manually' === $in['track_mode'] || 'disabled' === $in['track_mode'] ) {
|
||||||
*/
|
$value = stripslashes( $value );
|
||||||
public function getDebugData() {
|
if ( $this->check_network_activation() ) {
|
||||||
$debug = array(
|
update_site_option( 'wp-piwik-manually', $value );
|
||||||
'global_settings' => $this->globalSettings,
|
}
|
||||||
'settings' => $this->settings
|
return $value;
|
||||||
);
|
}
|
||||||
$debug['global_settings']['piwik_token'] = !empty($debug['global_settings']['piwik_token'])?'set':'not set';
|
|
||||||
return $debug;
|
return '';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Prepare the nocscript code
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* noscript code
|
||||||
|
* @param array $in
|
||||||
|
* configuration set
|
||||||
|
* @return string noscript code
|
||||||
|
* @phpstan-ignore method.unused
|
||||||
|
*/
|
||||||
|
private function prepare_nocscript_code( $value, $in ) {
|
||||||
|
if ( 'manually' === $in['track_mode'] ) {
|
||||||
|
return stripslashes( $value );
|
||||||
|
}
|
||||||
|
return $this->get_option( 'noscript_code' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get debug data
|
||||||
|
*
|
||||||
|
* @return array WP-Piwik settings for debug output
|
||||||
|
*/
|
||||||
|
public function get_debug_data() {
|
||||||
|
$debug = array(
|
||||||
|
'global_settings' => $this->global_settings,
|
||||||
|
'settings' => $this->settings,
|
||||||
|
);
|
||||||
|
$debug['global_settings']['piwik_token'] = ! empty( $debug['global_settings']['piwik_token'] ) ? 'set' : 'not set';
|
||||||
|
return $debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_ai_bot_tracking_enabled() {
|
||||||
|
return (bool) $this->get_global_option( self::TRACK_AI_BOTS );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_ai_bot_tracking_enabled_via_esi_includes() {
|
||||||
|
return (bool) $this->get_global_option( self::TRACK_AI_BOTS_USING_ESI );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_track_via_esi_enabled() {
|
||||||
|
return true === (bool) $this->get_global_option( 'track_ai_bots_using_esi' );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_matomo_url() {
|
||||||
|
if ( 'http' === $this->get_global_option( 'piwik_mode' ) ) {
|
||||||
|
return $this->get_global_option( 'piwik_url' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( 'cloud' === $this->get_global_option( 'piwik_mode' ) ) {
|
||||||
|
return 'https://' . $this->get_global_option( 'piwik_user' ) . '.innocraft.cloud/';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'https://' . $this->get_global_option( 'matomo_user' ) . '.matomo.cloud/';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_tracking_enabled() {
|
||||||
|
return 'disabled' !== $this->get_global_option( 'track_mode' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,28 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik;
|
namespace WP_Piwik;
|
||||||
|
|
||||||
class Shortcode {
|
class Shortcode {
|
||||||
|
|
||||||
private $available = array(
|
private $available = array(
|
||||||
'opt-out' => 'OptOut',
|
'opt-out' => 'OptOut',
|
||||||
'post' => 'Post',
|
'post' => 'Post',
|
||||||
'overview' => 'Overview'
|
'overview' => 'Overview',
|
||||||
), $content;
|
);
|
||||||
|
|
||||||
public function __construct($attributes, $wpPiwik, $settings) {
|
private $content;
|
||||||
$wpPiwik->log('Check requested shortcode widget '.$attributes['module']);
|
|
||||||
if (isset($attributes['module']) && isset($this->available[$attributes['module']])) {
|
/**
|
||||||
$wpPiwik->log('Add shortcode widget '.$this->available[$attributes['module']]);
|
* @param array $attributes
|
||||||
$class = '\\WP_Piwik\\Widget\\'.$this->available[$attributes['module']];
|
* @param \WP_Piwik $wp_piwik
|
||||||
$widget = new $class($wpPiwik, $settings, null, null, null, $attributes, true);
|
* @param Settings $settings
|
||||||
$widget->show();
|
*/
|
||||||
$this->content = $widget->get();
|
public function __construct( $attributes, $wp_piwik, $settings ) {
|
||||||
}
|
$wp_piwik->log( 'Check requested shortcode widget ' . $attributes['module'] );
|
||||||
|
if ( isset( $attributes['module'] ) && isset( $this->available[ $attributes['module'] ] ) ) {
|
||||||
|
$wp_piwik->log( 'Add shortcode widget ' . $this->available[ $attributes['module'] ] );
|
||||||
|
$class = '\\WP_Piwik\\Widget\\' . $this->available[ $attributes['module'] ];
|
||||||
|
$widget = new $class( $wp_piwik, $settings, null, null, null, $attributes, true );
|
||||||
|
$widget->show();
|
||||||
|
$this->content = $widget->get();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public function get() {
|
|
||||||
return $this->content;
|
public function get() {
|
||||||
}
|
return $this->content;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,31 +1,45 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik;
|
namespace WP_Piwik;
|
||||||
|
|
||||||
class Template {
|
class Template {
|
||||||
|
|
||||||
public static $logger, $settings, $wpPiwik;
|
|
||||||
|
|
||||||
public function __construct($wpPiwik, $settings) {
|
|
||||||
self::$settings = $settings;
|
|
||||||
self::$wpPiwik = $wpPiwik;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function output($array, $key, $default = '') {
|
/**
|
||||||
if (isset($array[$key]))
|
* @var Logger
|
||||||
return $array[$key];
|
*/
|
||||||
else
|
public static $logger;
|
||||||
return $default;
|
|
||||||
|
/**
|
||||||
|
* @var Settings
|
||||||
|
*/
|
||||||
|
public static $settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \WP_Piwik
|
||||||
|
*/
|
||||||
|
public static $wp_piwik;
|
||||||
|
|
||||||
|
public function __construct( $wp_piwik, $settings ) {
|
||||||
|
self::$settings = $settings;
|
||||||
|
self::$wp_piwik = $wp_piwik;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function output( $values, $key, $default_value = '' ) {
|
||||||
|
if ( isset( $values[ $key ] ) ) {
|
||||||
|
return $values[ $key ];
|
||||||
|
} else {
|
||||||
|
return $default_value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public function tabRow($name, $value) {
|
|
||||||
echo '<tr><td>'.$name.'</td><td>'.$value.'</td></tr>';
|
public function tab_row( $name, $value ) {
|
||||||
}
|
echo '<tr><td>' . esc_html( $name ) . '</td><td>' . esc_html( $value ) . '</td></tr>';
|
||||||
|
}
|
||||||
public function getRangeLast30() {
|
|
||||||
$diff = (self::$settings->getGlobalOption('default_date') == 'yesterday') ? -86400 : 0;
|
public function get_range_last30() {
|
||||||
$end = time() + $diff;
|
$diff = ( self::$settings->get_global_option( 'default_date' ) === 'yesterday' ) ? -86400 : 0;
|
||||||
$start = time() - 2592000 + $diff;
|
$end = time() + $diff;
|
||||||
return date('Y-m-d', $start).','.date('Y-m-d', $end);
|
$start = time() - 2592000 + $diff;
|
||||||
}
|
return gmdate( 'Y-m-d', $start ) . ',' . gmdate( 'Y-m-d', $end );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,63 +1,74 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Template;
|
namespace WP_Piwik\Template;
|
||||||
|
|
||||||
class MetaBoxCustomVars extends \WP_Piwik\Template {
|
class MetaBoxCustomVars extends \WP_Piwik\Template {
|
||||||
|
|
||||||
public function addMetabox() {
|
|
||||||
add_meta_box(
|
|
||||||
'wp-piwik_post_customvars',
|
|
||||||
__('Piwik Custom Variables', 'wp-piwik'),
|
|
||||||
array(&$this, 'showCustomvars'),
|
|
||||||
array('post', 'page', 'custom_post_type'),
|
|
||||||
'side',
|
|
||||||
'default'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function showCustomvars($objPost, $objBox ) {
|
public function addMetabox() {
|
||||||
wp_nonce_field(basename( __FILE__ ), 'wp-piwik_post_customvars_nonce'); ?>
|
add_meta_box(
|
||||||
|
'wp-piwik_post_customvars',
|
||||||
|
__( 'Piwik Custom Variables', 'wp-piwik' ),
|
||||||
|
array( &$this, 'showCustomvars' ),
|
||||||
|
array( 'post', 'page', 'custom_post_type' ),
|
||||||
|
'side',
|
||||||
|
'default'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showCustomvars( $obj_post, $obj_box ) {
|
||||||
|
wp_nonce_field( basename( __FILE__ ), 'wp-piwik_post_customvars_nonce' ); ?>
|
||||||
<table>
|
<table>
|
||||||
<tr><th></th><th><?php _e('Name', 'wp-piwik'); ?></th><th><?php _e('Value', 'wp-piwik'); ?></th></tr>
|
<tr><th></th><th><?php esc_html_e( 'Name', 'wp-piwik' ); ?></th><th><?php esc_html_e( 'Value', 'wp-piwik' ); ?></th></tr>
|
||||||
<?php for($i = 1; $i <= 5; $i++) { ?>
|
<?php for ( $i = 1; $i <= 5; $i++ ) { ?>
|
||||||
<tr>
|
<tr>
|
||||||
<th><label for="wp-piwik_customvar1"><?php echo $i; ?>: </label></th>
|
<th><label for="wp-piwik_customvar1"><?php echo esc_attr( $i ); // @phpstan-ignore-line ?>: </label></th>
|
||||||
<td><input class="widefat" type="text" name="wp-piwik_custom_cat<?php echo $i; ?>" value="<?php echo esc_attr(get_post_meta($objPost->ID, 'wp-piwik_custom_cat'.$i, true ) ); ?>" size="200" /></td>
|
<td><input class="widefat" type="text" name="wp-piwik_custom_cat<?php echo esc_attr( $i ); // @phpstan-ignore-line ?>" value="<?php echo esc_attr( get_post_meta( $obj_post->ID, 'wp-piwik_custom_cat' . $i, true ) ); ?>" size="200" /></td>
|
||||||
<td><input class="widefat" type="text" name="wp-piwik_custom_val<?php echo $i; ?>" value="<?php echo esc_attr(get_post_meta($objPost->ID, 'wp-piwik_custom_val'.$i, true ) ); ?>" size="200" /></td>
|
<td><input class="widefat" type="text" name="wp-piwik_custom_val<?php echo esc_attr( $i ); // @phpstan-ignore-line ?>" value="<?php echo esc_attr( get_post_meta( $obj_post->ID, 'wp-piwik_custom_val' . $i, true ) ); ?>" size="200" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</table>
|
</table>
|
||||||
<p><?php _e('Set custom variables for a page view', 'wp-piwik'); ?>. (<a href="http://piwik.org/docs/custom-variables/"><?php _e('More information', 'wp-piwik'); ?></a>.)</p>
|
<p><?php esc_html_e( 'Set custom variables for a page view', 'wp-piwik' ); ?>. (<a href="http://piwik.org/docs/custom-variables/"><?php esc_html_e( 'More information', 'wp-piwik' ); ?></a>.)</p>
|
||||||
<?php
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveCustomVars( $int_id, $obj_post ) {
|
||||||
|
// Verify the nonce before proceeding.
|
||||||
|
$nonce = isset( $_POST['wp-piwik_post_customvars_nonce'] )
|
||||||
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||||
|
? wp_unslash( $_POST['wp-piwik_post_customvars_nonce'] )
|
||||||
|
: '';
|
||||||
|
if (
|
||||||
|
empty( $nonce )
|
||||||
|
|| ! wp_verify_nonce( $nonce, basename( __FILE__ ) )
|
||||||
|
) {
|
||||||
|
return $int_id;
|
||||||
}
|
}
|
||||||
|
// Get post type object
|
||||||
public function saveCustomVars($intID, $objPost) {
|
$obj_post_type = get_post_type_object( $obj_post->post_type );
|
||||||
// Verify the nonce before proceeding.
|
// Check if the current user has permission to edit the post.
|
||||||
if (!isset( $_POST['wp-piwik_post_customvars_nonce'] ) || !wp_verify_nonce( $_POST['wp-piwik_post_customvars_nonce'], basename( __FILE__ ) ) )
|
if ( ! current_user_can( $obj_post_type->cap->edit_post, $int_id ) ) {
|
||||||
return $intID;
|
return $int_id;
|
||||||
// Get post type object
|
}
|
||||||
$objPostType = get_post_type_object($objPost->post_type);
|
$ary_names = array( 'cat', 'val' );
|
||||||
// Check if the current user has permission to edit the post.
|
for ( $i = 1; $i <= 5; $i++ ) {
|
||||||
if (!current_user_can($objPostType->cap->edit_post, $intID))
|
for ( $j = 0; $j <= 1; $j++ ) {
|
||||||
return $intID;
|
// Create key
|
||||||
$aryNames = array('cat', 'val');
|
$str_meta_key = 'wp-piwik_custom_' . $ary_names[ $j ] . $i;
|
||||||
for ($i = 1; $i <= 5; $i++)
|
// Get data
|
||||||
for ($j = 0; $j <= 1; $j++) {
|
$str_meta_val = isset( $_POST[ $str_meta_key ] ) ? esc_html( $str_meta_key ) : '';
|
||||||
// Get data
|
// Get the meta value of the custom field key
|
||||||
$strMetaVal = (isset($_POST['wp-piwik_custom_'.$aryNames[$j].$i])?htmlentities($_POST['wp-piwik_custom_'.$aryNames[$j].$i]):'');
|
$str_cur_val = get_post_meta( $int_id, $str_meta_key, true );
|
||||||
// Create key
|
if ( $str_meta_val && '' === $str_cur_val ) {
|
||||||
$strMetaKey = 'wp-piwik_custom_'.$aryNames[$j].$i;
|
|
||||||
// Get the meta value of the custom field key
|
|
||||||
$strCurVal = get_post_meta($intID, $strMetaKey, true);
|
|
||||||
// Add meta val:
|
// Add meta val:
|
||||||
if ($strMetaVal && '' == $strCurVal)
|
add_post_meta( $int_id, $str_meta_key, $str_meta_val, true );
|
||||||
add_post_meta($intID, $strMetaKey, $strMetaVal, true);
|
} elseif ( $str_meta_val && $str_meta_val !== $str_cur_val ) {
|
||||||
// Update meta val:
|
// Update meta val:
|
||||||
elseif ($strMetaVal && $strMetaVal != $strCurVal)
|
update_post_meta( $int_id, $str_meta_key, $str_meta_val );
|
||||||
update_post_meta($intID, $strMetaKey, $strMetaVal);
|
} elseif ( '' === $str_meta_val && $str_cur_val ) {
|
||||||
// Delete meta val:
|
// Delete meta val:
|
||||||
elseif (''==$strMetaVal && $strCurVal)
|
delete_post_meta( $int_id, $str_meta_key, $str_cur_val );
|
||||||
delete_post_meta($intID, $strMetaKey, $strCurVal);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,167 +1,264 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik;
|
namespace WP_Piwik;
|
||||||
|
|
||||||
class TrackingCode {
|
class TrackingCode {
|
||||||
|
|
||||||
private static $wpPiwik, $piwikUrl = false;
|
/**
|
||||||
|
* @var \WP_Piwik
|
||||||
private $trackingCode;
|
*/
|
||||||
|
private static $wp_piwik;
|
||||||
public $is404 = false, $isSearch = false, $isUsertracking = false;
|
|
||||||
|
private $tracking_code;
|
||||||
public function __construct($wpPiwik) {
|
|
||||||
self::$wpPiwik = $wpPiwik;
|
public $is_404 = false;
|
||||||
if (! self::$wpPiwik->isCurrentTrackingCode () || ! self::$wpPiwik->getOption ( 'tracking_code' ) || strpos( self::$wpPiwik->getOption ( 'tracking_code' ), '{"result":"error",' ) !== false )
|
public $is_search = false;
|
||||||
self::$wpPiwik->updateTrackingCode ();
|
public $is_usertracking = false;
|
||||||
$this->trackingCode = (self::$wpPiwik->isNetworkMode () && self::$wpPiwik->getGlobalOption ( 'track_mode' ) == 'manually') ? get_site_option ( 'wp-piwik-manually' ) : self::$wpPiwik->getOption ( 'tracking_code' );
|
|
||||||
}
|
public function __construct( $wp_piwik ) {
|
||||||
|
self::$wp_piwik = $wp_piwik;
|
||||||
public function getTrackingCode() {
|
if ( ! self::$wp_piwik->is_current_tracking_code() || ! self::$wp_piwik->get_option( 'tracking_code' ) || strpos( self::$wp_piwik->get_option( 'tracking_code' ), '{"result":"error",' ) !== false ) {
|
||||||
if ($this->isUsertracking)
|
self::$wp_piwik->update_tracking_code();
|
||||||
$this->applyUserTracking ();
|
}
|
||||||
if ($this->is404)
|
$this->tracking_code = ( self::$wp_piwik->is_network_mode() && self::$wp_piwik->get_global_option( 'track_mode' ) === 'manually' ) ? get_site_option( 'wp-piwik-manually' ) : self::$wp_piwik->get_option( 'tracking_code' );
|
||||||
$this->apply404Changes ();
|
}
|
||||||
if ($this->isSearch)
|
|
||||||
$this->applySearchChanges ();
|
public function get_tracking_code() {
|
||||||
if (is_single () || is_page())
|
if ( $this->is_usertracking ) {
|
||||||
$this->addCustomValues ();
|
$this->apply_user_tracking();
|
||||||
$this->trackingCode = apply_filters('wp-piwik_tracking_code', $this->trackingCode);
|
}
|
||||||
return $this->trackingCode;
|
if ( $this->is_404 ) {
|
||||||
}
|
$this->apply_404_changes();
|
||||||
|
}
|
||||||
public static function prepareTrackingCode($code, $settings, $logger) {
|
if ( $this->is_search ) {
|
||||||
global $current_user;
|
$this->apply_search_changes();
|
||||||
$logger->log ( 'Apply tracking code changes:' );
|
}
|
||||||
$settings->setOption ( 'last_tracking_code_update', time () );
|
if ( is_single() || is_page() ) {
|
||||||
if (preg_match ( '/var u="([^"]*)";/', $code, $hits )) {
|
$this->add_custom_values();
|
||||||
$fetchedProxyUrl = $hits [1];
|
}
|
||||||
} else $fetchedProxyUrl = '';
|
// ignoring for BC
|
||||||
if ($settings->getGlobalOption ( 'remove_type_attribute')) {
|
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
|
||||||
$code = str_replace (
|
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||||
array( ' type="text/javascript"', " type='text/javascript'" ),
|
$this->tracking_code = apply_filters( 'wp-piwik_tracking_code', $this->tracking_code );
|
||||||
'',
|
return $this->tracking_code;
|
||||||
$code
|
}
|
||||||
);
|
|
||||||
}
|
/**
|
||||||
if ($settings->getGlobalOption ( 'track_mode' ) == 'js')
|
* @param string $code
|
||||||
$code = str_replace ( array (
|
* @param Settings $settings
|
||||||
'piwik.js',
|
* @param Logger $logger
|
||||||
'piwik.php',
|
* @return array
|
||||||
'matomo.js',
|
*/
|
||||||
'matomo.php'
|
public static function prepare_tracking_code( $code, $settings, $logger ) {
|
||||||
), 'js/index.php', $code );
|
global $current_user;
|
||||||
elseif ($settings->getGlobalOption ( 'track_mode' ) == 'proxy') {
|
$logger->log( 'Apply tracking code changes:' );
|
||||||
$code = str_replace ( 'piwik.js', 'matomo.php', $code );
|
$settings->set_option( 'last_tracking_code_update', (string) time() );
|
||||||
$code = str_replace ( 'matomo.js', 'matomo.php', $code );
|
if ( preg_match( '/var u="([^"]*)";/', $code, $hits ) ) {
|
||||||
$code = str_replace ( 'piwik.php', 'matomo.php', $code );
|
$fetched_proxy_url = $hits [1];
|
||||||
$proxy = str_replace ( array (
|
} else {
|
||||||
'https://',
|
$fetched_proxy_url = '';
|
||||||
'http://'
|
}
|
||||||
), '//', plugins_url ( 'wp-piwik' ) . '/proxy' ) . '/';
|
if ( $settings->get_global_option( 'remove_type_attribute' ) ) {
|
||||||
$code = preg_replace ( '/var u="([^"]*)";/', 'var u="' . $proxy . '"', $code );
|
$code = str_replace(
|
||||||
$code = preg_replace ( '/img src="([^"]*)piwik.php/', 'img src="' . $proxy . 'matomo.php', $code );
|
array( ' type="text/javascript"', " type='text/javascript'" ),
|
||||||
$code = preg_replace ( '/img src="([^"]*)matomo.php/', 'img src="' . $proxy . 'matomo.php', $code );
|
'',
|
||||||
}
|
$code
|
||||||
if ($settings->getGlobalOption ( 'track_cdnurl' ) || $settings->getGlobalOption ( 'track_cdnurlssl' ))
|
);
|
||||||
$code = str_replace ( array (
|
}
|
||||||
"var d=doc",
|
if ( 'js' === $settings->get_global_option( 'track_mode' ) ) {
|
||||||
"g.src=u+"
|
$code = str_replace(
|
||||||
), array (
|
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",
|
'piwik.js',
|
||||||
"g.src=ucdn+"
|
'piwik.php',
|
||||||
), $code );
|
'matomo.js',
|
||||||
|
'matomo.php',
|
||||||
if ($settings->getGlobalOption ( 'track_datacfasync' ))
|
),
|
||||||
$code = str_replace ( '<script type', '<script data-cfasync="false" type', $code );
|
'js/index.php',
|
||||||
if ($settings->getGlobalOption ( 'set_download_extensions' ))
|
$code
|
||||||
$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' ))
|
} elseif ( 'proxy' === $settings->get_global_option( 'track_mode' ) ) {
|
||||||
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['addDownloadExtensions', '" . ($settings->getGlobalOption ( 'add_download_extensions' )) . "']);\n_paq.push(['trackPageView']);", $code );
|
$code = str_replace( 'piwik.js', 'matomo.php', $code );
|
||||||
if ($settings->getGlobalOption ( 'set_download_classes' ))
|
$code = str_replace( 'matomo.js', 'matomo.php', $code );
|
||||||
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setDownloadClasses', '" . ($settings->getGlobalOption ( 'set_download_classes' )) . "']);\n_paq.push(['trackPageView']);", $code );
|
$code = str_replace( 'piwik.php', 'matomo.php', $code );
|
||||||
if ($settings->getGlobalOption ( 'set_link_classes' ))
|
$proxy = str_replace(
|
||||||
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setLinkClasses', '" . ($settings->getGlobalOption ( 'set_link_classes' )) . "']);\n_paq.push(['trackPageView']);", $code );
|
array(
|
||||||
if ($settings->getGlobalOption ( 'limit_cookies' ))
|
'https://',
|
||||||
$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 );
|
'http://',
|
||||||
if ($settings->getGlobalOption ( 'force_protocol' ) != 'disabled')
|
),
|
||||||
$code = str_replace ( '"//', '"' . $settings->getGlobalOption ( 'force_protocol' ) . '://', $code );
|
'//',
|
||||||
if ($settings->getGlobalOption ( 'track_content' ) == 'all')
|
plugins_url( 'wp-piwik' ) . '/proxy'
|
||||||
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['trackAllContentImpressions']);", $code );
|
) . '/';
|
||||||
elseif ($settings->getGlobalOption ( 'track_content' ) == 'visible')
|
$code = preg_replace( '/var u="([^"]*)";/', 'var u="' . $proxy . '"', $code );
|
||||||
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['trackVisibleContentImpressions']);", $code );
|
$code = preg_replace( '/img src="([^"]*)piwik.php/', 'img src="' . $proxy . 'matomo.php', $code );
|
||||||
if ((int) $settings->getGlobalOption ( 'track_heartbeat' ) > 0)
|
$code = preg_replace( '/img src="([^"]*)matomo.php/', 'img src="' . $proxy . 'matomo.php', $code );
|
||||||
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['enableHeartBeatTimer', ".(int) $settings->getGlobalOption ( 'track_heartbeat' )."]);", $code );
|
}
|
||||||
if ($settings->getGlobalOption ( 'require_consent' ) == 'consent') {
|
if ( $settings->get_global_option( 'track_cdnurl' ) || $settings->get_global_option( 'track_cdnurlssl' ) ) {
|
||||||
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['requireConsent']);\n_paq.push(['trackPageView']);", $code );
|
$code = str_replace(
|
||||||
} elseif ($settings->getGlobalOption ( 'require_consent' ) == 'cookieconsent') {
|
array(
|
||||||
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['requireCookieConsent']);\n_paq.push(['trackPageView']);", $code );
|
'var d=doc',
|
||||||
}
|
'g.src=u+',
|
||||||
|
),
|
||||||
$noScript = array ();
|
array(
|
||||||
preg_match ( '/<noscript>(.*)<\/noscript>/', $code, $noScript );
|
"var ucdn=(('https:' == document.location.protocol) ? 'https://" . ( $settings->get_global_option( 'track_cdnurlssl' ) ? $settings->get_global_option( 'track_cdnurlssl' ) : $settings->get_global_option( 'track_cdnurl' ) ) . "/' : 'http://" . ( $settings->get_global_option( 'track_cdnurl' ) ? $settings->get_global_option( 'track_cdnurl' ) : $settings->get_global_option( 'track_cdnurlssl' ) ) . "/');\nvar d=doc",
|
||||||
if (isset ( $noScript [0] )) {
|
'g.src=ucdn+',
|
||||||
if ($settings->getGlobalOption ( 'track_nojavascript' ))
|
),
|
||||||
$noScript [0] = str_replace ( '?idsite', '?rec=1&idsite', $noScript [0] );
|
$code
|
||||||
$noScript = $noScript [0];
|
);
|
||||||
} else
|
}
|
||||||
$noScript = '';
|
|
||||||
$script = preg_replace ( '/<noscript>(.*)<\/noscript>/', '', $code );
|
if ( $settings->get_global_option( 'track_datacfasync' ) ) {
|
||||||
$script = preg_replace ( '/\s+(\r\n|\r|\n)/', '$1', $script );
|
$code = str_replace( '<script type', '<script data-cfasync="false" type', $code );
|
||||||
$logger->log ( 'Finished tracking code: ' . $script );
|
}
|
||||||
$logger->log ( 'Finished noscript code: ' . $noScript );
|
|
||||||
return array (
|
if ( $settings->is_ai_bot_tracking_enabled() ) {
|
||||||
'script' => $script,
|
// recMode is a temporary parameter introduced in core to conditionally
|
||||||
'noscript' => $noScript,
|
// enable AI bot tracking. if AI bot tracking is enabled in Connect Matomo,
|
||||||
'proxy' => $fetchedProxyUrl
|
// we set it to `2` here, to enable "auto" mode when doing JS tracking. in
|
||||||
);
|
// this mode, tracking requests with AI bot user agents will be tracked as
|
||||||
}
|
// bots instead of visits, while all other requests will be tracked normally
|
||||||
|
// as visits.
|
||||||
private function apply404Changes() {
|
$code = str_replace(
|
||||||
self::$wpPiwik->log ( 'Apply 404 changes. Blog ID: ' . get_current_blog_id () . ' Site ID: ' . self::$wpPiwik->getOption ( 'site_id' ) );
|
"_paq.push(['trackPageView']);",
|
||||||
$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 );
|
"_paq.push(['appendToTrackingUrl', 'recMode=2']);\n_paq.push(['trackPageView']);",
|
||||||
}
|
$code
|
||||||
|
);
|
||||||
private function applySearchChanges() {
|
|
||||||
global $wp_query;
|
// set cookie via javascript cookie for known AI bots so we can skip tracking server side
|
||||||
self::$wpPiwik->log ( 'Apply search tracking changes. Blog ID: ' . get_current_blog_id () . ' Site ID: ' . self::$wpPiwik->getOption ( 'site_id' ) );
|
// for them.
|
||||||
$intResultCount = $wp_query->found_posts;
|
// NOTE: this must be done ONLY for known AI bots to be compliant with privacy regulations.
|
||||||
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackSiteSearch','" . get_search_query () . "', false, " . $intResultCount . "]);\n_paq.push(['trackPageView']);", $this->trackingCode );
|
$user_agent_substrings = wp_json_encode( AjaxTracker::AI_BOT_USER_AGENT_SUBSTRINGS );
|
||||||
}
|
|
||||||
|
$cookie_set_fn = <<<EOF
|
||||||
private function applyUserTracking() {
|
_paq.push([ function () {
|
||||||
$pkUserId = null;
|
var userAgentSubstrings = $user_agent_substrings;
|
||||||
if (\is_user_logged_in()) {
|
for (var i = 0; i < userAgentSubstrings.length; ++i) {
|
||||||
// Get the User ID Admin option, and the current user's data
|
var isAiBotUserAgent = navigator.userAgent.toLowerCase().indexOf(userAgentSubstrings[i].toLowerCase()) !== -1;
|
||||||
$uidFrom = self::$wpPiwik->getGlobalOption ( 'track_user_id' );
|
if (isAiBotUserAgent) {
|
||||||
$current_user = wp_get_current_user(); // current user
|
var path = this.getCookiePath();
|
||||||
// Get the user ID based on the admin setting
|
var domain = this.getCookieDomain();
|
||||||
if ( $uidFrom == 'uid' ) {
|
var sameSite = 'Lax';
|
||||||
$pkUserId = $current_user->ID;
|
document.cookie = 'matomo_has_js=1;path=' +
|
||||||
} elseif ( $uidFrom == 'email' ) {
|
(path || '/') +
|
||||||
$pkUserId = $current_user->user_email;
|
(domain ? ';domain=' + domain : '') +
|
||||||
} elseif ( $uidFrom == 'username' ) {
|
';SameSite=' + sameSite
|
||||||
$pkUserId = $current_user->user_login;
|
;
|
||||||
} elseif ( $uidFrom == 'displayname' ) {
|
return;
|
||||||
$pkUserId = $current_user->display_name;
|
}
|
||||||
}
|
}
|
||||||
}
|
} ]);
|
||||||
$pkUserId = apply_filters('wp-piwik_tracking_user_id', $pkUserId);
|
EOF;
|
||||||
// Check we got a User ID to track, and track it
|
|
||||||
if ( isset( $pkUserId ) && ! empty( $pkUserId ))
|
$code = str_replace(
|
||||||
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setUserId', '" . esc_js( $pkUserId ) . "']);\n_paq.push(['trackPageView']);", $this->trackingCode );
|
"_paq.push(['trackPageView']);",
|
||||||
}
|
$cookie_set_fn . "\n_paq.push(['trackPageView']);",
|
||||||
|
$code
|
||||||
private function addCustomValues() {
|
);
|
||||||
$customVars = '';
|
}
|
||||||
for($i = 1; $i <= 5; $i ++) {
|
|
||||||
$postId = get_the_ID ();
|
if ( $settings->get_global_option( 'set_download_extensions' ) ) {
|
||||||
$metaKey = get_post_meta ( $postId, 'wp-piwik_custom_cat' . $i, true );
|
$code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['setDownloadExtensions', " . wp_json_encode( $settings->get_global_option( 'set_download_extensions' ) ) . "]);\n_paq.push(['trackPageView']);", $code );
|
||||||
$metaVal = get_post_meta ( $postId, 'wp-piwik_custom_val' . $i, true );
|
}
|
||||||
if (! empty ( $metaKey ) && ! empty ( $metaVal ))
|
if ( $settings->get_global_option( 'add_download_extensions' ) ) {
|
||||||
$customVars .= "_paq.push(['setCustomVariable'," . $i . ", '" . $metaKey . "', '" . $metaVal . "', 'page']);\n";
|
$code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['addDownloadExtensions', " . wp_json_encode( $settings->get_global_option( 'add_download_extensions' ) ) . "]);\n_paq.push(['trackPageView']);", $code );
|
||||||
}
|
}
|
||||||
if (! empty ( $customVars ))
|
if ( $settings->get_global_option( 'set_download_classes' ) ) {
|
||||||
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", $customVars . "_paq.push(['trackPageView']);", $this->trackingCode );
|
$code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['setDownloadClasses', " . wp_json_encode( $settings->get_global_option( 'set_download_classes' ) ) . "]);\n_paq.push(['trackPageView']);", $code );
|
||||||
}
|
}
|
||||||
}
|
if ( $settings->get_global_option( 'set_link_classes' ) ) {
|
||||||
|
$code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['setLinkClasses', " . wp_json_encode( $settings->get_global_option( 'set_link_classes' ) ) . "]);\n_paq.push(['trackPageView']);", $code );
|
||||||
|
}
|
||||||
|
if ( $settings->get_global_option( 'limit_cookies' ) ) {
|
||||||
|
$code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['setVisitorCookieTimeout', " . wp_json_encode( $settings->get_global_option( 'limit_cookies_visitor' ) ) . "]);\n_paq.push(['setSessionCookieTimeout', " . wp_json_encode( $settings->get_global_option( 'limit_cookies_session' ) ) . "]);\n_paq.push(['setReferralCookieTimeout', " . wp_json_encode( $settings->get_global_option( 'limit_cookies_referral' ) ) . "]);\n_paq.push(['trackPageView']);", $code );
|
||||||
|
}
|
||||||
|
if ( 'disabled' !== $settings->get_global_option( 'force_protocol' ) ) {
|
||||||
|
$code = str_replace( '"//', '"' . $settings->get_global_option( 'force_protocol' ) . '://', $code );
|
||||||
|
}
|
||||||
|
if ( 'all' === $settings->get_global_option( 'track_content' ) ) {
|
||||||
|
$code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['trackAllContentImpressions']);", $code );
|
||||||
|
} elseif ( 'visible' === $settings->get_global_option( 'track_content' ) ) {
|
||||||
|
$code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['trackVisibleContentImpressions']);", $code );
|
||||||
|
}
|
||||||
|
if ( (int) $settings->get_global_option( 'track_heartbeat' ) > 0 ) {
|
||||||
|
$code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['enableHeartBeatTimer', " . (int) $settings->get_global_option( 'track_heartbeat' ) . ']);', $code );
|
||||||
|
}
|
||||||
|
if ( 'consent' === $settings->get_global_option( 'require_consent' ) ) {
|
||||||
|
$code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['requireConsent']);\n_paq.push(['trackPageView']);", $code );
|
||||||
|
} elseif ( 'cookieconsent' === $settings->get_global_option( 'require_consent' ) ) {
|
||||||
|
$code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['requireCookieConsent']);\n_paq.push(['trackPageView']);", $code );
|
||||||
|
}
|
||||||
|
|
||||||
|
$no_script = array();
|
||||||
|
preg_match( '/<noscript>(.*)<\/noscript>/', $code, $no_script );
|
||||||
|
if ( isset( $no_script [0] ) ) {
|
||||||
|
if ( $settings->get_global_option( 'track_nojavascript' ) ) {
|
||||||
|
$no_script [0] = str_replace( '?idsite', '?rec=1&idsite', $no_script [0] );
|
||||||
|
}
|
||||||
|
$no_script = $no_script [0];
|
||||||
|
} else {
|
||||||
|
$no_script = '';
|
||||||
|
}
|
||||||
|
$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: ' . $no_script );
|
||||||
|
return array(
|
||||||
|
'script' => $script,
|
||||||
|
'noscript' => $no_script,
|
||||||
|
'proxy' => $fetched_proxy_url,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function apply_404_changes() {
|
||||||
|
self::$wp_piwik->log( 'Apply 404 changes. Blog ID: ' . get_current_blog_id() . ' Site ID: ' . self::$wp_piwik->get_option( 'site_id' ) );
|
||||||
|
$this->tracking_code = 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->tracking_code );
|
||||||
|
}
|
||||||
|
|
||||||
|
private function apply_search_changes() {
|
||||||
|
global $wp_query;
|
||||||
|
self::$wp_piwik->log( 'Apply search tracking changes. Blog ID: ' . get_current_blog_id() . ' Site ID: ' . self::$wp_piwik->get_option( 'site_id' ) );
|
||||||
|
$int_result_count = $wp_query->found_posts;
|
||||||
|
$this->tracking_code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['trackSiteSearch','" . get_search_query() . "', false, " . $int_result_count . "]);\n_paq.push(['trackPageView']);", $this->tracking_code );
|
||||||
|
}
|
||||||
|
|
||||||
|
private function apply_user_tracking() {
|
||||||
|
$pk_user_id = null;
|
||||||
|
if ( \is_user_logged_in() ) {
|
||||||
|
// Get the User ID Admin option, and the current user's data
|
||||||
|
$uid_from = self::$wp_piwik->get_global_option( 'track_user_id' );
|
||||||
|
$current_user = wp_get_current_user(); // current user
|
||||||
|
// Get the user ID based on the admin setting
|
||||||
|
if ( 'uid' === $uid_from ) {
|
||||||
|
$pk_user_id = $current_user->ID;
|
||||||
|
} elseif ( 'email' === $uid_from ) {
|
||||||
|
$pk_user_id = $current_user->user_email;
|
||||||
|
} elseif ( 'username' === $uid_from ) {
|
||||||
|
$pk_user_id = $current_user->user_login;
|
||||||
|
} elseif ( 'displayname' === $uid_from ) {
|
||||||
|
$pk_user_id = $current_user->display_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ignoring for BC
|
||||||
|
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
|
||||||
|
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||||
|
$pk_user_id = apply_filters( 'wp-piwik_tracking_user_id', $pk_user_id );
|
||||||
|
// Check we got a User ID to track, and track it
|
||||||
|
if ( isset( $pk_user_id ) && ! empty( $pk_user_id ) ) {
|
||||||
|
$this->tracking_code = str_replace( "_paq.push(['trackPageView']);", "_paq.push(['setUserId', '" . esc_js( $pk_user_id ) . "']);\n_paq.push(['trackPageView']);", $this->tracking_code );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function add_custom_values() {
|
||||||
|
$custom_vars = '';
|
||||||
|
for ( $i = 1; $i <= 5; $i++ ) {
|
||||||
|
$post_id = get_the_ID();
|
||||||
|
$meta_key = get_post_meta( $post_id, 'wp-piwik_custom_cat' . $i, true );
|
||||||
|
$meta_val = get_post_meta( $post_id, 'wp-piwik_custom_val' . $i, true );
|
||||||
|
if ( ! empty( $meta_key ) && ! empty( $meta_val ) ) {
|
||||||
|
$custom_vars .= "_paq.push(['setCustomVariable'," . $i . ', ' . wp_json_encode( $meta_key ) . ', ' . wp_json_encode( $meta_val ) . ", 'page']);\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! empty( $custom_vars ) ) {
|
||||||
|
$this->tracking_code = str_replace( "_paq.push(['trackPageView']);", $custom_vars . "_paq.push(['trackPageView']);", $this->tracking_code );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,435 +1,476 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik;
|
namespace WP_Piwik;
|
||||||
|
|
||||||
use WP_Piwik;
|
use WP_Piwik;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract widget class
|
* Abstract widget class
|
||||||
*
|
*
|
||||||
* @author André Bräkling
|
* @author André Bräkling
|
||||||
* @package WP_Piwik
|
* @package WP_Piwik
|
||||||
*/
|
*/
|
||||||
abstract class Widget
|
abstract class Widget {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var WP_Piwik
|
* @var WP_Piwik
|
||||||
*/
|
*/
|
||||||
protected static $wpPiwik;
|
protected static $wp_piwik;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Settings
|
* @var Settings
|
||||||
*/
|
*/
|
||||||
protected static $settings;
|
protected static $settings;
|
||||||
|
|
||||||
protected $isShortcode = false, $method = '', $title = '', $context = 'side', $priority = 'core', $parameter = array(), $apiID = array(), $pageId = 'dashboard', $blogId = null, $name = 'Value', $limit = 10, $content = '', $output = '';
|
protected $is_shortcode = false;
|
||||||
|
protected $method = '';
|
||||||
/**
|
protected $title = '';
|
||||||
* Widget constructor
|
protected $context = 'side';
|
||||||
*
|
protected $priority = 'core';
|
||||||
* @param WP_Piwik $wpPiwik
|
protected $parameter = array();
|
||||||
* current WP-Piwik object
|
protected $api_id = array();
|
||||||
* @param Settings $settings
|
protected $page_id = 'dashboard';
|
||||||
* current WP-Piwik settings
|
protected $blog_id = null;
|
||||||
* @param string $pageId
|
protected $name = 'Value';
|
||||||
* WordPress page ID (default: dashboard)
|
protected $limit = 10;
|
||||||
* @param string $context
|
protected $content = '';
|
||||||
* WordPress meta box context (defualt: side)
|
protected $output = '';
|
||||||
* @param string $priority
|
|
||||||
* WordPress meta box priority (default: default)
|
/**
|
||||||
* @param array $params
|
* Widget constructor
|
||||||
* widget parameters (default: empty array)
|
*
|
||||||
* @param boolean $isShortcode
|
* @param WP_Piwik $wp_piwik
|
||||||
* is the widget shown inline? (default: false)
|
* current WP-Piwik object
|
||||||
*/
|
* @param Settings $settings
|
||||||
public function __construct($wpPiwik, $settings, $pageId = 'dashboard', $context = 'side', $priority = 'default', $params = array(), $isShortcode = false)
|
* current WP-Piwik settings
|
||||||
{
|
* @param string $page_id
|
||||||
self::$wpPiwik = $wpPiwik;
|
* WordPress page ID (default: dashboard)
|
||||||
self::$settings = $settings;
|
* @param string $context
|
||||||
$this->pageId = $pageId;
|
* WordPress meta box context (defualt: side)
|
||||||
$this->context = $context;
|
* @param string $priority
|
||||||
$this->priority = $priority;
|
* WordPress meta box priority (default: default)
|
||||||
if (self::$settings->checkNetworkActivation() && function_exists('is_super_admin') && is_super_admin() && isset ($_GET ['wpmu_show_stats'])) {
|
* @param array $params
|
||||||
switch_to_blog(( int )$_GET ['wpmu_show_stats']);
|
* widget parameters (default: empty array)
|
||||||
$this->blogId = get_current_blog_id();
|
* @param boolean $is_shortcode
|
||||||
restore_current_blog();
|
* is the widget shown inline? (default: false)
|
||||||
}
|
*/
|
||||||
$this->isShortcode = $isShortcode;
|
public function __construct( $wp_piwik, $settings, $page_id = 'dashboard', $context = 'side', $priority = 'default', $params = array(), $is_shortcode = false ) {
|
||||||
$prefix = ($this->pageId == 'dashboard' ? self::$settings->getGlobalOption('plugin_display_name') . ' - ' : '');
|
self::$wp_piwik = $wp_piwik;
|
||||||
$this->configure($prefix, $params);
|
self::$settings = $settings;
|
||||||
if (is_array($this->method))
|
$this->page_id = $page_id;
|
||||||
foreach ($this->method as $method) {
|
$this->context = $context;
|
||||||
$this->apiID [$method] = Request::register($method, $this->parameter);
|
$this->priority = $priority;
|
||||||
self::$wpPiwik->log("Register request: " . $this->apiID [$method]);
|
if ( self::$settings->check_network_activation() && function_exists( 'is_super_admin' ) && is_super_admin() && isset( $_GET ['wpmu_show_stats'] ) ) {
|
||||||
}
|
switch_to_blog( (int) $_GET ['wpmu_show_stats'] );
|
||||||
else {
|
$this->blog_id = get_current_blog_id();
|
||||||
$this->apiID [$this->method] = Request::register($this->method, $this->parameter);
|
restore_current_blog();
|
||||||
self::$wpPiwik->log("Register request: " . $this->apiID [$this->method]);
|
}
|
||||||
}
|
$this->is_shortcode = $is_shortcode;
|
||||||
if ($this->isShortcode)
|
$prefix = ( 'dashboard' === $this->page_id ? self::$settings->get_global_option( 'plugin_display_name' ) . ' - ' : '' );
|
||||||
return;
|
$this->configure( $prefix, $params );
|
||||||
add_meta_box($this->getName(), $this->title, array(
|
if ( is_array( $this->method ) ) {
|
||||||
$this,
|
foreach ( $this->method as $method ) {
|
||||||
'show'
|
$this->api_id [ $method ] = Request::register( $method, $this->parameter );
|
||||||
), $pageId, $this->context, $this->priority);
|
self::$wp_piwik->log( 'Register request: ' . $this->api_id [ $method ] );
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
/**
|
$this->api_id [ $this->method ] = Request::register( $this->method, $this->parameter );
|
||||||
* Conifguration dummy method
|
self::$wp_piwik->log( 'Register request: ' . $this->api_id [ $this->method ] );
|
||||||
*
|
}
|
||||||
* @param string $prefix
|
if ( $this->is_shortcode ) {
|
||||||
* metabox title prefix (default: empty)
|
return;
|
||||||
* @param array $params
|
}
|
||||||
* widget parameters (default: empty array)
|
add_meta_box(
|
||||||
*/
|
$this->get_name(),
|
||||||
protected function configure($prefix = '', $params = array())
|
$this->title,
|
||||||
{
|
array(
|
||||||
}
|
$this,
|
||||||
|
'show',
|
||||||
/**
|
),
|
||||||
* Default show widget method, handles default Piwik output
|
$page_id,
|
||||||
*/
|
$this->context,
|
||||||
public function show()
|
$this->priority
|
||||||
{
|
);
|
||||||
$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 {
|
* Conifguration dummy method
|
||||||
if (isset ($response [0] ['nb_uniq_visitors']))
|
*
|
||||||
$unique = 'nb_uniq_visitors';
|
* @param string $prefix
|
||||||
else
|
* metabox title prefix (default: empty)
|
||||||
$unique = 'sum_daily_nb_uniq_visitors';
|
* @param array $params
|
||||||
$tableHead = array(
|
* widget parameters (default: empty array)
|
||||||
'label' => __($this->name, 'wp-piwik')
|
*/
|
||||||
);
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$tableHead [$unique] = __('Unique', 'wp-piwik');
|
}
|
||||||
if (isset ($response [0] ['nb_visits']))
|
|
||||||
$tableHead ['nb_visits'] = __('Visits', 'wp-piwik');
|
/**
|
||||||
if (isset ($response [0] ['nb_hits']))
|
* Default show widget method, handles default Piwik output
|
||||||
$tableHead ['nb_hits'] = __('Hits', 'wp-piwik');
|
*/
|
||||||
if (isset ($response [0] ['nb_actions']))
|
public function show() {
|
||||||
$tableHead ['nb_actions'] = __('Actions', 'wp-piwik');
|
$response = self::$wp_piwik->request( $this->api_id [ $this->method ] );
|
||||||
$tableBody = array();
|
if ( ! empty( $response ['result'] ) && 'error' === $response['result'] ) {
|
||||||
$count = 0;
|
$this->out( '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] ) );
|
||||||
if (is_array($response))
|
} else {
|
||||||
foreach ($response as $rowKey => $row) {
|
if ( isset( $response [0] ['nb_uniq_visitors'] ) ) {
|
||||||
$count++;
|
$unique = 'nb_uniq_visitors';
|
||||||
$tableBody [$rowKey] = array();
|
} else {
|
||||||
foreach ($tableHead as $key => $value)
|
$unique = 'sum_daily_nb_uniq_visitors';
|
||||||
$tableBody [$rowKey] [] = isset ($row [$key]) ? $row [$key] : '-';
|
}
|
||||||
if ($count == 10)
|
$table_head = array(
|
||||||
break;
|
'label' => $this->name,
|
||||||
}
|
);
|
||||||
$this->table($tableHead, $tableBody, null);
|
$table_head [ $unique ] = __( 'Unique', 'wp-piwik' );
|
||||||
}
|
if ( isset( $response [0] ['nb_visits'] ) ) {
|
||||||
}
|
$table_head ['nb_visits'] = __( 'Visits', 'wp-piwik' );
|
||||||
|
}
|
||||||
/**
|
if ( isset( $response [0] ['nb_hits'] ) ) {
|
||||||
* Display or store shortcode output
|
$table_head ['nb_hits'] = __( 'Hits', 'wp-piwik' );
|
||||||
*/
|
}
|
||||||
protected function out($output)
|
if ( isset( $response [0] ['nb_actions'] ) ) {
|
||||||
{
|
$table_head ['nb_actions'] = __( 'Actions', 'wp-piwik' );
|
||||||
if ($this->isShortcode)
|
}
|
||||||
$this->output .= $output;
|
$table_body = array();
|
||||||
else echo $output;
|
$count = 0;
|
||||||
}
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $row_key => $row ) {
|
||||||
/**
|
++$count;
|
||||||
* Return shortcode output
|
$table_body[ $row_key ] = array();
|
||||||
*/
|
foreach ( $table_head as $key => $value ) {
|
||||||
public function get()
|
$table_body[ $row_key ] [] = isset( $row[ $key ] ) ? $row[ $key ] : '-';
|
||||||
{
|
}
|
||||||
return $this->output;
|
if ( 10 === $count ) {
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Display a HTML table
|
}
|
||||||
*
|
$this->table( $table_head, $table_body, null );
|
||||||
* @param array $thead
|
}
|
||||||
* table header content (array of cells)
|
}
|
||||||
* @param array $tbody
|
|
||||||
* table body content (array of rows)
|
/**
|
||||||
* @param array $tfoot
|
* Display or store shortcode output
|
||||||
* table footer content (array of cells)
|
*/
|
||||||
* @param string $class
|
protected function out( $output ) {
|
||||||
* CSSclass name to apply on table sections
|
if ( $this->is_shortcode ) {
|
||||||
* @param string $javaScript
|
$this->output .= $output;
|
||||||
* array of javascript code to apply on body rows
|
} else {
|
||||||
*/
|
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
protected function table($thead, $tbody = array(), $tfoot = array(), $class = false, $javaScript = array(), $classes = array())
|
echo $output;
|
||||||
{
|
}
|
||||||
$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>');
|
* Return shortcode output
|
||||||
}
|
*/
|
||||||
if (!empty ($thead))
|
public function get() {
|
||||||
$this->tabHead($thead, $class);
|
return $this->output;
|
||||||
if (!empty ($tbody))
|
}
|
||||||
$this->tabBody($tbody, $class, $javaScript, $classes);
|
|
||||||
else
|
/**
|
||||||
$this->out('<tr><td colspan="10">' . __('No data available.', 'wp-piwik') . '</td></tr>');
|
* Display a HTML table
|
||||||
if (!empty ($tfoot))
|
*
|
||||||
$this->tabFoot($tfoot, $class);
|
* @param array|null $thead
|
||||||
$this->out('</table></div>');
|
* table header content (array of cells)
|
||||||
}
|
* @param array $tbody
|
||||||
|
* table body content (array of rows)
|
||||||
/**
|
* @param array|null $tfoot
|
||||||
* Display a HTML table header
|
* table footer content (array of cells)
|
||||||
*
|
* @param string|false $css_class
|
||||||
* @param array $thead
|
* CSS class name to apply on table sections
|
||||||
* array of cells
|
* @param array $java_script
|
||||||
* @param string $class
|
* array of javascript code to apply on body rows
|
||||||
* CSS class to apply
|
* @param array $css_classes
|
||||||
*/
|
* array mapping keys in $tbody to css classes to apply on table rows.
|
||||||
private function tabHead($thead, $class = false)
|
*/
|
||||||
{
|
protected function table( $thead, $tbody = array(), $tfoot = array(), $css_class = false, $java_script = array(), $css_classes = array() ) {
|
||||||
$this->out('<thead' . ($class ? ' class="' . $class . '"' : '') . '><tr>');
|
$this->out( '<div class="table"><table class="widefat wp-piwik-table">' );
|
||||||
$count = 0;
|
if ( $this->is_shortcode && $this->title ) {
|
||||||
foreach ($thead as $value)
|
$colspan = ! empty( $tbody ) ? count( $tbody[0] ) : 2;
|
||||||
$this->out('<th' . ($count++ ? ' class="right"' : '') . '>' . $value . '</th>');
|
$this->out( '<tr><th colspan="' . $colspan . '">' . esc_html( $this->title ) . '</th></tr>' );
|
||||||
$this->out('</tr></thead>');
|
}
|
||||||
}
|
if ( ! empty( $thead ) ) {
|
||||||
|
$this->tab_head( $thead, $css_class );
|
||||||
/**
|
}
|
||||||
* Display a HTML table body
|
if ( ! empty( $tbody ) ) {
|
||||||
*
|
$this->tab_body( $tbody, $css_class, $java_script, $css_classes );
|
||||||
* @param array $tbody
|
} else {
|
||||||
* array of rows, each row containing an array of cells
|
$this->out( '<tr><td colspan="10">' . esc_html__( 'No data available.', 'wp-piwik' ) . '</td></tr>' );
|
||||||
* @param string $class
|
}
|
||||||
* CSS class to apply
|
if ( ! empty( $tfoot ) ) {
|
||||||
* @param array $javaScript
|
$this->tab_foot( $tfoot, $css_class );
|
||||||
* array of javascript code to apply (one item per row)
|
}
|
||||||
*/
|
$this->out( '</table></div>' );
|
||||||
private function tabBody($tbody, $class = "", $javaScript = array(), $classes = array())
|
}
|
||||||
{
|
|
||||||
$this->out('<tbody' . ($class ? ' class="' . $class . '"' : '') . '>');
|
/**
|
||||||
foreach ($tbody as $key => $trow)
|
* Display a HTML table header
|
||||||
$this->tabRow($trow, isset($javaScript [$key]) ? $javaScript [$key] : '', isset ($classes [$key]) ? $classes [$key] : '');
|
*
|
||||||
$this->out('</tbody>');
|
* @param array $thead
|
||||||
}
|
* array of cells.
|
||||||
|
* @param string|false $css_class
|
||||||
/**
|
* CSS class to apply
|
||||||
* Display a HTML table footer
|
*/
|
||||||
*
|
private function tab_head( $thead, $css_class = false ) {
|
||||||
* @param array $tfoor
|
$this->out( '<thead' . ( $css_class ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '><tr>' );
|
||||||
* array of cells
|
$count = 0;
|
||||||
* @param string $class
|
foreach ( $thead as $value ) {
|
||||||
* CSS class to apply
|
$this->out( '<th' . ( $count++ ? ' class="right"' : '' ) . '>' . esc_html( $value ) . '</th>' );
|
||||||
*/
|
}
|
||||||
private function tabFoot($tfoot, $class = false)
|
$this->out( '</tr></thead>' );
|
||||||
{
|
}
|
||||||
$this->out('<tfoot' . ($class ? ' class="' . $class . '"' : '') . '><tr>');
|
|
||||||
$count = 0;
|
/**
|
||||||
foreach ($tfoot as $value)
|
* Display a HTML table body
|
||||||
$this->out('<td' . ($count++ ? ' class="right"' : '') . '>' . $value . '</td>');
|
*
|
||||||
$this->out('</tr></tfoot>');
|
* @param array $tbody
|
||||||
}
|
* array of rows, each row containing an array of cells
|
||||||
|
* @param string $css_class
|
||||||
/**
|
* CSS class to apply
|
||||||
* Display a HTML table row
|
* @param array $java_script
|
||||||
*
|
* array of javascript code to apply (one item per row)
|
||||||
* @param array $trow
|
*/
|
||||||
* array of cells
|
private function tab_body( $tbody, $css_class = '', $java_script = array(), $css_classes = array() ) {
|
||||||
* @param string $javaScript
|
$this->out( '<tbody' . ( $css_class ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' );
|
||||||
* javascript code to apply
|
foreach ( $tbody as $key => $trow ) {
|
||||||
*/
|
$this->tab_row( $trow, isset( $java_script [ $key ] ) ? $java_script [ $key ] : '', isset( $css_classes [ $key ] ) ? $css_classes [ $key ] : '' );
|
||||||
private function tabRow($trow, $javaScript = '', $class = '')
|
}
|
||||||
{
|
$this->out( '</tbody>' );
|
||||||
$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>');
|
* Display a HTML table footer
|
||||||
$this->out('</tr>');
|
*
|
||||||
}
|
* @param array $tfoot
|
||||||
|
* array of cells
|
||||||
/**
|
* @param string|false $css_class
|
||||||
* Get the current request's Piwik time settings
|
* CSS class to apply
|
||||||
*
|
*/
|
||||||
* @return array time settings: period => Piwik period, date => requested date, description => time description to show in widget title
|
private function tab_foot( $tfoot, $css_class = false ) {
|
||||||
*/
|
$this->out( '<tfoot' . ( $css_class ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '><tr>' );
|
||||||
protected function getTimeSettings()
|
$count = 0;
|
||||||
{
|
foreach ( $tfoot as $value ) {
|
||||||
switch (self::$settings->getGlobalOption('default_date')) {
|
// $value is allowed to contain html
|
||||||
case 'today' :
|
$this->out( '<td' . ( $count++ ? ' class="right"' : '' ) . '>' . $value . '</td>' );
|
||||||
$period = 'day';
|
}
|
||||||
$date = 'today';
|
$this->out( '</tr></tfoot>' );
|
||||||
$description = __('today', 'wp-piwik');
|
}
|
||||||
break;
|
|
||||||
case 'current_month' :
|
/**
|
||||||
$period = 'month';
|
* Display a HTML table row
|
||||||
$date = 'today';
|
*
|
||||||
$description = __('current month', 'wp-piwik');
|
* @param array $trow
|
||||||
break;
|
* array of cells
|
||||||
case 'last_month' :
|
* @param string $java_script
|
||||||
$period = 'month';
|
* javascript code to apply
|
||||||
$date = date("Y-m-d", strtotime("last day of previous month"));
|
*/
|
||||||
$description = __('last month', 'wp-piwik');
|
private function tab_row( $trow, $java_script = '', $css_class = '' ) {
|
||||||
break;
|
$this->out( '<tr' . ( ! empty( $java_script ) ? ' onclick="' . esc_attr( esc_js( $java_script ) ) . '"' : '' ) . ( ! empty( $css_class ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' );
|
||||||
case 'current_week' :
|
$count = 0;
|
||||||
$period = 'week';
|
foreach ( $trow as $tcell ) {
|
||||||
$date = 'today';
|
$this->out( '<td' . ( $count++ ? ' class="right"' : '' ) . '>' . esc_html( $tcell ) . '</td>' );
|
||||||
$description = __('current week', 'wp-piwik');
|
}
|
||||||
break;
|
$this->out( '</tr>' );
|
||||||
case 'last_week' :
|
}
|
||||||
$period = 'week';
|
|
||||||
$date = date("Y-m-d", strtotime("-1 week"));
|
/**
|
||||||
$description = __('last week', 'wp-piwik');
|
* Get the current request's Piwik time settings
|
||||||
break;
|
*
|
||||||
case 'yesterday' :
|
* @return array time settings: period => Piwik period, date => requested date, description => time description to show in widget title
|
||||||
$period = 'day';
|
*/
|
||||||
$date = 'yesterday';
|
protected function get_time_settings() {
|
||||||
$description = __('yesterday', 'wp-piwik');
|
switch ( self::$settings->get_global_option( 'default_date' ) ) {
|
||||||
break;
|
case 'today':
|
||||||
default :
|
$period = 'day';
|
||||||
break;
|
$date = 'today';
|
||||||
}
|
$description = __( 'today', 'wp-piwik' );
|
||||||
return array(
|
break;
|
||||||
'period' => $period,
|
case 'current_month':
|
||||||
'date' => isset ($_GET ['date']) ? ( int )$_GET ['date'] : $date,
|
$period = 'month';
|
||||||
'description' => isset ($_GET ['date']) ? $this->dateFormat($_GET ['date'], $period) : $description
|
$date = 'today';
|
||||||
);
|
$description = __( 'current month', 'wp-piwik' );
|
||||||
}
|
break;
|
||||||
|
case 'last_month':
|
||||||
/**
|
$period = 'month';
|
||||||
* Format a date to show in widget
|
$date = gmdate( 'Y-m-d', strtotime( 'last day of previous month' ) );
|
||||||
*
|
$description = __( 'last month', 'wp-piwik' );
|
||||||
* @param string $date
|
break;
|
||||||
* date string
|
case 'current_week':
|
||||||
* @param string $period
|
$period = 'week';
|
||||||
* Piwik period
|
$date = 'today';
|
||||||
* @return string formatted date
|
$description = __( 'current week', 'wp-piwik' );
|
||||||
*/
|
break;
|
||||||
protected function dateFormat($date, $period = 'day')
|
case 'last_week':
|
||||||
{
|
$period = 'week';
|
||||||
$prefix = '';
|
$date = gmdate( 'Y-m-d', strtotime( '-1 week' ) );
|
||||||
switch ($period) {
|
$description = __( 'last week', 'wp-piwik' );
|
||||||
case 'week' :
|
break;
|
||||||
$prefix = __('week', 'wp-piwik') . ' ';
|
case 'yesterday':
|
||||||
$format = 'W/Y';
|
default:
|
||||||
break;
|
$period = 'day';
|
||||||
case 'short_week' :
|
$date = 'yesterday';
|
||||||
$format = 'W';
|
$description = __( 'yesterday', 'wp-piwik' );
|
||||||
break;
|
break;
|
||||||
case 'month' :
|
}
|
||||||
$format = 'F Y';
|
|
||||||
$date = date('Y-m-d', strtotime($date));
|
if ( isset( $_GET['date'] ) ) {
|
||||||
break;
|
$date = intval( wp_unslash( $_GET['date'] ) );
|
||||||
default :
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||||
$format = get_option('date_format');
|
$description = $this->date_format( wp_unslash( $_GET['date'] ), $period );
|
||||||
}
|
}
|
||||||
return $prefix . date_i18n($format, strtotime($date));
|
|
||||||
}
|
return array(
|
||||||
|
'period' => $period,
|
||||||
/**
|
'date' => $date,
|
||||||
* Format time to show in widget
|
'description' => $description,
|
||||||
*
|
);
|
||||||
* @param int $time
|
}
|
||||||
* time in seconds
|
|
||||||
* @return string formatted time
|
/**
|
||||||
*/
|
* Format a date to show in widget
|
||||||
protected function timeFormat($time)
|
*
|
||||||
{
|
* @param string $date
|
||||||
return floor($time / 3600) . 'h ' . floor(($time % 3600) / 60) . 'm ' . floor(($time % 3600) % 60) . 's';
|
* date string
|
||||||
}
|
* @param string $period
|
||||||
|
* Piwik period
|
||||||
/**
|
* @return string formatted date
|
||||||
* Convert Piwik range into meaningful text
|
*/
|
||||||
*
|
protected function date_format( $date, $period = 'day' ) {
|
||||||
* @return string range description
|
$prefix = '';
|
||||||
*/
|
switch ( $period ) {
|
||||||
public function rangeName()
|
case 'week':
|
||||||
{
|
$prefix = __( 'week', 'wp-piwik' ) . ' ';
|
||||||
switch ($this->parameter ['date']) {
|
$format = 'W/Y';
|
||||||
case 'last90' :
|
break;
|
||||||
return __('last 90 days', 'wp-piwik');
|
case 'short_week':
|
||||||
case 'last60' :
|
$format = 'W';
|
||||||
return __('last 60 days', 'wp-piwik');
|
break;
|
||||||
case 'last30' :
|
case 'month':
|
||||||
return __('last 30 days', 'wp-piwik');
|
$format = 'F Y';
|
||||||
case 'last12' :
|
$date = gmdate( 'Y-m-d', strtotime( $date ) );
|
||||||
return __('last 12 ' . $this->parameter ['period'] . 's', 'wp-piwik');
|
break;
|
||||||
default :
|
default:
|
||||||
return $this->parameter ['date'];
|
$format = get_option( 'date_format' );
|
||||||
}
|
}
|
||||||
}
|
return $prefix . date_i18n( $format, strtotime( $date ) );
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Get the widget name
|
/**
|
||||||
*
|
* Format time to show in widget
|
||||||
* @return string widget name
|
*
|
||||||
*/
|
* @param int $time
|
||||||
public function getName()
|
* time in seconds
|
||||||
{
|
* @return string formatted time
|
||||||
return str_replace('\\', '-', get_called_class());
|
*/
|
||||||
}
|
protected function time_format( $time ) {
|
||||||
|
return floor( $time / 3600 ) . 'h ' . floor( ( $time % 3600 ) / 60 ) . 'm ' . floor( ( $time % 3600 ) % 60 ) . 's';
|
||||||
/**
|
}
|
||||||
* Display a pie chart
|
|
||||||
*
|
/**
|
||||||
* @param
|
* Convert Piwik range into meaningful text
|
||||||
* array chart data array(array(0 => name, 1 => value))
|
*
|
||||||
*/
|
* @return string range description
|
||||||
public function pieChart($data)
|
*/
|
||||||
{
|
public function range_name() {
|
||||||
$labels = '';
|
switch ( $this->parameter ['date'] ) {
|
||||||
$values = '';
|
case 'last90':
|
||||||
foreach ($data as $key => $dataSet) {
|
return __( 'last 90 days', 'wp-piwik' );
|
||||||
$labels .= '"' . htmlentities($dataSet [0]) . '", ';
|
case 'last60':
|
||||||
$values .= htmlentities($dataSet [1]) . ', ';
|
return __( 'last 60 days', 'wp-piwik' );
|
||||||
if ($key == 'Others') break;
|
case 'last30':
|
||||||
}
|
return __( 'last 30 days', 'wp-piwik' );
|
||||||
?>
|
case 'last12':
|
||||||
<div>
|
switch ( $this->parameter['period'] ) {
|
||||||
<canvas id="<?php echo 'wp-piwik_stats_' . $this->getName() . '_graph' ?>"></canvas>
|
case 'day':
|
||||||
</div>
|
return __( 'last 12 days', 'wp-piwik' );
|
||||||
<script>
|
case 'week':
|
||||||
new Chart(
|
return __( 'last 12 weeks', 'wp-piwik' );
|
||||||
document.getElementById('<?php echo 'wp-piwik_stats_' . $this->getName() . '_graph'; ?>'),
|
case 'month':
|
||||||
{
|
return __( 'last 12 months', 'wp-piwik' );
|
||||||
type: 'pie',
|
case 'year':
|
||||||
data: {
|
return __( 'last 12 years', 'wp-piwik' );
|
||||||
labels: [<?php echo $labels ?>],
|
default:
|
||||||
datasets: [
|
return __( 'last 12', 'wp-piwik' ) . $this->parameter['period'];
|
||||||
{
|
}
|
||||||
label: '',
|
default:
|
||||||
data: [<?php echo $values; ?>],
|
return $this->parameter ['date'];
|
||||||
backgroundColor: [
|
}
|
||||||
'#4dc9f6',
|
}
|
||||||
'#f67019',
|
|
||||||
'#f53794',
|
/**
|
||||||
'#537bc4',
|
* Get the widget name
|
||||||
'#acc236',
|
*
|
||||||
'#166a8f',
|
* @return string widget name
|
||||||
'#00a950',
|
*/
|
||||||
'#58595b',
|
public function get_name() {
|
||||||
'#8549ba'
|
return str_replace( '\\', '-', get_called_class() );
|
||||||
]
|
}
|
||||||
}
|
|
||||||
]
|
/**
|
||||||
},
|
* Display a pie chart
|
||||||
options: {
|
*
|
||||||
radius:"90%"
|
* @param array $data chart data array(array(0 => name, 1 => value))
|
||||||
}
|
*/
|
||||||
}
|
public function pie_chart( $data ) {
|
||||||
);
|
$labels = array();
|
||||||
</script>
|
$values = array();
|
||||||
<?php
|
foreach ( $data as $key => $data_set ) {
|
||||||
}
|
$labels[] = $data_set[0];
|
||||||
|
$values[] = $data_set[1];
|
||||||
/**
|
if ( 'Others' === $key ) {
|
||||||
* Return an array value by key, return '-' if not set
|
break;
|
||||||
*
|
}
|
||||||
* @param array $array
|
}
|
||||||
* array to get a value from
|
?>
|
||||||
* @param string $key
|
<div>
|
||||||
* key of the value to get from array
|
<canvas id="<?php echo esc_attr( 'wp-piwik_stats_' . $this->get_name() . '_graph' ); ?>"></canvas>
|
||||||
* @return string found value or '-' as a placeholder
|
</div>
|
||||||
*/
|
<script>
|
||||||
protected function value($array, $key)
|
new Chart(
|
||||||
{
|
document.getElementById(<?php echo wp_json_encode( 'wp-piwik_stats_' . $this->get_name() . '_graph' ); ?>),
|
||||||
return (isset ($array [$key]) ? $array [$key] : '-');
|
{
|
||||||
}
|
type: 'pie',
|
||||||
}
|
data: {
|
||||||
|
labels: <?php echo wp_json_encode( $labels ); ?>,
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: '',
|
||||||
|
data: <?php echo wp_json_encode( $values ); ?>,
|
||||||
|
backgroundColor: [
|
||||||
|
'#4dc9f6',
|
||||||
|
'#f67019',
|
||||||
|
'#f53794',
|
||||||
|
'#537bc4',
|
||||||
|
'#acc236',
|
||||||
|
'#166a8f',
|
||||||
|
'#00a950',
|
||||||
|
'#58595b',
|
||||||
|
'#8549ba'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
radius:"90%"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array value by key, return '-' if not set
|
||||||
|
*
|
||||||
|
* @param array $values
|
||||||
|
* array to get a value from
|
||||||
|
* @param string $key
|
||||||
|
* key of the value to get from array
|
||||||
|
* @return string|float found value or '-' as a placeholder
|
||||||
|
*/
|
||||||
|
protected function value( $values, $key ) {
|
||||||
|
return isset( $values[ $key ] ) ? $values[ $key ] : '-';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,70 +1,80 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
use WP_Piwik\Widget;
|
use WP_Piwik\Widget;
|
||||||
|
|
||||||
class BrowserDetails extends Widget {
|
class BrowserDetails extends Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
|
||||||
'period' => $timeSettings['period'],
|
|
||||||
'date' => $timeSettings['date']
|
|
||||||
);
|
|
||||||
$this->title = $prefix.__('Browser Details', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
|
||||||
$this->method = 'DevicesDetection.getBrowserVersions';
|
|
||||||
$this->context = 'normal';
|
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
|
||||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show() {
|
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
$tableBody = array();
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
|
||||||
else {
|
|
||||||
$tableHead = array(__('Browser', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
|
||||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
|
||||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
|
||||||
$count = 0;
|
|
||||||
$sum = 0;
|
|
||||||
$js = array();
|
|
||||||
$class = array();
|
|
||||||
if (is_array($response))
|
|
||||||
foreach ($response as $row) {
|
|
||||||
$count++;
|
|
||||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
|
||||||
if ($count < $this->limit)
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
elseif (!isset($tableBody['Others'])) {
|
|
||||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class['Others'] = 'wp-piwik-hideDetails';
|
|
||||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
} else {
|
|
||||||
$tableBody['Others'][1] += $row[$unique];
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($count > $this->limit)
|
|
||||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
|
||||||
|
|
||||||
foreach ($tableBody as $key => $row)
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
$time_settings = $this->get_time_settings();
|
||||||
|
$this->parameter = array(
|
||||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
'period' => $time_settings['period'],
|
||||||
|
'date' => $time_settings['date'],
|
||||||
|
);
|
||||||
|
$this->title = $prefix . __( 'Browser Details', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
|
$this->method = 'DevicesDetection.getBrowserVersions';
|
||||||
|
$this->context = 'normal';
|
||||||
|
|
||||||
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
|
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show() {
|
||||||
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
|
$table_body = array();
|
||||||
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
$table_head = array( __( 'Browser', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||||
|
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||||
|
$unique = 'nb_uniq_visitors';
|
||||||
|
} else {
|
||||||
|
$unique = 'sum_daily_nb_uniq_visitors';
|
||||||
}
|
}
|
||||||
|
$count = 0;
|
||||||
|
$sum = 0;
|
||||||
|
$js = array();
|
||||||
|
$css_class = array();
|
||||||
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $row ) {
|
||||||
|
++$count;
|
||||||
|
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||||
|
if ( $count < $this->limit ) {
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||||
|
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||||
|
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
} else {
|
||||||
|
$table_body['Others'][1] += $row[ $unique ];
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $count > $this->limit ) {
|
||||||
|
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $table_body as $key => $row ) {
|
||||||
|
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $table_body ) ) {
|
||||||
|
$this->pie_chart( $table_body );
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,73 +1,83 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
use WP_Piwik\Widget;
|
use WP_Piwik\Widget;
|
||||||
|
|
||||||
class Browsers extends Widget {
|
class Browsers extends Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
|
||||||
'period' => $timeSettings['period'],
|
|
||||||
'date' => $timeSettings['date']
|
|
||||||
);
|
|
||||||
$this->title = $prefix.__('Browsers', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
|
||||||
$this->method = 'DevicesDetection.getBrowsers';
|
|
||||||
$this->context = 'normal';
|
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
|
||||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show() {
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
$time_settings = $this->get_time_settings();
|
||||||
$tableBody = array();
|
$this->parameter = array(
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
'period' => $time_settings['period'],
|
||||||
else {
|
'date' => $time_settings['date'],
|
||||||
$tableHead = array(__('Browser', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
);
|
||||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
$this->title = $prefix . __( 'Browsers', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
$this->method = 'DevicesDetection.getBrowsers';
|
||||||
$count = 0;
|
$this->context = 'normal';
|
||||||
$sum = 0;
|
|
||||||
$js = array();
|
|
||||||
$class = array();
|
|
||||||
if (is_array($response))
|
|
||||||
foreach ($response as $row) {
|
|
||||||
$count++;
|
|
||||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
|
||||||
if ($count < $this->limit)
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
elseif (!isset($tableBody['Others'])) {
|
|
||||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class['Others'] = 'wp-piwik-hideDetails';
|
|
||||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
} else {
|
|
||||||
$tableBody['Others'][1] += $row[$unique];
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($count > $this->limit)
|
|
||||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
|
||||||
elseif ($count == $this->limit) {
|
|
||||||
$class['Others'] = $js['Others'] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($tableBody as $key => $row)
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
}
|
||||||
|
|
||||||
|
public function show() {
|
||||||
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
|
$table_body = array();
|
||||||
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
$table_head = array( __( 'Browser', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||||
|
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||||
|
$unique = 'nb_uniq_visitors';
|
||||||
|
} else {
|
||||||
|
$unique = 'sum_daily_nb_uniq_visitors';
|
||||||
}
|
}
|
||||||
|
$count = 0;
|
||||||
|
$sum = 0;
|
||||||
|
$js = array();
|
||||||
|
$css_class = array();
|
||||||
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $row ) {
|
||||||
|
++$count;
|
||||||
|
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||||
|
if ( $count < $this->limit ) {
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||||
|
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||||
|
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
} else {
|
||||||
|
$table_body['Others'][1] += $row[ $unique ];
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $count > $this->limit ) {
|
||||||
|
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||||
|
} elseif ( $count === $this->limit ) {
|
||||||
|
$css_class['Others'] = '';
|
||||||
|
$js['Others'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $table_body as $key => $row ) {
|
||||||
|
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $table_body ) ) {
|
||||||
|
$this->pie_chart( $table_body );
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,85 +4,97 @@ namespace WP_Piwik\Widget;
|
|||||||
|
|
||||||
use WP_Piwik\Widget;
|
use WP_Piwik\Widget;
|
||||||
|
|
||||||
class Chart extends Visitors
|
class Chart extends Visitors {
|
||||||
{
|
|
||||||
|
|
||||||
public $className = __CLASS__;
|
public $class_name = __CLASS__;
|
||||||
|
|
||||||
public function show()
|
public function show() {
|
||||||
{
|
$result = $this->request_data();
|
||||||
$result = $this->requestData();
|
$response = $result['response'];
|
||||||
$response = $result["response"];
|
if ( ! $result['success'] ) {
|
||||||
if (!$result["success"]) {
|
$message = '';
|
||||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response[$method]['message'], ENT_QUOTES, 'utf-8');
|
if ( is_array( $this->method ) ) {
|
||||||
} else {
|
foreach ( $this->method as $m ) {
|
||||||
$values = $labels = $bounced = $unique = '';
|
if ( empty( $response[ $m ]['message'] ) ) {
|
||||||
$count = $uniqueSum = 0;
|
continue;
|
||||||
if (is_array($response['VisitsSummary.getVisits']))
|
}
|
||||||
foreach ($response['VisitsSummary.getVisits'] as $date => $value) {
|
|
||||||
$count++;
|
|
||||||
$values .= $value . ',';
|
|
||||||
$unique .= $response['VisitsSummary.getUniqueVisitors'][$date] . ',';
|
|
||||||
$bounced .= $response['VisitsSummary.getBounceCount'][$date] . ',';
|
|
||||||
if ($this->parameter['period'] == 'week') {
|
|
||||||
preg_match("/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", $date, $dateList);
|
|
||||||
$textKey = $this->dateFormat($dateList[0], 'short_week');
|
|
||||||
} else $textKey = substr($date, -2);
|
|
||||||
$labels .= '["' . $textKey . '"],';
|
|
||||||
$uniqueSum += $response['VisitsSummary.getActions'][$date];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$values = '0,';
|
|
||||||
$labels = '[0,"-"],';
|
|
||||||
$unique = '0,';
|
|
||||||
$bounced = '0,';
|
|
||||||
}
|
|
||||||
$average = round($uniqueSum / 30, 0);
|
|
||||||
$values = substr($values, 0, -1);
|
|
||||||
$unique = substr($unique, 0, -1);
|
|
||||||
$labels = substr($labels, 0, -1);
|
|
||||||
$bounced = substr($bounced, 0, -1);
|
|
||||||
?>
|
|
||||||
<div>
|
|
||||||
<canvas id="wp-piwik_stats_vistors_graph" style="height:220px;"></canvas>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
new Chart(
|
|
||||||
document.getElementById('wp-piwik_stats_vistors_graph'),
|
|
||||||
{
|
|
||||||
type: 'line',
|
|
||||||
data: {
|
|
||||||
labels: [<?php echo $labels ?>],
|
|
||||||
datasets: [
|
|
||||||
{
|
|
||||||
label: 'Visitors',
|
|
||||||
backgroundColor: '#0277bd',
|
|
||||||
borderColor: '#0277bd',
|
|
||||||
data: [<?php echo $values; ?>],
|
|
||||||
borderWidth: 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Unique',
|
|
||||||
backgroundColor: '#ff8f00',
|
|
||||||
borderColor: '#ff8f00',
|
|
||||||
data: [<?php echo $unique; ?>],
|
|
||||||
borderWidth: 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Bounced',
|
|
||||||
backgroundColor: '#ad1457',
|
|
||||||
borderColor: '#ad1457',
|
|
||||||
data: [<?php echo $bounced; ?>],
|
|
||||||
borderWidth: 1
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
options: {}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
</script>
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$message .= ' ' . $m . ' - ' . $response[ $m ]['message'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$message = $response[ $this->method ]['message'];
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $message );
|
||||||
|
} else {
|
||||||
|
$values = array();
|
||||||
|
$labels = array();
|
||||||
|
$bounced = array();
|
||||||
|
$unique = array();
|
||||||
|
$count = 0;
|
||||||
|
$unique_sum = 0;
|
||||||
|
if ( is_array( $response['VisitsSummary.getVisits'] ) ) {
|
||||||
|
foreach ( $response['VisitsSummary.getVisits'] as $date => $value ) {
|
||||||
|
++$count;
|
||||||
|
$values [] = $value;
|
||||||
|
$unique [] = $response['VisitsSummary.getUniqueVisitors'][ $date ];
|
||||||
|
$bounced [] = $response['VisitsSummary.getBounceCount'][ $date ];
|
||||||
|
if ( 'week' === $this->parameter['period'] ) {
|
||||||
|
preg_match( '/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/', $date, $date_list );
|
||||||
|
$text_key = $this->date_format( $date_list[0], 'short_week' );
|
||||||
|
} else {
|
||||||
|
$text_key = substr( $date, -2 );
|
||||||
|
}
|
||||||
|
$labels [] = array( $text_key );
|
||||||
|
$unique_sum += $response['VisitsSummary.getActions'][ $date ];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$values = array( 0 );
|
||||||
|
$labels = array( array( 0, '-' ) );
|
||||||
|
$unique = array( 0 );
|
||||||
|
$bounced = array( 0 );
|
||||||
|
}
|
||||||
|
$average = round( $unique_sum / 30, 0 );
|
||||||
|
?>
|
||||||
|
<div>
|
||||||
|
<canvas id="wp-piwik_stats_vistors_graph" style="height:220px;"></canvas>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
new Chart(
|
||||||
|
document.getElementById('wp-piwik_stats_vistors_graph'),
|
||||||
|
{
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
labels: <?php echo wp_json_encode( $labels ); ?>,
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Visitors',
|
||||||
|
backgroundColor: '#0277bd',
|
||||||
|
borderColor: '#0277bd',
|
||||||
|
data: <?php echo wp_json_encode( $values ); ?>,
|
||||||
|
borderWidth: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Unique',
|
||||||
|
backgroundColor: '#ff8f00',
|
||||||
|
borderColor: '#ff8f00',
|
||||||
|
data: <?php echo wp_json_encode( $unique ); ?>,
|
||||||
|
borderWidth: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Bounced',
|
||||||
|
backgroundColor: '#ad1457',
|
||||||
|
borderColor: '#ad1457',
|
||||||
|
data: <?php echo wp_json_encode( $bounced ); ?>,
|
||||||
|
borderWidth: 1
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
options: {}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,73 +1,83 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
use WP_Piwik\Widget;
|
use WP_Piwik\Widget;
|
||||||
|
|
||||||
class City extends Widget {
|
class City extends Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
|
||||||
'period' => $timeSettings['period'],
|
|
||||||
'date' => $timeSettings['date']
|
|
||||||
);
|
|
||||||
$this->title = $prefix.__('Cities', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
|
||||||
$this->method = 'UserCountry.getCity';
|
|
||||||
$this->context = 'normal';
|
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
|
||||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show() {
|
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
$tableBody = array();
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
|
||||||
else {
|
|
||||||
$tableHead = array(__('City', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
|
||||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
|
||||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
|
||||||
$count = 0;
|
|
||||||
$sum = 0;
|
|
||||||
$js = array();
|
|
||||||
$class = array();
|
|
||||||
if (is_array($response))
|
|
||||||
foreach ($response as $row) {
|
|
||||||
$count++;
|
|
||||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
|
||||||
if ($count < $this->limit)
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
elseif (!isset($tableBody['Others'])) {
|
|
||||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class['Others'] = 'wp-piwik-hideDetails';
|
|
||||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
} else {
|
|
||||||
$tableBody['Others'][1] += $row[$unique];
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($count > $this->limit)
|
|
||||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
|
||||||
elseif ($count == $this->limit) {
|
|
||||||
$class['Others'] = $js['Others'] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($tableBody as $key => $row)
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
$time_settings = $this->get_time_settings();
|
||||||
|
$this->parameter = array(
|
||||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
'period' => $time_settings['period'],
|
||||||
|
'date' => $time_settings['date'],
|
||||||
|
);
|
||||||
|
$this->title = $prefix . __( 'Cities', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
|
$this->method = 'UserCountry.getCity';
|
||||||
|
$this->context = 'normal';
|
||||||
|
|
||||||
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
|
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show() {
|
||||||
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
|
$table_body = array();
|
||||||
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
$table_head = array( __( 'City', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||||
|
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||||
|
$unique = 'nb_uniq_visitors';
|
||||||
|
} else {
|
||||||
|
$unique = 'sum_daily_nb_uniq_visitors';
|
||||||
}
|
}
|
||||||
|
$count = 0;
|
||||||
|
$sum = 0;
|
||||||
|
$js = array();
|
||||||
|
$css_class = array();
|
||||||
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $row ) {
|
||||||
|
++$count;
|
||||||
|
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||||
|
if ( $count < $this->limit ) {
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||||
|
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||||
|
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
} else {
|
||||||
|
$table_body['Others'][1] += $row[ $unique ];
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $count > $this->limit ) {
|
||||||
|
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||||
|
} elseif ( $count === $this->limit ) {
|
||||||
|
$css_class['Others'] = '';
|
||||||
|
$js['Others'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $table_body as $key => $row ) {
|
||||||
|
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $table_body ) ) {
|
||||||
|
$this->pie_chart( $table_body );
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,70 +4,80 @@
|
|||||||
|
|
||||||
use WP_Piwik\Widget;
|
use WP_Piwik\Widget;
|
||||||
|
|
||||||
class Country extends Widget {
|
class Country extends Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
|
||||||
'period' => $timeSettings['period'],
|
|
||||||
'date' => $timeSettings['date']
|
|
||||||
);
|
|
||||||
$this->title = $prefix.__('Countries', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
|
||||||
$this->method = 'UserCountry.getCountry ';
|
|
||||||
$this->context = 'normal';
|
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
|
||||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show() {
|
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
$tableBody = array();
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
|
||||||
else {
|
|
||||||
$tableHead = array(__('Country', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
|
||||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
|
||||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
|
||||||
$count = 0;
|
|
||||||
$sum = 0;
|
|
||||||
$js = array();
|
|
||||||
$class = array();
|
|
||||||
if (is_array($response))
|
|
||||||
foreach ($response as $row) {
|
|
||||||
$count++;
|
|
||||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
|
||||||
if ($count < $this->limit)
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
elseif (!isset($tableBody['Others'])) {
|
|
||||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class['Others'] = 'wp-piwik-hideDetails';
|
|
||||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
} else {
|
|
||||||
$tableBody['Others'][1] += $row[$unique];
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($count > $this->limit)
|
|
||||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
|
||||||
elseif ($count == $this->limit) {
|
|
||||||
$class['Others'] = $js['Others'] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($tableBody as $key => $row)
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
$time_settings = $this->get_time_settings();
|
||||||
|
$this->parameter = array(
|
||||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
'period' => $time_settings['period'],
|
||||||
|
'date' => $time_settings['date'],
|
||||||
|
);
|
||||||
|
$this->title = $prefix . __( 'Countries', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
|
$this->method = 'UserCountry.getCountry ';
|
||||||
|
$this->context = 'normal';
|
||||||
|
|
||||||
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
|
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show() {
|
||||||
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
|
$table_body = array();
|
||||||
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
$table_head = array( __( 'Country', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||||
|
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||||
|
$unique = 'nb_uniq_visitors';
|
||||||
|
} else {
|
||||||
|
$unique = 'sum_daily_nb_uniq_visitors';
|
||||||
}
|
}
|
||||||
|
$count = 0;
|
||||||
|
$sum = 0;
|
||||||
|
$js = array();
|
||||||
|
$css_class = array();
|
||||||
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $row ) {
|
||||||
|
++$count;
|
||||||
|
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||||
|
if ( $count < $this->limit ) {
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||||
|
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||||
|
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
} else {
|
||||||
|
$table_body['Others'][1] += $row[ $unique ];
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $count > $this->limit ) {
|
||||||
|
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||||
|
} elseif ( $count === $this->limit ) {
|
||||||
|
$css_class['Others'] = '';
|
||||||
|
$js['Others'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $table_body as $key => $row ) {
|
||||||
|
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $table_body ) ) {
|
||||||
|
$this->pie_chart( $table_body );
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,50 +2,52 @@
|
|||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Ecommerce extends \WP_Piwik\Widget
|
class Ecommerce extends \WP_Piwik\Widget {
|
||||||
{
|
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array())
|
public $class_name = __CLASS__;
|
||||||
{
|
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->title = $prefix . __('E-Commerce', 'wp-piwik');
|
|
||||||
$this->method = 'Goals.get';
|
|
||||||
$this->parameter = array(
|
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
|
||||||
'period' => $timeSettings['period'],
|
|
||||||
'date' => $timeSettings['date']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show()
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
{
|
$time_settings = $this->get_time_settings();
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
$this->title = $prefix . __( 'E-Commerce', 'wp-piwik' );
|
||||||
if (!empty($response['result']) && $response['result'] = 'error')
|
$this->method = 'Goals.get';
|
||||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
$this->parameter = array(
|
||||||
else {
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
$tableHead = null;
|
'period' => $time_settings['period'],
|
||||||
$revenue = is_float($this->value($response, 'revenue')) ? number_format($this->value($response, 'revenue'), 2) : "";
|
'date' => $time_settings['date'],
|
||||||
$revenue_new = is_float($this->value($response, 'revenue_new_visit')) ? number_format($this->value($response, 'revenue_new_visit'), 2) : "";
|
);
|
||||||
$revenue_return = is_float($this->value($response, 'revenue_returning_visit')) ? number_format($this->value($response, 'revenue_returning_visit'), 2) : "";
|
}
|
||||||
$tableBody = array(
|
|
||||||
array(__('Conversions', 'wp-piwik') . ':', $this->value($response, 'nb_conversions')),
|
|
||||||
array(__('Visits converted', 'wp-piwik') . ':', $this->value($response, 'nb_visits_converted')),
|
|
||||||
array(__('Revenue', 'wp-piwik') . ':', $revenue),
|
|
||||||
array(__('Conversion rate', 'wp-piwik') . ':', $this->value($response, 'conversion_rate')),
|
|
||||||
array(__('Conversions (new visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_conversions_new_visit')),
|
|
||||||
array(__('Visits converted (new visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_visits_converted_new_visit')),
|
|
||||||
array(__('Revenue (new visitor)', 'wp-piwik') . ':', $revenue_new),
|
|
||||||
array(__('Conversion rate (new visitor)', 'wp-piwik') . ':', $this->value($response, 'conversion_rate_new_visit')),
|
|
||||||
array(__('Conversions (returning visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_conversions_returning_visit')),
|
|
||||||
array(__('Visits converted (returning visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_visits_converted_returning_visit')),
|
|
||||||
array(__('Revenue (returning visitor)', 'wp-piwik') . ':', $revenue_return),
|
|
||||||
array(__('Conversion rate (returning visitor)', 'wp-piwik') . ':', $this->value($response, 'conversion_rate_returning_visit')),
|
|
||||||
);
|
|
||||||
$tableFoot = (self::$settings->getGlobalOption('piwik_shortcut') ? array(__('Shortcut', 'wp-piwik') . ':', '<a href="' . self::$settings->getGlobalOption('piwik_url') . '">Piwik</a>' . (isset($aryConf['inline']) && $aryConf['inline'] ? ' - <a href="?page=wp-piwik_stats">WP-Piwik</a>' : '')) : null);
|
|
||||||
$this->table($tableHead, $tableBody, $tableFoot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
public function show() {
|
||||||
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
$table_head = null;
|
||||||
|
$revenue = is_numeric( $this->value( $response, 'revenue' ) ) ? number_format( (float) $this->value( $response, 'revenue' ), 2 ) : '';
|
||||||
|
$revenue_new = is_numeric( $this->value( $response, 'revenue_new_visit' ) ) ? number_format( (float) $this->value( $response, 'revenue_new_visit' ), 2 ) : '';
|
||||||
|
$revenue_return = is_numeric( $this->value( $response, 'revenue_returning_visit' ) ) ? number_format( (float) $this->value( $response, 'revenue_returning_visit' ), 2 ) : '';
|
||||||
|
$table_body = array(
|
||||||
|
array( __( 'Conversions', 'wp-piwik' ) . ':', $this->value( $response, 'nb_conversions' ) ),
|
||||||
|
array( __( 'Visits converted', 'wp-piwik' ) . ':', $this->value( $response, 'nb_visits_converted' ) ),
|
||||||
|
array( __( 'Revenue', 'wp-piwik' ) . ':', $revenue ),
|
||||||
|
array( __( 'Conversion rate', 'wp-piwik' ) . ':', $this->value( $response, 'conversion_rate' ) ),
|
||||||
|
array( __( 'Conversions (new visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'nb_conversions_new_visit' ) ),
|
||||||
|
array( __( 'Visits converted (new visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'nb_visits_converted_new_visit' ) ),
|
||||||
|
array( __( 'Revenue (new visitor)', 'wp-piwik' ) . ':', $revenue_new ),
|
||||||
|
array( __( 'Conversion rate (new visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'conversion_rate_new_visit' ) ),
|
||||||
|
array( __( 'Conversions (returning visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'nb_conversions_returning_visit' ) ),
|
||||||
|
array( __( 'Visits converted (returning visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'nb_visits_converted_returning_visit' ) ),
|
||||||
|
array( __( 'Revenue (returning visitor)', 'wp-piwik' ) . ':', $revenue_return ),
|
||||||
|
array( __( 'Conversion rate (returning visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'conversion_rate_returning_visit' ) ),
|
||||||
|
);
|
||||||
|
$table_foot = self::$settings->get_global_option( 'piwik_shortcut' )
|
||||||
|
? array(
|
||||||
|
esc_html__( 'Shortcut', 'wp-piwik' ) . ':',
|
||||||
|
'<a href="' . esc_attr( self::$settings->get_global_option( 'piwik_url' ) ) . '">Piwik</a>',
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
$this->table( $table_head, $table_body, $table_foot );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,52 +1,55 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Items extends \WP_Piwik\Widget {
|
class Items extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->title = $prefix.__('E-Commerce Items', 'wp-piwik');
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$this->method = 'Goals.getItemsName';
|
$time_settings = $this->get_time_settings();
|
||||||
$this->parameter = array(
|
$this->title = $prefix . __( 'E-Commerce Items', 'wp-piwik' );
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
$this->method = 'Goals.getItemsName';
|
||||||
'period' => $timeSettings['period'],
|
$this->parameter = array(
|
||||||
'date' => $timeSettings['date']
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
);
|
'period' => $time_settings['period'],
|
||||||
}
|
'date' => $time_settings['date'],
|
||||||
|
);
|
||||||
public function show() {
|
}
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
public function show() {
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
else {
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
$tableHead = array(
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
__('Label', 'wp-piwik'),
|
} else {
|
||||||
__('Revenue', 'wp-piwik'),
|
$table_head = array(
|
||||||
__('Quantity', 'wp-piwik'),
|
__( 'Label', 'wp-piwik' ),
|
||||||
__('Orders', 'wp-piwik'),
|
__( 'Revenue', 'wp-piwik' ),
|
||||||
__('Avg. price', 'wp-piwik'),
|
__( 'Quantity', 'wp-piwik' ),
|
||||||
__('Avg. quantity', 'wp-piwik'),
|
__( 'Orders', 'wp-piwik' ),
|
||||||
__('Conversion rate', 'wp-piwik'),
|
__( 'Avg. price', 'wp-piwik' ),
|
||||||
);
|
__( 'Avg. quantity', 'wp-piwik' ),
|
||||||
$tableBody = array();
|
__( 'Conversion rate', 'wp-piwik' ),
|
||||||
if (is_array($response))
|
);
|
||||||
foreach ($response as $data) {
|
$table_body = array();
|
||||||
array_push($tableBody, array(
|
if ( is_array( $response ) ) {
|
||||||
$data['label'],
|
foreach ( $response as $data ) {
|
||||||
number_format($data['revenue'],2),
|
array_push(
|
||||||
$data['quantity'],
|
$table_body,
|
||||||
$data['orders'],
|
array(
|
||||||
number_format($data['avg_price'],2),
|
$data['label'],
|
||||||
$data['avg_quantity'],
|
number_format( $data['revenue'], 2 ),
|
||||||
$data['conversion_rate']
|
$data['quantity'],
|
||||||
));
|
$data['orders'],
|
||||||
}
|
number_format( $data['avg_price'], 2 ),
|
||||||
$tableFoot = array();
|
$data['avg_quantity'],
|
||||||
$this->table($tableHead, $tableBody, $tableFoot);
|
$data['conversion_rate'],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$table_foot = array();
|
||||||
|
$this->table( $table_head, $table_body, $table_foot );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,49 +4,52 @@ namespace WP_Piwik\Widget;
|
|||||||
|
|
||||||
class ItemsCategory extends \WP_Piwik\Widget {
|
class ItemsCategory extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
public $class_name = __CLASS__;
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$timeSettings = $this->getTimeSettings();
|
$time_settings = $this->get_time_settings();
|
||||||
$this->title = $prefix.__('E-Commerce Item Categories', 'wp-piwik');
|
$this->title = $prefix . __( 'E-Commerce Item Categories', 'wp-piwik' );
|
||||||
$this->method = 'Goals.getItemsCategory';
|
$this->method = 'Goals.getItemsCategory';
|
||||||
$this->parameter = array(
|
$this->parameter = array(
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
'period' => $timeSettings['period'],
|
'period' => $time_settings['period'],
|
||||||
'date' => $timeSettings['date']
|
'date' => $time_settings['date'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show() {
|
public function show() {
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
else {
|
} else {
|
||||||
$tableHead = array(
|
$table_head = array(
|
||||||
__('Label', 'wp-piwik'),
|
__( 'Label', 'wp-piwik' ),
|
||||||
__('Revenue', 'wp-piwik'),
|
__( 'Revenue', 'wp-piwik' ),
|
||||||
__('Quantity', 'wp-piwik'),
|
__( 'Quantity', 'wp-piwik' ),
|
||||||
__('Orders', 'wp-piwik'),
|
__( 'Orders', 'wp-piwik' ),
|
||||||
__('Avg. price', 'wp-piwik'),
|
__( 'Avg. price', 'wp-piwik' ),
|
||||||
__('Avg. quantity', 'wp-piwik'),
|
__( 'Avg. quantity', 'wp-piwik' ),
|
||||||
__('Conversion rate', 'wp-piwik'),
|
__( 'Conversion rate', 'wp-piwik' ),
|
||||||
);
|
);
|
||||||
$tableBody = array();
|
$table_body = array();
|
||||||
if (is_array($response))
|
if ( is_array( $response ) ) {
|
||||||
foreach ($response as $data) {
|
foreach ( $response as $data ) {
|
||||||
array_push($tableBody, array(
|
array_push(
|
||||||
$data['label'],
|
$table_body,
|
||||||
isset($data['revenue'])?number_format($data['revenue'],2):"-.--",
|
array(
|
||||||
isset($data['quantity'])?$data['quantity']:'-',
|
$data['label'],
|
||||||
isset($data['orders'])?$data['orders']:'-',
|
isset( $data['revenue'] ) ? number_format( $data['revenue'], 2 ) : '-.--',
|
||||||
number_format($data['avg_price'],2),
|
isset( $data['quantity'] ) ? $data['quantity'] : '-',
|
||||||
$data['avg_quantity'],
|
isset( $data['orders'] ) ? $data['orders'] : '-',
|
||||||
$data['conversion_rate']
|
number_format( $data['avg_price'], 2 ),
|
||||||
));
|
$data['avg_quantity'],
|
||||||
}
|
$data['conversion_rate'],
|
||||||
$tableFoot = array();
|
)
|
||||||
$this->table($tableHead, $tableBody, $tableFoot);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$table_foot = array();
|
||||||
}
|
$this->table( $table_head, $table_body, $table_foot );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,21 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Keywords extends \WP_Piwik\Widget {
|
class Keywords extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
|
||||||
'period' => $timeSettings['period'],
|
|
||||||
'date' => $timeSettings['date']
|
|
||||||
);
|
|
||||||
$this->title = $prefix.__('Keywords', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
|
||||||
$this->method = 'Referrers.getKeywords';
|
|
||||||
$this->name = 'Keyword';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
|
$time_settings = $this->get_time_settings();
|
||||||
|
$this->parameter = array(
|
||||||
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
|
'period' => $time_settings['period'],
|
||||||
|
'date' => $time_settings['date'],
|
||||||
|
);
|
||||||
|
$this->title = $prefix . __( 'Keywords', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
|
$this->method = 'Referrers.getKeywords';
|
||||||
|
$this->name = 'Keyword';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,73 +1,83 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
use WP_Piwik\Widget;
|
use WP_Piwik\Widget;
|
||||||
|
|
||||||
class Models extends Widget {
|
class Models extends Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
|
||||||
'period' => $timeSettings['period'],
|
|
||||||
'date' => $timeSettings['date']
|
|
||||||
);
|
|
||||||
$this->title = $prefix.__('Models', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
|
||||||
$this->method = 'DevicesDetection.getModel';
|
|
||||||
$this->context = 'normal';
|
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
|
||||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show() {
|
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
$tableBody = array();
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
|
||||||
else {
|
|
||||||
$tableHead = array(__('Model', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
|
||||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
|
||||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
|
||||||
$count = 0;
|
|
||||||
$sum = 0;
|
|
||||||
$js = array();
|
|
||||||
$class = array();
|
|
||||||
if (is_array($response))
|
|
||||||
foreach ($response as $row) {
|
|
||||||
$count++;
|
|
||||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
|
||||||
if ($count < $this->limit)
|
|
||||||
$tableBody[$row['label']] = array(htmlentities($row['label']), $row[$unique], 0);
|
|
||||||
elseif (!isset($tableBody['Others'])) {
|
|
||||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class['Others'] = 'wp-piwik-hideDetails';
|
|
||||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
} else {
|
|
||||||
$tableBody['Others'][1] += $row[$unique];
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($count > $this->limit)
|
|
||||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
|
||||||
elseif ($count == $this->limit) {
|
|
||||||
$class['Others'] = $js['Others'] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($tableBody as $key => $row)
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
$time_settings = $this->get_time_settings();
|
||||||
|
$this->parameter = array(
|
||||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
'period' => $time_settings['period'],
|
||||||
|
'date' => $time_settings['date'],
|
||||||
|
);
|
||||||
|
$this->title = $prefix . __( 'Models', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
|
$this->method = 'DevicesDetection.getModel';
|
||||||
|
$this->context = 'normal';
|
||||||
|
|
||||||
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
|
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show() {
|
||||||
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
|
$table_body = array();
|
||||||
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
$table_head = array( __( 'Model', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||||
|
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||||
|
$unique = 'nb_uniq_visitors';
|
||||||
|
} else {
|
||||||
|
$unique = 'sum_daily_nb_uniq_visitors';
|
||||||
}
|
}
|
||||||
|
$count = 0;
|
||||||
|
$sum = 0;
|
||||||
|
$js = array();
|
||||||
|
$css_class = array();
|
||||||
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $row ) {
|
||||||
|
++$count;
|
||||||
|
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||||
|
if ( $count < $this->limit ) {
|
||||||
|
$table_body[ $row['label'] ] = array( htmlentities( $row['label'] ), $row[ $unique ], 0 );
|
||||||
|
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||||
|
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||||
|
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
} else {
|
||||||
|
$table_body['Others'][1] += $row[ $unique ];
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $count > $this->limit ) {
|
||||||
|
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||||
|
} elseif ( $count === $this->limit ) {
|
||||||
|
$css_class['Others'] = '';
|
||||||
|
$js['Others'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $table_body as $key => $row ) {
|
||||||
|
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $table_body ) ) {
|
||||||
|
$this->pie_chart( $table_body );
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,37 +2,42 @@
|
|||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Noresult extends \WP_Piwik\Widget {
|
class Noresult extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
$time_settings = $this->get_time_settings();
|
||||||
'period' => $timeSettings['period'],
|
$this->parameter = array(
|
||||||
'date' => $timeSettings['date']
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
);
|
'period' => $time_settings['period'],
|
||||||
$this->title = $prefix.__('Site Search', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
'date' => $time_settings['date'],
|
||||||
$this->method = 'Actions.getSiteSearchNoResultKeywords';
|
);
|
||||||
}
|
$this->title = $prefix . __( 'Site Search', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
|
$this->method = 'Actions.getSiteSearchNoResultKeywords';
|
||||||
public function show() {
|
}
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
public function show() {
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
else {
|
if (
|
||||||
$tableHead = array(__('Keyword', 'wp-piwik'), __('Requests', 'wp-piwik'), __('Bounced', 'wp-piwik'));
|
! empty( $response['result'] )
|
||||||
$tableBody = array();
|
&& 'error' === $response['result']
|
||||||
$count = 0;
|
) {
|
||||||
if (is_array($response))
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
foreach ($response as $row) {
|
} else {
|
||||||
$count++;
|
$table_head = array( __( 'Keyword', 'wp-piwik' ), __( 'Requests', 'wp-piwik' ), __( 'Bounced', 'wp-piwik' ) );
|
||||||
$tableBody[] = array($row['label'], $row['nb_visits'], $row['bounce_rate']);
|
$table_body = array();
|
||||||
if ($count == 10) break;
|
$count = 0;
|
||||||
}
|
if ( is_array( $response ) ) {
|
||||||
$this->table($tableHead, $tableBody, null);
|
foreach ( $response as $row ) {
|
||||||
|
++$count;
|
||||||
|
$table_body[] = array( $row['label'], $row['nb_visits'], $row['bounce_rate'] );
|
||||||
|
if ( 10 === $count ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$this->table( $table_head, $table_body, null );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,37 +2,34 @@
|
|||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class OptOut extends \WP_Piwik\Widget
|
class OptOut extends \WP_Piwik\Widget {
|
||||||
{
|
|
||||||
|
|
||||||
public $className = __CLASS__;
|
public $class_name = __CLASS__;
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array())
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
{
|
$this->parameter = $params;
|
||||||
$this->parameter = $params;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function show()
|
public function show() {
|
||||||
{
|
$protocol = ( isset( $_SERVER ['HTTPS'] ) && 'off' !== $_SERVER ['HTTPS'] ) ? 'https' : 'http';
|
||||||
$protocol = (isset ($_SERVER ['HTTPS']) && $_SERVER ['HTTPS'] != 'off') ? 'https' : 'http';
|
switch ( self::$settings->get_global_option( 'piwik_mode' ) ) {
|
||||||
switch (self::$settings->getGlobalOption('piwik_mode')) {
|
case 'php':
|
||||||
case 'php' :
|
$piwik_url = $protocol . ':' . self::$settings->get_global_option( 'proxy_url' );
|
||||||
$PIWIK_URL = $protocol . ':' . self::$settings->getGlobalOption('proxy_url');
|
break;
|
||||||
break;
|
case 'cloud':
|
||||||
case 'cloud' :
|
$piwik_url = 'https://' . self::$settings->get_global_option( 'piwik_user' ) . '.innocraft.cloud/';
|
||||||
$PIWIK_URL = 'https://' . self::$settings->getGlobalOption('piwik_user') . '.innocraft.cloud/';
|
break;
|
||||||
break;
|
case 'cloud-matomo':
|
||||||
case 'cloud-matomo':
|
$piwik_url = 'https://' . self::$settings->get_global_option( 'matomo_user' ) . '.matomo.cloud/';
|
||||||
$PIWIK_URL = 'https://' . self::$settings->getGlobalOption('matomo_user') . '.matomo.cloud/';
|
break;
|
||||||
break;
|
default:
|
||||||
default :
|
$piwik_url = self::$settings->get_global_option( 'piwik_url' );
|
||||||
$PIWIK_URL = self::$settings->getGlobalOption('piwik_url');
|
break;
|
||||||
}
|
}
|
||||||
$width = (isset($this->parameter['width']) ? esc_attr($this->parameter['width']) : '');
|
$width = ( isset( $this->parameter['width'] ) ? rawurlencode( $this->parameter['width'] ) : '' );
|
||||||
$height = (isset($this->parameter['height']) ? esc_attr($this->parameter['height']) : '');
|
$height = ( isset( $this->parameter['height'] ) ? rawurlencode( $this->parameter['height'] ) : '' );
|
||||||
$idSite = (isset($this->parameter['idsite']) ? 'idsite=' . (int)$this->parameter['idsite'] . '&' : '');
|
$idsite = ( isset( $this->parameter['idsite'] ) ? 'idsite=' . (int) $this->parameter['idsite'] . '&' : '' );
|
||||||
$language = (isset($this->parameter['language']) ? esc_attr($this->parameter['language']) : 'en');
|
$language = ( isset( $this->parameter['language'] ) ? rawurlencode( $this->parameter['language'] ) : 'en' );
|
||||||
$this->out('<iframe frameborder="no" width="' . $width . '" height="' . $height . '" src="' . $PIWIK_URL . 'index.php?module=CoreAdminHome&action=optOut&' . $idSite . 'language=' . $language . '"></iframe>');
|
$this->out( '<iframe frameborder="no" width="' . esc_attr( $width ) . '" height="' . esc_attr( $height ) . '" src="' . esc_attr( $piwik_url . 'index.php?module=CoreAdminHome&action=optOut&' . $idsite . 'language=' . $language ) . '"></iframe>' );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -2,65 +2,76 @@
|
|||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Overview extends \WP_Piwik\Widget
|
class Overview extends \WP_Piwik\Widget {
|
||||||
{
|
|
||||||
|
|
||||||
public $className = __CLASS__;
|
public $class_name = __CLASS__;
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array())
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
{
|
$time_settings = $this->get_time_settings();
|
||||||
$timeSettings = $this->getTimeSettings();
|
$this->parameter = array(
|
||||||
$this->parameter = array(
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
'period' => isset( $params['period'] ) ? $params['period'] : $time_settings['period'],
|
||||||
'period' => isset($params['period']) ? $params['period'] : $timeSettings['period'],
|
'date' => isset( $params['date'] ) ? $params['date'] : $time_settings['date'],
|
||||||
'date' => isset($params['date']) ? $params['date'] : $timeSettings['date'],
|
'description' => $time_settings['description'],
|
||||||
'description' => $timeSettings['description']
|
);
|
||||||
);
|
$this->title = ! $this->is_shortcode ? $prefix . __( 'Overview', 'wp-piwik' ) . ' (' . ( 'dashboard' === $this->page_id ? $this->range_name() : $time_settings['description'] ) . ')' : ( $params['title'] ? $params['title'] : '' );
|
||||||
$this->title = !$this->isShortcode ? $prefix . __('Overview', 'wp-piwik') . ' (' . __($this->pageId == 'dashboard' ? $this->rangeName() : $timeSettings['description'], 'wp-piwik') . ')' : ($params['title'] ? $params['title'] : '');
|
$this->method = 'VisitsSummary.get';
|
||||||
$this->method = 'VisitsSummary.get';
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function show()
|
public function show() {
|
||||||
{
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
if (!empty($response['result']) && $response['result'] = 'error')
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
} else {
|
||||||
else {
|
if ( in_array( $this->parameter['date'], array( 'last30', 'last60', 'last90' ), true ) ) {
|
||||||
if (in_array($this->parameter['date'], array('last30', 'last60', 'last90'))) {
|
$result = array();
|
||||||
$result = array();
|
if ( is_array( $response ) ) {
|
||||||
if (is_array($response)) {
|
foreach ( $response as $data ) {
|
||||||
foreach ($response as $data)
|
foreach ( $data as $key => $value ) {
|
||||||
foreach ($data as $key => $value)
|
if ( isset( $result[ $key ] ) && is_numeric( $value ) ) {
|
||||||
if (isset($result[$key]) && is_numeric($value))
|
$result[ $key ] += $value;
|
||||||
$result[$key] += $value;
|
} elseif ( is_numeric( $value ) ) {
|
||||||
elseif (is_numeric($value))
|
$result[ $key ] = $value;
|
||||||
$result[$key] = $value;
|
} else {
|
||||||
else
|
$result[ $key ] = 0;
|
||||||
$result[$key] = 0;
|
}
|
||||||
if (isset($result['nb_visits']) && $result['nb_visits'] > 0) {
|
}
|
||||||
$result['nb_actions_per_visit'] = round($result['nb_actions'] / $result['nb_visits'], 1);
|
}
|
||||||
$result['bounce_rate'] = round($result['bounce_count'] / $result['nb_visits'] * 100, 1) . '%';
|
if ( isset( $result['nb_visits'] ) && $result['nb_visits'] > 0 ) {
|
||||||
$result['avg_time_on_site'] = round($result['sum_visit_length'] / $result['nb_visits'], 0);
|
$result['nb_actions_per_visit'] = round( $result['nb_actions'] / $result['nb_visits'], 1 );
|
||||||
} else $result['nb_actions_per_visit'] = $result['bounce_rate'] = $result['avg_time_on_site'] = 0;
|
$result['bounce_rate'] = round( $result['bounce_count'] / $result['nb_visits'] * 100, 1 ) . '%';
|
||||||
}
|
$result['avg_time_on_site'] = round( $result['sum_visit_length'] / $result['nb_visits'], 0 );
|
||||||
$response = $result;
|
} else {
|
||||||
}
|
$result['nb_actions_per_visit'] = 0;
|
||||||
$time = isset($response['sum_visit_length']) ? $this->timeFormat($response['sum_visit_length']) : '-';
|
$result['bounce_rate'] = 0;
|
||||||
$avgTime = isset($response['avg_time_on_site']) ? $this->timeFormat($response['avg_time_on_site']) : '-';
|
$result['avg_time_on_site'] = 0;
|
||||||
$tableHead = null;
|
}
|
||||||
$tableBody = array(array(__('Visitors', 'wp-piwik') . ':', $this->value($response, 'nb_visits')));
|
}
|
||||||
if ($this->value($response, 'nb_uniq_visitors') != '-')
|
$response = $result;
|
||||||
array_push($tableBody, array(__('Unique visitors', 'wp-piwik') . ':', $this->value($response, 'nb_uniq_visitors')));
|
}
|
||||||
array_push($tableBody,
|
$time = isset( $response['sum_visit_length'] ) ? $this->time_format( $response['sum_visit_length'] ) : '-';
|
||||||
array(__('Page views', 'wp-piwik') . ':', $this->value($response, 'nb_actions') . ' (Ø ' . $this->value($response, 'nb_actions_per_visit') . ')'),
|
$avg_time = isset( $response['avg_time_on_site'] ) ? $this->time_format( $response['avg_time_on_site'] ) : '-';
|
||||||
array(__('Total time spent', 'wp-piwik') . ':', $time . ' (Ø ' . $avgTime . ')'),
|
$table_head = null;
|
||||||
array(__('Bounce count', 'wp-piwik') . ':', $this->value($response, 'bounce_count') . ' (' . $this->value($response, 'bounce_rate') . ')')
|
$table_body = array( array( __( 'Visitors', 'wp-piwik' ) . ':', $this->value( $response, 'nb_visits' ) ) );
|
||||||
);
|
if ( '-' !== $this->value( $response, 'nb_uniq_visitors' ) ) {
|
||||||
if (!in_array($this->parameter['date'], array('last30', 'last60', 'last90')))
|
array_push( $table_body, array( __( 'Unique visitors', 'wp-piwik' ) . ':', $this->value( $response, 'nb_uniq_visitors' ) ) );
|
||||||
array_push($tableBody, array(__('Time/visit', 'wp-piwik') . ':', $avgTime), array(__('Max. page views in one visit', 'wp-piwik') . ':', $this->value($response, 'max_actions')));
|
}
|
||||||
$tableFoot = (self::$settings->getGlobalOption('piwik_shortcut') ? array(__('Shortcut', 'wp-piwik') . ':', '<a href="' . self::$settings->getGlobalOption('piwik_url') . '" target="_BLANK">Matomo</a>' . (isset($aryConf['inline']) && $aryConf['inline'] ? ' - <a href="?page=wp-piwik_stats">WP-Piwik</a>' : '')) : null);
|
array_push(
|
||||||
$this->table($tableHead, $tableBody, $tableFoot);
|
$table_body,
|
||||||
}
|
array( __( 'Page views', 'wp-piwik' ) . ':', $this->value( $response, 'nb_actions' ) . ' (Ø ' . $this->value( $response, 'nb_actions_per_visit' ) . ')' ),
|
||||||
}
|
array( __( 'Total time spent', 'wp-piwik' ) . ':', $time . ' (Ø ' . $avg_time . ')' ),
|
||||||
|
array( __( 'Bounce count', 'wp-piwik' ) . ':', $this->value( $response, 'bounce_count' ) . ' (' . $this->value( $response, 'bounce_rate' ) . ')' )
|
||||||
}
|
);
|
||||||
|
if ( ! in_array( $this->parameter['date'], array( 'last30', 'last60', 'last90' ), true ) ) {
|
||||||
|
array_push( $table_body, array( __( 'Time/visit', 'wp-piwik' ) . ':', $avg_time ), array( __( 'Max. page views in one visit', 'wp-piwik' ) . ':', $this->value( $response, 'max_actions' ) ) );
|
||||||
|
}
|
||||||
|
$table_foot = self::$settings->get_global_option( 'piwik_shortcut' )
|
||||||
|
? array(
|
||||||
|
esc_html__( 'Shortcut', 'wp-piwik' ) . ':',
|
||||||
|
'<a href="' . esc_attr( self::$settings->get_global_option( 'piwik_url' ) ) . '" target="_BLANK">Matomo</a>',
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
$this->table( $table_head, $table_body, $table_foot );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,21 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Pages extends \WP_Piwik\Widget {
|
class Pages extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
$time_settings = $this->get_time_settings();
|
||||||
'period' => $timeSettings['period'],
|
$this->parameter = array(
|
||||||
'date' => $timeSettings['date']
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
);
|
'period' => $time_settings['period'],
|
||||||
$this->title = $prefix.__('Pages', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
'date' => $time_settings['date'],
|
||||||
$this->method = 'Actions.getPageTitles';
|
);
|
||||||
$this->name = __('Page', 'wp-piwik' );
|
$this->title = $prefix . __( 'Pages', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
}
|
$this->method = 'Actions.getPageTitles';
|
||||||
|
$this->name = __( 'Page', 'wp-piwik' );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,38 +1,40 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Plugins extends \WP_Piwik\Widget {
|
class Plugins extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
$time_settings = $this->get_time_settings();
|
||||||
'period' => $timeSettings['period'],
|
$this->parameter = array(
|
||||||
'date' => $timeSettings['date']
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
);
|
'period' => $time_settings['period'],
|
||||||
$this->title = $prefix.__('Plugins', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
'date' => $time_settings['date'],
|
||||||
$this->method = 'DevicePlugins.getPlugin';
|
);
|
||||||
}
|
$this->title = $prefix . __( 'Plugins', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
|
$this->method = 'DevicePlugins.getPlugin';
|
||||||
public function show() {
|
}
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
public function show() {
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
else {
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
$tableHead = array(__('Plugin', 'wp-piwik'), __('Visits', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
$tableBody = array();
|
} else {
|
||||||
$count = 0;
|
$table_head = array( __( 'Plugin', 'wp-piwik' ), __( 'Visits', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||||
if (is_array($response))
|
$table_body = array();
|
||||||
foreach ($response as $row) {
|
$count = 0;
|
||||||
$count++;
|
if ( is_array( $response ) ) {
|
||||||
$tableBody[] = array($row['label'], $row['nb_visits'], $row['nb_visits_percentage']);
|
foreach ( $response as $row ) {
|
||||||
if ($count == 10) break;
|
++$count;
|
||||||
}
|
$table_body[] = array( $row['label'], $row['nb_visits'], $row['nb_visits_percentage'] );
|
||||||
$this->table($tableHead, $tableBody, null);
|
if ( 10 === $count ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$this->table( $table_head, $table_body, null );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,82 +1,95 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Post extends \WP_Piwik\Widget {
|
class Post extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
global $post;
|
|
||||||
$timeSettings = $this->getTimeSettings();
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$this->parameter = array(
|
global $post;
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
$time_settings = $this->get_time_settings();
|
||||||
'period' => isset($params['period']) ? $params['period'] : $timeSettings['period'],
|
$this->parameter = array(
|
||||||
'date' => isset($params['date']) ? $params['date'] : $timeSettings['date'],
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
'key' => isset($params['key'])?$params['key']:null,
|
'period' => isset( $params['period'] ) ? $params['period'] : $time_settings['period'],
|
||||||
'pageUrl' => isset($params['url'])?$params['url']:urlencode(get_permalink($post->ID)),
|
'date' => isset( $params['date'] ) ? $params['date'] : $time_settings['date'],
|
||||||
'description' => $timeSettings['description']
|
'key' => isset( $params['key'] ) ? $params['key'] : null,
|
||||||
);
|
'pageUrl' => isset( $params['url'] ) ? $params['url'] : get_permalink( $post->ID ),
|
||||||
$this->title = $prefix.__('Overview', 'wp-piwik').' ('.__($this->parameter['date'],'wp-piwik').')';
|
'description' => $time_settings['description'],
|
||||||
$this->method = 'Actions.getPageUrl';
|
);
|
||||||
}
|
$this->title = $prefix . esc_html__( 'Overview', 'wp-piwik' ) . ' (' . $this->parameter['date'] . ')';
|
||||||
|
$this->method = 'Actions.getPageUrl';
|
||||||
public function show() {
|
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
if (!empty($response['result']) && $response['result'] = 'error')
|
|
||||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
|
||||||
else {
|
|
||||||
if (in_array($this->parameter['date'], array('last30', 'last60', 'last90'))) {
|
|
||||||
$result = array();
|
|
||||||
if (is_array($response)) {
|
|
||||||
foreach ($response as $data) {
|
|
||||||
if (isset($data[0])) {
|
|
||||||
foreach ($data[0] as $key => $value)
|
|
||||||
if (isset($result[$key]) && is_numeric($value))
|
|
||||||
$result[$key] += $value;
|
|
||||||
elseif (is_numeric($value))
|
|
||||||
$result[$key] = $value;
|
|
||||||
else
|
|
||||||
$result[$key] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($result['nb_visits']) && $result['nb_visits'] > 0) {
|
|
||||||
$result['nb_actions_per_visit'] = round((isset( $result['nb_actions'] ) ? $result['nb_actions'] : 0) / $result['nb_visits'], 1);
|
|
||||||
$result['bounce_rate'] = round((isset($result['bounce_count']) ? $result['bounce_count'] : 0) / $result['nb_visits'] * 100, 1) . '%';
|
|
||||||
$result['avg_time_on_site'] = round((isset($result['sum_visit_length']) ? $result['sum_visit_length'] : 0) / $result['nb_visits'], 0);
|
|
||||||
} else $result['nb_actions_per_visit'] = $result['bounce_rate'] = $result['avg_time_on_site'] = 0;
|
|
||||||
}
|
|
||||||
$response = $result;
|
|
||||||
} else {
|
|
||||||
if (isset($response[0]))
|
|
||||||
$response = $response[0];
|
|
||||||
if ($this->parameter['key']) {
|
|
||||||
$this->out(isset($response[$this->parameter['key']])?$response[$this->parameter['key']]:'<em>not defined</em>');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$time = isset($response['sum_visit_length']) ? $this->timeFormat($response['sum_visit_length']) : '-';
|
|
||||||
$avgTime = isset($response['avg_time_on_site']) ? $this->timeFormat($response['avg_time_on_site']) : '-';
|
|
||||||
$tableHead = null;
|
|
||||||
$tableBody = array(array(__('Visitors', 'wp-piwik') . ':', $this->value($response, 'nb_visits')));
|
|
||||||
if ($this->value($response, 'nb_uniq_visitors') != '-')
|
|
||||||
array_push($tableBody, array(__('Unique visitors', 'wp-piwik') . ':', $this->value($response, 'nb_uniq_visitors')));
|
|
||||||
elseif ($this->value($response, 'sum_daily_nb_uniq_visitors') != '-') {
|
|
||||||
array_push($tableBody, __('Unique visitors', 'wp-piwik') . ':', $this->value($response, 'sum_daily_nb_uniq_visitors'));
|
|
||||||
}
|
|
||||||
array_push($tableBody,
|
|
||||||
array(__('Page views', 'wp-piwik').':', $this->value($response, 'nb_hits').' (Ø '.$this->value($response, 'entry_nb_actions').')'),
|
|
||||||
array(__('Total time spent', 'wp-piwik').':', $time),
|
|
||||||
array(__('Bounce count', 'wp-piwik').':', $this->value($response, 'entry_bounce_count').' ('.$this->value($response, 'bounce_rate').')'),
|
|
||||||
array(__('Time/visit', 'wp-piwik').':', $avgTime),
|
|
||||||
array(__('Min. generation time', 'wp-piwik').':', $this->value($response, 'min_time_generation')),
|
|
||||||
array(__('Max. generation time', 'wp-piwik').':', $this->value($response, 'max_time_generation'))
|
|
||||||
);
|
|
||||||
if (!in_array($this->parameter['date'], array('last30', 'last60', 'last90')))
|
|
||||||
array_push($tableBody, array(__('Time/visit', 'wp-piwik') . ':', $avgTime), array(__('Max. page views in one visit', 'wp-piwik') . ':', $this->value($response, 'max_actions')));
|
|
||||||
$tableFoot = (self::$settings->getGlobalOption('piwik_shortcut') ? array(__('Shortcut', 'wp-piwik') . ':', '<a href="' . self::$settings->getGlobalOption('piwik_url') . '">Piwik</a>' . (isset($aryConf['inline']) && $aryConf['inline'] ? ' - <a href="?page=wp-piwik_stats">WP-Piwik</a>' : '')) : null);
|
|
||||||
$this->table($tableHead, $tableBody, $tableFoot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function show() {
|
||||||
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
if ( in_array( $this->parameter['date'], array( 'last30', 'last60', 'last90' ), true ) ) {
|
||||||
|
$result = array();
|
||||||
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $data ) {
|
||||||
|
if ( isset( $data[0] ) ) {
|
||||||
|
foreach ( $data[0] as $key => $value ) {
|
||||||
|
if ( isset( $result[ $key ] ) && is_numeric( $value ) ) {
|
||||||
|
$result[ $key ] += $value;
|
||||||
|
} elseif ( is_numeric( $value ) ) {
|
||||||
|
$result[ $key ] = $value;
|
||||||
|
} else {
|
||||||
|
$result[ $key ] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( isset( $result['nb_visits'] ) && $result['nb_visits'] > 0 ) {
|
||||||
|
$result['nb_actions_per_visit'] = round( ( isset( $result['nb_actions'] ) ? $result['nb_actions'] : 0 ) / $result['nb_visits'], 1 );
|
||||||
|
$result['bounce_rate'] = round( ( isset( $result['bounce_count'] ) ? $result['bounce_count'] : 0 ) / $result['nb_visits'] * 100, 1 ) . '%';
|
||||||
|
$result['avg_time_on_site'] = round( ( isset( $result['sum_visit_length'] ) ? $result['sum_visit_length'] : 0 ) / $result['nb_visits'], 0 );
|
||||||
|
} else {
|
||||||
|
$result['nb_actions_per_visit'] = 0;
|
||||||
|
$result['bounce_rate'] = 0;
|
||||||
|
$result['avg_time_on_site'] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$response = $result;
|
||||||
|
} else {
|
||||||
|
if ( isset( $response[0] ) ) {
|
||||||
|
$response = $response[0];
|
||||||
|
}
|
||||||
|
if ( $this->parameter['key'] ) {
|
||||||
|
$this->out( isset( $response[ $this->parameter['key'] ] ) ? esc_html( $response[ $this->parameter['key'] ] ) : '<em>not defined</em>' );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$time = isset( $response['sum_visit_length'] ) ? $this->time_format( $response['sum_visit_length'] ) : '-';
|
||||||
|
$avg_time = isset( $response['avg_time_on_site'] ) ? $this->time_format( $response['avg_time_on_site'] ) : '-';
|
||||||
|
$table_head = null;
|
||||||
|
$table_body = array( array( __( 'Visitors', 'wp-piwik' ) . ':', $this->value( $response, 'nb_visits' ) ) );
|
||||||
|
if ( '-' !== $this->value( $response, 'nb_uniq_visitors' ) ) {
|
||||||
|
array_push( $table_body, array( __( 'Unique visitors', 'wp-piwik' ) . ':', $this->value( $response, 'nb_uniq_visitors' ) ) );
|
||||||
|
} elseif ( '-' !== $this->value( $response, 'sum_daily_nb_uniq_visitors' ) ) {
|
||||||
|
array_push( $table_body, __( 'Unique visitors', 'wp-piwik' ) . ':', $this->value( $response, 'sum_daily_nb_uniq_visitors' ) );
|
||||||
|
}
|
||||||
|
array_push(
|
||||||
|
$table_body,
|
||||||
|
array( __( 'Page views', 'wp-piwik' ) . ':', $this->value( $response, 'nb_hits' ) . ' (Ø ' . $this->value( $response, 'entry_nb_actions' ) . ')' ),
|
||||||
|
array( __( 'Total time spent', 'wp-piwik' ) . ':', $time ),
|
||||||
|
array( __( 'Bounce count', 'wp-piwik' ) . ':', $this->value( $response, 'entry_bounce_count' ) . ' (' . $this->value( $response, 'bounce_rate' ) . ')' ),
|
||||||
|
array( __( 'Time/visit', 'wp-piwik' ) . ':', $avg_time ),
|
||||||
|
array( __( 'Min. generation time', 'wp-piwik' ) . ':', $this->value( $response, 'min_time_generation' ) ),
|
||||||
|
array( __( 'Max. generation time', 'wp-piwik' ) . ':', $this->value( $response, 'max_time_generation' ) )
|
||||||
|
);
|
||||||
|
if ( ! in_array( $this->parameter['date'], array( 'last30', 'last60', 'last90' ), true ) ) {
|
||||||
|
array_push( $table_body, array( __( 'Time/visit', 'wp-piwik' ) . ':', $avg_time ), array( __( 'Max. page views in one visit', 'wp-piwik' ) . ':', $this->value( $response, 'max_actions' ) ) );
|
||||||
|
}
|
||||||
|
$table_foot = self::$settings->get_global_option( 'piwik_shortcut' )
|
||||||
|
? array(
|
||||||
|
esc_html__( 'Shortcut', 'wp-piwik' ) . ':',
|
||||||
|
'<a href="' . esc_attr( self::$settings->get_global_option( 'piwik_url' ) ) . '">Piwik</a>',
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
$this->table( $table_head, $table_body, $table_foot );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -2,20 +2,19 @@
|
|||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Referrers extends \WP_Piwik\Widget {
|
class Referrers extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
$time_settings = $this->get_time_settings();
|
||||||
'period' => $timeSettings['period'],
|
$this->parameter = array(
|
||||||
'date' => $timeSettings['date']
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
);
|
'period' => $time_settings['period'],
|
||||||
$this->title = $prefix.__('Referrers', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
'date' => $time_settings['date'],
|
||||||
$this->method = 'Referrers.getWebsites';
|
);
|
||||||
$this->name = 'Referrer';
|
$this->title = $prefix . __( 'Referrers', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
}
|
$this->method = 'Referrers.getWebsites';
|
||||||
|
$this->name = 'Referrer';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,68 +1,77 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Screens extends \WP_Piwik\Widget {
|
class Screens extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
|
||||||
'period' => $timeSettings['period'],
|
|
||||||
'date' => $timeSettings['date']
|
|
||||||
);
|
|
||||||
$this->title = $prefix.__('Resolutions', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
|
||||||
$this->method = 'Resolution.getResolution';
|
|
||||||
$this->context = 'normal';
|
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
|
||||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show() {
|
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
$tableBody = array();
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
|
||||||
else {
|
|
||||||
$tableHead = array(__('Resolution', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
|
||||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
|
||||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
|
||||||
$count = 0;
|
|
||||||
$sum = 0;
|
|
||||||
$js = array();
|
|
||||||
$class = array();
|
|
||||||
if (is_array($response))
|
|
||||||
foreach ($response as $row) {
|
|
||||||
$count++;
|
|
||||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
|
||||||
if ($count < $this->limit)
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
elseif (!isset($tableBody['Others'])) {
|
|
||||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class['Others'] = 'wp-piwik-hideDetails';
|
|
||||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
} else {
|
|
||||||
$tableBody['Others'][1] += $row[$unique];
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($count > $this->limit)
|
|
||||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
|
||||||
|
|
||||||
foreach ($tableBody as $key => $row)
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
$time_settings = $this->get_time_settings();
|
||||||
|
$this->parameter = array(
|
||||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
'period' => $time_settings['period'],
|
||||||
|
'date' => $time_settings['date'],
|
||||||
|
);
|
||||||
|
$this->title = $prefix . __( 'Resolutions', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
|
$this->method = 'Resolution.getResolution';
|
||||||
|
$this->context = 'normal';
|
||||||
|
|
||||||
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
|
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show() {
|
||||||
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
|
$table_body = array();
|
||||||
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
$table_head = array( __( 'Resolution', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||||
|
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||||
|
$unique = 'nb_uniq_visitors';
|
||||||
|
} else {
|
||||||
|
$unique = 'sum_daily_nb_uniq_visitors';
|
||||||
}
|
}
|
||||||
|
$count = 0;
|
||||||
|
$sum = 0;
|
||||||
|
$js = array();
|
||||||
|
$css_class = array();
|
||||||
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $row ) {
|
||||||
|
++$count;
|
||||||
|
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||||
|
if ( $count < $this->limit ) {
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||||
|
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||||
|
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
} else {
|
||||||
|
$table_body['Others'][1] += $row[ $unique ];
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $count > $this->limit ) {
|
||||||
|
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $table_body as $key => $row ) {
|
||||||
|
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $table_body ) ) {
|
||||||
|
$this->pie_chart( $table_body );
|
||||||
|
}
|
||||||
|
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,38 +1,40 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Search extends \WP_Piwik\Widget {
|
class Search extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
$time_settings = $this->get_time_settings();
|
||||||
'period' => $timeSettings['period'],
|
$this->parameter = array(
|
||||||
'date' => $timeSettings['date']
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
);
|
'period' => $time_settings['period'],
|
||||||
$this->title = $prefix.__('Site Search', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
'date' => $time_settings['date'],
|
||||||
$this->method = 'Actions.getSiteSearchKeywords';
|
);
|
||||||
}
|
$this->title = $prefix . __( 'Site Search', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
|
$this->method = 'Actions.getSiteSearchKeywords';
|
||||||
public function show() {
|
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
|
||||||
else {
|
|
||||||
$tableHead = array(__('Keyword', 'wp-piwik'), __('Requests', 'wp-piwik'), __('Bounced', 'wp-piwik'));
|
|
||||||
$tableBody = array();
|
|
||||||
$count = 0;
|
|
||||||
if (is_array($response))
|
|
||||||
foreach ($response as $row) {
|
|
||||||
$count++;
|
|
||||||
$tableBody[] = array(htmlentities($row['label']), $row['nb_visits'], $row['bounce_rate']);
|
|
||||||
if ($count == 10) break;
|
|
||||||
}
|
|
||||||
$this->table($tableHead, $tableBody, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function show() {
|
||||||
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
$table_head = array( __( 'Keyword', 'wp-piwik' ), __( 'Requests', 'wp-piwik' ), __( 'Bounced', 'wp-piwik' ) );
|
||||||
|
$table_body = array();
|
||||||
|
$count = 0;
|
||||||
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $row ) {
|
||||||
|
++$count;
|
||||||
|
$table_body[] = array( $row['label'], $row['nb_visits'], $row['bounce_rate'] );
|
||||||
|
if ( 10 === $count ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->table( $table_head, $table_body, null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,31 +1,33 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Seo extends \WP_Piwik\Widget {
|
class Seo extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
public $class_name = __CLASS__;
|
||||||
$this->parameter = array(
|
|
||||||
'url' => get_bloginfo('url')
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
);
|
$this->parameter = array(
|
||||||
$this->title = $prefix.__('SEO', 'wp-piwik');
|
'url' => get_bloginfo( 'url' ),
|
||||||
$this->method = 'SEO.getRank';
|
);
|
||||||
}
|
$this->title = $prefix . __( 'SEO', 'wp-piwik' );
|
||||||
|
$this->method = 'SEO.getRank';
|
||||||
public function show() {
|
}
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
public function show() {
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
else {
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
echo '<div class="table"><table class="widefat"><tbody>';
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
if (is_array($response))
|
} else {
|
||||||
foreach ($response as $val)
|
echo '<div class="table"><table class="widefat"><tbody>';
|
||||||
echo '<tr><td>'.(isset($val['logo_link']) && !empty($val['logo_link'])?'<a href="'.$val['logo_link'].'" title="'.$val['logo_tooltip'].'">'.$val['label'].'</a>':$val['label']).'</td><td>'.$val['rank'].'</td></tr>';
|
if ( is_array( $response ) ) {
|
||||||
else echo '<tr><td>SEO module currently not available.</td></tr>';
|
foreach ( $response as $val ) {
|
||||||
echo '</tbody></table></div>';
|
echo '<tr><td>' . ( isset( $val['logo_link'] ) && ! empty( $val['logo_link'] ) ? '<a href="' . esc_attr( $val['logo_link'] ) . '" title="' . esc_attr( $val['logo_tooltip'] ) . '">' . esc_html( $val['label'] ) . '</a>' : esc_html( $val['label'] ) ) . '</td><td>' . esc_html( $val['rank'] ) . '</td></tr>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo '<tr><td>SEO module currently not available.</td></tr>';
|
||||||
}
|
}
|
||||||
|
echo '</tbody></table></div>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,66 +1,76 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class SystemDetails extends \WP_Piwik\Widget {
|
class SystemDetails extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
|
||||||
'period' => $timeSettings['period'],
|
|
||||||
'date' => $timeSettings['date']
|
|
||||||
);
|
|
||||||
$this->title = $prefix.__('Operation System Details', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
|
||||||
$this->method = 'DevicesDetection.getOsVersions';
|
|
||||||
$this->context = 'normal';
|
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
|
||||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show() {
|
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
$tableBody = array();
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
|
||||||
else {
|
|
||||||
$tableHead = array(__('Operation System', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
|
||||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
|
||||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
|
||||||
$count = 0;
|
|
||||||
$sum = 0;
|
|
||||||
$js = array();
|
|
||||||
$class = array();
|
|
||||||
if (is_array($response))
|
|
||||||
foreach ($response as $row) {
|
|
||||||
$count++;
|
|
||||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
|
||||||
if ($count < $this->limit)
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
elseif (!isset($tableBody['Others'])) {
|
|
||||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class['Others'] = 'wp-piwik-hideDetails';
|
|
||||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
} else {
|
|
||||||
$tableBody['Others'][1] += $row[$unique];
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($count > $this->limit)
|
|
||||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
|
||||||
|
|
||||||
foreach ($tableBody as $key => $row)
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
$time_settings = $this->get_time_settings();
|
||||||
|
$this->parameter = array(
|
||||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
'period' => $time_settings['period'],
|
||||||
|
'date' => $time_settings['date'],
|
||||||
|
);
|
||||||
|
$this->title = $prefix . __( 'Operation System Details', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
|
$this->method = 'DevicesDetection.getOsVersions';
|
||||||
|
$this->context = 'normal';
|
||||||
|
|
||||||
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
|
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show() {
|
||||||
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
|
$table_body = array();
|
||||||
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
$table_head = array( __( 'Operation System', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||||
|
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||||
|
$unique = 'nb_uniq_visitors';
|
||||||
|
} else {
|
||||||
|
$unique = 'sum_daily_nb_uniq_visitors';
|
||||||
}
|
}
|
||||||
|
$count = 0;
|
||||||
|
$sum = 0;
|
||||||
|
$js = array();
|
||||||
|
$css_class = array();
|
||||||
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $row ) {
|
||||||
|
++$count;
|
||||||
|
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||||
|
if ( $count < $this->limit ) {
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||||
|
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||||
|
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
} else {
|
||||||
|
$table_body['Others'][1] += $row[ $unique ];
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $count > $this->limit ) {
|
||||||
|
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $table_body as $key => $row ) {
|
||||||
|
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $table_body ) ) {
|
||||||
|
$this->pie_chart( $table_body );
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,65 +2,75 @@
|
|||||||
|
|
||||||
namespace WP_Piwik\Widget;
|
namespace WP_Piwik\Widget;
|
||||||
|
|
||||||
class Systems extends \WP_Piwik\Widget {
|
class Systems extends \WP_Piwik\Widget {
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array()) {
|
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
|
||||||
'period' => $timeSettings['period'],
|
|
||||||
'date' => $timeSettings['date']
|
|
||||||
);
|
|
||||||
$this->title = $prefix.__('Operation Systems', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
|
||||||
$this->method = 'DevicesDetection.getOsFamilies';
|
|
||||||
$this->context = 'normal';
|
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
|
||||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show() {
|
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
|
||||||
$tableBody = array();
|
|
||||||
if (!empty($response['result']) && $response['result'] ='error')
|
|
||||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
|
||||||
else {
|
|
||||||
$tableHead = array(__('Operation System', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
|
||||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
|
||||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
|
||||||
$count = 0;
|
|
||||||
$sum = 0;
|
|
||||||
$js = array();
|
|
||||||
$class = array();
|
|
||||||
if (is_array($response))
|
|
||||||
foreach ($response as $row) {
|
|
||||||
$count++;
|
|
||||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
|
||||||
if ($count < $this->limit)
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
elseif (!isset($tableBody['Others'])) {
|
|
||||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class['Others'] = 'wp-piwik-hideDetails';
|
|
||||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
} else {
|
|
||||||
$tableBody['Others'][1] += $row[$unique];
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($count > $this->limit)
|
|
||||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
|
||||||
|
|
||||||
foreach ($tableBody as $key => $row)
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
$time_settings = $this->get_time_settings();
|
||||||
|
$this->parameter = array(
|
||||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
'period' => $time_settings['period'],
|
||||||
|
'date' => $time_settings['date'],
|
||||||
|
);
|
||||||
|
$this->title = $prefix . __( 'Operation Systems', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
|
$this->method = 'DevicesDetection.getOsFamilies';
|
||||||
|
$this->context = 'normal';
|
||||||
|
|
||||||
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
|
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show() {
|
||||||
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
|
$table_body = array();
|
||||||
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
$table_head = array( __( 'Operation System', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||||
|
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||||
|
$unique = 'nb_uniq_visitors';
|
||||||
|
} else {
|
||||||
|
$unique = 'sum_daily_nb_uniq_visitors';
|
||||||
}
|
}
|
||||||
|
$count = 0;
|
||||||
|
$sum = 0;
|
||||||
|
$js = array();
|
||||||
|
$css_class = array();
|
||||||
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $row ) {
|
||||||
|
++$count;
|
||||||
|
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||||
|
if ( $count < $this->limit ) {
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||||
|
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||||
|
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
} else {
|
||||||
|
$table_body['Others'][1] += $row[ $unique ];
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $count > $this->limit ) {
|
||||||
|
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $table_body as $key => $row ) {
|
||||||
|
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $table_body ) ) {
|
||||||
|
$this->pie_chart( $table_body );
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,77 +4,81 @@ namespace WP_Piwik\Widget;
|
|||||||
|
|
||||||
use WP_Piwik\Widget;
|
use WP_Piwik\Widget;
|
||||||
|
|
||||||
class Types extends Widget
|
class Types extends Widget {
|
||||||
{
|
|
||||||
|
|
||||||
public $className = __CLASS__;
|
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array())
|
public $class_name = __CLASS__;
|
||||||
{
|
|
||||||
$timeSettings = $this->getTimeSettings();
|
|
||||||
$this->parameter = array(
|
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
|
||||||
'period' => $timeSettings['period'],
|
|
||||||
'date' => $timeSettings['date']
|
|
||||||
);
|
|
||||||
$this->title = $prefix . __('Types', 'wp-piwik') . ' (' . __($timeSettings['description'], 'wp-piwik') . ')';
|
|
||||||
$this->method = 'DevicesDetection.getType';
|
|
||||||
$this->context = 'normal';
|
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL() . 'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script('wp-piwik-chartjs', self::$wpPiwik->getPluginURL() . 'js/chartjs/chart.min.js', "3.4.1");
|
|
||||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL() . 'css/wp-piwik.css', array(), self::$wpPiwik->getPluginVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show()
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
{
|
$time_settings = $this->get_time_settings();
|
||||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
$this->parameter = array(
|
||||||
$tableBody = array();
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
if (!empty($response['result']) && $response['result'] = 'error')
|
'period' => $time_settings['period'],
|
||||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
'date' => $time_settings['date'],
|
||||||
else {
|
);
|
||||||
$tableHead = array(__('Type', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
$this->title = $prefix . __( 'Types', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||||
if (isset($response[0]['nb_uniq_visitors'])) {
|
$this->method = 'DevicesDetection.getType';
|
||||||
$unique = 'nb_uniq_visitors';
|
$this->context = 'normal';
|
||||||
} else {
|
|
||||||
$unique = 'sum_daily_nb_uniq_visitors';
|
|
||||||
}
|
|
||||||
$count = 0;
|
|
||||||
$sum = 0;
|
|
||||||
$js = array();
|
|
||||||
$class = array();
|
|
||||||
if (is_array($response))
|
|
||||||
foreach ($response as $row) {
|
|
||||||
$key = isset($row[$unique]) ? $unique : "nb_visits";
|
|
||||||
$count++;
|
|
||||||
$sum += isset($row[$key]) ? $row[$key] : 0;
|
|
||||||
if ($count < $this->limit)
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$key], 0);
|
|
||||||
elseif (!isset($tableBody['Others'])) {
|
|
||||||
$tableBody['Others'] = array($row['label'], $row[$key], 0);
|
|
||||||
$class['Others'] = 'wp-piwik-hideDetails';
|
|
||||||
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$key], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
} else {
|
|
||||||
$tableBody['Others'][1] += $row[$key];
|
|
||||||
$tableBody[$row['label']] = array($row['label'], $row[$key], 0);
|
|
||||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
|
||||||
$js[$row['label']] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($count > $this->limit) {
|
|
||||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
|
||||||
} elseif ($count == $this->limit) {
|
|
||||||
$class['Others'] = $js['Others'] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($tableBody as $key => $row)
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
$tableBody[$key][2] = number_format($row[1] / $sum * 100, 2) . '%';
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
|
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
public function show() {
|
||||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||||
}
|
$table_body = array();
|
||||||
}
|
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||||
|
} else {
|
||||||
|
$table_head = array( __( 'Type', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||||
|
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||||
|
$unique = 'nb_uniq_visitors';
|
||||||
|
} else {
|
||||||
|
$unique = 'sum_daily_nb_uniq_visitors';
|
||||||
|
}
|
||||||
|
$count = 0;
|
||||||
|
$sum = 0;
|
||||||
|
$js = array();
|
||||||
|
$css_class = array();
|
||||||
|
if ( is_array( $response ) ) {
|
||||||
|
foreach ( $response as $row ) {
|
||||||
|
$key = isset( $row[ $unique ] ) ? $unique : 'nb_visits';
|
||||||
|
++$count;
|
||||||
|
$sum += isset( $row[ $key ] ) ? $row[ $key ] : 0;
|
||||||
|
if ( $count < $this->limit ) {
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $key ], 0 );
|
||||||
|
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||||
|
$table_body['Others'] = array( $row['label'], $row[ $key ], 0 );
|
||||||
|
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||||
|
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $key ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
} else {
|
||||||
|
$table_body['Others'][1] += $row[ $key ];
|
||||||
|
$table_body[ $row['label'] ] = array( $row['label'], $row[ $key ], 0 );
|
||||||
|
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||||
|
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $count > $this->limit ) {
|
||||||
|
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||||
|
} elseif ( $count === $this->limit ) {
|
||||||
|
$css_class['Others'] = '';
|
||||||
|
$js['Others'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
foreach ( $table_body as $key => $row ) {
|
||||||
|
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $table_body ) ) {
|
||||||
|
$this->pie_chart( $table_body );
|
||||||
|
}
|
||||||
|
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -4,76 +4,97 @@ namespace WP_Piwik\Widget;
|
|||||||
|
|
||||||
use WP_Piwik\Widget;
|
use WP_Piwik\Widget;
|
||||||
|
|
||||||
class Visitors extends Widget
|
class Visitors extends Widget {
|
||||||
{
|
|
||||||
|
|
||||||
public $className = __CLASS__;
|
public $class_name = __CLASS__;
|
||||||
|
|
||||||
protected function configure($prefix = '', $params = array())
|
protected function configure( $prefix = '', $params = array() ) {
|
||||||
{
|
$time_settings = $this->get_time_settings();
|
||||||
$timeSettings = $this->getTimeSettings();
|
$this->parameter = array(
|
||||||
$this->parameter = array(
|
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
'period' => isset( $params['period'] ) ? $params['period'] : $time_settings['period'],
|
||||||
'period' => isset($params['period']) ? $params['period'] : $timeSettings['period'],
|
'date' => 'last' . ( 'day' === $time_settings['period'] ? '30' : '12' ),
|
||||||
'date' => 'last' . ($timeSettings['period'] == 'day' ? '30' : '12'),
|
'limit' => null,
|
||||||
'limit' => null
|
);
|
||||||
);
|
$this->title = $prefix . __( 'Visitors', 'wp-piwik' ) . ' (' . $this->range_name() . ')';
|
||||||
$this->title = $prefix . __('Visitors', 'wp-piwik') . ' (' . __($this->rangeName(), 'wp-piwik') . ')';
|
$this->method = array( 'VisitsSummary.getVisits', 'VisitsSummary.getUniqueVisitors', 'VisitsSummary.getBounceCount', 'VisitsSummary.getActions' );
|
||||||
$this->method = array('VisitsSummary.getVisits', 'VisitsSummary.getUniqueVisitors', 'VisitsSummary.getBounceCount', 'VisitsSummary.getActions');
|
$this->context = 'normal';
|
||||||
$this->context = 'normal';
|
|
||||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL() . 'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
|
||||||
wp_enqueue_script('wp-piwik-chartjs', self::$wpPiwik->getPluginURL() . 'js/chartjs/chart.min.js', "3.4.1");
|
|
||||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL() . 'css/wp-piwik.css', array(), self::$wpPiwik->getPluginVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function requestData()
|
$version = self::$wp_piwik->get_plugin_version();
|
||||||
{
|
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||||
$response = array();
|
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||||
$success = true;
|
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||||
foreach ($this->method as $method) {
|
}
|
||||||
$response[$method] = self::$wpPiwik->request($this->apiID[$method]);
|
|
||||||
if (!empty($response[$method]['result']) && $response[$method]['result'] = 'error')
|
|
||||||
$success = false;
|
|
||||||
}
|
|
||||||
return array("response" => $response, "success" => $success);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show()
|
public function request_data() {
|
||||||
{
|
$response = array();
|
||||||
$result = $this->requestData();
|
$success = true;
|
||||||
$response = $result["response"];
|
foreach ( $this->method as $method ) {
|
||||||
if (!$result["success"]) {
|
$response[ $method ] = self::$wp_piwik->request( $this->api_id[ $method ] );
|
||||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response[$method]['message'], ENT_QUOTES, 'utf-8');
|
if ( ! empty( $response[ $method ]['result'] ) && 'error' === $response[ $method ]['result'] ) {
|
||||||
} else {
|
$success = false;
|
||||||
$data = array();
|
}
|
||||||
if (is_array($response) && is_array($response['VisitsSummary.getVisits']))
|
}
|
||||||
foreach ($response['VisitsSummary.getVisits'] as $key => $value) {
|
return array(
|
||||||
if ($this->parameter['period'] == 'week') {
|
'response' => $response,
|
||||||
preg_match("/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", $key, $dateList);
|
'success' => $success,
|
||||||
$jsKey = $dateList[0];
|
);
|
||||||
$textKey = $this->dateFormat($jsKey, 'week');
|
}
|
||||||
} elseif ($this->parameter['period'] == 'month') {
|
|
||||||
$jsKey = $key . '-01';
|
|
||||||
$textKey = $key;
|
|
||||||
} else $jsKey = $textKey = $key;
|
|
||||||
$data[] = array(
|
|
||||||
$textKey,
|
|
||||||
$value,
|
|
||||||
$response['VisitsSummary.getUniqueVisitors'][$key] ? $response['VisitsSummary.getUniqueVisitors'][$key] : '-',
|
|
||||||
$response['VisitsSummary.getBounceCount'][$key] ? $response['VisitsSummary.getBounceCount'][$key] : '-',
|
|
||||||
$response['VisitsSummary.getActions'][$key] ? $response['VisitsSummary.getActions'][$key] : '-'
|
|
||||||
);
|
|
||||||
$javaScript[] = 'javascript:wp_piwik_datelink(\'' . urlencode('wp-piwik_stats') . '\',\'' . str_replace('-', '', $jsKey) . '\',\'' . (isset($_GET['wpmu_show_stats']) ? (int)$_GET['wpmu_show_stats'] : '') . '\');';
|
|
||||||
}
|
|
||||||
$this->table(
|
|
||||||
array(__('Date', 'wp-piwik'), __('Visits', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Bounced', 'wp-piwik'), __('Page Views', 'wp-piwik')),
|
|
||||||
array_reverse($data),
|
|
||||||
array(),
|
|
||||||
'clickable',
|
|
||||||
array_reverse(isset($javaScript) ? $javaScript : [])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
public function show() {
|
||||||
|
$result = $this->request_data();
|
||||||
|
$response = $result['response'];
|
||||||
|
if ( ! $result['success'] ) {
|
||||||
|
$message = '';
|
||||||
|
if ( is_array( $this->method ) ) {
|
||||||
|
foreach ( $this->method as $m ) {
|
||||||
|
if ( empty( $response[ $m ]['message'] ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
$message .= ' ' . $m . ' - ' . $response[ $m ]['message'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$message = $response[ $this->method ]['message'];
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $message );
|
||||||
|
} else {
|
||||||
|
$data = array();
|
||||||
|
if ( is_array( $response ) && is_array( $response['VisitsSummary.getVisits'] ) ) {
|
||||||
|
foreach ( $response['VisitsSummary.getVisits'] as $key => $value ) {
|
||||||
|
if ( 'week' === $this->parameter['period'] ) {
|
||||||
|
preg_match( '/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/', $key, $date_list );
|
||||||
|
$js_key = $date_list[0];
|
||||||
|
$text_key = $this->date_format( $js_key, 'week' );
|
||||||
|
} elseif ( 'month' === $this->parameter['period'] ) {
|
||||||
|
$js_key = $key . '-01';
|
||||||
|
$text_key = $key;
|
||||||
|
} else {
|
||||||
|
$js_key = $key;
|
||||||
|
$text_key = $key;
|
||||||
|
}
|
||||||
|
$data[] = array(
|
||||||
|
$text_key,
|
||||||
|
$value,
|
||||||
|
$response['VisitsSummary.getUniqueVisitors'][ $key ] ? $response['VisitsSummary.getUniqueVisitors'][ $key ] : '-',
|
||||||
|
$response['VisitsSummary.getBounceCount'][ $key ] ? $response['VisitsSummary.getBounceCount'][ $key ] : '-',
|
||||||
|
$response['VisitsSummary.getActions'][ $key ] ? $response['VisitsSummary.getActions'][ $key ] : '-',
|
||||||
|
);
|
||||||
|
$java_script[] = 'javascript:wp_piwik_datelink('
|
||||||
|
. wp_json_encode( rawurlencode( 'wp-piwik_stats' ) ) . ','
|
||||||
|
. wp_json_encode( str_replace( '-', '', $js_key ) ) . ','
|
||||||
|
. wp_json_encode( isset( $_GET['wpmu_show_stats'] ) ? (int) $_GET['wpmu_show_stats'] : '' )
|
||||||
|
. ');';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->table(
|
||||||
|
array( __( 'Date', 'wp-piwik' ), __( 'Visits', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Bounced', 'wp-piwik' ), __( 'Page Views', 'wp-piwik' ) ),
|
||||||
|
array_reverse( $data ),
|
||||||
|
array(),
|
||||||
|
'clickable',
|
||||||
|
array_reverse( isset( $java_script ) ? $java_script : array() )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
20
wp-content/plugins/wp-piwik/composer.json
Normal file
20
wp-content/plugins/wp-piwik/composer.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "^1.2",
|
||||||
|
"phpcompatibility/phpcompatibility-wp": "^2.1",
|
||||||
|
"squizlabs/php_codesniffer": "^3.13",
|
||||||
|
"wp-coding-standards/wpcs": "^3.3",
|
||||||
|
"friendsofphp/php-cs-fixer": "^3.94"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"allow-plugins": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": true,
|
||||||
|
"phpstan/extension-installer": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpstan/phpstan": "^2.1",
|
||||||
|
"szepeviktor/phpstan-wordpress": "^2.0",
|
||||||
|
"phpstan/extension-installer": "^1.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
3529
wp-content/plugins/wp-piwik/composer.lock
generated
Normal file
3529
wp-content/plugins/wp-piwik/composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/******************************************************
|
/******************************************************
|
||||||
* Configure WP-Piwik Logger
|
* Configure WP-Piwik Logger
|
||||||
* 0: Logger disabled
|
* 0: Logger disabled
|
||||||
* 1: Log to screen
|
* 1: Log to screen
|
||||||
* 2: Log to file (logs/YYYYMMDD_wp-piwik.log)
|
* 2: Log to file (logs/YYYYMMDD_wp-piwik.log)
|
||||||
|
*
|
||||||
|
* @package WP_Piwik
|
||||||
******************************************************/
|
******************************************************/
|
||||||
define ( 'WP_PIWIK_ACTIVATE_LOGGER', 0 );
|
|
||||||
|
define( 'WP_PIWIK_ACTIVATE_LOGGER', 0 );
|
||||||
|
|||||||
@ -56,19 +56,10 @@ input.wp-piwik-wide {
|
|||||||
width:100%;
|
width:100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.wp-piwik-donate {
|
.wp-matomo-inline-notice {
|
||||||
float:right;
|
padding: 1em;
|
||||||
width:220px;
|
|
||||||
background:#ffc;
|
|
||||||
padding:10px;
|
|
||||||
border:1px solid black;
|
|
||||||
margin: 10px 10px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
div.wp-piwik-donate div {
|
.wp-matomo-inline-notice.wp-matomo-warning {
|
||||||
width:190px;
|
background-color: rgba(255, 165, 0, 0.2);
|
||||||
text-align:center;
|
}
|
||||||
border:solid black;
|
|
||||||
border-width:1px 0 0 0 ;
|
|
||||||
padding:5px
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,2 +1 @@
|
|||||||
<?php
|
<?php
|
||||||
// Nothing to see...
|
|
||||||
|
|||||||
2
wp-content/plugins/wp-piwik/libs/matomo-php-tracker/.gitattributes
vendored
Normal file
2
wp-content/plugins/wp-piwik/libs/matomo-php-tracker/.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
tests/ export-ignore
|
||||||
|
run_tests.sh export-ignore
|
||||||
5
wp-content/plugins/wp-piwik/libs/matomo-php-tracker/.gitignore
vendored
Normal file
5
wp-content/plugins/wp-piwik/libs/matomo-php-tracker/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/.idea/
|
||||||
|
/vendor/
|
||||||
|
.phpunit.result.cache
|
||||||
|
/tests/.phpunit.result.cache
|
||||||
|
composer.lock
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
# Matomo PHP Tracker Changelog
|
||||||
|
|
||||||
|
This is the Developer Changelog for Matomo PHP Tracker. All breaking changes or new features are listed below.
|
||||||
|
|
||||||
|
## Matomo PHP Tracker 3.3.2
|
||||||
|
### Changed
|
||||||
|
- Support for formFactors client hint parameter, supported as of Matomo 5.2.0
|
||||||
|
|
||||||
|
## Matomo PHP Tracker 3.3.1
|
||||||
|
### Fixed
|
||||||
|
- closed curl connection
|
||||||
|
|
||||||
|
## Matomo PHP Tracker 3.3.0
|
||||||
|
### Removed
|
||||||
|
- support for PHP versions lower than 7.2
|
||||||
|
### Changed
|
||||||
|
- all `MatomoTracker` class constants are now explicitly public
|
||||||
|
- all `MatomoTracker` dynamic properties are now explicitly public
|
||||||
|
|
||||||
|
## Matomo PHP Tracker 3.0.0
|
||||||
|
|
||||||
|
Attention: This version of Matomo PHP Tracker is no longer compatible with Matomo 3.x or earlier
|
||||||
|
|
||||||
|
- Support for new page performance metrics (added in Matomo 4) has been added. You can use `setPerformanceTimings()` to set them for page views.
|
||||||
|
- Setting page generation time using `setGenerationTime()` has been discontinued. The method still exists to not break applications still using it, but it does not have any effect. Please use new page performance metrics as replacement.
|
||||||
|
- Sending requests using cURL will now throw an exception if an error occurs in a request.
|
||||||
|
- Matomo does not longer support tracking of these browser plugins: Gears, Director. Therefor the signature of `setPlugins()` changed.
|
||||||
|
- Implementation of ecommerce views changed from custom variables to raw parameters
|
||||||
|
- It is now possible to configure cookie options for Secure, HTTPOnly and SameSite.
|
||||||
|
- Add method setRequestMethodNonBulk() to allow (non bulk) POST requests.
|
||||||
27
wp-content/plugins/wp-piwik/libs/matomo-php-tracker/LICENSE
Normal file
27
wp-content/plugins/wp-piwik/libs/matomo-php-tracker/LICENSE
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
Copyright (c) 2014, Matomo Open Source Analytics
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of the {organization} nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace WP_Piwik {
|
||||||
|
/**
|
||||||
|
* Matomo - free/libre analytics platform
|
||||||
|
*
|
||||||
|
* For more information, see README.md
|
||||||
|
*
|
||||||
|
* @license released under BSD License http://www.opensource.org/licenses/bsd-license.php
|
||||||
|
* @link https://matomo.org/docs/tracking-api/
|
||||||
|
*
|
||||||
|
* @category Matomo
|
||||||
|
* @package MatomoTracker
|
||||||
|
*/
|
||||||
|
if (!\class_exists('\\WP_Piwik\\MatomoTracker')) {
|
||||||
|
include_once 'MatomoTracker.php';
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Helper function to quickly generate the URL to track a page view.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* @param $idSite
|
||||||
|
* @param string $documentTitle
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function Piwik_getUrlTrackPageView($idSite, $documentTitle = '')
|
||||||
|
{
|
||||||
|
return \WP_Piwik\Matomo_getUrlTrackPageView($idSite, $documentTitle);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Helper function to quickly generate the URL to track a goal.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* @param $idSite
|
||||||
|
* @param $idGoal
|
||||||
|
* @param float $revenue
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function Piwik_getUrlTrackGoal($idSite, $idGoal, $revenue = 0.0)
|
||||||
|
{
|
||||||
|
return \WP_Piwik\Matomo_getUrlTrackGoal($idSite, $idGoal, $revenue);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* For BC only
|
||||||
|
*
|
||||||
|
* @deprecated use MatomoTracker instead
|
||||||
|
*/
|
||||||
|
class PiwikTracker extends MatomoTracker
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
# PHP Client for Matomo Analytics Tracking API
|
||||||
|
|
||||||
|
The PHP Tracker Client provides all features of the [Matomo Javascript Tracker](https://developer.matomo.org/api-reference/tracking-javascript), such as Ecommerce Tracking, Custom Variables, Event Tracking and more.
|
||||||
|
|
||||||
|
## Documentation and examples
|
||||||
|
Check out our [Matomo-PHP-Tracker developer documentation](https://developer.matomo.org/api-reference/PHP-Piwik-Tracker) and [Matomo Tracking API guide](https://matomo.org/docs/tracking-api/).
|
||||||
|
|
||||||
|
|
||||||
|
```php
|
||||||
|
// Required variables
|
||||||
|
$matomoSiteId = 6; // Site ID
|
||||||
|
$matomoUrl = "https://example.tld"; // Your matomo URL
|
||||||
|
$matomoToken = ""; // Your authentication token
|
||||||
|
|
||||||
|
// Optional variable
|
||||||
|
$matomoPageTitle = ""; // The title of the page
|
||||||
|
|
||||||
|
// Load object
|
||||||
|
require_once("MatomoTracker.php");
|
||||||
|
|
||||||
|
// Matomo object
|
||||||
|
$matomoTracker = new MatomoTracker((int)$matomoSiteId, $matomoUrl);
|
||||||
|
|
||||||
|
// Set authentication token
|
||||||
|
$matomoTracker->setTokenAuth($matomoToken);
|
||||||
|
|
||||||
|
// Track page view
|
||||||
|
$matomoTracker->doTrackPageView($matomoPageTitle);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Requirements:
|
||||||
|
* JSON extension (json_decode, json_encode)
|
||||||
|
* cURL or stream extension (to issue the HTTPS request to Matomo)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
### Composer
|
||||||
|
|
||||||
|
```
|
||||||
|
composer require matomo/matomo-php-tracker
|
||||||
|
```
|
||||||
|
|
||||||
|
### Manually
|
||||||
|
|
||||||
|
Alternatively, you can download the files and require the Matomo tracker manually:
|
||||||
|
|
||||||
|
```
|
||||||
|
require_once("MatomoTracker.php");
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Released under the [BSD License](https://opensource.org/licenses/BSD-3-Clause)
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"name": "matomo\/matomo-php-tracker",
|
||||||
|
"description": "PHP Client for Matomo Analytics Tracking API",
|
||||||
|
"keywords": [
|
||||||
|
"matomo",
|
||||||
|
"piwik",
|
||||||
|
"tracker",
|
||||||
|
"analytics"
|
||||||
|
],
|
||||||
|
"homepage": "https:\/\/matomo.org",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "The Matomo Team",
|
||||||
|
"email": "hello@matomo.org",
|
||||||
|
"homepage": "https:\/\/matomo.org\/team\/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"forum": "https:\/\/forum.matomo.org\/",
|
||||||
|
"issues": "https:\/\/github.com\/matomo-org\/matomo-php-tracker\/issues",
|
||||||
|
"source": "https:\/\/github.com\/matomo-org\/matomo-php-tracker"
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.2 || ^8.0",
|
||||||
|
"ext-json": "*"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-curl": "Using this extension to issue the HTTPS request to Matomo"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"classmap": [
|
||||||
|
"."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"\\": "tests\/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit\/phpunit": "^8.5 || ^9.3 || ^10.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||||
|
backupGlobals="true"
|
||||||
|
verbose="true">
|
||||||
|
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="UnitTests">
|
||||||
|
<directory>./tests/Unit</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
||||||
108
wp-content/plugins/wp-piwik/misc/track_ai_bot.php
Normal file
108
wp-content/plugins/wp-piwik/misc/track_ai_bot.php
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Matomo - free/libre analytics platform
|
||||||
|
*
|
||||||
|
* @link https://matomo.org
|
||||||
|
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||||
|
* @package matomo
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This script, when included or visited, will send an AI bot tracking
|
||||||
|
* request to Matomo in a shutdown function.
|
||||||
|
*
|
||||||
|
* It will only send this request if the current user agent is for a
|
||||||
|
* known AI bot.
|
||||||
|
*
|
||||||
|
* This script can be added to a user's wp-config.php or be executed
|
||||||
|
* via an HTTP request in an <esi:include> directive. It should have as
|
||||||
|
* few dependencies as possible, and load as few PHP files as possible.
|
||||||
|
*
|
||||||
|
* phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||||
|
*/
|
||||||
|
function wp_piwik_track_if_ai_bot() {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
if (
|
||||||
|
( ! defined( 'WP_CACHE' ) || ! WP_CACHE )
|
||||||
|
&& empty( $_GET['mtm_esi'] )
|
||||||
|
) { // advanced-cache.php not in use and we are not tracking via esi:include
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isset( $_GET['mtm_esi'] ) ) { // executing via esi:include directive
|
||||||
|
$GLOBALS['WP_PIWIK_IN_ESI'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../libs/matomo-php-tracker/MatomoTracker.php';
|
||||||
|
|
||||||
|
// check user agent is AI bot first thing, so if it is a normal request we do
|
||||||
|
// as little extra work as possible
|
||||||
|
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||||
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
|
||||||
|
$user_agent = ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? stripslashes( $_SERVER['HTTP_USER_AGENT'] ) : '';
|
||||||
|
if ( ! \WP_Piwik\MatomoTracker::isUserAgentAIBot( $user_agent ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||||
|
$GLOBALS['wp_plugin_paths'] = array();
|
||||||
|
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
// being called from a esi:include directive
|
||||||
|
define( 'SHORTINIT', true );
|
||||||
|
|
||||||
|
$wp_config_file = dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) . '/wp-config.php';
|
||||||
|
if ( ! is_file( $wp_config_file ) && ! empty( $_SERVER['SCRIPT_FILENAME'] ) ) {
|
||||||
|
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||||
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
|
||||||
|
$script_filename = stripslashes( $_SERVER['SCRIPT_FILENAME'] );
|
||||||
|
$wp_config_file = dirname( dirname( dirname( dirname( dirname( $script_filename ) ) ) ) ) . '/wp-config.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once $wp_config_file;
|
||||||
|
} else {
|
||||||
|
// being called from request that uses advanced-cache.php
|
||||||
|
require_once ABSPATH . WPINC . '/class-wp-list-util.php';
|
||||||
|
require_once ABSPATH . WPINC . '/class-wp-token-map.php';
|
||||||
|
require_once ABSPATH . WPINC . '/formatting.php';
|
||||||
|
require_once ABSPATH . WPINC . '/functions.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once ABSPATH . WPINC . '/link-template.php';
|
||||||
|
require_once ABSPATH . WPINC . '/general-template.php';
|
||||||
|
require_once ABSPATH . WPINC . '/http.php';
|
||||||
|
require_once ABSPATH . WPINC . '/class-wp-http.php';
|
||||||
|
require_once ABSPATH . WPINC . '/class-wp-http-streams.php';
|
||||||
|
require_once ABSPATH . WPINC . '/class-wp-http-curl.php';
|
||||||
|
require_once ABSPATH . WPINC . '/class-wp-http-proxy.php';
|
||||||
|
require_once ABSPATH . WPINC . '/class-wp-http-cookie.php';
|
||||||
|
require_once ABSPATH . WPINC . '/class-wp-http-encoding.php';
|
||||||
|
require_once ABSPATH . WPINC . '/class-wp-http-response.php';
|
||||||
|
require_once ABSPATH . WPINC . '/class-wp-http-requests-response.php';
|
||||||
|
require_once ABSPATH . WPINC . '/class-wp-http-requests-hooks.php';
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../wp-piwik.php';
|
||||||
|
|
||||||
|
if ( empty( $wpdb ) ) {
|
||||||
|
require_wp_db();
|
||||||
|
wp_set_wpdb_vars();
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_start_object_cache();
|
||||||
|
|
||||||
|
if ( ! defined( 'WPMU_PLUGIN_DIR' ) ) {
|
||||||
|
wp_plugin_directory_constants();
|
||||||
|
}
|
||||||
|
|
||||||
|
// url is passed to tracker so we don't want to modify it
|
||||||
|
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||||
|
$url = ! empty( $_REQUEST['mtm_url'] ) ? wp_unslash( $_REQUEST['mtm_url'] ) : null;
|
||||||
|
|
||||||
|
$wp_piwik = new \WP_Piwik();
|
||||||
|
$settings = new \WP_Piwik\Settings( $wp_piwik );
|
||||||
|
$ai_bot_tracking = new \WP_Piwik\AIBotTracking( $settings, \WP_Piwik::get_logger() );
|
||||||
|
$ai_bot_tracking->do_ai_bot_tracking( $url );
|
||||||
|
}
|
||||||
|
|
||||||
|
register_shutdown_function( 'wp_piwik_track_if_ai_bot' );
|
||||||
131
wp-content/plugins/wp-piwik/package-lock.json
generated
Normal file
131
wp-content/plugins/wp-piwik/package-lock.json
generated
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
{
|
||||||
|
"name": "wp-matomo",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"devDependencies": {
|
||||||
|
"@fastify/pre-commit": "^2.2.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@fastify/pre-commit": {
|
||||||
|
"version": "2.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@fastify/pre-commit/-/pre-commit-2.2.1.tgz",
|
||||||
|
"integrity": "sha512-EluAZU4mFnCJfb6RyWFpWvEIAwdchipoiWMSRkQEaQ6ubbf6UVzYuXKSSZJR36SgtgZmKV5oRMxxwMNta5hskg==",
|
||||||
|
"dev": true,
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/fastify"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/fastify"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"cross-spawn": "^7.0.3",
|
||||||
|
"which": "^5.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/cross-spawn": {
|
||||||
|
"version": "7.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||||
|
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"path-key": "^3.1.0",
|
||||||
|
"shebang-command": "^2.0.0",
|
||||||
|
"which": "^2.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/cross-spawn/node_modules/isexe": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
|
"node_modules/cross-spawn/node_modules/which": {
|
||||||
|
"version": "2.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||||
|
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"isexe": "^2.0.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"node-which": "bin/node-which"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/isexe": {
|
||||||
|
"version": "3.1.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/isexe/-/isexe-3.1.5.tgz",
|
||||||
|
"integrity": "sha512-6B3tLtFqtQS4ekarvLVMZ+X+VlvQekbe4taUkf/rhVO3d/h0M2rfARm/pXLcPEsjjMsFgrFgSrhQIxcSVrBz8w==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "BlueOak-1.0.0",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/path-key": {
|
||||||
|
"version": "3.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
|
||||||
|
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/shebang-command": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"shebang-regex": "^3.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/shebang-regex": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/which": {
|
||||||
|
"version": "5.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/which/-/which-5.0.0.tgz",
|
||||||
|
"integrity": "sha512-JEdGzHwwkrbWoGOlIHqQ5gtprKGOenpDHpxE9zVR1bWbOtYRyPPHMe9FaP6x61CmNaTThSkb0DAJte5jD+DmzQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"isexe": "^3.1.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"node-which": "bin/which.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^18.17.0 || >=20.5.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
wp-content/plugins/wp-piwik/package.json
Normal file
12
wp-content/plugins/wp-piwik/package.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"phpcs": "./vendor/bin/phpcs",
|
||||||
|
"phpcbf": "./vendor/bin/phpcbf"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@fastify/pre-commit": "^2.2.1"
|
||||||
|
},
|
||||||
|
"pre-commit": [
|
||||||
|
"phpcs"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
$wpRootDir = isset($wpRootDir)?$wpRootDir:'../../../../';
|
// Get the install directory of WP.
|
||||||
|
// Usefull for immutable WP install, like : https://github.com/zorglube/clever-wordpress OR https://github.com/CleverCloud/wordpress-bedrock-example where WP core and Plugins are in separate directories
|
||||||
|
$wpRootDir = getenv('WP_MATOMO_WP_ROOT_DIR');
|
||||||
|
$wpRootDir = !empty($wpRootDir)?$wpRootDir:'../../../../';
|
||||||
require ($wpRootDir.'wp-load.php');
|
require ($wpRootDir.'wp-load.php');
|
||||||
|
|
||||||
require_once ('../classes/WP_Piwik/Settings.php');
|
require_once ('../classes/WP_Piwik/Settings.php');
|
||||||
@ -11,29 +14,31 @@ $settings = new WP_Piwik\Settings ( $logger );
|
|||||||
|
|
||||||
$protocol = (isset ( $_SERVER ['HTTPS'] ) && $_SERVER ['HTTPS'] != 'off') ? 'https' : 'http';
|
$protocol = (isset ( $_SERVER ['HTTPS'] ) && $_SERVER ['HTTPS'] != 'off') ? 'https' : 'http';
|
||||||
|
|
||||||
switch ($settings->getGlobalOption ( 'piwik_mode' )) {
|
switch ($settings->get_global_option ( 'piwik_mode' )) {
|
||||||
case 'php' :
|
case 'php' :
|
||||||
$PIWIK_URL = $settings->getGlobalOption ( 'proxy_url' );
|
$PIWIK_URL = $settings->get_global_option ( 'proxy_url' );
|
||||||
break;
|
break;
|
||||||
case 'cloud' :
|
case 'cloud' :
|
||||||
$PIWIK_URL = 'https://' . $settings->getGlobalOption ( 'piwik_user' ) . '.innocraft.cloud/';
|
$PIWIK_URL = 'https://' . $settings->get_global_option ( 'piwik_user' ) . '.innocraft.cloud/';
|
||||||
break;
|
break;
|
||||||
case 'cloud-matomo' :
|
case 'cloud-matomo' :
|
||||||
$PIWIK_URL = 'https://' . $settings->getGlobalOption ( 'matomo_user' ) . '.matomo.cloud/';
|
$PIWIK_URL = 'https://' . $settings->get_global_option ( 'matomo_user' ) . '.matomo.cloud/';
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
$PIWIK_URL = $settings->getGlobalOption ( 'piwik_url' );
|
$PIWIK_URL = $settings->get_global_option ( 'piwik_url' );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (substr ( $PIWIK_URL, 0, 2 ) == '//')
|
if ( substr ( $PIWIK_URL, 0, 2 ) == '//' ) {
|
||||||
$PIWIK_URL = $protocol . ':' . $PIWIK_URL;
|
$PIWIK_URL = $protocol . ':' . $PIWIK_URL;
|
||||||
|
}
|
||||||
|
|
||||||
$TOKEN_AUTH = $settings->getGlobalOption ( 'piwik_token' );
|
$TOKEN_AUTH = $settings->get_global_option ( 'piwik_token' );
|
||||||
$timeout = $settings->getGlobalOption ( 'connection_timeout' );
|
$timeout = $settings->get_global_option ( 'connection_timeout' );
|
||||||
$useCurl = (
|
$useCurl = (
|
||||||
(function_exists('curl_init') && ini_get('allow_url_fopen') && $settings->getGlobalOption('http_connection') == 'curl') || (function_exists('curl_init') && !ini_get('allow_url_fopen'))
|
(function_exists('curl_init') && ini_get('allow_url_fopen') && $settings->get_global_option('http_connection') == 'curl') || (function_exists('curl_init') && !ini_get('allow_url_fopen'))
|
||||||
);
|
);
|
||||||
|
|
||||||
$settings->getGlobalOption ( 'http_connection' );
|
$settings->get_global_option ( 'http_connection' );
|
||||||
|
|
||||||
ini_set ( 'display_errors', 0 );
|
ini_set ( 'display_errors', 0 );
|
||||||
|
|||||||
@ -126,6 +126,10 @@ if (strpos($path, 'piwik.php') === 0 || strpos($path, 'matomo.php') === 0) {
|
|||||||
'cip' => getVisitIp(),
|
'cip' => getVisitIp(),
|
||||||
'token_auth' => $TOKEN_AUTH,
|
'token_auth' => $TOKEN_AUTH,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!isset($_GET['token_auth']) && !isset($_POST['token_auth'])) {
|
||||||
|
sanitizeTrackingOverrideParams($_GET);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$url = $MATOMO_URL . $path;
|
$url = $MATOMO_URL . $path;
|
||||||
@ -293,8 +297,14 @@ function getHttpContentAndStatus($url, $timeout, $user_agent)
|
|||||||
// if there's POST data, send our proxy request as a POST
|
// if there's POST data, send our proxy request as a POST
|
||||||
if (!empty($_POST)) {
|
if (!empty($_POST)) {
|
||||||
$postBody = file_get_contents("php://input");
|
$postBody = file_get_contents("php://input");
|
||||||
|
if (!isset($_GET['token_auth']) && !isset($_POST['token_auth'])) {
|
||||||
|
$didSanitizePostParams = sanitizeTrackingOverrideParams($_POST);
|
||||||
|
if ($didSanitizePostParams) {
|
||||||
|
$postBody = http_build_query($_POST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$stream_options['http']['method'] = 'POST';
|
$stream_options['http']['method'] = 'POST';
|
||||||
$stream_options['http']['header'][] = "Content-type: application/x-www-form-urlencoded";
|
$stream_options['http']['header'][] = "Content-type: application/x-www-form-urlencoded";
|
||||||
$stream_options['http']['header'][] = "Content-Length: " . strlen($postBody);
|
$stream_options['http']['header'][] = "Content-Length: " . strlen($postBody);
|
||||||
$stream_options['http']['content'] = $postBody;
|
$stream_options['http']['content'] = $postBody;
|
||||||
@ -365,6 +375,20 @@ function getHttpContentAndStatus($url, $timeout, $user_agent)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sanitizeTrackingOverrideParams(&$params)
|
||||||
|
{
|
||||||
|
$didSanitizeParams = false;
|
||||||
|
$queryParamsToUnset = ['cdt', 'country', 'region', 'city', 'lat', 'long', 'cip'];
|
||||||
|
foreach ($queryParamsToUnset as $queryParamToUnset) {
|
||||||
|
if (isset($params[$queryParamToUnset])) {
|
||||||
|
unset($params[$queryParamToUnset]);
|
||||||
|
$didSanitizeParams = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $didSanitizeParams;
|
||||||
|
}
|
||||||
|
|
||||||
function sendHeader($header, $replace = true)
|
function sendHeader($header, $replace = true)
|
||||||
{
|
{
|
||||||
headers_sent() || header($header, $replace);
|
headers_sent() || header($header, $replace);
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
=== Connect Matomo (WP-Matomo, WP-Piwik) ===
|
=== Connect Matomo - Analytics Dashboard for WordPress ===
|
||||||
|
|
||||||
Contributors: Braekling
|
Contributors: Braekling
|
||||||
Requires at least: 5.0
|
Requires at least: 5.0
|
||||||
Tested up to: 6.3
|
Tested up to: 6.9.4
|
||||||
Stable tag: 1.0.30
|
Stable tag: 1.1.5
|
||||||
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
|
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
|
||||||
Tags: matomo, tracking, statistics, stats, analytics
|
Tags: matomo, tracking, statistics, stats, analytics
|
||||||
|
|
||||||
@ -11,14 +11,16 @@ Adds Matomo (former Piwik) statistics to your WordPress dashboard and is also ab
|
|||||||
|
|
||||||
== Description ==
|
== 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/).
|
**Version 1.1.4 includes several important security related fixes, it is highly recommended to update to this version.**
|
||||||
|
|
||||||
|
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.
|
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).
|
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).
|
||||||
|
|
||||||
**Requirements:** PHP 7.0 (or higher), WordPress 5.0 (or higher), Matomo 4.0 (or higher)
|
**Requirements:** PHP 7.0 (or higher), WordPress 5.0 (or higher), Matomo 4.0 (or higher)
|
||||||
|
|
||||||
**Languages:** English, Albanian, Chinese, Dutch, French, German, Greek, Hungarian, Italian, Polish, Portuguese (Brazil). Partially supported: Azerbaijani, Belarusian, Hindi, Lithuanian, Luxembourgish, Norwegian, Persian, Romanian, Russian, Spanish, Swedish, Turkish, Ukrainian
|
**Languages:** English, Albanian, Chinese, Dutch, French, German, Greek, Hungarian, Italian, Polish, Portuguese (Brazil). Partially supported: Azerbaijani, Belarusian, Hindi, Lithuanian, Luxembourgish, Norwegian, Persian, Romanian, Russian, Spanish, Swedish, Turkish, Ukrainian
|
||||||
|
|
||||||
= What is Matomo? =
|
= What is Matomo? =
|
||||||
@ -122,7 +124,7 @@ Thank you very much! :-)
|
|||||||
|
|
||||||
There are two differents methods to use WP-Matomo in a multisite environment:
|
There are two differents methods to use WP-Matomo in a multisite environment:
|
||||||
|
|
||||||
* As a Site Specific Plugin it behaves like a plugin installed on a simple WordPress blog. Each user can enable, configure and use WP-Matomo on his own. Users can even use their own Matomo instances (and accordingly they have to).
|
* As a Site Specific Plugin it behaves like a plugin installed on a simple WordPress blog. Each user can enable, configure and use WP-Matomo on his own. Users can even use their own Matomo instances (and accordingly they have to).
|
||||||
* Using WP-Matomo as a Network Plugin equates to a central approach. A single Matomo instance is used and the site admin configures the plugin completely. Users are just allowed to see their own statistics, site admins can see each blog's stats.
|
* Using WP-Matomo as a Network Plugin equates to a central approach. A single Matomo instance is used and the site admin configures the plugin completely. Users are just allowed to see their own statistics, site admins can see each blog's stats.
|
||||||
|
|
||||||
*Site Specific Plugin*
|
*Site Specific Plugin*
|
||||||
@ -145,6 +147,33 @@ Add WP-Matomo to your /wp-content/plugins folder and enable it as [Network Plugi
|
|||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
= 1.1.5 =
|
||||||
|
* Update Matomo logo and screenshots.
|
||||||
|
* Update tracker proxy code with latest changes.
|
||||||
|
* Ensure query strings are correctly created when arg_separator.input is not '&'.
|
||||||
|
|
||||||
|
= 1.1.4 =
|
||||||
|
* Bug fix: fix URL to settings displayed upon installation.
|
||||||
|
* Remove donation form.
|
||||||
|
* Several assorted security related fixes.
|
||||||
|
|
||||||
|
= 1.1.3 =
|
||||||
|
* Replaced wp_unslash with stripslashes to address cases where wp_unslash may be undefined.
|
||||||
|
|
||||||
|
= 1.1.2 =
|
||||||
|
* Allow $wpRootDir variable in the proxy config.php file to be defined by the WP_MATOMO_WP_ROOT_DIR environment variable if present.
|
||||||
|
* Using phpcs and phpstan fix several issues including several vulnerabilities.
|
||||||
|
|
||||||
|
= 1.1.1 =
|
||||||
|
* Security bug fix: convert custom variable name and values to JSON before using in tracking code.
|
||||||
|
|
||||||
|
= 1.1.0 =
|
||||||
|
* Support for tracking AI bots to Matomo.
|
||||||
|
|
||||||
|
= 1.0.31 =
|
||||||
|
* Do not display value of persisted Matomo token in settings page.
|
||||||
|
* Fix notice when persisted notifications value is for some reason not an array.
|
||||||
|
|
||||||
= 1.0.30 =
|
= 1.0.30 =
|
||||||
* Fix settings behavior
|
* Fix settings behavior
|
||||||
* Fix auto configuration in PHP API mode
|
* Fix auto configuration in PHP API mode
|
||||||
@ -168,7 +197,7 @@ Add WP-Matomo to your /wp-content/plugins folder and enable it as [Network Plugi
|
|||||||
* Fix JavaScript typos on settings page which broke some interface functionality
|
* Fix JavaScript typos on settings page which broke some interface functionality
|
||||||
* Fix proxy path on multisite networks (thanks to caveman99, [details](https://github.com/braekling/WP-Matomo/pull/98))
|
* Fix proxy path on multisite networks (thanks to caveman99, [details](https://github.com/braekling/WP-Matomo/pull/98))
|
||||||
* Fix array key warnings (thanks to goaround, [details](https://github.com/braekling/WP-Matomo/pull/102))
|
* Fix array key warnings (thanks to goaround, [details](https://github.com/braekling/WP-Matomo/pull/102))
|
||||||
* Fixed a bug in proxy config.php to avoid adding the protocol twice to the Matomo URL
|
* Fixed a bug in proxy config.php to avoid adding the protocol twice to the Matomo URL
|
||||||
* Proxy script will run proxy/config.local.php before proxy/config.php to set an individual WordPress root directory via $wpRootDir
|
* Proxy script will run proxy/config.local.php before proxy/config.php to set an individual WordPress root directory via $wpRootDir
|
||||||
|
|
||||||
= 1.0.26 =
|
= 1.0.26 =
|
||||||
@ -358,7 +387,7 @@ Add WP-Matomo to your /wp-content/plugins folder and enable it as [Network Plugi
|
|||||||
* Bugfix: Keep sure the revision ID is stored and avoid re-installing the plugin again and again
|
* Bugfix: Keep sure the revision ID is stored and avoid re-installing the plugin again and again
|
||||||
* Bugfix: http/pro - after configuration the settings page had to be reloaded once to start working
|
* Bugfix: http/pro - after configuration the settings page had to be reloaded once to start working
|
||||||
* Typo fixes
|
* Typo fixes
|
||||||
|
|
||||||
= 0.10.0.6 =
|
= 0.10.0.6 =
|
||||||
* Bugfix: Option storage bug if WP-Matomo is used as single site plugin on blog networks
|
* Bugfix: Option storage bug if WP-Matomo is used as single site plugin on blog networks
|
||||||
* Bugfix: WP-Matomo will work without Matomo superuser access, again
|
* Bugfix: WP-Matomo will work without Matomo superuser access, again
|
||||||
@ -413,7 +442,7 @@ Add WP-Matomo to your /wp-content/plugins folder and enable it as [Network Plugi
|
|||||||
* Improvement: Only activate/ load admin components if an admin page is actually loaded. Thanks to Michael!
|
* Improvement: Only activate/ load admin components if an admin page is actually loaded. Thanks to Michael!
|
||||||
* Bugfix: Proxy tracking will work again. Matomo 2.7 or higher is recommended.
|
* Bugfix: Proxy tracking will work again. Matomo 2.7 or higher is recommended.
|
||||||
* Bugfix: Avoid a PHP notice in dashboard
|
* Bugfix: Avoid a PHP notice in dashboard
|
||||||
* NOTE: If you update Matomo and use the "add tracking code" feature, please also update your WP-Matomo tracking code: Just open the WP-Matomo tracking code settings and save them again.
|
* NOTE: If you update Matomo and use the "add tracking code" feature, please also update your WP-Matomo tracking code: Just open the WP-Matomo tracking code settings and save them again.
|
||||||
|
|
||||||
= 0.9.9.12 =
|
= 0.9.9.12 =
|
||||||
* Bugfix: Avoid forced relogin on site change (WP network)
|
* Bugfix: Avoid forced relogin on site change (WP network)
|
||||||
@ -470,7 +499,7 @@ Add WP-Matomo to your /wp-content/plugins folder and enable it as [Network Plugi
|
|||||||
* Use Transients API (one week caching)
|
* Use Transients API (one week caching)
|
||||||
* Option: Track visitors without JavaScript, see http://piwik.org/faq/how-to/#faq_176
|
* Option: Track visitors without JavaScript, see http://piwik.org/faq/how-to/#faq_176
|
||||||
|
|
||||||
= 0.9.9.3 =
|
= 0.9.9.3 =
|
||||||
* Sparkline script update (IE 10 compatibility)
|
* Sparkline script update (IE 10 compatibility)
|
||||||
* Syntax error fixes
|
* Syntax error fixes
|
||||||
|
|
||||||
@ -486,7 +515,7 @@ Add WP-Matomo to your /wp-content/plugins folder and enable it as [Network Plugi
|
|||||||
* Made <noscript> code optional. Move <noscript> code to site footer.
|
* Made <noscript> code optional. Move <noscript> code to site footer.
|
||||||
|
|
||||||
= 0.9.9.0 =
|
= 0.9.9.0 =
|
||||||
* Matomo 1.11 compatibility fixes (Matomo 1.11 required now!)
|
* Matomo 1.11 compatibility fixes (Matomo 1.11 required now!)
|
||||||
* Depending on Matomo 1.11 WP-Matomo will use async tracking now
|
* Depending on Matomo 1.11 WP-Matomo will use async tracking now
|
||||||
* CDN support added, see http://wordpress.org/support/topic/request-cdn-support-1
|
* CDN support added, see http://wordpress.org/support/topic/request-cdn-support-1
|
||||||
|
|
||||||
@ -538,7 +567,7 @@ Add WP-Matomo to your /wp-content/plugins folder and enable it as [Network Plugi
|
|||||||
= 0.9.5 =
|
= 0.9.5 =
|
||||||
* WordPress 3.4 compatible (workaround)
|
* WordPress 3.4 compatible (workaround)
|
||||||
|
|
||||||
= 0.9.4 =
|
= 0.9.4 =
|
||||||
* Requires at least Matomo 1.8.2!
|
* Requires at least Matomo 1.8.2!
|
||||||
* Choose between HTTP API or PHP API
|
* Choose between HTTP API or PHP API
|
||||||
* Show graph on WordPress Toolbar
|
* Show graph on WordPress Toolbar
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB |
@ -1,108 +1,129 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Uninstall script.
|
||||||
|
*
|
||||||
|
* @package wp-piwik
|
||||||
|
*/
|
||||||
|
|
||||||
// Check if uninstall call is valid
|
// Check if uninstall call is valid
|
||||||
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
|
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
$globalSettings = array(
|
|
||||||
'revision',
|
|
||||||
'last_settings_update',
|
|
||||||
'piwik_mode',
|
|
||||||
'piwik_url',
|
|
||||||
'piwik_path',
|
|
||||||
'piwik_user',
|
|
||||||
'matomo_user',
|
|
||||||
'piwik_token',
|
|
||||||
'auto_site_config',
|
|
||||||
'default_date',
|
|
||||||
'stats_seo',
|
|
||||||
'dashboard_widget',
|
|
||||||
'dashboard_chart',
|
|
||||||
'dashboard_seo',
|
|
||||||
'toolbar',
|
|
||||||
'capability_read_stats',
|
|
||||||
'perpost_stats',
|
|
||||||
'plugin_display_name',
|
|
||||||
'piwik_shortcut',
|
|
||||||
'shortcodes',
|
|
||||||
'track_mode',
|
|
||||||
'track_codeposition',
|
|
||||||
'track_noscript',
|
|
||||||
'track_nojavascript',
|
|
||||||
'proxy_url',
|
|
||||||
'track_content',
|
|
||||||
'track_search',
|
|
||||||
'track_404',
|
|
||||||
'add_post_annotations',
|
|
||||||
'add_customvars_box',
|
|
||||||
'add_download_extensions',
|
|
||||||
'disable_cookies',
|
|
||||||
'limit_cookies',
|
|
||||||
'limit_cookies_visitor',
|
|
||||||
'limit_cookies_session',
|
|
||||||
'limit_cookies_referral',
|
|
||||||
'track_admin',
|
|
||||||
'capability_stealth',
|
|
||||||
'track_across',
|
|
||||||
'track_across_alias',
|
|
||||||
'track_crossdomain_linking',
|
|
||||||
'track_feed',
|
|
||||||
'track_feed_addcampaign',
|
|
||||||
'track_feed_campaign',
|
|
||||||
'cache',
|
|
||||||
'disable_timelimit',
|
|
||||||
'connection_timeout',
|
|
||||||
'disable_ssl_verify',
|
|
||||||
'disable_ssl_verify_host',
|
|
||||||
'piwik_useragent',
|
|
||||||
'piwik_useragent_string',
|
|
||||||
'track_datacfasync',
|
|
||||||
'track_cdnurl',
|
|
||||||
'track_cdnurlssl',
|
|
||||||
'force_protocol'
|
|
||||||
);
|
|
||||||
|
|
||||||
$settings = array (
|
|
||||||
'name',
|
|
||||||
'site_id',
|
|
||||||
'noscript_code',
|
|
||||||
'tracking_code',
|
|
||||||
'last_tracking_code_update',
|
|
||||||
'dashboard_revision'
|
|
||||||
);
|
|
||||||
|
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
if (function_exists('is_multisite') && is_multisite()) {
|
|
||||||
if ($limit && $page)
|
|
||||||
$queryLimit = 'LIMIT '.(int) (($page - 1) * $limit).','.(int) $limit.' ';
|
|
||||||
$aryBlogs = $wpdb->get_results('SELECT blog_id FROM '.$wpdb->blogs.' '.$queryLimit.'ORDER BY blog_id', ARRAY_A);
|
|
||||||
if (is_array($aryBlogs))
|
|
||||||
foreach ($aryBlogs as $aryBlog) {
|
|
||||||
foreach ($settings as $key) {
|
|
||||||
delete_blog_option($aryBlog['blog_id'], 'wp-piwik-'.$key);
|
|
||||||
}
|
|
||||||
switch_to_blog($aryBlog['blog_id']);
|
|
||||||
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key LIKE 'wp-piwik_%'");
|
|
||||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wp-piwik_%'");
|
|
||||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_wp-piwik_%'");
|
|
||||||
restore_current_blog();
|
|
||||||
}
|
|
||||||
foreach ($globalSettings as $key)
|
|
||||||
delete_site_option('wp-piwik_global-'.$key);
|
|
||||||
delete_site_option('wp-piwik-manually');
|
|
||||||
delete_site_option('wp-piwik-notices');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($settings as $key)
|
/**
|
||||||
delete_option('wp-piwik-'.$key);
|
* @return void
|
||||||
|
* @phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
|
||||||
foreach ($globalSettings as $key)
|
* @phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
delete_option('wp-piwik_global-'.$key);
|
*/
|
||||||
|
function wp_matomo_uninstall() {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
delete_option('wp-piwik-manually');
|
$global_settings = array(
|
||||||
delete_option('wp-piwik-notices');
|
'revision',
|
||||||
|
'last_settings_update',
|
||||||
|
'piwik_mode',
|
||||||
|
'piwik_url',
|
||||||
|
'piwik_path',
|
||||||
|
'piwik_user',
|
||||||
|
'matomo_user',
|
||||||
|
'piwik_token',
|
||||||
|
'auto_site_config',
|
||||||
|
'default_date',
|
||||||
|
'stats_seo',
|
||||||
|
'dashboard_widget',
|
||||||
|
'dashboard_chart',
|
||||||
|
'dashboard_seo',
|
||||||
|
'toolbar',
|
||||||
|
'capability_read_stats',
|
||||||
|
'perpost_stats',
|
||||||
|
'plugin_display_name',
|
||||||
|
'piwik_shortcut',
|
||||||
|
'shortcodes',
|
||||||
|
'track_mode',
|
||||||
|
'track_codeposition',
|
||||||
|
'track_noscript',
|
||||||
|
'track_nojavascript',
|
||||||
|
'proxy_url',
|
||||||
|
'track_content',
|
||||||
|
'track_search',
|
||||||
|
'track_404',
|
||||||
|
'add_post_annotations',
|
||||||
|
'add_customvars_box',
|
||||||
|
'add_download_extensions',
|
||||||
|
'disable_cookies',
|
||||||
|
'limit_cookies',
|
||||||
|
'limit_cookies_visitor',
|
||||||
|
'limit_cookies_session',
|
||||||
|
'limit_cookies_referral',
|
||||||
|
'track_admin',
|
||||||
|
'capability_stealth',
|
||||||
|
'track_across',
|
||||||
|
'track_across_alias',
|
||||||
|
'track_crossdomain_linking',
|
||||||
|
'track_feed',
|
||||||
|
'track_feed_addcampaign',
|
||||||
|
'track_feed_campaign',
|
||||||
|
'cache',
|
||||||
|
'disable_timelimit',
|
||||||
|
'connection_timeout',
|
||||||
|
'disable_ssl_verify',
|
||||||
|
'disable_ssl_verify_host',
|
||||||
|
'piwik_useragent',
|
||||||
|
'piwik_useragent_string',
|
||||||
|
'track_datacfasync',
|
||||||
|
'track_cdnurl',
|
||||||
|
'track_cdnurlssl',
|
||||||
|
'force_protocol',
|
||||||
|
);
|
||||||
|
|
||||||
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key LIKE 'wp-piwik-%'");
|
$settings = array(
|
||||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wp-piwik_%'");
|
'name',
|
||||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_wp-piwik_%'");
|
'site_id',
|
||||||
|
'noscript_code',
|
||||||
|
'tracking_code',
|
||||||
|
'last_tracking_code_update',
|
||||||
|
'dashboard_revision',
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
|
||||||
|
if ( isset( $limit ) && isset( $page ) ) {
|
||||||
|
$query_limit = 'LIMIT ' . (int) ( ( $page - 1 ) * $limit ) . ',' . (int) $limit . ' ';
|
||||||
|
}
|
||||||
|
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||||
|
$ary_blogs = $wpdb->get_results( $wpdb->prepare( 'SELECT blog_id FROM %s ' . $query_limit . 'ORDER BY blog_id', $wpdb->blogs ), ARRAY_A );
|
||||||
|
if ( is_array( $ary_blogs ) ) {
|
||||||
|
foreach ( $ary_blogs as $ary_blog ) {
|
||||||
|
foreach ( $settings as $key ) {
|
||||||
|
delete_blog_option( $ary_blog['blog_id'], 'wp-piwik-' . $key );
|
||||||
|
}
|
||||||
|
switch_to_blog( $ary_blog['blog_id'] );
|
||||||
|
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE 'wp-piwik_%'" );
|
||||||
|
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wp-piwik_%'" );
|
||||||
|
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_wp-piwik_%'" );
|
||||||
|
restore_current_blog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ( $global_settings as $key ) {
|
||||||
|
delete_site_option( 'wp-piwik_global-' . $key );
|
||||||
|
}
|
||||||
|
delete_site_option( 'wp-piwik-manually' );
|
||||||
|
delete_site_option( 'wp-piwik-notices' );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $settings as $key ) {
|
||||||
|
delete_option( 'wp-piwik-' . $key );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $global_settings as $key ) {
|
||||||
|
delete_option( 'wp-piwik_global-' . $key );
|
||||||
|
}
|
||||||
|
|
||||||
|
delete_option( 'wp-piwik-manually' );
|
||||||
|
delete_option( 'wp-piwik-notices' );
|
||||||
|
|
||||||
|
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE 'wp-piwik-%'" );
|
||||||
|
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wp-piwik_%'" );
|
||||||
|
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_wp-piwik_%'" );
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_matomo_uninstall();
|
||||||
|
|||||||
@ -1,41 +1,55 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
// Get & delete old version's options
|
* @package wp-piwik
|
||||||
if (self::$settings->checkNetworkActivation ()) {
|
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||||
$oldGlobalOptions = get_site_option ( 'wp-piwik_global-settings', array () );
|
*/
|
||||||
delete_site_option('wp-piwik_global-settings');
|
|
||||||
} else {
|
// Get & delete old version's options
|
||||||
$oldGlobalOptions = get_option ( 'wp-piwik_global-settings', array () );
|
if ( self::$settings->check_network_activation() ) {
|
||||||
delete_option('wp-piwik_global-settings');
|
$old_global_options = get_site_option( 'wp-piwik_global-settings', array() );
|
||||||
}
|
delete_site_option( 'wp-piwik_global-settings' );
|
||||||
|
} else {
|
||||||
$oldOptions = get_option ( 'wp-piwik_settings', array () );
|
$old_global_options = get_option( 'wp-piwik_global-settings', array() );
|
||||||
delete_option('wp-piwik_settings');
|
delete_option( 'wp-piwik_global-settings' );
|
||||||
|
}
|
||||||
if (self::$settings->checkNetworkActivation ()) {
|
|
||||||
global $wpdb;
|
$old_options = get_option( 'wp-piwik_settings', array() );
|
||||||
$aryBlogs = \WP_Piwik\Settings::getBlogList();
|
delete_option( 'wp-piwik_settings' );
|
||||||
if (is_array($aryBlogs))
|
|
||||||
foreach ($aryBlogs as $aryBlog) {
|
if ( self::$settings->check_network_activation() ) {
|
||||||
$oldOptions = get_blog_option ( $aryBlog['blog_id'], 'wp-piwik_settings', array () );
|
global $wpdb;
|
||||||
if (!$this->isConfigured())
|
$ary_blogs = \WP_Piwik\Settings::get_blog_list();
|
||||||
foreach ( $oldOptions as $key => $value )
|
if ( is_array( $ary_blogs ) ) {
|
||||||
self::$settings->setOption ( $key, $value, $aryBlog['blog_id'] );
|
foreach ( $ary_blogs as $ary_blog ) {
|
||||||
delete_blog_option($aryBlog['blog_id'], 'wp-piwik_settings');
|
$old_options = get_blog_option( $ary_blog['blog_id'], 'wp-piwik_settings', array() );
|
||||||
}
|
if ( ! $this->is_configured() ) {
|
||||||
}
|
foreach ( $old_options as $key => $value ) {
|
||||||
|
self::$settings->set_option( $key, $value, $ary_blog['blog_id'] );
|
||||||
if (!$this->isConfigured()) {
|
}
|
||||||
if (!$oldGlobalOptions['add_tracking_code']) $oldGlobalOptions['track_mode'] = 'disabled';
|
}
|
||||||
elseif (!$oldGlobalOptions['track_mode']) $oldGlobalOptions['track_mode'] = 'default';
|
delete_blog_option( $ary_blog['blog_id'], 'wp-piwik_settings' );
|
||||||
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 )
|
if ( ! $this->is_configured() ) {
|
||||||
self::$settings->setGlobalOption ( $key, $value );
|
if ( ! $old_global_options['add_tracking_code'] ) {
|
||||||
foreach ( $oldOptions as $key => $value )
|
$old_global_options['track_mode'] = 'disabled';
|
||||||
self::$settings->setOption ( $key, $value );
|
} elseif ( ! $old_global_options['track_mode'] ) {
|
||||||
}
|
$old_global_options['track_mode'] = 'default';
|
||||||
|
} elseif ( 1 === (int) $old_global_options['track_mode'] ) {
|
||||||
self::$settings->save ();
|
$old_global_options['track_mode'] = 'js';
|
||||||
|
} elseif ( 2 === (int) $old_global_options['track_mode'] ) {
|
||||||
|
$old_global_options['track_mode'] = 'proxy';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store old values in new settings
|
||||||
|
foreach ( $old_global_options as $key => $value ) {
|
||||||
|
self::$settings->set_global_option( $key, $value );
|
||||||
|
}
|
||||||
|
foreach ( $old_options as $key => $value ) {
|
||||||
|
self::$settings->set_option( $key, $value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$settings->save();
|
||||||
|
|||||||
@ -1,13 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* @package wp-piwik
|
||||||
|
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||||
|
*/
|
||||||
|
|
||||||
// Re-write Piwik Pro configuration to default http configuration
|
// Re-write Piwik Pro configuration to default http configuration
|
||||||
if ($this->isConfigured() && self::$settings->getGlobalOption ( 'piwik_mode' ) == 'pro') {
|
if ( $this->is_configured() && 'pro' === self::$settings->get_global_option( 'piwik_mode' ) ) {
|
||||||
self::$settings->setGlobalOption ( 'piwik_url', 'https://' . self::$settings->getGlobalOption ( 'piwik_user' ) . '.piwik.pro/');
|
self::$settings->set_global_option( 'piwik_url', 'https://' . self::$settings->get_global_option( 'piwik_user' ) . '.piwik.pro/' );
|
||||||
self::$settings->setGlobalOption ( 'piwik_mode', 'http' );
|
self::$settings->set_global_option( 'piwik_mode', 'http' );
|
||||||
}
|
}
|
||||||
|
|
||||||
// If post annotations are already enabled, choose all existing post types
|
// If post annotations are already enabled, choose all existing post types
|
||||||
if (self::$settings->getGlobalOption('add_post_annotations'))
|
if ( self::$settings->get_global_option( 'add_post_annotations' ) ) {
|
||||||
self::$settings->setGlobalOption('add_post_annotations', get_post_types());
|
self::$settings->set_global_option( 'add_post_annotations', get_post_types() );
|
||||||
|
}
|
||||||
|
|
||||||
self::$settings->save ();
|
self::$settings->save();
|
||||||
|
|||||||
@ -1,10 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* @package wp-piwik
|
||||||
|
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||||
|
*/
|
||||||
|
|
||||||
// Set range for per post stats
|
// Set range for per post stats
|
||||||
if (self::$settings->getGlobalOption('perpost_stats')) {
|
if ( self::$settings->get_global_option( 'perpost_stats' ) ) {
|
||||||
self::$settings->setGlobalOption('perpost_stats', "last30");
|
self::$settings->set_global_option( 'perpost_stats', 'last30' );
|
||||||
} else {
|
} else {
|
||||||
self::$settings->setGlobalOption('perpost_stats', "disabled");
|
self::$settings->set_global_option( 'perpost_stats', 'disabled' );
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$settings->save ();
|
self::$settings->save();
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* @package wp-piwik
|
||||||
|
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||||
|
*/
|
||||||
|
|
||||||
self::$settings->setGlobalOption('plugin_display_name', "Connect Matomo");
|
self::$settings->set_global_option( 'plugin_display_name', 'Connect Matomo' );
|
||||||
self::$settings->save ();
|
self::$settings->save();
|
||||||
|
|||||||
@ -1,9 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
$aryWPMUConfig = get_site_option ( 'wpmu-piwik_global-settings', false );
|
/**
|
||||||
if (self::$settings->checkNetworkActivation () && $aryWPMUConfig) {
|
* @package wp-piwik
|
||||||
foreach ( $aryWPMUConfig as $key => $value )
|
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||||
self::$settings->setGlobalOption ( $key, $value );
|
*/
|
||||||
delete_site_option ( 'wpmu-piwik_global-settings' );
|
|
||||||
self::$settings->setGlobalOption ( 'auto_site_config', true );
|
$ary_wpmu_config = get_site_option( 'wpmu-piwik_global-settings', false );
|
||||||
} else
|
if ( self::$settings->check_network_activation() && $ary_wpmu_config ) {
|
||||||
self::$settings->setGlobalOption ( 'auto_site_config', false );
|
foreach ( $ary_wpmu_config as $key => $value ) {
|
||||||
|
self::$settings->set_global_option( $key, $value );
|
||||||
|
}
|
||||||
|
delete_site_option( 'wpmu-piwik_global-settings' );
|
||||||
|
self::$settings->set_global_option( 'auto_site_config', true );
|
||||||
|
} else {
|
||||||
|
self::$settings->set_global_option( 'auto_site_config', false );
|
||||||
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
if (self::$settings->getGlobalOption ( 'track_compress' ))
|
if ( self::$settings->get_global_option( 'track_compress' ) ) {
|
||||||
self::$settings->setGlobalOption ( 'track_mode', 1 );
|
self::$settings->set_global_option( 'track_mode', 1 );
|
||||||
else
|
} else {
|
||||||
self::$settings->setGlobalOption ( 'track_mode', 0 );
|
self::$settings->set_global_option( 'track_mode', 0 );
|
||||||
|
}
|
||||||
|
|||||||
@ -1,10 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
$aryRemoveOptions = array (
|
/**
|
||||||
'wp-piwik_siteid',
|
* @package wp-piwik
|
||||||
'wp-piwik_404',
|
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||||
'wp-piwik_scriptupdate',
|
*/
|
||||||
'wp-piwik_dashboardid',
|
|
||||||
'wp-piwik_jscode'
|
$ary_remove_options = array(
|
||||||
);
|
'wp-piwik_siteid',
|
||||||
foreach ( $aryRemoveOptions as $strRemoveOption )
|
'wp-piwik_404',
|
||||||
delete_option ( $strRemoveOption );
|
'wp-piwik_scriptupdate',
|
||||||
|
'wp-piwik_dashboardid',
|
||||||
|
'wp-piwik_jscode',
|
||||||
|
);
|
||||||
|
foreach ( $ary_remove_options as $str_remove_option ) {
|
||||||
|
delete_option( $str_remove_option );
|
||||||
|
}
|
||||||
|
|||||||
@ -1,83 +1,77 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/**
|
||||||
Plugin Name: Connect Matomo
|
* Plugin Name: Connect Matomo
|
||||||
|
* Plugin URI: http://wordpress.org/extend/plugins/wp-piwik/
|
||||||
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.1.5
|
||||||
Description: Adds Matomo statistics to your WordPress dashboard and is also able to add the Matomo Tracking Code to your blog.
|
* Author: Matomo, André Bräkling
|
||||||
|
* Author URI: https://matomo.org
|
||||||
Version: 1.0.30
|
* Text Domain: wp-piwik
|
||||||
Author: André Bräkling
|
* Domain Path: /languages
|
||||||
Author URI: https://www.braekling.de
|
*
|
||||||
Text Domain: wp-piwik
|
* @link https://matomo.org
|
||||||
Domain Path: /languages
|
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||||
License: GPL3
|
* @package wp-piwik
|
||||||
|
*/
|
||||||
******************************************************************************************
|
|
||||||
Copyright (C) 2009-today Andre Braekling (email: webmaster@braekling.de)
|
if ( ! function_exists( 'add_action' ) ) {
|
||||||
|
header( 'Status: 403 Forbidden' );
|
||||||
This program is free software: you can redistribute it and/or modify
|
header( 'HTTP/1.1 403 Forbidden' );
|
||||||
it under the terms of the GNU General Public License as published by
|
exit();
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
}
|
||||||
at your option) any later version.
|
|
||||||
|
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
|
||||||
This program is distributed in the hope that it will be useful,
|
if ( ! defined( 'NAMESPACE_SEPARATOR' ) ) {
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
define( 'NAMESPACE_SEPARATOR', '\\' );
|
||||||
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/>.
|
* Define WP-Piwik autoloader
|
||||||
*******************************************************************************************/
|
*
|
||||||
|
* @param string $class_name
|
||||||
if (! function_exists ( 'add_action' )) {
|
* class name
|
||||||
header ( 'Status: 403 Forbidden' );
|
*/
|
||||||
header ( 'HTTP/1.1 403 Forbidden' );
|
function wp_piwik_autoloader( $class_name ) {
|
||||||
exit ();
|
if ( 'WP_Piwik' . NAMESPACE_SEPARATOR === substr( $class_name, 0, 9 ) ) {
|
||||||
}
|
$class_name = str_replace( '.', '', str_replace( NAMESPACE_SEPARATOR, DIRECTORY_SEPARATOR, substr( $class_name, 9 ) ) );
|
||||||
|
$file = 'classes' . DIRECTORY_SEPARATOR . 'WP_Piwik' . DIRECTORY_SEPARATOR . $class_name . '.php';
|
||||||
if (! defined ( 'NAMESPACE_SEPARATOR' ))
|
if ( is_file( __DIR__ . '/' . $file ) ) {
|
||||||
define ( 'NAMESPACE_SEPARATOR', '\\' );
|
require_once $file;
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Define WP-Piwik autoloader
|
}
|
||||||
*
|
|
||||||
* @param string $class
|
/**
|
||||||
* class name
|
* Show notice about outdated PHP version
|
||||||
*/
|
*/
|
||||||
function wp_piwik_autoloader($class) {
|
function wp_piwik_phperror() {
|
||||||
if (substr ( $class, 0, 9 ) == 'WP_Piwik' . NAMESPACE_SEPARATOR) {
|
echo '<div class="error"><p>';
|
||||||
$class = str_replace ( '.', '', str_replace ( NAMESPACE_SEPARATOR, DIRECTORY_SEPARATOR, substr ( $class, 9 ) ) );
|
printf( esc_html__( 'WP-Matomo requires at least PHP 5.3. You are using the deprecated version %s. Please update PHP to use WP-Matomo.', 'wp-piwik' ), PHP_VERSION );
|
||||||
require_once ('classes' . DIRECTORY_SEPARATOR . 'WP_Piwik' . DIRECTORY_SEPARATOR . $class . '.php');
|
echo '</p></div>';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
function wp_piwik_load_textdomain() {
|
||||||
/**
|
load_plugin_textdomain( 'wp-piwik', false, plugin_basename( __DIR__ ) . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR );
|
||||||
* Show notice about outdated PHP version
|
}
|
||||||
*/
|
add_action( 'plugins_loaded', 'wp_piwik_load_textdomain' );
|
||||||
function wp_piwik_phperror() {
|
|
||||||
echo '<div class="error"><p>';
|
if ( version_compare( PHP_VERSION, '5.3.0', '<' ) ) {
|
||||||
printf ( __ ( 'WP-Matomo requires at least PHP 5.3. You are using the deprecated version %s. Please update PHP to use WP-Matomo.', 'wp-piwik' ), PHP_VERSION );
|
add_action( 'admin_notices', 'wp_piwik_phperror' );
|
||||||
echo '</p></div>';
|
} else {
|
||||||
}
|
define( 'WP_PIWIK_FILE', __FILE__ );
|
||||||
|
define( 'WP_PIWIK_PATH', __DIR__ . DIRECTORY_SEPARATOR );
|
||||||
function wp_piwik_load_textdomain() {
|
require_once WP_PIWIK_PATH . 'config.php';
|
||||||
load_plugin_textdomain( 'wp-piwik', false, plugin_basename( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR );
|
require_once WP_PIWIK_PATH . 'classes' . DIRECTORY_SEPARATOR . 'WP_Piwik.php';
|
||||||
}
|
spl_autoload_register( 'wp_piwik_autoloader' );
|
||||||
add_action( 'plugins_loaded', 'wp_piwik_load_textdomain' );
|
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||||
|
$GLOBALS['wp-piwik_debug'] = false;
|
||||||
if (version_compare ( PHP_VERSION, '5.3.0', '<' ))
|
if ( class_exists( 'WP_Piwik' ) ) {
|
||||||
add_action ( 'admin_notices', 'wp_piwik_phperror' );
|
add_action( 'setup_theme', 'wp_piwik_loader' );
|
||||||
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');
|
function wp_piwik_loader() {
|
||||||
spl_autoload_register ( 'wp_piwik_autoloader' );
|
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||||
$GLOBALS ['wp-piwik_debug'] = false;
|
$GLOBALS['wp-piwik'] = new WP_Piwik();
|
||||||
if (class_exists ( 'WP_Piwik' ))
|
}
|
||||||
add_action( 'init', 'wp_piwik_loader' );
|
|
||||||
}
|
|
||||||
|
|
||||||
function wp_piwik_loader() {
|
|
||||||
$GLOBALS ['wp-piwik'] = new WP_Piwik ();
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user