Skip to content
wiki.fftac.org

Foundation - Source Excerpt 31

Back to Foundation

Summary

This source excerpt preserves a bounded section of Anti-Christ.org/wp-content/plugins/fftac-foundation-core/inc/foundation.php so readers can inspect the evidence without opening the full source file.

**Source path:** Anti-Christ.org/wp-content/plugins/fftac-foundation-core/inc/foundation.php

'atlas_url'          => (string) ($claim['atlas_url'] ?? ''),
        );
    }

    return $rows;
}

/**
 * Returns normalized rows for the timeline CSV export.
 *
 * @return array<int, array<string, scalar>>
 */
function antichrist_engine_foundation_get_research_timeline_export_rows()
{
    $rows = array();

    foreach (antichrist_engine_foundation_get_enriched_timeline_entries() as $entry) {
        $rows[] = array(
            'record_id'   => (string) ($entry['record_id'] ?? ''),
            'year'        => (string) ($entry['year'] ?? ''),
            'title'       => (string) ($entry['title'] ?? ''),
            'category'    => (string) ($entry['category'] ?? ''),
            'tag_count'   => (int) ($entry['tag_count'] ?? 0),
            'tags'        => implode('|', array_map('strval', (array) ($entry['tags'] ?? array()))),
            'summary'     => (string) ($entry['summary'] ?? ''),
            'record_url'  => (string) ($entry['record_request_url'] ?? ''),
            'atlas_url'   => (string) ($entry['atlas_url'] ?? ''),
        );
    }

    return $rows;
}

/**
 * Returns normalized rows for the projection ledger CSV export.
 *
 * @return array<int, array<string, scalar>>
 */
function antichrist_engine_foundation_get_research_projection_export_rows()
{
    $rows = array();

    foreach (antichrist_engine_foundation_get_projection_ledger_entries() as $entry) {
        $rows[] = array(
            'record_id'         => (string) ($entry['record_id'] ?? ''),
            'claim_record_id'   => (string) ($entry['claim_record_id'] ?? ''),
            'claim_title'       => (string) ($entry['claim_title'] ?? ''),
            'claim_category'    => (string) ($entry['claim_category'] ?? ''),
            'claim_verdict'     => (string) ($entry['claim_verdict'] ?? ''),
            'claim_evidence'    => (string) ($entry['claim_evidence'] ?? ''),
            'period'            => (string) ($entry['period'] ?? ''),
            'source'            => (string) ($entry['source'] ?? ''),
            'status'            => (string) ($entry['status'] ?? ''),
            'summary'           => (string) ($entry['summary'] ?? ''),
            'source_record_ids' => implode('|', array_map(static function ($source_reference) {
                return (string) ($source_reference['record_id'] ?? '');
            }, (array) ($entry['source_references'] ?? array()))),
            'record_url'        => (string) ($entry['record_request_url'] ?? ''),
            'claim_record_url'  => (string) ($entry['claim_record_request_url'] ?? ''),
            'atlas_url'         => (string) ($entry['atlas_url'] ?? ''),
        );
    }

    return $rows;
}

/**
 * Returns normalized rows for the sources CSV export.
 *
 * @return array<int, array<string, scalar>>
 */
function antichrist_engine_foundation_get_research_source_export_rows()
{
    $rows = array();

    foreach (antichrist_engine_foundation_get_research_api_sources() as $source) {
        $rows[] = array(
            'record_id'        => (string) ($source['record_id'] ?? ''),
            'title'            => (string) ($source['title'] ?? ''),
            'publisher'        => (string) ($source['publisher'] ?? ''),
            'group'            => (string) ($source['group'] ?? ''),
            'citation_count'   => (int) ($source['citation_count'] ?? 0),
            'claim_record_ids' => implode('|', array_map(static function ($claim_reference) {
                return (string) ($claim_reference['record_id'] ?? '');
            }, (array) ($source['claim_references'] ?? array()))),
            'source_url'       => (string) ($source['url'] ?? ''),
            'record_url'       => (string) ($source['record_request_url'] ?? ''),
            'atlas_url'        => (string) ($source['atlas_url'] ?? ''),
            'note'             => (string) ($source['note'] ?? ''),
        );
    }

    return $rows;
}

/**
 * Returns normalized record rows for NDJSON export.
 *
 * @return array<int, array<string, mixed>>
 */
function antichrist_engine_foundation_get_research_record_export_rows()
{
    $rows = array();

    foreach (antichrist_engine_foundation_get_research_record_lookup() as $record) {
        $type = (string) ($record['record_type'] ?? '');
        $rows[] = array(
            'record_id'   => (string) ($record['record_id'] ?? ''),
            'type'        => $type,
            'type_label'  => (string) ($record['type_label'] ?? ''),
            'title'       => (string) ($record['title'] ?? ''),
            'summary'     => (string) ($record['summary'] ?? $record['note'] ?? ''),
            'category'    => (string) ($record['category'] ?? ''),
            'year'        => (string) ($record['year'] ?? ''),
            'publisher'   => (string) ($record['publisher'] ?? ''),
            'format_meta' => implode(' / ', array_filter(array(
                $record['duration'] ?? '',
                $record['group'] ?? '',
                $record['period'] ?? '',
                $record['status'] ?? '',
            ))),
            'record_url'  => (string) ($record['record_request_url'] ?? ''),
            'atlas_url'   => (string) ($record['atlas_url'] ?? ''),
        );
    }

    usort($rows, static function ($left, $right) {
        if (($left['type'] ?? '') === ($right['type'] ?? '')) {
            return strcmp((string) ($left['record_id'] ?? ''), (string) ($right['record_id'] ?? ''));
        }

        return strcmp((string) ($left['type'] ?? ''), (string) ($right['type'] ?? ''));
    });

    return $rows;
}

/**
 * Returns a plain-text provenance note for research exports.
 *
 * @return string
 */
function antichrist_engine_foundation_get_research_export_provenance_text()
{
    $overview        = antichrist_engine_foundation_get_research_api_overview();
    $route_map       = antichrist_engine_foundation_get_research_api_route_map();
    $download_routes = antichrist_engine_foundation_get_research_export_download_route_map();
    $lines           = array(
        'Foundation For The Anti-Christ research export provenance',
        'Generated: ' . gmdate(DATE_ATOM),
        'Site: ' . home_url('/'),
        'Research page: ' . antichrist_engine_foundation_get_page_url('research'),
        'Counts:',
        '  Claims: ' . number_format_i18n((int) ($overview['counts']['claims'] ?? 0)),
        '  Timeline entries: ' . number_format_i18n((int) ($overview['counts']['timeline'] ?? 0)),
        '  Projection ledger entries: ' . number_format_i18n((int) ($overview['counts']['projections'] ?? 0)),
        '  Sources: ' . number_format_i18n((int) ($overview['counts']['sources'] ?? 0)),
        '  Briefings: ' . number_format_i18n((int) ($overview['counts']['briefings'] ?? 0)),
        'Primary JSON routes:',
        '  Overview: ' . ($route_map['overview'] ?? ''),
        '  Full export: ' . ($route_map['export'] ?? ''),
        '  Claims: ' . ($route_map['claims'] ?? ''),
        '  Timeline: ' . ($route_map['timeline'] ?? ''),
        '  Projection ledger: ' . ($route_map['projections'] ?? ''),
        '  Sources: ' . ($route_map['sources'] ?? ''),
        '  Connection map: ' . ($route_map['map'] ?? ''),
        'Download routes:',
        '  Claims CSV: ' . ($download_routes['claims_csv'] ?? ''),
        '  Timeline CSV: ' . ($download_routes['timeline_csv'] ?? ''),
        '  Projection ledger CSV: ' . ($download_routes['projections_csv'] ?? ''),
        '  Sources CSV: ' . ($download_routes['sources_csv'] ?? ''),
        '  Records NDJSON: ' . ($download_routes['records_ndjson'] ?? ''),
        'Attribution: Cite FFTAC record IDs and link back to anti-christ.org when reusing atlas exports.',
        'Note: These exports are generated from the live theme-backed atlas and do not replace future dedicated data-layer provenance.',
    );

    return implode("\n", $lines) . "\n";
}

/**
 * Returns a generated research download payload for a supported export slug.
 *
 * @param string $slug Export slug.
 * @return array<string, string>
 */
function antichrist_engine_foundation_get_research_export_download_payload($slug)
{
    $slug = sanitize_key((string) $slug);

    if ('claims_csv' === $slug) {
        return array(
            'filename'     => 'fftac-research-claims.csv',
            'content_type' => 'text/csv; charset=utf-8',
            'content'      => antichrist_engine_foundation_convert_rows_to_csv(antichrist_engine_foundation_get_research_claim_export_rows()),
        );
    }

    if ('timeline_csv' === $slug) {
        return array(
            'filename'     => 'fftac-research-timeline.csv',
            'content_type' => 'text/csv; charset=utf-8',