';
echo '
';
echo '';
foreach ( $modules as $key => $module ) {
$is_enabled = $data[ $key ]['enabled'] ?? false;
$has_toggle = null !== $module['option_key'];
$events = $data[ $key ]['events'] ?? array();
$stats = $data[ $key ]['stats'] ?? array();
$card_class = 'advan-dashboard-card';
$card_class .= $is_enabled ? ' advan-card-enabled' : ' advan-card-disabled';
$tab_anchor = '#aadvana-options-tab-' . $module['settings_tab'];
echo '
';
// Card header.
echo '';
// Card body.
echo '
';
if ( ! $is_enabled ) {
echo '
';
echo '
';
echo '
' . \esc_html__( 'Module disabled', '0-day-analytics' ) . '
';
echo '
' . \esc_html( $module['description'] ) . '
';
echo '
';
} elseif ( 'server_info' === $key && ! empty( $stats ) ) {
self::render_server_info_card( $stats );
} elseif ( 'crons' === $key && ! empty( $stats ) ) {
self::render_crons_card( $stats );
} elseif ( 'transients' === $key && ! empty( $stats ) ) {
self::render_transients_card( $stats );
} elseif ( 'security' === $key ) {
self::render_security_card( $stats, $events );
} elseif ( 'rest_api' === $key && ! empty( $stats ) ) {
self::render_rest_api_card( $stats );
} elseif ( 'traffic' === $key && ! empty( $stats ) ) {
self::render_traffic_card( $stats );
} elseif ( 'requests' === $key ) {
self::render_requests_card( $stats, $events );
} elseif ( ! empty( $stats ) ) {
self::render_stats_card( $stats, $module );
} elseif ( ! empty( $events ) ) {
self::render_events_card( $events, $module );
} else {
echo '
';
echo '
' . \esc_html( $module['description'] ) . '
';
echo '
' . \esc_html__( 'No recent data', '0-day-analytics' ) . '';
echo '
';
}
echo '
';
// Card footer.
if ( $is_enabled ) {
echo '';
}
echo '
';
}
echo '
';
echo '';
}
/**
* Render the dark/light theme toggle switch.
*
* @return void
*/
private static function render_theme_switch(): void {
echo '';
}
/**
* Render server info card content with gauges.
*
* @param array $stats Server info stats.
*
* @return void
*/
private static function render_server_info_card( array $stats ): void {
echo '';
foreach ( $stats as $metric_key => $metric ) {
$value = round( (float) $metric['value'] );
$color = $value < 55 ? 'var(--advan-success)' : ( $value < 80 ? 'var(--advan-warning)' : 'var(--advan-danger)' );
echo '
';
echo '
';
echo '
';
echo '
' . \esc_html( $value . '%' ) . '';
echo '
';
echo '
' . \esc_html( $metric['label'] ) . '';
echo '
';
}
echo '
';
}
/**
* Render crons card content with statistics.
*
* @param array $stats Crons stats.
*
* @return void
*/
private static function render_crons_card( array $stats ): void {
echo '';
echo '
';
echo '' . \esc_html( (string) ( $stats['total'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Total', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['core'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'WP Core', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['custom'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Custom', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['noaction'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'No Callback', '0-day-analytics' ) . '';
echo '
';
echo '
';
}
/**
* Render transients card content with statistics.
*
* @param array $stats Transients stats.
*
* @return void
*/
private static function render_transients_card( array $stats ): void {
echo '';
echo '
';
echo '' . \esc_html( (string) ( $stats['total'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Total', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['core'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'WP Core', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['custom'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Custom', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['expired'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Expired', '0-day-analytics' ) . '';
echo '
';
echo '
';
}
/**
* Render security card with events and stats.
*
* @param array $stats Security summary stats.
* @param array $events Recent security events.
*
* @return void
*/
private static function render_security_card( array $stats, array $events ): void {
if ( ! empty( $stats ) ) {
echo '';
echo '
';
echo '' . \esc_html( (string) ( $stats['total_events'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Total Events', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['critical_7_days'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Critical (7d)', '0-day-analytics' ) . '';
echo '
';
echo '
';
}
if ( ! empty( $events ) ) {
self::render_events_card( $events, array() );
} elseif ( empty( $stats ) ) {
echo '';
echo '' . \esc_html__( 'No security events', '0-day-analytics' ) . '';
echo '
';
}
}
/**
* Render REST API card with endpoint stats.
*
* @param array $stats REST API stats.
*
* @return void
*/
private static function render_rest_api_card( array $stats ): void {
echo '';
echo '
';
echo '' . \esc_html( (string) ( $stats['total'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Total', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['enabled'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Enabled', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['disabled'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Disabled', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['obfuscated'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Obfuscated', '0-day-analytics' ) . '';
echo '
';
echo '
';
}
/**
* Render traffic card with today's stats.
*
* @param array $stats Traffic stats.
*
* @return void
*/
private static function render_traffic_card( array $stats ): void {
echo '';
if ( isset( $stats['online'] ) ) {
echo '
';
echo '' . \esc_html( (string) $stats['online'] ) . '';
echo '' . \esc_html__( 'Online (30 min)', '0-day-analytics' ) . '';
echo '
';
}
echo '
';
echo '' . \esc_html( (string) ( $stats['visitors'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Visitors Today', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['pageviews'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Pageviews Today', '0-day-analytics' ) . '';
echo '
';
echo '
';
}
/**
* Render generic stats card.
*
* @param array $stats Stats data.
* @param array $module Module definition.
*
* @return void
*/
private static function render_stats_card( array $stats, array $module ): void {
echo '';
foreach ( $stats as $stat_key => $stat_value ) {
if ( is_array( $stat_value ) ) {
continue;
}
$label = ucwords( str_replace( '_', ' ', $stat_key ) );
echo '
';
echo '' . \esc_html( (string) $stat_value ) . '';
echo '' . \esc_html( $label ) . '';
echo '
';
}
echo '
';
}
/**
* Render HTTP Requests card with stats and recent events.
*
* @param array $stats Direction statistics.
* @param array $events Recent request events.
*
* @return void
*/
private static function render_requests_card( array $stats, array $events ): void {
if ( ! empty( $stats ) ) {
echo '';
echo '
';
echo '' . \esc_html( (string) ( $stats['internal'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'Internal', '0-day-analytics' ) . '';
echo '
';
echo '
';
echo '' . \esc_html( (string) ( $stats['external'] ?? 0 ) ) . '';
echo '' . \esc_html__( 'External', '0-day-analytics' ) . '';
echo '
';
echo '
';
}
if ( ! empty( $events ) ) {
self::render_events_card( $events, array() );
}
if ( empty( $stats ) && empty( $events ) ) {
echo '';
echo '' . \esc_html__( 'No recent data', '0-day-analytics' ) . '';
echo '
';
}
}
/**
* Render events card with recent entries.
*
* @param array $events Events data.
* @param array $module Module definition.
*
* @return void
*/
private static function render_events_card( array $events, array $module ): void {
echo '';
}
}
}