Skip to content

Commit 74622fa

Browse files
committed
complete functionality of new welcome page
1 parent 5e8fece commit 74622fa

5 files changed

Lines changed: 127 additions & 25 deletions

File tree

assets/js/marketplace_setup_wizard.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ window.jQuery(document).ready(function ($) {
2222
if (data.active) {
2323
if (!setActiveClass) {
2424
$('.wizard-waiting-for').hide();
25-
$('.wizard-reloading').show();
25+
} else {
26+
$('.wizard-waiting-for .waiting-for-activation').hide();
2627
}
2728

28-
window.location.reload();
29+
$('.wizard-reloading').show();
30+
31+
// reload after the dom has had a chance to update
32+
setTimeout(function () {
33+
window.location.reload();
34+
});
35+
2936
clearInterval(interval);
3037
} else if (data.installed && setActiveClass) {
3138
$('.wizard-waiting-for .waiting-for-install').hide();

classes/WpMatomo/Admin/Marketplace.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public function show() {
5353
$valid_tabs = $this->get_valid_tabs();
5454

5555
$marketplace_setup_wizard = \WpMatomo::get_active_feature( MarketplaceSetupWizard::class );
56-
$matomo_marketplace_url = MarketplaceSetupWizardBody::get_marketplace_zip_url();
56+
$matomo_marketplace_url = MarketplaceSetupWizardBody::get_marketplace_zip_url();
57+
} else {
58+
wp_safe_redirect( admin_url( 'admin.php?page=matomo-marketplace&tab=install' ) );
5759
}
5860

5961
$matomo_currency = $this->get_currency_based_on_timezone();
@@ -62,7 +64,14 @@ public function show() {
6264
}
6365

6466
private function get_valid_tabs() {
65-
$valid_tabs = [ 'marketplace' ];
67+
$valid_tabs = [];
68+
if (
69+
! MarketplaceSetupWizard::is_marketplace_installed()
70+
|| ! is_plugin_active( MarketplaceSetupWizard::MARKETPLACE_PLUGIN_FILE )
71+
) {
72+
$valid_tabs[] = 'marketplace';
73+
}
74+
6675
if ( $this->can_user_manage() ) {
6776
if ( current_user_can( 'install_plugins' ) ) {
6877
$valid_tabs[] = 'install';

classes/WpMatomo/Admin/MarketplaceSetupWizard.php

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public function is_active() {
2222
return false;
2323
}
2424

25-
if ( $this->is_plugin_install_page() ) {
25+
if (
26+
$this->is_plugin_install_page()
27+
|| $this->is_plugin_activation_request()
28+
) {
2629
return true;
2730
}
2831

@@ -55,6 +58,35 @@ public function show() {
5558
public function register_hooks() {
5659
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
5760
add_action( 'admin_notices', [ $this, 'admin_notices' ] );
61+
add_action( 'activated_plugin', [ $this, 'on_plugin_activated' ] );
62+
add_action( 'admin_footer', [ $this, 'on_admin_footer' ] );
63+
}
64+
65+
public function on_plugin_activated( $plugin ) {
66+
if ( 'matomo-marketplace-for-wordpress/matomo-marketplace-for-wordpress.php' !== $plugin ) {
67+
return;
68+
}
69+
70+
if (
71+
empty( $_SERVER['HTTP_REFERER'] )
72+
|| false === strpos( esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ), 'mtm_marketplace_install' )
73+
) {
74+
return;
75+
}
76+
77+
// if we are in the marketplace install workflow, and the plugin has been
78+
// activated, close the current window to go back to the marketplace setup
79+
?>
80+
<html>
81+
<head></head>
82+
<body>
83+
<script>
84+
window.close();
85+
</script>
86+
</body>
87+
</html>
88+
<?php
89+
wp_die();
5890
}
5991

6092
public function admin_notices() {
@@ -64,12 +96,28 @@ public function admin_notices() {
6496
?>
6597
<div class="notice notice-info">
6698
<p>
67-
<?php esc_html_e( 'You are almost there! Upload the .zip file below to install the Marketplace and start exploring advanced analytics features.', 'matomo' ); ?>
99+
<?php esc_html_e( 'You\'re almost there! Upload the .zip file below to install the Marketplace and start exploring advanced analytics features.', 'matomo' ); ?>
68100
</p>
69101
</div>
70102
<?php
71103
}
72104

105+
public function on_admin_footer() {
106+
if ( ! $this->is_plugin_install_page() ) {
107+
return;
108+
}
109+
110+
// add script to add query param to plugin upload form submit URL
111+
?>
112+
<script>
113+
window.jQuery(document).ready(function ($) {
114+
var $form = $('.wp-upload-form');
115+
$form.attr('action', $form.attr('action') + '&mtm_marketplace_install=1');
116+
});
117+
</script>
118+
<?php
119+
}
120+
73121
public function enqueue_scripts() {
74122
wp_enqueue_script(
75123
'matomo-marketplace-setup-wizard',
@@ -86,7 +134,12 @@ public function enqueue_scripts() {
86134
'ajax_url' => admin_url( 'admin-ajax.php' ),
87135
'is_active_nonce' => wp_create_nonce( self::AJAX_IS_ACTIVE_NONCE_NAME ),
88136
'activate_nonce' => wp_create_nonce( self::AJAX_ACTIVATE_NONCE_NAME ),
89-
'is_welcome_page' => wp_unslash( $_REQUEST['page'] ) === Menu::SLUG_MARKETPLACE && wp_unslash( $_REQUEST['tab'] ) === 'marketplace',
137+
'is_welcome_page' => isset( $_REQUEST['page'] )
138+
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
139+
&& Menu::SLUG_MARKETPLACE === wp_unslash( $_REQUEST['page'] )
140+
&& isset( $_REQUEST['tab'] )
141+
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
142+
&& 'marketplace' === wp_unslash( $_REQUEST['tab'] ),
90143
]
91144
);
92145
}
@@ -132,19 +185,44 @@ private function is_plugin_install_page() {
132185
return false;
133186
}
134187

135-
$request_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
188+
$request_path = wp_parse_url( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ), PHP_URL_PATH );
136189
if ( ! preg_match( '%/wp-admin/plugin-install\\.php$%', $request_path ) ) {
137190
return false;
138191
}
139192

140193
if (
141194
empty( $_REQUEST['tab'] )
142-
|| wp_unslash( $_REQUEST['tab'] ) !== 'upload'
195+
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
196+
|| 'upload' !== wp_unslash( $_REQUEST['tab'] )
143197
|| empty( $_REQUEST['mtm_marketplace_install'] )
144198
) {
145199
return false;
146200
}
147201

148202
return true;
149203
}
204+
205+
private function is_plugin_activation_request() {
206+
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
207+
return false;
208+
}
209+
210+
$request_path = wp_parse_url( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ), PHP_URL_PATH );
211+
if ( ! preg_match( '%/wp-admin/plugins\\.php$%', $request_path ) ) {
212+
return false;
213+
}
214+
215+
if (
216+
empty( $_REQUEST['action'] )
217+
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
218+
|| 'activate' === wp_unslash( $_REQUEST['action'] )
219+
|| empty( $_REQUEST['plugin'] )
220+
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
221+
|| 'matomo-marketplace-for-wordpress/matomo-marketplace-for-wordpress.php' === wp_unslash( $_REQUEST['plugin'] )
222+
) {
223+
return false;
224+
}
225+
226+
return true;
227+
}
150228
}

classes/WpMatomo/Admin/views/marketplace.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class="nav-tab <?php echo ( 'marketplace' === $active_tab ) ? 'nav-tab-active' :
3333
<?php if ( in_array( 'install', $valid_tabs, true ) ) { ?>
3434
<a href="?page=matomo-marketplace&tab=install"
3535
class="nav-tab <?php echo ( 'install' === $active_tab ) ? 'nav-tab-active' : ''; ?>"
36-
><?php esc_html_e( 'Install Plugins', 'matomo' ); ?></a>
36+
><?php esc_html_e( 'Marketplace', 'matomo' ); ?></a>
3737
<?php } ?>
3838
<?php if ( in_array( 'subscriptions', $valid_tabs, true ) ) { ?>
3939
<a href="?page=matomo-marketplace&tab=subscriptions"
@@ -49,7 +49,7 @@ class="nav-tab <?php echo 'subscriptions' === $active_tab ? 'nav-tab-active' : '
4949
<?php } ?>
5050

5151
<?php
52-
if ( isset( $marketplace_setup_wizard ) && $active_tab !== 'marketplace' ) {
52+
if ( isset( $marketplace_setup_wizard ) && 'marketplace' !== $active_tab ) {
5353
$marketplace_setup_wizard->show();
5454
return;
5555
}
@@ -252,26 +252,34 @@ class="nav-tab <?php echo 'subscriptions' === $active_tab ? 'nav-tab-active' : '
252252

253253
<div class="matomo-setup-divider"></div>
254254
<p class="matomo-smaller-text">
255-
<?php echo sprintf(
255+
<?php
256+
echo sprintf(
256257
esc_html__( 'Don\'t want to use the plugin? Download directly %1$son our marketplace,%2$s but keep in mind, you won\'t receive automatic updates unless you use the Matomo Marketplace plugin.', 'matomo' ),
257258
'<a href="https://plugins.matomo.org/?wp=1" target="_blank" rel="noreferrer noopener">',
258259
'</a>'
259-
); ?>
260+
);
261+
?>
260262
</p>
261263
<div>
262264
<div class="wizard-waiting-for matomo-primary-color-fg">
263265
<span class="waiting-for-install" style="display: none;">
264266
<!-- TODO: change to css animation -->
265267
<svg class="matomo-primary-color-fill" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10.72,19.9a8,8,0,0,1-6.5-9.79A7.77,7.77,0,0,1,10.4,4.16a8,8,0,0,1,9.49,6.52A1.54,1.54,0,0,0,21.38,12h.13a1.37,1.37,0,0,0,1.38-1.54,11,11,0,1,0-12.7,12.39A1.54,1.54,0,0,0,12,21.34h0A1.47,1.47,0,0,0,10.72,19.9Z"><animateTransform attributeName="transform" type="rotate" dur="0.75s" values="0 12 12;360 12 12" repeatCount="indefinite"/></path></svg>
266268

267-
<?php esc_html_e( 'Waiting for plugin installation', 'matomo' ); ?>
269+
<?php esc_html_e( 'Waiting for plugin installation', 'matomo' ); ?>...
268270
</span>
269271
<span class="waiting-for-activation" style="display: none;">
270272
<!-- TODO: change to css animation -->
271273
<svg class="matomo-primary-color-fill" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10.72,19.9a8,8,0,0,1-6.5-9.79A7.77,7.77,0,0,1,10.4,4.16a8,8,0,0,1,9.49,6.52A1.54,1.54,0,0,0,21.38,12h.13a1.37,1.37,0,0,0,1.38-1.54,11,11,0,1,0-12.7,12.39A1.54,1.54,0,0,0,12,21.34h0A1.47,1.47,0,0,0,10.72,19.9Z"><animateTransform attributeName="transform" type="rotate" dur="0.75s" values="0 12 12;360 12 12" repeatCount="indefinite"/></path></svg>
272274

273275
<?php esc_html_e( 'Waiting for plugin activation', 'matomo' ); ?>...
274276
</span>
277+
<span class="wizard-reloading" style="display: none;">
278+
<!-- TODO: change to css animation -->
279+
<svg class="matomo-primary-color-fill" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10.72,19.9a8,8,0,0,1-6.5-9.79A7.77,7.77,0,0,1,10.4,4.16a8,8,0,0,1,9.49,6.52A1.54,1.54,0,0,0,21.38,12h.13a1.37,1.37,0,0,0,1.38-1.54,11,11,0,1,0-12.7,12.39A1.54,1.54,0,0,0,12,21.34h0A1.47,1.47,0,0,0,10.72,19.9Z"><animateTransform attributeName="transform" type="rotate" dur="0.75s" values="0 12 12;360 12 12" repeatCount="indefinite"/></path></svg>
280+
281+
<?php esc_html_e( 'Reloading page', 'matomo' ); ?>...
282+
</span>
275283
</div>
276284
</div>
277285
</div>
@@ -284,7 +292,7 @@ class="nav-tab <?php echo 'subscriptions' === $active_tab ? 'nav-tab-active' : '
284292
<?php esc_html_e( 'Download the Matomo Marketplace for WordPress plugin as a .zip file to your computer.', 'matomo' ); ?>
285293
</p>
286294
<div>
287-
<a href="<?php echo esc_attr( $matomo_marketplace_url ); ?>" target="_blank" rel="noreferrer noopener" class="download-plugin">
295+
<a href="<?php echo esc_attr( $matomo_marketplace_url ); ?>" rel="noreferrer noopener" class="download-plugin">
288296
<button class="button-primary"><?php esc_html_e( 'Download .zip', 'matomo' ); ?></button>
289297
</a>
290298
</div>
@@ -310,7 +318,7 @@ class="nav-tab <?php echo 'subscriptions' === $active_tab ? 'nav-tab-active' : '
310318

311319
<?php
312320
$matomo_popular_features = [
313-
'MarketingCampaignsReporting' => [
321+
'MarketingCampaignsReporting' => [
314322
'name' => __( 'Marketing Campaigns Reporting', 'matomo' ),
315323
'desc' => __( "Measure the effectiveness of your marketing campaigns. Track up to five channels instead of two: campaign, source, medium, keyword, content.', 'matomo'", 'matomo' ),
316324
],
@@ -319,31 +327,31 @@ class="nav-tab <?php echo 'subscriptions' === $active_tab ? 'nav-tab-active' : '
319327
'desc' => __( 'All keywords searched by your users on search engines are now visible into your Referrers reports! The ultimate solution to \'Keyword not defined\'.', 'matomo' ),
320328
'price' => '79EUR / 89USD',
321329
],
322-
'HeatmapSessionRecording' => [
330+
'HeatmapSessionRecording' => [
323331
'name' => __( 'Heatmap & Session Recording', 'matomo' ),
324332
'desc' => __( 'Truly understand your visitors by seeing where they click, hover, type and scroll. Replay their actions in a video and ultimately increase conversions.', 'matomo' ),
325333
'price' => '109EUR / 129USD',
326334
],
327-
'CustomAlerts' => [
328-
'name' => __( 'Custom Alerts', 'matomo' ),
329-
'desc' => __( 'Create custom Alerts to be notified of important changes on your website or app!', 'matomo' ),
335+
'CustomAlerts' => [
336+
'name' => __( 'Custom Alerts', 'matomo' ),
337+
'desc' => __( 'Create custom Alerts to be notified of important changes on your website or app!', 'matomo' ),
330338
],
331-
'MediaAnalytics' => [
339+
'MediaAnalytics' => [
332340
'name' => __( 'Media Analytics', 'matomo' ),
333341
'desc' => __( 'Grow your business with advanced video & audio analytics. Get powerful insights into how your audience watches your videos and listens to your audio.', 'matomo' ),
334342
'price' => '89EUR / 99USD',
335343
],
336-
'CustomReports' => [
344+
'CustomReports' => [
337345
'name' => __( 'Custom Reports', 'matomo' ),
338346
'desc' => __( 'Pull out the information you need in order to be successful. Develop your custom strategy to meet your individualized goals while saving money & time.', 'matomo' ),
339347
'price' => '109EUR / 129USD',
340348
],
341-
'WpPremiumBundle' => [
349+
'WpPremiumBundle' => [
342350
'name' => __( 'WordPress Premium Bundle', 'matomo' ),
343351
'desc' => __( 'All premium features in one bundle, make the most out of your Matomo for WordPress and enjoy discounts of up to 25%!', 'matomo' ),
344352
'price' => '549EUR / 639USD',
345353
],
346-
'UsersFlow' => [
354+
'UsersFlow' => [
347355
'name' => __( 'Users Flow', 'matomo' ),
348356
'desc' => __( 'Users Flow is a visual representation of the most popular paths your users take through your website & app which lets you understand your users needs.', 'matomo' ),
349357
'price' => '49EUR / 59USD',

0 commit comments

Comments
 (0)