Frontendcontroller - Source Excerpt 08
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/spiralist-workspace/includes/Web/FrontendController.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/plugins/spiralist-workspace/includes/Web/FrontendController.php
? $this->reviews->find_for_prompt_and_user($prompt_id, $user_id, 'peer')
: [];
return $prompt;
}
/**
* Returns the active review summary after any appeal-based reset.
*
* @param array<string,mixed>|null $appeal_summary
* @return array<string,mixed>
*/
private function current_review_summary(int $prompt_id, ?array $appeal_summary = null): array
{
if ($appeal_summary === null) {
$appeal_summary = $this->appeals->summary_for_prompt($prompt_id);
}
$since_utc = (string) ($appeal_summary['governance_reset_utc'] ?? '');
return $this->reviews->summary_for_prompt($prompt_id, $since_utc);
}
/**
* Returns sanitized library filters from the current request.
*
* @return array<string,string>
*/
private function library_filters_from_request(): array
{
$raw = wp_unslash($_GET);
$route_key = sanitize_key((string) get_query_var('spiralist_workspace_filter_key', ''));
$route_value = sanitize_text_field((string) get_query_var('spiralist_workspace_filter_value', ''));
if ($route_key !== '' && $route_value !== '') {
$target_key = $route_key === 'moderation' ? 'moderation_status' : $route_key;
$raw[$target_key] = $route_value;
}
$search = sanitize_text_field((string) ($raw['search'] ?? ''));
$intent = trim((string) ($raw['intent'] ?? '')) !== ''
? PromptIntentRegistry::normalize_intent((string) ($raw['intent'] ?? ''))
: '';
$redirect_intent = $intent === '' ? PromptIntentRegistry::redirect_intent_for_search($search) : '';
if ($redirect_intent !== '') {
$intent = $redirect_intent;
$search = '';
}
return [
'search' => $search,
'intent' => $intent,
'category' => trim((string) ($raw['category'] ?? '')) !== ''
? PromptCategoryRegistry::normalize_category((string) ($raw['category'] ?? ''))
: '',
'subcategory' => sanitize_text_field((string) ($raw['subcategory'] ?? '')),
'lane' => trim((string) ($raw['lane'] ?? '')) !== ''
? PromptMetaRegistry::normalize_publication_lane((string) ($raw['lane'] ?? ''))
: '',
'provenance' => trim((string) ($raw['provenance'] ?? '')) !== ''
? PromptMetaRegistry::normalize_provenance((string) ($raw['provenance'] ?? ''))
: '',
'moderation_status' => trim((string) ($raw['moderation_status'] ?? '')) !== ''
? PromptMetaRegistry::normalize_moderation_status((string) ($raw['moderation_status'] ?? ''))
: '',
'risk' => trim((string) ($raw['risk'] ?? '')) !== ''
? (PromptMetaRegistry::normalize_risk_labels([(string) ($raw['risk'] ?? '')])[0] ?? '')
: '',
'function' => trim((string) ($raw['function'] ?? '')) !== ''
? (PromptMetaRegistry::normalize_function_tags([(string) ($raw['function'] ?? '')])[0] ?? '')
: '',
'level' => trim((string) ($raw['level'] ?? '')) !== ''
? PromptMetaRegistry::normalize_maturity_level((string) ($raw['level'] ?? ''))
: '',
];
}
/**
* Returns whether a prompt matches the current library filters.
*
* @param array<string,string> $filters
*/
private function matches_library_filters(array $prompt, array $filters): bool
{
if (($filters['intent'] ?? '') !== '' && !PromptIntentRegistry::matches_prompt_intent($prompt, (string) $filters['intent'])) {
return false;
}
if (($filters['category'] ?? '') !== '' && (string) ($prompt['category'] ?? '') !== (string) $filters['category']) {
return false;
}
if (($filters['subcategory'] ?? '') !== '' && (string) ($prompt['subcategory'] ?? '') !== (string) $filters['subcategory']) {
return false;
}
if (($filters['lane'] ?? '') !== '' && (string) ($prompt['publication_lane'] ?? '') !== (string) $filters['lane']) {
return false;
}
if (($filters['provenance'] ?? '') !== '' && (string) ($prompt['provenance'] ?? '') !== (string) $filters['provenance']) {
return false;
}
if (($filters['moderation_status'] ?? '') !== '' && (string) ($prompt['moderation_status'] ?? '') !== (string) $filters['moderation_status']) {
return false;
}
if (($filters['risk'] ?? '') !== '' && !in_array((string) $filters['risk'], (array) ($prompt['risk_labels'] ?? []), true)) {
return false;
}
if (($filters['function'] ?? '') !== '' && !in_array((string) $filters['function'], (array) ($prompt['function_tags'] ?? []), true)) {
return false;
}
if (($filters['level'] ?? '') !== '' && (string) ($prompt['maturity_level'] ?? '') !== (string) $filters['level']) {
return false;
}
$search = trim((string) ($filters['search'] ?? ''));
if ($search === '') {
return true;
}
$haystack = implode(
"\n",
[
(string) ($prompt['title'] ?? ''),
(string) ($prompt['summary'] ?? ''),
implode(', ', (array) ($prompt['tags'] ?? [])),
implode(', ', (array) ($prompt['risk_labels'] ?? [])),
implode(', ', (array) ($prompt['function_tags'] ?? [])),
(string) ($prompt['editorial_note'] ?? ''),
implode(', ', (array) ($prompt['related_symbols'] ?? [])),
implode(', ', (array) ($prompt['related_axioms'] ?? [])),
implode(', ', (array) ($prompt['related_manuscripts'] ?? [])),
]
);
return stripos($haystack, $search) !== false;
}
/**
* Groups prompts by publication lane.
*
* @param array<int,array<string,mixed>> $records
* @return array<string,array<int,array<string,mixed>>>
*/
private function group_by_publication_lane(array $records): array
{
$sections = [
'official_canon' => [],
'community_library' => [],
'prompt_ecology_archive' => [],
];
foreach ($records as $record) {
$lane = (string) ($record['publication_lane'] ?? 'community_library');
if (!isset($sections[$lane])) {
$lane = 'community_library';
}
$sections[$lane][] = $record;
}
return $sections;
}
/**
* Returns unfiltered public counts by publication lane.
*
* @param array<int,array<string,mixed>> $records
* @return array<string,int>
*/
private function lane_counts(array $records): array
{
$counts = [
'official_canon' => 0,
'community_library' => 0,
'prompt_ecology_archive' => 0,
];
foreach ($records as $record) {
$lane = (string) ($record['publication_lane'] ?? 'community_library');
if (!isset($counts[$lane])) {
$lane = 'community_library';
}
$counts[$lane]++;
}
return $counts;
}
/**
* Returns unfiltered public counts by moderation state.
*
* @param array<int,array<string,mixed>> $records
* @return array<string,int>
*/
private function moderation_counts(array $records): array
{
$counts = [
'provisional_public' => 0,
'peer_reviewed' => 0,
'official_canon' => 0,
];
foreach ($records as $record) {
$status = PromptMetaRegistry::normalize_moderation_status((string) ($record['moderation_status'] ?? 'draft'));
if (isset($counts[$status])) {
$counts[$status]++;
}
}
return $counts;
}
/**
* Returns curator-led collections for the public library.
*
* @return array<int,array<string,mixed>>
*/
private function featured_collections(array $records): array
{
$collections = [
[
'slug' => 'starter-canon',
'title' => 'Starter Canon',
'summary' => 'A practical first pass through the official Spiralist prompt canon.',
'query' => ['lane' => 'official_canon'],
'records' => array_values(
array_filter(
$records,