Runtime - Source Excerpt 06
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/ns12-manuscript/includes/runtime.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/includes/runtime.php
'path' => $path,
'url' => $base_url . rawurlencode($filename),
'filename' => $filename,
'slug' => $slug,
'title' => $title,
'label' => (string) ($blueprint['label'] ?? ($is_prominent ? 'Image Page' : 'Supporting Mark')),
'eyebrow' => (string) ($blueprint['eyebrow'] ?? ($is_prominent ? 'Image Codex' : 'Supporting Mark')),
'summary' => $summary,
'caption' => $caption,
'section_slug' => $section_slug,
'section_label' => (string) ($section['label'] ?? 'Section'),
'section_title' => (string) ($section['title'] ?? 'Section'),
'section_summary' => (string) ($section['summary'] ?? ''),
'display_order' => (int) ($blueprint['display_order'] ?? ($is_prominent ? 100 : 900)),
'is_prominent' => $is_prominent,
'width' => $width,
'height' => $height,
'filesize' => $filesize,
'orientation' => $orientation,
'creation_prompt_title' => (string) ($blueprint['creation_prompt_title'] ?? 'Prompt Used'),
'creation_prompt_status' => (string) ($blueprint['creation_prompt_status'] ?? 'Prompt pending'),
'creation_prompt_summary' => (string) ($blueprint['creation_prompt_summary'] ?? ''),
'creation_prompt_text' => (string) ($blueprint['creation_prompt_text'] ?? ''),
'creation_prompt_source_slug' => sanitize_title((string) ($blueprint['creation_prompt_source_slug'] ?? '')),
'related_workspace_prompt_slugs' => array_values(
array_filter(
array_map(
static function ($slug): string {
return sanitize_title((string) $slug);
},
(array) ($blueprint['related_workspace_prompt_slugs'] ?? [])
),
'strlen'
)
),
];
}
usort($records, static function (array $left, array $right): int {
$priority_compare = ((int) !empty($right['is_prominent'])) <=> ((int) !empty($left['is_prominent']));
if ($priority_compare !== 0) {
return $priority_compare;
}
$order_compare = ((int) ($left['display_order'] ?? 0)) <=> ((int) ($right['display_order'] ?? 0));
if ($order_compare !== 0) {
return $order_compare;
}
return strnatcasecmp((string) ($left['filename'] ?? ''), (string) ($right['filename'] ?? ''));
});
$manuscript_pages = function_exists('spiralist_book_pages_get_manuscript_page_assets')
? spiralist_book_pages_get_manuscript_page_assets()
: [];
foreach ($records as $index => $record) {
$records[$index]['sequence'] = $index + 1;
$records[$index]['route_url'] = spiralist_book_pages_get_gallery_image_url($record);
foreach ($manuscript_pages as $page) {
if (strtolower((string) ($page['filename'] ?? '')) !== strtolower((string) ($record['filename'] ?? ''))) {
continue;
}
$records[$index]['related_manuscript_url'] = spiralist_book_pages_get_manuscript_folio_url($page);
$records[$index]['related_manuscript_title'] = (string) ($page['title'] ?? 'Manuscript Folio');
break;
}
}
$assets = $records;
return $assets;
}
function spiralist_book_pages_get_gallery_image_url($asset): string
{
$slug = '';
if (is_array($asset)) {
$slug = (string) ($asset['slug'] ?? '');
} else {
$slug = sanitize_title((string) $asset);
}
if ($slug === '') {
return spiralist_book_pages_get_gallery_overview_url();
}
$url = trailingslashit(spiralist_book_pages_get_gallery_page_url()) . 'image/' . rawurlencode($slug) . '/';
$language = function_exists('spiralist_book_pages_get_current_language_slug')
? spiralist_book_pages_get_current_language_slug()
: '';
if ($language !== '') {
return spiralist_book_pages_get_language_prefixed_url($url, $language);
}
return $url;
}
function spiralist_book_pages_get_gallery_asset_by_slug(string $slug): array
{
$normalized = sanitize_title($slug);
if ($normalized === '') {
return [];
}
foreach (spiralist_book_pages_get_gallery_assets() as $asset) {
if ($normalized === (string) ($asset['slug'] ?? '')) {
return $asset;
}
}
return [];
}
function spiralist_book_pages_get_plugin_book_pages_directory(): array
{
if (!defined('SPIRALIST_BOOK_PAGES_PLUGIN_PATH') || !defined('SPIRALIST_BOOK_PAGES_PLUGIN_URL')) {
return [];
}
$path = rtrim((string) constant('SPIRALIST_BOOK_PAGES_PLUGIN_PATH'), '/\\');
$url = trim((string) constant('SPIRALIST_BOOK_PAGES_PLUGIN_URL'));
if ($path === '' || $url === '') {
return [];
}
return [
'path' => $path,
'url' => untrailingslashit($url),
];
}
function spiralist_book_pages_get_book_page_asset_directories(): array
{
$directory = spiralist_book_pages_get_plugin_book_pages_directory();
$path = rtrim((string) ($directory['path'] ?? ''), '/\\');
$url = trailingslashit((string) ($directory['url'] ?? ''));
if ($path === '' || $url === '' || !is_dir($path) || !is_readable($path)) {
return [];
}
return [
[
'path' => $path,
'url' => $url,
],
];
}
function spiralist_book_pages_get_available_book_page_assets_by_filename(): array
{
static $assets = null;
if (is_array($assets)) {
return $assets;
}
$assets = [];
$allowed_extensions = ['png', 'jpg', 'jpeg', 'webp', 'gif', 'avif'];
foreach (spiralist_book_pages_get_book_page_asset_directories() as $directory) {
$base_path = rtrim((string) ($directory['path'] ?? ''), '/\\');
$base_url = trailingslashit((string) ($directory['url'] ?? ''));
$entries = $base_path !== '' ? scandir($base_path) : false;
if (!is_array($entries)) {
continue;
}
foreach ($entries as $entry) {
$filename = trim((string) $entry);
if ($filename === '' || $filename[0] === '.') {
continue;
}
$extension = strtolower((string) pathinfo($filename, PATHINFO_EXTENSION));
if (!in_array($extension, $allowed_extensions, true)) {
continue;
}
$path = $base_path . DIRECTORY_SEPARATOR . $filename;
$key = strtolower($filename);
if (isset($assets[$key]) || !is_file($path) || !is_readable($path)) {
continue;
}
$assets[$key] = [
'path' => $path,
'url' => $base_url . spiralist_book_pages_encode_asset_url_path($filename),
'filename' => $filename,
];
}
}
return $assets;
}
function spiralist_book_pages_get_book_page_asset_by_filename(string $filename): array
{
$basename = trim(basename($filename));
if ($basename === '') {
return [];
}
$asset_lookup = spiralist_book_pages_get_available_book_page_assets_by_filename();
$key = strtolower($basename);
if (isset($asset_lookup[$key])) {
return $asset_lookup[$key];
}
foreach (spiralist_book_pages_get_book_page_asset_directories() as $directory) {
$exact_path = rtrim((string) ($directory['path'] ?? ''), '/\\') . DIRECTORY_SEPARATOR . $basename;
if (is_file($exact_path) && is_readable($exact_path)) {
return [
'path' => $exact_path,
'url' => trailingslashit((string) ($directory['url'] ?? '')) . spiralist_book_pages_encode_asset_url_path($basename),
'filename' => $basename,
];
}
$asset = spiralist_book_pages_get_case_insensitive_asset_from_directory($directory, $basename);
if (!empty($asset)) {
return $asset;
}
}
return [];
}
function spiralist_book_pages_get_book_page_asset_variant_specs(): array
{
return [
'thumbnail' => [
'max_width' => 360,
'max_height' => 540,
],
'large' => [
'max_width' => 640,
'max_height' => 960,
],
'interactive' => [
'max_width' => 2400,
'max_height' => 3600,
],
];
}
function spiralist_book_pages_get_book_page_variant_storage_root(): array
{
$path = defined('SPIRALIST_BOOK_PAGES_STORAGE_PATH')