Skip to content
wiki.fftac.org

Library - Source Excerpt 01

Back to Library

Summary

This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/spiralist-workspace/templates/library.php so readers can inspect the evidence without opening the full source file.

**Source path:** Spiralist/wp-content/plugins/spiralist-workspace/templates/library.php

<?php

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

$plugin = spiralist_workspace();
$frontend = $plugin->frontend();
$context = $frontend->library_context();
$current_locale = function_exists('spiralist_get_current_locale_tag') ? spiralist_get_current_locale_tag() : 'en-us';
$route_url = static function (string $path, array $query = []) use ($current_locale): string {
    $url = home_url('/' . trim($path, '/') . '/');

    $url = $current_locale !== '' && function_exists('spiralist_get_language_prefixed_url')
        ? spiralist_get_language_prefixed_url($url, $current_locale)
        : $url;

    return !empty($query) ? add_query_arg($query, $url) : $url;
};
$filter_route_url = static function (array $query) use ($route_url): string {
    $query = array_filter(
        $query,
        static fn($value): bool => is_scalar($value) && trim((string) $value) !== ''
    );

    if (count($query) !== 1) {
        return $route_url('prompts', $query);
    }

    $key = (string) array_key_first($query);
    $value = str_replace('_', '-', sanitize_title((string) reset($query)));

    if ($value === '') {
        return $route_url('prompts');
    }

    if ($key === 'search') {
        return $route_url('prompts/search/' . rawurlencode($value));
    }

    if ($key === 'lane' && $value === 'prompt-ecology-archive') {
        return $route_url('prompts/archive');
    }

    if ($key === 'lane' && in_array($value, ['official-canon', 'community-library'], true)) {
        return $route_url('prompts/' . rawurlencode($value));
    }

    if (in_array($key, ['lane', 'category', 'provenance', 'moderation_status', 'risk', 'function', 'level', 'intent'], true)) {
        $route_key = $key === 'moderation_status' ? 'moderation' : $key;

        return $route_url('prompts/' . rawurlencode($route_key) . '/' . rawurlencode($value));
    }

    return $route_url('prompts', $query);
};
$engagement_target = static function (string $value, string $fallback = 'item'): string {
    $target = sanitize_key(str_replace([' ', '_'], '-', $value));

    return $target !== '' ? $target : $fallback;
};

$filters = (array) ($context['filters'] ?? []);
$sections = (array) ($context['sections'] ?? []);
$lane_counts = (array) ($context['lane_counts'] ?? []);
$moderation_counts = (array) ($context['moderation_counts'] ?? []);
$all_count = (int) ($context['all_count'] ?? 0);
$filtered_count = (int) ($context['filtered_count'] ?? 0);
$categories = (array) ($context['categories'] ?? []);
$facets = (array) ($context['facets'] ?? []);
$intent_records = (array) ($context['intents'] ?? []);
$featured_collections = (array) ($context['featured_collections'] ?? []);
$api_examples = (array) ($context['api_examples'] ?? []);
$filters_active = !empty($context['filters_active']);
$api_url = rest_url('spiralist-workspace/v1/public/prompts');
$workspace_url = $route_url('workspace');
$members_url = $route_url('members');
$run_prompt_url = function_exists('spiralist_get_run_prompt_page_url')
    ? spiralist_get_run_prompt_page_url()
    : $route_url('prompt-generator');
$symbols_url = $route_url('symbols');
$login_url = function_exists('spiralist_get_login_url') ? spiralist_get_login_url($workspace_url) : wp_login_url($workspace_url);
$lane_labels = \SpiralistWorkspace\Support\PromptMetaRegistry::publication_lanes();
$provenance_labels = \SpiralistWorkspace\Support\PromptMetaRegistry::provenances();
$moderation_labels = array_intersect_key(
    \SpiralistWorkspace\Support\PromptMetaRegistry::moderation_statuses(),
    array_flip(['provisional_public', 'peer_reviewed', 'official_canon'])
);
$risk_labels = \SpiralistWorkspace\Support\PromptMetaRegistry::risk_labels();
$function_labels = \SpiralistWorkspace\Support\PromptMetaRegistry::function_tags();
$level_labels = \SpiralistWorkspace\Support\PromptMetaRegistry::maturity_levels();
$all_prompt_records = array_values(
    array_filter(
        array_merge(
            (array) ($sections['official_canon'] ?? []),
            (array) ($sections['community_library'] ?? []),
            (array) ($sections['prompt_ecology_archive'] ?? [])
        ),
        static fn($record): bool => is_array($record)
    )
);
$starter_query_cards = array_map(
    static function (array $intent) use ($filter_route_url): array {
        $value = (string) ($intent['value'] ?? '');

        return [
            'label' => (string) ($intent['short_label'] ?? $intent['label'] ?? 'Intent'),
            'title' => (string) ($intent['label'] ?? 'Prompt intent'),
            'copy' => (string) ($intent['summary'] ?? ''),
            'url' => $filter_route_url(['intent' => $value]),
        ];
    },
    $intent_records
);
$starter_query_cards[] = [
    'label' => 'Start',
    'title' => 'Run a first Spiralist session',
    'copy' => 'Use the safest newcomer path: one explanation, one prompt, one next step.',
    'url' => $filter_route_url(['search' => 'first session']),
];
$starter_query_cards[] = [
    'label' => 'Review',
    'title' => 'Check boundaries first',
    'copy' => 'Inspect guardrails, moderation labels, and reality checks before publishing or intensifying a prompt.',
    'url' => $filter_route_url(['function' => 'governance']),
];
$study_mode_cards = [
    [
        'label' => 'Official Canon',
        'title' => 'Reviewed starter material',
        'copy' => 'The center of gravity for practical Spiralism prompts.',
        'url' => $filter_route_url(['lane' => 'official_canon']),
    ],
    [
        'label' => 'Prompt Builders',
        'title' => 'Tools for making prompts',
        'copy' => 'Prompt systems that help draft, revise, or structure other prompts.',
        'url' => $filter_route_url(['function' => 'tooling']),
    ],
    [
        'label' => 'Safety And Governance',
        'title' => 'How public prompts stay bounded',
        'copy' => 'Moderation state, risk labels, provenance, and peer review.',
        'url' => $filter_route_url(['moderation_status' => 'peer_reviewed']),
    ],
    [
        'label' => 'Archive Analysis',
        'title' => 'Historical records with context',
        'copy' => 'Research material preserved without turning it into default practice.',
        'url' => $filter_route_url(['lane' => 'prompt_ecology_archive']),
    ],
    [
        'label' => 'Symbols And Axioms',
        'title' => 'Connect prompts to the language layer',
        'copy' => 'Move from a prompt into symbolic references and system terms.',
        'url' => $symbols_url,
    ],
];
$preferred_starter_terms = ['first session', 'newcomer', 'improve', 'action plan', 'working agreement', 'risk', 'mirrorfield', 'awakening', 'boundary', 'pattern'];
$starter_prompt_records = [];
$starter_prompt_keys = [];
$append_starter_prompt = static function (array $record) use (&$starter_prompt_records, &$starter_prompt_keys): void {
    $record_id = (int) ($record['id'] ?? 0);
    $record_key = $record_id > 0 ? 'id:' . $record_id : 'slug:' . (string) ($record['slug'] ?? '');

    if ($record_key === 'slug:' || isset($starter_prompt_keys[$record_key])) {
        return;
    }

    $starter_prompt_keys[$record_key] = true;
    $starter_prompt_records[] = $record;
};
foreach ($preferred_starter_terms as $term) {
    foreach ($all_prompt_records as $record) {
        $haystack = strtolower(
            implode(
                ' ',
                [
                    (string) ($record['title'] ?? ''),
                    (string) ($record['summary'] ?? ''),
                    (string) ($record['category'] ?? ''),
                    (string) ($record['subcategory'] ?? ''),
                ]
            )
        );

        if (strpos($haystack, $term) === false) {
            continue;
        }

        $append_starter_prompt($record);
        break;
    }

    if (count($starter_prompt_records) >= 8) {
        break;
    }
}

if (count($starter_prompt_records) < 6) {
    foreach ($all_prompt_records as $record) {
        $append_starter_prompt($record);

        if (count($starter_prompt_records) >= 8) {
            break;
        }
    }
}

$prompt_plain_badges = static function (array $prompt): array {
    $risk_keys = array_values(array_filter(array_map('strval', (array) ($prompt['risk_labels'] ?? [])), 'strlen'));
    $function_keys = array_values(array_filter(array_map('strval', (array) ($prompt['function_tags'] ?? [])), 'strlen'));
    $moderation = (string) ($prompt['moderation_status'] ?? '');
    $lane = (string) ($prompt['publication_lane'] ?? '');
    $category = (string) ($prompt['category'] ?? '');
    $haystack = strtolower(
        implode(
            ' ',
            [
                (string) ($prompt['title'] ?? ''),
                (string) ($prompt['summary'] ?? ''),
                $category,