__('Documented by Google', 'aiot-site-audit'), 'advice' => __('Good practice, not a Google rule', 'aiot-site-audit'), 'policy' => __('Advertising policy', 'aiot-site-audit')]; } function aiotsa_tab_learn($S) { $D = aiotsa_lessons($S['lang']); $L = (array) ($D['lessons'] ?? []); $reg = (array) apply_filters('aiotsa_learn_registry', aiotsa_registry()); $secs = aiotsa_sections(); $base = admin_url('admin.php?page=aiotsa&tab=learn'); $aid = (int) aiotsa_audit_latest('own'); $A = $aid ? aiotsa_audit_get($aid) : null; $R = $A ? (array) $A['results'] : []; $stl = ['pass' => __('Pass', 'aiot-site-audit'), 'warn' => __('Warning', 'aiot-site-audit'), 'fail' => __('Fail', 'aiot-site-audit'), 'info' => __('Info', 'aiot-site-audit'), 'skip' => __('Not checked', 'aiot-site-audit')]; $id = isset($_GET['lesson']) ? sanitize_key(wp_unslash($_GET['lesson'])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only if ($id !== '' && isset($L[$id], $reg[$id])) { aiotsa_lesson_page($id, $L[$id], $reg, $secs, $D, $R, $stl, $base, $aid); return; } echo '

' . esc_html__('Learn', 'aiot-site-audit') . '

' . esc_html__('One short lesson for each check: what it is, why it matters, what goes wrong and how to fix it. The mark next to a lesson is the result of your latest full audit.', 'aiot-site-audit') . '

'; if (!$A) echo '

' . esc_html__('Run an audit on the Audit tab to see your own result next to each lesson.', 'aiot-site-audit') . '

'; echo '

'; $words = aiotsa_note_words(); $n = 0; foreach ($secs as $k => [$name]) { $rows = ''; foreach ($reg as $cid => [$s, $title]) { if ($s !== $k || !isset($L[$cid])) continue; $st = $R[$cid]['s'] ?? ''; $n++; $rows .= '
  • ' . esc_html($title) . '' . ($st !== '' ? ' ' . esc_html($stl[$st] ?? $st) . '' : '') . '
  • '; } if ($rows !== '') echo '

    ' . esc_html($name) . '

    '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- every part of $rows is escaped above } echo ''; /* translators: 1: number of lessons, 2: a date */ echo '

    ' . esc_html(sprintf(__('%1$d lessons. The lessons were written from Google\'s public documentation and checked on %2$s. They explain; they are not Google\'s own words.', 'aiot-site-audit'), $n, (string) ($D['checked'] ?? ''))) . '

    '; } function aiotsa_lesson_page($id, $x, $reg, $secs, $D, $R, $stl, $base, $aid) { $kinds = aiotsa_lesson_kinds(); $sec = $reg[$id][0]; $ids = array_values(array_filter(array_keys($reg), function ($c) use ($D) { return isset($D['lessons'][$c]); })); $at = array_search($id, $ids, true); echo '

    ' . esc_html__('Learn', 'aiot-site-audit') . ' › ' . esc_html($secs[$sec][0] ?? '') . '

    ' . esc_html($reg[$id][1]) . '

    '; echo '

    ' . esc_html($kinds[$x['k']] ?? $kinds['advice']) . '

    '; if (isset($R[$id])) { $r = $R[$id]; echo '
    ' . esc_html__('Your site', 'aiot-site-audit') . ': ' . esc_html($stl[$r['s']] ?? $r['s']) . ' ' . esc_html(aiotsa_tf($r['m'], 'en')) . (isset($r['f']) ? '
    ' . esc_html__('Fix', 'aiot-site-audit') . ': ' . esc_html(aiotsa_tf($r['f'], 'en')) . '
    ' : '') . ' ' . esc_html__('Open the report', 'aiot-site-audit') . '
    '; } $part = function ($h, $v) { if (is_array($v)) { if (!$v) return; echo '

    ' . esc_html($h) . '

    '; } elseif ((string) $v !== '') echo '

    ' . esc_html($h) . '

    ' . esc_html($v) . '

    '; }; $part(__('What this is', 'aiot-site-audit'), $x['w']); $part(__('Why it matters', 'aiot-site-audit'), $x['y']); $part(__('What goes wrong', 'aiot-site-audit'), $x['e']); $part(__('How to fix it', 'aiot-site-audit'), $x['f']); $part(__('How to make it better', 'aiot-site-audit'), $x['i']); $part(__('What Google says, in our words', 'aiot-site-audit'), $x['g']); $src = $D['sources'][$x['s']] ?? null; if ($src) echo '

    ' . esc_html__('Read more', 'aiot-site-audit') . ': ' . esc_html($src[0]) . ' ' . esc_html__('(opens in a new tab)', 'aiot-site-audit') . '

    '; echo '

    '; if ($at !== false && $at > 0) echo '← ' . esc_html($reg[$ids[$at - 1]][1]) . ' '; if ($at !== false && $at < count($ids) - 1) echo '' . esc_html($reg[$ids[$at + 1]][1]) . ' →'; echo '

    '; }