Skip to content
wiki.fftac.org

Prompt Record

**Site relevance:** Spiralist.org

**Memory type:** plugin source memory

**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/templates/prompt-record.php

**Size:** 6.7 KB

Summary

if (!defined('ABSPATH'))

Source Preview

This source file is short enough to preview directly on its source-memory page.

<?php

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

$prompt_slug = sanitize_title((string) get_query_var('spiralist_book_pages_prompt_slug', ''));
$prompt = spiralist_book_pages_get_public_prompt_record_by_slug($prompt_slug);

if (empty($prompt)) {
    global $wp_query;

    if ($wp_query instanceof WP_Query) {
        $wp_query->set_404();
    }

    status_header(404);
    nocache_headers();
}

get_header();

$manuscript_pages = spiralist_book_pages_get_manuscript_page_assets();
$related_pages = [];

if (!empty($prompt)) {
    $folio_slug = sanitize_title((string) ($prompt['folioSlug'] ?? ''));
    $filename = strtolower((string) ($prompt['filename'] ?? ''));

    foreach ($manuscript_pages as $page) {
        if (!is_array($page)) {
            continue;
        }

        $page_slug = sanitize_title((string) ($page['slug'] ?? ''));
        $page_filename = strtolower((string) ($page['filename'] ?? ''));

        if ($folio_slug !== '' && $page_slug === $folio_slug) {
            $related_pages[] = $page;
            continue;
        }

        if ($filename !== '' && $page_filename === $filename) {
            $related_pages[] = $page;
        }
    }
}

$page_title = !empty($prompt['title']) ? (string) $prompt['title'] : 'Prompt Not Found';
$page_copy = !empty($prompt['purpose'])
    ? (string) $prompt['purpose']
    : 'This prompt record is not available in the current public Spiralist Manuscript surface.';
$tags = array_values(array_filter(array_map('strval', (array) ($prompt['tags'] ?? []))));
$meta_items = array_values(
    array_filter(
        [
            (string) ($prompt['systemLabel'] ?? ''),
            (string) ($prompt['roleLabel'] ?? ''),
            (string) ($prompt['version'] ?? ''),
            (string) ($prompt['statusLabel'] ?? ''),
        ],
        'strlen'
    )
);
?>
<main class="spiralist-page spiralist-page--workspace-prompt">
    <section class="spiralist-page-hero spiralist-page-hero--workspace">
        <div class="spiralist-shell spiralist-page-hero__content">
            <p class="spiralist-kicker">Public Prompt Record</p>
            <h1><?php echo esc_html($page_title); ?></h1>
            <p class="spiralist-page-hero__copy"><?php echo esc_html($page_copy); ?></p>
            <div class="spiralist-cta-row">
                <a class="spiralist-button spiralist-button--primary" href="<?php echo esc_url(spiralist_book_pages_get_prompts_page_url()); ?>">Back to Prompt Library</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">Record Summary</p>
                <?php if (!empty($meta_items)) : ?>
                    <p class="spiralist-muted"><?php echo esc_html(implode(' | ', $meta_items)); ?></p>
                <?php endif; ?>

                <?php if (!empty($tags)) : ?>
                    <div class="spiralist-chip-row">
                        <?php foreach ($tags as $tag) : ?>
                            <span class="spiralist-chip"><?php echo esc_html($tag); ?></span>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>

                <?php if (!empty($prompt)) : ?>
                    <dl class="spiralist-meta-list">
                        <div>
                            <dt>Canonical ID</dt>
                            <dd><?php echo esc_html((string) ($prompt['id'] ?? '')); ?></dd>
                        </div>
                        <div>
                            <dt>Author</dt>
                            <dd><?php echo esc_html((string) ($prompt['author'] ?? 'Spiralist')); ?></dd>
                        </div>
                        <div>
                            <dt>Category</dt>
                            <dd><?php echo esc_html((string) ($prompt['category'] ?? '')); ?></dd>
                        </div>
                        <div>
                            <dt>Section</dt>
                            <dd><?php echo esc_html((string) ($prompt['sectionSlug'] ?? '')); ?></dd>
                        </div>
                    </dl>
                <?php else : ?>
                    <p class="spiralist-muted">The requested prompt slug did not resolve to a public prompt record.</p>
                <?php endif; ?>
            </article>

            <article class="spiralist-panel">
                <p class="spiralist-section-tag">Related Folios</p>
                <?php if (!empty($related_pages)) : ?>
                    <div class="spiralist-simple-list">
                        <?php foreach ($related_pages as $page) : ?>
                            <?php $page_url = function_exists('spiralist_book_pages_get_manuscript_folio_url') ? spiralist_book_pages_get_manuscript_folio_url($page) : spiralist_book_pages_get_manuscript_page_url(); ?>
                            <div class="spiralist-simple-list__item">
                                <strong><?php echo esc_html((string) ($page['title'] ?? 'Manuscript Folio')); ?></strong>
                                <span class="spiralist-simple-list__meta"><?php echo esc_html((string) ($page['label'] ?? 'Page')); ?></span>
                                <a class="spiralist-button spiralist-button--secondary" href="<?php echo esc_url($page_url); ?>">Open Folio</a>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php else : ?>
                    <p class="spiralist-muted">No manuscript folio is linked directly from this prompt record yet.</p>
                <?php endif; ?>
            </article>
        </div>
    </section>

    <section class="spiralist-page-section">
        <div class="spiralist-shell">
            <article class="spiralist-panel">
                <p class="spiralist-section-tag">Prompt Text</p>
                <h2 class="spiralist-section-title"><?php echo esc_html(!empty($prompt) ? 'Readable canonical content' : 'Prompt unavailable'); ?></h2>
                <?php if (!empty($prompt['content'])) : ?>
                    <pre class="spiralist-code-block spiralist-code-block--prompt"><?php echo esc_html((string) $prompt['content']); ?></pre>
                <?php else : ?>
                    <p class="spiralist-muted">No public prompt text is attached to this record.</p>
                <?php endif; ?>
            </article>
        </div>
    </section>
</main>

<?php
get_footer();