PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.6
ShopBuilder – WooCommerce Builder For Elementor v3.2.6
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Elementor / Widgets / Single / ProductImages.php

ProductImages.php in ShopBuilder – WooCommerce Builder For Elementor 3.2.6, at app/Elementor/Widgets/Single/ProductImages.php

348 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main ProductImages class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Elementor\Widgets\Single;
9
10 use RadiusTheme\SB\Helpers\BuilderFns;
11 use RadiusTheme\SB\Helpers\ElementorDataMap;
12 use RadiusTheme\SB\Helpers\Fns;
13 use RadiusTheme\SB\Abstracts\ElementorWidgetBase;
14 use RadiusTheme\SB\Elementor\Widgets\Controls\ProductImagesSettings;
15 use RadiusTheme\SBPRO\Helpers\BuilderFunPro;
16
17 // Do not allow directly accessing this file.
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit( 'This script cannot be accessed directly.' );
20 }
21
22 /**
23 * Product Images class
24 */
25 class ProductImages extends ElementorWidgetBase {
26 /**
27 * Construct function
28 *
29 * @param array $data default array.
30 * @param mixed $args default arg.
31 */
32 public function __construct( $data = [], $args = null ) {
33 $this->rtsb_name = esc_html__( 'Product Images', 'shopbuilder' );
34 $this->rtsb_base = 'rtsb-product-image';
35 parent::__construct( $data, $args );
36 $this->the_hooks();
37 }
38 /**
39 * Widget Field
40 *
41 * @return array
42 */
43 public function widget_fields() {
44 return $this->modify_widget_fields();
45 }
46 /**
47 * Widget Field
48 *
49 * @return array
50 */
51 public function modify_widget_fields() {
52 $fields = ProductImagesSettings::widget_fields( $this );
53 $extra_controls['image_border'] = [
54 'mode' => 'group',
55 'type' => 'border',
56 'selector' => $this->selectors['image_border'],
57 'size_units' => [ 'px' ],
58 'fields_options' => [
59 'border' => [
60 'label' => esc_html__( 'Border', 'shopbuilder' ),
61 'label_block' => true,
62 ],
63 'color' => [
64 'label' => esc_html__( 'Border Color', 'shopbuilder' ),
65 ],
66 ],
67 ];
68 $fields = Fns::insert_controls( 'image_width', $fields, $extra_controls, true );
69 return $fields;
70 }
71
72 /**
73 * Widget Field.
74 *
75 * @return void
76 */
77 public function init_scripts() {
78 ?>
79 <script type="text/javascript">
80 if (!'<?php echo esc_attr( Fns::is_optimization_enabled() ); ?>') {
81 setTimeout(function() {
82 window.rtsbVariationGallery();
83 }, 4000);
84 } else {
85 if (typeof elementorFrontend !== 'undefined') {
86 elementorFrontend.hooks.addAction(
87 'frontend/element_ready/<?php echo esc_attr( $this->rtsb_base ); ?>.default',
88 () => {
89 window.waitForRTSB((RTSB) => {
90 RTSB.modules.get('variationGallery')?.refresh();
91 });
92 }
93 );
94 }
95 }
96 /*
97 * Initialize all galleries on page.
98 */
99 jQuery('.woocommerce-product-gallery').each(function () {
100 const that = this;
101
102 setTimeout(function () {
103 jQuery(this).trigger('wc-product-gallery-before-init', [this, wc_single_product_params]);
104 jQuery(that).wc_product_gallery(wc_single_product_params);
105 jQuery(that).trigger('wc-product-gallery-after-init', [this, wc_single_product_params]);
106 }, 1000);
107
108 });
109 <?php if ( function_exists( 'rtwpvg' ) ) { ?>
110 setTimeout(function () {
111 jQuery('.rtwpvg-wrapper, .rtwpvg-grid-wrapper').rtWpVGallery();
112 }, 1000);
113 <?php } ?>
114
115
116 if (!'<?php echo esc_attr( Fns::is_optimization_enabled() ); ?>') {
117 jQuery(document).ready(function ($) {
118 setTimeout(function () {
119 const zoomIcon = $('.rtsb-product-images').attr('data-zoom-icon');
120 if (!zoomIcon) {
121 $('.rtsb-product-images')
122 .find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger')
123 .remove();
124 }
125 $('.rtsb-product-images')
126 .find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger')
127 .html(zoomIcon);
128 }, 50);
129 });
130 } else {
131 if (typeof elementorFrontend !== 'undefined') {
132 elementorFrontend.hooks.addAction(
133 'frontend/element_ready/<?php echo esc_attr( $this->rtsb_base ); ?>.default',
134 ($scope) => {
135 window.waitForRTSB((RTSB) => {
136 RTSB.modules.get('productImage')?.refresh?.($, $scope);
137 });
138 }
139 );
140 }
141 }
142
143 </script>
144 <?php
145 }
146
147 /**
148 * Widget Field.
149 *
150 * @param array $control Control.
151 *
152 * @return void
153 */
154 public function the_hooks( $control = [] ) {
155 if ( empty( $control ) ) {
156 return;
157 }
158 add_filter(
159 'woocommerce_product_thumbnails_columns',
160 function ( $col ) {
161 $col = 0;
162
163 return $col;
164 }
165 );
166 if ( empty( $control['show_zoom'] ) ) {
167 add_filter( 'rtwpvg_trigger_icon', '__return_false' );
168 }
169 if ( empty( $control['show_thumbnails'] ) ) {
170 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false' );
171 remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
172 }
173 add_filter( 'rtwpvg_thumbnail_slider_js_options', [ $this, 'thumbnail_slider_js_options' ], 50 );
174 add_filter( 'rtwpvg_thumbnail_position', [ $this, 'thumbnail_position' ], 50 );
175 add_filter( 'rtwpvg_thumbnails_columns', [ $this, 'thumbnails_columns' ] );
176 add_filter( 'rtwpvg_sm_thumbnails_columns', [ $this, 'thumbnails_columns_sm' ] );
177 add_filter( 'rtwpvg_xs_thumbnails_columns', [ $this, 'thumbnails_columns_xs' ] );
178 // RTSB.
179 add_filter( 'rtsb/vg/thumbnails/position', [ $this, 'vg_thumbnail_position' ], 50 );
180 add_filter( 'rtsb/vg/lightbox', [ $this, 'vg_lightbox' ], 50 );
181 add_filter( 'rtsb/vg/lightbox/trigger/icon', [ $this, 'vg_lightbox' ], 50 );
182 add_filter( 'rtsb/vg/thumbnails/slider/options', [ $this, 'thumbnail_slider_js_options' ], 50, 2 );
183 add_filter( 'rtsb/vg/lightbox/position', [ $this, 'vg_lightbox_position' ], 50, 2 );
184 add_filter( 'rtsb/vg/gallery/columns', [ $this, 'vg_gallery_columns' ], 50, 2 );
185 }
186 /**
187 * Thumbnail Columns.
188 *
189 * @param int $col number.
190 *
191 * @return int
192 */
193 public function vg_gallery_columns( $col ) {
194 $controllers = $this->get_settings_for_display();
195 if ( ! empty( $controllers['gallery_thumbs_column']['size'] ) ) {
196 $col = absint( $controllers['gallery_thumbs_column']['size'] );
197 }
198 return $col;
199 }
200 /**
201 * Thumbnail slider js options.
202 *
203 * @param array $options Options.
204 *
205 * @return array
206 */
207 public function thumbnail_slider_js_options( $options ) {
208 $controllers = $this->get_settings_for_display();
209 if ( ! empty( $controllers['gallery_thumbs_column']['size'] ) ) {
210 $options['slidesPerView'] = absint( $controllers['gallery_thumbs_column']['size'] );
211 }
212 if ( ! empty( $controllers['gallery_thumbs_column_gap']['size'] ) ) {
213 $options['spaceBetween'] = $controllers['gallery_thumbs_column_gap']['size'];
214 }
215 return $options;
216 }
217
218 /**
219 * Thumbnails columns.
220 *
221 * @param int $column Column.
222 *
223 * @return mixed
224 */
225 public function thumbnails_columns( $column ) {
226 $controllers = $this->get_settings_for_display();
227 $column = ! empty( $controllers['gallery_thumbs_column']['size'] ) ? $controllers['gallery_thumbs_column']['size'] : $column;
228
229 return $column;
230 }
231
232 /**
233 * Thumbnails columns.
234 *
235 * @param int $column Column.
236 *
237 * @return mixed
238 */
239 public function thumbnails_columns_sm( $column ) {
240 $controllers = $this->get_settings_for_display();
241 $column = ! empty( $controllers['gallery_thumbs_column_tablet']['size'] ) ? $controllers['gallery_thumbs_column_tablet']['size'] : $column;
242
243 return $column;
244 }
245
246 /**
247 * Thumbnails columns.
248 *
249 * @param int $column Column.
250 *
251 * @return mixed
252 */
253 public function thumbnails_columns_xs( $column ) {
254 $controllers = $this->get_settings_for_display();
255 $column = ! empty( $controllers['gallery_thumbs_column_mobile']['size'] ) ? $controllers['gallery_thumbs_column_mobile']['size'] : $column;
256
257 return $column;
258 }
259 /**
260 * Thumbnail position.
261 *
262 * @param string $position Position.
263 *
264 * @return string
265 */
266 public function thumbnail_position( $position ) {
267 if ( ! function_exists( 'rtwpvg' ) || ! rtwpvg()->active_pro() || ! ( BuilderFns::is_product() || BuilderFns::is_quick_views_page() ) ) {
268 return $position;
269 }
270
271 $controllers = $this->get_settings_for_display();
272 $show_thumbnails = ! empty( $controllers['show_thumbnails'] ) ? $controllers['show_thumbnails'] : false;
273 if ( ! $show_thumbnails && 'grid' !== ( $controllers['image_layout'] ?? '' ) ) {
274 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false', 20 );
275 return 'bottom';
276 }
277 return ! empty( $controllers['image_layout'] ) ? $controllers['image_layout'] : 'bottom';
278 }
279 /**
280 * Thumbnail position.
281 *
282 * @param string $position Position.
283 *
284 * @return string
285 */
286 public function vg_thumbnail_position( $position ) {
287 if ( ! rtsb()->has_pro() ) {
288 return $position;
289 }
290 $controllers = $this->get_settings_for_display();
291 return ! empty( $controllers['image_layout'] ) ? $controllers['image_layout'] : 'bottom';
292 }
293
294 /**
295 * @param bool $lightbox Lightbox.
296 * @return mixed
297 */
298 public function vg_lightbox( $lightbox ) {
299 $controllers = $this->get_settings_for_display();
300 return ! empty( $controllers['lightbox_icon'] ) ? Fns::icons_manager( $controllers['lightbox_icon'] ) : $lightbox;
301 }
302 /**
303 * @param string $position position text.
304 * @return mixed
305 */
306 public function vg_lightbox_position( $position ) {
307 $controllers = $this->get_settings_for_display();
308 return ! empty( $controllers['vg_lightbox_position'] ) ? $controllers['vg_lightbox_position'] : $position;
309 }
310
311 /**
312 * Render Function
313 *
314 * @return void
315 */
316 protected function render() {
317 add_action( 'wp_footer', 'woocommerce_photoswipe' );
318 global $product, $post;
319 $_product = $product;
320 $product = Fns::get_product();
321 $controllers = $this->get_settings_for_display();
322 if ( empty( $controllers['show_module_badges'] ) ) {
323 add_filter( 'rtsb/module/badges/show', '__return_false', 99 );
324 }
325
326 $this->theme_support();
327 $controllers['lightbox_icon'] = Fns::icons_manager( $controllers['lightbox_icon'] );
328 $data = [
329 'template' => 'elementor/single-product/product-images',
330 'controllers' => $controllers,
331 ];
332 $this->the_hooks( $controllers );
333
334 Fns::load_template( $data['template'], $data );
335
336 if ( $this->is_builder_mode() ) {
337 $this->init_scripts();
338 }
339
340 if ( empty( $controllers['show_module_badges'] ) ) {
341 remove_filter( 'rtsb/module/badges/show', '__return_false', 99 );
342 }
343
344 $this->theme_support( 'render_reset' );
345 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
346 }
347 }
348