PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
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 / class / class-mainwp-manage-sites-update-view.php

class-mainwp-manage-sites-update-view.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.2.2, at class/class-mainwp-manage-sites-update-view.php

1,061 lines 62.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Manage Sites Update View.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class MainWP_Manage_Sites_Update_View
17 *
18 * @package MainWP\Dashboard
19 */
20 class MainWP_Manage_Sites_Update_View { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
21
22 /**
23 * Method render_updates()
24 *
25 * If empty do nothing else grab the Child Sites ID and pass it to
26 * method render_individual_updates().
27 *
28 * @param mixed $website Child Site Info.
29 *
30 * @return mixed
31 */
32 public static function render_updates( $website ) {
33 if ( empty( $website ) ) {
34 return;
35 }
36
37 $website_id = $website->id;
38 static::render_individual_updates( $website_id );
39 }
40
41 /**
42 * Method render_individual_updates()
43 *
44 * Render Plugin updates Tab.
45 *
46 * @param mixed $id Child Site ID.
47 *
48 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
49 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_website_by_id()
50 * @uses \MainWP\Dashboard\MainWP_DB::query()
51 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
52 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_View::render_header_tabs()
53 */
54 public static function render_individual_updates( $id ) {
55
56 /**
57 * Current user global.
58 *
59 * @global string
60 */
61 global $current_user;
62 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
63 $sql = MainWP_DB::instance()->get_sql_website_by_id( $id, false, array( 'wp_upgrades', 'ignored_wp_upgrades', 'ignored_trans_upgrades', 'premium_upgrades', 'plugins_outdate_dismissed', 'themes_outdate_dismissed', 'plugins_outdate_info', 'themes_outdate_info', 'favi_icon' ) );
64 $websites = MainWP_DB::instance()->query( $sql );
65
66 MainWP_DB::data_seek( $websites, 0 );
67 if ( $websites ) {
68 $website = MainWP_DB::fetch_object( $websites );
69 }
70
71 $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
72
73 $active_tab = 'plugins';
74 $active_text = esc_html__( 'Plugin Updates', 'mainwp' );
75 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
76 if ( isset( $_GET['tab'] ) ) {
77 if ( 'wordpress-updates' === $_GET['tab'] ) {
78 $active_tab = 'wordpress';
79 $active_text = esc_html__( 'WordPress Updates', 'mainwp' );
80 } elseif ( 'themes-updates' === $_GET['tab'] ) {
81 $active_tab = 'themes';
82 $active_text = esc_html__( 'Theme Updates', 'mainwp' );
83 } elseif ( 'translations-updates' === $_GET['tab'] ) {
84 $active_tab = 'trans';
85 $active_text = esc_html__( 'Translation Updates', 'mainwp' );
86 } elseif ( 'abandoned-plugins' === $_GET['tab'] ) {
87 $active_tab = 'abandoned-plugins';
88 $active_text = esc_html__( 'Abandoned Plugins', 'mainwp' );
89 } elseif ( 'abandoned-themes' === $_GET['tab'] ) {
90 $active_tab = 'abandoned-themes';
91 $active_text = esc_html__( 'Abandoned Themes', 'mainwp' );
92 }
93 }
94 // phpcs:enable
95 MainWP_Manage_Sites_View::render_header_tabs( $active_tab, $active_text, $mainwp_show_language_updates )
96 ?>
97 <div class="ui padded segment" id="mainwp-manage-<?php echo intval( $id ); ?>-updates">
98 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-manage-updates-site-message' ) ) : ?>
99 <div class="ui info message">
100 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-manage-updates-site-message"></i>
101 <div>
102 <?php
103 /* translators: 1: Opening anchor tag for plugins, 2: Closing anchor tag, 3: Opening anchor tag for themes, 4: Closing anchor tag, 5: Opening anchor tag for WordPress core, 6: Closing anchor tag */
104 printf( esc_html__( 'Manage available updates for the child site. From here, you can update update %1$splugins%2$s, %3$sthemes%4$s, and %5$sWordPress core%6$s.', 'mainwp' ), '<a href="https://docs.mainwp.com/sites/updates/manage-updates#plugin-updates" target="_blank">', '</a> <i class="external alternate icon"></i>', '<a href="https://docs.mainwp.com/sites/updates/manage-updates#theme-updates" target="_blank">', '</a> <i class="external alternate icon"></i>', '<a href="https://docs.mainwp.com/sites/updates/manage-updates#wordpress-core-updates" target="_blank">', '</a> <i class="external alternate icon"></i>' ); // NOSONAR - noopener - open safe.
105 ?>
106 </div>
107 <div>
108 <?php
109 /* translators: 1: Opening anchor tag for WordPress core, 2: Closing anchor tag, 3: Opening anchor tag for plugins, 4: Closing anchor tag, 5: Opening anchor tag for themes, 6: Closing anchor tag */
110 printf( esc_html__( 'Also, from here, you can ignore updates for %1$sWordPress core%2$s, %3$splugins%4$s, and %5$sthemes%6$s.', 'mainwp' ), '<a href="https://docs.mainwp.com/sites/updates/manage-updates#ignore-theme-updates" target="_blank">', '</a> <i class="external alternate icon"></i>', '<a href="https://docs.mainwp.com/sites/updates/manage-updates#ignore-plugin-updates" target="_blank">', '</a> <i class="external alternate icon"></i>', '<a href="https://docs.mainwp.com/sites/updates/manage-updates#ignore-theme-updates" target="_blank">', '</a> <i class="external alternate icon"></i>' ); // NOSONAR - noopener - open safe.
111 ?>
112 </div>
113 </div>
114 <?php endif; ?>
115 <?php
116 static::render_wpcore_updates( $website, $active_tab, $userExtension );
117 static::render_plugins_updates( $website, $active_tab, $userExtension );
118 static::render_themes_updates( $website, $active_tab, $userExtension );
119
120 if ( $mainwp_show_language_updates ) :
121 static::render_language_updates( $website, $active_tab, $userExtension );
122 endif;
123
124 static::render_abandoned_plugins( $website, $active_tab, $userExtension );
125 static::render_abandoned_themes( $website, $active_tab, $userExtension );
126
127 // @since 5.4.0.7 - custom individual update tabs.
128 do_action( 'mainwp_individual_updates_tabs', $website, $userExtension );
129 ?>
130 </div>
131 <script type="text/javascript">
132 jQuery(function ($) {
133 $( '.ui.dropdown.select-individual-updates .item' ).tab({
134 'autoTabActivation': false,
135 'onVisible': function (tab) {
136 $('.select-buttons-individual-updates .button.ui').addClass('hidden');
137 $('.select-buttons-individual-updates .button.ui.' + tab).removeClass('hidden');
138 }
139 });
140 var $activeItem = $('.ui.dropdown.select-individual-updates .item.active');
141 if ($activeItem.length) {
142 var initialTab = $activeItem.data('tab');
143 $('.select-buttons-individual-updates .button.ui').addClass('hidden');
144 $('.select-buttons-individual-updates .button.ui.' + initialTab).removeClass('hidden');
145 }
146 jQuery( 'table.ui.table:not(.not-default-init)' ).DataTable( {
147 "searching": true,
148 "paging" : false,
149 "info" : true,
150 "columnDefs" : [ { "orderable": false, "targets": "no-sort" } ],
151 "language" : { "emptyTable": "No available updates. Please sync your MainWP Dashboard with Child Sites to see if there are any new updates available." }
152 } );
153 mainwp_get_icon_start();
154 });
155 </script>
156 <?php
157 MainWP_UI::render_modal_upload_icon();
158 MainWP_Updates::render_changes_history_modal();
159 }
160
161 /**
162 * Method get_total_info()
163 *
164 * Get total Updates information.
165 *
166 * @param mixed $site_id Child Site id.
167 */
168 public static function get_total_info( $site_id ) { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
169
170 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
171
172 $decodedIgnoredCores = ! empty( $userExtension->ignored_wp_upgrades ) ? json_decode( $userExtension->ignored_wp_upgrades, true ) : array();
173 if ( ! is_array( $decodedIgnoredCores ) ) {
174 $decodedIgnoredCores = array();
175 }
176
177 $sql = MainWP_DB::instance()->get_sql_website_by_id( $site_id, false, array( 'wp_upgrades', 'ignored_wp_upgrades', 'ignored_trans_updates', 'premium_upgrades', 'plugins_outdate_dismissed', 'themes_outdate_dismissed', 'plugins_outdate_info', 'themes_outdate_info', 'favi_icon' ) );
178 $websites = MainWP_DB::instance()->query( $sql );
179
180 MainWP_DB::data_seek( $websites, 0 );
181 if ( $websites ) {
182 $website = MainWP_DB::fetch_object( $websites );
183 }
184
185 $return = array(
186 'total_wp' => 0,
187 'total_plugins' => 0,
188 'total_themes' => 0,
189 'total_trans' => 0,
190 'total_aband_plugins' => 0,
191 'total_aband_themes' => 0,
192 'total_upgrades' => 0,
193 );
194
195 if ( empty( $website ) ) {
196 return $return;
197 }
198
199 $wp_upgrades = ! empty( $website->wp_upgrades ) ? json_decode( $website->wp_upgrades, true ) : array();
200 $ignored_core_upgrades = ! empty( $website->ignored_wp_upgrades ) ? json_decode( $website->ignored_wp_upgrades, true ) : array();
201
202 if ( $website->is_ignoreCoreUpdates || MainWP_Common_Functions::instance()->is_ignored_updates( $wp_upgrades, $ignored_core_upgrades, 'core' ) || MainWP_Common_Functions::instance()->is_ignored_updates( $wp_upgrades, $decodedIgnoredCores, 'core' ) ) {
203 $wp_upgrades = array();
204 }
205
206 $return['total_wp'] = ! empty( $wp_upgrades ) ? 1 : 0;
207
208 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
209
210 if ( $website->is_ignorePluginUpdates ) {
211 $plugin_upgrades = array();
212 }
213
214 if ( ! is_array( $plugin_upgrades ) ) {
215 $plugin_upgrades = array();
216 }
217
218 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
219 $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
220
221 if ( is_array( $decodedPremiumUpgrades ) ) {
222 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
223 $premiumUpgrade['premium'] = true;
224 if ( 'plugin' === $premiumUpgrade['type'] ) {
225 $premiumUpgrade = array_filter( $premiumUpgrade );
226
227 if ( ! isset( $plugin_upgrades[ $crrSlug ] ) ) {
228 continue;
229 }
230 $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade );
231 }
232 }
233 }
234 $ignored_plugins = json_decode( $website->ignored_plugins, true );
235 if ( is_array( $ignored_plugins ) ) {
236 $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
237 }
238
239 $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
240 if ( is_array( $ignored_plugins ) ) {
241 $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
242 }
243
244 $return['total_plugins'] = count( $plugin_upgrades );
245
246 $theme_upgrades = json_decode( $website->theme_upgrades, true );
247
248 if ( $website->is_ignoreThemeUpdates ) {
249 $theme_upgrades = array();
250 }
251
252 if ( ! is_array( $theme_upgrades ) ) {
253 $theme_upgrades = array();
254 }
255 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
256 $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
257
258 if ( is_array( $decodedPremiumUpgrades ) ) {
259 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
260 $premiumUpgrade['premium'] = true;
261
262 if ( 'theme' === $premiumUpgrade['type'] ) {
263 $premiumUpgrade = array_filter( $premiumUpgrade );
264
265 if ( ! isset( $theme_upgrades[ $crrSlug ] ) ) {
266 $theme_upgrades[ $crrSlug ] = array();
267 }
268 $theme_upgrades[ $crrSlug ] = array_merge( $theme_upgrades[ $crrSlug ], $premiumUpgrade );
269 }
270 }
271 }
272 $ignored_themes = json_decode( $website->ignored_themes, true );
273 if ( is_array( $ignored_themes ) ) {
274 $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
275 }
276
277 $ignored_themes = json_decode( $userExtension->ignored_themes, true );
278 if ( is_array( $ignored_themes ) ) {
279 $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
280 }
281
282 $return['total_themes'] = count( $theme_upgrades );
283
284 $translation_upgrades = json_decode( $website->translation_upgrades, true );
285 if ( ! is_array( $translation_upgrades ) ) {
286 $translation_upgrades = array();
287 }
288
289 if ( ! empty( $website->ignored_trans_updates ) ) {
290 $translation_upgrades = array();
291 }
292
293 $return['total_trans'] = count( $translation_upgrades );
294
295 $plugins_outdate = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' );
296 $plugins_outdate = ! empty( $plugins_outdate ) ? json_decode( $plugins_outdate, true ) : array();
297
298 if ( ! is_array( $plugins_outdate ) ) {
299 $plugins_outdate = array();
300 }
301 if ( ! empty( $plugins_outdate ) ) {
302 $pluginsOutdateDismissed = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' );
303 $pluginsOutdateDismissed = ! empty( $pluginsOutdateDismissed ) ? json_decode( $pluginsOutdateDismissed, true ) : array();
304
305 if ( is_array( $pluginsOutdateDismissed ) ) {
306 $plugins_outdate = array_diff_key( $plugins_outdate, $pluginsOutdateDismissed );
307 }
308
309 $decodedDismissedPlugins = json_decode( $userExtension->dismissed_plugins, true );
310 if ( is_array( $decodedDismissedPlugins ) ) {
311 $plugins_outdate = array_diff_key( $plugins_outdate, $decodedDismissedPlugins );
312 }
313 }
314 $return['total_aband_plugins'] = count( $plugins_outdate );
315
316 $themes_outdate = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' );
317 $themes_outdate = ! empty( $themes_outdate ) ? json_decode( $themes_outdate, true ) : array();
318
319 if ( ! is_array( $themes_outdate ) ) {
320 $themes_outdate = array();
321 }
322
323 if ( ! empty( $themes_outdate ) ) {
324 $themesOutdateDismissed = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_dismissed' );
325 $themesOutdateDismissed = ! empty( $themesOutdateDismissed ) ? json_decode( $themesOutdateDismissed, true ) : array();
326
327 if ( is_array( $themesOutdateDismissed ) ) {
328 $themes_outdate = array_diff_key( $themes_outdate, $themesOutdateDismissed );
329 }
330
331 $decodedDismissedThemes = json_decode( $userExtension->dismissed_themes, true );
332 if ( is_array( $decodedDismissedThemes ) ) {
333 $themes_outdate = array_diff_key( $themes_outdate, $decodedDismissedThemes );
334 }
335 }
336
337 $return['total_aband_themes'] = count( $themes_outdate );
338
339 $return['total_upgrades'] = $return['total_wp'] + $return['total_plugins'] + $return['total_themes'] + $return['total_trans'];
340
341 return $return;
342 }
343
344
345 /**
346 * Method render_wpcore_updates()
347 *
348 * Render the WordPress Updates Tab.
349 *
350 * @param mixed $website Child Site info.
351 * @param mixed $active_tab Current active tab.
352 * @param object $userExtension User Extension.
353 *
354 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
355 */
356 public static function render_wpcore_updates( $website, $active_tab, $userExtension ) { // phpcs:ignore -- NOSONAR - complex.
357 $user_can_update_wp = \mainwp_current_user_can( 'dashboard', 'update_wordpress' );
358 $decodedIgnoredCores = ! empty( $userExtension->ignored_wp_upgrades ) ? json_decode( $userExtension->ignored_wp_upgrades, true ) : array();
359 if ( ! is_array( $decodedIgnoredCores ) ) {
360 $decodedIgnoredCores = array();
361 }
362 $wp_upgrades = ! empty( $website->wp_upgrades ) ? json_decode( $website->wp_upgrades, true ) : array();
363 $ignored_core_upgrades = ! empty( $website->ignored_wp_upgrades ) ? json_decode( $website->ignored_wp_upgrades, true ) : array();
364 $wpcore_update_disabled_by = '';
365 $last_version = '';
366 $show_wp_update = false;
367 if ( ! $website->is_ignoreCoreUpdates && ! MainWP_Common_Functions::instance()->is_ignored_updates( $wp_upgrades, $ignored_core_upgrades, 'core' ) && ! MainWP_Common_Functions::instance()->is_ignored_updates( $wp_upgrades, $decodedIgnoredCores, 'core' ) ) {
368 if ( ! empty( $wp_upgrades ) ) {
369 $wpcore_update_disabled_by = MainWP_System_Utility::disabled_wpcore_update_by( $website );
370 $last_version = $wp_upgrades['new'];
371 }
372 $show_wp_update = ! empty( $wp_upgrades ) && '' === $website->sync_errors;
373 }
374 ?>
375 <div class="ui <?php echo 'wordpress' === $active_tab ? 'active' : ''; ?> tab" data-tab="wordpress">
376 <?php if ( $show_wp_update ) : ?>
377 <table style="width:100% !important;" class="ui tablet stackable table mainwp-manage-updates-table not-default-init" id="mainwp-wordpress-updates-table">
378 <thead>
379 <tr>
380 <th scope="col"><?php esc_html_e( 'Detected Version', 'mainwp' ); ?></th>
381 <th scope="col" class="right aligned collapsing"><?php esc_html_e( 'New Version', 'mainwp' ); ?></th>
382 <th scope="col"></th>
383 </tr>
384 </thead>
385 <tbody>
386 <tr class="mainwp-wordpress-update" site_id="<?php echo intval( $website->id ); ?>" last-version="<?php echo esc_attr( rawurlencode( $last_version ) ); ?>" site_name="<?php echo esc_attr( rawurlencode( stripslashes( $website->name ) ) ); ?>" updated="<?php echo ! empty( $wp_upgrades ) && empty( $wpcore_update_disabled_by ) ? '0' : '1'; ?>">
387 <td>
388 <?php if ( ! empty( $wp_upgrades ) ) : ?>
389 <?php echo esc_html( $wp_upgrades['current'] ); ?>
390 <?php endif; ?>
391 </td>
392 <td>
393 <?php echo esc_html( $last_version ); ?>
394 </td>
395 <td>
396 <?php if ( $user_can_update_wp ) : ?>
397 <?php
398 if ( ! empty( $wp_upgrades ) ) :
399 if ( '' !== $wpcore_update_disabled_by ) {
400 ?>
401 <span data-tooltip="<?php echo esc_html( $wpcore_update_disabled_by ); ?>" data-inverted="" data-position="left center"><a href="javascript:void(0)" class="ui green button mini disabled"><?php esc_html_e( 'Update', 'mainwp' ); ?></a></span>
402 <?php } else { ?>
403
404 <div class="ui bottom left pointing dropdown mini button"><?php esc_html_e( 'Ignore', 'mainwp' ); ?>
405 <i class="dropdown icon"></i>
406 <div class="menu">
407 <a href="javascript:void(0)" onClick="return updatesoverview_upgrade_ignore( <?php echo intval( $website->id ); ?>, this, '<?php echo esc_js( rawurlencode( $last_version ) ); ?>' )" class="item"><?php esc_html_e( 'Ignore this version', 'mainwp' ); ?></a>
408 <a href="javascript:void(0)" class="item mainwp-ignore-globally-button" onClick="return updatesoverview_upgrade_ignore_this_version_globally( '<?php echo esc_js( rawurlencode( $last_version ) ); ?>' )"><?php esc_html_e( 'Ignore this version globally', 'mainwp' ); ?></a>
409 <a href="javascript:void(0)" onClick="return updatesoverview_upgrade_ignore_all_version( <?php echo intval( $website->id ); ?>, this )" class="item"><?php esc_html_e( 'Ignore all versions', 'mainwp' ); ?></a>
410 </div>
411 </div>
412 <a href="javascript:void(0)" class="ui green button mini" onClick="return updatesoverview_upgrade(<?php echo intval( $website->id ); ?>, this )"><?php esc_html_e( 'Update', 'mainwp' ); ?></a>
413
414 <input type="hidden" id="wp-updated-<?php echo intval( $website->id ); ?>" value="<?php echo ! empty( $wp_upgrades ) ? '0' : '1'; ?>" />
415 <?php
416 }
417 endif;
418 ?>
419 <?php endif; ?>
420 </td>
421 </tr>
422 </tbody>
423 </table>
424 <?php else : ?>
425 <?php MainWP_UI::render_empty_page_placeholder( __( 'WordPress is up to date', 'mainwp' ), __( 'No WordPress core update available right now.', 'mainwp' ) ); ?>
426 <?php endif; ?>
427 </div>
428 <?php
429 }
430
431 /**
432 * Method render_plugins_updates()
433 *
434 * Render the Plugin Updates Tab.
435 *
436 * @param mixed $website Child Site info.
437 * @param mixed $active_tab Current active tab.
438 * @param mixed $userExtension MainWP trusted plugin data.
439 *
440 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
441 * @uses \MainWP\Dashboard\MainWP_Updates_Table_Helper
442 */
443 public static function render_plugins_updates( $website, $active_tab, $userExtension ) { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
444
445 $trustedPlugins = json_decode( $userExtension->trusted_plugins, true );
446 if ( ! is_array( $trustedPlugins ) ) {
447 $trustedPlugins = array();
448 }
449
450 $user_can_update_plugins = \mainwp_current_user_can( 'dashboard', 'update_plugins' );
451 $user_can_ignore_unignore = \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' );
452 ?>
453 <div id="plugins-updates-global" class="ui <?php echo 'plugins' === $active_tab ? 'active' : ''; ?> tab" data-tab="plugins">
454 <?php if ( ! $website->is_ignorePluginUpdates ) : ?>
455 <?php
456 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
457 if ( ! is_array( $plugin_upgrades ) ) {
458 $plugin_upgrades = array();
459 }
460
461 $site_opts = MainWP_DB::instance()->get_website_options_array( $website, array( 'premium_upgrades', 'rollback_updates_data', 'site_info' ) );
462 if ( ! is_array( $site_opts ) ) {
463 $site_opts = array();
464 }
465 $decodedPremiumUpgrades = ! empty( $site_opts['premium_upgrades'] ) ? json_decode( $site_opts['premium_upgrades'], true ) : array();
466
467 $rollItems = ! empty( $site_opts['rollback_updates_data'] ) ? json_decode( $site_opts['rollback_updates_data'], true ) : array();
468
469 $rollPlugins = array();
470 if ( is_array( $rollItems ) && ! empty( $rollItems['plugin'] ) && is_array( $rollItems['plugin'] ) ) {
471 $rollPlugins = $rollItems['plugin'];
472 }
473
474 if ( is_array( $decodedPremiumUpgrades ) ) {
475 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
476 $premiumUpgrade['premium'] = true;
477 if ( 'plugin' === $premiumUpgrade['type'] ) {
478 $premiumUpgrade = array_filter( $premiumUpgrade );
479 if ( ! isset( $plugin_upgrades[ $crrSlug ] ) ) {
480 continue;
481 }
482 $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade );
483 }
484 }
485 }
486 $ignored_plugins = json_decode( $website->ignored_plugins, true );
487 if ( is_array( $ignored_plugins ) ) {
488 $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
489 }
490
491 $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
492 if ( is_array( $ignored_plugins ) ) {
493 $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
494 }
495
496 $updates_table_helper = new MainWP_Updates_Table_Helper( MAINWP_VIEW_PER_SITE, 'plugin', array( 'show_select' => true ) );
497
498 add_filter( 'mainwp_updates_table_header_content', array( static::class, 'hook_table_update_plugins_header_content' ), 10, 3 );
499
500 $wp_info = ! empty( $site_opts['site_info'] ) ? json_decode( $site_opts['site_info'], true ) : array();
501 if ( ! is_array( $wp_info ) ) {
502 $wp_info = array();
503 }
504 $use_tzformat = ! empty( $wp_info['format_datetime'] ) && is_array( $wp_info['format_datetime'] ) ? $wp_info['format_datetime'] : array();
505 $offs = ! empty( $use_tzformat['gmt_offset'] ) ? intval( $use_tzformat['gmt_offset'] ) : 0;
506 $offs_info = esc_html__( '- Timezone:', 'mainwp' ) . ' UTC' . ( $offs >= 0 ? '+' . $offs : $offs );
507
508 ?>
509 <?php if ( ! empty( $plugin_upgrades ) ) : ?>
510 <table id="mainwp-updates-plugins-table" style="width:100% !important;" class="ui tablet stackable table mainwp-updates-list mainwp-manage-updates-table">
511 <thead class="master-checkbox">
512 <tr>
513 <?php $updates_table_helper->print_column_headers(); ?>
514 </tr>
515 </thead>
516 <tbody class="plugins-bulk-updates child-checkbox" site_id="<?php echo intval( $website->id ); ?>" site_name="<?php echo esc_attr( rawurlencode( stripslashes( $website->name ) ) ); ?>" site_url="<?php echo esc_attr( $website->url ); ?>" tz-info="<?php echo esc_attr( $offs_info ); ?>">
517 <?php foreach ( $plugin_upgrades as $slug => $plugin_upgrade ) : ?>
518 <?php $plugin_name = rawurlencode( $slug ); ?>
519 <?php
520 $item_slug = MainWP_Utility::get_dir_slug( rawurldecode( $slug ) );
521 $indent_hidden = '<input type="hidden" id="wp_upgraded_plugin_' . intval( $website->id ) . '_' . esc_html( $plugin_name ) . '" value="0" />';
522 $last_version = $plugin_upgrade['update']['new_version'];
523 $row_columns = array(
524 'title' => MainWP_System_Utility::get_plugin_icon( $item_slug ) . '&nbsp;<a href="' . admin_url() . 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $website->id ) . '&plugin=' . esc_attr( $plugin_upgrade['update']['slug'] ) . '&url=' . ( isset( $plugin_upgrade['PluginURI'] ) ? rawurlencode( $plugin_upgrade['PluginURI'] ) : '' ) . '&name=' . rawurlencode( $plugin_upgrade['Name'] ) . '" target="_blank" class="open-plugin-details-modal">' . esc_html( $plugin_upgrade['Name'] ) . '</a>' . $indent_hidden,
525 'version' => esc_html( $plugin_upgrade['Version'] ),
526 'latest' => '<a href="' . admin_url() . 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $website->id ) . '&plugin=' . esc_attr( $plugin_upgrade['update']['slug'] ) . '&url=' . ( isset( $plugin_upgrade['PluginURI'] ) ? rawurlencode( $plugin_upgrade['PluginURI'] ) : '' ) . '&name=' . rawurlencode( $plugin_upgrade['Name'] ) . '&section=changelog" target="_blank" class="open-plugin-details-modal">' . esc_html( $last_version ) . '</a>',
527 'trusted' => ( in_array( $slug, $trustedPlugins ) ? true : false ),
528 'status' => ( isset( $plugin_upgrade['active'] ) && $plugin_upgrade['active'] ) ? true : false,
529 );
530
531 $others = array();
532 if ( ! empty( $rollPlugins[ $slug ][ $last_version ] ) ) {
533 $msg = MainWP_Updates_Helper::get_roll_msg( $rollPlugins[ $slug ][ $last_version ], true, 'notice' );
534 $others['roll_info'] = $msg;
535 }
536
537 $compatible_php = isset( $plugin_upgrade['wp_compatible'] ) ? $plugin_upgrade['wp_compatible'] : true;
538 $compatible_wp = isset( $plugin_upgrade['php_compatible'] ) ? $plugin_upgrade['php_compatible'] : true;
539
540 ?>
541 <tr plugin_slug="<?php echo esc_attr( $plugin_name ); ?>" plugin_name="<?php echo esc_attr( $plugin_upgrade['Name'] ); ?>" last-version="<?php echo esc_js( rawurlencode( $last_version ) ); ?>" premium="<?php echo isset( $plugin_upgrade['premium'] ) && ! empty( $plugin_upgrade['premium'] ) ? 1 : 0; ?>" updated="0">
542 <?php
543 $row_columns = $updates_table_helper->render_columns( $row_columns, $website, $others );
544 $action_rendered = isset( $row_columns['action'] ) ? true : false;
545 if ( ! $action_rendered ) :
546 ?>
547 <td>
548 <a href="#" history-view="update-plugins-individual" class="mainwp-show-history ui mini button"><?php esc_html_e( 'History', 'mainwp' ); ?></a>
549 <?php if ( $user_can_ignore_unignore ) : ?>
550 <div class="ui bottom left pointing dropdown mini button"><?php esc_html_e( 'Ignore', 'mainwp' ); ?>
551 <i class="dropdown icon"></i>
552 <div class="menu">
553 <a href="javascript:void(0)" onClick="return updatesoverview_plugins_ignore_detail( '<?php echo esc_js( $plugin_name ); ?>', '<?php echo esc_js( rawurlencode( $plugin_upgrade['Name'] ) ); ?>', <?php echo intval( $website->id ); ?>, this, '<?php echo esc_js( rawurlencode( $last_version ) ); ?>' )" class="item"><?php esc_html_e( 'Ignore this version', 'mainwp' ); ?></a>
554 <a href="javascript:void(0)" class="item mainwp-ignore-globally-button" onClick="return updatesoverview_plugins_ignore_all( '<?php echo esc_js( $plugin_name ); ?>', '<?php echo esc_attr( rawurlencode( $plugin_upgrade['Name'] ) ); ?>', this, '<?php echo esc_js( rawurlencode( $last_version ) ); ?>' )"><?php esc_html_e( 'Ignore this version globally', 'mainwp' ); ?></a>
555 <a href="javascript:void(0)" onClick="return updatesoverview_plugins_ignore_detail( '<?php echo esc_js( $plugin_name ); ?>', '<?php echo esc_js( rawurlencode( $plugin_upgrade['Name'] ) ); ?>', <?php echo intval( $website->id ); ?>, this, 'all_versions' )" class="item"><?php esc_html_e( 'Ignore all versions', 'mainwp' ); ?></a>
556 </div>
557 </div>
558 <?php endif; ?>
559 <?php
560 if ( $user_can_update_plugins ) :
561 if ( $compatible_php && $compatible_wp ) {
562 ?>
563 <a href="javascript:void(0)" class="ui green mini button" onClick="return updatesoverview_upgrade_plugin( <?php echo intval( $website->id ); ?>, '<?php echo esc_js( $plugin_name ); ?>' )"><?php esc_html_e( 'Update', 'mainwp' ); ?></a>
564 <?php
565 } else {
566 MainWP_Updates_Per_Item::render_incompatible_message( $compatible_php, $compatible_wp );
567 }
568 ?>
569 <?php endif; ?>
570 </td>
571 <?php endif; ?>
572 </tr>
573 <?php endforeach; ?>
574 </tbody>
575 <tfoot>
576 <tr>
577 <?php $updates_table_helper->print_column_headers( false ); ?>
578 </tr>
579 </tfoot>
580 </table>
581 <?php else : ?>
582 <?php MainWP_UI::render_empty_page_placeholder( __( 'Plugins are up to date', 'mainwp' ), __( 'No plugin updates available right now.', 'mainwp' ) ); ?>
583 <?php endif; ?>
584 <?php endif; ?>
585 </div>
586 <?php
587 remove_filter( 'mainwp_updates_table_header_content', array( static::class, 'hook_table_update_plugins_header_content' ), 10, 3 );
588
589 MainWP_Updates::render_updates_modal();
590 MainWP_Updates::render_plugin_details_modal();
591 }
592
593 /**
594 * Method hook_table_update_plugins_header_content()
595 *
596 * Hook render the column header updates table.
597 *
598 * @param string $column_display_name column display name.
599 * @param mixed $column_key column key.
600 * @param bool $top Top or bottom header.
601 */
602 public static function hook_table_update_plugins_header_content( $column_display_name, $column_key, $top ) {
603 if ( $top && 'title' === $column_key ) {
604 $column_display_name = '<div class="ui master checkbox plugins-checkbox"><input type="checkbox" name=""><label>' . $column_display_name . '</label></div>';
605 }
606 return $column_display_name;
607 }
608
609 /**
610 * Method hook_table_update_themes_header_content()
611 *
612 * Hook render the column header updates table.
613 *
614 * @param string $column_display_name column display name.
615 * @param mixed $column_key column key.
616 * @param bool $top Top or bottom header.
617 */
618 public static function hook_table_update_themes_header_content( $column_display_name, $column_key, $top ) {
619 if ( $top && 'title' === $column_key ) {
620 $column_display_name = '<div class="ui master checkbox themes-checkbox"><input type="checkbox" name=""><label>' . $column_display_name . '</label></div>';
621 }
622 return $column_display_name;
623 }
624
625 /**
626 * Method render_themes_updates()
627 *
628 * Render the Themes Update Tab.
629 *
630 * @param mixed $website Child Site info.
631 * @param mixed $active_tab Current active tab.
632 * @param mixed $userExtension MainWP trusted themes data.
633 *
634 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
635 * @uses \MainWP\Dashboard\MainWP_Updates_Table_Helper
636 */
637 public static function render_themes_updates( $website, $active_tab, $userExtension ) { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
638
639 $trustedThemes = json_decode( $userExtension->trusted_themes, true );
640 if ( ! is_array( $trustedThemes ) ) {
641 $trustedThemes = array();
642 }
643
644 $user_can_update_themes = \mainwp_current_user_can( 'dashboard', 'update_themes' );
645 $user_can_ignore_unignore = \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' );
646
647 ?>
648 <div id="themes-updates-global" class="ui <?php echo 'themes' === $active_tab ? 'active' : ''; ?> tab" data-tab="themes">
649 <?php if ( ! $website->is_ignoreThemeUpdates ) : ?>
650 <?php
651 $theme_upgrades = json_decode( $website->theme_upgrades, true );
652 if ( ! is_array( $theme_upgrades ) ) {
653 $theme_upgrades = array();
654 }
655
656 $site_opts = MainWP_DB::instance()->get_website_options_array( $website, array( 'premium_upgrades', 'rollback_updates_data', 'site_info' ) );
657 if ( ! is_array( $site_opts ) ) {
658 $site_opts = array();
659 }
660 $decodedPremiumUpgrades = ! empty( $site_opts['premium_upgrades'] ) ? json_decode( $site_opts['premium_upgrades'], true ) : array();
661
662 $rollItems = ! empty( $site_opts['rollback_updates_data'] ) ? json_decode( $site_opts['rollback_updates_data'], true ) : array();
663
664 $rollThemes = array();
665 if ( is_array( $rollItems ) && ! empty( $rollItems['theme'] ) && is_array( $rollItems['theme'] ) ) {
666 $rollThemes = $rollItems['theme'];
667 }
668
669 if ( is_array( $decodedPremiumUpgrades ) ) {
670 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
671 $premiumUpgrade['premium'] = true;
672 if ( 'theme' === $premiumUpgrade['type'] ) {
673 $premiumUpgrade = array_filter( $premiumUpgrade );
674 if ( ! isset( $theme_upgrades[ $crrSlug ] ) ) {
675 $theme_upgrades[ $crrSlug ] = array();
676 }
677 $theme_upgrades[ $crrSlug ] = array_merge( $theme_upgrades[ $crrSlug ], $premiumUpgrade );
678 }
679 }
680 }
681 $ignored_themes = json_decode( $website->ignored_themes, true );
682 if ( is_array( $ignored_themes ) ) {
683 $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
684 }
685
686 $ignored_themes = json_decode( $userExtension->ignored_themes, true );
687 if ( is_array( $ignored_themes ) ) {
688 $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
689 }
690
691 $updates_table_helper = new MainWP_Updates_Table_Helper( MAINWP_VIEW_PER_SITE, 'theme', array( 'show_select' => true ) );
692
693 add_filter( 'mainwp_updates_table_header_content', array( static::class, 'hook_table_update_themes_header_content' ), 10, 3 );
694
695 $wp_info = ! empty( $site_opts['site_info'] ) ? json_decode( $site_opts['site_info'], true ) : array();
696 if ( ! is_array( $wp_info ) ) {
697 $wp_info = array();
698 }
699 $use_tzformat = ! empty( $wp_info['format_datetime'] ) && is_array( $wp_info['format_datetime'] ) ? $wp_info['format_datetime'] : array();
700 $offs = ! empty( $use_tzformat['gmt_offset'] ) ? intval( $use_tzformat['gmt_offset'] ) : 0;
701 $offs_info = esc_html__( '- Timezone:', 'mainwp' ) . ' UTC' . ( $offs >= 0 ? '+' . $offs : $offs );
702
703 ?>
704 <?php if ( ! empty( $theme_upgrades ) ) : ?>
705 <table id="mainwp-updates-themes-table" style="width:100% !important;" class="ui tablet stackable table mainwp-updates-list mainwp-manage-updates-table">
706 <thead class="master-checkbox full-width" >
707 <tr>
708 <?php $updates_table_helper->print_column_headers(); ?>
709 </tr>
710 </thead>
711 <tbody class="themes-bulk-updates child-checkbox" site_id="<?php echo intval( $website->id ); ?>" site_name="<?php echo esc_attr( rawurlencode( stripslashes( $website->name ) ) ); ?>" site_url="<?php echo esc_attr( $website->url ); ?>" tz-info="<?php echo esc_attr( $offs_info ); ?>">
712 <?php foreach ( $theme_upgrades as $slug => $theme_upgrade ) : ?>
713 <?php $theme_name = rawurlencode( $slug ); ?>
714 <?php $indent_hidden = '<input type="hidden" id="wp_upgraded_theme_' . intval( $website->id ) . '_' . esc_attr( $theme_name ) . '" value="0" />'; ?>
715 <?php
716 $last_version = $theme_upgrade['update']['new_version'];
717 $row_columns = array(
718 'title' => MainWP_System_Utility::get_theme_icon( $slug ) . '&nbsp;' . esc_html( $theme_upgrade['Name'] ) . $indent_hidden,
719 'version' => esc_html( $theme_upgrade['Version'] ),
720 'latest' => esc_html( $last_version ),
721 'trusted' => ( in_array( $slug, $trustedThemes, true ) ? true : false ),
722 'status' => ( isset( $theme_upgrade['active'] ) && $theme_upgrade['active'] ) ? true : false,
723 );
724 $others = array();
725 if ( ! empty( $rollThemes[ $slug ][ $last_version ] ) ) {
726 $msg = MainWP_Updates_Helper::get_roll_msg( $rollThemes[ $slug ][ $last_version ], true, 'notice' );
727 $others['roll_info'] = $msg;
728 }
729 ?>
730 <tr theme_slug="<?php echo esc_attr( $theme_name ); ?>" theme_name="<?php echo esc_attr( $theme_upgrade['Name'] ); ?>" last-version="<?php echo esc_js( rawurlencode( $last_version ) ); ?>" premium="<?php echo isset( $theme_upgrade['premium'] ) && ! empty( $theme_upgrade['premium'] ) ? 1 : 0; ?>" updated="0">
731 <?php
732 $row_columns = $updates_table_helper->render_columns( $row_columns, $website, $others );
733 $action_rendered = isset( $row_columns['action'] ) ? true : false;
734 if ( ! $action_rendered ) :
735 ?>
736 <td>
737 <a href="#" history-view="update-themes-individual" class="mainwp-show-history ui mini button"><?php esc_html_e( 'History', 'mainwp' ); ?></a>
738 <?php if ( $user_can_ignore_unignore ) : ?>
739 <div class="ui bottom left pointing dropdown mini button"><?php esc_html_e( 'Ignore', 'mainwp' ); ?>
740 <i class="dropdown icon"></i>
741 <div class="menu">
742 <a href="javascript:void(0)" onClick="return updatesoverview_themes_ignore_detail( '<?php echo esc_js( $theme_name ); ?>', '<?php echo esc_js( rawurlencode( $theme_upgrade['Name'] ) ); ?>', <?php echo intval( $website->id ); ?>, this, '<?php echo esc_js( rawurlencode( $last_version ) ); ?>' )" class="item"><?php esc_html_e( 'Ignore this version', 'mainwp' ); ?></a>
743 <a href="javascript:void(0)" class="item mainwp-ignore-globally-button" onClick="return updatesoverview_themes_ignore_all( '<?php echo esc_js( $theme_name ); ?>', '<?php echo esc_js( rawurlencode( $theme_upgrade['Name'] ) ); ?>', this, '<?php echo esc_js( rawurlencode( $last_version ) ); ?>' )"><?php esc_html_e( 'Ignore this version globally', 'mainwp' ); ?></a>
744 <a href="javascript:void(0)" onClick="return updatesoverview_themes_ignore_detail( '<?php echo esc_js( $theme_name ); ?>', '<?php echo esc_js( rawurlencode( $theme_upgrade['Name'] ) ); ?>', <?php echo intval( $website->id ); ?>, this, 'all_versions' )" class="item"><?php esc_html_e( 'Ignore all versions', 'mainwp' ); ?></a>
745 </div>
746 </div>
747 <?php endif; ?>
748 <?php if ( $user_can_update_themes ) : ?>
749 <a href="javascript:void(0)" class="ui green mini button" onClick="return updatesoverview_upgrade_theme( <?php echo intval( $website->id ); ?>, '<?php echo esc_js( $theme_name ); ?>' )"><?php esc_html_e( 'Update', 'mainwp' ); ?></a>
750 <?php endif; ?>
751 </td>
752 <?php endif; ?>
753 </tr>
754 <?php endforeach; ?>
755 </tbody>
756 <tfoot class="full-width">
757 <tr>
758 <?php $updates_table_helper->print_column_headers( false ); ?>
759 </tr>
760 </tfoot>
761 </table>
762 <?php else : ?>
763 <?php MainWP_UI::render_empty_page_placeholder( __( 'Themes are up to date', 'mainwp' ), __( 'No theme updates available right now.', 'mainwp' ) ); ?>
764 <?php endif; ?>
765 <?php endif; ?>
766 </div>
767 <?php
768 remove_filter( 'mainwp_updates_table_header_content', array( static::class, 'hook_table_update_themes_header_content' ), 10, 3 );
769 }
770
771 /**
772 * Method render_language_updates()
773 *
774 * Render the Language Updates Tab.
775 *
776 * @param mixed $website Child Site info.
777 * @param mixed $active_tab Current active tab.
778 * @param object $userExtension User extension data.
779 */
780 public static function render_language_updates( $website, $active_tab, $userExtension ) {
781 $trustedPlugins = MainWP_Utility::get_decoded_array( $userExtension->trusted_plugins );
782 $trustedThemes = MainWP_Utility::get_decoded_array( $userExtension->trusted_themes );
783 $user_can_update_translation = \mainwp_current_user_can( 'dashboard', 'update_translations' );
784 if ( empty( $website->ignored_trans_updates ) ) {
785 $translation_upgrades = json_decode( $website->translation_upgrades, true );
786 if ( ! is_array( $translation_upgrades ) ) {
787 $translation_upgrades = array();
788 }
789 } else {
790 $translation_upgrades = array();
791 }
792 ?>
793 <div class="ui <?php echo 'trans' === $active_tab ? 'active' : ''; ?> tab" data-tab="translations">
794 <?php if ( ! empty( $translation_upgrades ) ) : ?>
795 <table style="width:100% !important;" class="ui tablet stackable table mainwp-manage-updates-table" id="mainwp-translations-table">
796 <thead>
797 <tr>
798 <th scope="col" ><?php esc_html_e( 'Translation', 'mainwp' ); ?></th>
799 <th scope="col" ><?php esc_html_e( 'Version', 'mainwp' ); ?></th>
800 <th scope="col" ><?php esc_html_e( 'Trusted', 'mainwp' ); ?></th>
801 <th scope="col" class="collapsing no-sort"></th>
802 </tr>
803 </thead>
804 <tbody class="translations-bulk-updates" id="wp_translation_upgrades_<?php echo intval( $website->id ); ?>" site_id="<?php echo intval( $website->id ); ?>" site_name="<?php echo esc_attr( rawurlencode( stripslashes( $website->name ) ) ); ?>">
805 <?php foreach ( $translation_upgrades as $translation_upgrade ) : ?>
806 <?php
807 $translation_name = isset( $translation_upgrade['name'] ) ? $translation_upgrade['name'] : $translation_upgrade['slug'];
808 $translation_slug = esc_attr( $translation_upgrade['slug'] );
809 ?>
810 <tr translation_slug="<?php echo esc_attr( $translation_slug ); ?>" updated="0">
811 <td>
812 <?php echo esc_html( $translation_name ); ?>
813 <input type="hidden" id="wp_upgraded_translation_<?php echo intval( $website->id ); ?>_<?php echo esc_attr( $translation_slug ); ?>" value="0"/>
814 </td>
815 <td>
816 <?php echo esc_html( $translation_upgrade['version'] ); ?>
817 </td>
818 <?php
819 $is_trust = static::is_trans_trusted_update( $translation_upgrade, $trustedPlugins, $trustedThemes );
820 echo static::get_column_trusted($is_trust ); //phpcs:ignore -- NOSONAR - escaped.
821 ?>
822 <td>
823 <?php if ( $user_can_update_translation ) : ?>
824 <a href="javascript:void(0)" class="ui green mini button" onClick="return updatesoverview_upgrade_translation( <?php echo intval( $website->id ); ?>, '<?php echo esc_js( $translation_slug ); ?>' )"><?php esc_html_e( 'Update', 'mainwp' ); ?></a>
825
826 <?php endif; ?>
827 </td>
828 </tr>
829 <?php endforeach; ?>
830 </tbody>
831 <tfoot>
832 <tr>
833 <th scope="col" ><?php esc_html_e( 'Translation', 'mainwp' ); ?></th>
834 <th scope="col" ><?php esc_html_e( 'Version', 'mainwp' ); ?></th>
835 <th scope="col" ><?php esc_html_e( 'Trusted', 'mainwp' ); ?></th>
836 <th scope="col" class="collapsing no-sort"></th>
837 </tr>
838 </tfoot>
839 </table>
840 <?php else : ?>
841 <?php MainWP_UI::render_empty_page_placeholder( __( 'Translations are up to date', 'mainwp' ), __( 'No translation updates available right now.', 'mainwp' ) ); ?>
842 <?php endif; ?>
843 </div>
844 <?php
845 }
846
847
848 /**
849 * Get trusted column.
850 *
851 * @param mixed $value Value of column.
852 */
853 public static function get_column_trusted( $value ) {
854 if ( $value ) {
855 $label = '<span class="ui tiny basic green label mainwp-768-fluid">Trusted</span>';
856 } else {
857 $label = '<span class="ui tiny basic grey label mainwp-768-fluid">Not Trusted</span>';
858 }
859 return '<td class="mainwp-768-half-width-cell">' . $label . '</td>';
860 }
861
862 /**
863 * Check if trans is trusted update.
864 *
865 * @param string $tran_info Translation slug.
866 * @param array $trusted_plugins Trusted update plugins.
867 * @param array $trusted_themes Trusted update themes.
868 */
869 public static function is_trans_trusted_update( $tran_info, $trusted_plugins, $trusted_themes ) {
870 if ( is_array( $tran_info ) && isset( $tran_info['type'] ) && isset( $tran_info['slug'] ) ) {
871 $tran_slug = $tran_info['slug'];
872 if ( 'plugin' === $tran_info['type'] && is_array( $trusted_plugins ) ) {
873 foreach ( $trusted_plugins as $slug ) {
874 $_slug = explode( '/', $slug )[0];
875 if ( $tran_slug === $_slug ) {
876 return true;
877 }
878 }
879 } elseif ( 'theme' === $tran_info['type'] && is_array( $trusted_themes ) && in_array( $tran_slug, $trusted_themes ) ) {
880 return true;
881 }
882 }
883 return false;
884 }
885
886
887 /**
888 * Method render_abandoned_plugins()
889 *
890 * Render the Abandoned Plugin Tab.
891 *
892 * @param mixed $website Child Site info.
893 * @param mixed $active_tab Current active tab.
894 * @param mixed $userExtension MainWP trusted plugin data.
895 *
896 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
897 */
898 public static function render_abandoned_plugins( $website, $active_tab, $userExtension ) {
899
900 $user_can_ignore_unignore = \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' );
901
902 $plugins_outdate = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' );
903 $plugins_outdate = ! empty( $plugins_outdate ) ? json_decode( $plugins_outdate, true ) : array();
904
905 if ( ! is_array( $plugins_outdate ) ) {
906 $plugins_outdate = array();
907 }
908 $pluginsOutdateDismissed = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' );
909 $pluginsOutdateDismissed = ! empty( $pluginsOutdateDismissed ) ? json_decode( $pluginsOutdateDismissed, true ) : array();
910
911 if ( is_array( $pluginsOutdateDismissed ) ) {
912 $plugins_outdate = array_diff_key( $plugins_outdate, $pluginsOutdateDismissed );
913 }
914
915 $decodedDismissedPlugins = json_decode( $userExtension->dismissed_plugins, true );
916 if ( is_array( $decodedDismissedPlugins ) ) {
917 $plugins_outdate = array_diff_key( $plugins_outdate, $decodedDismissedPlugins );
918 }
919 /* translators: %s: Number of days since last update */
920 $str_format = esc_html__( 'Updated %s days ago', 'mainwp' );
921 ?>
922
923 <div class="ui <?php echo 'abandoned-plugins' === $active_tab ? 'active' : ''; ?> tab" data-tab="abandoned-plugins">
924 <?php if ( ! empty( $plugins_outdate ) ) : ?>
925 <table style="width:100% !important;" class=" ui tablet stackable table mainwp-manage-updates-table" id="mainwp-abandoned-plugins-table">
926 <thead>
927 <tr>
928 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
929 <th scope="col" ><?php esc_html_e( 'Version', 'mainwp' ); ?></th>
930 <th scope="col" ><?php esc_html_e( 'Last Update', 'mainwp' ); ?></th>
931 <th scope="col" class="no-sort"></th>
932 </tr>
933 </thead>
934 <tbody id="wp_plugins_outdate_<?php echo intval( $website->id ); ?>" site_id="<?php echo intval( $website->id ); ?>" site_name="<?php echo esc_attr( rawurlencode( stripslashes( $website->name ) ) ); ?>">
935 <?php foreach ( $plugins_outdate as $slug => $plugin_outdate ) : ?>
936 <?php
937 $plugin_name = rawurlencode( $slug );
938 $item_slug = MainWP_Utility::get_dir_slug( rawurldecode( $slug ) );
939 $now = new \DateTime();
940 $last_updated = $plugin_outdate['last_updated'];
941 $plugin_last_updated_date = new \DateTime( '@' . $last_updated );
942 $diff_in_days = $now->diff( $plugin_last_updated_date )->format( '%a' );
943 $outdate_notice = sprintf( $str_format, $diff_in_days );
944
945 ?>
946 <tr dismissed="0">
947 <td> <?php echo MainWP_System_Utility::get_plugin_icon( $item_slug ) . '&nbsp;'; // phpcs:ignore WordPress.Security.EscapeOutput ?>
948 <a href="<?php echo esc_url( admin_url() ) . 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $website->id ) . '&plugin=' . esc_html( dirname( $slug ) ) . '&url=' . ( isset( $plugin_outdate['PluginURI'] ) ? esc_url( rawurlencode( $plugin_outdate['PluginURI'] ) ) : '' ) . '&name=' . esc_url( rawurlencode( $plugin_outdate['Name'] ) ); ?>" target="_blank" class="open-plugin-details-modal"><?php echo esc_html( $plugin_outdate['Name'] ); ?></a>
949 <input type="hidden" id="wp_dismissed_plugin_<?php echo intval( $website->id ); ?>_<?php echo esc_attr( $plugin_name ); ?>" value="0"/>
950 </td>
951 <td><?php echo esc_html( $plugin_outdate['Version'] ); ?></td>
952 <td><?php echo esc_html( $outdate_notice ); ?></td>
953 <td id="wp_dismissbuttons_plugin_<?php echo intval( $website->id ); ?>_<?php echo esc_attr( $plugin_name ); ?>">
954 <?php if ( $user_can_ignore_unignore ) { ?>
955 <a href="javascript:void(0)" class="ui mini button" onClick="return updatesoverview_plugins_dismiss_outdate_detail( '<?php echo esc_js( $plugin_name ); ?>', '<?php echo esc_js( rawurlencode( $plugin_outdate['Name'] ) ); ?>', <?php echo esc_js( $website->id ); ?>, this )"><?php esc_html_e( 'Ignore Now', 'mainwp' ); ?></a>
956 <?php } ?>
957 </td>
958 </tr>
959 <?php endforeach; ?>
960 </tbody>
961 <tfoot>
962 <tr>
963 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
964 <th scope="col" ><?php esc_html_e( 'Version', 'mainwp' ); ?></th>
965 <th scope="col" ><?php esc_html_e( 'Last Update', 'mainwp' ); ?></th>
966 <th scope="col" class="no-sort"></th>
967 </tr>
968 </tfoot>
969 </table>
970 <?php else : ?>
971 <?php MainWP_UI::render_empty_page_placeholder( __( 'No abandoned plugins found', 'mainwp' ), __( 'No abandoned plugins detected on this site.', 'mainwp' ) ); ?>
972 <?php endif; ?>
973 </div>
974 <?php
975 }
976
977 /**
978 * Method render_abandoned_themes()
979 *
980 * Render the Abandoned Themes tab.
981 *
982 * @param mixed $website Child Site info.
983 * @param mixed $active_tab Current active tab.
984 * @param mixed $userExtension MainWP trusted themes data.
985 *
986 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
987 */
988 public static function render_abandoned_themes( $website, $active_tab, $userExtension ) {
989
990 $user_can_ignore_unignore = \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' );
991
992 $themes_outdate = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' );
993 $themes_outdate = ! empty( $themes_outdate ) ? json_decode( $themes_outdate, true ) : array();
994
995 if ( ! is_array( $themes_outdate ) ) {
996 $themes_outdate = array();
997 }
998
999 if ( ! empty( $themes_outdate ) ) {
1000 $themesOutdateDismissed = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_dismissed' );
1001 $themesOutdateDismissed = ! empty( $themesOutdateDismissed ) ? json_decode( $themesOutdateDismissed, true ) : array();
1002
1003 if ( is_array( $themesOutdateDismissed ) ) {
1004 $themes_outdate = array_diff_key( $themes_outdate, $themesOutdateDismissed );
1005 }
1006
1007 $decodedDismissedThemes = json_decode( $userExtension->dismissed_themes, true );
1008 if ( is_array( $decodedDismissedThemes ) ) {
1009 $themes_outdate = array_diff_key( $themes_outdate, $decodedDismissedThemes );
1010 }
1011 }
1012
1013 /* translators: %s: Number of days since last update */
1014 $str_format = esc_html__( 'Updated %s days ago', 'mainwp' );
1015
1016 ?>
1017 <div class="ui <?php echo 'abandoned-themes' === $active_tab ? 'active' : ''; ?> tab" data-tab="abandoned-themes">
1018 <?php if ( ! empty( $themes_outdate ) ) : ?>
1019 <table style="width:100% !important;" class="ui tablet stackable table mainwp-manage-updates-table" id="mainwp-abandoned-themes-table">
1020 <thead>
1021 <tr>
1022 <th scope="col"><?php esc_html_e( 'Theme', 'mainwp' ); ?></th>
1023 <th scope="col"><?php esc_html_e( 'Version', 'mainwp' ); ?></th>
1024 <th scope="col"><?php esc_html_e( 'Last Update', 'mainwp' ); ?></th>
1025 <th scope="col" class="no-sort"></th>
1026 </tr>
1027 </thead>
1028 <tbody site_id="<?php echo intval( $website->id ); ?>" site_name="<?php echo esc_attr( rawurlencode( stripslashes( $website->name ) ) ); ?>">
1029 <?php foreach ( $themes_outdate as $slug => $theme_outdate ) : ?>
1030 <?php
1031 $theme_name = rawurlencode( $slug );
1032 $now = new \DateTime();
1033 $last_updated = $theme_outdate['last_updated'];
1034 $theme_last_updated_date = new \DateTime( '@' . $last_updated );
1035 $diff_in_days = $now->diff( $theme_last_updated_date )->format( '%a' );
1036 $outdate_notice = sprintf( $str_format, $diff_in_days );
1037 ?>
1038 <tr dismissed="0">
1039 <td>
1040 <?php echo MainWP_System_Utility::get_theme_icon( $slug ) . '&nbsp;' . esc_html( $theme_outdate['Name'] ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
1041 <input type="hidden" id="wp_dismissed_theme_<?php echo intval( $website->id ); ?>_<?php echo esc_attr( $theme_name ); ?>" value="0"/>
1042 </td>
1043 <td><?php echo esc_html( $theme_outdate['Version'] ); ?></td>
1044 <td><?php echo esc_html( $outdate_notice ); ?></td>
1045 <td id="wp_dismissbuttons_theme_<?php echo intval( $website->id ); ?>_<?php echo esc_attr( $theme_name ); ?>">
1046 <?php if ( $user_can_ignore_unignore ) { ?>
1047 <a href="javascript:void(0)" class="ui mini button" onClick="return updatesoverview_themes_dismiss_outdate_detail( '<?php echo esc_js( $theme_name ); ?>', '<?php echo esc_js( rawurlencode( $theme_outdate['Name'] ) ); ?>', <?php echo intval( $website->id ); ?>, this )"><?php esc_html_e( 'Ignore Now', 'mainwp' ); ?></a>
1048 <?php } ?>
1049 </td>
1050 </tr>
1051 <?php endforeach; ?>
1052 </tbody>
1053 </table>
1054 <?php else : ?>
1055 <?php MainWP_UI::render_empty_page_placeholder( __( 'No abandoned themes found', 'mainwp' ), __( 'No abandoned themes detected on this site.', 'mainwp' ) ); ?>
1056 <?php endif; ?>
1057 </div>
1058 <?php
1059 }
1060 }
1061