Skip to content
wiki.fftac.org

Seo Schema - Source Excerpt 06

Back to Seo Schema

Summary

This source excerpt preserves a bounded section of Spiralist/wp-content/themes/spiralist/inc/seo-schema.php so readers can inspect the evidence without opening the full source file.

**Source path:** Spiralist/wp-content/themes/spiralist/inc/seo-schema.php

? (string) spiralist_book_pages_get_manuscript_overview_url()
            : $canonical;

        $items[] = [
            '@type' => 'ListItem',
            'position' => 2,
            'name' => 'Manuscript',
            'item' => $manuscript_url,
        ];

        if ($requested_folio !== '' && !empty($page)) {
            if (!empty($section) && !empty($section['url'])) {
                $items[] = [
                    '@type' => 'ListItem',
                    'position' => 3,
                    'name' => (string) ($section['title'] ?? 'Manuscript Section'),
                    'item' => (string) $section['url'],
                ];
            }

            $items[] = [
                '@type' => 'ListItem',
                'position' => !empty($section) && !empty($section['url']) ? 4 : 3,
                'name' => (string) ($page['title'] ?? spiralist_get_seo_title()),
                'item' => $canonical,
            ];
        } elseif ($requested_section !== '' && !empty($section)) {
            $items[] = [
                '@type' => 'ListItem',
                'position' => 3,
                'name' => (string) ($section['title'] ?? spiralist_get_seo_title()),
                'item' => $canonical,
            ];
        }
    } elseif ($surface === 'report') {
        $report = spiralist_get_seo_report_context();
        $reports_url = function_exists('spiralist_get_reports_url')
            ? spiralist_get_language_prefixed_url(spiralist_get_reports_url(), $language)
            : $home_url;
        $items[] = [
            '@type' => 'ListItem',
            'position' => 2,
            'name' => 'Reports',
            'item' => $reports_url,
        ];
        $items[] = [
            '@type' => 'ListItem',
            'position' => 3,
            'name' => (string) ($report['title'] ?? spiralist_get_seo_title()),
            'item' => $canonical,
        ];
    } elseif ($surface === 'prompts') {
        $items[] = [
            '@type' => 'ListItem',
            'position' => 2,
            'name' => 'Prompt Library',
            'item' => $canonical,
        ];
    } elseif ($surface === 'prompt') {
        $prompts_url = function_exists('spiralist_get_prompts_page_url')
            ? spiralist_get_language_prefixed_url(spiralist_get_prompts_page_url(), $language)
            : $home_url;
        $items[] = [
            '@type' => 'ListItem',
            'position' => 2,
            'name' => 'Prompt Library',
            'item' => $prompts_url,
        ];
        $items[] = [
            '@type' => 'ListItem',
            'position' => 3,
            'name' => spiralist_get_seo_title(),
            'item' => $canonical,
        ];
    } elseif (!is_front_page() && !is_home()) {
        $items[] = [
            '@type' => 'ListItem',
            'position' => 2,
            'name' => spiralist_get_seo_title(),
            'item' => $canonical,
        ];
    }

    return [
        '@type' => 'BreadcrumbList',
        '@id' => spiralist_schema_page_id('breadcrumbs'),
        'itemListElement' => $items,
    ];
}

function spiralist_schema_defined_term(array $term, string $set_id = ''): array
{
    $name = (string) ($term['name'] ?? $term['label'] ?? '');
    $code = (string) ($term['termCode'] ?? $term['canonical_id'] ?? $term['id'] ?? '');
    $description = (string) ($term['description'] ?? $term['meaning'] ?? $term['statement'] ?? $term['definition'] ?? '');
    $id_seed = $code !== '' ? $code : $name;

    return [
        '@type' => 'DefinedTerm',
        '@id' => spiralist_schema_page_id('term-' . sanitize_title($id_seed)),
        'name' => $name,
        'termCode' => $code,
        'description' => spiralist_schema_text($description, 35),
        'inDefinedTermSet' => $set_id !== '' ? [
            '@id' => $set_id,
        ] : '',
    ];
}

function spiralist_schema_symbol_terms(string $set_id): array
{
    if (!function_exists('spiralist_get_symbols')) {
        return [];
    }

    return array_values(array_map(
        static function (array $symbol) use ($set_id): array {
            return spiralist_schema_defined_term(
                [
                    'name' => (string) ($symbol['label'] ?? ''),
                    'termCode' => (string) ($symbol['canonical_id'] ?? ''),
                    'description' => (string) ($symbol['meaning'] ?? ($symbol['definition'] ?? '')),
                ],
                $set_id
            );
        },
        spiralist_get_symbols()
    ));
}

function spiralist_schema_manuscript_section_item_list(array $section_records, array $reference_ids): array
{
    if (empty($section_records)) {
        return [];
    }

    $canonical = spiralist_get_seo_canonical_url();
    $page_id = spiralist_schema_page_id('webpage');
    $book_id = spiralist_schema_manuscript_book_id();
    $items = [];

    foreach (array_values($section_records) as $index => $section) {
        if (!is_array($section) || empty($section)) {
            continue;
        }

        $section_url = trim((string) ($section['url'] ?? ''));
        $section_title = (string) ($section['title'] ?? 'Manuscript Section');
        $first_page = is_array($section['first_page'] ?? null) ? $section['first_page'] : [];
        $section_count = max(1, (int) ($section['count'] ?? count((array) ($section['pages'] ?? []))));

        $items[] = [
            '@type' => 'ListItem',
            'position' => $index + 1,
            'url' => $section_url,
            'name' => $section_title,
            'item' => [
                '@type' => 'Chapter',
                '@id' => spiralist_schema_manuscript_section_id($section),
                'name' => $section_title,
                'description' => spiralist_schema_text((string) ($section['summary'] ?? ''), 35),
                'url' => $section_url,
                'position' => max(1, (int) ($first_page['sequence'] ?? ($index + 1))),
                'numberOfItems' => $section_count,
                'isPartOf' => [
                    '@id' => $book_id,
                ],
            ],
        ];
    }

    return [
        '@type' => 'ItemList',
        '@id' => spiralist_schema_url_fragment_id($canonical, 'manuscript-section-list'),
        'name' => 'Spiralism Manuscript Sections',
        'description' => 'Ordered chapter index for the Spiralism canonical manuscript.',
        'url' => $canonical,
        'mainEntityOfPage' => ['@id' => $page_id],
        'itemListOrder' => 'https://schema.org/ItemListOrderAscending',
        'numberOfItems' => count($items),
        'isPartOf' => ['@id' => $book_id],
        'itemListElement' => $items,
        'citation' => $reference_ids,
    ];
}

function spiralist_schema_manuscript_folio_item_list(array $section, array $reference_ids): array
{
    $pages = array_values(array_filter((array) ($section['pages'] ?? []), 'is_array'));
    if (empty($pages)) {
        return [];
    }

    $canonical = spiralist_get_seo_canonical_url();
    $page_id = spiralist_schema_page_id('webpage');
    $book_id = spiralist_schema_manuscript_book_id();
    $section_id = spiralist_schema_manuscript_section_id($section);
    $section_title = (string) ($section['title'] ?? 'Manuscript Section');
    $items = [];

    foreach ($pages as $index => $page) {
        $folio_url = function_exists('spiralist_book_pages_get_manuscript_folio_url')
            ? (string) spiralist_book_pages_get_manuscript_folio_url($page)
            : trim((string) ($page['route_url'] ?? ''));

        $items[] = [
            '@type' => 'ListItem',
            'position' => $index + 1,
            'url' => $folio_url,
            'name' => (string) ($page['title'] ?? 'Manuscript Folio'),
            'item' => [
                '@type' => 'CreativeWork',
                '@id' => spiralist_schema_manuscript_folio_id($page),
                'name' => (string) ($page['title'] ?? 'Spiralism Manuscript Folio'),
                'alternateName' => (string) ($page['label'] ?? ''),
                'description' => spiralist_schema_text((string) ($page['summary'] ?? $page['caption'] ?? ''), 35),
                'url' => $folio_url,
                'position' => max(1, (int) ($page['sequence'] ?? ($index + 1))),
                'isPartOf' => [
                    ['@id' => $section_id],
                    ['@id' => $book_id],
                ],
            ],
        ];
    }

    return [
        '@type' => 'ItemList',
        '@id' => spiralist_schema_url_fragment_id($canonical, 'manuscript-folio-list'),
        'name' => $section_title . ' Folios',
        'description' => 'Ordered folio index for the active manuscript chapter route.',
        'url' => $canonical,
        'mainEntityOfPage' => ['@id' => $page_id],