PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.3
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / pages / page-mainwp-extensions.php

page-mainwp-extensions.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.3, at pages/page-mainwp-extensions.php

825 lines 44.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Extension Page
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Extensions
12 */
13 class MainWP_Extensions { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
14
15 /**
16 * Method get_class_name()
17 *
18 * Get Class Name.
19 *
20 * @return object Class name.
21 */
22 public static function get_class_name() {
23 return __CLASS__;
24 }
25
26 /**
27 * Instantiate action hooks.
28 *
29 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_class_name()
30 */
31 public static function init() {
32 /**
33 * This hook allows you to render the Extensions page header via the 'mainwp-pageheader-extensions' action.
34 *
35 * @link http://codex.mainwp.com/#mainwp-pageheader-extensions
36 *
37 * @see \MainWP_Extensions::render_header
38 */
39 add_action( 'mainwp-pageheader-extensions', array( static::get_class_name(), 'render_header' ) ); // @deprecated Use 'mainwp_pageheader_extensions' instead.
40 add_action( 'mainwp_pageheader_extensions', array( static::get_class_name(), 'render_header' ) );
41
42 /**
43 * This hook allows you to render the Extensions page footer via the 'mainwp-pagefooter-extensions' action.
44 *
45 * @link http://codex.mainwp.com/#mainwp-pagefooter-extensions
46 *
47 * @see \MainWP_Extensions::render_footer
48 */
49 add_action( 'mainwp-pagefooter-extensions', array( static::get_class_name(), 'render_footer' ) ); // @deprecated Use 'mainwp_pagefooter_extensions' instead.
50 add_action( 'mainwp_pagefooter_extensions', array( static::get_class_name(), 'render_footer' ) );
51
52 add_action( 'mainwp_help_sidebar_content', array( static::get_class_name(), 'mainwp_help_content' ) );
53
54 add_filter( 'mainwp-extensions-apigeneratepassword', array( MainWP_Extensions_Handler::get_class_name(), 'gen_api_password' ), 10, 3 );
55 add_filter( 'mainwp_extensions_apigeneratepassword', array( MainWP_Extensions_Handler::get_class_name(), 'gen_api_password' ), 10, 3 );
56 }
57
58 /**
59 * Method init_menu()
60 *
61 * Instantiate Extensions Menu.
62 *
63 * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_activation_info()
64 * @uses \MainWP\Dashboard\MainWP_Extensions_View::init_menu()
65 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
66 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::polish_ext_name()
67 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::added_on_menu()
68 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
69 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
70 */
71 public static function init_menu() { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
72 if ( ! MainWP_Menu::is_disable_menu_item( 2, 'Extensions' ) ) {
73 MainWP_Extensions_View::init_menu();
74 }
75
76 $save_extensions = array();
77
78 /**
79 * Get extensions
80 *
81 * Adds extension to MainWP system.
82 *
83 * @since 4.1
84 */
85 $init_extensions = array();
86 $init_extensions = apply_filters_deprecated( 'mainwp-getextensions', array( $init_extensions ), '4.0.7.2', 'mainwp_getextensions' ); // NOSONAR - not IP.
87 $init_extensions = apply_filters( 'mainwp_getextensions', $init_extensions );
88
89 $all_available_extensions = MainWP_Extensions_View::get_available_extensions( 'all' );
90
91 $activations_cached = get_option( 'mainwp_extensions_all_activation_cached', array() );
92
93 if ( ! is_array( $activations_cached ) ) {
94 $activations_cached = array();
95 }
96
97 $is_cached = ! empty( $activations_cached ) ? true : false;
98
99 $extraHeaders = array(
100 'IconURI' => 'Icon URI',
101 'SupportForumURI' => 'Support Forum URI',
102 'DocumentationURI' => 'Documentation URI',
103 );
104
105 $extsPages = array();
106
107 $compatible_v4_checks = array(
108 'advanced-uptime-monitor-extension/advanced-uptime-monitor-extension.php',
109 'mainwp-article-uploader-extension/mainwp-article-uploader-extension.php',
110 'mainwp-backwpup-extension/mainwp-backwpup-extension.php',
111 'boilerplate-extension/boilerplate-extension.php',
112 'mainwp-branding-extension/mainwp-branding-extension.php',
113 'mainwp-bulk-settings-manager/mainwp-bulk-settings-manager.php',
114 'mainwp-clean-and-lock-extension/mainwp-clean-and-lock-extension.php',
115 'mainwp-client-reports-extension/mainwp-client-reports-extension.php',
116 'mainwp-clone-extension/mainwp-clone-extension.php',
117 'mainwp-code-snippets-extension/mainwp-code-snippets-extension.php',
118 'mainwp-comments-extension/mainwp-comments-extension.php',
119 'mainwp-favorites-extension/mainwp-favorites-extension.php',
120 'mainwp-file-uploader-extension/mainwp-file-uploader-extension.php',
121 'mainwp-google-analytics-extension/mainwp-google-analytics-extension.php',
122 'mainwp-maintenance-extension/mainwp-maintenance-extension.php',
123 'mainwp-piwik-extension/mainwp-piwik-extension.php',
124 'mainwp-post-dripper-extension/mainwp-post-dripper-extension.php',
125 'mainwp-rocket-extension/mainwp-rocket-extension.php',
126 'mainwp-sucuri-extension/mainwp-sucuri-extension.php',
127 'mainwp-team-control/mainwp-team-control.php',
128 'mainwp-updraftplus-extension/mainwp-updraftplus-extension.php',
129 'mainwp-url-extractor-extension/mainwp-url-extractor-extension.php',
130 'mainwp-woocommerce-shortcuts-extension/mainwp-woocommerce-shortcuts-extension.php',
131 'mainwp-woocommerce-status-extension/mainwp-woocommerce-status-extension.php',
132 'mainwp-wordfence-extension/mainwp-wordfence-extension.php',
133 'wordpress-seo-extension/wordpress-seo-extension.php',
134 'mainwp-page-speed-extension/mainwp-page-speed-extension.php',
135 'mainwp-ithemes-security-extension/mainwp-ithemes-security-extension.php',
136 'mainwp-post-plus-extension/mainwp-post-plus-extension.php',
137 'mainwp-staging-extension/mainwp-staging-extension.php',
138 'mainwp-custom-post-types/mainwp-custom-post-types.php',
139 'mainwp-buddy-extension/mainwp-buddy-extension.php',
140 'mainwp-vulnerability-checker-extension/mainwp-vulnerability-checker-extension.php',
141 'mainwp-timecapsule-extension/mainwp-timecapsule-extension.php',
142 'activity-log-mainwp/activity-log-mainwp.php',
143 );
144 include_once ABSPATH . '/wp-admin/includes/plugin.php'; // NOSONAR - WP compatible.
145
146 $deactivated_imcompatible = array();
147 foreach ( $init_extensions as $extension ) {
148 $slug = plugin_basename( $extension['plugin'] );
149 $plugin_data = get_plugin_data( $extension['plugin'], true, false );
150 $file_data = get_file_data( $extension['plugin'], $extraHeaders );
151
152 if ( ! isset( $plugin_data['Name'] ) || ( '' === $plugin_data['Name'] ) ) {
153 continue;
154 }
155
156 if ( in_array( $slug, $compatible_v4_checks ) ) {
157 $check_minver = '3.99999';
158 if ( 'advanced-uptime-monitor-extension/advanced-uptime-monitor-extension.php' === $slug ) {
159 $check_minver = '4.6.2';
160 } elseif ( 'activity-log-mainwp/activity-log-mainwp.php' === $slug ) {
161 $check_minver = '1.0.5';
162 }
163
164 if ( isset( $plugin_data['Version'] ) && version_compare( $plugin_data['Version'], $check_minver, '<' ) ) {
165 $deactivated_imcompatible[] = $plugin_data['Name'];
166 deactivate_plugins( $slug, true );
167 continue;
168 }
169 }
170
171 $extension['slug'] = $slug;
172
173 if ( ! isset( $extension['name'] ) ) {
174 $extension['name'] = $plugin_data['Name'];
175 }
176 $extension['version'] = $plugin_data['Version'];
177 $extension['description'] = $plugin_data['Description'];
178 $extension['author'] = $plugin_data['Author'];
179 $extension['icon'] = isset( $extension['icon'] ) ? trim( $extension['icon'] ) : '';
180 $extension['iconURI'] = $file_data['IconURI'];
181 $extension['SupportForumURI'] = $file_data['SupportForumURI'];
182 $extension['DocumentationURI'] = $file_data['DocumentationURI'];
183 $extension['page'] = 'Extensions-' . str_replace( ' ', '-', ucwords( str_replace( '-', ' ', dirname( $slug ) ) ) );
184
185 if ( isset( $extension['apiManager'] ) && $extension['apiManager'] ) {
186
187 $api_slug = dirname( $slug );
188
189 if ( $is_cached ) {
190 $options = isset( $activations_cached[ $api_slug ] ) ? $activations_cached[ $api_slug ] : array();
191 } else {
192 $options = MainWP_Api_Manager::instance()->get_activation_info( $api_slug );
193 $activations_cached[ $api_slug ] = $options;
194 }
195
196 if ( ! is_array( $options ) ) {
197 $options = array();
198 }
199
200 $extension['api_key'] = isset( $options['api_key'] ) ? $options['api_key'] : '';
201 $extension['activated_key'] = isset( $options['activated_key'] ) ? $options['activated_key'] : 'Deactivated';
202 $extension['deactivate_checkbox'] = isset( $options['deactivate_checkbox'] ) ? $options['deactivate_checkbox'] : 'off';
203 $extension['product_id'] = isset( $options['product_id'] ) ? $options['product_id'] : '';
204 $extension['instance_id'] = isset( $options['instance_id'] ) ? $options['instance_id'] : '';
205 $extension['software_version'] = isset( $options['software_version'] ) ? $options['software_version'] : '';
206 $extension['mainwp_version'] = isset( $options['mainwp_version'] ) ? $options['mainwp_version'] : '';
207
208 if ( isset( $options['product_item_id'] ) ) {
209 $extension['product_item_id'] = $options['product_item_id'];
210 }
211 }
212
213 $ext_slug = dirname( $slug );
214 if ( isset( $all_available_extensions[ $ext_slug ] ) ) {
215 $extension['type'] = $all_available_extensions[ $ext_slug ]['type']; // to fix.
216 }
217
218 $save_extensions[] = $extension;
219 if ( \mainwp_current_user_can( 'extension', dirname( $slug ) ) ) {
220 $callback = isset( $extension['callback'] ) ? $extension['callback'] : '';
221 $menu_name = MainWP_Extensions_Handler::polish_ext_name( $extension );
222 if ( MainWP_Extensions_Handler::added_on_menu( $slug ) ) {
223 $_page = add_submenu_page( 'mainwp_tab', $extension['name'], $menu_name, 'read', $extension['page'], $callback );
224 } else {
225 $_page = add_submenu_page( 'mainwp_tab', $extension['name'], '<div class="mainwp-hidden">' . $extension['name'] . '</div>', 'read', $extension['page'], $callback );
226 }
227
228 if ( isset( $extension['on_load_callback'] ) && ! empty( $extension['on_load_callback'] ) ) {
229 add_action( 'load-' . $_page, $extension['on_load_callback'] );
230 }
231
232 $_item = array(
233 'title' => $menu_name,
234 'slug' => $extension['page'],
235 'href' => isset( $extension['href'] ) ? $extension['href'] : '',
236 );
237
238 $extsPages[] = $_item;
239 }
240 }
241
242 if ( ! empty( $deactivated_imcompatible ) ) {
243 set_transient( 'mainwp_transient_deactivated_incomtible_exts', $deactivated_imcompatible );
244 }
245
246 MainWP_Utility::update_option( 'mainwp_extensions', $save_extensions );
247 MainWP_Extensions_Handler::get_extensions( true ); // forced reload.
248
249 if ( ! $is_cached ) {
250 update_option( 'mainwp_extensions_all_activation_cached', $activations_cached );
251 }
252 static::init_left_menu( $extsPages );
253 }
254
255 /**
256 * Method init_left_menu()
257 *
258 * Initiate top level Extensions Menues.
259 *
260 * @param array $extPages List of extension pages.
261 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
262 * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
263 * @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_left_menu()
264 */
265 public static function init_left_menu( $extPages ) {
266 $subPages = array();
267 if ( ! MainWP_Menu::is_disable_menu_item( 2, 'Extensions' ) ) {
268 MainWP_Menu::add_left_menu(
269 array(
270 'title' => esc_html__( 'Extensions', 'mainwp' ),
271 'parent_key' => 'mainwp_tab',
272 'slug' => 'Extensions',
273 'href' => 'admin.php?page=Extensions',
274 'icon' => '<i class="puzzle piece icon"></i>',
275 ),
276 0
277 );
278
279 $init_sub_subleftmenu = array(
280 array(
281 'title' => esc_html__( 'Manage Extensions', 'mainwp' ),
282 'parent_key' => 'Extensions',
283 'href' => 'admin.php?page=Extensions',
284 'slug' => 'Extensions',
285 'right' => '',
286 ),
287 );
288
289 MainWP_Menu::init_subpages_left_menu( $subPages, $init_sub_subleftmenu, 'Extensions', 'Extensions' );
290
291 foreach ( $init_sub_subleftmenu as $item ) {
292 if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
293 continue;
294 }
295 MainWP_Menu::add_left_menu( $item, 2 );
296 }
297
298 if ( ! empty( $extPages ) ) {
299
300 $init_sub_subleftmenu = array();
301 $slug = '';
302 MainWP_Menu::init_subpages_left_menu( $extPages, $init_sub_subleftmenu, 'Extensions', $slug );
303
304 foreach ( $init_sub_subleftmenu as $item ) {
305 if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
306 continue;
307 }
308 MainWP_Menu::add_left_menu( $item, 2 );
309 }
310 }
311 }
312 }
313
314 /**
315 * Method init_subpages_menu()
316 *
317 * Initiate Extensions Subpage Menu.
318 *
319 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
320 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::added_on_menu()
321 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::polish_ext_name()
322 */
323 public static function init_subpages_menu() {
324 $exts = MainWP_Extensions_Handler::get_extensions();
325 if ( empty( $exts ) ) {
326 return;
327 }
328 $html = '';
329 foreach ( $exts as $extension ) {
330 if ( defined( 'MWP_TEAMCONTROL_PLUGIN_SLUG' ) && ( MWP_TEAMCONTROL_PLUGIN_SLUG === $extension['slug'] ) && ! \mainwp_current_user_can( 'extension', dirname( MWP_TEAMCONTROL_PLUGIN_SLUG ) ) ) {
331 continue;
332 }
333 if ( MainWP_Extensions_Handler::added_on_menu( $extension['slug'] ) ) {
334 continue;
335 }
336 $menu_name = MainWP_Extensions_Handler::polish_ext_name( $extension );
337
338 if ( isset( $extension['direct_page'] ) ) {
339 $html .= '<a href="' . esc_url( admin_url( 'admin.php?page=' . $extension['direct_page'] ) ) . '" class="mainwp-submenu">' . $menu_name . '</a>';
340 } else {
341 $html .= '<a href="' . esc_url( admin_url( 'admin.php?page=' . $extension['page'] ) ) . '" class="mainwp-submenu">' . $menu_name . '</a>';
342 }
343 }
344 if ( empty( $html ) ) {
345 return;
346 }
347 ?>
348 <div id="menu-mainwp-Extensions" class="mainwp-submenu-wrapper" xmlns="http://www.w3.org/1999/html">
349 <div class="wp-submenu sub-open" style="">
350 <div class="mainwp_boxout mainwp-submenu-wide">
351 <div class="mainwp_boxoutin"></div>
352 <?php echo $html; // phpcs:ignore WordPress.Security.EscapeOutput ?>
353 </div>
354 </div>
355 </div>
356 <?php
357 }
358
359
360 /**
361 * Method ajax_get_purchased_extensions()
362 *
363 * Get purchased MainWP Extensions.
364 *
365 * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_purchased_extension()
366 * @uses \MainWP\Dashboard\MainWP_Api_Manager::check_response_for_intall_errors()
367 * @uses \MainWP\Dashboard\MainWP_Extensions_View::get_available_extensions()
368 * @uses \MainWP\Dashboard\MainWP_Extensions_View::get_extension_groups()
369 * @uses \MainWP\Dashboard\MainWP_Post_Handler::secure_request()
370 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
371 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
372 */
373 public static function ajax_get_purchased_extensions() { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
374
375 MainWP_Post_Handler::instance()->secure_request( 'mainwp_extension_getpurchased' );
376
377 $api_key = isset( $_POST['api_key'] ) ? trim( wp_unslash( $_POST['api_key'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
378
379 $all_available_extensions_compatible_api_response = array();
380 $all_free_pro_exts = array();
381 $all_org_exts = array();
382 $map_extensions_group = array();
383 $purchased_data = array();
384
385 $all_groups = MainWP_Extensions_View::get_extension_groups();
386
387 $grouped_exts = array(
388 'others' => '',
389 'all' => '',
390 );
391
392 foreach ( MainWP_Extensions_View::get_available_extensions( 'all' ) as $ext ) {
393 $all_available_extensions_compatible_api_response[ $ext['product_id'] ] = $ext;
394 $map_extensions_group[ $ext['product_id'] ] = current( $ext['group'] );
395 if ( 'free' === $ext['type'] || 'pro' === $ext['type'] ) {
396 $all_free_pro_exts[ $ext['product_id'] ] = $ext['product_id'];
397 } elseif ( 'org' === $ext['type'] ) {
398 $all_org_exts[ $ext['product_id'] ] = $ext['product_id'];
399 }
400 }
401
402 $extensions = MainWP_Extensions_Handler::get_extensions();
403 $installed_softwares = array();
404
405 foreach ( $extensions as $extension ) {
406 if ( isset( $extension['type'] ) ) {
407 if ( 'free' === $extension['type'] || 'pro' === $extension['type'] ) {
408 if ( isset( $extension['product_id'] ) && ! empty( $extension['product_id'] ) ) {
409 $installed_softwares[ $extension['product_id'] ] = $extension['product_id'];
410 }
411 } elseif ( 'org' === $extension['type'] ) {
412 $ext_slug = dirname( $extension['slug'] );
413 $installed_softwares[ $ext_slug ] = $ext_slug;
414 }
415 }
416 }
417
418 $all_disabled_extensions = MainWP_Extensions_Handler::get_extensions_disabled( true );
419
420 foreach ( $all_disabled_extensions as $ext ) {
421 $installed_softwares[ $ext['product_id'] ] = $ext['product_id'];
422 }
423
424 $not_purchased_exts = $all_free_pro_exts;
425 $not_installed_org_exts = array_diff_key( $all_org_exts, $installed_softwares );
426 $installing_exts = $not_installed_org_exts;
427
428 if ( ! empty( $api_key ) ) {
429
430 $data = MainWP_Api_Manager::instance()->get_purchased_extension( $api_key );
431
432 $result = json_decode( $data, true );
433 $return = array();
434
435 if ( is_array( $result ) ) {
436 if ( isset( $result['success'] ) && $result['success'] ) {
437 $purchased_data = ( isset( $result['purchased_data'] ) && is_array( $result['purchased_data'] ) ) ? $result['purchased_data'] : array();
438 $not_purchased_exts = array_diff_key( $all_free_pro_exts, $purchased_data );
439 $installing_exts = array_diff_key( $purchased_data, $installed_softwares );
440 $installing_exts = array_merge( $installing_exts, $not_installed_org_exts );
441 } elseif ( isset( $result['error'] ) ) {
442 $return = array( 'error' => $result['error'] );
443 }
444 } else {
445 $apisslverify = get_option( 'mainwp_api_sslVerifyCertificate' );
446 if ( 1 === $apisslverify ) {
447 MainWP_Utility::update_option( 'mainwp_api_sslVerifyCertificate', 0 );
448 $return['retry_action'] = 1;
449 }
450 }
451
452 if ( ! empty( $return ) ) {
453 wp_send_json( $return );
454 }
455 }
456
457 foreach ( $all_available_extensions_compatible_api_response as $product_id => $ext ) {
458
459 $item_html = '';
460 $error = '';
461 $ext_source_label = '';
462 $type = '';
463 $notice = '';
464 $integration_type = '';
465 $pri = (int) $ext['privacy'];
466
467 if ( 0 === $pri ) {
468 $integration_type = 'standalone-extension';
469 } elseif ( 1 === $pri ) {
470 $integration_type = 'api-extension';
471 } elseif ( 2 === $pri ) {
472 $integration_type = 'plugin-extension';
473 }
474
475 $item_slug = MainWP_Utility::get_dir_slug( $ext['slug'] );
476
477 $privacy = '<a href="#" class="extension-privacy-info-link" base-slug="' . esc_attr( $item_slug ) . '" style="text-decoration:none"> <i class="shield alternate small icon"></i></a>';
478
479 $new = '';
480
481 $software_title = MainWP_Extensions_Handler::polish_string_name( $ext['title'] );
482
483 if ( ! empty( $ext['type'] ) ) {
484 $type = $ext['type'];
485 if ( 'free' === $type ) {
486 $ext_source_label = '<span class="ui mini green label">FREE</span>';
487 } elseif ( 'pro' === $type ) {
488 $ext_source_label = '<span class="ui mini blue label">PRO</span>';
489 } elseif ( 'org' === $type ) {
490 $ext_source_label = '<span class="ui mini grey label">.ORG</span>';
491 }
492 }
493
494 if ( isset( $ext['release_date'] ) && ( time() - $ext['release_date'] < MONTH_IN_SECONDS ) ) {
495 $new = '<span class="ui mini green label">NEW!</span>';
496 }
497
498 if ( 'MainWP WordPress SEO Extension' === $product_id || 'seopress-for-mainwp' === $product_id ) {
499 $notice = ' <i class="info circle small icon"></i>';
500 }
501
502 $ext_source_label .= '&nbsp;';
503
504 if ( isset( $installing_exts[ $product_id ] ) ) {
505
506 $product_info = isset( $installing_exts[ $product_id ] ) ? $installing_exts[ $product_id ] : array();
507 if ( ! is_array( $product_info ) ) {
508 $product_info = array();
509 }
510
511 if ( 'free' === $type || 'pro' === $type ) {
512
513 if ( $product_info && isset( $product_info['package'] ) && ! empty( $product_info['package'] ) ) {
514
515 /**
516 * API Manager Upgrade URL
517 *
518 * Filters the Upgrade URL for extensions.
519 *
520 * @since Unknown
521 * @ignore
522 */
523 $package_url = apply_filters( 'mainwp_api_manager_upgrade_package_url', $product_info['package'], $product_info );
524
525 $item_html = '
526 <div class="item extension extension-to-install ' . esc_attr( $integration_type ) . '" download-link="' . esc_url( $package_url ) . '" plugin-slug="" product-id="' . esc_attr( $product_id ) . '" slug="' . esc_attr( $ext['slug'] ) . '">
527 <div class="ui stackable grid">
528 <div class="two column row">
529 <div class="column"><span class="ui checkbox"><input type="checkbox" status="queue"><label>' . $ext_source_label . '<strong><a href="' . esc_url( $ext['link'] ) . '" target="_blank">' . esc_html( $software_title ) . '</a>' . $privacy . ' ' . $notice . ' ' . $new . '</strong></label></span></div>
530 <div class="right aligned column"><span class="installing-extension" status="queue"></span></div>
531 </div>
532 </div>
533 </div>';
534
535 } elseif ( isset( $product_info['error'] ) && ! empty( $product_info['error'] ) ) {
536 $error = MainWP_Api_Manager::instance()->check_response_for_intall_errors( $product_info, $software_title );
537 } else {
538 $error = esc_html__( 'Undefined error occurred. Please try again.', 'mainwp' );
539 }
540
541 if ( ! empty( $error ) ) {
542 $item_html = '
543 <div class="item extension ' . esc_attr( $integration_type ) . '" product-id="' . esc_attr( $product_id ) . '">
544 <div class="ui stackable grid">
545 <div class="two column row">
546 <div class="column"><span class="ui checkbox"><input type="checkbox" disabled="disabled"><label>' . $ext_source_label . ' <a href="' . esc_url( $ext['link'] ) . '" target="_blank">' . esc_html( $software_title ) . '</a>' . $privacy . ' ' . $notice . ' ' . $new . '</label></span></div>
547 <div class="right aligned column"><span data-tooltip="' . $error . '" data-inverted="" data-position="left center"><i class="times red icon"></i></span></div>
548 </div>
549 </div>
550 </div>';
551 }
552 } elseif ( 'org' === $type ) {
553 $item_html = '
554 <div class="item extension extension-to-install ' . esc_attr( $integration_type ) . '" download-link="" plugin-slug="' . esc_attr( $ext['slug'] ) . '" product-id="' . esc_attr( $product_id ) . '" slug="' . esc_attr( $ext['slug'] ) . '">
555 <div class="ui stackable grid">
556 <div class="two column row">
557 <div class="column"><span class="ui checkbox"><input type="checkbox" status="queue"><label>' . $ext_source_label . '<strong><a href="' . esc_url( $ext['link'] ) . '" target="_blank">' . esc_html( $software_title ) . '</a>' . $privacy . ' ' . $notice . ' ' . $new . '</strong></label></span></div>
558 <div class="right aligned column"><span class="installing-extension" status="queue"></span></div>
559 </div>
560 </div>
561 </div>';
562 }
563 } elseif ( isset( $not_purchased_exts[ $product_id ] ) ) {
564 if ( 'free' === $type || 'pro' === $type ) {
565 $item_html = '
566 <div class="item extension ' . esc_attr( $integration_type ) . '" product-id="' . esc_attr( $product_id ) . '" slug="' . esc_attr( $ext['slug'] ) . '">
567 <div class="ui stackable grid">
568 <div class="two column row">
569 <div class="column"><span class="ui checkbox"><input type="checkbox" disabled="disabled"><label>' . $ext_source_label . ' <a href="' . esc_url( $ext['link'] ) . '" target="_blank">' . esc_html( $software_title ) . '</a>' . $privacy . ' ' . $notice . ' ' . $new . '</label></span></div>
570 <div class="right aligned column"><a href="' . $ext['link'] . '" target="_blank" data-tooltip="' . esc_html__( 'Extension not purchased. Click to find out more.', 'mainwp' ) . '" data-position="left center" data-inverted=""><i class="info blue icon"></i></a></div>
571 </div>
572 </div>
573 </div>';
574 } elseif ( 'org' === $type ) {
575 $item_html = '
576 <div class="item extension ' . esc_attr( $integration_type ) . '" product-id="' . esc_attr( $product_id ) . '" slug="' . esc_attr( $ext['slug'] ) . '">
577 <div class="ui stackable grid">
578 <div class="two column row">
579 <div class="column"><span class="ui checkbox"><input type="checkbox" disabled="disabled"><label>' . $ext_source_label . ' <a href="' . esc_url( $ext['link'] ) . '" target="_blank">' . esc_html( $software_title ) . '</a>' . $privacy . ' ' . $notice . ' ' . $new . '</label></span></div>
580 <div class="right aligned column"><a href="' . $ext['url'] . '" target="_blank" data-tooltip="' . esc_html__( 'Extension not installed. Click to find out more.', 'mainwp' ) . '" data-position="left center" data-inverted=""><i class="info blue icon"></i></a></div>
581 </div>
582 </div>
583 </div>';
584 }
585 } elseif ( isset( $installed_softwares[ $product_id ] ) ) {
586 $item_html = '
587 <div class="item extension ' . esc_attr( $integration_type ) . '" product-id="' . esc_attr( $product_id ) . '" slug="' . esc_attr( $ext['slug'] ) . '">
588 <div class="ui stackable grid">
589 <div class="two column row">
590 <div class="column"><span class="ui checkbox"><input type="checkbox" disabled="disabled"><label>' . $ext_source_label . ' <a href="' . esc_url( $ext['link'] ) . '" target="_blank">' . esc_html( $software_title ) . '</a> ' . $notice . '</label></span>' . $privacy . ' ' . $new . '</div>
591 <div class="right aligned column">Installed</div>
592 </div>
593 </div>
594 </div>';
595 }
596
597 $group_id = isset( $map_extensions_group[ $product_id ] ) ? $map_extensions_group[ $product_id ] : false;
598 if ( ! empty( $group_id ) && isset( $all_groups[ $group_id ] ) ) {
599 if ( isset( $grouped_exts[ $group_id ] ) ) {
600 $grouped_exts[ $group_id ] .= $item_html;
601 } else {
602 $grouped_exts[ $group_id ] = $item_html;
603 }
604 } else {
605 $grouped_exts['others'] .= $item_html;
606 }
607 $grouped_exts['all'] .= $item_html;
608 }
609
610 $html = '<div class="mainwp-installing-extensions">';
611
612 if ( empty( $installing_exts ) && count( $purchased_data ) === count( $all_free_pro_exts ) ) {
613 $html .= '<div class="ui message yellow">' . esc_html__( 'All purchased extensions already installed.', 'mainwp' ) . '</div>';
614 } else {
615 if ( isset( $not_purchased_exts ) && ! empty( $not_purchased_exts ) ) {
616 $html .= '<div class="ui message info">' . esc_html__( 'You have access to all our Free and third-party Extensions on WP.org and any that you have registered for, but you DO NOT need to install them. ', 'mainwp' );
617 $html .= '<br /><br />';
618 $html .= esc_html__( 'To avoid information overload, we highly recommend adding Extensions one at a time and as you need them. Skip any Extension you do not want to install at this time.', 'mainwp' );
619 $html .= '<br /><br />';
620 $html .= sprintf( esc_html__( 'After installing all your selected Extensions, close the modal by clicking the Close button and %1$sactivate Extensions API license%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/activate-extensions-api/" target="_blank">', '</a> <i class="external alternate icon"></i>' ) . '</div>'; // NOSONAR - noopener - open safe.
621 } else {
622 $html .= '<div class="ui message info">' . esc_html__( 'You have access to the MainWP Pro plan, which gives you access to all MainWP-created Extensions, but you DO NOT need to install all of them.', 'mainwp' );
623 $html .= '<br /><br />';
624 $html .= esc_html__( 'To avoid information overload, we highly recommend adding Extensions one at a time and as you need them. Skip any Extension you do not want to install at this time.', 'mainwp' );
625 $html .= '<br /><br />';
626 $html .= sprintf( esc_html__( 'After installing all your selected Extensions, close the modal by clicking the Close button and %1$sactivate Extensions API license%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/activate-extensions-api/" target="_blank">', '</a> <i class="external alternate icon"></i>' ) . '</div>'; // NOSONAR - noopener - open safe.
627 }
628
629 $html .= '<div id="mainwp-bulk-activating-extensions-status" class="ui message" style="display:none;"></div>';
630
631 $html .= '<div class="ui secondary green pointing tabular stackable menu" id="mainwp-install-extensions-menu">';
632 foreach ( $all_groups as $gr_id => $gr_name ) {
633 if ( isset( $grouped_exts[ $gr_id ] ) ) {
634 $html .= '<a class="item" data-tab="' . $gr_id . '">' . $gr_name . '</a>';
635 }
636 }
637
638 if ( isset( $grouped_exts['others'] ) && ! empty( $grouped_exts['others'] ) ) {
639 $html .= '<a class="item" data-tab="other">' . esc_html__( 'Other', 'mainwp' ) . '</a>';
640 }
641
642 $html .= '<a class="item" data-tab="search"><i class="search icon"></i></a>';
643
644 $html .= '</div>';
645
646 foreach ( $all_groups as $gr_id => $gr_name ) {
647 if ( isset( $grouped_exts[ $gr_id ] ) && 'all' !== $gr_id ) {
648 $html .= '<div class="ui tab" data-tab="' . $gr_id . '">';
649 $html .= '<div class="ui hidden divider"></div>';
650 $html .= '<h3>' . $gr_name . '</h3>';
651 $html .= '<div class="ui hidden divider"></div>';
652 $html .= '<div class="ui relaxed divided list">';
653 $html .= $grouped_exts[ $gr_id ];
654 $html .= '</div>';
655 $html .= '</div>';
656 }
657 }
658
659 if ( isset( $grouped_exts['others'] ) && ! empty( $grouped_exts['others'] ) ) {
660 $html .= '<div class="ui tab" data-tab="other">';
661 $html .= '<h3>Other</h3>';
662 $html .= '<div class="ui relaxed divided list">';
663 $html .= $grouped_exts['others'];
664 $html .= '</div>';
665 $html .= '</div>';
666 }
667
668 $html .= '<div class="ui tab" data-tab="search">';
669 $html .= '<h3>Search Extensions</h3>';
670 $html .= '<div id="mainwp-search-extensions-install" class="ui fluid search">
671 <div class="ui icon fluid input">
672 <input class="prompt" id="mainwp-search-extensions-install-input" type="text" placeholder="Find extension...">
673 <i class="search icon"></i>
674 </div>
675 </div>';
676 $html .= '<div class="ui relaxed divided list" id="mainwp-extensions-to-install-list">';
677 $html .= $grouped_exts['all'];
678 $html .= '</div>';
679 $html .= '</div>';
680
681 }
682 $html .= '<div class="ui hidden divider"></div>';
683 $html .= '<div class="ui secondary segment">';
684 $html .= '<div class="ui checkbox"><input type="checkbox" checked="" id="mainwp-standalone-extensions-filer" name="mainwp-standalone-extensions-filer"><label>' . esc_html__( 'Show standalone extensions', 'mainwp' ) . '</label></div><br/>';
685 $html .= '<div class="ui checkbox"><input type="checkbox" checked="" id="mainwp-api-extensions-filer" name="mainwp-api-extensions-filer"><label>' . esc_html__( 'Show extensions that integrate with 3rd party API', 'mainwp' ) . '</label></div><br/>';
686 $html .= '<div class="ui checkbox"><input type="checkbox" checked="" id="mainwp-plugin-extensions-filer" name="mainwp-plugin-extensions-filer"><label>' . esc_html__( 'Show extensions that integrate with 3rd party plugin', 'mainwp' ) . '</label></div>';
687 $html .= '</div>';
688 $html .= '<div class="ui hidden divider"></div>';
689 $html .= '<div class="ui secondary segment">';
690 $html .= '<span class="ui mini green label">FREE</span> - ' . esc_html__( 'Free extension developed by MainWP', 'mainwp' ) . '<br/>';
691 $html .= '<span class="ui mini blue label">PRO</span> - ' . esc_html__( 'Premium extension developed by MainWP', 'mainwp' ) . '<br/>';
692 $html .= '<span class="ui mini grey label">.ORG</span> - ' . esc_html__( 'Free extension developed by 3rd party author, available on WordPress.org', 'mainwp' );
693 $html .= '<div class="ui hidden fitted divider"></div>';
694 $html .= '<i class="info circle icon"></i> ' . esc_html__( 'Extension requires the corresponding plugin on your MainWP Dashboard site too.', 'mainwp' ) . '<br/>';
695 $html .= '<i class="shield alternate icon"></i> ' . esc_html__( 'Shows the extension privacy info.', 'mainwp' ) . '<br/>';
696 $html .= '</div>';
697
698 $html .= '<script>jQuery( "#mainwp-install-extensions-menu .item" ).tab();</script>';
699 $html .= '<script type="text/javascript">
700 jQuery( document ).ready( function () {
701 jQuery( "#mainwp-search-extensions-install-input" ).on( "keyup", function () {
702 let searchQuery = jQuery( this ).val().toLowerCase();
703 let extensions = jQuery( "#mainwp-extensions-to-install-list" ).find( ".item.extension" );
704 for ( let i = 0; i < extensions.length; i++ ) {
705 let currentExtension = jQuery( extensions[i] );
706 let extensionTitle = jQuery( currentExtension ).attr( "product-id" ).toLowerCase();
707 if ( extensionTitle.indexOf( searchQuery ) > -1 ) {
708 currentExtension.show();
709 } else {
710 currentExtension.hide();
711 }
712 }
713 } );
714 jQuery( "#mainwp-standalone-extensions-filer" ).on( "change", function () {
715 jQuery( "#mainwp-get-purchased-extensions-modal .ui.relaxed.divided.list .item.extension.standalone-extension" ).toggle( 200 );
716 } );
717 jQuery( "#mainwp-api-extensions-filer" ).on( "change", function () {
718 jQuery( "#mainwp-get-purchased-extensions-modal .ui.relaxed.divided.list .item.extension.api-extension" ).toggle( 200 );
719 } );
720 jQuery( "#mainwp-plugin-extensions-filer" ).on( "change", function () {
721 jQuery( "#mainwp-get-purchased-extensions-modal .ui.relaxed.divided.list .item.extension.plugin-extension" ).toggle( 200 );
722 } );
723 } );
724 </script>';
725
726 if ( ! empty( $installing_exts ) ) {
727 $html .= '<p>
728 <span class="extension_api_loading">
729 <i class="ui active inline loader tiny" style="display: none;"></i><span class="status hidden"></span>
730 </span>
731 </p> ';
732 }
733
734 $html .= '</div>';
735 $return = array(
736 'result' => 'SUCCESS',
737 'data' => $html,
738 );
739
740 wp_send_json( $return );
741 }
742
743 /**
744 * Method render_header()
745 *
746 * Render page header.
747 *
748 * @param string $shownPage The page slug shown at this moment.
749 *
750 * @uses \MainWP\Dashboard\MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook()
751 * @uses \MainWP\Dashboard\MainWP_Extensions_View::render_header()
752 */
753 public static function render_header( $shownPage = '' ) {
754 MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook();
755 MainWP_Extensions_View::render_header( $shownPage );
756 }
757
758 /**
759 * Method render_footer()
760 *
761 * Render page footer.
762 *
763 * @param string $shownPage The page slug shown at this moment.
764 *
765 * @uses \MainWP\Dashboard\MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook()
766 * @uses \MainWP\Dashboard\MainWP_Extensions_View::render_footer()
767 */
768 public static function render_footer( $shownPage ) {
769 MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook();
770 MainWP_Extensions_View::render_footer( $shownPage );
771 }
772
773 /**
774 * Method render()
775 *
776 * Render page content.
777 *
778 * @uses \MainWP\Dashboard\MainWP_Extensions_View::render()
779 * @uses \MainWP\Dashboard\MainWP_UI::render_top_header()
780 */
781 public static function render() {
782
783 $params = array(
784 'title' => esc_html__( 'Extensions', 'mainwp' ),
785 );
786 MainWP_UI::render_top_header( $params );
787
788 MainWP_Extensions_View::render();
789 echo '</div>';
790 }
791
792 /**
793 * Method mainwp_help_content()
794 *
795 * Creates the MainWP Help Documentation List for the help component in the sidebar.
796 */
797 public static function mainwp_help_content() {
798 if ( isset( $_GET['page'] ) && 'Extensions' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
799 ?>
800 <p><?php esc_html_e( 'If you need help with your MainWP Extensions, please review following help documents', 'mainwp' ); ?></p>
801 <div class="ui list">
802 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-extensions/" target="_blank"><i class="fa fa-book"></i> What are the MainWP Extensions</a></div> <?php // NOSONAR - noopener - open safe. ?>
803 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-extensions/#order-extensions" target="_blank"><i class="fa fa-book"></i> Order Extension(s)</a></div> <?php // NOSONAR - noopener - open safe. ?>
804 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-extensions/#install-extensions" target="_blank"><i class="fa fa-book"></i> Install Extension(s)</a></div> <?php // NOSONAR - noopener - open safe. ?>
805 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-extensions/#activate-extensions" target="_blank"><i class="fa fa-book"></i> Activate Extension(s) API</a></div> <?php // NOSONAR - noopener - open safe. ?>
806 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-extensions/#update-extensions" target="_blank"><i class="fa fa-book"></i> Updating Extension(s)</a></div> <?php // NOSONAR - noopener - open safe. ?>
807 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-extensions/#remove-unneeded-extensions" target="_blank"><i class="fa fa-book"></i> Remove Extension(s)</a></div> <?php // NOSONAR - noopener - open safe. ?>
808 </div>
809 <?php
810 /**
811 * Action: mainwp_extensions_help_item
812 *
813 * Fires at the bottom of the help articles list in the Help sidebar on the Extensions page.
814 *
815 * Suggested HTML markup:
816 *
817 * <div class="item"><a href="Your custom URL">Your custom text</a></div>
818 *
819 * @since 5.2
820 */
821 do_action( 'mainwp_extensions_help_item' );
822 }
823 }
824 }
825