Skip to content
wiki.fftac.org

Page Prompts - Source Excerpt 01

Back to Page Prompts

Summary

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

**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/templates/page-prompts.php

<?php

if (!defined('ABSPATH')) {
    exit;
}

get_header();

if (have_posts()) {
    the_post();
}

$page_title = get_the_title();
$page_copy = spiralist_book_pages_get_editorial_excerpt();
if ($page_copy === '') {
    $page_copy = 'Public prompt records bundled with the Spiralist book system, kept readable as standalone references instead of hidden inside a private workspace.';
}

$prompt_search = sanitize_text_field((string) get_query_var('spiralist_book_pages_prompt_search', ''));
if ($prompt_search === '' && isset($_GET['prompt_search'])) {
    $prompt_search = sanitize_text_field(wp_unslash((string) $_GET['prompt_search']));
}
$normalize_prompt_search_text = static function (string $value): string {
    return function_exists('mb_strtolower')
        ? mb_strtolower($value)
        : strtolower($value);
};
$all_prompt_records = spiralist_book_pages_get_public_prompt_records();
$prompt_records = array_values(
    array_filter(
        $all_prompt_records,
        static function (array $prompt) use ($prompt_search, $normalize_prompt_search_text): bool {
            if ($prompt_search === '') {
                return true;
            }

            $haystack = implode(
                "\n",
                array_filter(
                    [
                        (string) ($prompt['id'] ?? ''),
                        (string) ($prompt['slug'] ?? ''),
                        (string) ($prompt['title'] ?? ''),
                        (string) ($prompt['purpose'] ?? ''),
                        (string) ($prompt['summary'] ?? ''),
                        (string) ($prompt['content'] ?? ''),
                        (string) ($prompt['instructions'] ?? ''),
                        implode("\n", array_map('strval', (array) ($prompt['tags'] ?? []))),
                        implode("\n", array_map('strval', (array) ($prompt['relatedSymbols'] ?? []))),
                        implode("\n", array_map('strval', (array) ($prompt['relatedAxioms'] ?? []))),
                        implode("\n", array_map('strval', (array) ($prompt['relatedTransformations'] ?? []))),
                    ],
                    'strlen'
                )
            );

            return strpos($normalize_prompt_search_text($haystack), $normalize_prompt_search_text($prompt_search)) !== false;
        }
    )
);
$featured_prompts = array_values(
    array_filter(
        $prompt_records,
        static function (array $prompt): bool {
            return !empty($prompt['featured']);
        }
    )
);
$manuscript_pages = spiralist_book_pages_get_manuscript_page_assets();
$manuscript_by_slug = [];
$manuscript_by_filename = [];

foreach ($manuscript_pages as $page) {
    $slug = sanitize_title((string) ($page['slug'] ?? ''));
    $filename = strtolower((string) ($page['filename'] ?? ''));

    if ($slug !== '') {
        $manuscript_by_slug[$slug] = $page;
    }

    if ($filename !== '') {
        $manuscript_by_filename[$filename] = $page;
    }
}

$resolve_manuscript_page = static function (array $prompt) use ($manuscript_by_slug, $manuscript_by_filename): array {
    $folio_slug = sanitize_title((string) ($prompt['folioSlug'] ?? ''));
    $filename = strtolower((string) ($prompt['filename'] ?? ''));

    if ($folio_slug !== '' && isset($manuscript_by_slug[$folio_slug])) {
        return $manuscript_by_slug[$folio_slug];
    }

    if ($filename !== '' && isset($manuscript_by_filename[$filename])) {
        return $manuscript_by_filename[$filename];
    }

    return [];
};

$render_prompt_cards = static function (array $records) use ($resolve_manuscript_page, $prompt_search): void {
    if (empty($records)) {
        echo '<article class="spiralist-panel">';
        echo '<p class="spiralist-section-tag">Prompt Status</p>';
        if ($prompt_search !== '') {
            echo '<h2 class="spiralist-section-title">No prompt records matched this search.</h2>';
            echo '<p class="spiralist-muted">Try a symbol meaning, prompt title, tag, or related axiom phrase instead.</p>';
        } else {
            echo '<h2 class="spiralist-section-title">No public prompt records are available yet.</h2>';
            echo '<p class="spiralist-muted">Add prompt definitions under the plugin content directory to populate this public library.</p>';
        }
        echo '</article>';

        return;
    }

    echo '<div class="spiralist-archive-grid">';

    foreach ($records as $prompt) {
        if (!is_array($prompt)) {
            continue;
        }

        $prompt_url = (string) ($prompt['url'] ?? spiralist_book_pages_get_prompts_page_url());
        $manuscript_page = $resolve_manuscript_page($prompt);
        $manuscript_url = !empty($manuscript_page) && function_exists('spiralist_book_pages_get_manuscript_folio_url')
            ? spiralist_book_pages_get_manuscript_folio_url($manuscript_page)
            : '';
        $tags = array_values(array_filter(array_map('strval', (array) ($prompt['tags'] ?? []))));
        $meta = array_values(
            array_filter(
                [
                    (string) ($prompt['systemLabel'] ?? ''),
                    (string) ($prompt['roleLabel'] ?? ''),
                    (string) ($prompt['version'] ?? ''),
                ],
                'strlen'
            )
        );

        echo '<article class="spiralist-archive-card">';
        echo '<p class="spiralist-section-tag">' . esc_html((string) ($prompt['statusLabel'] ?? 'Prompt')) . '</p>';
        echo '<strong>' . esc_html((string) ($prompt['title'] ?? 'Prompt')) . '</strong>';
        echo '<p>' . esc_html((string) ($prompt['purpose'] ?? '')) . '</p>';

        if (!empty($meta)) {
            echo '<p class="spiralist-muted">' . esc_html(implode(' | ', $meta)) . '</p>';
        }

        if (!empty($tags)) {
            echo '<div class="spiralist-chip-row">';
            foreach (array_slice($tags, 0, 4) as $tag) {
                echo '<span class="spiralist-chip">' . esc_html($tag) . '</span>';
            }
            echo '</div>';
        }

        echo '<div class="spiralist-cta-row spiralist-cta-row--start">';
        echo '<a class="spiralist-button spiralist-button--primary" href="' . esc_url($prompt_url) . '">Open Prompt</a>';

        if ($manuscript_url !== '') {
            echo '<a class="spiralist-button spiralist-button--secondary" href="' . esc_url($manuscript_url) . '">Open Manuscript Page</a>';
        }

        echo '</div>';
        echo '</article>';
    }

    echo '</div>';
};
?>
<main class="spiralist-page spiralist-page--workspace-library">
    <section class="spiralist-page-hero spiralist-page-hero--workspace">
        <div class="spiralist-shell spiralist-page-hero__content">
            <p class="spiralist-kicker">Book Prompt Library</p>
            <h1><?php echo esc_html($page_title !== '' ? $page_title : 'Prompts'); ?></h1>
            <p class="spiralist-page-hero__copy"><?php echo esc_html($page_copy); ?></p>
            <form class="spiralist-search-form" method="get" action="<?php echo esc_url(spiralist_book_pages_get_prompts_page_url()); ?>">
                <label class="screen-reader-text" for="spiralist-prompt-search">Search prompts</label>
                <input id="spiralist-prompt-search" type="search" name="prompt_search" value="<?php echo esc_attr($prompt_search); ?>" placeholder="Search prompts, symbols, axioms, or tags" />
                <button class="spiralist-button spiralist-button--secondary" type="submit">Search</button>
            </form>
            <div class="spiralist-cta-row">
                <a class="spiralist-button spiralist-button--primary" href="<?php echo esc_url(spiralist_book_pages_get_manuscript_page_url()); ?>">Open Manuscript</a>
                <a class="spiralist-button spiralist-button--secondary" href="<?php echo esc_url(spiralist_book_pages_get_prompts_api_url()); ?>">Prompt API</a>
            </div>
        </div>
    </section>

    <section class="spiralist-page-section">
        <div class="spiralist-shell spiralist-grid spiralist-grid--split">
            <article class="spiralist-panel">
                <p class="spiralist-section-tag">Public Records</p>
                <h2 class="spiralist-section-title"><?php echo esc_html((string) count($prompt_records)); ?> available prompt<?php echo count($prompt_records) === 1 ? '' : 's'; ?></h2>
                <p class="spiralist-muted">
                    <?php if ($prompt_search !== '') : ?>
                        Showing matches for "<?php echo esc_html($prompt_search); ?>" across titles, prompt text, symbols, axioms, transformations, and tags.
                    <?php else : ?>