Skip to content

Commit

Permalink
Update live for next release (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur authored Sep 6, 2021
1 parent be8c033 commit 0816e2b
Show file tree
Hide file tree
Showing 167 changed files with 34,249 additions and 3,142 deletions.
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
/scripts/ export-ignore
/vendor/ export-ignore
/bin/ export-ignore
/node_modules/chart.js/auto export-ignore
/node_modules/chart.js/helpers export-ignore
/node_modules/chart.js/types export-ignore
/node_modules/chart.js/dist/chunks export-ignore
/node_modules/chart.js/dist/chart.esm.js export-ignore
/node_modules/chart.js/dist/chart.js export-ignore
/node_modules/chart.js/dist/helpers.esm.js export-ignore
/README.md export-ignore
/.wordpress-org export-ignore
/.github export-ignore
.github export-ignore
.gitignore export-ignore
.gitattributes export-ignore
.travis.yml export-ignore
package-lock.json
bower.json export-ignore
composer.json export-ignore
composer.lock export-ignore
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.DS_Store
/vendor/
.php-cs-fixer.cache
.*~
*~
9 changes: 3 additions & 6 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
<file>./matomo.php</file>
<file>./shared.php</file>
<file>./uninstall.php</file>
<exclude-pattern>/classes/WpMatomo/Db/*</exclude-pattern>
<exclude-pattern>/classes/WpMatomo/AjaxTracker.php</exclude-pattern>
<exclude-pattern>/tests/phpunit/bootstrap.php</exclude-pattern>
<exclude-pattern>tests/phpunit/framework/test-matomo-test-case.php</exclude-pattern>
<exclude-pattern>tests/phpunit/framework/test-local-tracker.php</exclude-pattern>

<exclude-pattern>/classes/WpMatomo/Db/*.php</exclude-pattern>
<exclude-pattern>/classes/WpMatomo/AjaxTracker.php</exclude-pattern>
<!-- How to scan -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
Expand Down Expand Up @@ -58,6 +54,7 @@
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound"/>
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar"/>
<exclude name="WordPress.WP.I18n.MissingTranslatorsComment"/>
<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found"/>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ matrix:
env: WP_VERSION=trunk
- php: 7.2
env: WP_TRAVISCI=phpcs
allow_failures:
- env: WP_TRAVISCI=phpcs

before_install:
- if [[ "$WP_TRAVISCI" == "phpcs" ]]; then export PHPCS_DIR=/tmp/phpcs; fi
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
== Changelog ==

= 4.4.2 =
* Allow users to add opt out using a Gutenberg block
* Add a visual graph to the summary page
* Enable feature to select default report date
* Internal change: Improve coding style consistency
* Improve installation process

= 4.4.1 =
* Update core to 4.4.1
* Fix CORS settings could not be saved in the Matomo admin
Expand Down
7 changes: 6 additions & 1 deletion LEGALNOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ See a list of all components/libraries and its licenses in Matomo in `app/LEGALN

THIRD-PARTY CONTENT

See the list in `app/LEGALNOTICE`
Name: chart.js
Link: https://www.chartjs.org/
License: The MIT License (MIT) see node_modules/chart.js/LICENSE.md

For more third party content see the list in `app/LEGALNOTICE`.

52 changes: 52 additions & 0 deletions assets/chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
jQuery(document).ready(function(){
jQuery('.matomo-table[data-chart]').each(function() {
let $this = jQuery(this);
let $postbox = $this.parents('div.postbox');
let $table = $postbox.find('table');
$table.hide();
let $canvas = jQuery('<canvas/>',{'id':$this.attr('data-chart')});
$canvas.insertAfter($table);
let data = [];
let labels = [];
let title = $postbox.find('h2').text();
let $row;
let value;
$table.find('tr').each(function() {
$row = jQuery(this);
value = $row.find('td:nth-child(2)').text();
if ( '-' === value ) {
value = 0;
}
data.push(value);
labels.push($row.find('td:nth-child(1)').text());
});

var myChart = new Chart($canvas, {
type: 'line',
data: {
labels: labels.reverse(),
datasets: [{
label: title,
data: data.reverse(),
borderColor: "#55bae7",
pointBackgroundColor: "#55bae7",
pointBorderColor: "#55bae7",
pointHoverBackgroundColor: "#55bae7",
pointHoverBorderColor: "#55bae7",
}]
},
options: {
plugins: {
legend: {
display: false
}
},
scales: {
y: {
beginAtZero: true
}
}
}
});
});
});
19 changes: 19 additions & 0 deletions assets/js/blocks/matomo_opt_out.js

Large diffs are not rendered by default.

95 changes: 48 additions & 47 deletions classes/WpMatomo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@
exit; // if accessed directly
}

use WpMatomo\Admin\Menu;
use WpMatomo\Admin\Admin;
use WpMatomo\Admin\Chart;
use WpMatomo\Admin\Dashboard;
use WpMatomo\Admin\Menu;
use WpMatomo\AjaxTracker;
use WpMatomo\Annotations;
use WpMatomo\API;
use WpMatomo\Capabilities;
use WpMatomo\Commands\MatomoCommands;
use WpMatomo\Ecommerce\EasyDigitalDownloads;
use WpMatomo\Ecommerce\MemberPress;
use WpMatomo\Ecommerce\Woocommerce;
use WpMatomo\Installer;
use WpMatomo\OptOut;
use WpMatomo\Paths;
use WpMatomo\ScheduledTasks;
use \WpMatomo\Site\Sync as SiteSync;
use WpMatomo\AjaxTracker;
use \WpMatomo\User\Sync as UserSync;
use \WpMatomo\Installer;
use \WpMatomo\Updater;
use \WpMatomo\Roles;
use \WpMatomo\Annotations;
use \WpMatomo\TrackingCode;
use \WpMatomo\Settings;
use \WpMatomo\Capabilities;
use \WpMatomo\Ecommerce\Woocommerce;
use \WpMatomo\Report\Renderer;
use WpMatomo\API;
use \WpMatomo\Admin\Admin;
use WpMatomo\RedirectOnActivation;
use WpMatomo\Report\Renderer;
use WpMatomo\Roles;
use WpMatomo\ScheduledTasks;
use WpMatomo\Settings;
use WpMatomo\Site\Sync as SiteSync;
use WpMatomo\TrackingCode;
use WpMatomo\Updater;
use WpMatomo\User\Sync as UserSync;

class WpMatomo {

/**
* @var Settings
*/
Expand All @@ -58,7 +58,7 @@ public function __construct() {
return;
}

add_action( 'init', array( $this, 'init_plugin' ) );
add_action( 'init', [ $this, 'init_plugin' ] );

$capabilities = new Capabilities( self::$settings );
$capabilities->register_hooks();
Expand Down Expand Up @@ -97,10 +97,13 @@ public function __construct() {
$referral->register_hooks();
}

$chart = new Chart();
$chart->register_hooks();

/*
* @see https://github.com/matomo-org/matomo-for-wordpress/issues/434
*/
$redirect = new RedirectOnActivation($this);
$redirect = new RedirectOnActivation( $this );
$redirect->register_hooks();
}

Expand All @@ -115,10 +118,10 @@ public function __construct() {

add_filter(
'plugin_action_links_' . plugin_basename( MATOMO_ANALYTICS_FILE ),
array(
[
$this,
'add_settings_link',
)
]
);
}

Expand All @@ -134,15 +137,15 @@ private function check_compatibility() {
$upload_path = $paths->get_upload_base_dir();

if ( $upload_path
&& ! is_writable( dirname( $upload_path ) ) ) {
&& ! is_writable( dirname( $upload_path ) ) ) {
add_action(
'init',
function () use ( $upload_path ) {
if ( self::is_admin_user() ) {
add_action(
'admin_notices',
function () use ( $upload_path ) {
echo '<div class="error"><p>' . sprintf( __( 'Matomo Analytics requires the uploads directory %s to be writable. Please make the directory writable for it to work.', 'matomo' ), '(' . esc_html( dirname( $upload_path ) ) . ')' ) . '</p></div>';
echo '<div class="error"><p>' . sprintf( esc_html__( 'Matomo Analytics requires the uploads directory %s to be writable. Please make the directory writable for it to work.', 'matomo' ), '(' . esc_html( dirname( $upload_path ) ) . ')' ) . '</p></div>';
}
);
}
Expand All @@ -157,24 +160,13 @@ function () use ( $upload_path ) {

public static function is_admin_user() {
if ( ! function_exists( 'is_multisite' )
|| ! is_multisite() ) {
|| ! is_multisite() ) {
return current_user_can( 'administrator' );
}

return is_super_admin();
}

private static function get_active_plugins() {
$plugins = [];
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
$muplugins = get_site_option( 'active_sitewide_plugins' );
$plugins = array_keys( $muplugins );
}
$plugins = array_merge( (array) get_option( 'active_plugins', array() ), $plugins );

return $plugins;
}

public static function is_safe_mode() {
if ( defined( 'MATOMO_SAFE_MODE' ) ) {
return MATOMO_SAFE_MODE;
Expand All @@ -183,14 +175,29 @@ public static function is_safe_mode() {
// we are not using is_plugin_active() for performance reasons
$active_plugins = self::get_active_plugins();

if ( in_array( 'wp-rss-aggregator/wp-rss-aggregator.php', $active_plugins )
|| in_array( 'wp-defender/wp-defender.php', $active_plugins ) ) {
if ( in_array( 'wp-rss-aggregator/wp-rss-aggregator.php', $active_plugins, true )
|| in_array( 'wp-defender/wp-defender.php', $active_plugins, true ) ) {
return true;
}

return false;
}

private static function get_active_plugins() {
$plugins = [];
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
$muplugins = get_site_option( 'active_sitewide_plugins' );
$plugins = array_keys( $muplugins );
}
$plugins = array_merge( (array) get_option( 'active_plugins', [] ), $plugins );

return $plugins;
}

public static function should_disable_addhandler() {
return defined( 'MATOMO_DISABLE_ADDHANDLER' ) && MATOMO_DISABLE_ADDHANDLER;
}

public function add_settings_link( $links ) {
$get_started = new \WpMatomo\Admin\GetStarted( self::$settings );

Expand All @@ -204,13 +211,11 @@ public function add_settings_link( $links ) {
}

public function init_plugin() {
if ( ( is_admin() || matomo_is_app_request() )
&& ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
if ( ( is_admin() || matomo_is_app_request() ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
$installer = new Installer( self::$settings );
$installer->register_hooks();
if ( $installer->looks_like_it_is_installed() ) {
if ( is_admin()
&& ( ! defined( 'MATOMO_ENABLE_AUTO_UPGRADE' ) || MATOMO_ENABLE_AUTO_UPGRADE ) ) {
if ( is_admin() && ( ! defined( 'MATOMO_ENABLE_AUTO_UPGRADE' ) || MATOMO_ENABLE_AUTO_UPGRADE ) ) {
$updater = new Updater( self::$settings );
$updater->update_if_needed();
}
Expand All @@ -228,8 +233,8 @@ public function init_plugin() {
}
$tracking_code = new TrackingCode( self::$settings );
if ( self::$settings->is_tracking_enabled()
&& self::$settings->get_global_option( 'track_ecommerce' )
&& ! $tracking_code->is_hidden_user() ) {
&& self::$settings->get_global_option( 'track_ecommerce' )
&& ! $tracking_code->is_hidden_user() ) {
$tracker = new AjaxTracker( self::$settings );

$woocommerce = new Woocommerce( $tracker );
Expand All @@ -244,8 +249,4 @@ public function init_plugin() {
do_action( 'matomo_ecommerce_init', $tracker );
}
}

public static function should_disable_addhandler() {
return defined( 'MATOMO_DISABLE_ADDHANDLER' ) && MATOMO_DISABLE_ADDHANDLER;
}
}
Loading

0 comments on commit 0816e2b

Please sign in to comment.