get_sites_connections_status();
if ( ! is_array( $counts ) ) {
$counts = array();
}
$count_connected = ! empty( $counts['connected_sites'] ) ? (int) $counts['connected_sites'] : 0;
$count_disconnected = ! empty( $counts['disconnected_sites'] ) ? (int) $counts['disconnected_sites'] : 0;
static::render_content( $count_connected, $count_disconnected );
MainWP_UI::render_modal_reconnect();
}
/**
* The renders the MainWP Operations page Connection Status Widget Header and Drop down Box.
*
* @param int $count_connected Number of connected sites.
* @param int $count_disconnected Number of disconnected sites.
*/
public static function render_content( $count_connected, $count_disconnected ) {
?>
'false',
'paging' => 'true',
'pagingType' => 'full_numbers',
'info' => 'false',
'colReorder' => '{columns:":not(.check-column):not(:last-child)"}',
'stateSave' => 'false',
'stateDuration' => '60 * 60 * 24 * 30',
'order' => '[]',
'scrollX' => 'true',
'responsive' => 'true',
'fixedColumns' => '',
'searchDelay' => 350,
'numbers' => 3,
);
$pages_length = array(
25 => '25',
);
$pagelength_val = implode( ',', array_keys( $pages_length ) );
$pagelength_title = implode( ',', array_values( $pages_length ) );
?>
esc_html__( 'Detail', 'mainwp' ),
);
}
/**
* Echo the column headers.
*
* @return void
*/
public static function print_column_headers() {
$columns = static::get_columns();
foreach ( $columns as $column_event_key => $column_display_name ) {
$class = array( 'manage-' . $column_event_key . '-column' );
$attr = '';
$class[] = 'no-sort';
$tag = 'th';
$id = "id='$column_event_key'";
if ( ! empty( $class ) ) {
$class = "class='" . join( ' ', $class ) . "'";
}
echo "<$tag $id $class $attr style=\"display:none;\">$column_display_name$tag>"; // phpcs:ignore WordPress.Security.EscapeOutput
}
}
/**
* The renders the connections status tab.
*
* @param string $current_tab The current tab.
*/
public function prepare_items( $current_tab ) {
// phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( ! in_array( $current_tab, array( 'all-sites', 'connected', 'disconnected' ), true ) ) {
wp_die( wp_json_encode( array( 'error' => __( 'The selected site\'s status is invalid. Please try again.', 'mainwp' ) ) ) );
}
$per_page = isset( $_POST['per_page'] ) ? intval( wp_unslash( $_POST['per_page'] ) ) : 25; // phpcs:ignore -- NOSONAR - ok.
$page = isset( $_POST['page'] ) ? intval( wp_unslash( $_POST['page'] ) ) : 1; // phpcs:ignore -- NOSONAR - ok.
$perPage = isset( $_REQUEST['length'] ) ? intval( $_REQUEST['length'] ) : 25;
$start = isset( $_REQUEST['start'] ) ? intval( $_REQUEST['start'] ) : 0;
// phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$status = $current_tab;
if ( 'all-sites' === $status ) {
$status = 'any';
}
$wpsite_fields = array( 'id', 'name', 'url', 'adminname' );
$sync_fields = array( 'sync_errors', 'dtsSync' );
$args = array(
'select_wp_fields' => $wpsite_fields,
'select_sync_fields' => $sync_fields,
'status' => $status,
'offset' => $start,
'rowcount' => $perPage,
'orderby' => 'wp.url',
'view' => 'custom_view',
'others_fields' => array(),
);
$results = MainWP_DB::instance()->query(
MainWP_DB::instance()->get_sql_websites_for_current_user_by_params(
apply_filters(
'mainwp_connection_status_widget_get_sites_query_params',
$args
)
)
);
$items = array();
while ( $results && $website = MainWP_DB::fetch_object( $results ) ) {
$items[] = $website;
}
MainWP_DB::free_result( $results );
$args['count_sql'] = true;
$total_sql = MainWP_DB::instance()->get_sql_websites_for_current_user_by_params(
apply_filters(
'mainwp_connection_status_widget_get_sites_query_params',
$args
)
);
$total_items = MainWP_DB::instance()->get_var_field( $total_sql );
$this->items = $items;
$this->total_items = $total_items ? (int) $total_items : 0;
unset( $items );
}
/**
* Method ajax_display_rows()
*
* Display table rows.
*/
public function ajax_display_rows() {
MainWP_Post_Handler::instance()->check_security( 'mainwp_widgets_connections_status_details_display_rows' );
$current_tab = isset( $_POST['current_tab'] ) ? sanitize_text_field( wp_unslash( $_POST['current_tab'] ) ) : ''; // phpcs:ignore -- NOSONAR - ok.
$this->prepare_items( $current_tab );
$output = $this->ajax_get_datatable_rows( $current_tab );
wp_send_json( $output );
}
/**
* Get table rows.
*
* @param string $current_tab The current tab.
*
* @return array Rows html.
*/
public function ajax_get_datatable_rows( $current_tab ) {
$all_rows = array();
$info_rows = array();
$columns = static::get_columns();
if ( $this->items ) {
foreach ( $this->items as $site ) {
$rw_classes = 'mainwp-connect-status-item-' . intval( $site->id );
$info_item = array(
'rowClass' => esc_html( $rw_classes ),
'site_id' => $site->id,
);
$cols_data = array();
foreach ( $columns as $column_name => $column_display_name ) {
ob_start();
echo $this->column_default( $site, $column_name, $current_tab ); // phpcs:ignore WordPress.Security.EscapeOutput
$cols_data[ $column_name ] = ob_get_clean();
}
$all_rows[] = $cols_data;
$info_rows[] = $info_item;
}
}
return array(
'data' => $all_rows,
'recordsTotal' => (int) $this->total_items,
'recordsFiltered' => (int) $this->total_items,
'rowsInfo' => $info_rows,
);
}
/**
* Returns the column content for the provided item and column.
*
* @param object $website Website data.
* @param string $column_name Column name.
* @param string $current_tab The current tab.
*
* @return string $out Output.
*/
public function column_default( $website, $column_name, $current_tab ) { //phpcs:ignore -- NOSONAR -complex.
$status = $current_tab;
if ( 'all-sites' === $current_tab ) {
$status = 'any';
}
$SYNCERRORS = 'disconnected';
$UP = 'connected';
$ALL = 'any';
$output = '';
if ( 'status_details' === $column_name ) {
$hasSyncErrors = ( '' !== $website->sync_errors );
$lastSyncTime = ! empty( $website->dtsSync ) ? MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $website->dtsSync ) ) : '';
ob_start();
if ( $status === $ALL ) {
static::render_all_item( $website, $lastSyncTime, $hasSyncErrors );
} elseif ( $status === $UP ) {
static::render_up_item( $website, $lastSyncTime );
} elseif ( $status === $SYNCERRORS ) {
static::render_down_item( $website, $lastSyncTime );
}
/**
* Action: mainwp_connection_status_widget_bottom
*
* Fires at the bottom of the Connection Status widget.
*
* @since 4.1
*/
do_action( 'mainwp_connection_status_widget_bottom' );
$output = ob_get_clean();
}
if ( empty( $output ) ) {
return '';
}
return $output; //phpcs:ignore -- escaped.
}
/**
* Render connection status summary section.
*
* @param int $count_connected Connected Count.
* @param int $count_disconnected Disconnected Count.
*/
public static function render_multi_status( $count_connected, $count_disconnected ) {
?>