wiki.fftac.org Core - Source Excerpt 06
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
$parts = array_values( array_filter( explode( '/', trim( $route, '/' ) ) ) );
?>
<nav class="aiwikis-breadcrumbs" aria-label="<?php echo esc_attr__( 'Breadcrumbs', 'aiwikis-core' ); ?>">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php echo esc_html__( 'Home', 'aiwikis-core' ); ?></a>
<?php
$current = '';
foreach ( $parts as $index => $part ) :
$current .= '/' . $part;
$crumb_route = $current . '/';
$is_last = $index === count( $parts ) - 1;
$record = aiwikis_core_get_public_search_record_by_route( $crumb_route );
$label = ! empty( $record['title'] ) ? (string) $record['title'] : aiwikis_core_route_label( $crumb_route );
?>
<span aria-hidden="true">/</span>
<?php if ( ! $is_last && ! empty( $record ) ) : ?>
<a href="<?php echo esc_url( home_url( $crumb_route ) ); ?>"><?php echo esc_html( $label ); ?></a>
<?php else : ?>
<span><?php echo esc_html( $label ); ?></span>
<?php endif; ?>
<?php endforeach; ?>
</nav>
<?php
}
/**
* Return contextual next routes for a content page.
*
* @param array<string,mixed> $page Content page record.
* @return array<int,array<string,mixed>>
*/
function aiwikis_core_get_contextual_route_records( array $page, int $limit = 6 ): array {
$route = isset( $page['route'] ) ? (string) $page['route'] : '/';
$frontmatter = isset( $page['frontmatter'] ) && is_array( $page['frontmatter'] ) ? $page['frontmatter'] : array();
$page_type = aiwikis_core_frontmatter_string( $frontmatter, 'page_type' );
$category = aiwikis_core_frontmatter_string( $frontmatter, 'primary_category' );
$prefix = trim( explode( '/', trim( $route, '/' ) )[0] ?? '', '/' );
$candidates = array();
foreach ( aiwikis_core_get_public_search_records() as $record ) {
$record_route = isset( $record['route'] ) ? (string) $record['route'] : '';
if ( '' === $record_route || $record_route === $route ) {
continue;
}
$score = 0;
if ( '' !== $prefix && str_starts_with( trim( $record_route, '/' ), $prefix . '/' ) ) {
$score += 6;
}
if ( '' !== $category && $category === (string) ( $record['primary_category'] ?? '' ) ) {
$score += 4;
}
if ( '' !== $page_type && $page_type === (string) ( $record['page_type'] ?? '' ) ) {
$score += 2;
}
if ( in_array( $record_route, array( '/start-here/', '/search/', '/memory/crawl-map/', '/memory/sources/', '/wp-fftac-memory-and-site-structure/', '/for-ai-agents/' ), true ) ) {
$score += 1;
}
if ( $score > 0 ) {
$record['_context_score'] = $score;
$candidates[] = $record;
}
}
usort(
$candidates,
static function ( array $a, array $b ): int {
$score_compare = (int) ( $b['_context_score'] ?? 0 ) <=> (int) ( $a['_context_score'] ?? 0 );
if ( 0 !== $score_compare ) {
return $score_compare;
}
return strcasecmp( (string) ( $a['route'] ?? '' ), (string) ( $b['route'] ?? '' ) );
}
);
return array_slice( $candidates, 0, $limit );
}
/**
* Render source/status context and next links for a content page.
*
* @param array<string,mixed> $page Content page record.
*/
function aiwikis_core_render_page_context( array $page ): void {
$frontmatter = isset( $page['frontmatter'] ) && is_array( $page['frontmatter'] ) ? $page['frontmatter'] : array();
$route = isset( $page['route'] ) ? (string) $page['route'] : '/';
$next = aiwikis_core_get_contextual_route_records( $page );
?>
<section class="aiwikis-page-context" aria-label="<?php echo esc_attr__( 'Page context', 'aiwikis-core' ); ?>">
<div>
<strong><?php echo esc_html__( 'Route', 'aiwikis-core' ); ?></strong>
<code><?php echo esc_html( $route ); ?></code>
</div>
<?php if ( '' !== aiwikis_core_frontmatter_string( $frontmatter, 'source_status' ) ) : ?>
<div>
<strong><?php echo esc_html__( 'Source status', 'aiwikis-core' ); ?></strong>
<span><?php echo esc_html( aiwikis_core_frontmatter_string( $frontmatter, 'source_status' ) ); ?></span>
</div>
<?php endif; ?>
<?php if ( '' !== aiwikis_core_frontmatter_string( $frontmatter, 'trust_level' ) ) : ?>
<div>
<strong><?php echo esc_html__( 'Trust', 'aiwikis-core' ); ?></strong>
<span><?php echo esc_html( aiwikis_core_frontmatter_string( $frontmatter, 'trust_level' ) ); ?></span>
</div>
<?php endif; ?>
<?php if ( ! empty( $next ) ) : ?>
<div class="aiwikis-page-context-next">
<strong><?php echo esc_html__( 'Related routes', 'aiwikis-core' ); ?></strong>
<ul>
<?php foreach ( $next as $record ) : ?>
<li><a href="<?php echo esc_url( home_url( (string) ( $record['route'] ?? '/' ) ) ); ?>"><?php echo esc_html( (string) ( $record['title'] ?? $record['route'] ?? '' ) ); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</section>
<?php
}
/**
* Render the public reviewed-memory search page.
*/
function aiwikis_core_render_search_page_response(): void {
$query = aiwikis_core_get_search_query();
$records = '' === $query ? array() : aiwikis_core_search_public_records( $query, 50 );
status_header( 200 );
get_header();
?>
<main id="main" class="aiwikis-main">
<article class="aiwikis-article aiwikis-search-page">
<?php aiwikis_core_render_memory_navigation(); ?>
<?php aiwikis_core_render_breadcrumbs( array( 'route' => '/search/', 'title' => 'Search Reviewed Memory' ) ); ?>
<h1><?php echo esc_html__( 'Search Reviewed Memory', 'aiwikis-core' ); ?></h1>
<p class="aiwikis-lede"><?php echo esc_html__( 'Search public wiki routes, source summaries, archive labels, and reviewed memory descriptions. Source sites remain authoritative for live claims.', 'aiwikis-core' ); ?></p>
<form class="aiwikis-search-form aiwikis-search-form-large" action="<?php echo esc_url( home_url( '/search/' ) ); ?>" method="get">
<label for="aiwikis-core-search"><?php echo esc_html__( 'Search wiki.fftac.org memory', 'aiwikis-core' ); ?></label>
<div>
<input id="aiwikis-core-search" type="search" name="q" value="<?php echo esc_attr( $query ); ?>" placeholder="<?php echo esc_attr__( 'source, topic, route, handoff, package...', 'aiwikis-core' ); ?>">
<button type="submit"><?php echo esc_html__( 'Search', 'aiwikis-core' ); ?></button>
</div>
</form>
<div class="aiwikis-search-results">
<?php if ( '' === $query ) : ?>
<h2><?php echo esc_html__( 'Good Starting Points', 'aiwikis-core' ); ?></h2>
<ul class="aiwikis-task-links">
<li><a href="<?php echo esc_url( home_url( '/start-here/' ) ); ?>"><?php echo esc_html__( 'Start Here', 'aiwikis-core' ); ?></a></li>
<li><a href="<?php echo esc_url( home_url( '/memory/crawl-map/' ) ); ?>"><?php echo esc_html__( 'Memory Crawl Map', 'aiwikis-core' ); ?></a></li>
<li><a href="<?php echo esc_url( home_url( '/memory/sources/' ) ); ?>"><?php echo esc_html__( 'All Memory Sources', 'aiwikis-core' ); ?></a></li>
<li><a href="<?php echo esc_url( home_url( '/for-ai-agents/' ) ); ?>"><?php echo esc_html__( 'For AI Agents', 'aiwikis-core' ); ?></a></li>
</ul>
<?php elseif ( empty( $records ) ) : ?>
<p><?php echo esc_html__( 'No reviewed memory routes matched that query.', 'aiwikis-core' ); ?></p>
<?php else : ?>
<h2>
<?php
printf(
/* translators: %d: result count. */
esc_html__( '%d reviewed route matches', 'aiwikis-core' ),
count( $records )
);
?>
</h2>
<?php foreach ( $records as $record ) : ?>
<article class="aiwikis-search-result">
<h3><a href="<?php echo esc_url( home_url( (string) ( $record['route'] ?? '/' ) ) ); ?>"><?php echo esc_html( (string) ( $record['title'] ?? '' ) ); ?></a></h3>
<p class="aiwikis-meta"><code><?php echo esc_html( (string) ( $record['route'] ?? '' ) ); ?></code> <?php echo esc_html( (string) ( $record['source_status'] ?? '' ) ); ?></p>
<p><?php echo esc_html( (string) ( $record['description'] ?? $record['body_preview'] ?? '' ) ); ?></p>
</article>
<?php endforeach; ?>
<?php endif; ?>
</div>
</article>
</main>
<?php
get_footer();
exit;
}
/**
* Render an explicit 404 for missing Markdown-backed public routes.
*/
function aiwikis_core_render_missing_content_response( string $slug ): void {
global $wp_query;
if ( $wp_query instanceof WP_Query ) {
$wp_query->set_404();
}
status_header( 404 );
nocache_headers();