Helpers - Source Excerpt 16
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
'summary' => (string) ($prompt_summary['purpose'] ?? $summary),
'text' => !empty($prompt_text_blocks) ? implode("\n\n", $prompt_text_blocks) : '',
'url' => (string) ($prompt_summary['url'] ?? ($prompt_slug !== '' ? spiralist_get_workspace_prompt_url($prompt_slug) : '')),
'source_slug' => $source_slug,
'has_prompt' => true,
'status_variant' => 'fresh',
'audit_state' => 'published',
'needs_attention' => false,
'attention_title' => '',
'attention_copy' => '',
];
}
}
if ($text !== '') {
return [
'title' => $title !== '' ? $title : $default_title,
'status' => $status !== '' ? $status : 'Inline prompt attached',
'summary' => $summary !== '' ? $summary : 'This page includes an inline prompt record in the theme metadata.',
'text' => $text,
'url' => '',
'source_slug' => $source_slug,
'has_prompt' => true,
'status_variant' => 'fresh',
'audit_state' => 'inline',
'needs_attention' => false,
'attention_title' => '',
'attention_copy' => '',
];
}
if ($source_slug !== '') {
return [
'title' => $title !== '' ? $title : $default_title,
'status' => 'Prompt unresolved',
'summary' => $summary !== '' ? $summary : $default_summary,
'text' => '',
'url' => '',
'source_slug' => $source_slug,
'has_prompt' => false,
'status_variant' => 'missing',
'audit_state' => 'missing_public_record',
'needs_attention' => true,
'attention_title' => 'Public prompt still unresolved',
'attention_copy' => 'This folio already has a source slug, but no public, published workspace prompt currently resolves for it.',
];
}
return [
'title' => $title !== '' ? $title : $default_title,
'status' => 'Source slug missing',
'summary' => $summary !== '' ? $summary : $default_summary,
'text' => '',
'url' => '',
'source_slug' => $source_slug,
'has_prompt' => false,
'status_variant' => 'missing',
'audit_state' => 'missing_source_slug',
'needs_attention' => true,
'attention_title' => 'Prompt source slug still missing',
'attention_copy' => 'This folio does not yet declare the source slug that should resolve to its public prompt record.',
];
}
function spiralist_get_manuscript_prompt_audit(array $pages = []): array
{
$pages = empty($pages) ? spiralist_get_manuscript_page_assets() : array_values($pages);
$records = [];
$published_count = 0;
$attention_count = 0;
$missing_source_count = 0;
$missing_public_count = 0;
foreach ($pages as $page) {
$prompt = spiralist_get_book_page_creation_prompt_payload($page);
$record = [
'label' => (string) ($page['label'] ?? 'Page'),
'title' => (string) ($page['title'] ?? 'Manuscript folio'),
'slug' => (string) ($page['slug'] ?? ''),
'url' => function_exists('spiralist_get_manuscript_folio_url')
? spiralist_get_manuscript_folio_url($page)
: '',
'source_slug' => (string) ($prompt['source_slug'] ?? ''),
'status' => (string) ($prompt['status'] ?? ''),
'audit_state' => (string) ($prompt['audit_state'] ?? ''),
'needs_attention' => !empty($prompt['needs_attention']),
];
if (!empty($prompt['has_prompt'])) {
$published_count++;
}
if (!empty($prompt['needs_attention'])) {
$attention_count++;
}
if ((string) ($prompt['audit_state'] ?? '') === 'missing_source_slug') {
$missing_source_count++;
}
if ((string) ($prompt['audit_state'] ?? '') === 'missing_public_record') {
$missing_public_count++;
}
$records[] = $record;
}
$total = count($records);
$coverage = $total > 0 ? (int) round(($published_count / $total) * 100) : 0;
return [
'total' => $total,
'published_count' => $published_count,
'attention_count' => $attention_count,
'missing_source_count' => $missing_source_count,
'missing_public_count' => $missing_public_count,
'coverage_percent' => max(0, min(100, $coverage)),
'is_complete' => $total > 0 && $published_count === $total,
'records' => $records,
];
}
function spiralist_get_contribute_page_url(): string
{
return spiralist_get_page_url('contribute');
}
function spiralist_get_axioms_page_url(): string
{
return trailingslashit(spiralist_get_system_url()) . '#axioms';
}
function spiralist_get_transformations_page_url(): string
{
return trailingslashit(spiralist_get_symbols_page_url()) . '#transformations';
}
function spiralist_get_manuscript_page_url(): string
{
return spiralist_get_page_url('manuscript');
}
function spiralist_get_manuscript_stream_url(): string
{
return spiralist_get_manuscript_image_url();
}
function spiralist_get_public_images_directory(): array
{
$candidates = [
[
'path' => rtrim(ABSPATH, '/\\') . DIRECTORY_SEPARATOR . 'Images',
'url' => home_url('/Images'),
],
[
'path' => rtrim(ABSPATH, '/\\') . DIRECTORY_SEPARATOR . 'images',
'url' => home_url('/images'),
],
];
foreach ($candidates as $candidate) {
$path = (string) ($candidate['path'] ?? '');
if ($path !== '' && is_dir($path) && is_readable($path)) {
return $candidate;
}
}
return [];
}
function spiralist_encode_asset_url_path(string $path): string
{
$normalized = str_replace('\\', '/', trim($path));
if ($normalized === '') {
return '';
}
$segments = array_values(array_filter(explode('/', trim($normalized, '/')), 'strlen'));
if (empty($segments)) {
return '';
}
return implode('/', array_map('rawurlencode', $segments));
}
function spiralist_get_runtime_cache_option_key(string $suffix): string
{
return 'spiralist_runtime_cache_' . sanitize_key($suffix);
}
function spiralist_read_runtime_cache(string $suffix): array
{
$cached = get_option(spiralist_get_runtime_cache_option_key($suffix), []);
return is_array($cached) ? $cached : [];
}
function spiralist_write_runtime_cache(string $suffix, array $payload): void
{
update_option(spiralist_get_runtime_cache_option_key($suffix), $payload, false);
}
function spiralist_delete_runtime_cache(string $suffix): void
{
delete_option(spiralist_get_runtime_cache_option_key($suffix));
}
function spiralist_get_directory_asset_manifest(array $directories, array $allowed_extensions): array
{
static $manifest_cache = [];
$cache_key = hash(
'sha256',
(string) wp_json_encode(
[
'directories' => array_map(
static function (array $directory): array {
return [
'path' => rtrim((string) ($directory['path'] ?? ''), '/\\'),
'url' => trailingslashit((string) ($directory['url'] ?? '')),
];
},
$directories
),
'extensions' => array_values(array_map('strtolower', $allowed_extensions)),
]
)
);
if (isset($manifest_cache[$cache_key])) {
return $manifest_cache[$cache_key];
}