'; } } if ( '' === $cells[0] && '' === $dots ) { continue; } $items .= '
  • ' . ( '' !== $dots ? '' : '' ) . '' . esc_html( $cells[0] ) . '
  • '; } if ( '' === $items ) { return; } $wrapper = AIEO_Engine_Blocks::wrapper( $library, [ 'class' => 'rooster-family-card rooster-family-card--palettes', 'data-rooster-ui' => 'rooster-one/card' ] ); AIEO_Engine_Blocks::out( sprintf( '', $wrapper, $items ) ); return; } $family = sanitize_key( (string) ( $attributes['family'] ?? '' ) ); $name = trim( (string) ( $attributes['name'] ?? '' ) ); $href = esc_url( (string) ( $attributes['href'] ?? '' ) ); $text = trim( (string) ( $attributes['text'] ?? '' ) ); $level = min( 4, max( 2, (int) ( $attributes['level'] ?? 3 ) ) ); if ( '' === $name && '' === trim( (string) ( $attributes['heading'] ?? '' ) ) ) { return; } $rows = static function ( string $value ): array { $out = []; foreach ( AIEO_Engine_Blocks::lines( $value ) as $line ) { $out[] = array_map( 'trim', explode( '|', $line ) ); } return $out; }; $motif = static function ( string $class ) use ( $attributes ): string { $slug = trim( (string) ( $attributes['motif'] ?? '' ) ); if ( '' === $slug || ! class_exists( 'WP_Block_Patterns_Registry' ) ) { return ''; } $pattern = WP_Block_Patterns_Registry::get_instance()->get_registered( $slug ); if ( ! $pattern || empty( $pattern['content'] ) ) { return ''; } $html = trim( (string) do_blocks( (string) $pattern['content'] ) ); return '' === $html ? '' : ''; }; $classes = 'rooster-family-card rooster-family-card--' . $layout . ( '' !== $family ? ' is-style-accent-' . $family : '' ); $mobile = function_exists( 'rooster_device_class' ) && 'mobile' === rooster_device_class(); if ( 'tile' === $layout ) { $logo = ''; $logo_id = (int) get_theme_mod( 'custom_logo' ); $src = $logo_id ? wp_get_attachment_image_src( $logo_id, 'full' ) : false; if ( $src ) { $logo = sprintf( '', esc_url( (string) $src[0] ), (int) $src[1], (int) $src[2] ); } $wrapper = AIEO_Engine_Blocks::wrapper( $library, [ 'class' => $classes . ' is-style-section-dark', 'data-rooster-ui' => 'rooster-one/card' ] ); AIEO_Engine_Blocks::out( sprintf( '%3$s%4$s%5$s', $wrapper, '' !== $href ? $href : '#', $logo, esc_html( (string) preg_replace( '/\s+/u', "\n", $name, 1 ) ), $motif( 'rooster-family-card__motif--tile' ) ) ); return; } $features = ''; foreach ( $rows( (string) ( $attributes['features'] ?? '' ) ) as $row ) { $label = (string) ( $row[0] ?? '' ); if ( '' === $label ) { continue; } $link = esc_url( (string) ( $row[1] ?? '' ) ); $features .= '
  • ' . ( '' !== $link ? '' . esc_html( $label ) . '' : esc_html( $label ) ) . '
  • '; } $features = '' !== $features ? '' : ''; if ( 'banner' === $layout ) { $heading = trim( (string) ( $attributes['heading'] ?? '' ) ); $inner = '' !== $name ? '

    ' . esc_html( $name ) . '

    ' : ''; if ( '' !== $heading ) { $inner .= sprintf( '%2$s', min( 3, $level ), esc_html( $heading ) ); } if ( '' !== $text ) { $inner .= '

    ' . AIEO_Engine_Blocks::inline( $text ) . '

    '; } $inner .= $features; $buttons = ''; foreach ( $rows( (string) ( $attributes['products'] ?? '' ) ) as $i => $row ) { $label = (string) ( $row[0] ?? '' ); $link = esc_url( (string) ( $row[1] ?? '' ) ); if ( '' !== $label && '' !== $link ) { $buttons .= '' . esc_html( $label ) . ''; } } $inner .= '' !== $buttons ? '
    ' . $buttons . '
    ' : ''; $wrapper = AIEO_Engine_Blocks::wrapper( $library, [ 'class' => $classes . ' is-style-section-dark', 'data-rooster-ui' => 'rooster-one/card' ] ); AIEO_Engine_Blocks::out( sprintf( '
    %2$s
    %3$s
    ', $wrapper, $motif( 'rooster-family-card__motif--banner' ), $inner ) ); return; } if ( 'links' === $layout ) { $top = sprintf( '
    %2$s%3$s
    ', $level, esc_html( $name ), '' !== $text ? '

    ' . AIEO_Engine_Blocks::inline( $text ) . '

    ' : '' ); if ( ! $mobile ) { $top .= $motif( 'rooster-family-card__motif--box is-style-section-dark' ); } $items = ''; foreach ( $rows( (string) ( $attributes['products'] ?? '' ) ) as $row ) { $label = (string) ( $row[0] ?? '' ); $link = esc_url( (string) ( $row[1] ?? '' ) ); if ( '' === $label || '' === $link ) { continue; } $line = (string) ( $row[3] ?? '' ); $items .= '
  • ' . esc_html( $label ) . '' . ( '' !== $line ? '' . AIEO_Engine_Blocks::inline( $line, false ) . '' : '' ) . '
  • '; } $wrapper = AIEO_Engine_Blocks::wrapper( $library, [ 'class' => $classes, 'data-rooster-ui' => 'rooster-one/card' ] ); AIEO_Engine_Blocks::out( sprintf( '
    %2$s
    %3$s
    ', $wrapper, $top, '' !== $items ? '' : '' ) ); return; } $band = sprintf( '
    %2$s%3$s
    ', $level, esc_html( $name ), $motif( 'rooster-family-card__motif--band' ) ); $body = '' !== $text ? '

    ' . AIEO_Engine_Blocks::inline( $text ) . '

    ' : ''; $chips = ''; foreach ( $rows( (string) ( $attributes['products'] ?? '' ) ) as $row ) { $label = (string) ( $row[0] ?? '' ); if ( '' === $label ) { continue; } $link = esc_url( (string) ( $row[1] ?? '' ) ); $badge = (string) ( $row[2] ?? '' ); $chip = esc_html( $label ) . ( '' !== $badge ? '' . esc_html( $badge ) . '' : '' ); $chips .= '
  • ' . ( '' !== $link ? '' . $chip . '' : '' . $chip . '' ) . '
  • '; } if ( '' !== $chips ) { $body .= ''; } $body .= $features; $links = ''; $cta = trim( (string) ( $attributes['ctaText'] ?? '' ) ); if ( '' !== $href && '' !== $cta ) { $links .= '' . esc_html( $cta ) . ''; } $docs = esc_url( (string) ( $attributes['docsHref'] ?? '' ) ); if ( '' !== $docs ) { $docs_text = trim( (string) ( $attributes['docsText'] ?? '' ) ); $links .= '' . esc_html( '' !== $docs_text ? $docs_text : __( 'Documentation', 'ai-eshop-optimizer' ) ) . ''; } $body .= '' !== $links ? '' : ''; $wrapper = AIEO_Engine_Blocks::wrapper( $library, [ 'class' => $classes, 'data-rooster-ui' => 'rooster-one/card' ] ); AIEO_Engine_Blocks::out( sprintf( '
    %2$s
    %3$s
    ', $wrapper, $band, $body ) );