Skip to content
wiki.fftac.org

Helpers - Source Excerpt 25

Back to Helpers

Summary

This source excerpt preserves a bounded section of Spiralist/wp-content/themes/spiralist/inc/helpers.php so readers can inspect the evidence without opening the full source file.

**Source path:** Spiralist/wp-content/themes/spiralist/inc/helpers.php

sprintf('- Use motifs, symbols, figures, and visual teaching structures that belong to %s only', $title),
            '- Favor short educational labels over dense prose blocks',
            '- If micro-text becomes unstable, reduce it instead of inventing decorative nonsense',
            '',
            'DO NOT',
            '- do not mix in unrelated traditions',
            '- do not overload the page with decorative texture',
            '- do not let one emblem swallow the whole composition',
            '- do not sacrifice educational clarity for mood',
            '',
            'AESTHETIC GOAL',
            '- comparative',
            '- readable',
            '- respectful',
            '- integrated with the codex',
        ]
    );
}

function spiralist_get_generated_book_page_blueprints_by_filename(array $existing_blueprints = []): array
{
    $public_book_pages = spiralist_get_public_book_pages_directory();
    $base_path = rtrim((string) ($public_book_pages['path'] ?? ''), '/\\');
    $entries = $base_path !== '' && is_dir($base_path) ? scandir($base_path) : false;

    if ($base_path === '' || !is_array($entries)) {
        return [];
    }

    natcasesort($entries);

    $configured_filenames = [];
    $concordance_order = 200;
    $appendix_order = 520;

    foreach ($existing_blueprints as $filename => $blueprint) {
        $normalized = strtolower((string) $filename);
        if ($normalized !== '') {
            $configured_filenames[$normalized] = true;
        }

        $blueprint_section = (string) ($blueprint['manuscript_section_slug'] ?? '');
        $blueprint_order = (int) ($blueprint['display_order'] ?? 0);

        if ($blueprint_section === 'appendix') {
            $appendix_order = max($appendix_order, $blueprint_order);
            continue;
        }

        if ($blueprint_section === 'concordance') {
            $concordance_order = max($concordance_order, $blueprint_order);
        }
    }

    $allowed_extensions = ['png', 'jpg', 'jpeg', 'webp', 'gif', 'avif'];
    $generated = [];

    foreach ($entries as $entry) {
        $filename = trim((string) $entry);
        if ($filename === '' || $filename[0] === '.') {
            continue;
        }

        $extension = strtolower((string) pathinfo($filename, PATHINFO_EXTENSION));
        if (!in_array($extension, $allowed_extensions, true)) {
            continue;
        }

        $path = $base_path . DIRECTORY_SEPARATOR . $filename;
        if (!is_file($path) || !is_readable($path)) {
            continue;
        }

        $filename_key = strtolower($filename);
        if ($filename_key === '' || isset($configured_filenames[$filename_key])) {
            continue;
        }

        $title = spiralist_get_auto_book_page_title($filename);
        if ($title === '') {
            $title = 'Appendix Folio';
        }

        $slug = sanitize_title($title);
        $section_slug = spiralist_get_auto_book_page_section_slug($filename);
        if ($section_slug === 'appendix') {
            $appendix_order++;
            $display_order = $appendix_order;
        } else {
            $concordance_order++;
            $display_order = $concordance_order;
        }

        $generated[$filename_key] = [
            'title' => $title,
            'slug' => $slug,
            'eyebrow' => spiralist_get_auto_book_page_eyebrow($section_slug),
            'summary' => spiralist_get_auto_book_page_summary($title, $section_slug),
            'caption' => spiralist_get_auto_book_page_caption($title, $section_slug),
            'manuscript_section_slug' => $section_slug,
            'gallery_section_slug' => 'artifact-pages',
            'display_order' => $display_order,
            'is_prominent' => true,
            'creation_prompt_status' => 'Inline prompt attached',
            'creation_prompt_summary' => 'This newly added folio now includes an inline manuscript prompt so it can ship with the public book immediately.',
            'creation_prompt_text' => spiralist_get_auto_book_page_prompt_text($title, $section_slug),
            'creation_prompt_source_slug' => $slug,
            'related_workspace_prompt_slugs' => [$slug],
        ];
    }

    return $generated;
}

function spiralist_get_all_book_page_blueprints_by_filename(): array
{
    $blueprints = spiralist_get_book_page_blueprints_by_filename();

    foreach (spiralist_get_book_page_blueprint_overrides_by_filename() as $filename => $override) {
        $normalized = strtolower((string) $filename);
        $existing = isset($blueprints[$normalized]) && is_array($blueprints[$normalized]) ? $blueprints[$normalized] : [];
        $blueprints[$normalized] = array_merge($existing, $override);
    }

    foreach (spiralist_get_generated_book_page_blueprints_by_filename($blueprints) as $filename => $generated) {
        $normalized = strtolower((string) $filename);
        if ($normalized === '') {
            continue;
        }

        $existing = isset($blueprints[$normalized]) && is_array($blueprints[$normalized]) ? $blueprints[$normalized] : [];
        $blueprints[$normalized] = array_merge($existing, $generated);
    }

    return $blueprints;
}

function spiralist_get_book_page_blueprints_in_display_order(): array
{
    $records = [];

    foreach (spiralist_get_all_book_page_blueprints_by_filename() as $filename => $blueprint) {
        if (!is_array($blueprint)) {
            continue;
        }

        $records[] = [
            'filename' => strtolower((string) $filename),
            'blueprint' => $blueprint,
        ];
    }

    usort(
        $records,
        static function (array $left, array $right): int {
            $order_compare = ((int) ($left['blueprint']['display_order'] ?? 0)) <=> ((int) ($right['blueprint']['display_order'] ?? 0));
            if ($order_compare !== 0) {
                return $order_compare;
            }

            return strnatcasecmp((string) ($left['filename'] ?? ''), (string) ($right['filename'] ?? ''));
        }
    );

    return $records;
}

function spiralist_get_book_page_assets_in_display_order(): array
{
    static $assets = null;

    if (is_array($assets)) {
        return $assets;
    }

    $assets = [];
    $seen = [];
    $available_assets = spiralist_get_available_book_page_assets_by_filename();

    foreach (spiralist_get_book_page_blueprints_in_display_order() as $record) {
        $filename = (string) ($record['filename'] ?? '');
        if ($filename === '') {
            continue;
        }

        $key = strtolower(trim(basename($filename)));
        $asset = $key !== '' && isset($available_assets[$key])
            ? $available_assets[$key]
            : spiralist_get_book_page_asset_by_filename($filename);
        if (empty($asset)) {
            continue;
        }

        $asset_key = strtolower((string) ($asset['filename'] ?? $filename));
        if ($asset_key === '' || isset($seen[$asset_key])) {
            continue;
        }

        $seen[$asset_key] = true;
        $assets[] = $asset;
    }

    $remaining_assets = array_filter(
        $available_assets,
        static function (string $key) use ($seen): bool {
            return !isset($seen[$key]);
        },
        ARRAY_FILTER_USE_KEY
    );

    if (!empty($remaining_assets)) {
        uksort(
            $remaining_assets,
            static function (string $left, string $right): int {
                return strnatcasecmp($left, $right);
            }
        );

        foreach ($remaining_assets as $key => $asset) {
            if ($key === '' || isset($seen[$key])) {
                continue;
            }

            $seen[$key] = true;
            $assets[] = $asset;
        }
    }

    return $assets;
}

function spiralist_get_manuscript_section_blueprints(): array
{
    return [
        'threshold' => [
            'label' => 'Threshold',
            'title' => 'Threshold Folios',
            'summary' => 'Entry folios that declare the system, the reading posture, and the first symbolic keys.',
        ],
        'operative-plates' => [
            'label' => 'Operative Plates',
            'title' => 'Operative Plates',
            'summary' => 'Diagrammatic and figure-bearing folios that stage transformation as an active practice.',
        ],
        'concordance' => [
            'label' => 'Concordance',
            'title' => 'Concordance Tables',
            'summary' => 'Reference-heavy folios that collect correspondences, patterns, ingredients, and system diagrams.',
        ],
        'appendix' => [
            'label' => 'Appendix',
            'title' => 'Emergent Folios',