get_opts_public()['enabled_post_types'];
$excluded_ids = get_option( 'aije_excluded_posts', array() );
$nonce_dash = wp_create_nonce( 'aije_dashboard_nonce' );
if ( isset( $_GET['reset_excluded'] ) ) {
delete_option( 'aije_excluded_posts' );
wp_safe_redirect( admin_url( 'tools.php?page=aije-lite&tab=dashboard' ) ); exit;
}
$query = new WP_Query( array( 'post_type' => $types, 'posts_per_page' => -1, 'post_status' => 'publish', 'post__not_in' => $excluded_ids ) );
$scores = array(); $distribution = array( 'ready' => 0, 'mid' => 0, 'low' => 0 );
$cat_totals = array( 'content' => 0, 'eeat' => 0, 'technical' => 0, 'linking' => 0 ); $post_count = 0;
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post(); $p = get_post(); $analysis = $this->calculate_ai_analysis( $p ); $score = $analysis['score'];
$scores[] = array( 'id' => get_the_ID(), 'title' => get_the_title(), 'score' => $score );
if ( $score >= 75 ) { $distribution['ready']++; } elseif ( $score >= 50 ) { $distribution['mid']++; } else { $distribution['low']++; }
foreach ( $cat_totals as $k => $_ ) { $cat_totals[ $k ] += $analysis['categories'][ $k ]['score'] ?? 0; }
$post_count++;
}
wp_reset_postdata();
}
$avg = $post_count ? round( array_sum( array_column( $scores, 'score' ) ) / $post_count ) : 0;
$cat_avgs = array();
foreach ( $cat_totals as $k => $total ) { $cat_avgs[ $k ] = $post_count ? round( $total / $post_count ) : 0; }
$avg_color = $avg >= 75 ? '#27ae60' : ( $avg >= 50 ? '#e67e22' : '#e74c3c' );
echo '
' . esc_html__( 'AI Readiness Dashboard', 'ai-json-extractor-auto-embed-lite' ) . ' ' . esc_html( sprintf( /* translators: 1: post count, 2: average score */ __( '%1$d Artikel · Ø %2$d Punkte', 'ai-json-extractor-auto-embed-lite' ), $post_count, $avg ) ) . '
';
echo '';
echo '
' . esc_html__( 'Score-Verteilung', 'ai-json-extractor-auto-embed-lite' ) . '
';
echo '
' . esc_html__( 'Kategorien-Ø', 'ai-json-extractor-auto-embed-lite' ) . '
';
echo '
';
$chart_label_kiready = esc_js( __( 'KI-Ready', 'ai-json-extractor-auto-embed-lite' ) );
$chart_label_optimierbar = esc_js( __( 'Optimierbar', 'ai-json-extractor-auto-embed-lite' ) );
$chart_label_kritisch = esc_js( __( 'Kritisch', 'ai-json-extractor-auto-embed-lite' ) );
$chart_label_content = esc_js( __( 'Content', 'ai-json-extractor-auto-embed-lite' ) );
$chart_label_eeat = esc_js( __( 'E-E-A-T', 'ai-json-extractor-auto-embed-lite' ) );
$chart_label_technik = esc_js( __( 'Technik', 'ai-json-extractor-auto-embed-lite' ) );
$chart_label_vernetzung = esc_js( __( 'Vernetzung', 'ai-json-extractor-auto-embed-lite' ) );
echo '';
// Filter-Counts
$filter_counts = array( 'no_image' => 0, 'no_meta' => 0, 'too_short' => 0, 'no_eeat' => 0, 'no_h2' => 0, 'no_internal' => 0 );
$filter_needles = array(
'no_image' => array( 'no_featured_image' ),
'no_meta' => array( 'meta_desc_length_suboptimal', 'meta_desc_too_short', 'no_meta_desc' ),
'too_short' => array( 'content_too_short', 'content_slightly_short' ),
'no_eeat' => array( 'no_job_title' ),
'no_h2' => array( 'no_h2' ),
'no_internal' => array( 'no_internal_links' ),
); // Matching läuft über den stabilen 'key' aus trait-score.php, nicht über den (übersetzten) 'msg'-Text
$filter_labels = array( 'no_image' => '🖼 ' . __( 'Kein Bild', 'ai-json-extractor-auto-embed-lite' ), 'no_meta' => '📝 ' . __( 'Keine Meta', 'ai-json-extractor-auto-embed-lite' ), 'too_short' => '📏 ' . __( 'Text zu kurz', 'ai-json-extractor-auto-embed-lite' ), 'no_eeat' => '🏅 ' . __( 'Kein E-E-A-T', 'ai-json-extractor-auto-embed-lite' ), 'no_h2' => '📋 ' . __( 'Kein H2', 'ai-json-extractor-auto-embed-lite' ), 'no_internal' => '🔗 ' . __( 'Kein int. Linking', 'ai-json-extractor-auto-embed-lite' ) );
$all_posts_for_filter = get_posts( array( 'post_type' => $types, 'posts_per_page' => -1, 'post_status' => 'publish' ) );
foreach ( $all_posts_for_filter as $fp ) { $fa = $this->calculate_ai_analysis( $fp ); foreach ( $filter_counts as $fk => $_ ) { foreach ( $fa['issues'] as $iss ) { if ( in_array( $iss['key'] ?? '', $filter_needles[ $fk ], true ) ) { $filter_counts[ $fk ]++; break; } } } }
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
echo '
';
$excluded_count = count( get_option( 'aije_excluded_posts', array() ) );
echo '';
foreach ( $filter_labels as $fk => $fl ) {
if ( $filter_counts[ $fk ] > 0 ) { echo ''; }
}
if ( $excluded_count > 0 ) { echo ''; }
echo '
';
echo ''; $this->render_dashboard_list( 'bad' ); echo '
';
echo ''; $this->render_dashboard_list( 'medium' ); echo '
';
echo ''; $this->render_dashboard_list( 'good' ); echo '
';
foreach ( $filter_labels as $fk => $fl ) { echo '' . esc_html( $fl ) . ' – ' . sprintf( esc_html__( '%d Artikel betroffen', 'ai-json-extractor-auto-embed-lite' ), (int) $filter_counts[ $fk ] ) . '
'; $this->render_dashboard_list( 'filter', $fk ); echo '
'; }
$excluded_ids = get_option( 'aije_excluded_posts', array() );
echo '';
if ( empty( $excluded_ids ) ) { echo '
' . esc_html__( 'Keine ausgeschlossenen Artikel.', 'ai-json-extractor-auto-embed-lite' ) . '
'; }
else { echo '
'; foreach ( $excluded_ids as $ex_id ) { $ex_post = get_post( $ex_id ); if ( ! $ex_post ) { continue; } echo '- ' . esc_html( $ex_post->post_title ) . '
'; } echo '
'; }
echo '
';
$this->render_exclude_js();