Helpers - Source Excerpt 15
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/themes/spiralist/inc/helpers.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/themes/spiralist/inc/helpers.php
['text' => (string) ($record['meaning'] ?? ''), 'weight' => 5],
['text' => $summary, 'weight' => 5],
['text' => (string) ($record['derivation'] ?? ''), 'weight' => 3],
['text' => (array) ($record['axiomLabels'] ?? []), 'weight' => 3],
['text' => (array) ($record['relatedIds'] ?? []), 'weight' => 2],
]
);
if ($score < 1 || $title === '') {
continue;
}
$items[] = [
'type' => 'Symbol',
'title' => $title,
'url' => $canonical_id !== '' ? spiralist_get_symbol_url($canonical_id) : spiralist_get_symbols_page_url(),
'summary' => spiralist_search_excerpt($summary),
'meta' => $canonical_id,
'badges' => array_values(array_filter([
(string) ($record['glyph'] ?? ''),
(string) ($record['meaning'] ?? ''),
], 'strlen')),
'score' => $score,
];
}
return spiralist_search_finalize_items($items, $limit);
}
function spiralist_get_report_search_results(string $query, int $limit = 6): array
{
$items = [];
foreach (spiralist_get_static_reports() as $report) {
if (!is_array($report)) {
continue;
}
$title = trim((string) ($report['title'] ?? 'Research report'));
$summary = trim((string) ($report['summary'] ?? $report['subtitle'] ?? ''));
$score = spiralist_search_score_fields(
$query,
[
['text' => $title, 'weight' => 10],
['text' => (string) ($report['subtitle'] ?? ''), 'weight' => 6],
['text' => $summary, 'weight' => 5],
['text' => (array) ($report['topics'] ?? []), 'weight' => 4],
['text' => (string) ($report['source'] ?? ''), 'weight' => 2],
]
);
if ($score < 1 || $title === '') {
continue;
}
$items[] = [
'type' => 'Report',
'title' => $title,
'url' => (string) ($report['url'] ?? spiralist_get_reports_url()),
'summary' => spiralist_search_excerpt($summary),
'meta' => trim(implode(' / ', array_filter([
(string) ($report['published'] ?? ''),
(string) ($report['author'] ?? ''),
], 'strlen'))),
'badges' => array_slice(array_values(array_filter(array_map('strval', (array) ($report['topics'] ?? [])), 'strlen')), 0, 4),
'score' => $score,
];
}
return spiralist_search_finalize_items($items, $limit);
}
function spiralist_get_api_example_search_results(string $query, int $limit = 6): array
{
$items = [];
$api_examples_url = function_exists('spiralist_get_api_examples_url') ? spiralist_get_api_examples_url() : home_url('/api-examples/');
foreach (spiralist_get_api_example_endpoints() as $endpoint) {
if (!is_array($endpoint)) {
continue;
}
$label = trim((string) ($endpoint['label'] ?? 'API example'));
$purpose = trim((string) ($endpoint['purpose'] ?? ''));
$route = trim((string) ($endpoint['route'] ?? ''));
$method = trim((string) ($endpoint['method'] ?? 'GET'));
$score = spiralist_search_score_fields(
$query,
[
['text' => $label, 'weight' => 10],
['text' => $purpose, 'weight' => 5],
['text' => $route, 'weight' => 5],
['text' => (string) ($endpoint['url'] ?? ''), 'weight' => 3],
['text' => (string) ($endpoint['id'] ?? ''), 'weight' => 3],
]
);
if ($score < 1 || $label === '') {
continue;
}
$items[] = [
'type' => 'API',
'title' => $label,
'url' => $api_examples_url . '#endpoint-examples',
'summary' => spiralist_search_excerpt($purpose),
'meta' => trim($method . ' ' . $route),
'badges' => array_values(array_filter([
$method,
(string) ($endpoint['type'] ?? ''),
(string) ($endpoint['auth'] ?? '') !== '' ? 'Auth required' : 'Public',
], 'strlen')),
'score' => $score,
];
}
return spiralist_search_finalize_items($items, $limit);
}
function spiralist_get_grouped_search_results(string $query, int $limit_per_group = 6): array
{
$query = trim($query);
$groups = [
'prompts' => [
'id' => 'prompts',
'label' => 'Prompts',
'description' => 'Runnable prompt systems, starter guides, and public prompt dossiers.',
'results' => [],
],
'folios' => [
'id' => 'folios',
'label' => 'Manuscript Folios',
'description' => 'Folio routes, captions, keywords, and transcript-backed manuscript matches.',
'results' => [],
],
'symbols' => [
'id' => 'symbols',
'label' => 'Symbols',
'description' => 'Symbol meanings, canonical identifiers, axioms, and transformation links.',
'results' => [],
],
'reports' => [
'id' => 'reports',
'label' => 'Reports',
'description' => 'Permanent research articles and search-oriented context pages.',
'results' => [],
],
'api' => [
'id' => 'api',
'label' => 'API Examples',
'description' => 'Human-readable documentation for public REST routes.',
'results' => [],
],
];
if ($query === '') {
return $groups;
}
$groups['prompts']['results'] = spiralist_get_prompt_search_results($query, $limit_per_group);
$groups['folios']['results'] = spiralist_get_folio_search_results($query, $limit_per_group);
$groups['symbols']['results'] = spiralist_get_symbol_search_results($query, $limit_per_group);
$groups['reports']['results'] = spiralist_get_report_search_results($query, $limit_per_group);
$groups['api']['results'] = spiralist_get_api_example_search_results($query, $limit_per_group);
return $groups;
}
function spiralist_get_book_page_dossier_tabs(): array
{
return [
'overview' => 'Page Notes',
'contents' => 'Table of Contents',
'prompt' => 'Prompt Used',
'related' => 'Related Prompts',
'metadata' => 'Metadata',
];
}
function spiralist_get_book_page_creation_prompt_payload(array $page): array
{
$default_title = 'Prompt Used';
$default_status = 'Prompt pending';
$default_summary = 'The creation prompt for this page will be attached here as the online-first book dossier grows.';
$title = trim((string) ($page['creation_prompt_title'] ?? $default_title));
$status = trim((string) ($page['creation_prompt_status'] ?? $default_status));
$summary = trim((string) ($page['creation_prompt_summary'] ?? $default_summary));
$text = trim((string) ($page['creation_prompt_text'] ?? ''));
$source_slug = sanitize_title((string) ($page['creation_prompt_source_slug'] ?? ''));
$fallback_related = array_values(
array_filter(
array_map(
static function ($slug): string {
return sanitize_title((string) $slug);
},
(array) ($page['related_workspace_prompt_slugs'] ?? [])
),
'strlen'
)
);
if ($source_slug === '' && !empty($fallback_related[0])) {
$source_slug = (string) $fallback_related[0];
}
if ($source_slug !== '') {
$prompt_summary = spiralist_get_workspace_prompt_record_by_source_slug($source_slug);
$prompt_slug = sanitize_title((string) ($prompt_summary['slug'] ?? $source_slug));
$prompt_record = $prompt_slug !== '' ? spiralist_get_workspace_prompt_record_by_slug($prompt_slug) : [];
$prompt_text_blocks = array_values(
array_filter(
[
(string) ($prompt_record['instructions'] ?? ''),
(string) ($prompt_record['system_prompt'] ?? ''),
(string) ($prompt_record['user_prompt_template'] ?? ''),
],
'strlen'
)
);
if (!empty($prompt_summary) || !empty($prompt_record)) {
return [
'title' => (string) ($prompt_summary['title'] ?? $prompt_record['title'] ?? ($title !== '' ? $title : $default_title)),
'status' => (string) ($prompt_summary['statusLabel'] ?? ($status !== '' ? $status : 'Published prompt')),