add_query_arg( 'tab', $t, $base_url ); $table = $wpdb->prefix . 'aicom_backups'; // ── Dashboard data ───────────────────────────────────────────────────────── $total_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM $table" ); // phpcs:ignore $total_bytes = (int) $wpdb->get_var( "SELECT SUM(LENGTH(payload_json)) FROM $table" ); // phpcs:ignore $periods = [ '24h' => [ 'label' => __( 'Last 24 hours', 'aicom' ), 'interval' => 'INTERVAL 1 DAY' ], '7d' => [ 'label' => __( 'Last 7 days', 'aicom' ), 'interval' => 'INTERVAL 7 DAY' ], '30d' => [ 'label' => __( 'Last 30 days', 'aicom' ), 'interval' => 'INTERVAL 30 DAY' ], '1y' => [ 'label' => __( 'Last year', 'aicom' ), 'interval' => 'INTERVAL 1 YEAR' ], ]; $period_stats = []; foreach ( $periods as $key => $p ) { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $row = $wpdb->get_row( "SELECT COUNT(*) AS cnt, COALESCE(SUM(LENGTH(payload_json)),0) AS bytes FROM $table WHERE created_at >= DATE_SUB(NOW(), {$p['interval']})", ARRAY_A ); $period_stats[ $key ] = [ 'label' => $p['label'], 'count' => (int) ( $row['cnt'] ?? 0 ), 'bytes' => (int) ( $row['bytes'] ?? 0 ), ]; } $max_age = (int) get_option( 'aicom_backup_max_age_days', 0 ); $max_mb = (int) get_option( 'aicom_backup_max_size_mb', 0 ); function aicom_fmt_bytes( int $bytes ): string { if ( $bytes <= 0 ) { return '0 B'; } if ( $bytes < 1024 ) { return $bytes . ' B'; } if ( $bytes < 1048576 ) { return round( $bytes / 1024, 1 ) . ' KB'; } return round( $bytes / 1048576, 1 ) . ' MB'; } // ── Snapshots tab data ───────────────────────────────────────────────────── $filter_type = sanitize_key( wp_unslash( $_GET['target_type'] ?? '' ) ); $per_page = 50; $page_num = max( 1, absint( wp_unslash( $_GET['paged'] ?? 1 ) ) ); $where = [ '1=1' ]; $params = []; if ( $filter_type ) { $where[] = 'target_type = %s'; $params[] = $filter_type; } $where_sql = implode( ' AND ', $where ); $offset = ( $page_num - 1 ) * $per_page; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $snap_total = empty( $params ) ? (int) $wpdb->get_var( "SELECT COUNT(*) FROM $table WHERE $where_sql" ) : (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $table WHERE $where_sql", ...$params ) ); $class_labels = [ 'public' => __( 'Public', 'aicom' ), 'discovery' => __( 'Discovery', 'aicom' ), 'read' => __( 'Read', 'aicom' ), 'write' => __( 'Write', 'aicom' ), 'destructive' => __( 'Destructive', 'aicom' ), 'admin_sensitive' => __( 'Admin Sensitive','aicom' ), ]; $data_params = array_merge( $params, [ $per_page, $offset ] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $backups = $wpdb->get_results( $wpdb->prepare( "SELECT id, created_at, tool_name, target_type, target_id, session_id, LENGTH(payload_json) AS payload_bytes FROM $table WHERE $where_sql ORDER BY created_at DESC LIMIT %d OFFSET %d", ...$data_params ), ARRAY_A ); $num_pages = (int) ceil( $snap_total / $per_page ); $type_options = [ '' => __( 'All Types', 'aicom' ), 'post' => __( 'Post', 'aicom' ), 'term' => __( 'Term', 'aicom' ), 'elementor_page' => __( 'Elementor Page', 'aicom' ), ]; ?>
|
|
— | #— | 0 ? esc_html( $kb ) . ' KB' : '—'; ?> |