PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.10.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.10.1
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / classes / WpMatomo / Admin / MarketplaceSetupWizard.php
matomo / classes / WpMatomo / Admin Last commit date
Marketplace 1 month ago PluginSuggestions 3 months ago TrackingSettings 2 months ago views 1 month ago AccessSettings.php 4 years ago AdBlockDetector.php 7 months ago Admin.php 1 month ago AdminSettings.php 3 months ago AdminSettingsInterface.php 6 years ago AdvancedSettings.php 10 months ago Chart.php 2 months ago CookieConsent.php 4 years ago Dashboard.php 3 months ago ExclusionSettings.php 7 months ago GeolocationSettings.php 2 years ago GetStarted.php 3 months ago ImportWpStatistics.php 3 months ago Info.php 3 months ago InvalidIpException.php 4 years ago Marketplace.php 1 month ago MarketplaceSetupWizard.php 1 month ago MarketplaceSetupWizardBody.php 1 month ago MatomoPage.php 3 months ago MatomoPageContent.php 3 months ago Menu.php 1 month ago PluginMeasurableSettings.php 2 years ago PrivacySettings.php 1 year ago SafeModeMenu.php 3 months ago Summary.php 3 months ago SystemReport.php 2 months ago TrackingSettings.php 2 months ago WhatsNewNotifications.php 3 months ago
MarketplaceSetupWizard.php
229 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 * @package matomo
8 */
9
10 namespace WpMatomo\Admin;
11
12 use WpMatomo\Feature;
13 use WpMatomo\Settings;
14
15 class MarketplaceSetupWizard extends Feature {
16 const MARKETPLACE_PLUGIN_FILE = 'matomo-marketplace-for-wordpress/matomo-marketplace-for-wordpress.php';
17 const AJAX_IS_ACTIVE_NONCE_NAME = 'matomo-marketplace-setup-wizard-is-active';
18 const AJAX_ACTIVATE_NONCE_NAME = 'matomo-marketplace-setup-wizard-activate';
19
20 public function is_active() {
21 if ( ! is_admin() ) {
22 return false;
23 }
24
25 if (
26 $this->is_plugin_install_page()
27 || $this->is_plugin_activation_request()
28 ) {
29 return true;
30 }
31
32 if ( empty( $_REQUEST['page'] ) ) {
33 return false;
34 }
35
36 if ( Menu::SLUG_GET_STARTED === $_REQUEST['page'] ) {
37 return true;
38 }
39
40 if ( Menu::SLUG_MARKETPLACE !== $_REQUEST['page'] ) {
41 return false;
42 }
43
44 return true; // displayed in some manner on all tabs
45 }
46
47 public function get_body( $show_titles = true ) {
48 return new MarketplaceSetupWizardBody( $show_titles );
49 }
50
51 public function show() {
52 $matomo_logo_big = plugins_url( 'assets/img/logo-big.png?v=' . rawurlencode( matomo_get_asset_version() ), MATOMO_ANALYTICS_FILE );
53 $marketplace_setup_wizard_body = $this->get_body();
54
55 include dirname( __FILE__ ) . '/views/marketplace_setup_wizard.php';
56 }
57
58 public function register_hooks() {
59 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
60 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();
90 }
91
92 public function admin_notices() {
93 if ( ! $this->is_plugin_install_page() ) {
94 return;
95 }
96 ?>
97 <div class="notice notice-info">
98 <p>
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' ); ?>
100 </p>
101 </div>
102 <?php
103 }
104
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
121 public function enqueue_scripts() {
122 wp_enqueue_script(
123 'matomo-marketplace-setup-wizard',
124 plugins_url( '/assets/js/marketplace_setup_wizard.js', MATOMO_ANALYTICS_FILE ),
125 [ 'jquery' ],
126 matomo_get_asset_version(),
127 true
128 );
129
130 wp_localize_script(
131 'matomo-marketplace-setup-wizard',
132 'mtmMarketplaceWizardAjax',
133 [
134 'ajax_url' => admin_url( 'admin-ajax.php' ),
135 'is_active_nonce' => wp_create_nonce( self::AJAX_IS_ACTIVE_NONCE_NAME ),
136 'activate_nonce' => wp_create_nonce( self::AJAX_ACTIVATE_NONCE_NAME ),
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'] ),
143 ]
144 );
145 }
146
147 public function register_ajax() {
148 add_action( 'wp_ajax_matomo_is_marketplace_active', [ self::class, 'is_marketplace_active' ] );
149 add_action( 'wp_ajax_matomo_activate_marketplace', [ self::class, 'activate_marketplace_plugin' ] );
150 }
151
152 public static function is_marketplace_active() {
153 check_ajax_referer( self::AJAX_IS_ACTIVE_NONCE_NAME );
154
155 if ( ! current_user_can( 'activate_plugins' ) ) {
156 wp_send_json_error( [ 'message' => 'forbidden' ], 403 );
157 }
158
159 wp_send_json(
160 [
161 'installed' => self::is_marketplace_installed(),
162 'active' => is_plugin_active( self::MARKETPLACE_PLUGIN_FILE ),
163 ]
164 );
165 }
166
167 public static function activate_marketplace_plugin() {
168 check_ajax_referer( self::AJAX_ACTIVATE_NONCE_NAME );
169
170 if ( ! current_user_can( 'activate_plugins' ) ) {
171 wp_send_json_error( [ 'message' => 'forbidden' ], 403 );
172 }
173
174 activate_plugin( self::MARKETPLACE_PLUGIN_FILE );
175 wp_send_json( [] );
176 }
177
178 public static function is_marketplace_installed() {
179 return is_file( WP_PLUGIN_DIR . '/' . self::MARKETPLACE_PLUGIN_FILE )
180 || is_file( WP_CONTENT_DIR . '/mu-plugins/' . self::MARKETPLACE_PLUGIN_FILE );
181 }
182
183 private function is_plugin_install_page() {
184 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
185 return false;
186 }
187
188 $request_path = wp_parse_url( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ), PHP_URL_PATH );
189 if ( ! preg_match( '%/wp-admin/plugin-install\\.php$%', $request_path ) ) {
190 return false;
191 }
192
193 if (
194 empty( $_REQUEST['tab'] )
195 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
196 || 'upload' !== wp_unslash( $_REQUEST['tab'] )
197 || empty( $_REQUEST['mtm_marketplace_install'] )
198 ) {
199 return false;
200 }
201
202 return true;
203 }
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 }
228 }
229