PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.4.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.4.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Integrations / Bricks / Elements / Media.php
Media.php
241 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Integrations\Bricks\Elements;
4
5 use SureCart\Integrations\Bricks\Concerns\ConvertsBlocks;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 /**
12 * Media element.
13 */
14 class Media extends \Bricks\Element {
15 use ConvertsBlocks; // we have to use a trait since we can't extend the surecart class.
16
17 /**
18 * Element category.
19 *
20 * @var string
21 */
22 public $category = 'SureCart Elements';
23
24 /**
25 * Element name.
26 *
27 * @var string
28 */
29 public $name = 'surecart-product-media';
30
31 /**
32 * Element block name.
33 *
34 * @var string
35 */
36 public $block_name = 'surecart/product-media';
37
38 /**
39 * Element icon.
40 *
41 * @var string
42 */
43 public $icon = 'ti-layout-slider-alt';
44
45 /**
46 * Get element label.
47 *
48 * @return string
49 */
50 public function get_label() {
51 return esc_html__( 'Product media', 'surecart' );
52 }
53
54 /**
55 * Enqueue scripts and styles.
56 *
57 * @return void
58 */
59 public function enqueue_scripts() {
60 wp_enqueue_style( 'surecart-image-slider' );
61 }
62
63 /**
64 * Set controls.
65 *
66 * @return void
67 */
68 public function set_controls() {
69 $this->controls['desktop_gallery'] = [
70 'tab' => 'content',
71 'label' => esc_html__( 'Display Mode', 'surecart' ),
72 'type' => 'select',
73 'options' => [
74 'slider' => esc_html__( 'Slider View', 'surecart' ),
75 'gallery' => esc_html__( 'Gallery View', 'surecart' ),
76 ],
77 'inline' => true,
78 'fullAccess' => true,
79 'default' => 'slider',
80 ];
81
82 $this->controls['auto_height'] = [
83 'tab' => 'content',
84 'label' => esc_html__( 'Auto height', 'surecart' ),
85 'type' => 'checkbox',
86 'inline' => true,
87 'fullAccess' => true,
88 'default' => true,
89 'required' => [
90 [ 'desktop_gallery', '=', 'slider' ],
91 ],
92 ];
93
94 $this->controls['lightbox'] = [
95 'tab' => 'content',
96 'label' => esc_html__( 'Enlarge on click', 'surecart' ),
97 'type' => 'checkbox',
98 'inline' => true,
99 'fullAccess' => true,
100 'default' => true,
101 ];
102
103 $this->controls['height'] = [
104 'tab' => 'content',
105 'label' => esc_html__( 'Height', 'surecart' ),
106 'type' => 'number',
107 'units' => true,
108 'default' => '310px',
109 'placeholder' => '310px',
110 'required' => [
111 [ 'auto_height', '!=', true ],
112 [ 'desktop_gallery', '=', 'slider' ],
113 ],
114 'fullAccess' => true,
115 ];
116
117 $this->controls['max_image_width'] = [
118 'tab' => 'content',
119 'label' => esc_html__( 'Max image width', 'surecart' ),
120 'type' => 'number',
121 'units' => true,
122 'placeholder' => esc_html__( 'Unlimited', 'surecart' ),
123 ];
124
125 $this->controls['gallery_spacing'] = [
126 'tab' => 'content',
127 'label' => esc_html__( 'Gallery Spacing', 'surecart' ),
128 'type' => 'number',
129 'units' => true,
130 'default' => '1rem',
131 'placeholder' => '1rem',
132 'css' => [
133 [
134 'property' => 'gap',
135 'selector' => '&.sc-image-gallery .swiper-wrapper',
136 ],
137 [
138 'property' => 'margin-bottom',
139 'selector' => '&.sc-image-gallery .swiper-wrapper .swiper-slide',
140 ],
141 ],
142 'required' => [
143 [ 'desktop_gallery', '=', 'gallery' ],
144 ],
145 ];
146
147 $this->controls['thumbnails_per_page'] = [
148 'tab' => 'content',
149 'label' => esc_html__( 'Thumbs per page', 'surecart' ),
150 'type' => 'number',
151 'default' => 5,
152 'min' => 2,
153 'placeholder' => 5,
154 'required' => [
155 [ 'desktop_gallery', '=', 'slider' ],
156 ],
157 ];
158
159 $this->controls['show_thumbs'] = [
160 'tab' => 'content',
161 'label' => esc_html__( 'Show Thumbnails', 'surecart' ),
162 'type' => 'checkbox',
163 'inline' => true,
164 'fullAccess' => true,
165 'default' => true,
166 'required' => [
167 [ 'desktop_gallery', '=', 'slider' ],
168 ],
169 ];
170 }
171
172 /**
173 * Render element.
174 *
175 * @return void
176 */
177 public function render() {
178 $product = sc_get_product();
179 $settings = $this->settings;
180 $thumbnails_per_page = ! empty( $settings['thumbnails_per_page'] ) ? (int) $settings['thumbnails_per_page'] : 5;
181 $desktop_gallery = ! empty( $settings['desktop_gallery'] ) ? $settings['desktop_gallery'] : 'slider';
182
183 if ( $this->is_admin_editor() ) {
184 if ( 'gallery' === $desktop_gallery ) {
185 $content = '<div class="sc-image-gallery"><div class="swiper swiper-initialized"><div class="swiper-wrapper">';
186 for ( $i = 0; $i < 3; $i++ ) {
187 $content .= '<div class="swiper-slide">';
188 $content .= '<img src="' . esc_url( trailingslashit( \SureCart::core()->assets()->getUrl() ) . 'images/placeholder.jpg' ) . '"';
189 $content .= ' style="' . ( ! empty( $this->settings['max_image_width'] ) ? 'max-width:' . esc_attr( $this->settings['max_image_width'] ) : '' ) . '"';
190 $content .= ' alt="' . esc_attr( get_the_title() ) . '" />';
191 $content .= '</div>';
192 }
193 $content .= '</div></div></div>';
194 $content .= '<div class="bricks-element-placeholder" data-type="info" draggable="false"><i class="ti-layout-slider-alt"></i><div class="placeholder-inner"><div class="placeholder-description">' . __( 'The accurate preview for this element is only available on frontend due to compatibility issues.', 'surecart' ) . '</div></div></div>';
195 } else {
196 $content = '<div class="sc-image-slider"><div class="swiper swiper-initialized"><div class="swiper-wrapper">';
197 $content .= '<div class="swiper-slide"><img src="' . esc_url( trailingslashit( \SureCart::core()->assets()->getUrl() ) . 'images/placeholder.jpg' ) . '"';
198 $content .= ' style="' . ( ! empty( $this->settings['max_image_width'] ) ? 'max-width:' . esc_attr( $this->settings['max_image_width'] ) : '' ) . '"';
199 $content .= ' alt="' . esc_attr( get_the_title() ) . '" /></div>';
200 $content .= '</div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div>';
201
202 if ( ! empty( $this->settings['show_thumbs'] ) ) {
203 $content .= '<div class="sc-image-slider__thumbs"><div class="swiper swiper-initialized"><div class="swiper-wrapper sc-has-' . $thumbnails_per_page . '-thumbs">';
204 for ( $i = 0; $i < $thumbnails_per_page; $i++ ) {
205 $content .= '<div class="swiper-slide">';
206 $content .= '<img src="' . esc_url( trailingslashit( \SureCart::core()->assets()->getUrl() ) . 'images/placeholder.jpg' ) . '"';
207 $content .= ' alt="' . esc_attr( get_the_title() ) . '" />';
208 $content .= '</div>';
209 }
210 $content .= '</div></div></div>';
211 }
212 $content .= '</div>';
213 $content .= '<div class="bricks-element-placeholder" data-type="info" draggable="false"><i class="ti-layout-slider-alt"></i><div class="placeholder-inner"><div class="placeholder-description">' . __( 'The accurate preview for this element is only available on frontend due to compatibility issues.', 'surecart' ) . '</div></div></div>';
214 }
215
216 echo $this->preview( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
217 $content,
218 '',
219 'figure'
220 );
221
222 return;
223 }
224
225 $auto_height = 'gallery' === $desktop_gallery ? true : ! empty( $settings['auto_height'] );
226 $height = ! $auto_height ? ( ! empty( $settings['height'] ) ? $settings['height'] : '310px' ) : '';
227
228 echo $this->html( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
229 [
230 'auto_height' => $auto_height,
231 'height' => $height,
232 'lightbox' => (bool) ! empty( $this->settings['lightbox'] ),
233 'width' => esc_html( $this->settings['max_image_width'] ?? null ),
234 'thumbnails_per_page' => $thumbnails_per_page,
235 'desktop_gallery' => 'gallery' === $desktop_gallery,
236 'show_thumbs' => (bool) ! empty( $this->settings['show_thumbs'] ),
237 ]
238 );
239 }
240 }
241