Skip to content
wiki.fftac.org

Runtime - Source Excerpt 14

Back to Runtime

Summary

This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/ns12-manuscript/includes/runtime.php so readers can inspect the evidence without opening the full source file.

**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/includes/runtime.php

$sequence = max(1, (int) ($folio['sequence'] ?? ($index + 1)));
            $filename = trim((string) ($folio['filename'] ?? ''));
            $filenameKey = strtolower($filename);
            $asset = $filenameKey !== '' && isset($availableAssets[$filenameKey])
                ? $availableAssets[$filenameKey]
                : ($filename !== '' ? spiralist_book_pages_get_book_page_asset_by_filename($filename) : []);

            if (empty($asset) && $filename !== '') {
                $asset = [
                    'path' => rtrim((string) SPIRALIST_BOOK_PAGES_PLUGIN_PATH, '/\\') . DIRECTORY_SEPARATOR . $filename,
                    'url' => trailingslashit((string) SPIRALIST_BOOK_PAGES_PLUGIN_URL) . spiralist_book_pages_encode_asset_url_path($filename),
                    'filename' => $filename,
                ];
            }

            if (empty($asset)) {
                continue;
            }

            $slug = sanitize_title((string) ($folio['slug'] ?? ''));
            if ($slug === '') {
                $slug = 'folio-' . $sequence;
            }
            if (isset($usedSlugs[$slug])) {
                $suffix = $sequence;
                while (isset($usedSlugs[$slug . '-' . $suffix])) {
                    $suffix++;
                }
                $slug .= '-' . $suffix;
            }
            $usedSlugs[$slug] = true;

            $sectionSlug = sanitize_title((string) ($folio['section_slug'] ?? 'appendix'));
            if (!isset($sectionBlueprints[$sectionSlug])) {
                $sectionSlug = 'appendix';
            }
            $section = $sectionBlueprints[$sectionSlug];

            $pages[] = array_merge(
                $asset,
                [
                    'sequence' => $sequence,
                    'label' => (string) ($folio['label'] ?? ('Page ' . $sequence)),
                    'title' => (string) ($folio['title'] ?? ('Manuscript Folio ' . $sequence)),
                    'slug' => $slug,
                    'eyebrow' => (string) ($folio['eyebrow'] ?? ''),
                    'summary' => (string) ($folio['summary'] ?? ''),
                    'caption' => (string) ($folio['caption'] ?? ''),
                    'alt' => (string) ($folio['alt'] ?? ''),
                    'transcript' => (string) ($folio['transcript'] ?? ''),
                    'keywords' => array_values(array_filter(array_map('strval', (array) ($folio['keywords'] ?? [])))),
                    'subjects' => array_values(array_filter(array_map('strval', (array) ($folio['subjects'] ?? [])))),
                    'section_slug' => $sectionSlug,
                    'section_label' => (string) ($section['label'] ?? 'Section'),
                    'section_title' => (string) ($section['title'] ?? 'Section'),
                    'section_summary' => (string) ($section['summary'] ?? ''),
                    'is_study_surface' => !empty($folio['is_study_surface']),
                    'is_prominent' => !empty($folio['is_prominent']),
                    'creation_prompt_title' => (string) ($folio['creation_prompt_title'] ?? 'Prompt Used'),
                    'creation_prompt_status' => (string) ($folio['creation_prompt_status'] ?? 'Canonical prompt'),
                    'creation_prompt_summary' => (string) ($folio['creation_prompt_summary'] ?? ''),
                    'creation_prompt_text' => '',
                    'creation_prompt_source_slug' => sanitize_title((string) ($folio['creation_prompt_source_slug'] ?? '')),
                    'related_workspace_prompt_slugs' => array_values(
                        array_filter(
                            array_map(
                                static function ($relatedSlug): string {
                                    return sanitize_title((string) $relatedSlug);
                                },
                                (array) ($folio['related_workspace_prompt_slugs'] ?? [])
                            ),
                            'strlen'
                        )
                    ),
                ]
            );
        }

        if (!empty($pages)) {
            usort(
                $pages,
                static function (array $left, array $right): int {
                    return ((int) ($left['sequence'] ?? 0)) <=> ((int) ($right['sequence'] ?? 0));
                }
            );

            return $pages;
        }
    }

    $pages = [];
    $used_slugs = [];
    $section_blueprints = spiralist_book_pages_get_manuscript_section_blueprints();
    $page_blueprints = spiralist_book_pages_get_manuscript_page_blueprints();
    $filename_blueprints = spiralist_book_pages_get_manuscript_page_blueprints_by_filename();
    $build_page = static function (array $asset, int $sequence) use (&$used_slugs, $section_blueprints, $page_blueprints, $filename_blueprints): array {
        $filename_key = strtolower((string) ($asset['filename'] ?? ''));
        $blueprint = $filename_blueprints[$filename_key] ?? ($page_blueprints[$sequence] ?? []);
        $is_study_surface = !empty($blueprint['is_study_surface']);
        $title = trim((string) ($blueprint['title'] ?? spiralist_book_pages_humanize_asset_label((string) ($asset['filename'] ?? 'Manuscript Folio'))));
        if ($title === '') {
            $title = 'Manuscript Folio ' . $sequence;
        }

        $slug = sanitize_title((string) ($blueprint['slug'] ?? $title));
        if ($slug === '') {
            $slug = 'folio-' . $sequence;
        }

        if (isset($used_slugs[$slug])) {
            $slug .= '-' . $sequence;
        }

        $used_slugs[$slug] = true;

        $section_slug = sanitize_title((string) ($blueprint['section_slug'] ?? 'appendix'));
        if (!isset($section_blueprints[$section_slug])) {
            $section_slug = 'appendix';
        }

        $section = $section_blueprints[$section_slug];
        $label = trim((string) ($blueprint['label'] ?? ''));
        if ($label === '' || preg_match('/^page\s+\d+$/i', $label) === 1) {
            $label = 'Page ' . $sequence;
        }
        $eyebrow = trim((string) ($blueprint['eyebrow'] ?? ($is_study_surface ? 'Study Surface' : 'Continuation Folio')));
        $summary = trim((string) ($blueprint['summary'] ?? ($is_study_surface
            ? 'The primary manuscript page used for the study overlay and symbolic field inspection.'
            : 'Continuation page presented as a direct manuscript reading surface without overlay.')));
        $caption = trim((string) ($blueprint['caption'] ?? ($is_study_surface
            ? 'The primary folio remains the active study surface for symbolic inspection.'
            : 'This folio remains available as a direct artifact surface without overlay.')));

        return array_merge(
            $asset,
            [
                'sequence' => $sequence,
                'label' => $label,
                'title' => $title,
                'slug' => $slug,
                'eyebrow' => $eyebrow,
                'summary' => $summary,
                'caption' => $caption,
                'alt' => '',
                'transcript' => '',
                'keywords' => [],
                'subjects' => [],
                'section_slug' => $section_slug,
                'section_label' => (string) ($section['label'] ?? 'Section'),
                'section_title' => (string) ($section['title'] ?? 'Section'),
                'section_summary' => (string) ($section['summary'] ?? ''),
                'is_study_surface' => $is_study_surface,
                'creation_prompt_title' => (string) ($blueprint['creation_prompt_title'] ?? 'Prompt Used'),
                'creation_prompt_status' => (string) ($blueprint['creation_prompt_status'] ?? 'Prompt pending'),
                'creation_prompt_summary' => (string) ($blueprint['creation_prompt_summary'] ?? ''),
                'creation_prompt_text' => (string) ($blueprint['creation_prompt_text'] ?? ''),
                'creation_prompt_source_slug' => sanitize_title((string) ($blueprint['creation_prompt_source_slug'] ?? '')),
                'related_workspace_prompt_slugs' => array_values(
                    array_filter(
                        array_map(
                            static function ($slug): string {
                                return sanitize_title((string) $slug);
                            },
                            (array) ($blueprint['related_workspace_prompt_slugs'] ?? [])
                        ),
                        'strlen'
                    )
                ),
            ]
        );
    };

    foreach (spiralist_book_pages_get_book_page_assets_in_display_order() as $asset) {
        $sequence = count($pages) + 1;
        $pages[] = $build_page($asset, $sequence);
    }

    return $pages;
}