get_running_run('audit'); $latest_completed = $repo->get_latest_completed_run('audit'); $latest_any = $repo->get_latest_run('audit'); $trend = $repo->get_recent_runs('audit', 10); $settings = Settings::get(); $limits = isset($settings['scan_limits']) && is_array($settings['scan_limits']) ? $settings['scan_limits'] : []; // 4.0.17: show the limit the crawler actually applies. The dashboard // used to print the hidden legacy `full_scan_max_pages` value. $scan_mode = (string) ($settings['scan_mode'] ?? 'full'); $crawl_max_urls = (int) ($limits['crawl_max_urls'] ?? 0); $full_scan_max_pages = $crawl_max_urls > 0 ? $crawl_max_urls : (int) ($limits['full_scan_max_pages'] ?? 0); $audit_analysis_max_pages = (int) ($limits['audit_analysis_max_pages'] ?? 0); echo wp_kses(Brand::wrap_open(), Brand::admin_kses()); echo wp_kses(Brand::header(I18n::tr('Dashboard', 'لوحة التحكم')), Brand::admin_kses()); $runtime_version = defined('AETOS_SEO_VERSION') ? (string) AETOS_SEO_VERSION : 'unknown'; $runtime_slug = defined('AETOS_SEO_SLUG') ? (string) AETOS_SEO_SLUG : 'unknown'; if ($runtime_slug !== 'unknown' && $runtime_slug !== 'aetos-seo') { echo '

'; echo esc_html(I18n::tr( 'The plugin is running from a non-standard folder name. Keep only wp-content/plugins/aetos-seo active to avoid running old code.', 'تعمل الإضافة من مجلد باسم غير معتاد. أبقِ wp-content/plugins/aetos-seo وحده مفعلًا حتى لا يعمل كود قديم.' )); echo '

'; } $notice_raw = filter_input(INPUT_GET, 'aetos_seo_notice', FILTER_UNSAFE_RAW); $notice = is_string($notice_raw) ? sanitize_key(wp_unslash($notice_raw)) : ''; $notice_run_raw = filter_input(INPUT_GET, 'run_id', FILTER_UNSAFE_RAW); $notice_run_id = is_scalar($notice_run_raw) ? absint(wp_unslash((string) $notice_run_raw)) : 0; // Resolve stale queued notices (common after background completion). if (in_array($notice, ['audit_queued', 'combined_queued'], true) && $notice_run_id > 0) { $queued_notice_run = $repo->get_run($notice_run_id); if ($queued_notice_run) { $queued_status = (string) ($queued_notice_run['status'] ?? ''); if ($queued_status === 'completed') { $notice = 'audit_done'; $latest_completed = $queued_notice_run; $latest_any = $queued_notice_run; } elseif ($queued_status === 'failed') { $notice = 'audit_failed'; $latest_any = $queued_notice_run; } elseif (in_array($queued_status, ['queued', 'running'], true)) { if ($queued_status === 'running') { $notice = 'audit_running'; } $pending = $queued_notice_run; } } } if ($notice === 'audit_done') { echo '

' . esc_html(I18n::tr('The audit is complete. Your results are below.', 'اكتمل الفحص، والنتائج بالأسفل.')) . '

'; } elseif (in_array($notice, ['audit_queued', 'combined_queued'], true)) { $rid = $notice_run_id; echo '

' . esc_html(I18n::tr('The audit has started and runs in the background. You can keep working; this page updates by itself.', 'بدأ الفحص ويعمل في الخلفية. يمكنك متابعة عملك، وستتحدث هذه الصفحة تلقائيًا.')) . '

'; } elseif ($notice === 'audit_running') { echo '

' . esc_html(I18n::tr('An audit is already running.', 'يوجد فحص يعمل حاليًا.')) . '

'; } elseif ($notice === 'audit_failed') { echo '

' . esc_html(I18n::tr('The audit could not start or finish. Try again from this page. If it fails again, contact support from the Help menu.', 'تعذر بدء الفحص أو إكماله. حاول مرة أخرى من هذه الصفحة، وإذا تكرر ذلك فتواصل مع الدعم من قائمة المساعدة.')) . '

'; } // v2.1.1 — stale-crawl detection. If the latest crawl row collector // version is older than the plugin's current version, the new v2.1.0+ // checks (QuestionCoverage, DirectAnswerPattern, Cannibalization, // Freshness) silently skip pages because the heading-text fields are // empty in the old data. Show an actionable banner. $stale_warning = $this->detect_stale_crawl_rows($repo); if ($stale_warning !== '') { echo '

' . esc_html(I18n::tr('Stale crawl data detected', 'تم رصد بيانات زحف قديمة')) . ': ' . esc_html($stale_warning) . ' ' . esc_html(I18n::tr('Run a fresh crawl', 'شغّل زحفاً جديداً')) . '.

'; } $pending_id = 0; $pending_status = ''; $pending_phase = ''; $pending_progress = null; if ($pending) { $pending_id = (int) ($pending['id'] ?? 0); $pending_status = (string) ($pending['status'] ?? ''); $pending_notes_raw = isset($pending['notes']) ? (string) $pending['notes'] : ''; if ($pending_notes_raw !== '') { $pending_notes = json_decode($pending_notes_raw, true); if (is_array($pending_notes)) { $pending_phase = isset($pending_notes['phase']) ? (string) $pending_notes['phase'] : ''; if (isset($pending_notes['progress_percent']) && is_numeric($pending_notes['progress_percent'])) { $pending_progress = (int) $pending_notes['progress_percent']; } } } if ($pending_progress === null) { $pending_progress = ($pending_status === 'queued') ? 2 : 5; } $pending_progress = max(0, min(99, (int) $pending_progress)); if ($pending_phase === '') { $pending_phase = $pending_status === 'queued' ? I18n::tr('Getting ready...', 'جارٍ التحضير...') : I18n::tr('Checking your pages in the background...', 'يفحص صفحاتك في الخلفية...'); } } // 4.0.18: the dashboard answers one question, "how is my site and what // do I do next?". Order: running scan, score with the next action, // top priorities, category results, then scan details folded away. $has_pro_addon = (bool) apply_filters('aetos_seo_pro_addon_active', false); if ($pending_id > 0 && in_array($pending_status, ['queued', 'running'], true)) { $this->render_pending_status($pending_id, $pending_status, $pending_phase, (int) $pending_progress); } if (!$latest_any) { if (!$pending) { $this->render_first_run($has_pro_addon); } else { echo '

' . esc_html(I18n::tr('Your first audit is running. Results appear here automatically when it finishes.', 'أول فحص يعمل الآن، وستظهر النتائج هنا تلقائيًا عند انتهائه.')) . '

'; } echo ''; return; } if (!$latest_completed && $pending) { echo ''; return; } $latest = $latest_completed ?: $latest_any; if (!$latest_completed && !$pending && $notice !== 'audit_failed') { echo '

' . esc_html(I18n::tr('The latest audit did not finish. Run a new audit from this page.', 'آخر فحص لم يكتمل. شغّل فحصًا جديدًا من هذه الصفحة.')) . '

'; } $overall = (int) ($latest['overall_score'] ?? 0); $latest_run_id = (int) ($latest['id'] ?? 0); $category_scores = []; if (!empty($latest['category_scores'])) { $decoded = json_decode((string) $latest['category_scores'], true); if (is_array($decoded)) { $category_scores = $decoded; } } $latest_findings = $latest_run_id > 0 ? $repo->get_findings_for_run($latest_run_id) : []; $open_fix = []; $open_improve = []; foreach ($latest_findings as $f) { if (!is_array($f) || (string) ($f['status'] ?? 'open') !== 'open') { continue; } $group = Labels::group_of((string) ($f['severity'] ?? 'info')); if ($group === 'fix') { $open_fix[] = $f; } elseif ($group === 'improve') { $open_improve[] = $f; } } $has_high_open = false; foreach ($open_fix as $f) { if ((string) ($f['severity'] ?? '') === 'high') { $has_high_open = true; break; } } // ── Score and next action ────────────────────────────────────────── $score = max(0, min(100, $overall)); $score_color = $score >= 75 ? '#24A038' : ($score >= 50 ? '#b45309' : '#dc2626'); if ($score >= 90 && !$has_high_open) { $score_label = I18n::tr('Excellent', 'ممتاز'); } elseif ($score >= 75 && !$has_high_open) { $score_label = I18n::tr('Good, a few items left', 'جيد وبقيت بنود قليلة'); } elseif ($score >= 50 || $has_high_open) { $score_label = I18n::tr('Needs work', 'يحتاج إلى عمل'); } else { $score_label = I18n::tr('Needs urgent work', 'يحتاج إلى عمل عاجل'); } $fix_url = add_query_arg(['page' => 'aetos-seo-findings', 'run_id' => $latest_run_id, 'group' => 'fix'], admin_url('admin.php')); $all_url = add_query_arg(['page' => 'aetos-seo-findings', 'run_id' => $latest_run_id], admin_url('admin.php')); $radius = 44; $circ = 2 * pi() * $radius; $offset = $circ * (1 - ($score / 100)); echo '
'; echo '
'; echo ''; echo ''; echo ''; echo ''; // The number and "of 100" are separate lines, so RTL never flips "100/". echo '
' . esc_html((string) $score) . '' . esc_html(I18n::tr('out of 100', 'من 100')) . '
'; echo '
'; echo '
'; echo '

' . esc_html($score_label) . '

'; if (!empty($open_fix)) { $fix_phrase = self::fix_phrase(count($open_fix)); $line = empty($open_improve) ? sprintf(I18n::tr('%s.', 'هناك %s.'), $fix_phrase) : sprintf(I18n::tr('%1$s, and %2$s.', 'هناك %1$s و%2$s.'), $fix_phrase, self::improve_phrase(count($open_improve))); echo '

' . esc_html(self::sentence_case($line)) . '

'; } elseif (!empty($open_improve)) { echo '

' . esc_html(sprintf(I18n::tr('Nothing urgent. %s.', 'لا توجد مشكلات عاجلة، وهناك %s.'), self::improve_phrase(count($open_improve)))) . '

'; } else { echo '

' . esc_html(I18n::tr('No open issues in the latest audit.', 'لا توجد مشكلات مفتوحة في آخر فحص.')) . '

'; } $this->render_progress_line($trend, $latest_run_id, $overall, $latest); echo '
'; if (!empty($open_fix)) { echo '' . esc_html(I18n::tr('Show what to fix', 'اعرض ما يحتاج إصلاحًا')) . ''; } else { echo '' . esc_html(I18n::tr('Show all findings', 'اعرض كل النتائج')) . ''; } $this->render_run_form('button aetos-btn-secondary', I18n::tr('Run a new audit', 'شغّل فحصًا جديدًا')); echo '
'; echo '

' . esc_html(sprintf(I18n::tr('Last audit: %s', 'آخر فحص: %s'), $this->format_date((string) ($latest['created_at'] ?? '')))) . '

'; $coverage_line = self::coverage_line((string) ($latest['context_json'] ?? '')); if ($coverage_line !== '') { echo '

' . esc_html($coverage_line) . '

'; } echo '
'; echo '
'; // ── Top priorities ───────────────────────────────────────────────── $priority = array_slice($open_fix, 0, 5); if (!empty($priority)) { echo '
'; echo '

' . esc_html(I18n::tr('Fix these first', 'ابدأ بهذه')) . '

'; echo ''; if (count($open_fix) > count($priority)) { echo '

' . esc_html(sprintf(I18n::tr('See all %d issues that need fixing', 'اعرض كل المشكلات التي تحتاج إصلاحًا (%d)'), count($open_fix))) . '

'; } echo '
'; } elseif (!empty($open_improve)) { echo '
'; echo '

' . esc_html(I18n::tr('Quick improvements', 'تحسينات سريعة')) . '

'; echo '
'; } // ── Category results ─────────────────────────────────────────────── if (!empty($category_scores)) { echo '
'; echo '

' . esc_html(I18n::tr('Results by area', 'النتائج حسب المجال')) . '

'; echo '
'; $order = array_keys(CategoryLabels::map()); foreach (array_keys($category_scores) as $cat_key) { if (!in_array($cat_key, $order, true)) { $order[] = $cat_key; } } foreach ($order as $cat) { if (!isset($category_scores[$cat]) || in_array($cat, ['Logs', 'Database'], true) && (int) $category_scores[$cat] === 100) { continue; } $cat_score = (int) $category_scores[$cat]; $bar_color = $cat_score >= 75 ? '#24A038' : ($cat_score >= 50 ? '#b45309' : '#dc2626'); $cat_url = add_query_arg(['page' => 'aetos-seo-findings', 'run_id' => $latest_run_id, 'category' => $cat], admin_url('admin.php')); echo ''; echo '' . esc_html(CategoryLabels::label($cat)) . ''; echo '' . esc_html((string) $cat_score) . ''; echo ''; echo ''; } echo '
'; } // ── Scan details, folded ─────────────────────────────────────────── echo '
' . esc_html(I18n::tr('Audit details and history', 'تفاصيل الفحص والسجل')) . ''; $coverage_context = json_decode((string) ($latest['context_json'] ?? ''), true); $scope = is_array($coverage_context) ? ($coverage_context['audit_scope'] ?? []) : []; if (is_array($scope) && isset($scope['coverage']) && is_array($scope['coverage'])) { $coverage = $scope['coverage']; echo '

' . esc_html(I18n::tr('Coverage', 'التغطية')) . '

'; echo '

' . esc_html(sprintf( I18n::tr('Analysed %1$s of %2$s found on this site.', 'حُللت %1$s من أصل %2$s عُثر عليها في الموقع.'), self::page_phrase((int) ($coverage['parsed_html'] ?? 0)), self::page_phrase((int) ($scope['discovered_urls'] ?? 0), true) )) . '

'; } $duration_s = round((int) ($latest['duration_ms'] ?? 0) / 1000, 1); echo '

' . esc_html(sprintf(I18n::tr('The checks took %s seconds after the pages were collected.', 'استغرقت الفحوصات %s ثانية بعد جمع الصفحات.'), number_format_i18n($duration_s, 1))) . '

'; echo '

' . esc_html(sprintf( I18n::tr('Current limits: up to %1$s pages collected, %2$s analysed in detail.', 'الحدود الحالية: جمع حتى %1$s صفحة، وتحليل %2$s بالتفصيل.'), $full_scan_max_pages > 0 ? number_format_i18n($full_scan_max_pages) : I18n::tr('all', 'كل الصفحات'), $audit_analysis_max_pages > 0 ? number_format_i18n($audit_analysis_max_pages) : I18n::tr('all', 'كلها') )) . ' ' . esc_html(I18n::tr('Change settings', 'تغيير الإعدادات')) . '

'; if (count($trend) >= 2) { echo '

' . esc_html(I18n::tr('Score history', 'سجل النتيجة')) . '

'; echo wp_kses($this->render_trend_svg($trend), Brand::admin_kses()); echo ''; } $detected_stack = is_array($coverage_context) && isset($coverage_context['detected_stack']) && is_array($coverage_context['detected_stack']) ? $coverage_context['detected_stack'] : []; if (!empty($detected_stack)) { echo '

' . esc_html(I18n::tr('Tools found on the site', 'أدوات موجودة في الموقع')) . '

'; echo ''; } echo '
'; echo ''; } /** * One form for starting an audit (fresh crawl + audit). */ private function render_run_form(string $class, string $label): void { echo '
'; echo ''; wp_nonce_field('aetos_seo_run_combined'); echo ''; echo '
'; } private function render_first_run(bool $has_pro_addon): void { echo '
'; echo '
'; echo '

' . esc_html(I18n::tr('Find what is holding your site back', 'اعرف ما يعيق ظهور موقعك')) . '

'; echo '

' . esc_html($has_pro_addon ? I18n::tr('One audit checks your pages for search, speed, security and AI readiness, including your Pro modules, and lists what to fix first.', 'فحص واحد يراجع صفحاتك في البحث والسرعة والأمان وجاهزية الذكاء الاصطناعي، مع وحدات Pro، ويرتب لك ما تصلحه أولًا.') : I18n::tr('One audit checks your pages for search, speed, security and AI readiness, and lists what to fix first.', 'فحص واحد يراجع صفحاتك في البحث والسرعة والأمان وجاهزية الذكاء الاصطناعي، ويرتب لك ما تصلحه أولًا.')) . '

'; echo ''; $this->render_run_form('button button-primary button-hero', I18n::tr('Start the first audit', 'ابدأ أول فحص')); echo '
'; } private function render_pending_status(int $pending_id, string $status, string $phase, int $progress): void { $loading_class = $status === 'queued' ? ' aetos-loading' : ''; echo '
'; $label = $status === 'queued' ? I18n::tr('Waiting to start', 'في انتظار البدء') : I18n::tr('Scanning now', 'يفحص الآن'); echo '

' . esc_html($label) . '

'; echo '

' . esc_html($phase) . '

'; echo '
'; echo '
' . esc_html(I18n::tr('Audit progress', 'تقدم الفحص')) . '
'; echo '
' . esc_html((string) $progress) . '%
'; echo '
'; echo '
'; } /** * @param array> $trend * @param array $latest */ private function render_progress_line(array $trend, int $latest_run_id, int $overall, array $latest): void { $prev = null; $seen = false; foreach ($trend as $t_run) { if (!is_array($t_run)) { continue; } if (!$seen) { $seen = (int) ($t_run['id'] ?? 0) === $latest_run_id; continue; } $prev = $t_run; break; } if ($prev === null) { return; } $delta = $overall - (int) ($prev['overall_score'] ?? 0); if ($delta > 0) { $text = I18n::n($delta, 'Up %d point since the previous audit.', 'Up %d points since the previous audit.', 'ارتفعت النتيجة نقطة واحدة منذ الفحص السابق.', 'ارتفعت النتيجة نقطتين منذ الفحص السابق.', 'ارتفعت النتيجة %d نقاط منذ الفحص السابق.', 'ارتفعت النتيجة %d نقطة منذ الفحص السابق.'); } elseif ($delta < 0) { $text = I18n::n(abs($delta), 'Down %d point since the previous audit.', 'Down %d points since the previous audit.', 'انخفضت النتيجة نقطة واحدة منذ الفحص السابق.', 'انخفضت النتيجة نقطتين منذ الفحص السابق.', 'انخفضت النتيجة %d نقاط منذ الفحص السابق.', 'انخفضت النتيجة %d نقطة منذ الفحص السابق.'); } else { $text = I18n::tr('Same score as the previous audit.', 'النتيجة كما في الفحص السابق.'); } echo '

' . esc_html($text) . '

'; } /** * @param array $pf */ private function render_priority_item(array $pf, int $run_id): void { $sev = (string) ($pf['severity'] ?? 'info'); $row_id = (int) ($pf['id'] ?? 0); $url = add_query_arg(['page' => 'aetos-seo-findings', 'run_id' => $run_id, 'open_finding' => $row_id], admin_url('admin.php')); echo '
  • '; echo '' . esc_html(Labels::severity($sev)) . ''; echo '' . esc_html($this->finding_display_title($pf)) . ''; echo '' . esc_html(CategoryLabels::label((string) ($pf['category'] ?? ''))) . ''; echo '
  • '; } private function format_date(string $mysql): string { $ts = $mysql !== '' ? strtotime($mysql) : false; if ($ts === false) { return $mysql; } return wp_date(I18n::is_arabic() ? 'j F Y - g:i a' : 'F j, Y g:i a', $ts - (int) (get_option('gmt_offset', 0) * HOUR_IN_SECONDS)); } /** * @param array $finding */ private function finding_display_title(array $finding): string { $title = (string) ($finding['title'] ?? ''); $category = (string) ($finding['category'] ?? ''); $finding_id = (string) ($finding['finding_id'] ?? ''); $category_label = $category !== '' ? CategoryLabels::label($category) : I18n::tr('Audit', 'الفحص'); $fallback = sprintf( I18n::tr('%1$s issue: %2$s', 'مشكلة %1$s: %2$s'), $category_label, $finding_id !== '' ? $finding_id : I18n::tr('stored finding', 'نتيجة مخزنة') ); return I18n::english_safe($title, $fallback); } /** * @param array> $runs */ private function render_trend_svg(array $runs): string { if (empty($runs)) { return '

    ' . esc_html(I18n::tr('No trend data yet.', 'لا توجد بيانات اتجاه حتى الآن.')) . '

    '; } $scores = []; foreach (array_reverse($runs) as $run) { $scores[] = (int) ($run['overall_score'] ?? 0); } if (count($scores) < 2) { $baseline = (int) ($scores[0] ?? 0); return '

    ' . esc_html(sprintf(I18n::tr('First score saved: %d of 100. The history line appears after the next audit.', 'حُفظت أول نتيجة: %d من 100. يظهر خط السجل بعد الفحص التالي.'), $baseline)) . '

    '; } $width = 420; $height = 80; $padding = 8; $count = count($scores); $dx = ($width - 2 * $padding) / max(1, ($count - 1)); $points = []; foreach ($scores as $index => $score) { $x = $padding + ($index * $dx); $y = $height - $padding - ($score / 100) * ($height - 2 * $padding); $points[] = sprintf('%.2f,%.2f', $x, $y); } $polyline = implode(' ', $points); $last = end($scores); $out = '
    '; $out .= ''; $out .= ''; $out .= ''; $out .= '
    ' . esc_html(I18n::tr('Last score:', 'آخر نتيجة:')) . ' ' . esc_html((string) $last) . '
    '; $out .= '
    '; return $out; } private function format_stack_title_html(string $title): string { $title = trim($title); if ($title === '') { return ''; } if (preg_match('/^(.+?)\s+detected(?:\s+\(([^)]+)\))?$/i', $title, $m)) { $name = trim((string) $m[1]); $kind = isset($m[2]) ? trim((string) $m[2]) : ''; $out = esc_html(I18n::tr('Detected', 'تم رصد')) . ' ' . esc_html($name) . ''; if ($kind !== '') { $out .= ' - ' . esc_html($this->format_stack_kind($kind)); } return $out; } return '' . esc_html($title) . ''; } private function format_stack_kind(string $kind): string { $map = [ 'Adapter' => I18n::tr('Adapter', 'محول'), 'Speed Optimizer' => I18n::tr('Speed Optimizer', 'محسن السرعة'), 'Security Optimizer' => I18n::tr('Security Optimizer', 'محسن الأمان'), ]; return $map[$kind] ?? $kind; } /** * v2.1.1 — return a non-empty warning string if the latest crawl rows * predate the new collector_version field (i.e. v2.1.0+). The new AEO * checks (QuestionCoverage / DirectAnswerPattern / Cannibalization / * Freshness) need heading-text + first_paragraph fields that only exist * after a fresh crawl on v2.1.1+. */ private function detect_stale_crawl_rows(Repository $repo): string { $row = $repo->get_latest_crawl_row_meta(); if (!is_array($row) || empty($row)) { return ''; } $analysis_json = isset($row['analysis_json']) ? (string) $row['analysis_json'] : ''; if ($analysis_json === '') { return ''; } $decoded = json_decode($analysis_json, true); if (!is_array($decoded)) { return ''; } $cv = isset($decoded['collector_version']) ? (string) $decoded['collector_version'] : ''; $current_v = defined('AETOS_SEO_VERSION') ? (string) AETOS_SEO_VERSION : ''; // No collector_version at all = pre-v2.1.1 row. if ($cv === '') { return I18n::tr( 'The saved page data comes from an older version. Run a new audit once so every check has fresh data.', 'بيانات الصفحات المحفوظة من إصدار أقدم. شغّل فحصًا جديدًا مرة واحدة لتحصل كل الفحوصات على بيانات حديثة.' ); } if ($current_v !== '' && version_compare($cv, $current_v, '<')) { return sprintf( /* translators: 1: stale collector version, 2: current plugin version */ I18n::tr( 'The saved page data comes from version %1$s and the plugin is now %2$s. Run a new audit so every check has fresh data.', 'بيانات الصفحات المحفوظة من الإصدار %1$s والإضافة الآن %2$s. شغّل فحصًا جديدًا لتحصل كل الفحوصات على بيانات حديثة.' ), $cv, $current_v ); } return ''; } /** 4.0.18: counted phrases that agree with their number (see I18n::n). */ private static function fix_phrase(int $n): string { return I18n::n($n, '%d issue needs fixing', '%d issues need fixing', 'مشكلة واحدة تحتاج إصلاحًا', 'مشكلتان تحتاجان إصلاحًا', '%d مشكلات تحتاج إصلاحًا', '%d مشكلة تحتاج إصلاحًا'); } /** Nominative by default; the genitive dual follows «من أصل». */ private static function page_phrase(int $n, bool $genitive = false): string { return I18n::n($n, '%d page', '%d pages', 'صفحة واحدة', $genitive ? 'صفحتين' : 'صفحتان', '%d صفحات', '%d صفحة'); } /** * 4.0.18: the score says how much of the site it covers, so a sample * scan is never read as a whole-site result. */ private static function coverage_line(string $context_json): string { $context = json_decode($context_json, true); $scope = is_array($context) && isset($context['audit_scope']) && is_array($context['audit_scope']) ? $context['audit_scope'] : []; if (!isset($scope['coverage']) || !is_array($scope['coverage'])) { return ''; } $checked = (int) ($scope['coverage']['parsed_html'] ?? 0); $found = max($checked, (int) ($scope['discovered_urls'] ?? 0), (int) ($scope['crawl_inventory_total'] ?? 0)); $is_sample = (string) ($scope['scan_mode'] ?? '') === 'sample'; if (!$is_sample && $checked >= $found) { return sprintf(I18n::tr('Full scan: %s checked.', 'فحص كامل: فُحصت %s.'), self::page_phrase($checked)); } if ($checked >= $found) { // A sample that never crawled the site found nothing beyond what it // checked, so "1 of 1" would read as full coverage. return sprintf( I18n::tr('Sample scan: only %s checked and the rest of the site was not crawled. The score covers only what was checked.', 'فحص عينة: فُحصت %s فقط دون الزحف على بقية الموقع. النتيجة تخص ما فُحص فقط.'), self::page_phrase($checked) ); } return sprintf( $is_sample ? I18n::tr('Sample scan: %1$s checked out of %2$s found. The score covers only what was checked.', 'فحص عينة: فُحصت %1$s من أصل %2$s عُثر عليها. النتيجة تخص ما فُحص فقط.') : I18n::tr('Partial scan: %1$s checked out of %2$s found. The score covers only what was checked.', 'فحص جزئي: فُحصت %1$s من أصل %2$s عُثر عليها. النتيجة تخص ما فُحص فقط.'), self::page_phrase($checked), self::page_phrase($found, true) ); } private static function improve_phrase(int $n): string { return I18n::n($n, '%d improvement is suggested', '%d improvements are suggested', 'تحسين واحد مقترح', 'تحسينان مقترحان', '%d تحسينات مقترحة', '%d تحسينًا مقترحًا'); } private static function sentence_case(string $text): string { return I18n::is_arabic() ? $text : ucfirst($text); } }