get_dashboard_stats(); // Préparer les données pour l'affichage $total_schemas = isset($stats['total_schemas']) ? intval($stats['total_schemas']) : 0; $total_posts = isset($stats['total_posts']) ? intval($stats['total_posts']) : 0; $coverage_percent = $total_posts > 0 ? round(($total_schemas / $total_posts) * 100, 1) : 0; $types_distribution = isset($stats['types_distribution']) ? $stats['types_distribution'] : []; $last_validation_stats = isset($stats['last_validation_stats']) ? $stats['last_validation_stats'] : []; $validated_count = isset($last_validation_stats['validated']) ? intval($last_validation_stats['validated']) : 0; $errors_count = isset($last_validation_stats['errors']) ? intval($last_validation_stats['errors']) : 0; $warnings_count = isset($last_validation_stats['warnings']) ? intval($last_validation_stats['warnings']) : 0; $recent_activity = isset($stats['recent_activity']) ? $stats['recent_activity'] : []; // Calculer le score de richesse moyen (simplifié : ratio de schémas validés sans erreur) $richness_score = $validated_count > 0 ? round((($validated_count - $errors_count) / $validated_count) * 100, 1) : 0; if ($richness_score < 0) { $richness_score = 0; } /* * V786-B — le comportement part par wp_add_inline_script() (grief n°2 de wordpress.org, * compté ERREUR par le Plugin Check). NOWDOC obligatoire : $btn, $status, $progress, * $fill, $log, $ seraient vidés par un heredoc, en silence. */ $handle = 'aiforya-sm-tab-dashboard-js'; wp_register_script( $handle, false, array( 'jquery' ), AIFORYA_SM_VERSION, true ); wp_enqueue_script( $handle ); wp_localize_script( $handle, 'aiforyaSmDashboardL10n', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aiforya_sm_admin_nonce' ), 'starting' => __( 'Starting…', 'aiforya-schema-markup' ), 'batch' => __( 'Processing a batch…', 'aiforya-schema-markup' ), 'failed' => __( 'Failure', 'aiforya-schema-markup' ), 'done' => __( 'Completed', 'aiforya-schema-markup' ), 'noSuccess' => __( 'Stopped: 0 successes. See detailed errors below.', 'aiforya-schema-markup' ), 'network' => __( 'Network error.', 'aiforya-schema-markup' ), ) ); $js = <<<'JS' jQuery(function($){ var L = window.aiforyaSmDashboardL10n || {}; var nonce = L.nonce; var ajaxUrl = window.ajaxurl || L.ajaxUrl; var $btn = $('#aiforya-sm-generate-bulk-btn'); var $status = $('.aiforya-sm-bulk-status'); var $progress = $('.aiforya-sm-bulk-progress'); var $fill = $('.aiforya-sm-bulk-progress-fill'); var $log = $('.aiforya-sm-bulk-log'); function logLine(line, color) { var span = $('
').text(line); if (color) span.css('color', color); $log.append(span); $log.scrollTop($log[0].scrollHeight); } $btn.on('click', function(){ $btn.prop('disabled', true); $progress.show(); $log.empty(); $status.css('color','#94a3b8').text(L.starting); var totalProcessed = 0; var totalOk = 0, totalFail = 0; function nextBatch() { $status.css('color','#94a3b8').text(L.batch); $.post(ajaxUrl, { action:'aiforya_sm_generate_bulk', nonce:nonce, batch_size:25 }) .done(function(r){ if (!r || !r.success) { $status.css('color','#f87171').text((r && r.data && r.data.message) || L.failed); $btn.prop('disabled', false); return; } var d = r.data; totalProcessed += d.ok + d.fail + d.skipped; totalOk += d.ok; totalFail += d.fail; logLine('Batch : ' + d.ok + ' OK, ' + d.fail + ' fail, ' + d.skipped + ' skip — restants: ' + d.remaining); // Affiche les premières erreurs détaillées (debug F03/F04 chain). if (d.errors && d.errors.length) { d.errors.forEach(function(err){ logLine(' ' + err, '#f87171'); }); } var pct = (d.remaining + totalProcessed) > 0 ? Math.round( (totalProcessed / (totalProcessed + d.remaining)) * 100 ) : 100; $fill.css('width', pct + '%'); // Stop conditions : // - Plus de posts à traiter // - Le batch a 0 OK ET 0 skipped (= tous les essais ont échoué) → stop pour éviter boucle infinie if (d.remaining === 0) { $fill.css('width','100%'); $status.css('color','#4ade80').text(L.done + ' — ' + totalOk + ' OK / ' + totalFail + ' fail'); logLine('--- Done: ' + totalOk + ' generated, ' + totalFail + ' failed ---', '#4ade80'); $btn.prop('disabled', false); if (totalOk > 0) setTimeout(function(){ window.location.reload(); }, 2500); return; } if (d.ok === 0) { // Tous échouent → arrêter et afficher diagnostic. $status.css('color','#f87171').text(L.noSuccess); logLine('--- STOPPED: no schema generated, see the errors above ---', '#f87171'); $btn.prop('disabled', false); return; } // Continue setTimeout(nextBatch, 500); }) .fail(function(){ $status.css('color','#f87171').text(L.network); $btn.prop('disabled', false); }); } nextBatch(); }); }); JS; wp_add_inline_script( $handle, $js ); // Helper D2 : pastille d'aide « ? » charte (AiforyaTooltip). $text déjà traduit. $tip = static function ( $text ) { printf( '', esc_attr( $text ) ); }; ?>

%
%

0 ? round(($count / $total_schemas) * 100, 1) : 0; ?>