'success', 'pro' => 'danger', 'mixed' => 'warning', 'pro plugin' => 'warning' ); public static function applies( array $s ) { return self::NAME === (string) ( $s['_display'] ?? '' ); } public static function fold( array $sections ) { $out = array(); foreach ( array_values( $sections ) as $s ) { $prev = $out ? $out[ count( $out ) - 1 ] : null; if ( $prev && ! empty( $s['headless'] ) && self::folds( $prev, $s ) ) { $out[ count( $out ) - 1 ]['_parts'][] = $s; continue; } $out[] = $s; } return $out; } const PARTS = array( 'stats' => array( 'cards' ), 'cards' => array( 'gallery' ), 'prose' => array( 'cards' ) ); public static function folds( array $prev, array $s ) { $kind = (string) ( $s['kind'] ?? '' ); return 'pattern' !== $kind && ! AIEO_Content_Layout::applies( $s ) && ! AIEO_Content_Layout::applies( $prev ) && in_array( $kind, self::PARTS[ (string) ( $prev['kind'] ?? '' ) ] ?? array(), true ); } public static function render( array $s, array $media ) { switch ( (string) ( $s['kind'] ?? '' ) ) { case 'hero': return self::hero( $s ); case 'stats': return self::stats( $s ); case 'cards': return self::cards( $s, $media ); case 'gallery': return self::gallery( $s, $media ); case 'pricing': return self::pricing( $s ); case 'prose': return self::prose( $s ); case 'faq': return self::faq( $s ); case 'cta': return self::cta( $s ); } return ''; } private static function shell( array $s, $kind, $inner, array $box = array(), $extra_class = '' ) { $style = array( 'spacing' => array( 'margin' => array( 'top' => (string) ( $box['top'] ?? '0' ), 'bottom' => (string) ( $box['bottom'] ?? '0' ), 'left' => self::SIDE, 'right' => self::SIDE ), 'padding' => $box['padding'] ?? array( 'top' => (string) ( $box['pad'] ?? '60px' ), 'right' => '0', 'bottom' => '0', 'left' => '0' ), 'blockGap' => '0', ), ); if ( ! isset( $box['padding'] ) && '0' !== (string) ( $box['pad'] ?? '60px' ) ) { $style['@mobile'] = array( 'spacing' => array( 'padding' => array( 'top' => '44px' ) ) ); } $layout = isset( $box['center'] ) ? array( 'type' => 'constrained', 'contentSize' => (string) $box['center'], 'wideSize' => '100%' ) : array( 'type' => 'constrained', 'contentSize' => '74ch', 'wideSize' => '100%', 'justifyContent' => 'left' ); return AIEO_Content_Blocks::group( array( 'metadata' => self::metadata( $s, $kind ), 'anchor' => AIEO_Content_Sections::anchor( $s ), 'className' => 'rooster-r1 rooster-section--' . $kind . ( '' !== (string) $extra_class ? ' ' . $extra_class : '' ), 'style' => $style, 'layout' => $layout, ), $inner ); } public static function section( array $s, $kind, $layout ) { $center = 'center' === (string) ( $s['align'] ?? '' ); $head = empty( $s['headless'] ) ? self::head( $s, $center ) : ''; $tail = AIEO_Content_Sections::links( $s['links'] ?? null, $center ? array( 'align' => 'center' ) : array() ); $note = (string) ( $s['note'] ?? '' ); if ( ! empty( $s['buttons'] ) ) { $tail .= self::block( 'action', array( 'variant' => 'buttons', 'buttons' => self::cta_lines( (array) $s['buttons'] ) ) + ( $center ? array() : array( 'justify' => 'left' ) ), '28px' ); } $tail .= self::note( $note ); $box = ( $center ? array( 'center' => '74ch' ) : array() ) + ( '' !== trim( $note ) ? array( 'bottom' => '14px' ) : array() ); return self::shell( $s, $kind, AIEO_Content_Layout::place( $s, $head, $layout ) . $tail, $box, AIEO_Content_Sections::tone_class( $s ) ); } private static function metadata( array $s, $kind ) { $meta = AIEO_Content_Sections::metadata( $s, $kind ); $parts = array(); foreach ( (array) ( $s['_parts'] ?? array() ) as $part ) { $parts[] = array_filter( array( 'key' => (string) ( $part['key'] ?? '' ), 'kind' => (string) ( $part['kind'] ?? '' ), 'heading' => (string) ( $part['heading'] ?? '' ), 'level' => (int) ( $part['level'] ?? 0 ) ) ); } if ( $parts ) { $meta['rooster']['parts'] = $parts; } return $meta; } private static function style( array $type, $color, $top ) { $style = array(); if ( '' !== (string) $top ) { $style['spacing'] = array( 'margin' => array( 'top' => (string) $top, 'bottom' => '0' ) ); } $style['color'] = array( 'text' => $color ); if ( $type ) { $style['typography'] = $type; } return $style; } private static function head( array $s, $center = false ) { $inner = ''; $pill = AIEO_Content_Sections::is_pill( $s ); $align = $center ? array( 'align' => 'center' ) : array(); $id = static fn ( $target ) => '' !== AIEO_Content_Sections::alias( $s, $target ) ? array( 'anchor' => AIEO_Content_Sections::alias( $s, $target ) ) : array(); if ( ! empty( $s['icon'] ) && ! $pill ) { $inner .= AIEO_Content_Blocks::icon( (string) $s['icon'], '40px', 'rooster-section__icon' ); } if ( ! empty( $s['eyebrow'] ) ) { $inner .= AIEO_Content_Blocks::paragraph( $id( 'eyebrow' ) + $align + array( 'className' => 'rooster-eyebrow', 'style' => self::style( self::EYEBROW, self::MUTE, '' !== $inner ? '12px' : '0' ) ), AIEO_Content_Inline::html( (string) $s['eyebrow'] ) ); } if ( ! empty( $s['badge'] ) ) { $inner .= AIEO_Content_Blocks::paragraph( $id( 'badge' ) + $align + array( 'className' => 'rooster-badge', 'fontSize' => 'xs', 'style' => self::style( array(), self::MUTE, '' !== $inner ? '10px' : '0' ) ), AIEO_Content_Inline::html( (string) $s['badge'] ) ); } $heading = trim( (string) ( $s['heading'] ?? '' ) ); $level = (int) ( $s['level'] ?? 2 ); if ( '' !== $heading && empty( $s['headless'] ) && $pill ) { $inner .= AIEO_Content_Sections::pill( $s, $level, AIEO_Content_Inline::heading( $heading ), AIEO_Content_Sections::alias( $s, 'heading' ), $center ); } elseif ( '' !== $heading && empty( $s['headless'] ) ) { $role = AIEO_Content_Type::head_role( $level ); $type = 'h3' === $role ? AIEO_Content_Type::role( self::NAME, 'h3' ) : ( 'h1' === $role ? AIEO_Content_Type::role( self::NAME, 'h1' ) : self::H2 ); $inner .= AIEO_Content_Blocks::heading( array( 'level' => $level ) + $id( 'heading' ) + ( $center ? array( 'textAlign' => 'center' ) : array() ) + array( 'style' => self::style( $type, self::INK, '' !== $inner ? '10px' : '0' ) ), AIEO_Content_Inline::heading( $heading ) ); } if ( ! empty( $s['lede'] ) ) { $inner .= AIEO_Content_Inline::blocks( $s['lede'], $align + array( 'style' => self::style( self::LEDE, self::TEXT, '12px' ) ), AIEO_Content_Sections::lede_first( $s ) ); } if ( ! empty( $s['notice'] ) && ! AIEO_Content_Sections::notice_at_lede( $s ) ) { $inner .= AIEO_Content_Blocks::paragraph( $id( 'notice' ) + $align + array( 'className' => 'rooster-notice', 'fontSize' => 'sm', 'style' => self::style( array(), self::TEXT, '12px' ) ), AIEO_Content_Inline::html( (string) $s['notice'] ) ); } if ( '' === $inner ) { return ''; } return AIEO_Content_Blocks::group( array( 'metadata' => array( 'name' => __( 'Section head', 'ai-eshop-optimizer' ) ), 'templateLock' => 'contentOnly', 'lock' => array( 'move' => true, 'remove' => true ), ) + $id( 'head' ) + array( 'className' => 'rooster-section__head', 'style' => array( 'spacing' => array( 'blockGap' => '0' ) ), 'layout' => array( 'type' => 'default' ), ), $inner ); } private static function block( $name, array $attrs, $top = '' ) { $attrs['align'] = 'wide'; if ( '' !== (string) $top ) { $attrs['style'] = array( 'spacing' => array( 'margin' => array( 'top' => (string) $top ) ) ); } return AIEO_Content_Blocks::block( $name, $attrs ); } private static function note( $text ) { return '' !== trim( (string) $text ) ? self::block( 'mark', array( 'variant' => 'note', 'layout' => 'rule', 'text' => trim( (string) $text ) ), '18px' ) : ''; } private static function deferred( array $s, array $attrs, $height ) { if ( empty( $s['defer'] ) || ! in_array( (string) ( $s['kind'] ?? '' ), AIEO_Content_Sections::DEFERRABLE, true ) ) { return $attrs; } $label = AIEO_Content_Inline::heading_plain( (string) ( $s['heading'] ?? '' ) ); $attrs['roosterDefer'] = array( 'enabled' => true, 'height' => max( 160, (int) $height ) . 'px' ) + ( '' !== $label ? array( 'label' => $label ) : array() ); return $attrs; } private static function line( array $cells ) { return rtrim( implode( ' | ', array_map( static fn ( $c ) => trim( str_replace( array( "\r", "\n", '|' ), array( ' ', ' ', '/' ), (string) $c ) ), $cells ) ), ' |' ); } private static function tone( array $card ) { $tone = sanitize_key( (string) ( $card['tone'] ?? '' ) ); if ( '' !== $tone ) { return $tone; } return self::BADGE_TONES[ strtolower( trim( (string) ( $card['badge'] ?? '' ) ) ) ] ?? 'one'; } private static function cta_lines( array $buttons ) { $lines = array(); foreach ( array_values( $buttons ) as $i => $button ) { $style = (string) ( $button['style'] ?? ( 0 === $i ? 'primary' : 'secondary' ) ); $kind = 'outline' === $style ? 'light' : ( 'primary' === $style ? 'download' : 'dark' ); $href = (string) ( $button['href'] ?? '' ); if ( ! empty( $button['action'] ) && isset( AIEO_Content_Spec::BUTTON_ACTION_LINKS[ (string) $button['action'] ] ) ) { $href = AIEO_Content_Spec::BUTTON_ACTION_LINKS[ (string) $button['action'] ]; } $lines[] = self::line( array( AIEO_Content_Inline::plain( (string) ( $button['text'] ?? '' ) ), $href, $kind, AIEO_Content_Inline::plain( (string) ( $button['note'] ?? '' ) ), (string) ( $button['icon'] ?? '' ) ) ); } return implode( "\n", $lines ); } private static function hero( array $s ) { $inner = ''; if ( ! empty( $s['eyebrow'] ) ) { $attrs = array( 'variant' => 'pill', 'text' => AIEO_Content_Inline::plain( (string) $s['eyebrow'] ) ); if ( ! empty( $s['icon'] ) ) { $attrs['icon'] = sanitize_key( (string) $s['icon'] ); } $inner .= self::block( 'mark', $attrs ); } $heading = trim( (string) ( $s['heading'] ?? '' ) ); if ( '' !== $heading ) { $html = implode( '
', array_map( array( 'AIEO_Content_Inline', 'html' ), preg_split( '/\r\n|\r|\n/', $heading ) ?: array() ) ); $emphasis = trim( (string) ( $s['emphasis'] ?? '' ) ); if ( '' !== $emphasis ) { $words = esc_html( $emphasis ); $pos = strrpos( $html, $words ); if ( false !== $pos ) { $html = substr_replace( $html, '' . $words . '', $pos, strlen( $words ) ); } } $inner .= AIEO_Content_Blocks::heading( array( 'level' => 1, 'textAlign' => 'center', 'align' => 'wide', 'style' => self::style( self::H1, self::INK, '' !== $inner ? '18px' : '0' ) ), $html ); } if ( ! empty( $s['lede'] ) ) { $inner .= AIEO_Content_Inline::blocks( $s['lede'], array( 'align' => 'center', 'style' => self::style( self::LEDE, self::TEXT, '18px' ) ) ); } $buttons = (array) ( $s['buttons'] ?? array() ); if ( $buttons || ! empty( $s['note'] ) ) { $attrs = array( 'variant' => 'buttons', 'buttons' => self::cta_lines( $buttons ) ); if ( ! empty( $s['note'] ) ) { $attrs['note'] = (string) $s['note']; } $inner .= self::block( 'action', $attrs, '30px' ); } return self::shell( $s, 'hero', $inner, array( 'top' => '40px', 'padding' => array( 'top' => '16px', 'right' => '8px', 'bottom' => '44px', 'left' => '8px' ), 'center' => '760px' ) ); } private static function stats( array $s ) { $items = array(); foreach ( (array) ( $s['items'] ?? $s['stats'] ?? array() ) as $item ) { $items[] = self::line( array( (string) ( $item['value'] ?? '' ), (string) ( $item['label'] ?? '' ), (string) ( $item['tone'] ?? '' ) ) ); } if ( ! $items ) { return ''; } $headed = '' !== trim( (string) ( $s['heading'] ?? '' ) ) && empty( $s['headless'] ); if ( ! $headed ) { $inner = self::block( 'list', array( 'variant' => 'facts', 'layout' => 'counters', 'items' => implode( "\n", $items ) ) ) . self::note( (string) ( $s['note'] ?? '' ) ); return self::shell( $s, 'stats', $inner, array( 'pad' => '0', 'bottom' => ! empty( $s['note'] ) ? '14px' : '0' ) ); } $inner = self::head( $s ) . self::block( 'list', array( 'variant' => 'facts', 'layout' => 'tally', 'items' => implode( "\n", $items ) ), '28px' ); $after = '18px'; $note = (string) ( $s['note'] ?? '' ); foreach ( (array) ( $s['_parts'] ?? array() ) as $part ) { if ( 'cards' === (string) ( $part['kind'] ?? '' ) ) { $inner .= self::panels( $part, $after ); } if ( ! empty( $part['note'] ) ) { $note = (string) $part['note']; } } $inner .= self::note( $note ); return self::shell( $s, 'stats', $inner, array( 'bottom' => '' !== trim( $note ) ? '14px' : '0' ) ); } private static function panels( array $s, $top ) { $cards = array_values( (array) ( $s['cards'] ?? array() ) ); $row = 'row' === (string) ( $s['layout'] ?? '' ) || 2 === count( $cards ); $lines = array(); $chips = false; foreach ( $cards as $card ) { $tone = self::tone( $card ); $flags = array(); if ( ! $row ) { $flags[] = 'top'; } elseif ( 'danger' === $tone ) { $flags[] = 'neg'; } elseif ( 'one' === $tone ) { $flags[] = 'pos'; $flags[] = 'edge'; } $lines[] = '# ' . self::line( array( AIEO_Content_Inline::plain( (string) ( $card['badge'] ?? '' ) ), $tone, (string) ( $card['title'] ?? '' ), implode( ' ', $flags ) ) ); if ( ! empty( $card['chips'] ) ) { $chips = true; $lines[] = ( 'one' === $tone ? '~! ' : '~ ' ) . self::line( array_map( 'strval', (array) $card['chips'] ) ); } foreach ( preg_split( '/\r\n|\r|\n/', trim( (string) ( $card['text'] ?? '' ) ) ) ?: array() as $text ) { if ( '' !== trim( $text ) ) { $lines[] = trim( $text ); } } } $columns = ! $row ? '3' : ( $chips ? 'wide' : '2' ); return self::block( 'card', self::deferred( $s, array( 'variant' => 'tagged', 'columns' => $columns, 'items' => implode( "\n", $lines ) ), 330 * count( $cards ) ), $top ); } private static function cards( array $s, array $media ) { $cards = array_values( (array) ( $s['cards'] ?? array() ) ); if ( ! $cards ) { return ''; } $style = (string) ( $s['style'] ?? '' ); $first = $cards[0]; if ( in_array( $style, array( 'contrast', 'dark' ), true ) ) { $lines = array(); foreach ( $cards as $card ) { $lines[] = self::line( array( AIEO_Content_Inline::plain( (string) ( $card['title'] ?? '' ) ), (string) ( $card['text'] ?? '' ), ! empty( $card['highlighted'] ) ? 'hi' : '' ) ); } $attrs = array( 'variant' => 'stack', 'eyebrow' => AIEO_Content_Inline::plain( (string) ( $s['eyebrow'] ?? '' ) ), 'heading' => AIEO_Content_Inline::plain( (string) ( $s['heading'] ?? '' ) ), 'text' => is_array( $s['lede'] ?? null ) ? implode( "\n\n", $s['lede'] ) : (string) ( $s['lede'] ?? '' ), 'items' => implode( "\n", $lines ), ); return self::shell( $s, 'cards', self::block( 'media', array_filter( $attrs, 'strlen' ) ) ); } $inner = self::head( $s ); if ( ! empty( $first['colour'] ) && empty( $first['icon'] ) ) { $lines = array(); foreach ( $cards as $card ) { $ink = array_values( array_filter( preg_split( '/[\s,]+/', (string) ( $card['ink'] ?? '' ) ) ?: array(), 'strlen' ) ); $lines[] = self::line( array( AIEO_Content_Inline::plain( (string) ( $card['badge'] ?? '' ) ), self::tone( $card ), AIEO_Content_Inline::plain( (string) ( $card['title'] ?? '' ) ), (string) ( $card['text'] ?? '' ), (string) $card['colour'], (string) ( $ink[0] ?? '' ), (string) ( $ink[1] ?? '' ), 'row' === (string) ( $card['layout'] ?? '' ) ? 'wide' : '' ) ); } $inner .= self::block( 'table', self::deferred( $s, array( 'variant' => 'matrix', 'items' => implode( "\n", $lines ), 'level' => 3 ), 110 * count( $cards ) ), '28px' ); } elseif ( ! empty( $first['colour'] ) ) { $lines = array(); foreach ( $cards as $card ) { $lines[] = self::line( array( (string) ( $card['icon'] ?? '' ), AIEO_Content_Inline::plain( (string) ( $card['badge'] ?? '' ) ), AIEO_Content_Inline::plain( (string) ( $card['title'] ?? '' ) ), (string) ( $card['text'] ?? '' ), (string) $card['colour'] ) ); } $inner .= self::block( 'card', self::deferred( $s, array( 'variant' => 'role', 'items' => implode( "\n", $lines ), 'level' => 3 ), 190 * count( $cards ) ), '28px' ); } elseif ( ! empty( $s['numbered'] ) && empty( $first['badge'] ) ) { $lines = array(); foreach ( $cards as $card ) { $lines[] = self::line( array( AIEO_Content_Inline::plain( (string) ( $card['title'] ?? '' ) ), (string) ( $card['text'] ?? '' ) ) ); } $inner .= self::block( 'card', self::deferred( $s, array( 'variant' => 'grid', 'layout' => 'steps-plain', 'items' => implode( "\n", $lines ) ), 150 * count( $cards ) ), '28px' ); } elseif ( ! empty( $s['numbered'] ) ) { $lines = array(); foreach ( $cards as $card ) { $lines[] = '# ' . self::line( array( AIEO_Content_Inline::plain( (string) ( $card['badge'] ?? '' ) ), self::tone( $card ), (string) ( $card['title'] ?? '' ) ) ); foreach ( preg_split( '/\n\s*\n/', trim( (string) ( $card['text'] ?? '' ) ) ) ?: array() as $para ) { if ( '' !== trim( $para ) ) { $lines[] = trim( str_replace( array( "\r", "\n" ), ' ', $para ) ); } } } $inner .= self::block( 'card', self::deferred( $s, array( 'variant' => 'tagged', 'layout' => 'numbered', 'items' => implode( "\n", $lines ) ), 330 * count( $cards ) ), '28px' ); } elseif ( ! empty( $first['badge'] ) ) { $inner .= self::panels( $s, '28px' ); } else { return ''; } $parts = ''; foreach ( (array) ( $s['_parts'] ?? array() ) as $part ) { if ( 'gallery' === (string) ( $part['kind'] ?? '' ) ) { foreach ( (array) ( $part['items'] ?? array() ) as $item ) { $parts .= self::figure( (array) $item, $media, '20px' ); } } } $note = (string) ( $s['note'] ?? '' ); return self::shell( $s, 'cards', $inner . $parts . self::note( $note ), array( 'bottom' => '' !== trim( $note ) ? '14px' : '0' ) ); } private static function figure( array $item, array $media, $top ) { $path = (string) ( $item['src'] ?? $item['path'] ?? '' ); $id = (int) ( $media[ $path ]['id'] ?? 0 ); $attrs = array( 'variant' => 'figure', 'desktopId' => $id ); foreach ( array( 'alt' => 'desktopAlt', 'caption' => 'caption' ) as $key => $attr ) { if ( '' !== trim( (string) ( $item[ $key ] ?? '' ) ) ) { $attrs[ $attr ] = 'caption' === $key ? trim( (string) $item[ $key ] ) : AIEO_Content_Inline::plain( (string) $item[ $key ] ); } } foreach ( array( 'width', 'height' ) as $key ) { if ( ! empty( $item[ $key ] ) ) { $attrs[ $key ] = (int) $item[ $key ]; } } return self::block( 'media', $attrs, $top ); } private static function gallery( array $s, array $media ) { $items = (array) ( $s['items'] ?? array() ); if ( ! $items ) { return ''; } $inner = self::head( $s ); foreach ( array_values( $items ) as $i => $item ) { $inner .= self::figure( (array) $item, $media, 0 === $i ? ( '' !== $inner ? '28px' : '0' ) : '20px' ); } return self::shell( $s, 'gallery', $inner ); } private static function pricing( array $s ) { $tiers = array_values( (array) ( $s['tiers'] ?? array() ) ); if ( ! $tiers ) { return ''; } $cards = ''; foreach ( $tiers as $tier ) { $attrs = array( 'variant' => 'plan', 'name' => AIEO_Content_Inline::plain( (string) ( $tier['name'] ?? '' ) ), 'price' => AIEO_Content_Inline::plain( (string) ( $tier['price'] ?? '' ) ), 'period' => AIEO_Content_Inline::plain( (string) ( $tier['period'] ?? '' ) ), 'note' => (string) ( $tier['note'] ?? '' ), 'features' => implode( "\n", array_map( static fn ( $f ) => str_replace( array( "\r", "\n" ), ' ', (string) $f ), (array) ( $tier['features'] ?? array() ) ) ), 'ctaText' => AIEO_Content_Inline::plain( (string) ( $tier['ctaText'] ?? '' ) ), 'ctaHref' => (string) ( $tier['ctaHref'] ?? '' ), 'layout' => 'tier', 'tone' => self::tone( $tier + array( 'badge' => '' ) ), 'tagline' => AIEO_Content_Inline::plain( (string) ( $tier['tagline'] ?? '' ) ), ); $volume = (array) ( $tier['volume'] ?? array() ); if ( $volume ) { $rows = array( self::line( array_map( 'strval', (array) ( $volume['columns'] ?? array() ) ) ) ); foreach ( (array) ( $volume['rows'] ?? array() ) as $row ) { $rows[] = self::line( array_map( 'strval', (array) $row ) ); } $attrs['volume'] = implode( "\n", $rows ); $attrs['volumeCaption'] = AIEO_Content_Inline::plain( (string) ( $volume['caption'] ?? '' ) ); $attrs['volumeNote'] = AIEO_Content_Inline::plain( (string) ( $volume['note'] ?? '' ) ); } if ( ! empty( $tier['anchor'] ) ) { $attrs['anchor'] = sanitize_title( (string) $tier['anchor'] ); } $cards .= AIEO_Content_Blocks::block( 'plan', array_filter( $attrs, static fn ( $v ) => '' !== $v ) ); } $grid = AIEO_Content_Blocks::group( array( 'metadata' => array( 'name' => __( 'Plans', 'ai-eshop-optimizer' ) ), 'lock' => array( 'move' => true, 'remove' => true ), 'align' => 'wide', 'style' => array( 'spacing' => array( 'margin' => array( 'top' => '28px', 'bottom' => '0' ), 'blockGap' => '18px' ) ), 'layout' => array( 'type' => 'grid', 'columnCount' => min( 3, count( $tiers ) ), 'minimumColumnWidth' => '12rem' ), ), $cards ); $note = (string) ( $s['note'] ?? '' ); return self::shell( $s, 'pricing', self::head( $s ) . $grid . self::note( $note ), array( 'bottom' => '' !== trim( $note ) ? '14px' : '0' ) ); } private static function prose( array $s ) { $body = trim( (string) ( $s['body'] ?? '' ) ); $parts = (array) ( $s['_parts'] ?? array() ); $stage = null; foreach ( $parts as $part ) { if ( 'cards' === (string) ( $part['kind'] ?? '' ) && ! empty( $part['numbered'] ) ) { $stage = $part; } } if ( $stage ) { $heading = ''; $text = array(); foreach ( preg_split( '/\n\s*\n/', $body ) ?: array() as $para ) { if ( preg_match( '/^#{2,4}\s+(.+)$/u', trim( $para ), $m ) ) { $heading = $m[1]; } elseif ( '' !== trim( $para ) ) { $text[] = trim( $para ); } } $lines = array(); foreach ( (array) ( $stage['cards'] ?? array() ) as $card ) { $lines[] = self::line( array( AIEO_Content_Inline::plain( (string) ( $card['badge'] ?? '' ) ), self::tone( $card ), AIEO_Content_Inline::plain( (string) ( $card['title'] ?? '' ) ), AIEO_Content_Inline::plain( (string) ( $card['kicker'] ?? '' ) ), (string) ( $card['text'] ?? '' ) ) ); } $attrs = array( 'variant' => 'stages', 'heading' => AIEO_Content_Inline::plain( $heading ), 'text' => implode( "\n\n", $text ), 'items' => implode( "\n", $lines ), 'note' => (string) ( $stage['note'] ?? '' ), ); return self::shell( $s, 'prose', self::head( $s ) . self::block( 'list', array_filter( $attrs, 'strlen' ), '28px' ) ); } if ( ! empty( $s['buttons'] ) && '' !== $body ) { $buttons = array(); foreach ( (array) $s['buttons'] as $button ) { $cells = array( AIEO_Content_Inline::plain( (string) ( $button['text'] ?? '' ) ), (string) ( $button['href'] ?? '' ) ); if ( '' !== (string) ( $button['icon'] ?? '' ) ) { array_push( $cells, '', sanitize_key( (string) $button['icon'] ) ); } $buttons[] = self::line( $cells ); } $attrs = array( 'variant' => 'panel', 'layout' => 'wash', 'eyebrow' => AIEO_Content_Inline::plain( (string) ( $s['eyebrow'] ?? '' ) ), 'heading' => AIEO_Content_Inline::plain( (string) ( $s['heading'] ?? '' ) ), 'text' => $body, 'buttons' => implode( "\n", $buttons ), ); return self::shell( $s, 'prose', self::block( 'action', array_filter( $attrs, 'strlen' ) ) ); } return ''; } private static function faq( array $s ) { $items = array(); foreach ( (array) ( $s['items'] ?? array() ) as $item ) { $line = self::line( array( AIEO_Content_Inline::plain( (string) ( $item['q'] ?? '' ) ), (string) ( $item['a'] ?? '' ) ) ); $items[] = str_contains( $line, '|' ) ? $line : $line . ' |'; } if ( ! $items ) { return ''; } $inner = self::head( $s ) . self::block( 'questions', self::deferred( $s, array( 'variant' => 'boxed', 'items' => implode( "\n", $items ) ), 60 * count( $items ) + 80 ), '28px' ); return self::shell( $s, 'faq', $inner, array( 'bottom' => '8px' ) ); } private static function cta( array $s ) { $attrs = array( 'variant' => 'panel', 'layout' => 'ink', 'heading' => AIEO_Content_Inline::plain( (string) ( $s['heading'] ?? '' ) ), 'text' => (string) ( $s['text'] ?? $s['lede'] ?? '' ), 'buttons' => self::cta_lines( (array) ( $s['buttons'] ?? array() ) ), 'note' => (string) ( $s['note'] ?? '' ), ); return self::shell( $s, 'cta', self::block( 'action', array_filter( $attrs, 'strlen' ) ), array( 'bottom' => '24px' ) ); } }