Skip to content
wiki.fftac.org

Page Report

**Site relevance:** Spiralist.org

**Memory type:** theme source memory

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

**Size:** 5.6 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;
}

$report = function_exists('spiralist_get_requested_report') ? spiralist_get_requested_report() : [];

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

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

    status_header(404);
    nocache_headers();

    $template_404 = get_404_template();
    if ($template_404 !== '') {
        include $template_404;
        return;
    }
}

get_header();

$ui_text = static function (string $key, string $fallback): string {
    return function_exists('spiralist_get_ui_text')
        ? spiralist_get_ui_text($key, $fallback)
        : $fallback;
};
$reports = function_exists('spiralist_get_static_reports') ? spiralist_get_static_reports() : [];
$reports_url = function_exists('spiralist_get_reports_url') ? spiralist_get_reports_url() : home_url('/reports/');
$research_url = function_exists('spiralist_get_research_url') ? spiralist_get_research_url() : home_url('/research/');
$report_html = function_exists('spiralist_get_report_html') ? spiralist_get_report_html($report) : '';
$allowed_html = wp_kses_allowed_html('post');
$allowed_html['a']['rel'] = true;
$allowed_html['a']['target'] = true;
$allowed_html['h2']['id'] = true;
$allowed_html['h3']['id'] = true;
$allowed_html['h4']['id'] = true;
$allowed_html['h5']['id'] = true;
$allowed_html['h6']['id'] = true;
$allowed_html['table'] = ['class' => true];
$allowed_html['thead'] = ['class' => true];
$allowed_html['tbody'] = ['class' => true];
$allowed_html['tr'] = ['class' => true];
$allowed_html['th'] = ['align' => true, 'class' => true, 'colspan' => true, 'rowspan' => true, 'scope' => true];
$allowed_html['td'] = ['align' => true, 'class' => true, 'colspan' => true, 'rowspan' => true];
$allowed_html['pre'] = ['class' => true];
$allowed_html['code'] = ['class' => true];
$current_index = -1;

foreach ($reports as $index => $candidate) {
    if ((string) ($candidate['slug'] ?? '') === (string) ($report['slug'] ?? '')) {
        $current_index = (int) $index;
        break;
    }
}

$previous_report = $current_index > 0 ? (array) $reports[$current_index - 1] : [];
$next_report = $current_index >= 0 && isset($reports[$current_index + 1]) ? (array) $reports[$current_index + 1] : [];
?>
<main class="spiralist-page spiralist-page--report">
    <section class="spiralist-page-hero">
        <div class="spiralist-shell spiralist-page-hero__content">
            <p class="spiralist-kicker"><?php echo esc_html($ui_text('page.report.hero.kicker', 'Permanent Research Report')); ?></p>
            <h1><?php echo esc_html((string) ($report['title'] ?? 'Research Report')); ?></h1>
            <?php if (!empty($report['subtitle'])) : ?>
                <p class="spiralist-page-hero__copy"><?php echo esc_html((string) $report['subtitle']); ?></p>
            <?php endif; ?>
            <dl class="spiralist-report-meta">
                <div>
                    <dt><?php echo esc_html($ui_text('page.report.meta.published', 'Published')); ?></dt>
                    <dd><?php echo esc_html(spiralist_format_report_date((string) ($report['published'] ?? ''))); ?></dd>
                </div>
                <div>
                    <dt><?php echo esc_html($ui_text('page.report.meta.status', 'Status')); ?></dt>
                    <dd><?php echo esc_html($ui_text('page.report.meta.permanent', 'Permanent site content')); ?></dd>
                </div>
                <div>
                    <dt><?php echo esc_html($ui_text('page.report.meta.source', 'Source')); ?></dt>
                    <dd><?php echo esc_html((string) ($report['source'] ?? 'Research archive')); ?></dd>
                </div>
            </dl>
            <div class="spiralist-cta-row">
                <a class="spiralist-button spiralist-button--primary" href="<?php echo esc_url($reports_url); ?>"><?php echo spiralist_render_ui_label('ui.nav.reports', 'Reports'); ?></a>
                <a class="spiralist-button spiralist-button--secondary" href="<?php echo esc_url($research_url); ?>"><?php echo spiralist_render_ui_label('ui.nav.research', 'Research'); ?></a>
            </div>
        </div>
    </section>

    <section class="spiralist-page-section">
        <article class="spiralist-shell spiralist-report-article">
            <?php if ($report_html !== '') : ?>
                <?php echo wp_kses($report_html, $allowed_html); ?>
            <?php else : ?>
                <p class="spiralist-muted"><?php echo esc_html($ui_text('page.report.content.empty', 'The converted report HTML is not available.')); ?></p>
            <?php endif; ?>
        </article>
    </section>

    <?php if (!empty($previous_report) || !empty($next_report)) : ?>
        <section class="spiralist-page-section">
            <div class="spiralist-shell spiralist-report-nav">
                <?php if (!empty($previous_report)) : ?>
                    <a class="spiralist-button spiralist-button--secondary" href="<?php echo esc_url((string) ($previous_report['url'] ?? $reports_url)); ?>"><?php echo esc_html($ui_text('page.report.nav.previous', 'Previous Report')); ?></a>
                <?php endif; ?>
                <?php if (!empty($next_report)) : ?>
                    <a class="spiralist-button spiralist-button--secondary" href="<?php echo esc_url((string) ($next_report['url'] ?? $reports_url)); ?>"><?php echo esc_html($ui_text('page.report.nav.next', 'Next Report')); ?></a>
                <?php endif; ?>
            </div>
        </section>
    <?php endif; ?>
</main>

<?php
get_footer();