Skip to content
wiki.fftac.org

Antichrist Content System Implementation - Source Excerpt 09

Back to Antichrist Content System Implementation

Summary

This source excerpt preserves a bounded section of Antichrist.net/wp-content/plugins/antichrist-content-system/includes/antichrist-content-system-implementation.php so readers can inspect the evidence without opening the full source file.

**Source path:** Antichrist.net/wp-content/plugins/antichrist-content-system/includes/antichrist-content-system-implementation.php

/**
 * Detect seeded pages that exist but lost their real public content.
 *
 * @param WP_Post $post Existing page.
 * @param array   $page Expected page definition.
 * @return bool
 */
function acn_cs_seeded_page_needs_repair( $post, $page ) {
	$content  = isset( $post->post_content ) ? (string) $post->post_content : '';
	$expected = isset( $page['content'] ) ? (string) $page['content'] : '';

	if ( '' !== trim( $expected ) && '' === trim( $content ) ) {
		return true;
	}

	$forbidden = array(
		'No child pages are attached',
		'requested research dossier',
		'setup placeholder',
		'lorem' . ' ipsum',
		'seo.post.',
		'seo.page.',
	);

	foreach ( $forbidden as $needle ) {
		if ( false !== stripos( $content, $needle ) ) {
			return true;
		}
	}

	if (
		false !== strpos( $expected, '<span class="kicker">Report 01</span>' )
		&& false !== strpos( $expected, '<a class="section-directory-card"' )
		&& false !== strpos( $content, '<article class="section-directory-card"><span class="kicker">Report 01</span>' )
	) {
		return true;
	}

	$public_text   = trim( preg_replace( '/\s+/', ' ', wp_strip_all_tags( strip_shortcodes( $content ) ) ) );
	$expected_text = trim( preg_replace( '/\s+/', ' ', wp_strip_all_tags( strip_shortcodes( $expected ) ) ) );

	if ( strlen( $expected_text ) >= 220 && strlen( $public_text ) < 120 ) {
		return true;
	}

	if ( strlen( $expected_text ) >= 5000 && strlen( $public_text ) < 3000 ) {
		return true;
	}

	if (
		false !== strpos( $expected_text, 'Research Dossier: Antichrist Cults and Antichrist Rhetoric' )
		&& (
			false === strpos( $public_text, 'Research Dossier: Antichrist Cults and Antichrist Rhetoric' )
			|| false === strpos( $public_text, 'Order of Nine Angles' )
		)
	) {
		return true;
	}

	return false;
}

/**
 * Detect stale menu assignments/items.
 *
 * @return bool
 */
function acn_cs_menus_need_rebuild() {
	$locations = (array) get_theme_mod( 'nav_menu_locations', array() );

	$expected = array(
		'primary' => array( '', 'archive', 'research-agenda', 'research-library', 'timeline', 'symbols', 'apocalyptic-ai', 'state-and-religion', 'surveillance', 'community-baseline', 'about' ),
		'footer'  => array(
			'archive',
			'topics',
			'timeline',
			'symbols',
			'state-and-religion',
			'surveillance',
			'pre-christian-antichrist-history',
			'antichrist-like-figures-eastern-philosophy',
			'katechon',
			'apocalyptic-ai',
			'eschatological-accelerationism',
			'prophecy-tracking-resource-curation',
			'apocalyptic-optimism',
			'doomsday-preparedness',
			'antichrist-as-redeemer-of-mankind',
			'antichrist-redeemer-second-coming',
			'current-antichrist-cults',
			'antichrist-militia-groups',
			'message-board',
			'members',
			'community-baseline',
			'about',
			'editorial-policy',
			'archive-and-content-strategy',
			'research-agenda',
			'research-library',
		),
	);

	foreach ( $expected as $location => $paths ) {
		if ( empty( $locations[ $location ] ) || ! acn_cs_menu_matches_paths( (int) $locations[ $location ], $paths ) ) {
			return true;
		}
	}

	return false;
}

/**
 * Check a menu against expected page paths.
 *
 * @param int   $menu_id Menu term ID.
 * @param array $paths Expected page paths.
 * @return bool
 */
function acn_cs_menu_matches_paths( $menu_id, $paths ) {
	if ( ! $menu_id ) {
		return false;
	}

	$items = wp_get_nav_menu_items( $menu_id );
	if ( ! is_array( $items ) || count( $items ) !== count( $paths ) ) {
		return false;
	}

	$actual = array();
	foreach ( $items as $item ) {
		if ( 'custom' === $item->type ) {
			$item_url = isset( $item->url ) ? untrailingslashit( (string) $item->url ) : '';
			$home_url = untrailingslashit( home_url( '/' ) );
			if ( $item_url === $home_url ) {
				$actual[] = '';
				continue;
			}
			return false;
		}

		if ( 'page' !== $item->object || empty( $item->object_id ) ) {
			return false;
		}

		$page = get_post( (int) $item->object_id );
		if ( ! $page instanceof WP_Post ) {
			return false;
		}

		$actual[] = get_page_uri( $page );
	}

	return array_values( $paths ) === $actual;
}

/**
 * Pin the site to the initial public language set.
 */
function acn_cs_configure_locale_router() {
	$locale_repository = acn_cs_locale_repository_class();
	if ( '' === $locale_repository ) {
		return;
	}

	if ( get_option( 'acn_locale_router_config_version' ) === ACN_LOCALE_ROUTER_CONFIG_VERSION && ! acn_cs_locale_router_needs_config( $locale_repository ) ) {
		return;
	}

	$allowed = acn_cs_required_locale_tags();
	$locales = $locale_repository::get_supported_locales();
	$known   = array();

	foreach ( $locales as $locale ) {
		if ( is_array( $locale ) && ! empty( $locale['tag'] ) ) {
			$known[ (string) $locale['tag'] ] = true;
		}
	}

	foreach ( $allowed as $tag ) {
		if ( empty( $known[ $tag ] ) ) {
			$locales[] = acn_cs_required_locale_record( $tag );
		}
	}

	foreach ( $locales as &$locale ) {
		$tag = isset( $locale['tag'] ) ? (string) $locale['tag'] : '';

		$locale['enabled']   = in_array( $tag, $allowed, true );
		$locale['isDefault'] = 'en-US' === $tag;

		if ( in_array( $tag, $allowed, true ) ) {
			$locale = array_merge( $locale, acn_cs_required_locale_record( $tag ) );
		}
	}
	unset( $locale );

	$locale_repository::save_supported_locales( $locales );

	$option_prefix = class_exists( '\UAIXLocaleRouter\LocaleRepository' ) ? 'uaixlr' : 'ns12lr';
	update_option( $option_prefix . '_default_locale', 'en-US', false );

	$settings = (array) get_option( $option_prefix . '_settings', array() );
	$settings = array_merge(
		$settings,
		array(
			'enabled'                => true,
			'default_locale'         => 'en-US',
			'url_casing_strategy'    => 'lowercase',
			'trailing_slash_strategy' => 'always',
			'redirect_bare_urls'     => false,
			'content_link_rewriting' => true,
		)
	);
	update_option( $option_prefix . '_settings', $settings, false );
	foreach ( array( '\UAIXLocaleRouter\Settings', '\Ns12LocaleRouter\Settings' ) as $settings_class ) {
		if ( class_exists( $settings_class ) && method_exists( $settings_class, 'reset_cache' ) ) {
			$settings_class::reset_cache();
		}
	}

	acn_cs_write_ns12_dictionaries();
	update_option( 'acn_locale_router_config_version', ACN_LOCALE_ROUTER_CONFIG_VERSION, false );
}

/**
 * Preserve existing library pages while changing the public slug and language.
 */
function acn_cs_migrate_public_library_slug() {
	$current = get_page_by_path( 'research-library' );
	$legacy  = get_page_by_path( 'source-handoff-library' );

	if ( $current instanceof WP_Post || ! $legacy instanceof WP_Post ) {
		return;
	}

	wp_update_post(
		wp_slash(
			array(
				'ID'         => $legacy->ID,
				'post_title' => 'Research Library',
				'post_name'  => 'research-library',
			)
		)
	);
}

/**
 * Redirect old workflow-facing URLs to the reader-facing research library.
 */
function acn_cs_redirect_legacy_public_library() {
	if ( is_admin() ) {
		return;
	}

	$request_path = isset( $_SERVER['REQUEST_URI'] ) ? (string) wp_parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ) : '';
	$request_path = '/' . trim( strtolower( $request_path ), '/' ) . '/';

	$aliases = array(
		'/antichrist-malitia-groups/' => '/antichrist-militia-groups/',
		'/library/' => '/research-library/',
		'/state-religion/' => '/state-and-religion/',
		'/test/' => '/archive/legacy-front-page/',
		'/tool/convertimagetohtml/' => '/archive/legacy-utility-pages/',
		'/content/pdfs/antichrist_cx.pdf/' => '/archive/antichrist-cx/',
		'/content/pdfs/al_qaeda_net.pdf/' => '/archive/al-qaeda-net/',
	);
	if ( isset( $aliases[ $request_path ] ) ) {
		wp_safe_redirect( home_url( $aliases[ $request_path ] ), 301 );
		exit;
	}

	$asset_aliases = array(
		'/localhost.jpg/' => get_template_directory_uri() . '/assets/img/foundation-seal-1024.jpg',
		'/mk.png/'        => get_template_directory_uri() . '/assets/img/site-icon-192.png',
	);
	if ( isset( $asset_aliases[ $request_path ] ) ) {
		wp_safe_redirect( $asset_aliases[ $request_path ], 301 );
		exit;
	}

	if ( 0 !== strpos( $request_path, '/source-handoff-library/' ) ) {
		return;
	}

	$target_path = preg_replace( '#^/source-handoff-library/#', '/research-library/', $request_path );
	wp_safe_redirect( home_url( $target_path ), 301 );
	exit;
}

/**
 * Register root and language-level sitemap routes.
 */
function acn_cs_register_sitemap_routes() {
	add_rewrite_tag( '%acn_sitemap%', '(xml|html)' );
	add_rewrite_tag( '%acn_sitemap_locale%', '([A-Za-z]{2,8}(?:-[A-Za-z0-9]{2,8})*|root)' );
	add_rewrite_rule( '^sitemap\.(xml|html)$', 'index.php?acn_sitemap=$matches[1]&acn_sitemap_locale=root', 'top' );
	add_rewrite_rule( '^([A-Za-z]{2,8}(?:-[A-Za-z0-9]{2,8})*)/sitemap\.(xml|html)$', 'index.php?acn_sitemap=$matches[2]&acn_sitemap_locale=$matches[1]', 'top' );
}

/**
 * Add sitemap query variables.
 *
 * @param array $vars Query vars.
 * @return array
 */
function acn_cs_sitemap_query_vars( $vars ) {
	$vars[] = 'acn_sitemap';
	$vars[] = 'acn_sitemap_locale';
	return $vars;
}