$key ) { $gallery_array[$order] = $gallery_items[$key]; } } return $gallery_array; } /** * Generate the class to use for the gallery section. * * @since 1.0.0. * * @param array $bgbn_section_data The section data. * @param array $sections The list of sections. * @return string The class. */ function bgbn_builder_get_gallery_class( $bgbn_section_data, $sections ) { if ( ! bgbn_builder_is_section_type( 'gallery', $bgbn_section_data ) ) { return ''; } $gallery_class = ' '; // Section classes $gallery_class .= bgbn_get_builder_save()->section_classes( $bgbn_section_data, $sections ); // Columns $gallery_columns = ( isset( $bgbn_section_data['columns'] ) ) ? absint( $bgbn_section_data['columns'] ) : 1; $gallery_class .= ' builder-gallery-columns-' . $gallery_columns; // Captions if ( isset( $bgbn_section_data['captions'] ) && ! empty( $bgbn_section_data['captions'] ) ) { $gallery_class .= ' builder-gallery-captions-' . esc_attr( $bgbn_section_data['captions'] ); } // Caption color if ( isset( $bgbn_section_data['caption-color'] ) && ! empty( $bgbn_section_data['caption-color'] ) ) { $gallery_class .= ' builder-gallery-captions-' . esc_attr( $bgbn_section_data['caption-color'] ); } // Aspect Ratio if ( isset( $bgbn_section_data['aspect'] ) && ! empty( $bgbn_section_data['aspect'] ) ) { $gallery_class .= ' builder-gallery-aspect-' . esc_attr( $bgbn_section_data['aspect'] ); } // Test for background padding $bg_color = ( isset( $bgbn_section_data['background-color'] ) && ! empty( $bgbn_section_data['background-color'] ) ); $bg_image = ( isset( $bgbn_section_data['background-image'] ) && 0 !== absint( $bgbn_section_data['background-image'] ) ); if ( true === $bg_color || true === $bg_image ) { $gallery_class .= ' has-background'; } return apply_filters( 'bgbn_gallery_class', $gallery_class, $bgbn_section_data ); } /** * Generate the CSS for the gallery. * * @since 1.0.0. * * @param array $bgbn_section_data The section data. * @return string The CSS string. */ function bgbn_builder_get_gallery_style( $bgbn_section_data ) { if ( ! bgbn_builder_is_section_type( 'gallery', $bgbn_section_data ) ) { return ''; } $gallery_style = ''; // Background color if ( isset( $bgbn_section_data['background-color'] ) && ! empty( $bgbn_section_data['background-color'] ) ) { $gallery_style .= 'background-color:' . maybe_hash_hex_color( $bgbn_section_data['background-color'] ) . ';'; } // Background image if ( isset( $bgbn_section_data['background-image'] ) && 0 !== absint( $bgbn_section_data['background-image'] ) ) { $image_src = bgbn_get_image_src( $bgbn_section_data['background-image'], 'full' ); if ( isset( $image_src[0] ) ) { $gallery_style .= 'background-image: url(\'' . addcslashes( esc_url_raw( $image_src[0] ), '"' ) . '\');'; } } // Background style if ( isset( $bgbn_section_data['background-style'] ) && ! empty( $bgbn_section_data['background-style'] ) ) { if ( 'cover' === $bgbn_section_data['background-style'] ) { $gallery_style .= 'background-size: cover;'; } } return $gallery_style; } /** * Generate the class for an individual gallery item. * * @since 1.0.0. * * @param array $bgbn_section_data The section data. * @param int $i The current gallery item iterator * @return string The class. */ function bgbn_builder_get_gallery_item_class( $bgbn_section_data, $i ) { if ( ! bgbn_builder_is_section_type( 'gallery', $bgbn_section_data ) ) { return ''; } $gallery_class = ''; // Columns $gallery_columns = ( isset( $bgbn_section_data['columns'] ) ) ? absint( $bgbn_section_data['columns'] ) : 1; if ( $gallery_columns > 2 && 0 === $i % $gallery_columns ) { $gallery_class .= ' last-' . $gallery_columns; } if ( 0 === $i % 2 ) { $gallery_class .= ' last-2'; } return $gallery_class; } /** * Get the image for the gallery item. * * @since 1.0.0. * * @param array $item The item's data. * @param string $aspect The aspect ratio for the section. * @return string The HTML or CSS for the item's image. */ function bgbn_builder_get_gallery_item_image( $item, $aspect ) { global $bgbn_section_data; if ( ! bgbn_builder_is_section_type( 'gallery', $bgbn_section_data ) ) { return ''; } if ( 0 === bgbn_sanitize_image_id( $item[ 'image-id' ] ) ) { return ''; } $image_style = ''; $image_src = bgbn_get_image_src( $item[ 'image-id' ], 'large' ); if ( isset( $image_src[0] ) ) { $image_style .= 'background-image: url(\'' . addcslashes( esc_url_raw( $image_src[0] ), '"' ) . '\');'; } if ( 'none' === $aspect && isset( $image_src[1] ) && isset( $image_src[2] ) ) { $image_ratio = ( $image_src[2] / $image_src[1] ) * 100; $image_style .= 'padding-bottom: ' . $image_ratio . '%;'; } $image = ''; if ( '' !== $image_style ) { $image .= ''; } return $image; } /** * Get the columns data for a text section. * * @since 1.0.0. * * @param array $bgbn_section_data The section data. * @return array Array of data for columns in a text section. */ function bgbn_builder_get_text_array( $bgbn_section_data ) { if ( ! bgbn_builder_is_section_type( 'text', $bgbn_section_data ) ) { return array(); } $columns_number = ( isset( $bgbn_section_data['columns-number'] ) ) ? absint( $bgbn_section_data['columns-number'] ) : 1; $columns_order = array(); if ( isset( $bgbn_section_data['columns-order'] ) ) { $columns_order = $bgbn_section_data['columns-order']; } $columns_data = array(); if ( isset( $bgbn_section_data['columns'] ) ) { $columns_data = $bgbn_section_data['columns']; } $columns_array = array(); if ( ! empty( $columns_order ) && ! empty( $columns_data ) ) { $count = 0; foreach ( $columns_order as $order => $key ) { $columns_array[$order] = $columns_data[$key]; $count++; if ( $count >= $columns_number ) { break; } } } return $columns_array; } /** * Get the class for the text section. * * @since 1.0.0. * * @param array $bgbn_section_data The section data. * @param array $sections The list of sections. * @return string The class. */ function bgbn_builder_get_text_class( $bgbn_section_data, $sections ) { if ( ! bgbn_builder_is_section_type( 'text', $bgbn_section_data ) ) { return ''; } $text_class = ' '; // Section classes $text_class .= bgbn_get_builder_save()->section_classes( $bgbn_section_data, $sections ); // Columns $columns_number = ( isset( $bgbn_section_data['columns-number'] ) ) ? absint( $bgbn_section_data['columns-number'] ) : 1; $text_class .= ' builder-text-columns-' . $columns_number; return $text_class; } /** * Get the data for the array section. * * @since 1.0.0. * * @param array $bgbn_section_data The section data. * @return array The data. */ function bgbn_builder_get_banner_array( $bgbn_section_data ) { if ( ! bgbn_builder_is_section_type( 'banner', $bgbn_section_data ) ) { return array(); } $banner_order = array(); if ( isset( $bgbn_section_data['banner-slide-order'] ) ) { $banner_order = $bgbn_section_data['banner-slide-order']; } $banner_slides = array(); if ( isset( $bgbn_section_data['banner-slides'] ) ) { $banner_slides = $bgbn_section_data['banner-slides']; } $banner_array = array(); if ( ! empty( $banner_order ) && ! empty( $banner_slides ) ) { foreach ( $banner_order as $order => $key ) { $banner_array[$order] = $banner_slides[$key]; } } return $banner_array; } /** * Get the class for a banner section. * * @since 1.0.0. * * @param array $bgbn_section_data The section data. * @param array $sections The list of sections. * @return string The class. */ function bgbn_builder_get_banner_class( $bgbn_section_data, $sections ) { if ( ! bgbn_builder_is_section_type( 'banner', $bgbn_section_data ) ) { return ''; } $banner_class = ' '; // Section classes $banner_class .= bgbn_get_builder_save()->section_classes( $bgbn_section_data, $sections ); // Banner id $banner_id = ( isset( $bgbn_section_data['id'] ) ) ? absint( $bgbn_section_data['id'] ) : 1; $banner_class .= ' builder-section-banner-' . $banner_id; return apply_filters( 'bgbn_builder_banner_class', $banner_class, $bgbn_section_data ); } /** * Get the attributes for a banner slider. * * @since 1.0.0. * * @param array $bgbn_section_data The section data. * @return string The attributes. */ function bgbn_builder_get_banner_slider_atts( $bgbn_section_data ) { if ( ! bgbn_builder_is_section_type( 'banner', $bgbn_section_data ) ) { return ''; } $atts = shortcode_atts( array( 'autoplay' => true, 'transition' => 'scrollHorz', 'delay' => 6000 ), $bgbn_section_data ); // Data attributes $data_attributes = ' data-cycle-log="false"'; $data_attributes .= ' data-cycle-slides="div.builder-banner-slide"'; $data_attributes .= ' data-cycle-swipe="true"'; // Autoplay $autoplay = (bool) $atts['autoplay']; if ( false === $autoplay ) { $data_attributes .= ' data-cycle-paused="true"'; } // Delay $delay = absint( $atts['delay'] ); if ( 0 === $delay ) { $delay = 6000; } if ( 4000 !== $delay ) { $data_attributes .= ' data-cycle-timeout="' . esc_attr( $delay ) . '"'; } // Effect $effect = trim( $atts['transition'] ); if ( ! in_array( $effect, array( 'fade', 'fadeout', 'scrollHorz', 'none' ) ) ) { $effect = 'scrollHorz'; } if ( 'fade' !== $effect ) { $data_attributes .= ' data-cycle-fx="' . esc_attr( $effect ) . '"'; } return $data_attributes; } /** * Get the class attribute for a slide. * * @since 1.0.0. * * @param array $slide The data for an individual slide. * @return string The slide's class. */ function bgbn_builder_banner_slide_class( $slide ) { $slide_class = ''; // Content position if ( isset( $slide['alignment'] ) && '' !== $slide['alignment'] ) { $slide_class .= ' ' . sanitize_html_class( 'content-position-' . $slide['alignment'] ); } return $slide_class; } /** * Get the CSS for a slide. * * @since 1.0.0. * * @param array $slide The slide data. * @param array $bgbn_section_data The section data. * @return string The CSS. */ function bgbn_builder_banner_slide_style( $slide, $bgbn_section_data ) { $slide_style = ''; // Background color if ( isset( $slide['background-color'] ) && '' !== $slide['background-color'] ) { $slide_style .= 'background-color:' . maybe_hash_hex_color( $slide['background-color'] ) . ';'; } // Background image if ( isset( $slide['image-id'] ) && 0 !== bgbn_sanitize_image_id( $slide['image-id'] ) ) { $image_src = bgbn_get_image_src( $slide['image-id'], 'full' ); if ( isset( $image_src[0] ) ) { $slide_style .= 'background-image: url(\'' . addcslashes( esc_url_raw( $image_src[0] ), '"' ) . '\');'; } } return esc_attr( $slide_style ); }