Skip to content
wiki.fftac.org

Foundation - Source Excerpt 37

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

$lane_slugs = array_values(array_unique(array_filter(array(
                $category,
                (string) ($related_claim['category'] ?? ''),
            ))));
            $lane_labels = array_values(array_map(static function ($lane_slug) use ($claim_labels) {
                return (string) ($claim_labels[$lane_slug] ?? ucwords(str_replace('-', ' ', $lane_slug)));
            }, $lane_slugs));

            $edges[] = array(
                'from'                => $pair[0],
                'to'                  => $pair[1],
                'type'                => 'related',
                'weight'              => (int) ($related_claim['score'] ?? 1),
                'shared_source_count' => (int) ($related_claim['shared_source_count'] ?? 0),
                'shared_terms'        => array_values((array) ($related_claim['shared_terms'] ?? array())),
                'same_category'       => !empty($related_claim['same_category']),
                'same_verdict'        => !empty($related_claim['same_verdict']),
                'same_evidence'       => !empty($related_claim['same_evidence']),
                'lane_slugs'          => $lane_slugs,
                'lane_labels'         => $lane_labels,
            );
            $relation_edges++;

            $primary_claim = $claim_lookup[$pair[0]] ?? array();
            $secondary_claim = $claim_lookup[$pair[1]] ?? array();
            $claim_bridges[] = array(
                'id'                    => 'bridge-' . sanitize_title(implode(' ', $pair)),
                'score'                 => (int) ($related_claim['score'] ?? 1),
                'shared_source_count'   => (int) ($related_claim['shared_source_count'] ?? 0),
                'shared_terms'          => array_values((array) ($related_claim['shared_terms'] ?? array())),
                'shared_source_records' => array_values((array) ($related_claim['shared_source_records'] ?? array())),
                'same_category'         => !empty($related_claim['same_category']),
                'same_verdict'          => !empty($related_claim['same_verdict']),
                'same_evidence'         => !empty($related_claim['same_evidence']),
                'lane_slugs'            => $lane_slugs,
                'lane_labels'           => $lane_labels,
                'primary_record_id'     => (string) ($primary_claim['record_id'] ?? $pair[0]),
                'primary_title'         => (string) ($primary_claim['title'] ?? ''),
                'primary_url'           => (string) ($primary_claim['record_url'] ?? $primary_claim['research_url'] ?? ''),
                'secondary_record_id'   => (string) ($secondary_claim['record_id'] ?? $pair[1]),
                'secondary_title'       => (string) ($secondary_claim['title'] ?? ''),
                'secondary_url'         => (string) ($secondary_claim['record_url'] ?? $secondary_claim['research_url'] ?? ''),
                'searchable'            => antichrist_engine_foundation_normalize_search_text(implode(' ', array_filter(array(
                    $pair[0],
                    $pair[1],
                    (string) ($primary_claim['title'] ?? ''),
                    (string) ($secondary_claim['title'] ?? ''),
                    implode(' ', (array) ($related_claim['shared_terms'] ?? array())),
                    implode(' ', array_map(static function ($source) {
                        return trim((string) ($source['record_id'] ?? '') . ' ' . (string) ($source['title'] ?? ''));
                    }, (array) ($related_claim['shared_source_records'] ?? array()))),
                    implode(' ', $lane_labels),
                )))),
            );
        }
    }

    foreach ($claim_lanes as $category => $lane) {
        usort($lane['claim_references'], static function ($left, $right) {
            if ((int) $left['source_count'] === (int) $right['source_count']) {
                if ((int) $left['episode_count'] === (int) $right['episode_count']) {
                    return strcasecmp((string) $left['title'], (string) $right['title']);
                }

                return (int) $right['episode_count'] <=> (int) $left['episode_count'];
            }

            return (int) $right['source_count'] <=> (int) $left['source_count'];
        });

        arsort($lane['source_counts']);

        $top_sources = array();

        foreach ($lane['source_counts'] as $source_record_id => $count) {
            if (!isset($source_hub_lookup[$source_record_id])) {
                continue;
            }

            $top_sources[] = array(
                'record_id'      => (string) $source_hub_lookup[$source_record_id]['record_id'],
                'title'          => (string) ($source_hub_lookup[$source_record_id]['title'] ?? ''),
                'record_url'     => (string) ($source_hub_lookup[$source_record_id]['record_url'] ?? $source_hub_lookup[$source_record_id]['research_url'] ?? ''),
                'citation_count' => (int) $count,
            );
        }

        $verdict_snapshot = array();

        foreach ((array) $lane['verdict_counts'] as $verdict_slug => $count) {
            $verdict_snapshot[] = array(
                'slug'  => (string) $verdict_slug,
                'label' => (string) ($verdicts[$verdict_slug]['label'] ?? ucwords(str_replace('-', ' ', (string) $verdict_slug))),
                'count' => (int) $count,
            );
        }

        usort($verdict_snapshot, static function ($left, $right) {
            if ((int) $left['count'] === (int) $right['count']) {
                return strcasecmp((string) $left['label'], (string) $right['label']);
            }

            return (int) $right['count'] <=> (int) $left['count'];
        });

        $claim_lanes[$category] = array(
            'slug'             => (string) $lane['slug'],
            'label'            => (string) $lane['label'],
            'claim_count'      => (int) $lane['claim_count'],
            'source_total'     => count((array) $lane['source_ids']),
            'citation_edges'   => (int) $lane['citation_edges'],
            'url'              => (string) $lane['url'],
            'top_claims'       => array_slice((array) $lane['claim_references'], 0, 3),
            'top_sources'      => array_slice($top_sources, 0, 3),
            'verdict_snapshot' => array_slice($verdict_snapshot, 0, 3),
        );
    }

    $claim_lanes = array_values($claim_lanes);

    usort($source_hubs, static function ($left, $right) {
        if ((int) $left['citation_count'] === (int) $right['citation_count']) {
            return strcasecmp((string) $left['title'], (string) $right['title']);
        }

        return (int) $right['citation_count'] <=> (int) $left['citation_count'];
    });

    usort($claim_lanes, static function ($left, $right) {
        if ((int) $left['claim_count'] === (int) $right['claim_count']) {
            return strcasecmp((string) $left['label'], (string) $right['label']);
        }

        return (int) $right['claim_count'] <=> (int) $left['claim_count'];
    });

    usort($claim_bridges, static function ($left, $right) {
        if ((int) $left['score'] === (int) $right['score']) {
            if ((int) $left['shared_source_count'] === (int) $right['shared_source_count']) {
                $left_title = (string) $left['primary_title'] . ' ' . (string) $left['secondary_title'];
                $right_title = (string) $right['primary_title'] . ' ' . (string) $right['secondary_title'];

                return strcasecmp($left_title, $right_title);
            }

            return (int) $right['shared_source_count'] <=> (int) $left['shared_source_count'];
        }

        return (int) $right['score'] <=> (int) $left['score'];
    });

    $map = array(
        'summary' => array(
            'claim_nodes'        => count($claims),
            'source_nodes'       => count($source_hubs),
            'citation_edges'     => $citation_edges,
            'relationship_edges' => $relation_edges,
            'lane_total'         => count($claim_lanes),
            'bridge_total'       => count($claim_bridges),
        ),
        'source_hubs'    => array_values($source_hubs),
        'claim_lanes'    => $claim_lanes,
        'claim_bridges'  => array_values($claim_bridges),
        'nodes'          => $nodes,
        'edges'          => $edges,
    );

    return $map;
}

/**
 * Builds a lookup table for focused research-record views.
 *
 * @return array<string, array<string, mixed>>
 */
function antichrist_engine_foundation_get_research_record_lookup()
{
    static $records = null;

    if (null !== $records) {
        return $records;
    }

    $records = array();

    foreach (antichrist_engine_foundation_get_enriched_briefings() as $briefing) {