PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.6.0.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.6.0.1
6.2.3 6.2.2 6.2.1 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 All 156 releases
mainwp / pages / page-mainwp-extensions.php

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

813 lines 36.0 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 {
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( self::get_class_name(), 'render_header' ) ); // @deprecated Use 'mainwp_pageheader_extensions' instead.
40 add_action( 'mainwp_pageheader_extensions', array( self::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( self::get_class_name(), 'render_footer' ) ); // @deprecated Use 'mainwp_pagefooter_extensions' instead.
50 add_action( 'mainwp_pagefooter_extensions', array( self::get_class_name(), 'render_footer' ) );
51
52 add_action( 'mainwp_help_sidebar_content', array( self::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 -- 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' );
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';
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 if ( isset( $options['product_item_id'] ) ) {
207 $extension['product_item_id'] = $options['product_item_id'];
208 }
209 }
210
211 $ext_slug = dirname( $slug );
212 if ( isset( $all_available_extensions[ $ext_slug ] ) ) {
213 $extension['type'] = $all_available_extensions[ $ext_slug ]['type']; // to fix.
214 }
215
216 $save_extensions[] = $extension;
217 if ( mainwp_current_user_have_right( 'extension', dirname( $slug ) ) ) {
218 $callback = isset( $extension['callback'] ) ? $extension['callback'] : '';
219 $menu_name = MainWP_Extensions_Handler::polish_ext_name( $extension );
220 if ( MainWP_Extensions_Handler::added_on_menu( $slug ) ) {
221 $_page = add_submenu_page( 'mainwp_tab', $extension['name'], $menu_name, 'read', $extension['page'], $callback );
222 } else {
223 $_page = add_submenu_page( 'mainwp_tab', $extension['name'], '<div class="mainwp-hidden">' . $extension['name'] . '</div>', 'read', $extension['page'], $callback );
224 }
225
226 if ( isset( $extension['on_load_callback'] ) && ! empty( $extension['on_load_callback'] ) ) {
227 add_action( 'load-' . $_page, $extension['on_load_callback'] );
228 }
229
230 $_item = array(
231 'title' => $menu_name,
232 'slug' => $extension['page'],
233 'href' => isset( $extension['href'] ) ? $extension['href'] : '',
234 );
235
236 $extsPages[] = $_item;
237 }
238 }
239
240 if ( ! empty( $deactivated_imcompatible ) ) {
241 set_transient( 'mainwp_transient_deactivated_incomtible_exts', $deactivated_imcompatible );
242 }
243
244 MainWP_Utility::update_option( 'mainwp_extensions', $save_extensions );
245 MainWP_Extensions_Handler::get_extensions( true ); // forced reload.
246
247 if ( ! $is_cached ) {
248 update_option( 'mainwp_extensions_all_activation_cached', $activations_cached );
249 }
250 self::init_left_menu( $extsPages );
251 }
252
253 /**
254 * Method init_left_menu()
255 *
256 * Initiate top level Extensions Menues.
257 *
258 * @param array $extPages List of extension pages.
259 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
260 * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
261 * @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_left_menu()
262 */
263 public static function init_left_menu( $extPages ) {
264 $subPages = array();
265 if ( ! MainWP_Menu::is_disable_menu_item( 2, 'Extensions' ) ) {
266 MainWP_Menu::add_left_menu(
267 array(
268 'title' => esc_html__( 'Extensions', 'mainwp' ),
269 'parent_key' => 'mainwp_tab',
270 'slug' => 'Extensions',
271 'href' => 'admin.php?page=Extensions',
272 'icon' => '<i class="puzzle piece icon"></i>',
273 'id' => 'menu-item-extensions',
274 ),
275 0
276 );
277
278 $init_sub_subleftmenu = array(
279 array(
280 'title' => esc_html__( 'Manage Extensions', 'mainwp' ),
281 'parent_key' => 'Extensions',
282 'href' => 'admin.php?page=Extensions',
283 'slug' => 'Extensions',
284 'right' => '',
285 ),
286 );
287
288 MainWP_Menu::init_subpages_left_menu( $subPages, $init_sub_subleftmenu, 'Extensions', 'Extensions' );
289
290 foreach ( $init_sub_subleftmenu as $item ) {
291 if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
292 continue;
293 }
294 MainWP_Menu::add_left_menu( $item, 2 );
295 }
296
297 if ( 0 < count( $extPages ) ) {
298
299 $init_sub_subleftmenu = array();
300 $slug = '';
301 MainWP_Menu::init_subpages_left_menu( $extPages, $init_sub_subleftmenu, 'Extensions', $slug );
302
303 foreach ( $init_sub_subleftmenu as $item ) {
304 if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
305 continue;
306 }
307 MainWP_Menu::add_left_menu( $item, 2 );
308 }
309 }
310 }
311 }
312
313 /**
314 * Method init_subpages_menu()
315 *
316 * Initiate Extensions Subpage Menu.
317 *
318 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
319 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::added_on_menu()
320 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::polish_ext_name()
321 */
322 public static function init_subpages_menu() {
323 $exts = MainWP_Extensions_Handler::get_extensions();
324 if ( empty( $exts ) ) {
325 return;
326 }
327 $html = '';
328 foreach ( $exts as $extension ) {
329 if ( defined( 'MWP_TEAMCONTROL_PLUGIN_SLUG' ) && ( MWP_TEAMCONTROL_PLUGIN_SLUG === $extension['slug'] ) && ! mainwp_current_user_have_right( 'extension', dirname( MWP_TEAMCONTROL_PLUGIN_SLUG ) ) ) {
330 continue;
331 }
332 if ( MainWP_Extensions_Handler::added_on_menu( $extension['slug'] ) ) {
333 continue;
334 }
335 $menu_name = MainWP_Extensions_Handler::polish_ext_name( $extension );
336
337 if ( isset( $extension['direct_page'] ) ) {
338 $html .= '<a href="' . esc_url( admin_url( 'admin.php?page=' . $extension['direct_page'] ) ) . '" class="mainwp-submenu">' . $menu_name . '</a>';
339 } else {
340 $html .= '<a href="' . esc_url( admin_url( 'admin.php?page=' . $extension['page'] ) ) . '" class="mainwp-submenu">' . $menu_name . '</a>';
341 }
342 }
343 if ( empty( $html ) ) {
344 return;
345 }
346 ?>
347 <div id="menu-mainwp-Extensions" class="mainwp-submenu-wrapper" xmlns="http://www.w3.org/1999/html">
348 <div class="wp-submenu sub-open" style="">
349 <div class="mainwp_boxout mainwp-submenu-wide">
350 <div class="mainwp_boxoutin"></div>
351 <?php echo $html; // phpcs:ignore WordPress.Security.EscapeOutput ?>
352 </div>
353 </div>
354 </div>
355 <?php
356 }
357
358
359 /**
360 * Method ajax_get_purchased_extensions()
361 *
362 * Get purchased MainWP Extensions.
363 *
364 * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_purchased_extension()
365 * @uses \MainWP\Dashboard\MainWP_Api_Manager::check_response_for_intall_errors()
366 * @uses \MainWP\Dashboard\MainWP_Extensions_View::get_available_extensions()
367 * @uses \MainWP\Dashboard\MainWP_Extensions_View::get_extension_groups()
368 * @uses \MainWP\Dashboard\MainWP_Post_Handler::secure_request()
369 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
370 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
371 */
372 public static function ajax_get_purchased_extensions() { // phpcs:ignore -- complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
373
374 MainWP_Post_Handler::instance()->secure_request( 'mainwp_extension_getpurchased' );
375
376 $api_key = isset( $_POST['api_key'] ) ? trim( wp_unslash( $_POST['api_key'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
377
378 $all_available_extensions_compatible_api_response = array();
379 $all_free_pro_exts = array();
380 $all_org_exts = array();
381 $map_extensions_group = array();
382 $purchased_data = array();
383
384 $all_groups = MainWP_Extensions_View::get_extension_groups();
385
386 $grouped_exts = array(
387 'others' => '',
388 'all' => '',
389 );
390
391 foreach ( MainWP_Extensions_View::get_available_extensions( 'all' ) as $ext ) {
392 $all_available_extensions_compatible_api_response[ $ext['product_id'] ] = $ext;
393 $map_extensions_group[ $ext['product_id'] ] = current( $ext['group'] );
394 if ( 'free' === $ext['type'] || 'pro' === $ext['type'] ) {
395 $all_free_pro_exts[ $ext['product_id'] ] = $ext['product_id'];
396 } elseif ( 'org' === $ext['type'] ) {
397 $all_org_exts[ $ext['product_id'] ] = $ext['product_id'];
398 }
399 }
400
401 $extensions = MainWP_Extensions_Handler::get_extensions();
402 $installed_softwares = array();
403
404 foreach ( $extensions as $extension ) {
405 if ( isset( $extension['type'] ) ) {
406 if ( 'free' === $extension['type'] || 'pro' === $extension['type'] ) {
407 if ( isset( $extension['product_id'] ) && ! empty( $extension['product_id'] ) ) {
408 $installed_softwares[ $extension['product_id'] ] = $extension['product_id'];
409 }
410 } elseif ( 'org' === $extension['type'] ) {
411 $ext_slug = dirname( $extension['slug'] );
412 $installed_softwares[ $ext_slug ] = $ext_slug;
413 }
414 }
415 }
416
417 $all_disabled_extensions = MainWP_Extensions_Handler::get_extensions_disabled( true );
418
419 foreach ( $all_disabled_extensions as $ext ) {
420 $installed_softwares[ $ext['product_id'] ] = $ext['product_id'];
421 }
422
423 $not_purchased_exts = $all_free_pro_exts;
424 $not_installed_org_exts = array_diff_key( $all_org_exts, $installed_softwares );
425 $installing_exts = $not_installed_org_exts;
426
427 if ( ! empty( $api_key ) ) {
428
429 $data = MainWP_Api_Manager::instance()->get_purchased_extension( $api_key );
430
431 $result = json_decode( $data, true );
432 $return = array();
433
434 if ( is_array( $result ) ) {
435 if ( isset( $result['success'] ) && $result['success'] ) {
436 $purchased_data = ( isset( $result['purchased_data'] ) && is_array( $result['purchased_data'] ) ) ? $result['purchased_data'] : array();
437 $not_purchased_exts = array_diff_key( $all_free_pro_exts, $purchased_data );
438 $installing_exts = array_diff_key( $purchased_data, $installed_softwares );
439 $installing_exts = array_merge( $installing_exts, $not_installed_org_exts );
440 } elseif ( isset( $result['error'] ) ) {
441 $return = array( 'error' => $result['error'] );
442 }
443 } else {
444 $apisslverify = get_option( 'mainwp_api_sslVerifyCertificate' );
445 if ( 1 === $apisslverify ) {
446 MainWP_Utility::update_option( 'mainwp_api_sslVerifyCertificate', 0 );
447 $return['retry_action'] = 1;
448 }
449 }
450
451 if ( ! empty( $return ) ) {
452 wp_send_json( $return );
453 }
454 }
455
456 foreach ( $all_available_extensions_compatible_api_response as $product_id => $ext ) {
457
458 $item_html = '';
459 $error = '';
460 $ext_source_label = '';
461 $type = '';
462 $notice = '';
463 $integration_type = '';
464 $pri = (int) $ext['privacy'];
465
466 if ( 0 === $pri ) {
467 $integration_type = 'standalone-extension';
468 } elseif ( 1 === $pri ) {
469 $integration_type = 'api-extension';
470 } elseif ( 2 === $pri ) {
471 $integration_type = 'plugin-extension';
472 }
473
474 $item_slug = MainWP_Utility::get_dir_slug( $ext['slug'] );
475
476 $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>';
477
478 $new = '';
479
480 $software_title = MainWP_Extensions_Handler::polish_string_name( $ext['title'] );
481
482 if ( ! empty( $ext['type'] ) ) {
483 $type = $ext['type'];
484 if ( 'free' === $type ) {
485 $ext_source_label = '<span class="ui mini green label">FREE</span>';
486 } elseif ( 'pro' === $type ) {
487 $ext_source_label = '<span class="ui mini blue label">PRO</span>';
488 } elseif ( 'org' === $type ) {
489 $ext_source_label = '<span class="ui mini grey label">.ORG</span>';
490 }
491 }
492
493 if ( isset( $ext['release_date'] ) && ( time() - $ext['release_date'] < MONTH_IN_SECONDS ) ) {
494 $new = '<span class="ui mini green label">NEW!</span>';
495 }
496
497 if ( 'MainWP WordPress SEO Extension' === $product_id || 'seopress-for-mainwp' === $product_id ) {
498 $notice = ' <i class="info circle small icon"></i>';
499 }
500
501 $ext_source_label .= '&nbsp;';
502
503 if ( isset( $installing_exts[ $product_id ] ) ) {
504
505 $product_info = isset( $installing_exts[ $product_id ] ) ? $installing_exts[ $product_id ] : array();
506 if ( ! is_array( $product_info ) ) {
507 $product_info = array();
508 }
509
510 if ( 'free' === $type || 'pro' === $type ) {
511
512 if ( $product_info && isset( $product_info['package'] ) && ! empty( $product_info['package'] ) ) {
513
514 /**
515 * API Manager Upgrade URL
516 *
517 * Filters the Upgrade URL for extensions.
518 *
519 * @since Unknown
520 * @ignore
521 */
522 $package_url = apply_filters( 'mainwp_api_manager_upgrade_package_url', $product_info['package'], $product_info );
523
524 $item_html = '
525 <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'] ) . '">
526 <div class="ui stackable grid">
527 <div class="two column row">
528 <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>
529 <div class="right aligned column"><span class="installing-extension" status="queue"></span></div>
530 </div>
531 </div>
532 </div>';
533
534 } elseif ( isset( $product_info['error'] ) && ! empty( $product_info['error'] ) ) {
535 $error = MainWP_Api_Manager::instance()->check_response_for_intall_errors( $product_info, $software_title );
536 } else {
537 $error = esc_html__( 'Undefined error occurred. Please try again.', 'mainwp' );
538 }
539
540 if ( ! empty( $error ) ) {
541 $item_html = '
542 <div class="item extension ' . esc_attr( $integration_type ) . '" product-id="' . esc_attr( $product_id ) . '">
543 <div class="ui stackable grid">
544 <div class="two column row">
545 <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>
546 <div class="right aligned column"><span data-tooltip="' . $error . '" data-inverted="" data-position="left center"><i class="times red icon"></i></span></div>
547 </div>
548 </div>
549 </div>';
550 }
551 } elseif ( 'org' === $type ) {
552 $item_html = '
553 <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'] ) . '">
554 <div class="ui stackable grid">
555 <div class="two column row">
556 <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>
557 <div class="right aligned column"><span class="installing-extension" status="queue"></span></div>
558 </div>
559 </div>
560 </div>';
561 }
562 } elseif ( isset( $not_purchased_exts[ $product_id ] ) ) {
563 if ( 'free' === $type || 'pro' === $type ) {
564 $item_html = '
565 <div class="item extension ' . esc_attr( $integration_type ) . '" product-id="' . esc_attr( $product_id ) . '" slug="' . esc_attr( $ext['slug'] ) . '">
566 <div class="ui stackable grid">
567 <div class="two column row">
568 <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>
569 <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>
570 </div>
571 </div>
572 </div>';
573 } elseif ( 'org' === $type ) {
574 $item_html = '
575 <div class="item extension ' . esc_attr( $integration_type ) . '" product-id="' . esc_attr( $product_id ) . '" slug="' . esc_attr( $ext['slug'] ) . '">
576 <div class="ui stackable grid">
577 <div class="two column row">
578 <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>
579 <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>
580 </div>
581 </div>
582 </div>';
583 }
584 } elseif ( isset( $installed_softwares[ $product_id ] ) ) {
585 $item_html = '
586 <div class="item extension ' . esc_attr( $integration_type ) . '" product-id="' . esc_attr( $product_id ) . '" slug="' . esc_attr( $ext['slug'] ) . '">
587 <div class="ui stackable grid">
588 <div class="two column row">
589 <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>
590 <div class="right aligned column">Installed</div>
591 </div>
592 </div>
593 </div>';
594 }
595
596 $group_id = isset( $map_extensions_group[ $product_id ] ) ? $map_extensions_group[ $product_id ] : false;
597 if ( ! empty( $group_id ) && isset( $all_groups[ $group_id ] ) ) {
598 if ( isset( $grouped_exts[ $group_id ] ) ) {
599 $grouped_exts[ $group_id ] .= $item_html;
600 } else {
601 $grouped_exts[ $group_id ] = $item_html;
602 }
603 } else {
604 $grouped_exts['others'] .= $item_html;
605 }
606 $grouped_exts['all'] .= $item_html;
607 }
608
609 $html = '<div class="mainwp-installing-extensions">';
610
611 if ( empty( $installing_exts ) && count( $purchased_data ) === count( $all_free_pro_exts ) ) {
612 $html .= '<div class="ui message yellow">' . esc_html__( 'All purchased extensions already installed.', 'mainwp' ) . '</div>';
613 } else {
614 if ( isset( $not_purchased_exts ) && ! empty( $not_purchased_exts ) ) {
615 $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' );
616 $html .= '<br /><br />';
617 $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' );
618 $html .= '<br /><br />';
619 $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>' ) . '</div>';
620 } else {
621 $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' );
622 $html .= '<br /><br />';
623 $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' );
624 $html .= '<br /><br />';
625 $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>' ) . '</div>';
626 }
627
628 $html .= '<div id="mainwp-bulk-activating-extensions-status" class="ui message" style="display:none;"></div>';
629
630 $html .= '<div class="ui secondary green pointing tabular stackable menu" id="mainwp-install-extensions-menu">';
631 foreach ( $all_groups as $gr_id => $gr_name ) {
632 if ( isset( $grouped_exts[ $gr_id ] ) ) {
633 $html .= '<a class="item" data-tab="' . $gr_id . '">' . $gr_name . '</a>';
634 }
635 }
636
637 if ( isset( $grouped_exts['others'] ) && ! empty( $grouped_exts['others'] ) ) {
638 $html .= '<a class="item" data-tab="other">' . esc_html__( 'Other', 'mainwp' ) . '</a>';
639 }
640
641 $html .= '<a class="item" data-tab="search"><i class="search icon"></i></a>';
642
643 $html .= '</div>';
644
645 foreach ( $all_groups as $gr_id => $gr_name ) {
646 if ( isset( $grouped_exts[ $gr_id ] ) && 'all' !== $gr_id ) {
647 $html .= '<div class="ui tab" data-tab="' . $gr_id . '">';
648 $html .= '<div class="ui hidden divider"></div>';
649 $html .= '<h3>' . $gr_name . '</h3>';
650 $html .= '<div class="ui hidden divider"></div>';
651 $html .= '<div class="ui relaxed divided list">';
652 $html .= $grouped_exts[ $gr_id ];
653 $html .= '</div>';
654 $html .= '</div>';
655 }
656 }
657
658 if ( isset( $grouped_exts['others'] ) && ! empty( $grouped_exts['others'] ) ) {
659 $html .= '<div class="ui tab" data-tab="other">';
660 $html .= '<h3>Other</h3>';
661 $html .= '<div class="ui relaxed divided list">';
662 $html .= $grouped_exts['others'];
663 $html .= '</div>';
664 $html .= '</div>';
665 }
666
667 $html .= '<div class="ui tab" data-tab="search">';
668 $html .= '<h3>Search Extensions</h3>';
669 $html .= '<div id="mainwp-search-extensions-install" class="ui fluid search">
670 <div class="ui icon fluid input">
671 <input class="prompt" id="mainwp-search-extensions-install-input" type="text" placeholder="Find extension...">
672 <i class="search icon"></i>
673 </div>
674 </div>';
675 $html .= '<div class="ui relaxed divided list" id="mainwp-extensions-to-install-list">';
676 $html .= $grouped_exts['all'];
677 $html .= '</div>';
678 $html .= '</div>';
679
680 }
681 $html .= '<div class="ui hidden divider"></div>';
682 $html .= '<div class="ui secondary segment">';
683 $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/>';
684 $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/>';
685 $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>';
686 $html .= '</div>';
687 $html .= '<div class="ui hidden divider"></div>';
688 $html .= '<div class="ui secondary segment">';
689 $html .= '<span class="ui mini green label">FREE</span> - ' . esc_html__( 'Free extension developed by MainWP', 'mainwp' ) . '<br/>';
690 $html .= '<span class="ui mini blue label">PRO</span> - ' . esc_html__( 'Premium extension developed by MainWP', 'mainwp' ) . '<br/>';
691 $html .= '<span class="ui mini grey label">.ORG</span> - ' . esc_html__( 'Free extension developed by 3rd party author, available on WordPress.org', 'mainwp' );
692 $html .= '<div class="ui hidden fitted divider"></div>';
693 $html .= '<i class="info circle icon"></i> ' . esc_html__( 'Extension requires the corresponding plugin on your MainWP Dashboard site too.', 'mainwp' ) . '<br/>';
694 $html .= '<i class="shield alternate icon"></i> ' . esc_html__( 'Shows the extension privacy info.', 'mainwp' ) . '<br/>';
695 $html .= '</div>';
696
697 $html .= '<script>jQuery( "#mainwp-install-extensions-menu .item" ).tab();</script>';
698 $html .= '<script type="text/javascript">
699 jQuery( document ).ready( function () {
700 jQuery( "#mainwp-search-extensions-install-input" ).on( "keyup", function () {
701 var searchQuery = jQuery( this ).val().toLowerCase();
702 var extensions = jQuery( "#mainwp-extensions-to-install-list" ).find( ".item.extension" );
703 for ( var i = 0; i < extensions.length; i++ ) {
704 var currentExtension = jQuery( extensions[i] );
705 var extensionTitle = jQuery( currentExtension ).attr( "product-id" ).toLowerCase();
706 if ( extensionTitle.indexOf( searchQuery ) > -1 ) {
707 currentExtension.show();
708 } else {
709 currentExtension.hide();
710 }
711 }
712 } );
713 jQuery( "#mainwp-standalone-extensions-filer" ).on( "change", function () {
714 jQuery( "#mainwp-get-purchased-extensions-modal .ui.relaxed.divided.list .item.extension.standalone-extension" ).toggle( 200 );
715 } );
716 jQuery( "#mainwp-api-extensions-filer" ).on( "change", function () {
717 jQuery( "#mainwp-get-purchased-extensions-modal .ui.relaxed.divided.list .item.extension.api-extension" ).toggle( 200 );
718 } );
719 jQuery( "#mainwp-plugin-extensions-filer" ).on( "change", function () {
720 jQuery( "#mainwp-get-purchased-extensions-modal .ui.relaxed.divided.list .item.extension.plugin-extension" ).toggle( 200 );
721 } );
722 } );
723 </script>';
724
725 if ( ! empty( $installing_exts ) ) {
726 $html .= '<p>
727 <span class="extension_api_loading">
728 <i class="ui active inline loader tiny" style="display: none;"></i><span class="status hidden"></span>
729 </span>
730 </p> ';
731 }
732
733 $html .= '</div>';
734 $return = array(
735 'result' => 'SUCCESS',
736 'data' => $html,
737 );
738
739 wp_send_json( $return );
740 }
741
742 /**
743 * Method render_header()
744 *
745 * Render page header.
746 *
747 * @param string $shownPage The page slug shown at this moment.
748 *
749 * @uses \MainWP\Dashboard\MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook()
750 * @uses \MainWP\Dashboard\MainWP_Extensions_View::render_header()
751 */
752 public static function render_header( $shownPage = '' ) {
753 MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook();
754 MainWP_Extensions_View::render_header( $shownPage );
755 }
756
757 /**
758 * Method render_footer()
759 *
760 * Render page footer.
761 *
762 * @param string $shownPage The page slug shown at this moment.
763 *
764 * @uses \MainWP\Dashboard\MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook()
765 * @uses \MainWP\Dashboard\MainWP_Extensions_View::render_footer()
766 */
767 public static function render_footer( $shownPage ) {
768 MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook();
769 MainWP_Extensions_View::render_footer( $shownPage );
770 }
771
772 /**
773 * Method render()
774 *
775 * Render page content.
776 *
777 * @uses \MainWP\Dashboard\MainWP_Extensions_View::render()
778 * @uses \MainWP\Dashboard\MainWP_UI::render_top_header()
779 */
780 public static function render() {
781
782 $params = array(
783 'title' => esc_html__( 'Extensions', 'mainwp' ),
784 );
785 MainWP_UI::render_top_header( $params );
786
787 MainWP_Extensions_View::render();
788 echo '</div>';
789 }
790
791 /**
792 * Method mainwp_help_content()
793 *
794 * Create the MainWP Help Document List for the help component in the sidebar.
795 */
796 public static function mainwp_help_content() {
797 if ( isset( $_GET['page'] ) && 'Extensions' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
798 ?>
799 <p><?php esc_html_e( 'If you need help with your MainWP Extensions, please review following help documents', 'mainwp' ); ?></p>
800 <div class="ui relaxed bulleted list">
801 <div class="item"><a href="https://kb.mainwp.com/docs/what-are-mainwp-extensions/" target="_blank"><i class="fa fa-book"></i> What are the MainWP Extensions</a></div>
802 <div class="item"><a href="https://kb.mainwp.com/docs/order-extensions/" target="_blank"><i class="fa fa-book"></i> Order Extension(s)</a></div>
803 <div class="item"><a href="https://kb.mainwp.com/docs/my-downloads-and-api-keys/" target="_blank"><i class="fa fa-book"></i> My Downloads and API Keys</a></div>
804 <div class="item"><a href="https://kb.mainwp.com/docs/install-extensions/" target="_blank"><i class="fa fa-book"></i> Install Extension(s)</a></div>
805 <div class="item"><a href="https://kb.mainwp.com/docs/activate-extensions-api/" target="_blank"><i class="fa fa-book"></i> Activate Extension(s) API</a></div>
806 <div class="item"><a href="https://kb.mainwp.com/docs/updating-extensions/" target="_blank"><i class="fa fa-book"></i> Updating Extension(s)</a></div>
807 <div class="item"><a href="https://kb.mainwp.com/docs/remove-extensions/" target="_blank"><i class="fa fa-book"></i> Remove Extension(s)</a></div>
808 </div>
809 <?php
810 }
811 }
812 }
813