Skip to content
wiki.fftac.org

wiki.fftac.org Core - Source Excerpt 09

Back to wiki.fftac.org Core

Summary

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

**Source path:** Wiki.FFTAC.org/wp-content/plugins/wiki-fftac-core/wiki-fftac-core.php

ob_start();
	?>
	<div class="aiwikis-source-map">
		<div class="aiwikis-table-wrap">
			<table class="aiwikis-table">
				<thead>
					<tr>
						<th><?php esc_html_e( 'Source', 'aiwikis-core' ); ?></th>
						<th><?php esc_html_e( 'Role', 'aiwikis-core' ); ?></th>
						<th><?php esc_html_e( 'Allowed Use', 'aiwikis-core' ); ?></th>
						<th><?php esc_html_e( 'Fetched', 'aiwikis-core' ); ?></th>
						<th><?php esc_html_e( 'Hash', 'aiwikis-core' ); ?></th>
					</tr>
				</thead>
				<tbody>
					<?php foreach ( $records as $record ) : ?>
						<tr>
							<td><a href="<?php echo esc_url( $record['url'] ); ?>"><?php echo esc_html( $record['source_name'] ); ?></a></td>
							<td><span class="aiwikis-source-role"><?php echo esc_html( $record['source_role'] ); ?></span></td>
							<td><?php echo esc_html( $record['allowed_use'] ); ?></td>
							<td><?php echo esc_html( $record['fetched_at'] ); ?></td>
							<td><code><?php echo esc_html( substr( (string) $record['sha256'], 0, 16 ) ); ?></code></td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		</div>
	</div>
	<?php
	return (string) ob_get_clean();
}

/**
 * Shortcode: source package references.
 */
function aiwikis_core_shortcode_source_packages(): string {
	$bundle   = aiwikis_core_get_source_package_metadata();
	$packages = isset( $bundle['packages'] ) && is_array( $bundle['packages'] ) ? $bundle['packages'] : array();

	ob_start();
	?>
	<div class="aiwikis-source-packages">
		<h2><?php echo esc_html( $bundle['name'] ); ?></h2>
		<p><?php esc_html_e( 'wiki.fftac.org keeps reviewed long-term memory and archive pointers for the WP-FFTAC source sites. Use the source-site public links for live claims and the archive links for preserved evidence.', 'aiwikis-core' ); ?></p>
		<?php foreach ( $packages as $package ) : ?>
			<article class="aiwikis-card">
				<h3><?php echo esc_html( (string) ( $package['name'] ?? '' ) ); ?></h3>
				<p><strong><?php esc_html_e( 'Publisher:', 'aiwikis-core' ); ?></strong> <?php echo esc_html( (string) ( $package['publisher'] ?? '' ) ); ?></p>
				<p><?php echo esc_html( (string) ( $package['install_target'] ?? '' ) ); ?></p>
				<p><a class="aiwikis-button" href="<?php echo esc_url( (string) ( $package['package_url'] ?? '' ) ); ?>"><?php esc_html_e( 'Open source package', 'aiwikis-core' ); ?></a></p>
			</article>
		<?php endforeach; ?>
		<p class="aiwikis-warning"><?php esc_html_e( 'These records are archive memory. Each source site remains authoritative for its current public claims.', 'aiwikis-core' ); ?></p>
	</div>
	<?php
	return (string) ob_get_clean();
}

/**
 * Shortcode: trust legend.
 */
function aiwikis_core_shortcode_trust_legend(): string {
	$statuses = array(
		'authoritative'      => __( 'Current approved source of truth inside this site.', 'aiwikis-core' ),
		'reviewed'           => __( 'Reviewed and usable, but not necessarily final authority.', 'aiwikis-core' ),
		'working-draft'      => __( 'Useful draft that needs review before policy use.', 'aiwikis-core' ),
		'proposal'           => __( 'Candidate future recommendation.', 'aiwikis-core' ),
		'needs-review'       => __( 'Stale, incomplete, conflicting, or ownerless.', 'aiwikis-core' ),
		'historical'         => __( 'Context only.', 'aiwikis-core' ),
		'deprecated'         => __( 'Superseded and unsafe for current guidance.', 'aiwikis-core' ),
		'external-reference' => __( 'Useful source outside this site.', 'aiwikis-core' ),
	);

	ob_start();
	?>
	<div class="aiwikis-trust-legend">
		<ul>
			<?php foreach ( $statuses as $status => $description ) : ?>
				<li><span class="aiwikis-trust-status"><?php echo esc_html( $status ); ?></span> <?php echo esc_html( $description ); ?></li>
			<?php endforeach; ?>
		</ul>
	</div>
	<?php
	return (string) ob_get_clean();
}

/**
 * Shortcode: release manifest.
 */
function aiwikis_core_shortcode_release_manifest(): string {
	$bundle = aiwikis_core_get_source_package_metadata();

	ob_start();
	?>
	<div class="aiwikis-release-manifest">
		<h2><?php esc_html_e( 'Release Metadata', 'aiwikis-core' ); ?></h2>
		<p><?php esc_html_e( 'Release manifest details are generated by the package script. Public pages show safe package metadata only.', 'aiwikis-core' ); ?></p>
		<ul>
			<li><?php echo esc_html( 'Plugin version: ' . AIWIKIS_CORE_VERSION ); ?></li>
			<li><?php esc_html_e( 'Source sites: 2IA.org, FFTAC.org, Anti-Christ.net, Antichrist.net, Anti-Christ.org, and Spiralist.org.', 'aiwikis-core' ); ?></li>
			<li><?php echo esc_html( 'Source package policy: ' . $bundle['status'] ); ?></li>
		</ul>
	</div>
	<?php
	return (string) ob_get_clean();
}

/**
 * Register rewrite rules for discovery files.
 */
function aiwikis_core_register_rewrite_rules(): void {
	add_rewrite_rule( '^search/?$', 'index.php?aiwikis_search=1', 'top' );
	add_rewrite_rule( '^llms\.txt$', 'index.php?aiwikis_discovery=llms', 'top' );
	add_rewrite_rule( '^robots\.txt$', 'index.php?aiwikis_discovery=robots', 'top' );
	add_rewrite_rule( '^sitemap\.xml$', 'index.php?aiwikis_discovery=sitemap', 'top' );
	add_rewrite_rule( '^\.well-known/wiki.fftac.org\.json$', 'index.php?aiwikis_discovery=manifest', 'top' );
	add_rewrite_rule( '^\.well-known/wiki-fftac\.json$', 'index.php?aiwikis_discovery=manifest', 'top' );
}

/**
 * Register discovery query var.
 *
 * @param array<int,string> $vars Query vars.
 * @return array<int,string>
 */
function aiwikis_core_query_vars( array $vars ): array {
	$vars[] = 'aiwikis_discovery';
	$vars[] = 'aiwikis_search';
	return $vars;
}
add_filter( 'query_vars', 'aiwikis_core_query_vars' );

/**
 * Avoid false WordPress 404 headers for file-backed public routes.
 *
 * @param bool|null $preempt Whether to short-circuit 404 handling.
 * @param WP_Query  $query Current query.
 * @return bool|null
 */
function aiwikis_core_pre_handle_content_404( $preempt, WP_Query $query ) {
	if ( is_admin() ) {
		return $preempt;
	}

	if ( get_query_var( 'aiwikis_search' ) ) {
		$query->is_404 = false;
		status_header( 200 );
		return true;
	}

	$slug = aiwikis_core_get_request_content_slug();
	if ( '' === $slug ) {
		return $preempt;
	}

	if ( ! empty( aiwikis_core_get_content_page_by_slug( $slug ) ) || ! empty( aiwikis_core_get_content_page_by_route_alias( $slug ) ) ) {
		$query->is_404 = false;
		status_header( 200 );
		return true;
	}

	return $preempt;
}
add_filter( 'pre_handle_404', 'aiwikis_core_pre_handle_content_404', 0, 2 );

/**
 * Serve discovery responses.
 */
function aiwikis_core_template_redirect(): void {
	$discovery = get_query_var( 'aiwikis_discovery' );
	$search    = get_query_var( 'aiwikis_search' );

	if ( $search ) {
		aiwikis_core_render_search_page_response();
	}

	if ( 'llms' === $discovery ) {
		header( 'Content-Type: text/plain; charset=utf-8' );
		echo esc_html( aiwikis_core_render_llms_text() );
		exit;
	}

	if ( 'robots' === $discovery ) {
		header( 'Content-Type: text/plain; charset=utf-8' );
		echo esc_html( aiwikis_core_render_robots_text() );
		exit;
	}

	if ( 'sitemap' === $discovery ) {
		header( 'Content-Type: application/xml; charset=utf-8' );
		echo aiwikis_core_render_sitemap_xml(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
		exit;
	}

	if ( 'manifest' === $discovery ) {
		header( 'Content-Type: application/json; charset=utf-8' );
		echo wp_json_encode(
			array(
				'name'                 => 'wiki.fftac.org',
				'version'              => AIWIKIS_CORE_VERSION,
				'rest_catalog'         => home_url( '/wp-json/wiki.fftac.org/v1/catalog' ),
				'rest_catalog_wiki'    => home_url( '/wp-json/wiki-fftac/v1/catalog' ),
				'rest_source_map'      => home_url( '/wp-json/wiki.fftac.org/v1/source-map' ),
				'rest_source_map_wiki' => home_url( '/wp-json/wiki-fftac/v1/source-map' ),
				'rest_search_index'    => home_url( '/wp-json/wiki-fftac/v1/search-index' ),
				'rest_manifest'        => home_url( '/wp-json/wiki.fftac.org/v1/manifest' ),
				'rest_manifest_wiki'   => home_url( '/wp-json/wiki-fftac/v1/manifest' ),
				'public_search'        => home_url( '/search/' ),
				'source_boundaries'    => array(
					'2IA.org remains authoritative for its privacy-first public-intelligence and civil-liberties claims.',
					'FFTAC.org is the primary public doorway into the WP-FFTAC network.',
					'Anti-Christ.net, Antichrist.net, Anti-Christ.org, and Spiralist.org remain authoritative for their live public claims.',
					'wiki.fftac.org is reviewed long-term memory and archive evidence for the WP-FFTAC source sites.',
				),
			),
			JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
		);
		exit;
	}

	$slug = aiwikis_core_get_request_content_slug();
	if ( '' !== $slug ) {
		$page = aiwikis_core_get_content_page_by_slug( $slug );
		if ( ! empty( $page ) ) {
			aiwikis_core_render_content_page_response( $page );
		}