AIEO_Content_Sections::padding_value( $v ); $style = array( 'spacing' => array( 'padding' => array( 'top' => $value( $pad[0] ), 'bottom' => $value( $pad[1] ) ), 'margin' => array( 'top' => '0', 'bottom' => '0' ) ), '@mobile' => array( 'spacing' => array( 'padding' => array( 'top' => $value( $pad[2] ), 'bottom' => $value( $pad[3] ) ) ) ), ); if ( 'subtle' === (string) ( $s['style'] ?? '' ) && 'none' !== $rules ) { $line = array( 'color' => self::TINT_LINE, 'style' => 'solid', 'width' => '1px' ); $style['border'] = 'top' === $rules ? array( 'top' => $line ) : array( 'top' => $line, 'bottom' => $line ); } $attrs = array( 'metadata' => AIEO_Content_Sections::metadata( $s, $kind ), 'align' => 'full', 'anchor' => AIEO_Content_Sections::anchor( $s ), 'className' => trim( AIEO_Content_Sections::classes( $s, $kind ) . ( '' !== $extra_class ? ' ' . $extra_class : '' ) ), 'style' => AIEO_Content_Sections::padded( $s, $style ), 'layout' => array( 'type' => 'constrained' ), ); if ( ! empty( $s['_nested'] ) ) { unset( $attrs['align'] ); } return AIEO_Content_Blocks::group( $attrs, $inner ); } public static function section( array $s, $kind, $layout ) { $center = 'center' === (string) ( $s['align'] ?? '' ); $head = empty( $s['headless'] ) ? self::head( $s, array( 'center' => $center ) ) : ''; return self::shell( $s, $kind, AIEO_Content_Layout::place( $s, $head, $layout ) . self::tail( $s, $center ) ); } private static function tail( array $s, $center ) { $out = AIEO_Content_Sections::links( $s['links'] ?? null, $center ? array( 'align' => 'center' ) : array() ); $out .= self::buttons( (array) ( $s['buttons'] ?? array() ), '2.5rem', $center ? 'center' : 'left' ); if ( ! empty( $s['note'] ) ) { $out .= self::measure( __( 'Note', 'ai-eshop-optimizer' ), '48rem', '1.5rem', AIEO_Content_Inline::blocks( $s['note'], ( $center ? array( 'align' => 'center' ) : array() ) + array( 'className' => 'rooster-section__note', 'textColor' => 'muted', 'fontSize' => 'sm', 'style' => array( 'typography' => array( 'lineHeight' => '1.625' ) ) ) ), $center ); } return $out; } private static function eyebrow( $text, array $margin = array(), array $extra = array() ) { $style = array( 'typography' => self::EYEBROW ); if ( $margin ) { $style = array( 'spacing' => array( 'margin' => $margin ) ) + $style; } return AIEO_Content_Blocks::paragraph( $extra + array( 'className' => 'rooster-eyebrow', 'textColor' => 'accent-text', 'fontSize' => 'sm', 'style' => $style ), AIEO_Content_Inline::html( (string) $text ) ); } private static function heading( $html, $level, array $type, $margin, array $extra = array() ) { $style = array( 'typography' => $type ); if ( '' !== (string) $margin ) { $style = array( 'spacing' => array( 'margin' => array( 'top' => (string) $margin ) ) ) + $style; } return AIEO_Content_Blocks::heading( array( 'level' => (int) $level ) + $extra + array( 'textColor' => 'contrast', 'style' => $style ), $html ); } private static function measure( $name, $width, $margin, $inner, $center = false ) { $attrs = array( 'metadata' => array( 'name' => $name ) ); if ( '' !== (string) $margin ) { $attrs['style'] = array( 'spacing' => array( 'margin' => array( 'top' => (string) $margin ) ) ); } $attrs['layout'] = $center ? array( 'type' => 'constrained', 'contentSize' => (string) $width ) : array( 'type' => 'constrained', 'contentSize' => (string) $width, 'justifyContent' => 'left' ); return AIEO_Content_Blocks::group( $attrs, $inner ); } private static function head( array $s, array $opts = array() ) { $inner = ''; $center = ! empty( $opts['center'] ); $align = $center ? array( 'align' => 'center' ) : array(); $pill = AIEO_Content_Sections::is_pill( $s ); $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'] ) && empty( $opts['no_eyebrow'] ) ) { $inner .= self::eyebrow( (string) $s['eyebrow'], '' !== $inner ? array( 'top' => '0.75rem' ) : array(), $id( 'eyebrow' ) + $align ); } if ( ! empty( $s['badge'] ) ) { $inner .= AIEO_Content_Blocks::paragraph( $id( 'badge' ) + $align + array( 'className' => 'rooster-badge', 'fontSize' => 'xs', 'style' => array( 'spacing' => array( 'margin' => array( 'top' => '0.75rem' ) ) ) ), AIEO_Content_Inline::html( (string) $s['badge'] ) ); } $heading = trim( (string) ( $s['heading'] ?? '' ) ); if ( '' !== $heading && empty( $s['headless'] ) && $pill ) { $inner .= AIEO_Content_Sections::pill( $s, (int) ( $s['level'] ?? 2 ), AIEO_Content_Inline::heading( $heading ), AIEO_Content_Sections::alias( $s, 'heading' ), $center ); } elseif ( '' !== $heading && empty( $s['headless'] ) ) { $level = (int) ( $s['level'] ?? 2 ); $role = AIEO_Content_Type::head_role( $level ); $type = (array) ( $opts['type'] ?? ( 'h3' === $role ? AIEO_Content_Type::role( self::NAME, 'h3' ) : ( 'h1' === $role ? self::H1 : self::H2 ) ) ); $inner .= self::heading( AIEO_Content_Inline::heading( $heading ), $level, $type, (string) ( $opts['margin'] ?? '0.75rem' ), $id( 'heading' ) + ( $center ? array( 'textAlign' => 'center' ) : array() ) ); } if ( ! empty( $s['lede'] ) ) { $inner .= self::measure( __( 'Lede', 'ai-eshop-optimizer' ), '48rem', '1rem', AIEO_Content_Inline::blocks( $s['lede'], $align + array( 'textColor' => 'contrast-2', 'style' => array( 'typography' => self::LEDE ) ), AIEO_Content_Sections::lede_first( $s ) ), $center ); } 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' => array( 'spacing' => array( 'margin' => array( 'top' => '1rem' ) ) ) ), 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' . ( $center ? '' : ' rooster-align-start' ), 'style' => array( 'spacing' => array( 'blockGap' => '0' ) ), 'layout' => $center ? array( 'type' => 'constrained' ) : array( 'type' => 'constrained', 'justifyContent' => 'left' ), ), $inner ); } private static function block( $name, array $attrs, $margin = '', $wide = true ) { if ( $wide ) { $attrs['align'] = 'wide'; } if ( '' !== (string) $margin ) { $attrs['style'] = array( 'spacing' => array( 'margin' => array( 'top' => (string) $margin ) ) ); } return AIEO_Content_Blocks::block( $name, $attrs ); } 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 estimate( $block, array $items ) { $lines = static fn ( $text, $per_line ) => max( 1, (int) ceil( mb_strlen( AIEO_Content_Inline::plain( (string) $text ) ) / $per_line ) ); $h = 0; $widths = array(); if ( 'data-table' === $block && $items ) { $longest = array(); $word = array(); foreach ( $items as $row ) { foreach ( array_values( (array) $row ) as $c => $cell ) { $cell = is_string( $cell ) ? AIEO_Content_Inline::plain( $cell ) : ''; $longest[ $c ] = max( $longest[ $c ] ?? 3, mb_strlen( $cell ) ); foreach ( preg_split( '/\s+/u', $cell ) ?: array() as $w ) { $word[ $c ] = max( $word[ $c ] ?? 3, mb_strlen( $w ) ); } } } $sum = array_sum( $longest ) ?: 1; foreach ( $longest as $c => $n ) { $widths[ $c ] = max( 7.5 * $word[ $c ], 464 * $n / $sum ); } $scale = 464 / ( array_sum( $widths ) ?: 464 ); foreach ( $widths as $c => $w ) { $widths[ $c ] = $w * min( 1, $scale ) < 7.5 * $word[ $c ] ? 7.5 * $word[ $c ] : $w * $scale; } } foreach ( array_values( $items ) as $i => $item ) { $item = is_array( $item ) ? $item : array( 'title' => (string) $item ); switch ( $block ) { case 'card-grid': case 'steps': $h += ( 'steps' === $block ? 36 : 44 ) + 74 + 28 * $lines( $item['title'] ?? '', 33 ) + 26 * $lines( $item['text'] ?? '', 42 ) + ( $i ? 24 : 0 ); break; case 'link-cards': $h += 58 + 19.25 * $lines( $item['text'] ?? '', 48 ) + ( $i ? 16 : 0 ); break; case 'question-list': $h += 25 + 24 * $lines( explode( ' | ', (string) ( $item['title'] ?? '' ) )[0], 36 ) + ( $i ? 1 : 0 ); break; case 'data-table': $cells = array_values( array_map( static fn ( $c ) => is_string( $c ) && ! in_array( $c, array( 'yes', 'no' ), true ) ? AIEO_Content_Inline::plain( $c ) : '', (array) $item ) ); $most = 1; foreach ( $cells as $c => $cell ) { $most = max( $most, $lines( $cell, max( 8, (int) floor( ( $widths[ $c ] ?? 150 ) / 7 ) ) ) ); } $h += 24 + 20 * $most + ( in_array( 'yes', (array) $item, true ) ? 4.5 : 0 ) + 1; break; case 'detail-cards': $h += 70 + ( $i ? 16 : 0 ); if ( 0 === $i ) { foreach ( (array) ( $item['items'] ?? array() ) as $j => $entry ) { $entry = is_array( $entry ) ? $entry : array( 'title' => (string) $entry ); $h += 22 * $lines( $entry['title'] ?? '', 32 ) + 20 * ( '' !== (string) ( $entry['text'] ?? '' ) ? $lines( $entry['text'], 40 ) : 0 ) + ( $j ? 12 : 33 ); } } break; } } return (int) round( $h + ( 'data-table' === $block ? 46 : 0 ) ); } private static function line( array $cells, array $marked = array() ) { $out = array(); foreach ( array_values( $cells ) as $i => $c ) { $c = in_array( $i, $marked, true ) ? (string) $c : AIEO_Content_Inline::plain( (string) $c ); $out[] = trim( str_replace( array( "\r", "\n", '|' ), array( ' ', ' ', '/' ), $c ) ); } return rtrim( implode( ' | ', $out ), ' |' ); } private static function buttons( array $buttons, $margin, $justify = 'left' ) { $rows = array(); $outline = false; foreach ( array_values( $buttons ) as $i => $button ) { $style = (string) ( $button['style'] ?? ( 0 === $i ? 'primary' : 'outline' ) ); if ( in_array( $style, array( 'secondary', 'outline' ), true ) ) { $outline = true; } } foreach ( array_values( $buttons ) as $i => $button ) { $style = (string) ( $button['style'] ?? ( 0 === $i ? 'primary' : 'outline' ) ); $is_out = in_array( $style, array( 'secondary', 'outline' ), true ); $href = (string) ( $button['href'] ?? '' ); $host = (string) wp_parse_url( $href, PHP_URL_HOST ); $external = ! empty( $button['external'] ) || ( '' !== $host && $host !== (string) wp_parse_url( home_url( '/' ), PHP_URL_HOST ) ); $class = array(); if ( ! $external && '' !== AIEO_Content_Blocks::button_icon_style( 'arrow-right' ) ) { $class[] = AIEO_Content_Blocks::button_icon_style( 'arrow-right' ); } $edge = $is_out ? '0.625rem' : ( $outline ? '0.6875rem' : '0.625rem' ); $attrs = array( 'style' => array( 'color' => $is_out ? array( 'background' => 'light-dark(var(--wp--preset--color--bg), transparent)' ) : array( 'text' => 'var(--wp--preset--color--bg)', 'background' => 'light-dark(var(--wp--preset--color--contrast), var(--wp--preset--color--accent))' ), 'border' => $is_out ? array( 'color' => 'color-mix(in srgb, var(--wp--preset--color--contrast) 15%, transparent)', 'radius' => '0.5rem', 'style' => 'solid', 'width' => '1px' ) : array( 'radius' => '0.5rem' ), 'spacing' => array( 'padding' => array( 'left' => '1.25rem', 'right' => '1.25rem', 'top' => $edge, 'bottom' => $edge ) ), 'typography' => array( 'fontWeight' => '600', 'lineHeight' => '1.5' ), ), ); if ( ! $is_out && $outline ) { $attrs['style']['@mobile'] = array( 'spacing' => array( 'padding' => array( 'top' => '0.625rem', 'bottom' => '0.625rem' ) ) ); } $row = array( 'text' => AIEO_Content_Inline::plain( (string) ( $button['text'] ?? '' ) ), 'href' => $href, 'style' => $is_out ? 'outline' : 'primary', 'class' => implode( ' ', $class ), 'fontSize' => 'md', 'attrs' => $attrs ); if ( $is_out ) { $row['textColor'] = 'contrast'; } if ( $external && false !== ( $button['new_tab'] ?? null ) ) { $row['external'] = true; } if ( '' !== AIEO_Content_Blocks::button_icon_class( (string) ( $button['icon'] ?? '' ) ) ) { $row['icon'] = sanitize_key( (string) $button['icon'] ); } if ( ! empty( $button['action'] ) && isset( AIEO_Content_Spec::BUTTON_ACTIONS[ (string) $button['action'] ] ) ) { $row['class'] = trim( $row['class'] . ' ' . AIEO_Content_Spec::BUTTON_ACTIONS[ (string) $button['action'] ] ); $row['href'] = AIEO_Content_Spec::BUTTON_ACTION_LINKS[ (string) $button['action'] ] ?? '#'; } $rows[] = $row; } if ( ! $rows ) { return ''; } return AIEO_Content_Blocks::buttons( array( 'style' => array( 'spacing' => array( 'blockGap' => 'var:preset|spacing|3', 'margin' => array( 'top' => (string) $margin ) ), '@mobile' => array( 'layout' => array( 'type' => 'flex', 'orientation' => 'vertical', 'justifyContent' => 'stretch' ) ), ), 'layout' => array( 'type' => 'flex', 'justifyContent' => (string) $justify ), ), $rows ); } private static function hero( array $s, array $media ) { $text = ''; $family = sanitize_key( (string) ( $s['family'] ?? $s['_family'] ?? '' ) ); if ( '' !== $family ) { $text .= AIEO_Content_Blocks::block( 'mark', array( 'variant' => 'crumb', 'family' => $family ) ); } if ( ! empty( $s['eyebrow'] ) ) { $text .= self::eyebrow( (string) $s['eyebrow'], array( 'top' => '1rem' ) ); } if ( ! empty( $s['heading'] ) ) { $text .= self::heading( AIEO_Content_Inline::heading( (string) $s['heading'] ), 1, self::H1, '0.75rem' ); } if ( ! empty( $s['lede'] ) ) { $text .= self::measure( __( 'Lede', 'ai-eshop-optimizer' ), '42rem', '1.25rem', AIEO_Content_Inline::blocks( $s['lede'], array( 'textColor' => 'contrast-2', 'style' => array( 'typography' => self::HERO_LEDE ) ) ) ); } $text .= self::buttons( (array) ( $s['buttons'] ?? array() ), '2rem' ); $facts = array(); foreach ( (array) ( $s['strip'] ?? array() ) as $stat ) { $facts[] = self::line( array( (string) ( $stat['value'] ?? '' ), (string) ( $stat['label'] ?? '' ) ), array( 1 ) ); } if ( $facts ) { $text .= self::block( 'list', array( 'variant' => 'facts', 'items' => implode( "\n", $facts ) ), '2.5rem', false ); } $copy = AIEO_Content_Blocks::group( array( 'metadata' => array( 'name' => __( 'Hero text', 'ai-eshop-optimizer' ) ), 'templateLock' => 'contentOnly', 'lock' => array( 'move' => true, 'remove' => true ), 'className' => 'rooster-hero__copy rooster-align-start', 'style' => array( 'spacing' => array( 'blockGap' => '0' ) ), 'layout' => array( 'type' => 'constrained', 'justifyContent' => 'left' ), ), $text ); $image = (array) ( $s['image'] ?? array() ); $side = static fn ( $v ) => is_array( $v ) ? (string) ( $v['src'] ?? '' ) : (string) $v; $frame = array(); $path = $side( $image['desktop'] ?? $image['src'] ?? '' ); if ( '' !== $path && (int) ( $media[ $path ]['id'] ?? 0 ) ) { $frame['desktopId'] = (int) $media[ $path ]['id']; $mobile = $side( $image['mobile'] ?? '' ); if ( '' !== $mobile && (int) ( $media[ $mobile ]['id'] ?? 0 ) ) { $frame['mobileId'] = (int) $media[ $mobile ]['id']; } if ( ! empty( $image['alt'] ) ) { $frame['desktopAlt'] = (string) $image['alt']; } $frame['sizes'] = '(max-width: 1023px) calc(100vw - 32px), 457px'; $frame['priority'] = 'high'; } if ( ! empty( $s['motif'] ) ) { $frame['motif'] = (string) $s['motif']; } $media_html = $frame ? AIEO_Content_Blocks::block( 'media', array( 'variant' => 'frame' ) + $frame ) : ''; $inner = '' !== $media_html ? AIEO_Content_Sections::columns( AIEO_Content_Sections::column( $copy, '56.8866%', 'rooster-hero__text' ), AIEO_Content_Sections::column( $media_html, '39.6412%', 'rooster-hero__media' ), array( 'className' => 'rooster-hero__columns rooster-align-start', 'style' => array( 'spacing' => array( 'blockGap' => array( 'top' => '2.5rem', 'left' => '2.5rem' ) ) ) ) ) : $copy; $style = AIEO_Content_Sections::padded( $s, array( 'color' => array( 'gradient' => 'radial-gradient(60% 60% at 70% 20%,light-dark(color-mix(in srgb, var(--wp--preset--color--accent) 8%, transparent),color-mix(in srgb, var(--wp--preset--color--accent) 12%, transparent)) 0%,transparent 70%) 0 -6rem / 100% 28rem no-repeat' ), 'spacing' => array( 'padding' => array( 'top' => '3.5rem', 'bottom' => 'var:preset|spacing|9' ), 'margin' => array( 'top' => '0', 'bottom' => '0' ) ), '@mobile' => array( 'spacing' => array( 'padding' => array( 'top' => '2.5rem', 'bottom' => 'var:preset|spacing|8' ) ) ), ) ); return AIEO_Content_Blocks::group( array( 'metadata' => AIEO_Content_Sections::metadata( $s, 'hero' ), 'align' => 'full', 'anchor' => AIEO_Content_Sections::anchor( $s ), 'className' => 'rooster-hero rooster-hero--landing ' . AIEO_Content_Sections::classes( $s, 'hero' ), 'style' => $style, 'layout' => array( 'type' => 'constrained' ), ), $inner ); } private static function cards( array $s ) { $cards = array_values( (array) ( $s['cards'] ?? array() ) ); if ( 'row' === (string) ( $s['layout'] ?? '' ) ) { $lines = array(); foreach ( $cards as $card ) { $lines[] = self::line( array( (string) ( $card['title'] ?? '' ), (string) ( $card['text'] ?? '' ), (string) ( $card['href'] ?? '' ) ), array( 1 ) ); } $inner = self::head( $s, array( 'type' => self::H2_SMALL, 'margin' => '0', 'no_eyebrow' => true ) ) . self::block( 'card', self::deferred( $s, array( 'variant' => 'link', 'items' => implode( "\n", $lines ) ), self::estimate( 'link-cards', $cards ) ), '1.5rem' ); return self::shell( $s, 'cards', $inner, array( '5rem', '5rem', 8, 8 ) ); } if ( ! empty( $s['collapsible'] ) ) { $lines = array(); foreach ( $cards as $card ) { $lines[] = '# ' . self::line( array( (string) ( $card['title'] ?? '' ), (string) ( $card['icon'] ?? '' ) ) ); foreach ( (array) ( $card['items'] ?? array() ) as $item ) { $lines[] = is_array( $item ) ? self::line( array( (string) ( $item['title'] ?? '' ), (string) ( $item['text'] ?? '' ) ), array( 1 ) ) : self::line( array( (string) $item ) ); } } $attrs = array( 'variant' => 'detail', 'items' => implode( "\n", $lines ) ); if ( ! empty( $s['unit'] ) ) { $attrs['unit'] = (string) $s['unit']; } return self::shell( $s, 'cards', self::head( $s ) . self::block( 'card', self::deferred( $s, $attrs, self::estimate( 'detail-cards', $cards ) ), '2.5rem' ) ); } $steps = ! empty( $s['numbered'] ); $lines = array(); foreach ( $cards as $card ) { $lines[] = $steps ? self::line( array( (string) ( $card['title'] ?? '' ), (string) ( $card['text'] ?? '' ) ), array( 1 ) ) : self::line( array( (string) ( $card['icon'] ?? '' ), (string) ( $card['title'] ?? '' ), (string) ( $card['text'] ?? '' ) ), array( 2 ) ); } $attrs = array( 'variant' => 'grid', 'layout' => $steps ? 'steps' : 'cards', 'items' => implode( "\n", $lines ) ); if ( ! $steps && in_array( (int) ( $s['columns'] ?? 0 ), array( 2, 4 ), true ) ) { $attrs['columns'] = (string) (int) $s['columns']; } return self::shell( $s, 'cards', self::head( $s ) . self::block( 'card', self::deferred( $s, $attrs, self::estimate( $steps ? 'steps' : 'card-grid', $cards ) ), '2.5rem' ) ); } private static function split( array $s ) { $items = array_values( array_filter( array_map( static fn ( $i ) => self::line( array( is_array( $i ) ? (string) ( $i['title'] ?? $i['text'] ?? '' ) : (string) $i ), array( 0 ) ), (array) ( $s['items'] ?? array() ) ), 'strlen' ) ); if ( ! $items || ! empty( $s['image'] ) || ! empty( $s['pattern'] ) ) { return ''; } $left = self::head( $s ); if ( ! empty( $s['aside'] ) ) { $left .= self::block( 'mark', array( 'variant' => 'note', 'text' => trim( (string) $s['aside'] ) ), '1.5rem', false ); } $right = self::block( 'list', array( 'variant' => 'checks', 'layout' => 'cards', 'items' => implode( "\n", $items ) ), '', false ); $columns = AIEO_Content_Sections::columns( AIEO_Content_Sections::column( $left, '', 'rooster-split__text', false ), AIEO_Content_Sections::column( $right, '', 'rooster-split__side', false ), array( 'verticalAlignment' => null, 'className' => 'rooster-split__columns', 'style' => array( 'spacing' => array( 'blockGap' => array( 'top' => '2.5rem', 'left' => '2.5rem' ) ) ) ) ); return self::shell( $s, 'split', $columns ); } private static function prose( array $s ) { $items = array(); foreach ( preg_split( '/\r\n|\r|\n/', trim( (string) ( $s['body'] ?? '' ) ) ) ?: array() as $row ) { if ( '' === trim( $row ) ) { continue; } if ( ! preg_match( '/^\s*[-*]\s+(.+)$/u', $row, $m ) ) { return ''; } $items[] = self::line( array( $m[1] ), array( 0 ) ); } if ( ! $items || ! empty( $s['markup'] ) ) { return ''; } return self::shell( $s, 'prose', self::head( $s ) . self::block( 'list', array( 'variant' => 'checks', 'items' => implode( "\n", $items ) ), '2.5rem' ) ); } private static function table( array $s ) { if ( ! empty( $s['groups'] ) ) { return ''; } $cell = static function ( $c ) { if ( is_array( $c ) ) { $note = trim( (string) ( $c['note'] ?? '' ) ); return '' !== $note ? $note : (string) ( $c['mark'] ?? '' ); } return (string) $c; }; $rows = array(); foreach ( (array) ( $s['rows'] ?? array() ) as $row ) { $rows[] = self::line( array_map( $cell, (array) $row ), range( 1, max( 1, count( (array) $row ) ) ) ); } $attrs = array( 'variant' => 'data', 'columns' => self::line( array_map( 'strval', (array) ( $s['columns'] ?? array() ) ) ), 'rows' => implode( "\n", $rows ), 'label' => AIEO_Content_Inline::heading_plain( (string) ( $s['heading'] ?? '' ) ), ); return self::shell( $s, 'table', self::head( $s ) . self::block( 'table', self::deferred( $s, $attrs, self::estimate( 'data-table', (array) ( $s['rows'] ?? array() ) ) ), '2.5rem' ) ); } private static function pricing( array $s ) { $plans = ''; $tiers = array_values( (array) ( $s['tiers'] ?? array() ) ); foreach ( $tiers as $tier ) { if ( ! empty( $tier['volume'] ) ) { return ''; } $features = array(); foreach ( (array) ( $tier['features'] ?? array() ) as $feature ) { $features[] = str_replace( array( "\r", "\n" ), ' ', (string) $feature ); } $attrs = array( 'variant' => 'plan', 'name' => AIEO_Content_Inline::plain( (string) ( $tier['name'] ?? '' ) ), 'tagline' => AIEO_Content_Inline::plain( (string) ( $tier['tagline'] ?? '' ) ), 'price' => AIEO_Content_Inline::plain( (string) ( $tier['price'] ?? '' ) ), 'period' => AIEO_Content_Inline::plain( (string) ( $tier['period'] ?? '' ) ), 'note' => trim( (string) ( $tier['note'] ?? '' ) ), 'features' => implode( "\n", $features ), 'ctaText' => AIEO_Content_Inline::plain( (string) ( $tier['ctaText'] ?? '' ) ), 'ctaHref' => (string) ( $tier['ctaHref'] ?? '' ), ); if ( ! empty( $tier['highlighted'] ) ) { $attrs['highlighted'] = true; } if ( ! empty( $tier['badge'] ) ) { $attrs['badge'] = AIEO_Content_Inline::plain( (string) $tier['badge'] ); } if ( ! empty( $tier['anchor'] ) ) { $attrs['anchor'] = sanitize_title( (string) $tier['anchor'] ); } $plans .= AIEO_Content_Blocks::block( 'plan', array_filter( $attrs, static fn ( $v ) => '' !== $v ) ); } if ( '' === $plans ) { return ''; } $includes = (array) ( $s['includes'] ?? array() ); $items = array_values( array_filter( array_map( static fn ( $i ) => self::line( array( (string) $i ), array( 0 ) ), (array) ( $includes['items'] ?? array() ) ), 'strlen' ) ); $wide = count( $tiers ) > 2 && ! $items; $p_attrs = array( 'metadata' => array( 'name' => __( 'Plans', 'ai-eshop-optimizer' ) ) ); $p_style = array( 'spacing' => array( 'blockGap' => 'var:preset|spacing|5' ) ); if ( $items ) { $p_style['layout'] = array( 'columnSpan' => 2 ); } else { $p_attrs['lock'] = array( 'move' => true, 'remove' => true ); $p_attrs['align'] = 'wide'; $p_style['spacing']['margin'] = array( 'top' => '2.5rem' ); } $p_attrs['style'] = $p_style; $p_attrs['layout'] = array( 'type' => 'grid', 'columnCount' => $wide ? min( 4, count( $tiers ) ) : 2, 'minimumColumnWidth' => '12rem' ); $body = AIEO_Content_Blocks::group( $p_attrs, $plans ); if ( $items ) { $panel = AIEO_Content_Blocks::block( 'list', array( 'variant' => 'checks', 'layout' => 'panel', 'heading' => AIEO_Content_Inline::plain( (string) ( $includes['heading'] ?? __( 'Every plan includes', 'ai-eshop-optimizer' ) ) ), 'items' => implode( "\n", $items ) ) ); $body = AIEO_Content_Blocks::group( array( 'metadata' => array( 'name' => __( 'Plans and what they include', 'ai-eshop-optimizer' ) ), 'lock' => array( 'move' => true, 'remove' => true ), 'align' => 'wide', 'style' => array( 'spacing' => array( 'blockGap' => 'var:preset|spacing|5', 'margin' => array( 'top' => '2.5rem' ) ) ), 'layout' => array( 'type' => 'grid', 'columnCount' => 3, 'minimumColumnWidth' => '15rem' ), ), $panel . $body ); } $note = ''; if ( ! empty( $s['note'] ) ) { $note = self::measure( __( 'Note', 'ai-eshop-optimizer' ), '48rem', '1.5rem', AIEO_Content_Inline::blocks( $s['note'], array( 'textColor' => 'muted', 'fontSize' => 'sm', 'style' => array( 'typography' => array( 'lineHeight' => '1.625' ) ) ) ) ); } return self::shell( $s, 'pricing', self::head( $s ) . $body . $note ); } private static function faq( array $s ) { $items = array(); foreach ( (array) ( $s['items'] ?? array() ) as $item ) { $line = self::line( array( (string) ( $item['q'] ?? '' ), (string) ( $item['a'] ?? '' ) ), array( 1 ) ); $items[] = str_contains( $line, '|' ) ? $line : $line . ' |'; } if ( ! $items ) { return ''; } $aside = ''; if ( '' !== trim( (string) ( $s['heading'] ?? '' ) ) ) { $aside .= self::heading( AIEO_Content_Inline::heading( (string) $s['heading'] ), 2, self::H2, '0.75rem' ); } $links = $s['links'] ?? null; if ( is_array( $links ) && $links ) { $heading = array_is_list( $links ) ? '' : (string) ( $links['heading'] ?? '' ); $list = array(); foreach ( (array) ( array_is_list( $links ) ? $links : ( $links['items'] ?? array() ) ) as $link ) { $list[] = self::line( array( (string) ( $link['text'] ?? '' ), (string) ( $link['href'] ?? '' ) ) ); } if ( '' !== $heading ) { $aside .= AIEO_Content_Blocks::paragraph( array( 'textColor' => 'contrast-2', 'style' => array( 'spacing' => array( 'margin' => array( 'top' => '1rem' ) ), 'typography' => array( 'lineHeight' => '1.5' ) ) ), AIEO_Content_Inline::html( $heading ) ); } if ( $list ) { $aside .= self::block( 'list', array( 'variant' => 'checks', 'layout' => 'links', 'items' => implode( "\n", $list ) ), '0.5rem', false ); } } $aside = AIEO_Content_Blocks::group( array( 'metadata' => array( 'name' => __( 'Section head', 'ai-eshop-optimizer' ) ), 'templateLock' => 'contentOnly', 'lock' => array( 'move' => true, 'remove' => true ), 'style' => array( 'spacing' => array( 'blockGap' => '0' ) ), 'layout' => array( 'type' => 'constrained', 'justifyContent' => 'left' ) ), $aside ); $list = self::block( 'questions', self::deferred( $s, array( 'variant' => 'rows', 'items' => implode( "\n", $items ) ), self::estimate( 'question-list', $items ) ), '', false ); $columns = AIEO_Content_Sections::columns( AIEO_Content_Sections::column( $aside, '31.0185%', 'rooster-faq__aside', false ), AIEO_Content_Sections::column( $list, '65.5093%', 'rooster-faq__main', false ), array( 'verticalAlignment' => null, 'className' => 'rooster-faq__columns', 'style' => array( 'spacing' => array( 'blockGap' => array( 'top' => '2.5rem', 'left' => '2.5rem' ) ) ) ) ); return self::shell( $s, 'faq', $columns, array( 9, 9, 8, 8 ), 'top', 'rooster-faq' ); } private static function cta( array $s ) { $band = 'left' === (string) ( $s['align'] ?? '' ); $buttons = array(); foreach ( (array) ( $s['buttons'] ?? array() ) as $i => $button ) { $style = (string) ( $button['style'] ?? ( 0 === $i ? 'primary' : 'secondary' ) ); $cells = array( (string) ( $button['text'] ?? '' ), (string) ( $button['href'] ?? '' ), in_array( $style, array( 'secondary', 'outline' ), true ) ? 'secondary' : 'primary' ); if ( '' !== (string) ( $button['icon'] ?? '' ) ) { $cells[] = sanitize_key( (string) $button['icon'] ); } $buttons[] = self::line( $cells ); } $items = array_values( array_filter( array_map( static fn ( $i ) => self::line( array( (string) $i ), array( 0 ) ), (array) ( $s['items'] ?? array() ) ), 'strlen' ) ); $attrs = array( 'variant' => 'panel', 'layout' => $band ? 'band' : 'center', 'eyebrow' => AIEO_Content_Inline::plain( (string) ( $s['eyebrow'] ?? '' ) ), 'heading' => AIEO_Content_Inline::heading_plain( (string) ( $s['heading'] ?? '' ) ), 'text' => trim( (string) ( $s['text'] ?? $s['lede'] ?? '' ) ), 'items' => implode( "\n", $items ), 'buttons' => implode( "\n", $buttons ), 'align' => 'wide', ); $panel = AIEO_Content_Blocks::block( 'action', array_filter( $attrs, static fn ( $v ) => '' !== $v ) ); $plain = array( 'style' => 'default' ) + $s; $plain['style'] = 'default'; if ( $band ) { return self::shell( $plain, 'cta', $panel, array( 8, 8, 7, 7 ) ); } $after_related = 'cards' === (string) ( $s['_prev_kind'] ?? '' ) && 'row' === (string) ( $s['_prev_layout'] ?? '' ); return self::shell( $plain, 'cta', $panel, $after_related ? array( 0, 9, 0, 8 ) : array( 9, 9, 8, 8 ) ); } }