Skip to content
wiki.fftac.org

Foundation - Source Excerpt 25

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

'loc' => $loc,
        );

        if ($lastmod) {
            $entry['lastmod'] = $lastmod;
        }

        $entries[] = $entry;
    }

    return $entries;
}

/**
 * Returns the number of XML sitemap pages needed for focused records.
 *
 * @return int
 */
function antichrist_engine_foundation_get_research_record_sitemap_max_pages()
{
    if (!antichrist_engine_foundation_allows_public_indexing()) {
        return 0;
    }

    $max_urls = function_exists('wp_sitemaps_get_max_urls') ? (int) wp_sitemaps_get_max_urls('fftac-research-record') : 2000;
    $max_urls = max(1, $max_urls);

    return (int) ceil(count(antichrist_engine_foundation_get_research_record_lookup()) / $max_urls);
}

/**
 * Registers focused research records with the WordPress XML sitemap index.
 *
 * @return void
 */
function antichrist_engine_foundation_register_research_record_sitemap_provider()
{
    if (!function_exists('wp_register_sitemap_provider') || !class_exists('WP_Sitemaps_Provider')) {
        return;
    }

    if (!class_exists('Antichrist_Engine_Foundation_Research_Record_Sitemap_Provider', false)) {
        class Antichrist_Engine_Foundation_Research_Record_Sitemap_Provider extends WP_Sitemaps_Provider
        {
            public function __construct()
            {
                $this->name        = 'fftac-research-records';
                $this->object_type = 'fftac-research-record';
            }

            public function get_url_list($page_num, $object_subtype = '')
            {
                return antichrist_engine_foundation_get_research_record_sitemap_url_entries((int) $page_num);
            }

            public function get_max_num_pages($object_subtype = '')
            {
                return antichrist_engine_foundation_get_research_record_sitemap_max_pages();
            }
        }
    }

    wp_register_sitemap_provider(
        'fftac-research-records',
        new Antichrist_Engine_Foundation_Research_Record_Sitemap_Provider()
    );
}
add_action('wp_sitemaps_init', 'antichrist_engine_foundation_register_research_record_sitemap_provider');

/**
 * Builds JSON-LD graphs for the current view.
 *
 * @return array<int, array<string, mixed>>
 */
function antichrist_engine_foundation_get_structured_data_graphs()
{
    $identity         = antichrist_engine_foundation_identity();
    $breadcrumbs      = antichrist_engine_foundation_get_breadcrumb_items();
    $current_url      = antichrist_engine_foundation_get_current_request_url();
    $site_url         = home_url('/');
    $organization_id  = $site_url . '#organization';
    $website_id       = $site_url . '#website';
    $webpage_id       = $current_url . '#webpage';
    $description      = antichrist_engine_foundation_get_meta_description();
    $document_title   = antichrist_engine_foundation_get_contextual_document_title(wp_get_document_title());
    $current_page_key = is_page() ? antichrist_engine_foundation_get_page_key_by_id(get_queried_object_id()) : '';
    $active_record    = antichrist_engine_foundation_get_active_research_record();
    $graphs           = array(
        array(
            '@type'       => 'Organization',
            '@id'         => $organization_id,
            'name'        => $identity['name'],
            'url'         => $site_url,
            'description' => $identity['summary'],
            'logo'        => get_template_directory_uri() . '/assets/images/hero-sigil.svg',
        ),
        array(
            '@type'       => 'WebSite',
            '@id'         => $website_id,
            'url'         => $site_url,
            'name'        => antichrist_engine_foundation_get_site_name(),
            'description' => antichrist_engine_foundation_get_site_description(),
            'publisher'   => array('@id' => $organization_id),
            'potentialAction' => array(
                '@type'       => 'SearchAction',
                'target'      => array(
                    '@type'       => 'EntryPoint',
                    'urlTemplate' => home_url('/?s={search_term_string}'),
                ),
                'query-input' => 'required name=search_term_string',
            ),
        ),
    );

    $breadcrumb_id = '';

    if (count($breadcrumbs) > 1) {
        $breadcrumb_id    = $current_url . '#breadcrumb';
        $breadcrumb_items = array();

        foreach ($breadcrumbs as $index => $item) {
            $breadcrumb_items[] = array(
                '@type'    => 'ListItem',
                'position' => $index + 1,
                'name'     => $item['label'],
                'item'     => $item['url'] ?: $current_url,
            );
        }

        $graphs[] = array(
            '@type'           => 'BreadcrumbList',
            '@id'             => $breadcrumb_id,
            'itemListElement' => $breadcrumb_items,
        );
    }

    $webpage_type = 'WebPage';

    if (is_search()) {
        $webpage_type = 'SearchResultsPage';
    } elseif (is_home() || is_archive()) {
        $webpage_type = 'CollectionPage';
    } elseif ($current_page_key) {
        $webpage_type = antichrist_engine_foundation_get_page_webpage_type($current_page_key, $webpage_type);
    }

    $webpage = array(
        '@type'       => $webpage_type,
        '@id'         => $webpage_id,
        'url'         => $current_url,
        'name'        => $document_title,
        'description' => $description,
        'isPartOf'    => array('@id' => $website_id),
        'publisher'   => array('@id' => $organization_id),
    );

    if ($breadcrumb_id) {
        $webpage['breadcrumb'] = array('@id' => $breadcrumb_id);
    }

    if ($active_record) {
        $webpage['mainEntity'] = array(
            '@id' => $current_url . '#record',
        );
    } elseif ($current_page_key) {
        $page_main_entity_id = antichrist_engine_foundation_get_page_main_entity_id($current_page_key, $current_url, $organization_id);

        if ($page_main_entity_id) {
            $webpage['mainEntity'] = array('@id' => $page_main_entity_id);
        }
    }

    if ('support' === $current_page_key) {
        $support_destination = antichrist_engine_foundation_get_support_destination();

        if (!empty($support_destination['url'])) {
            $webpage['potentialAction'] = array('@id' => $current_url . '#donate');
        }
    }

    $graphs[] = $webpage;

    if ($current_page_key) {
        $graphs = array_merge(
            $graphs,
            antichrist_engine_foundation_get_page_structured_data_graphs(
                $current_page_key,
                $current_url,
                $webpage_id,
                $website_id,
                $organization_id,
                $description
            )
        );
    }

    if (is_singular('post')) {
        $image_url = get_the_post_thumbnail_url(get_the_ID(), 'full');
        $author_id = (int) get_post_field('post_author', get_the_ID());
        $article   = array(
            '@type'            => 'BlogPosting',
            '@id'              => $current_url . '#article',
            'headline'         => get_the_title(),
            'description'      => $description,
            'datePublished'    => get_post_time(DATE_ATOM, true, get_the_ID()),
            'dateModified'     => get_post_modified_time(DATE_ATOM, true, get_the_ID()),
            'mainEntityOfPage' => array('@id' => $webpage_id),
            'author'           => array(
                '@type' => 'Person',
                'name'  => get_the_author_meta('display_name', $author_id),
            ),
            'publisher'        => array('@id' => $organization_id),
        );

        if ($image_url) {
            $article['image'] = array($image_url);
        }

        $graphs[] = $article;
    }

    if ($active_record) {
        $graphs[] = antichrist_engine_foundation_get_research_record_structured_data_graph(
            $active_record,
            $current_url,
            $webpage_id,
            $organization_id,
            $description
        );
    }

    return $graphs;
}

/**
 * Prints structured data for the current view.
 *
 * @return void
 */
function antichrist_engine_foundation_print_structured_data()
{
    $graphs = antichrist_engine_foundation_get_structured_data_graphs();

    if (!$graphs) {
        return;
    }

    echo '<script type="application/ld+json">' . wp_json_encode(array(
        '@context' => 'https://schema.org',
        '@graph'   => $graphs,
    ), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . '</script>' . "\n";
}
add_action('wp_head', 'antichrist_engine_foundation_print_structured_data', 20);

/**
 * Returns related foundation documents for contextual sidebars.
 *
 * @param string $page_key Current foundation page key.