| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Client Overview Sites Widget |
| 4 |
* |
| 5 |
* Displays the Client Info. |
| 6 |
* |
| 7 |
* @package MainWP/MainWP_Client_Overview_Sites |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace MainWP\Dashboard; |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Class MainWP_Client_Overview_Sites |
| 19 |
* |
| 20 |
* Displays the Client info. |
| 21 |
*/ |
| 22 |
class MainWP_Client_Overview_Sites { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. |
| 23 |
|
| 24 |
|
| 25 |
/** |
| 26 |
* Public variable to hold Items information. |
| 27 |
* |
| 28 |
* @var array |
| 29 |
*/ |
| 30 |
public $items; |
| 31 |
|
| 32 |
/** |
| 33 |
* Public variable to hold Total Items information. |
| 34 |
* |
| 35 |
* @var array |
| 36 |
*/ |
| 37 |
public $total_items; |
| 38 |
|
| 39 |
/** |
| 40 |
* Protected variable to hold columns headers |
| 41 |
* |
| 42 |
* @var array |
| 43 |
*/ |
| 44 |
protected $column_headers; |
| 45 |
|
| 46 |
|
| 47 |
/** |
| 48 |
* The single instance of the class |
| 49 |
* |
| 50 |
* @var mixed Default null |
| 51 |
*/ |
| 52 |
protected static $instance = null; |
| 53 |
|
| 54 |
/** |
| 55 |
* Protected variable to hold User extension. |
| 56 |
* |
| 57 |
* @var mixed Default null. |
| 58 |
*/ |
| 59 |
protected $userExtension = null; |
| 60 |
|
| 61 |
/** |
| 62 |
* Method get_class_name() |
| 63 |
* |
| 64 |
* @return string __CLASS__ Class name. |
| 65 |
*/ |
| 66 |
public static function get_class_name() { |
| 67 |
return __CLASS__; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Check if there is a session, |
| 72 |
* if there isn't one create it. |
| 73 |
* |
| 74 |
* @return static::singlton Overview Page Session. |
| 75 |
* |
| 76 |
* @uses \MainWP\Dashboard\MainWP_Overview |
| 77 |
*/ |
| 78 |
public static function instance() { |
| 79 |
if ( null === static::$instance ) { |
| 80 |
static::$instance = new self(); |
| 81 |
} |
| 82 |
|
| 83 |
return static::$instance; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Method render() |
| 88 |
* |
| 89 |
* @return mixed render_site_info() |
| 90 |
*/ |
| 91 |
public static function render() { |
| 92 |
$client_id = isset( $_GET['client_id'] ) ? intval( $_GET['client_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 93 |
if ( empty( $client_id ) ) { |
| 94 |
return; |
| 95 |
} |
| 96 |
static::instance()->render_websites( $client_id ); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
/** |
| 101 |
* Render client overview Info. |
| 102 |
* |
| 103 |
* @param object $client_id Client ID. |
| 104 |
*/ |
| 105 |
public function render_websites( $client_id ) { |
| 106 |
|
| 107 |
$client_info = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $client_id, ARRAY_A ); |
| 108 |
|
| 109 |
?> |
| 110 |
<div class="mainwp-widget-header"> |
| 111 |
<h2 class="ui header handle-drag"> |
| 112 |
<?php |
| 113 |
/** |
| 114 |
* Filter: mainwp_clients_overview_websites_widget_title |
| 115 |
* |
| 116 |
* Filters the Site info widget title text. |
| 117 |
* |
| 118 |
* @param object $client_info Object containing the child site info. |
| 119 |
* |
| 120 |
* @since 4.1 |
| 121 |
*/ |
| 122 |
echo esc_html( apply_filters( 'mainwp_clients_overview_websites_widget_title', esc_html__( 'Sites', 'mainwp' ), $client_info ) ); |
| 123 |
?> |
| 124 |
<div class="sub header"><?php echo esc_html__( 'Websites that belong to the client.', 'mainwp' ); ?></div> |
| 125 |
</h2> |
| 126 |
</div> |
| 127 |
<div class="mainwp-widget-client-card mainwp-scrolly-overflow"> |
| 128 |
<?php |
| 129 |
/** |
| 130 |
* Actoin: mainwp_clients_overview_websites_widget_top |
| 131 |
* |
| 132 |
* Fires at the top of the Site Info widget on the Individual site overview page. |
| 133 |
* |
| 134 |
* @param object $client_info Object containing the child site info. |
| 135 |
* |
| 136 |
* @since 4.0 |
| 137 |
*/ |
| 138 |
do_action( 'mainwp_clients_overview_websites_widget_top', $client_info ); |
| 139 |
?> |
| 140 |
<?php |
| 141 |
if ( $client_info ) { |
| 142 |
$this->prepare_items( $client_id ); |
| 143 |
?> |
| 144 |
<table id="mainwp-manage-sites-monitor-table" style="width:100%" class="ui unstackable table mainwp-with-preview-table"> |
| 145 |
<thead> |
| 146 |
<tr><?php $this->print_column_headers( true ); ?></tr> |
| 147 |
</thead> |
| 148 |
<tbody id="mainwp-manage-sites-body-table"> |
| 149 |
<?php $this->display_rows_or_placeholder(); ?> |
| 150 |
</tbody> |
| 151 |
</table> |
| 152 |
<?php } ?> |
| 153 |
<?php |
| 154 |
/** |
| 155 |
* Action: mainwp_clients_overview_websites_widget_bottom |
| 156 |
* |
| 157 |
* Fires at the bottom of the Site Info widget on the Individual site overview page. |
| 158 |
* |
| 159 |
* @param object $client_info Object containing the child site info. |
| 160 |
* |
| 161 |
* @since 4.0 |
| 162 |
*/ |
| 163 |
do_action( 'mainwp_clients_overview_websites_widget_bottom', $client_info ); |
| 164 |
?> |
| 165 |
</div> |
| 166 |
<div class="ui grid mainwp-widget-footer"> |
| 167 |
<div class="column"> |
| 168 |
<a href="admin.php?page=managesites&client=<?php echo intval( $client_id ); ?>" title="" class="ui mini basic button"><?php echo esc_html__( 'Manage Client Sites', 'mainwp' ); ?></a> |
| 169 |
</div> |
| 170 |
</div> |
| 171 |
|
| 172 |
<?php |
| 173 |
// @NO_SONAR_START@ - duplicated issue. |
| 174 |
|
| 175 |
$sites_per_page = get_option( 'mainwp_default_sites_per_page', 25 ); |
| 176 |
|
| 177 |
$sites_per_page = intval( $sites_per_page ); |
| 178 |
|
| 179 |
$pages_length = array( |
| 180 |
25 => '25', |
| 181 |
10 => '10', |
| 182 |
50 => '50', |
| 183 |
100 => '100', |
| 184 |
300 => '300', |
| 185 |
); |
| 186 |
|
| 187 |
$pages_length = $pages_length + array( $sites_per_page => $sites_per_page ); |
| 188 |
ksort( $pages_length ); |
| 189 |
|
| 190 |
if ( isset( $pages_length[-1] ) ) { |
| 191 |
unset( $pages_length[-1] ); |
| 192 |
} |
| 193 |
|
| 194 |
$pagelength_val = implode( ',', array_keys( $pages_length ) ); |
| 195 |
$pagelength_title = implode( ',', array_values( $pages_length ) ); |
| 196 |
|
| 197 |
$table_features = array( |
| 198 |
'searching' => 'true', |
| 199 |
'paging' => 'true', |
| 200 |
'info' => 'false', |
| 201 |
'colReorder' => '{ columns:":not(.manage-status-column):not(.manage-site_actions-column)"} ', |
| 202 |
'stateSave' => 'true', |
| 203 |
'stateDuration' => '60 * 60 * 24 * 30', |
| 204 |
'order' => '[]', |
| 205 |
'scrollX' => 'true', |
| 206 |
'responsive' => 'true', |
| 207 |
'searchDelay' => 350, |
| 208 |
); |
| 209 |
|
| 210 |
?> |
| 211 |
|
| 212 |
<script type="text/javascript"> |
| 213 |
jQuery( document ).ready( function( $ ) { |
| 214 |
let responsive = true; |
| 215 |
if( jQuery( window ).width() > 1140 ) { |
| 216 |
responsive = false; |
| 217 |
} |
| 218 |
try { |
| 219 |
$manage_sites_table = jQuery( '#mainwp-manage-sites-monitor-table' ).DataTable( { |
| 220 |
"searching" : <?php echo esc_js( $table_features['searching'] ); ?>, |
| 221 |
"responsive": responsive, |
| 222 |
"paging" : <?php echo esc_js( $table_features['paging'] ); ?>, |
| 223 |
"info" : <?php echo esc_js( $table_features['info'] ); ?>, |
| 224 |
"layout": { |
| 225 |
"bottom": 'paging', |
| 226 |
"bottomStart": null, |
| 227 |
"bottomEnd": null |
| 228 |
}, |
| 229 |
"scrollX" : <?php echo esc_js( $table_features['scrollX'] ); ?>, |
| 230 |
"colReorder" : <?php echo $table_features['colReorder']; // phpcs:ignore -- specical chars. ?>, |
| 231 |
"stateSave" : <?php echo esc_js( $table_features['stateSave'] ); ?>, |
| 232 |
"stateDuration" : <?php echo esc_js( $table_features['stateDuration'] ); ?>, |
| 233 |
"order" : <?php echo $table_features['order']; // phpcs:ignore -- specical chars. ?>, |
| 234 |
"lengthMenu" : [ [<?php echo esc_js( $pagelength_val ); ?>, -1 ], [<?php echo esc_js( $pagelength_title ); ?>, "All" ] ], |
| 235 |
"columnDefs": <?php echo wp_json_encode( $this->get_columns_defines() ); ?>, |
| 236 |
"pageLength": <?php echo intval( $sites_per_page ); ?>, |
| 237 |
"initComplete": function( settings, json ) { |
| 238 |
}, |
| 239 |
"language": { |
| 240 |
"emptyTable": "<?php esc_html_e( 'No websites found.', 'mainwp' ); ?>" |
| 241 |
}, |
| 242 |
"drawCallback": function( settings ) { |
| 243 |
if ( jQuery('#mainwp-manage-sites-body-table td.dt-empty').length > 0 && jQuery('#sites-table-count-empty').length ){ |
| 244 |
jQuery('#mainwp-manage-sites-body-table td.dt-empty').html(jQuery('#sites-table-count-empty').html()); |
| 245 |
} |
| 246 |
}, |
| 247 |
stateSaveParams: function (settings, data) { |
| 248 |
data._mwpv = mainwpParams.mainwpVersion || 'dev'; |
| 249 |
}, |
| 250 |
stateLoadParams: function (settings, data) { |
| 251 |
if ((mainwpParams.mainwpVersion || 'dev') !== data._mwpv) return false; |
| 252 |
}, |
| 253 |
search: { regex: false, smart: false }, |
| 254 |
orderMulti: false, |
| 255 |
searchDelay: <?php echo intval( $table_features['searchDelay'] ); ?> |
| 256 |
} ).on( 'columns-reordered', function () { |
| 257 |
setTimeout(() => { |
| 258 |
$( '#mainwp-manage-sites-monitor-table .ui.dropdown' ).dropdown(); |
| 259 |
$( '#mainwp-manage-sites-monitor-table .ui.checkbox' ).checkbox(); |
| 260 |
mainwp_datatable_fix_menu_overflow( '#mainwp-manage-sites-monitor-table' ); |
| 261 |
}, 1000 ); |
| 262 |
} ); |
| 263 |
} catch(err) { |
| 264 |
// to fix js error. |
| 265 |
console.log(err); |
| 266 |
} |
| 267 |
mainwp_datatable_fix_menu_overflow( '#mainwp-manage-sites-monitor-table' ); |
| 268 |
}); |
| 269 |
</script> |
| 270 |
<?php |
| 271 |
// @NO_SONAR_END@ . |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
/** |
| 276 |
* Prepare the items to be listed. |
| 277 |
* |
| 278 |
* @param int $client_id client id. |
| 279 |
*/ |
| 280 |
public function prepare_items( $client_id ) { |
| 281 |
|
| 282 |
if ( null === $this->userExtension ) { |
| 283 |
$this->userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 284 |
} |
| 285 |
|
| 286 |
$total_params = array( |
| 287 |
'count_only' => true, |
| 288 |
'selectgroups' => true, |
| 289 |
'orderby' => 'wp.url', |
| 290 |
'offset' => 0, |
| 291 |
'rowcount' => 9999, |
| 292 |
'client_id' => array( $client_id ), |
| 293 |
); |
| 294 |
|
| 295 |
$params = array( |
| 296 |
'selectgroups' => true, |
| 297 |
'orderby' => 'wp.url', |
| 298 |
'offset' => 0, |
| 299 |
'rowcount' => 9999, |
| 300 |
'client_id' => array( $client_id ), |
| 301 |
); |
| 302 |
|
| 303 |
$totalRecords = 0; |
| 304 |
$websites = false; |
| 305 |
|
| 306 |
if ( $client_id ) { |
| 307 |
$total_websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_search_websites_for_current_user( $total_params ) ); |
| 308 |
$totalRecords = ( $total_websites ? MainWP_DB::num_rows( $total_websites ) : 0 ); |
| 309 |
$websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_search_websites_for_current_user( $params ) ); |
| 310 |
} |
| 311 |
|
| 312 |
$this->items = $websites; |
| 313 |
$this->total_items = $totalRecords; |
| 314 |
} |
| 315 |
|
| 316 |
/** |
| 317 |
* Echo the column headers. |
| 318 |
*/ |
| 319 |
public function print_column_headers() { |
| 320 |
|
| 321 |
list( $columns ) = $this->get_column_info(); |
| 322 |
|
| 323 |
$sortable = array( |
| 324 |
'site' => array( 'site', false ), |
| 325 |
'update' => array( 'update', false ), |
| 326 |
'client_name' => array( 'client_name', false ), |
| 327 |
); |
| 328 |
|
| 329 |
$def_columns = $columns; |
| 330 |
$def_columns['site_actions'] = ''; |
| 331 |
|
| 332 |
foreach ( $columns as $column_overview_key => $column_display_name ) { |
| 333 |
|
| 334 |
$class = array( 'manage-' . $column_overview_key . '-column' ); |
| 335 |
$attr = ''; |
| 336 |
if ( ! isset( $def_columns[ $column_overview_key ] ) ) { |
| 337 |
$class[] = 'extra-column'; |
| 338 |
} |
| 339 |
|
| 340 |
if ( ! isset( $sortable[ $column_overview_key ] ) ) { |
| 341 |
$class[] = 'no-sort'; |
| 342 |
} |
| 343 |
|
| 344 |
$tag = 'th'; |
| 345 |
$id = "id='$column_overview_key'"; |
| 346 |
|
| 347 |
if ( ! empty( $class ) ) { |
| 348 |
$class = "class='" . join( ' ', $class ) . "'"; |
| 349 |
} |
| 350 |
|
| 351 |
echo "<$tag $id $class $attr>$column_display_name</$tag>"; // phpcs:ignore WordPress.Security.EscapeOutput |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
/** |
| 357 |
* Return empty table place holders. |
| 358 |
*/ |
| 359 |
public function display_rows_or_placeholder() { |
| 360 |
if ( $this->has_items() ) { |
| 361 |
$this->display_rows(); |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
/** |
| 368 |
* Fetch single row item. |
| 369 |
* |
| 370 |
* @return mixed Single Row Item. |
| 371 |
* |
| 372 |
* @uses \MainWP\Dashboard\MainWP_DB::is_result() |
| 373 |
* @uses \MainWP\Dashboard\MainWP_DB::fetch_array() |
| 374 |
*/ |
| 375 |
public function display_rows() { |
| 376 |
if ( MainWP_DB::is_result( $this->items ) ) { |
| 377 |
while ( $this->items && ( $item = MainWP_DB::fetch_array( $this->items ) ) ) { |
| 378 |
$this->single_row( $item ); |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
/** |
| 384 |
* Single Row. |
| 385 |
* |
| 386 |
* @param mixed $website Child Site. |
| 387 |
* |
| 388 |
* @uses \MainWP\Dashboard\MainWP_Utility::sanitize_file_name() |
| 389 |
*/ |
| 390 |
public function single_row( $website ) { |
| 391 |
$classes = ''; |
| 392 |
$hasSyncErrors = ( '' !== $website['sync_errors'] ); |
| 393 |
$classes = ' class="child-site mainwp-child-site-' . intval( $website['id'] ) . ' ' . ( $hasSyncErrors ? 'error' : '' ) . ' ' . $classes . '"'; |
| 394 |
echo '<tr id="child-site-' . intval( $website['id'] ) . '"' . $classes . ' siteid="' . intval( $website['id'] ) . '" site-url="' . esc_url( $website['url'] ) . '">'; // phpcs:ignore WordPress.Security.EscapeOutput |
| 395 |
$this->single_row_columns( $website ); |
| 396 |
echo '</tr>'; |
| 397 |
} |
| 398 |
|
| 399 |
/** |
| 400 |
* Get default columns. |
| 401 |
* |
| 402 |
* @return array Array of default column names. |
| 403 |
*/ |
| 404 |
public function get_default_columns() { |
| 405 |
return array( |
| 406 |
'status' => '', |
| 407 |
'site' => esc_html__( 'Site', 'mainwp' ), |
| 408 |
'update' => esc_html__( 'Updates', 'mainwp' ), |
| 409 |
); |
| 410 |
} |
| 411 |
|
| 412 |
/** |
| 413 |
* Method get_columns() |
| 414 |
* |
| 415 |
* Combine all columns. |
| 416 |
* |
| 417 |
* @return array $columns Array of column names. |
| 418 |
*/ |
| 419 |
public function get_columns() { |
| 420 |
|
| 421 |
$columns = $this->get_default_columns(); |
| 422 |
|
| 423 |
$columns['site_actions'] = ''; |
| 424 |
|
| 425 |
return $columns; |
| 426 |
} |
| 427 |
|
| 428 |
/** |
| 429 |
* Get column info. |
| 430 |
*/ |
| 431 |
protected function get_column_info() { |
| 432 |
|
| 433 |
if ( isset( $this->column_headers ) && is_array( $this->column_headers ) ) { |
| 434 |
$column_headers = array( array(), array(), array() ); |
| 435 |
foreach ( $this->column_headers as $key => $value ) { |
| 436 |
$column_headers[ $key ] = $value; |
| 437 |
} |
| 438 |
|
| 439 |
return $column_headers; |
| 440 |
} |
| 441 |
|
| 442 |
$columns = $this->get_columns(); |
| 443 |
|
| 444 |
$this->column_headers = array( $columns ); |
| 445 |
|
| 446 |
return $this->column_headers; |
| 447 |
} |
| 448 |
|
| 449 |
/** |
| 450 |
* Get column defines. |
| 451 |
* |
| 452 |
* @return array $defines |
| 453 |
*/ |
| 454 |
public function get_columns_defines() { |
| 455 |
$defines = array(); |
| 456 |
$defines[] = array( |
| 457 |
'targets' => 'no-sort', |
| 458 |
'orderable' => false, |
| 459 |
); |
| 460 |
$defines[] = array( |
| 461 |
'targets' => array( 'manage-status-column' ), |
| 462 |
'className' => 'collapsing center aligned', |
| 463 |
); |
| 464 |
$defines[] = array( |
| 465 |
'targets' => 'manage-site-column', |
| 466 |
'className' => 'column-site-bulk mainwp-site-cell', |
| 467 |
); |
| 468 |
$defines[] = array( |
| 469 |
'targets' => array( 'manage-update-column' ), |
| 470 |
'className' => 'collapsing center aligned', |
| 471 |
); |
| 472 |
$defines[] = array( |
| 473 |
'targets' => array( 'manage-site_actions-column' ), |
| 474 |
'className' => 'collapsing right aligned', |
| 475 |
); |
| 476 |
return $defines; |
| 477 |
} |
| 478 |
|
| 479 |
/** |
| 480 |
* Columns for a single row. |
| 481 |
* |
| 482 |
* @param mixed $website Child Site. |
| 483 |
* |
| 484 |
* @uses \MainWP\Dashboard\MainWP_Connect::get_favico_url() |
| 485 |
* @uses \MainWP\Dashboard\MainWP_DB::instance()::get_website_options_array() |
| 486 |
* @uses \MainWP\Dashboard\MainWP_Utility::get_site_health() |
| 487 |
* @uses \MainWP\Dashboard\MainWP_Utility::esc_content() |
| 488 |
* @uses \MainWP\Dashboard\MainWP_Utility::get_http_codes() |
| 489 |
* @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp() |
| 490 |
* @uses \MainWP\Dashboard\MainWP_Utility::get_timestamp() |
| 491 |
*/ |
| 492 |
protected function single_row_columns( $website ) { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 493 |
|
| 494 |
$userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 495 |
$decodedIgnoredCores = ! empty( $userExtension->ignored_wp_upgrades ) ? json_decode( $userExtension->ignored_wp_upgrades, true ) : array(); |
| 496 |
|
| 497 |
// @NO_SONAR_START@ - duplicated issue. |
| 498 |
$total_wp_upgrades = 0; |
| 499 |
$total_plugin_upgrades = 0; |
| 500 |
$total_theme_upgrades = 0; |
| 501 |
|
| 502 |
$site_options = MainWP_DB::instance()->get_website_options_array( $website, array( 'wp_upgrades', 'ignored_wp_upgrades', 'premium_upgrades', 'primary_lasttime_backup' ) ); |
| 503 |
$wp_upgrades = isset( $site_options['wp_upgrades'] ) ? json_decode( $site_options['wp_upgrades'], true ) : array(); |
| 504 |
$ignored_core_upgrades = isset( $site_options['ignored_wp_upgrades'] ) ? json_decode( $site_options['ignored_wp_upgrades'], true ) : array(); |
| 505 |
|
| 506 |
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' ) ) { |
| 507 |
$wp_upgrades = array(); |
| 508 |
} |
| 509 |
|
| 510 |
if ( is_array( $wp_upgrades ) && ! empty( $wp_upgrades ) ) { |
| 511 |
++$total_wp_upgrades; |
| 512 |
} |
| 513 |
|
| 514 |
$plugin_upgrades = json_decode( $website['plugin_upgrades'], true ); |
| 515 |
|
| 516 |
if ( $website['is_ignorePluginUpdates'] ) { |
| 517 |
$plugin_upgrades = array(); |
| 518 |
} |
| 519 |
|
| 520 |
$theme_upgrades = json_decode( $website['theme_upgrades'], true ); |
| 521 |
|
| 522 |
if ( $website['is_ignoreThemeUpdates'] ) { |
| 523 |
$theme_upgrades = array(); |
| 524 |
} |
| 525 |
|
| 526 |
$decodedPremiumUpgrades = isset( $site_options['premium_upgrades'] ) ? json_decode( $site_options['premium_upgrades'], true ) : array(); |
| 527 |
if ( is_array( $decodedPremiumUpgrades ) ) { |
| 528 |
foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) { |
| 529 |
$premiumUpgrade['premium'] = true; |
| 530 |
|
| 531 |
if ( 'plugin' === $premiumUpgrade['type'] ) { |
| 532 |
if ( ! is_array( $plugin_upgrades ) ) { |
| 533 |
$plugin_upgrades = array(); |
| 534 |
} |
| 535 |
if ( ! $website['is_ignorePluginUpdates'] ) { |
| 536 |
$plugin_upgrades[ $crrSlug ] = $premiumUpgrade; |
| 537 |
} |
| 538 |
} elseif ( 'theme' === $premiumUpgrade['type'] ) { |
| 539 |
if ( ! is_array( $theme_upgrades ) ) { |
| 540 |
$theme_upgrades = array(); |
| 541 |
} |
| 542 |
if ( ! $website['is_ignoreThemeUpdates'] ) { |
| 543 |
$theme_upgrades[ $crrSlug ] = $premiumUpgrade; |
| 544 |
} |
| 545 |
} |
| 546 |
} |
| 547 |
} |
| 548 |
|
| 549 |
if ( is_array( $plugin_upgrades ) ) { |
| 550 |
|
| 551 |
$ignored_plugins = json_decode( $website['ignored_plugins'], true ); |
| 552 |
if ( is_array( $ignored_plugins ) ) { |
| 553 |
$plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins ); |
| 554 |
|
| 555 |
} |
| 556 |
|
| 557 |
$ignored_plugins = json_decode( $this->userExtension->ignored_plugins, true ); |
| 558 |
if ( is_array( $ignored_plugins ) ) { |
| 559 |
$plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins ); |
| 560 |
} |
| 561 |
|
| 562 |
$total_plugin_upgrades += count( $plugin_upgrades ); |
| 563 |
} |
| 564 |
|
| 565 |
if ( is_array( $theme_upgrades ) ) { |
| 566 |
|
| 567 |
$ignored_themes = json_decode( $website['ignored_themes'], true ); |
| 568 |
if ( is_array( $ignored_themes ) ) { |
| 569 |
$theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes ); |
| 570 |
} |
| 571 |
|
| 572 |
$ignored_themes = json_decode( $this->userExtension->ignored_themes, true ); |
| 573 |
if ( is_array( $ignored_themes ) ) { |
| 574 |
$theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes ); |
| 575 |
} |
| 576 |
|
| 577 |
$total_theme_upgrades += count( $theme_upgrades ); |
| 578 |
} |
| 579 |
|
| 580 |
$total_updates = $total_wp_upgrades + $total_plugin_upgrades + $total_theme_upgrades; |
| 581 |
$hasSyncErrors = ( '' !== $website['sync_errors'] ); |
| 582 |
|
| 583 |
// @NO_SONAR_END@ . |
| 584 |
|
| 585 |
list( $columns ) = $this->get_column_info(); |
| 586 |
|
| 587 |
foreach ( $columns as $column_name => $column_display_name ) { |
| 588 |
?> |
| 589 |
|
| 590 |
<?php if ( 'status' === $column_name ) { ?> |
| 591 |
<td class="center aligned collapsing"> |
| 592 |
<?php if ( $hasSyncErrors ) : ?> |
| 593 |
<a class="mainwp_site_reconnect" href="#"><i class="red large times icon"></i></a> |
| 594 |
<?php else : ?> |
| 595 |
<a class="managesites_syncdata" href="#"> |
| 596 |
<?php echo '1' === $website['suspended'] ? '<i class="yellow pause large icon"></i>' : '<i class="green large check icon"></i>'; ?> |
| 597 |
</a> |
| 598 |
<?php endif; ?> |
| 599 |
</td> |
| 600 |
<?php |
| 601 |
} elseif ( 'site' === $column_name ) { |
| 602 |
$cls_site = ''; |
| 603 |
if ( ! empty( $website['sync_errors'] ) ) { |
| 604 |
$cls_site = 'site-sync-error'; |
| 605 |
} |
| 606 |
?> |
| 607 |
<td class="column-site-bulk mainwp-site-cell all <?php echo esc_html( $cls_site ); ?>"> |
| 608 |
<?php if ( ! \mainwp_current_user_can( 'dashboard', 'access_wpadmin_on_child_sites' ) ) : ?> |
| 609 |
<i class="sign in icon"></i> |
| 610 |
<?php else : ?> |
| 611 |
<a href="<?php MainWP_Site_Open::get_open_site_url( $website['id'] ); ?>" data-tooltip="<?php esc_attr_e( 'Jump to the site WP Admin', 'mainwp' ); ?>" data-position="right center" data-inverted="" class="open_newwindow_wpadmin" target="_blank"><i class="sign in icon"></i></a> |
| 612 |
<?php endif; ?> |
| 613 |
<a href="<?php echo 'admin.php?page=managesites&dashboard=' . intval( $website['id'] ); ?>" > |
| 614 |
<?php echo esc_html( stripslashes( $website['name'] ) ); ?> |
| 615 |
</a> |
| 616 |
<div> |
| 617 |
<span class="ui small text"> |
| 618 |
<a href="<?php echo esc_url( $website['url'] ); ?>" class="mainwp-may-hide-referrer open_site_url ui grey text" target="_blank"> |
| 619 |
<?php echo esc_html( MainWP_Utility::get_nice_url( $website['url'] ) ); ?> |
| 620 |
</a> |
| 621 |
</span> |
| 622 |
</div> |
| 623 |
</td> |
| 624 |
<?php } elseif ( 'update' === $column_name ) { ?> |
| 625 |
<td> |
| 626 |
<a class="ui mini basic grey button" href="admin.php?page=managesites&updateid=<?php echo intval( $website['id'] ); ?>"> |
| 627 |
<i class="sync alternate icon"></i> <?php echo intval( $total_updates ); ?> |
| 628 |
</a> |
| 629 |
</td> |
| 630 |
<?php |
| 631 |
} elseif ( 'site_actions' === $column_name ) { |
| 632 |
// @NO_SONAR_START@ - duplicated issue. |
| 633 |
?> |
| 634 |
<td class="collapsing not-selectable"> |
| 635 |
<div class="ui right pointing dropdown" style="z-index: 99;"> |
| 636 |
<i class="ellipsis vertical icon"></i> |
| 637 |
<div class="menu" siteid="<?php echo intval( $website['id'] ); ?>"> |
| 638 |
<?php if ( '' !== $website['sync_errors'] ) : ?> |
| 639 |
<a class="mainwp_site_reconnect item" href="#"><?php esc_html_e( 'Reconnect', 'mainwp' ); ?></a> |
| 640 |
<?php else : ?> |
| 641 |
<a class="managesites_syncdata item" href="#"><?php esc_html_e( 'Sync Data', 'mainwp' ); ?></a> |
| 642 |
<?php endif; ?> |
| 643 |
<?php if ( \mainwp_current_user_can( 'dashboard', 'access_individual_dashboard' ) ) : ?> |
| 644 |
<a class="item" href="admin.php?page=managesites&dashboard=<?php echo intval( $website['id'] ); ?>"><?php esc_html_e( 'Overview', 'mainwp' ); ?></a> |
| 645 |
<?php endif; ?> |
| 646 |
<?php if ( \mainwp_current_user_can( 'dashboard', 'edit_sites' ) ) : ?> |
| 647 |
<a class="item" href="admin.php?page=managesites&id=<?php echo intval( $website['id'] ); ?>"><?php esc_html_e( 'Settings', 'mainwp' ); ?></a> |
| 648 |
<?php endif; ?> |
| 649 |
</div> |
| 650 |
</div> |
| 651 |
</td> |
| 652 |
<?php |
| 653 |
// @NO_SONAR_END@ . |
| 654 |
} |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
|
| 659 |
/** |
| 660 |
* Set the column names. |
| 661 |
* |
| 662 |
* @param mixed $item MainWP Sitetable Item. |
| 663 |
* @param string $column_name Column name to use. |
| 664 |
* |
| 665 |
* @return string Column Name. |
| 666 |
*/ |
| 667 |
public function column_default( $item, $column_name ) { // phpcs:ignore -- NOSONAR - comlex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 668 |
|
| 669 |
switch ( $column_name ) { |
| 670 |
case 'status': |
| 671 |
case 'site': |
| 672 |
case 'login': |
| 673 |
case 'update': |
| 674 |
case 'site_actions': |
| 675 |
return ''; |
| 676 |
default: |
| 677 |
return isset( $item[ $column_name ] ) ? $item[ $column_name ] : ''; |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
/** |
| 683 |
* Method has_items(). |
| 684 |
* |
| 685 |
* Verify if items exist. |
| 686 |
*/ |
| 687 |
public function has_items() { |
| 688 |
return ! empty( $this->items ); |
| 689 |
} |
| 690 |
|
| 691 |
/** |
| 692 |
* Clear Items. |
| 693 |
* |
| 694 |
* @uses \MainWP\Dashboard\MainWP_DB::is_result() |
| 695 |
* @uses \MainWP\Dashboard\MainWP_DB::free_result() |
| 696 |
*/ |
| 697 |
public function clear_items() { |
| 698 |
if ( MainWP_DB::is_result( $this->items ) ) { |
| 699 |
MainWP_DB::free_result( $this->items ); |
| 700 |
} |
| 701 |
} |
| 702 |
} |
| 703 |
|