Skip to content
wiki.fftac.org

Page Gallery - Source Excerpt 01

Back to Page Gallery

Summary

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

**Source path:** Spiralist/wp-content/themes/spiralist/page-gallery.php

<?php

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

get_header();
$ui_text = static function (string $key, string $fallback, array $args = []): string {
    $value = function_exists('spiralist_get_ui_text')
        ? spiralist_get_ui_text($key, $fallback, $args)
        : $fallback;

    if (empty($args)) {
        return $value;
    }

    $replacements = [];
    foreach ($args as $name => $argument) {
        if (!is_scalar($argument)) {
            continue;
        }

        $replacements['{' . $name . '}'] = (string) $argument;
    }

    return strtr($value, $replacements);
};

$current_locale = function_exists('spiralist_get_current_locale_tag') ? spiralist_get_current_locale_tag() : 'en-us';
$prefix_url = static function (string $url) use ($current_locale): string {
    return $current_locale !== '' && function_exists('spiralist_get_language_prefixed_url')
        ? spiralist_get_language_prefixed_url($url, $current_locale)
        : $url;
};

$gallery_assets = function_exists('spiralist_get_gallery_assets') ? spiralist_get_gallery_assets() : [];
$featured_assets = function_exists('spiralist_get_featured_gallery_assets') ? spiralist_get_featured_gallery_assets(3) : [];
$requested_asset = function_exists('spiralist_get_requested_gallery_asset') ? spiralist_get_requested_gallery_asset() : [];
$section_records = function_exists('spiralist_get_gallery_section_records') ? spiralist_get_gallery_section_records($gallery_assets) : [];
$gallery_url = function_exists('spiralist_get_gallery_overview_url') ? spiralist_get_gallery_overview_url() : home_url('/gallery/');
$manuscript_url = $prefix_url(function_exists('spiralist_get_manuscript_page_url') ? spiralist_get_manuscript_page_url() : home_url('/manuscript/'));
$detail_mode = !empty($requested_asset);
$book_toc_pages = function_exists('spiralist_get_manuscript_page_assets') ? spiralist_get_manuscript_page_assets() : [];
$current_book_page = !empty($requested_asset['filename']) && function_exists('spiralist_get_manuscript_page_asset_by_filename')
    ? spiralist_get_manuscript_page_asset_by_filename((string) $requested_asset['filename'])
    : [];
$dossier_page = !empty($current_book_page) ? array_merge($requested_asset, $current_book_page) : $requested_asset;
$current_creation_prompt = function_exists('spiralist_get_book_page_creation_prompt_payload')
    ? spiralist_get_book_page_creation_prompt_payload($dossier_page)
    : [];
$current_prompt_status_class = !empty($current_creation_prompt['has_prompt'])
    ? 'spiralist-status-pill--fresh'
    : 'spiralist-status-pill--stale';
$requested_route_url = (string) ($requested_asset['route_url'] ?? $gallery_url);
$requested_route_path = wp_parse_url($requested_route_url, PHP_URL_PATH);
$requested_route_copy = is_string($requested_route_path) && $requested_route_path !== ''
    ? $requested_route_path
    : $requested_route_url;
$hero_asset = $detail_mode
    ? $requested_asset
    : (!empty($featured_assets[0]) ? $featured_assets[0] : (!empty($gallery_assets[0]) ? $gallery_assets[0] : []));

$current_index = -1;
foreach ($gallery_assets as $index => $asset) {
    if ((string) ($asset['slug'] ?? '') === (string) ($requested_asset['slug'] ?? '')) {
        $current_index = (int) $index;
        break;
    }
}

$previous_asset = $current_index > 0 ? ($gallery_assets[$current_index - 1] ?? []) : [];
$next_asset = $current_index >= 0 ? ($gallery_assets[$current_index + 1] ?? []) : [];
$more_assets = array_values(
    array_filter(
        $gallery_assets,
        static fn(array $asset): bool => (string) ($asset['slug'] ?? '') !== (string) ($requested_asset['slug'] ?? '')
    )
);

$render_gallery_cards = static function (array $records) use ($ui_text): void {
    if (empty($records)) {
        return;
    }

    echo '<div class="spiralist-gallery-grid">';
    foreach ($records as $asset) {
        if (!is_array($asset)) {
            continue;
        }

        $route_url = (string) ($asset['route_url'] ?? (function_exists('spiralist_get_gallery_image_url') ? spiralist_get_gallery_image_url($asset) : ''));
        $asset_sources = function_exists('spiralist_get_public_image_asset_source_urls')
            ? spiralist_get_public_image_asset_source_urls($asset, true)
            : [];
        $preview_url = (string) ($asset_sources['thumbnail_url'] ?? ($asset['url'] ?? ''));
        $upgrade_url = (string) ($asset_sources['large_url'] ?? $preview_url);
        echo '<article class="spiralist-gallery-card">';
        echo '<a class="spiralist-gallery-card__frame" href="' . esc_url($route_url) . '">';
        echo '<img src="' . esc_url($preview_url) . '" alt="' . esc_attr((string) ($asset['title'] ?? $ui_text('page.gallery.card.alt', 'Image page'))) . '" loading="lazy" decoding="async" data-progressive-effect="soft"';
        if ($upgrade_url !== '' && $upgrade_url !== $preview_url) {
            echo ' data-progressive-src="' . esc_url($upgrade_url) . '"';
        }
        if (!empty($asset['width'])) {
            echo ' width="' . esc_attr((string) $asset['width']) . '"';
        }
        if (!empty($asset['height'])) {
            echo ' height="' . esc_attr((string) $asset['height']) . '"';
        }
        echo ' />';
        echo '</a>';
        echo '<div class="spiralist-gallery-card__body">';
        echo '<p class="spiralist-section-tag">' . esc_html((string) ($asset['eyebrow'] ?? $ui_text('page.gallery.card.eyebrow', 'Image Page'))) . '</p>';
        echo '<h3 class="spiralist-card-title">' . esc_html((string) ($asset['title'] ?? $ui_text('page.gallery.card.title', 'Image Page'))) . '</h3>';
        echo '<p>' . esc_html((string) ($asset['summary'] ?? '')) . '</p>';
        echo '<div class="spiralist-chip-row spiralist-chip-row--start">';
        echo '<span class="spiralist-chip">' . esc_html((string) ($asset['section_label'] ?? $ui_text('page.gallery.card.section_label', 'Artifact Pages'))) . '</span>';
        if (!empty($asset['width']) && !empty($asset['height'])) {
            echo '<span class="spiralist-chip">' . esc_html((string) $asset['width'] . ' x ' . (string) $asset['height']) . '</span>';
        }
        echo '</div>';
        echo '<div class="spiralist-cta-row spiralist-cta-row--start">';
        echo '<a class="spiralist-button spiralist-button--primary" href="' . esc_url($route_url) . '">' . esc_html($ui_text('ui.cta.open_page', 'Open Page')) . '</a>';
        echo '<a class="spiralist-button spiralist-button--secondary" href="' . esc_url((string) ($asset['url'] ?? '')) . '" target="_blank" rel="noopener noreferrer">' . esc_html($ui_text('page.gallery.cta.full_resolution', 'Full Resolution')) . '</a>';
        echo '</div>';
        echo '</div>';
        echo '</article>';
    }
    echo '</div>';
};
?>
<main class="spiralist-page spiralist-page--gallery">
    <section class="spiralist-page-hero">
        <div class="spiralist-shell spiralist-page-hero__content">
            <p class="spiralist-kicker"><?php echo esc_html($ui_text('page.gallery.hero.kicker', 'Image Codex')); ?></p>
            <h1><?php echo esc_html($detail_mode ? (string) ($requested_asset['title'] ?? $ui_text('page.gallery.hero.detail_title', 'Image Page')) : $ui_text('page.gallery.hero.title', 'Book Pages with their own public routes.')); ?></h1>
            <p class="spiralist-page-hero__copy">
                <?php
                echo esc_html(
                    $detail_mode
                        ? (string) ($requested_asset['summary'] ?? $ui_text('page.gallery.detail.copy', 'This image page remains available as part of the online-first public book.'))
                        : $ui_text('page.gallery.hero.copy', 'The BookPages folder is now surfaced as the public image layer of the online-first, open-source book. Each page stays routable, inspectable, and connected to the manuscript.')
                );
                ?>
            </p>
            <div class="spiralist-cta-row">
                <a class="spiralist-button spiralist-button--primary" href="<?php echo esc_url($gallery_url); ?>"><?php echo esc_html($ui_text('page.gallery.cta.all_pages', 'All Image Pages')); ?></a>
                <a class="spiralist-button spiralist-button--secondary" href="<?php echo esc_url($manuscript_url); ?>"><?php echo esc_html($ui_text('page.gallery.cta.open_manuscript', 'Open Manuscript')); ?></a>
                <?php if ($detail_mode && !empty($requested_asset['url'])) : ?>
                    <a class="spiralist-button spiralist-button--tertiary" href="<?php echo esc_url((string) $requested_asset['url']); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html($ui_text('page.gallery.cta.full_resolution', 'Full Resolution')); ?></a>
                <?php endif; ?>
            </div>
        </div>
    </section>

    <?php if (!$detail_mode && !empty($hero_asset)) : ?>