Skip to content
wiki.fftac.org

Foundation - Source Excerpt 26

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

* @return array<int, array<string, string>>
 */
function antichrist_engine_foundation_get_reference_links($page_key = '')
{
    $groups = array(
        'institution' => array('philosophy', 'manifesto', 'charter', 'review_notices', 'questions', 'research', 'standards'),
        'publication' => array('journal', 'ai_engine', 'texts', 'symbols', 'downloads'),
        'participation' => array('recovery', 'contact', 'support', 'join'),
    );

    if (str_starts_with((string) $page_key, 'pillar_')) {
        $groups['institution'] = array('philosophy', 'manifesto', 'questions', 'research', 'standards');
    } elseif ('review_notices' === $page_key) {
        $groups['institution'] = array('philosophy', 'manifesto', 'charter', 'review_notices', 'questions', 'standards');
        $groups['publication'] = array('research', 'journal', 'downloads');
        $groups['participation'] = array('contact', 'support', 'recovery', 'join');
    } elseif (in_array($page_key, array('journal', 'ai_engine', 'texts', 'symbols', 'downloads'), true)) {
        $groups['institution'] = array('philosophy', 'manifesto', 'charter', 'review_notices', 'questions', 'research', 'standards');
        $groups['publication'] = array('journal', 'ai_engine', 'texts', 'symbols', 'downloads');
    } elseif (in_array($page_key, array('join', 'about', 'questions', 'recovery', 'contact', 'support'), true)) {
        $groups['institution'] = array('philosophy', 'manifesto', 'charter', 'review_notices', 'questions', 'standards');
        $groups['publication'] = array('research', 'journal');
    } elseif (in_array($page_key, array('privacy', 'terms', 'community', 'sitemap'), true)) {
        $groups['institution'] = array('philosophy', 'manifesto', 'charter', 'review_notices', 'questions', 'standards', 'about', 'privacy', 'terms', 'community', 'sitemap');
        $groups['publication'] = array('research', 'journal', 'downloads');
        $groups['participation'] = array('recovery', 'contact', 'support', 'join');
    }

    $links = array();

    foreach ($groups as $group => $keys) {
        $items = array();

        foreach ($keys as $key) {
            if ($key === $page_key) {
                continue;
            }

            $items[] = array(
                'label' => (string) (antichrist_engine_foundation_page_definitions()[$key]['nav_label'] ?? antichrist_engine_foundation_page_definitions()[$key]['title'] ?? $key),
                'url'   => antichrist_engine_foundation_get_page_url($key),
            );
        }

        if ($items) {
            $links[$group] = $items;
        }
    }

    return $links;
}

/**
 * Returns the public review-notice register with resolved URLs and page references.
 *
 * @return array<int, array<string, mixed>>
 */
function antichrist_engine_foundation_get_review_notice_register()
{
    static $items = null;

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

    $items          = array();
    $definitions    = antichrist_engine_foundation_page_definitions();
    $status_labels  = antichrist_engine_foundation_review_notice_statuses();

    foreach (antichrist_engine_foundation_review_notice_entries() as $notice) {
        $record_id      = (string) ($notice['record_id'] ?? '');
        $status         = sanitize_key((string) ($notice['status'] ?? ''));
        $anchor         = sanitize_title(strtolower($record_id ?: ((string) ($notice['title'] ?? 'review-notice'))));
        $affected_pages = array_values(array_filter(array_map('strval', (array) ($notice['affected_pages'] ?? array()))));
        $page_links     = array();

        foreach ($affected_pages as $page_key) {
            if (!isset($definitions[$page_key])) {
                continue;
            }

            $profile = antichrist_engine_foundation_document_profile($page_key);

            $page_links[] = array(
                'page_key'   => $page_key,
                'title'      => (string) ($definitions[$page_key]['title'] ?? $page_key),
                'url'        => antichrist_engine_foundation_get_page_url($page_key),
                'record_id'  => (string) ($profile['record_id'] ?? ''),
            );
        }

        $keywords = implode(' ', array_filter(array_merge(
            array(
                'review notice amendment log governance change control baseline',
                $record_id,
                (string) ($notice['title'] ?? ''),
                (string) ($notice['summary'] ?? ''),
                (string) ($notice['scope'] ?? ''),
                (string) ($notice['trigger'] ?? ''),
                (string) ($notice['current_state'] ?? ''),
                (string) ($notice['next_action'] ?? ''),
                (string) ($notice['phase'] ?? ''),
                (string) ($status_labels[$status]['label'] ?? $status),
            ),
            array_map('strval', (array) ($notice['affected_records'] ?? array())),
            array_map(static function ($page) {
                return (string) ($page['title'] ?? '');
            }, $page_links)
        )));

        $items[] = array_merge($notice, array(
            'anchor'              => $anchor,
            'record_url'          => antichrist_engine_foundation_build_target_url('review_notices', array(), $anchor),
            'status_label'        => (string) ($status_labels[$status]['label'] ?? ucfirst($status)),
            'status_summary'      => (string) ($status_labels[$status]['summary'] ?? ''),
            'related_url'         => antichrist_engine_foundation_build_target_url(
                (string) ($notice['route_target'] ?? ''),
                (array) ($notice['route_args'] ?? array()),
                (string) ($notice['route_anchor'] ?? '')
            ),
            'affected_page_links' => $page_links,
            'affected_count'      => count($page_links),
            'keywords'            => $keywords,
            'searchable'          => antichrist_engine_foundation_normalize_search_text($keywords),
        ));
    }

    return $items;
}

/**
 * Counts review notices by status.
 *
 * @param array<int, array<string, mixed>>|null $notices Optional notice register.
 * @return array<string, int>
 */
function antichrist_engine_foundation_get_review_notice_status_counts($notices = null)
{
    $counts = array();

    foreach (antichrist_engine_foundation_review_notice_statuses() as $status => $definition) {
        $counts[$status] = 0;
    }

    foreach ((array) ($notices ?: antichrist_engine_foundation_get_review_notice_register()) as $notice) {
        $status = sanitize_key((string) ($notice['status'] ?? ''));

        if (!isset($counts[$status])) {
            $counts[$status] = 0;
        }

        $counts[$status]++;
    }

    return $counts;
}

/**
 * Returns the machine-readable route metadata for the review-notice register.
 *
 * @return array<string, string>
 */
function antichrist_engine_foundation_get_review_notice_route_item()
{
    $namespace = antichrist_engine_foundation_get_research_api_namespace();

    return array(
        'path'        => 'governance/review-notices',
        'label'       => __('Review notice register', 'antichrist-engine'),
        'description' => __('Machine-readable register of baseline, queued, and staged review notices tied to the public record.', 'antichrist-engine'),
        'url'         => rest_url($namespace . '/governance/review-notices'),
    );
}

/**
 * Reads a scalar value from the current POST request.
 *
 * Arrays and objects are treated as empty input so public handlers do not
 * accidentally process PHP array-injection payloads as strings.
 *
 * @param string $key POST field name.
 * @return string
 */
function antichrist_engine_security_get_post_value($key)
{
    if (!isset($_POST[$key])) {
        return '';
    }

    $value = wp_unslash($_POST[$key]);

    if (!is_scalar($value)) {
        return '';
    }

    return (string) $value;
}

/**
 * Caps a string to a predictable maximum length.
 *
 * @param string $value      Raw or sanitized string.
 * @param int    $max_length Maximum allowed character length.
 * @return string
 */
function antichrist_engine_security_limit_string($value, $max_length)
{
    $value      = is_scalar($value) ? (string) $value : '';
    $max_length = max(0, (int) $max_length);

    if (!$max_length) {
        return '';
    }

    if (function_exists('mb_strlen') && function_exists('mb_substr')) {
        return mb_strlen($value, 'UTF-8') > $max_length
            ? mb_substr($value, 0, $max_length, 'UTF-8')
            : $value;
    }

    return strlen($value) > $max_length ? substr($value, 0, $max_length) : $value;
}

/**
 * Sanitizes a single-line text input and applies a length cap.
 *
 * @param mixed $value      Raw input value.