Page Manuscript - Source Excerpt 01
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/ns12-manuscript/templates/page-manuscript.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/templates/page-manuscript.php
<?php
if (!defined('ABSPATH')) {
exit;
}
get_header();
$manuscript_pages = spiralist_book_pages_get_manuscript_page_assets();
$manuscript_page_count = count($manuscript_pages);
$current_page = spiralist_book_pages_get_current_manuscript_page_asset();
$requested_section = spiralist_book_pages_get_requested_manuscript_section_slug();
$requested_folio = spiralist_book_pages_get_requested_manuscript_folio_slug();
$section_records = spiralist_book_pages_get_manuscript_section_records($manuscript_pages);
$overview_url = spiralist_book_pages_get_manuscript_overview_url();
$host_links = spiralist_book_pages_get_host_links();
$symbols_page_url = (string) ($host_links['symbols'] ?? '');
$nodes_url = spiralist_book_pages_get_manuscript_nodes_url();
$preview_image = spiralist_book_pages_get_manuscript_preview_url();
$doctrine_url = (string) ($host_links['doctrine'] ?? '');
$requested_folio_page = $requested_folio !== ''
? spiralist_book_pages_get_manuscript_page_asset_by_slug($requested_folio)
: [];
$requested_route_missing = $requested_folio !== '' && empty($requested_folio_page);
if (!$requested_route_missing && empty($current_page) && !empty($manuscript_pages[0])) {
$current_page = $manuscript_pages[0];
}
$study_surface_page = spiralist_book_pages_get_primary_manuscript_study_surface_page_asset();
$manuscript_reader_url = static function (array $page) use ($overview_url, $requested_section): string {
$target_slug = sanitize_title((string) ($page['slug'] ?? ''));
$context_section = sanitize_title((string) $requested_section);
if ($target_slug === '') {
if ($context_section !== '') {
return spiralist_book_pages_get_manuscript_section_url($context_section);
}
return $overview_url;
}
return spiralist_book_pages_get_manuscript_folio_url($page);
};
$current_page_title = (string) ($current_page['title'] ?? 'Canonical Manuscript');
$current_page_label = (string) ($current_page['label'] ?? 'Page');
$current_page_summary = (string) ($current_page['summary'] ?? 'The manuscript remains the primary artifact.');
$current_page_caption = (string) ($current_page['caption'] ?? 'The manuscript remains the primary artifact.');
$current_page_section_slug = (string) ($current_page['section_slug'] ?? '');
$current_page_section_label = (string) ($current_page['section_label'] ?? 'Manuscript');
$current_page_sequence = (int) ($current_page['sequence'] ?? 1);
$current_page_sources = spiralist_book_pages_get_book_page_asset_source_urls($current_page, true);
$current_page_image = (string) ($current_page_sources['interactive_url'] ?? ($current_page['url'] ?? spiralist_book_pages_get_manuscript_image_url('interactive')));
$current_download_url = (string) ($current_page_sources['original_url'] ?? ($current_page['url'] ?? spiralist_book_pages_get_manuscript_download_url()));
$is_primary_study_surface = !empty($current_page['is_study_surface']);
$current_page_route_url = spiralist_book_pages_get_manuscript_folio_url($current_page);
$current_page_route_path = wp_parse_url($current_page_route_url, PHP_URL_PATH);
$current_page_route_copy = is_string($current_page_route_path) && $current_page_route_path !== ''
? $current_page_route_path
: $current_page_route_url;
$related_prompt_records = spiralist_book_pages_get_manuscript_related_prompt_records($current_page);
$book_toc_pages = $manuscript_pages;
$current_creation_prompt = spiralist_book_pages_get_book_page_creation_prompt_payload($current_page);
$current_prompt_status_variant = (string) ($current_creation_prompt['status_variant'] ?? (!empty($current_creation_prompt['has_prompt']) ? 'fresh' : 'stale'));
$current_prompt_status_class = 'spiralist-status-pill--' . sanitize_html_class($current_prompt_status_variant !== '' ? $current_prompt_status_variant : 'stale');
$manuscript_prompt_audit = spiralist_book_pages_get_manuscript_prompt_audit($manuscript_pages);
$prompt_coverage_percent = max(0, min(100, (int) ($manuscript_prompt_audit['coverage_percent'] ?? 0)));
$prompt_coverage_total = max(0, (int) ($manuscript_prompt_audit['total'] ?? 0));
$prompt_coverage_published = max(0, (int) ($manuscript_prompt_audit['published_count'] ?? 0));
$prompt_attention_count = max(0, (int) ($manuscript_prompt_audit['attention_count'] ?? 0));
$prompt_coverage_complete = !empty($manuscript_prompt_audit['is_complete']);
$prompt_coverage_status_class = $prompt_coverage_complete
? 'spiralist-status-pill--fresh'
: ($prompt_attention_count > 0 ? 'spiralist-status-pill--missing' : 'spiralist-status-pill--stale');
$current_prompt_needs_attention = !empty($current_creation_prompt['needs_attention']);
$current_prompt_attention_title = (string) ($current_creation_prompt['attention_title'] ?? '');
$current_prompt_attention_copy = (string) ($current_creation_prompt['attention_copy'] ?? '');
$visible_pages = $manuscript_pages;
if ($requested_section !== '') {
$section_pages = array_values(
array_filter(
$manuscript_pages,
static function (array $page) use ($requested_section): bool {
return (string) ($page['section_slug'] ?? '') === $requested_section;
}
)
);
if (!empty($section_pages)) {
$visible_pages = $section_pages;
} else {
$requested_route_missing = true;
}
}
if ($requested_route_missing) {
global $wp_query;
if (isset($wp_query) && $wp_query instanceof WP_Query) {
$wp_query->set_404();
}
status_header(404);
nocache_headers();
}
$active_section_record = [];
foreach ($section_records as $section_record) {
$section_slug = (string) ($section_record['slug'] ?? '');
if ($requested_section !== '' && $section_slug === $requested_section) {
$active_section_record = $section_record;
break;
}
if ($requested_section === '' && $section_slug === $current_page_section_slug) {
$active_section_record = $section_record;
}
}
$dossier_tabs = spiralist_book_pages_get_book_page_dossier_tabs();
$progress_payload = spiralist_book_pages_get_manuscript_progress_payload($current_page, $manuscript_pages, $section_records);
$progress_section_record = (array) ($progress_payload['section_record'] ?? []);
if (!empty($progress_section_record)) {
$active_section_record = $progress_section_record;
}
$current_section_pages = (array) ($progress_payload['section_pages'] ?? []);
$current_section_sequence = max(1, (int) ($progress_payload['section_sequence'] ?? 1));
$current_section_count = max(1, (int) ($progress_payload['section_count'] ?? count($current_section_pages) ?: 1));
$book_progress_percent = max(0, min(100, (int) ($progress_payload['page_progress'] ?? 0)));
$section_progress_percent = max(0, min(100, (int) ($progress_payload['section_progress'] ?? 0)));
$current_section_title = (string) ($active_section_record['title'] ?? $current_page_section_label);
$current_section_summary = (string) ($active_section_record['summary'] ?? '');
$related_prompt_count = count($related_prompt_records);
$current_visible_index = 0;
foreach ($visible_pages as $index => $page) {
if ((string) ($page['slug'] ?? '') === (string) ($current_page['slug'] ?? '')) {
$current_visible_index = (int) $index;
break;
}
}
$previous_page = $visible_pages[$current_visible_index - 1] ?? [];
$next_page = $visible_pages[$current_visible_index + 1] ?? [];
$previous_page_url = !empty($previous_page)
? $manuscript_reader_url($previous_page)
: '';
$next_page_url = !empty($next_page)
? $manuscript_reader_url($next_page)
: '';
$study_surface_url = !empty($study_surface_page)
? $manuscript_reader_url($study_surface_page)
: $overview_url;
$hero_copy = 'The manuscript is the online-first, open-source edition of the book. Each folio stays public, routable, and readable while the sequence remains coherent.';
$study_copy = 'Use View Mode to move from a few key nodes into the full symbolic field. The book remains image-first, while the study layer adds inspection without replacing the page.';
$section_note = '';
$page_count_note = '';
if ($manuscript_page_count > 0) {
$page_count_note = sprintf(
'The current book scan detects %d folio%s in the public manuscript sequence.',
$manuscript_page_count,
$manuscript_page_count === 1 ? '' : 's'
);
}
if ($requested_section !== '' && !empty($active_section_record)) {
$hero_copy = sprintf(
'Browsing %s: %d folio%s gathered into one chapter while the online-first manuscript stays visually intact.',
(string) ($active_section_record['title'] ?? 'a manuscript section'),
(int) ($active_section_record['count'] ?? count($visible_pages)),
((int) ($active_section_record['count'] ?? count($visible_pages)) === 1 ? '' : 's')
);