block_name = 'smart-image'; $this->styles = array( 'sp_smart_post_blocks_social_icons_style', 'pcp-font-awesome', // 'sp_smart_post_blocks_css', 'pcp-likes', 'sp_smart_post_blocks_google_fonts', // 'sp_smart_post_blocks_style', ); } /** * Render Smart_Image block. * * @param array $attributes array $attributes - Block attributes. * @param string $content string $content - Block content. * @param array $blocks bocks. * * @return $content. */ public function render_block( $attributes, $content = '', $blocks = array() ) { $attributes['page_id'] = get_the_ID(); $sp_block_name = isset( $attributes['blockName'] ) ? $attributes['blockName'] : ''; $align = isset( $attributes['align'] ) ? $attributes['align'] : ''; $unique_id = isset( $attributes['uniqueId'] ) ? $attributes['uniqueId'] : ''; $hide_on_desktop = isset( $attributes['hideOnDesktop'] ) ? $attributes['hideOnDesktop'] : false; $hide_on_tablet = isset( $attributes['hideOnTablet'] ) ? $attributes['hideOnTablet'] : false; $hide_on_mobile = isset( $attributes['hideOnMobile'] ) ? $attributes['hideOnMobile'] : false; $img_text_position = isset( $attributes['imgTextPosition'] ) ? $attributes['imgTextPosition'] : ''; $img_mask_enable = isset( $attributes['imgMaskingEnable'] ) ? $attributes['imgMaskingEnable'] : false; $mask_shape_set = isset( $attributes['imageShapeSet'] ) ? $attributes['imageShapeSet'] : 'shape-set'; $select_mask_shape = isset( $attributes['selectImageShape'] ) ? $attributes['selectImageShape'] : 'original'; $select_image = isset( $attributes['selectImage'] ) ? $attributes['selectImage'] : array(); $select_img_size = isset( $attributes['imageSize'] ) ? $attributes['imageSize'] : 'full'; $lazy_load = isset( $attributes['lazyLoad'] ) ? $attributes['lazyLoad'] : false; $aspect_ratio = isset( $attributes['aspectRatio'] ) ? $attributes['aspectRatio'] : 'original'; $img_animation = isset( $attributes['imgAnimationNormal'] ) ? $attributes['imgAnimationNormal'] : 'zoom-in'; $double_resolution_retina = isset( $attributes['doubleResolutionRetina'] ) ? $attributes['doubleResolutionRetina'] : false; $enable_link = isset( $attributes['enableLink'] ) ? $attributes['enableLink'] : false; $link_type = isset( $attributes['linkType'] ) ? $attributes['linkType'] : 'full-img'; $img_hover_overlay = isset( $attributes['imgHoverOverlayEnable'] ) ? $attributes['imgHoverOverlayEnable'] : false; $link_btn_position = isset( $attributes['buttonPosition'] ) ? $attributes['buttonPosition'] : 'center-center'; $link_btn_label = isset( $attributes['buttonLabel'] ) ? $attributes['buttonLabel'] : ''; $btn_link_url = isset( $attributes['linkUrl'] ) ? $attributes['linkUrl'] : ''; $open_in_tab = ! empty( $attributes['openInTab'] ) ? '_blank' : '_self'; $img_alt_text = isset( $attributes['imageAltText'] ) ? $attributes['imageAltText'] : ''; $img_bg_enable = isset( $attributes['smartImgBgEnable'] ) ? $attributes['smartImgBgEnable'] : false; $additional_class = isset( $attributes['additionalCssClass'] ) ? $attributes['additionalCssClass'] : false; $img_alignment = isset( $attributes['imgAlignment'] ) ? $attributes['imgAlignment'] : 'left'; if ( empty( $select_image['url'] ) && empty( $select_image['insertUrl'] ) ) { return; } $external_url = isset( $select_image['insertUrl'] ) ? $select_image['insertUrl'] : false; unset( $attributes['dynamicCss'] ); unset( $attributes['fontListsEditPage'] ); unset( $attributes['fontLists'] ); $img_size_array = $select_image['media_details']['sizes'][ $select_img_size ] ?? array(); if ( ! isset( $img_size_array['source_url'] ) && ! isset( $select_image['url'] ) ) { return ''; } $visibility_class = ( $hide_on_desktop ? ' sp-hide-on-desktop ' : '' ) . ( $hide_on_tablet ? ' sp-hide-on-tablet ' : '' ) . ( $hide_on_mobile ? ' sp-hide-on-mobile' : '' ); $img_mask_class = $img_mask_enable ? ( 'custom' !== $mask_shape_set ? ' sp-' . $select_mask_shape : ' sp-custom-mask' ) : ''; $img_srcset_retina = null; if ( ! empty( $select_image['srcset'] ) ) { if ( ! $double_resolution_retina ) { $img_srcset_retina = $select_image['srcset']; } else { // split into an array by commas. $src_array = array_map( 'trim', explode( ',', $select_image['srcset'] ) ); // filter only sizes >= 600w. $filtered = array_filter( $src_array, function ( $src ) { preg_match( '/(\d+)w$/', $src, $matches ); $size = isset( $matches[1] ) ? (int) $matches[1] : 0; return $size >= 600; } ); // join back into a string. $img_srcset_retina = implode( ', ', $filtered ); } } $image_id = $select_image['id'] ?? ''; $image_width = $img_size_array['width'] ?? ''; $image_height = $img_size_array['height'] ?? ''; $image_source_url = $img_size_array['source_url'] ?? ''; $image_url = $select_image['url'] ?? ''; $img_wp_class = ! $external_url && count( $select_image ) > 0 ? 'wp-image-' . $image_id : ''; $img_class = 'sp-smart-image sp-image-ratio-' . $aspect_ratio . ' sp-' . $img_animation . ' ' . $img_wp_class; $img_sizes_attr = ! $external_url ? '(max-width: ' . $image_width . 'px) 100vw, ' . $image_width . 'px' : ''; // Render the block content. ob_start(); ?>
'; } ?> <?php echo esc_attr( $img_alt_text ); ?>
'; } ?>