' . esc_html($chunk['text']) . '
Inspect text), registered like Diagnostics. Removing it // from the Aiwend submenu instead made WordPress deny access to everyone. add_submenu_page('', __('Inspect knowledge', 'aiwend'), __('Inspect knowledge', 'aiwend'), Capabilities::MANAGE_KNOWLEDGE, self::SLUG, [$this, 'render']); }); // A page without a parent gets no document title or menu highlight; give it Knowledge's. add_filter('admin_title', fn(string $title): string => $this->current() ? __('Extracted knowledge', 'aiwend') . ' ' . $title : $title); add_filter('parent_file', fn($file) => $this->current() ? 'aiwend' : $file); add_filter('submenu_file', fn($file) => $this->current() ? 'aiwend-knowledge' : $file); } private function current(): bool { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only navigation or filter parameter; no state is changed return is_admin() && isset($_GET['page']) && $_GET['page'] === self::SLUG; } public function render(): void { if (!current_user_can(Capabilities::MANAGE_KNOWLEDGE)) { wp_die('Not authorized.', '', ['response' => 403]); } nocache_headers(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only navigation or filter parameter; no state is changed $page = max(1, min(10000, absint($_GET['paged'] ?? 1))); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only navigation or filter parameter; no state is changed $data = $this->plugin->sources()->inspect(get_current_blog_id(), absint($_GET['source'] ?? 0), $page); AdminView::open($this->plugin, 'aiwend-knowledge', __('Extracted knowledge', 'aiwend'), __('The text Aiwend found in this source and answers from.', 'aiwend')); echo '
← ' . esc_html__('Back to knowledge', 'aiwend') . '
'; if ($data === null) { echo '' . esc_html__('Source unavailable. It may have been deleted.', 'aiwend') . '
' . esc_html($text) . '
'; } if ($version !== null) { /* translators: 1: index version number, 2: date and time of the last indexing, 3: number of chunks */ echo '' . esc_html(sprintf(__('Index version %1$d · Last indexed %2$s · %3$d chunks', 'aiwend'), $version['version_no'], wp_date('Y-m-d H:i', (int) $version['updated_at']), $version['chunk_count'])) . '
'; echo '' . esc_html($version['embedding_model'] . ' · ' . $version['dimension']) . '
' . esc_html__('Review coverage and reading order, especially for tables, columns and scanned pages. Chunks may overlap.', 'aiwend') . '
'; foreach ($data['chunks'] as $chunk) { // Heading and the real location reference (e.g. a PDF page), as stored with the chunk. $where = array_values(array_unique(array_filter([(string) $chunk['heading'], (string) $chunk['anchor']], 'strlen'))); echo '' . esc_html($chunk['text']) . '