PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.1
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / blocks / storeengine-product-gallery / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.11.1, at includes/blocks/storeengine-product-gallery/block.php

134 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ABlocks\Blocks\StoreengineProductGallery;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use ABlocks\Classes\BlockBaseAbstract;
10 use ABlocks\Classes\CssGenerator;
11 use ABlocks\Helper;
12 use ABlocks\Controls\Typography;
13 use ABlocks\Controls\Background;
14 use ABlocks\Controls\Border;
15 use ABlocks\Controls\Dimensions;
16 use ABlocks\Controls\Range;
17 use ABlocks\Controls\BoxShadow;
18 use ABlocks\Controls\Color;
19
20 class Block extends BlockBaseAbstract {
21 protected $block_name = 'storeengine-product-gallery';
22
23 public function build_css( $attributes ) {
24 $css_generator = new CssGenerator( $attributes, $this->block_name );
25
26 $css_generator->add_class_styles(
27 '{{WRAPPER}} .storeengine-gallery_wrapper .storeengine-col-12 .storeengine-placeholder,
28 {{WRAPPER}} .is-layout-constrained .storeengine-gallery_wrapper .storeengine-col-12 img,
29 {{WRAPPER}} .is-layout-constrained .storeengine-gallery_wrapper .carousel-main .flickity-slider img',
30 $this->get_gallary_image_css( $attributes ),
31 $this->get_gallary_image_css( $attributes, 'Tablet' ),
32 $this->get_gallary_image_css( $attributes, 'Mobile' )
33 );
34 $css_generator->add_class_styles(
35 '{{WRAPPER}} .storeengine-gallery_wrapper .storeengine-row .storeengine-col-12',
36 $this->get_gallary_image_container_css( $attributes ),
37 $this->get_gallary_image_container_css( $attributes, 'Tablet' ),
38 $this->get_gallary_image_container_css( $attributes, 'Mobile' )
39 );
40 $css_generator->add_class_styles(
41 '{{WRAPPER}} .storeengine-gallery_wrapper .storeengine-col-12 .storeengine-placeholder:hover',
42 $this->get_gallary_image_hover_css( $attributes ),
43 $this->get_gallary_image_hover_css( $attributes, 'Tablet' ),
44 $this->get_gallary_image_hover_css( $attributes, 'Mobile' )
45 );
46 return $css_generator->generate_css();
47 }
48
49 public function get_gallary_image_css( $attributes, $device = '' ) {
50 $css = [];
51 $css['opacity'] = $attributes['imageOpacity'] ?? '';
52 if ( ! empty( $alignment_value ) ) {
53 $css['display'] = 'flex';
54 $css['width'] = '100%';
55 $css['justify-content'] = $alignment_value;
56 }
57 return array_merge(
58 $css,
59 isset( $attributes['border'] ) ? Border::get_css( $attributes['border'], '', $device ) : [],
60 isset( $attributes['boxShadow'] ) ? BoxShadow::get_css( $attributes['boxShadow'], $device ) : [],
61 Range::get_css([
62 'attributeValue' => $attributes['imageWidth'],
63 'attribute_object_key' => 'value',
64 'isResponsive' => true,
65 'defaultValue' => 100,
66 'hasUnit' => true,
67 'unitDefaultValue' => '%',
68 'property' => 'width',
69 'device' => $device,
70 ]),
71 Range::get_css([
72 'attributeValue' => $attributes['imageHeight'],
73 'attribute_object_key' => 'value',
74 'isResponsive' => true,
75 'defaultValue' => 100,
76 'hasUnit' => true,
77 'unitDefaultValue' => '%',
78 'property' => 'height',
79 'device' => $device,
80 ]),
81 );
82
83 }
84
85 public function get_gallary_image_container_css( $attributes, $device = '' ) {
86 $alignment_value = $attributes['alignment'][ 'value' . $device ] ?? '';
87 $css = [];
88 return $css;
89 }
90
91 public function get_gallary_image_hover_css( $attributes, $device = '' ) {
92 $css = [];
93 $css['opacity'] = $attributes['imageOpacityH'] ?? '';
94
95 return array_merge(
96 isset( $attributes['border'] ) ? Border::get_hover_css( $attributes['border'], '', $device ) : [],
97 isset( $attributes['boxShadow'] ) ? BoxShadow::get_hover_css( $attributes['boxShadow'], $device ) : [],
98 );
99 }
100
101 public function render_block_content( $attributes, $content, $block_instance ) {
102 $attr_array = [
103 'product_id' => Helper::get_attribute_value( $attributes, 'product_id' ),
104 ];
105
106 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
107 $is_editor = ( isset( $_GET['context'] ) && 'edit' === sanitize_text_field( $_GET['context'] ) );
108
109 $is_custom = $attributes['isCustom'];
110
111 if ( $is_custom ) {
112 if ( empty( $attr_array['product_id'] ) && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) {
113 $attr_array['product_id'] = $block_instance->context['postId'];
114 }
115 } else {
116 if ( ! $is_editor && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) {
117 $attr_array['product_id'] = $block_instance->context['postId'];
118 }
119 }
120
121 if ( $is_editor && empty( $attr_array['product_id'] ) ) {
122 return '<p>Only in editor preview. Please Select a Product</p>';
123 }
124
125 if ( $is_editor ) {
126 $attr_array['dummy'] = true;
127 }
128
129 $shortcode = '[storeengine_single_product_gallery ' . Helper::attr_shortcode( $attr_array ) . ']';
130 echo do_shortcode( $shortcode );
131 }
132
133 }
134