' . esc_html__('Run an audit', 'aiot-site-audit') . ''); return $l; }); function aiotsa_tabs() { return apply_filters('aiotsa_tabs', ['audit' => __('Audit', 'aiot-site-audit'), 'report' => __('Report', 'aiot-site-audit'), 'tools' => __('Tools', 'aiot-site-audit'), 'settings' => __('Settings', 'aiot-site-audit'), 'keys' => __('API Keys', 'aiot-site-audit'), 'help' => __('Help', 'aiot-site-audit')]); } function aiotsa_buf_modes() { ob_start(); do_action('aiotsa_form_modes'); return (string) ob_get_clean(); } function aiotsa_buf_toolbar() { ob_start(); do_action('aiotsa_report_toolbar'); return (string) ob_get_clean(); } function aiotsa_tab() { $t = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'audit'; return isset(aiotsa_tabs()[$t]) ? $t : 'audit'; } // phpcs:ignore WordPress.Security.NonceVerification add_action('admin_enqueue_scripts', function ($hook) { if ($hook !== 'toplevel_page_aiotsa') return; wp_enqueue_media(); wp_enqueue_style('aiotsa-report', AIOTSA_URL . 'assets/css/report.css', [], AIOTSA_VERSION); wp_enqueue_style('aiotsa-admin', AIOTSA_URL . 'assets/css/admin.css', ['aiotsa-report'], AIOTSA_VERSION); $aiotsa_css = aiotsa_report_css('admin'); if ($aiotsa_css !== '') wp_add_inline_style('aiotsa-report', $aiotsa_css); wp_enqueue_script('aiotsa-admin', AIOTSA_URL . 'assets/js/admin.js', [], AIOTSA_VERSION, true); wp_localize_script('aiotsa-admin', 'AIOTSA', ['rest' => esc_url_raw(rest_url('aiotsa/v1')), 'nonce' => wp_create_nonce('wp_rest'), 'tab' => aiotsa_tab(), 'active' => aiotsa_audit_current(), 'id' => isset($_GET['id']) ? (int) $_GET['id'] : (int) (is_array(get_option('aiotsa_last')) ? get_option('aiotsa_last')['id'] : aiotsa_audit_latest('own')), // phpcs:ignore WordPress.Security.NonceVerification 'reportUrl' => admin_url('admin.php?page=aiotsa&tab=report&id='), 'keysUrl' => admin_url('admin.php?page=aiotsa&tab=keys'), 'presets' => aiotsa_robots_presets(), 'types' => ['own' => __('This website', 'aiot-site-audit'), 'page' => __('One page', 'aiot-site-audit'), 'external' => __('Another website', 'aiot-site-audit')], 's' => ['starting' => __('Starting...', 'aiot-site-audit'), 'left' => /* translators: %s: time left, like "2 min" */ __('about %s left', 'aiot-site-audit'), 'min' => __('min', 'aiot-site-audit'), 'sec' => __('sec', 'aiot-site-audit'), 'done' => __('Completed', 'aiot-site-audit'), 'running' => __('Running', 'aiot-site-audit'), 'pending' => __('Pending', 'aiot-site-audit'), 'failed' => __('could not finish', 'aiot-site-audit'), 'paused' => __('Paused', 'aiot-site-audit'), 'pages' => __('pages', 'aiot-site-audit'), 'confirmDel' => __('Delete this audit?', 'aiot-site-audit'), 'loading' => __('Loading...', 'aiot-site-audit'), 'close' => __('Close', 'aiot-site-audit'), 'copied' => __('Copied', 'aiot-site-audit'), 'saved' => __('Saved', 'aiot-site-audit'), 'error' => __('Something went wrong. Please try again.', 'aiot-site-audit'), 'rechecked' => __('Checked again', 'aiot-site-audit'), 'none' => __('Nothing here yet. This list is made from a full audit of "This website" (the site where the plugin is installed). Run one first.', 'aiot-site-audit'), 'ok' => __('The key works.', 'aiot-site-audit'), 'view' => __('View report', 'aiot-site-audit'), 'del' => __('Delete', 'aiot-site-audit'), 'linkFrom' => __('Add a link in', 'aiot-site-audit'), 'linkTo' => __('to', 'aiot-site-audit'), 'edit' => __('Edit', 'aiot-site-audit'), 'physical' => __('Your site has a real robots.txt file, so WordPress cannot add these lines for you. Copy them into that file.', 'aiot-site-audit')]]); }); /** * The fields of the settings forms, each cleaned for its own type as it is read. Only the fields named here are read from the request; * add-ons name their own fields (and the type of each) with the aiotsa_post_fields filter. The nonce is checked here before anything is read. */ function aiotsa_post_fields() { $types = ['lang' => 'key', 'thin' => 'int', 'keep' => 'int', 'pages' => 'urls', 'notes_print' => 'bool']; foreach ((array) apply_filters('aiotsa_key_ids', ['psi']) as $k) { $k = sanitize_key($k); $types['key_' . $k] = 'text'; $types['del_' . $k] = 'bool'; } check_admin_referer('aiotsa_save'); $types = (array) apply_filters('aiotsa_post_fields', $types); $P = []; foreach ($types as $name => $type) { $name = (string) $name; if (!isset($_POST[$name])) continue; if ($type === 'int') $P[$name] = (int) $_POST[$name]; elseif ($type === 'bool') $P[$name] = empty($_POST[$name]) ? 0 : 1; elseif ($type === 'key') $P[$name] = sanitize_key(wp_unslash($_POST[$name])); elseif ($type === 'url') $P[$name] = esc_url_raw(wp_unslash($_POST[$name])); elseif ($type === 'textarea') $P[$name] = sanitize_textarea_field(wp_unslash($_POST[$name])); elseif ($type === 'urls') $P[$name] = is_array($_POST[$name]) ? array_map('esc_url_raw', wp_unslash($_POST[$name])) : []; elseif ($type === 'bools') $P[$name] = is_array($_POST[$name]) ? array_map(function ($v) { return $v ? 1 : 0; }, array_map('absint', wp_unslash($_POST[$name]))) : []; else $P[$name] = sanitize_text_field(wp_unslash($_POST[$name])); } return $P; } add_action('admin_init', function () { if (empty($_POST['aiotsa_save']) || !current_user_can('manage_options')) return; check_admin_referer('aiotsa_save'); $what = sanitize_key(wp_unslash($_POST['aiotsa_save'])); $S = aiotsa_settings(); $P = aiotsa_post_fields(); if ($what === 'settings') { $S['lang'] = isset(aiotsa_langs()[$P['lang'] ?? '']) ? $P['lang'] : 'en'; $S['thin'] = max(100, min(1500, (int) ($P['thin'] ?? 300))); $S['keep'] = max(2, min(100, (int) ($P['keep'] ?? 10))); $S['notes_print'] = empty($P['notes_print']) ? 0 : 1; foreach ($S['pages'] as $k => $v) $S['pages'][$k] = esc_url_raw($P['pages'][$k] ?? ''); } if ($what === 'keys') { $K = get_option('aiotsa_keys', []); if (!is_array($K)) $K = []; foreach (apply_filters('aiotsa_key_ids', ['psi']) as $k) { $v = trim((string) ($P['key_' . $k] ?? '')); if (!empty($P['del_' . $k])) unset($K[$k]); elseif ($v !== '' && preg_match('/^[A-Za-z0-9_\-]{20,120}$/', $v)) $K[$k] = $v; elseif ($v !== '') add_settings_error('aiotsa', 'key', __('That does not look like a valid key. Copy it again, without spaces.', 'aiot-site-audit')); } update_option('aiotsa_keys', $K, false); } $S = apply_filters('aiotsa_save_settings', $S, $what, $P); update_option('aiotsa_settings', $S, false); if (!get_settings_errors('aiotsa')) add_settings_error('aiotsa', 'saved', __('Saved.', 'aiot-site-audit'), 'success'); set_transient('settings_errors', get_settings_errors(), 30); wp_safe_redirect(add_query_arg(['page' => 'aiotsa', 'tab' => in_array($what, ['testmail'], true) ? 'settings' : $what, 'settings-updated' => 1], admin_url('admin.php'))); exit; }); function aiotsa_admin_page() { if (!current_user_can('manage_options')) return; $tab = aiotsa_tab(); $S = aiotsa_settings(); echo '
' . esc_html(sprintf(/* translators: 1: website, 2: score */ __('The audit of %1$s is ready. Score: %2$d of 100.', 'aiot-site-audit'), $nt['target'], $nt['score'])) . ' ' . esc_html__('View report', 'aiot-site-audit') . '
' . esc_html__('View report', 'aiot-site-audit') . '
' . esc_html__('A new audit can be started when this one finishes.', 'aiot-site-audit') . ' ' . esc_html__('You can close this page. The audit keeps running on your server, and you get a notice in the admin when it is ready.', 'aiot-site-audit') . '
| ' . esc_html__('Date', 'aiot-site-audit') . ' | ' . esc_html__('Website', 'aiot-site-audit') . ' | ' . esc_html__('Type', 'aiot-site-audit') . ' | ' . esc_html__('Status', 'aiot-site-audit') . ' | ' . esc_html__('Score', 'aiot-site-audit') . ' | |
|---|---|---|---|---|---|
| ' . esc_html__('No audits yet.', 'aiot-site-audit') . ' | |||||
| ' . esc_html(wp_date(get_option('date_format') . ' ' . get_option('time_format'), strtotime($r['created'] . ' UTC'))) . ' | ' . esc_html($r['target']) . ' | ' . esc_html($types[$r['mode']] ?? $r['mode']) . ' | ' . esc_html($r['status']) . ' | ' . ($r['status'] === 'done' ? '' . (int) $r['score'] . '' : '-') . ' | ' . esc_html__('View report', 'aiot-site-audit') . ' · |
' . esc_html__('Loading...', 'aiot-site-audit') . '
' . esc_html__('Choose which AI services may read your site. "Allow" and "Block" add a rule; "No rule" leaves the crawler to your normal robots.txt. Well-behaved crawlers follow these rules; nothing can force a crawler to obey.', 'aiot-site-audit') . '
| ' . esc_html($b) . ' ' . esc_html($w) . ' |
' . esc_html__('A short list of your most useful pages for AI services. It is a new, optional standard: adding it does no harm, but no AI company promises to use it.', 'aiot-site-audit') . '
' . esc_html__('Posts that get few links, and posts on a related topic that could link to them. From the latest full audit. Matches are by shared words, so read each one before adding the link.', 'aiot-site-audit') . '