PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.1.3
ShopBuilder – WooCommerce Builder For Elementor v3.1.3
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.1.3, 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 add_action( 'wp_footer', 'woocommerce_photoswipe' );
37 $this->the_hooks();
38 }
39 /**
40 * Widget Field
41 *
42 * @return array
43 */
44 public function widget_fields() {
45 return $this->modify_widget_fields();
46 }
47 /**
48 * Widget Field
49 *
50 * @return array
51 */
52 public function modify_widget_fields() {
53 $fields = ProductImagesSettings::widget_fields( $this );
54 $extra_controls['image_border'] = [
55 'mode' => 'group',
56 'type' => 'border',
57 'selector' => $this->selectors['image_border'],
58 'size_units' => [ 'px' ],
59 'fields_options' => [
60 'border' => [
61 'label' => esc_html__( 'Border', 'shopbuilder' ),
62 'label_block' => true,
63 ],
64 'color' => [
65 'label' => esc_html__( 'Border Color', 'shopbuilder' ),
66 ],
67 ],
68 ];
69 $fields = Fns::insert_controls( 'image_width', $fields, $extra_controls, true );
70 return $fields;
71 }
72
73 /**
74 * Widget Field.
75 *
76 * @return void
77 */
78 public function init_scripts() {
79 ?>
80 <script type="text/javascript">
81 if (!'<?php echo esc_attr( Fns::is_optimization_enabled() ); ?>') {
82 setTimeout(function() {
83 window.rtsbVariationGallery();
84 }, 4000);
85 } else {
86 if (typeof elementorFrontend !== 'undefined') {
87 elementorFrontend.hooks.addAction(
88 'frontend/element_ready/<?php echo esc_attr( $this->rtsb_base ); ?>.default',
89 () => {
90 window.waitForRTSB((RTSB) => {
91 RTSB.modules.get('variationGallery')?.refresh();
92 });
93 }
94 );
95 }
96 }
97 /*
98 * Initialize all galleries on page.
99 */
100 jQuery('.woocommerce-product-gallery').each(function () {
101 const that = this;
102
103 setTimeout(function () {
104 jQuery(this).trigger('wc-product-gallery-before-init', [this, wc_single_product_params]);
105 jQuery(that).wc_product_gallery(wc_single_product_params);
106 jQuery(that).trigger('wc-product-gallery-after-init', [this, wc_single_product_params]);
107 }, 1000);
108
109 });
110 <?php if ( function_exists( 'rtwpvg' ) ) { ?>
111 setTimeout(function () {
112 jQuery('.rtwpvg-wrapper, .rtwpvg-grid-wrapper').rtWpVGallery();
113 }, 1000);
114 <?php } ?>
115
116
117 if (!'<?php echo esc_attr( Fns::is_optimization_enabled() ); ?>') {
118 jQuery(document).ready(function ($) {
119 setTimeout(function () {
120 const zoomIcon = $('.rtsb-product-images').attr('data-zoom-icon');
121 if (!zoomIcon) {
122 $('.rtsb-product-images')
123 .find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger')
124 .remove();
125 }
126 $('.rtsb-product-images')
127 .find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger')
128 .html(zoomIcon);
129 }, 50);
130 });
131 } else {
132 if (typeof elementorFrontend !== 'undefined') {
133 elementorFrontend.hooks.addAction(
134 'frontend/element_ready/<?php echo esc_attr( $this->rtsb_base ); ?>.default',
135 ($scope) => {
136 window.waitForRTSB((RTSB) => {
137 RTSB.modules.get('productImage')?.refresh?.($, $scope);
138 });
139 }
140 );
141 }
142 }
143
144 </script>
145 <?php
146 }
147
148 /**
149 * Widget Field.
150 *
151 * @param array $control Control.
152 *
153 * @return void
154 */
155 public function the_hooks( $control = [] ) {
156 if ( empty( $control ) ) {
157 return;
158 }
159 add_filter(
160 'woocommerce_product_thumbnails_columns',
161 function ( $col ) {
162 $col = 0;
163
164 return $col;
165 }
166 );
167 if ( empty( $control['show_zoom'] ) ) {
168 add_filter( 'rtwpvg_trigger_icon', '__return_false' );
169 }
170 if ( empty( $control['show_thumbnails'] ) ) {
171 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false' );
172 remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
173 }
174 add_filter( 'rtwpvg_thumbnail_slider_js_options', [ $this, 'thumbnail_slider_js_options' ], 50 );
175 add_filter( 'rtwpvg_thumbnail_position', [ $this, 'thumbnail_position' ], 50 );
176 add_filter( 'rtwpvg_thumbnails_columns', [ $this, 'thumbnails_columns' ] );
177 add_filter( 'rtwpvg_sm_thumbnails_columns', [ $this, 'thumbnails_columns_sm' ] );
178 add_filter( 'rtwpvg_xs_thumbnails_columns', [ $this, 'thumbnails_columns_xs' ] );
179 // RTSB.
180 add_filter( 'rtsb/vg/thumbnails/position', [ $this, 'vg_thumbnail_position' ], 50 );
181 add_filter( 'rtsb/vg/lightbox', [ $this, 'vg_lightbox' ], 50 );
182 add_filter( 'rtsb/vg/lightbox/trigger/icon', [ $this, 'vg_lightbox' ], 50 );
183 add_filter( 'rtsb/vg/thumbnails/slider/options', [ $this, 'thumbnail_slider_js_options' ], 50, 2 );
184 add_filter( 'rtsb/vg/lightbox/position', [ $this, 'vg_lightbox_position' ], 50, 2 );
185 add_filter( 'rtsb/vg/gallery/columns', [ $this, 'vg_gallery_columns' ], 50, 2 );
186 }
187 /**
188 * Thumbnail Columns.
189 *
190 * @param int $col number.
191 *
192 * @return int
193 */
194 public function vg_gallery_columns( $col ) {
195 $controllers = $this->get_settings_for_display();
196 if ( ! empty( $controllers['gallery_thumbs_column']['size'] ) ) {
197 $col = absint( $controllers['gallery_thumbs_column']['size'] );
198 }
199 return $col;
200 }
201 /**
202 * Thumbnail slider js options.
203 *
204 * @param array $options Options.
205 *
206 * @return array
207 */
208 public function thumbnail_slider_js_options( $options ) {
209 $controllers = $this->get_settings_for_display();
210 if ( ! empty( $controllers['gallery_thumbs_column']['size'] ) ) {
211 $options['slidesPerView'] = absint( $controllers['gallery_thumbs_column']['size'] );
212 }
213 if ( ! empty( $controllers['gallery_thumbs_column_gap']['size'] ) ) {
214 $options['spaceBetween'] = $controllers['gallery_thumbs_column_gap']['size'];
215 }
216 return $options;
217 }
218
219 /**
220 * Thumbnails columns.
221 *
222 * @param int $column Column.
223 *
224 * @return mixed
225 */
226 public function thumbnails_columns( $column ) {
227 $controllers = $this->get_settings_for_display();
228 $column = ! empty( $controllers['gallery_thumbs_column']['size'] ) ? $controllers['gallery_thumbs_column']['size'] : $column;
229
230 return $column;
231 }
232
233 /**
234 * Thumbnails columns.
235 *
236 * @param int $column Column.
237 *
238 * @return mixed
239 */
240 public function thumbnails_columns_sm( $column ) {
241 $controllers = $this->get_settings_for_display();
242 $column = ! empty( $controllers['gallery_thumbs_column_tablet']['size'] ) ? $controllers['gallery_thumbs_column_tablet']['size'] : $column;
243
244 return $column;
245 }
246
247 /**
248 * Thumbnails columns.
249 *
250 * @param int $column Column.
251 *
252 * @return mixed
253 */
254 public function thumbnails_columns_xs( $column ) {
255 $controllers = $this->get_settings_for_display();
256 $column = ! empty( $controllers['gallery_thumbs_column_mobile']['size'] ) ? $controllers['gallery_thumbs_column_mobile']['size'] : $column;
257
258 return $column;
259 }
260 /**
261 * Thumbnail position.
262 *
263 * @param string $position Position.
264 *
265 * @return string
266 */
267 public function thumbnail_position( $position ) {
268 if ( ! function_exists( 'rtwpvg' ) || ! rtwpvg()->active_pro() || ! ( BuilderFns::is_product() || BuilderFns::is_quick_views_page() ) ) {
269 return $position;
270 }
271
272 $controllers = $this->get_settings_for_display();
273 $show_thumbnails = ! empty( $controllers['show_thumbnails'] ) ? $controllers['show_thumbnails'] : false;
274 if ( ! $show_thumbnails && 'grid' !== ( $controllers['image_layout'] ?? '' ) ) {
275 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false', 20 );
276 return 'bottom';
277 }
278 return ! empty( $controllers['image_layout'] ) ? $controllers['image_layout'] : 'bottom';
279 }
280 /**
281 * Thumbnail position.
282 *
283 * @param string $position Position.
284 *
285 * @return string
286 */
287 public function vg_thumbnail_position( $position ) {
288 if ( ! rtsb()->has_pro() ) {
289 return $position;
290 }
291 $controllers = $this->get_settings_for_display();
292 return ! empty( $controllers['image_layout'] ) ? $controllers['image_layout'] : 'bottom';
293 }
294
295 /**
296 * @param bool $lightbox Lightbox.
297 * @return mixed
298 */
299 public function vg_lightbox( $lightbox ) {
300 $controllers = $this->get_settings_for_display();
301 return ! empty( $controllers['lightbox_icon'] ) ? Fns::icons_manager( $controllers['lightbox_icon'] ) : $lightbox;
302 }
303 /**
304 * @param string $position position text.
305 * @return mixed
306 */
307 public function vg_lightbox_position( $position ) {
308 $controllers = $this->get_settings_for_display();
309 return ! empty( $controllers['vg_lightbox_position'] ) ? $controllers['vg_lightbox_position'] : $position;
310 }
311
312 /**
313 * Render Function
314 *
315 * @return void
316 */
317 protected function render() {
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