PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.1.0
ShopBuilder – WooCommerce Builder For Elementor v2.1.0
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 / Helper / RenderHelpers.php

RenderHelpers.php in ShopBuilder – WooCommerce Builder For Elementor 2.1.0, at app/Elementor/Helper/RenderHelpers.php

896 lines 32.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor Render Helper Class.
4 *
5 * This class contains render helper logics.
6 *
7 * @package RadiusTheme\SB
8 */
9
10 namespace RadiusTheme\SB\Elementor\Helper;
11
12 use RadiusTheme\SB\Helpers\BuilderFns;
13 use RadiusTheme\SB\Helpers\Fns;
14
15 // Do not allow directly accessing this file.
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit( 'This script cannot be accessed directly.' );
18 }
19
20 /**
21 * BuilderFns class
22 */
23 class RenderHelpers {
24 /**
25 * Builds an array with field values.
26 *
27 * @param array $meta Field values.
28 * @param string $template Template name.
29 * @param array $raw_settings Raw settings.
30 *
31 * @return array
32 */
33 public static function meta_dataset( array $meta, $template = '', $raw_settings = [] ) {
34 $c_image_size = ! empty( $meta['image_custom_dimension'] ) ? $meta['image_custom_dimension'] : [];
35 $c_image_size['crop'] = ! empty( $meta['image_crop'] ) ? $meta['image_crop'] : '';
36
37 if ( ( ! empty( $_GET['displayview'] ) && 'list' === $_GET['displayview'] ) || ( empty( $_GET['displayview'] ) && ( ! empty( $meta['view_mode'] ) && 'list' === $meta['view_mode'] ) ) ) {
38 $meta['cols'] = ! empty( $meta['list_cols'] ) ? $meta['list_cols'] : 1;
39 $meta['cols_tablet'] = ! empty( $meta['list_cols_tablet'] ) ? $meta['list_cols_tablet'] : $meta['cols'];
40 $meta['cols_mobile'] = ! empty( $meta['list_cols_mobile'] ) ? $meta['list_cols_mobile'] : $meta['cols'];
41 }
42
43 $data = apply_filters(
44 'rtsb/elementor/render/meta_dataset',
45 [
46 // Layout.
47 'widget' => 'custom',
48 'template' => ! empty( $template ) ? $template : '',
49 'raw_settings' => ! empty( $raw_settings ) ? $raw_settings : [],
50 'layout' => ! empty( $meta['layout'] ) ? $meta['layout'] : 'layout1',
51 'grid_layout' => ! empty( $raw_settings['layout'] ) ? $raw_settings['layout'] : 'grid-layout1',
52 'list_layout' => ! empty( $raw_settings['list_layout'] ) ? $raw_settings['list_layout'] : 'list-layout1',
53 'd_cols' => ! empty( $meta['cols'] ) ? $meta['cols'] : 0,
54 't_cols' => ! empty( $meta['cols_tablet'] ) ? $meta['cols_tablet'] : 2,
55 'm_cols' => ! empty( $meta['cols_mobile'] ) ? $meta['cols_mobile'] : 1,
56 'grid_type' => ! empty( $meta['grid_style'] ) ? $meta['grid_style'] : 'even',
57
58 // Query.
59 'post_in' => ! empty( $meta['include_posts'] ) && is_array( $meta['include_posts'] ) ? $meta['include_posts'] : [],
60 'post_not_in' => ! empty( $meta['exclude_posts'] ) && is_array( $meta['exclude_posts'] ) ? $meta['exclude_posts'] : [],
61 'limit' => ( empty( $meta['posts_limit'] ) || '-1' === $meta['posts_limit'] ) ? 10000000 : $meta['posts_limit'],
62 'offset' => ! empty( $meta['posts_offset'] ) ? $meta['posts_offset'] : 0,
63 'order_by' => ! empty( $meta['posts_order_by'] ) ? $meta['posts_order_by'] : 'date',
64 'order' => ! empty( $meta['posts_order'] ) ? $meta['posts_order'] : 'DESC',
65 'author_in' => ! empty( $meta['filter_author'] ) && is_array( $meta['filter_author'] ) ? $meta['filter_author'] : [],
66 'display_by' => ! empty( $meta['products_filter'] ) ? $meta['products_filter'] : 'date',
67 'categories' => ! empty( $meta['filter_categories'] ) && is_array( $meta['filter_categories'] ) ? $meta['filter_categories'] : [],
68 'tags' => ! empty( $meta['filter_tags'] ) && is_array( $meta['filter_tags'] ) ? $meta['filter_tags'] : [],
69 'attributes' => ! empty( $meta['filter_attributes'] ) && is_array( $meta['filter_attributes'] ) ? $meta['filter_attributes'] : [],
70 'relation' => ! empty( $meta['tax_relation'] ) ? $meta['tax_relation'] : 'OR',
71 'category_source' => ! empty( $meta['select_source'] ) ? $meta['select_source'] : 'product_cat',
72 'category_term' => ! empty( $meta['select_cat'] ) ? $meta['select_cat'] : null,
73 'display_cat_by' => ! empty( $meta['display_cat_by'] ) ? $meta['display_cat_by'] : null,
74 'include_cats' => ! empty( $meta['include_cats'] ) && is_array( $meta['include_cats'] ) ? $meta['include_cats'] : [],
75 'exclude_cats' => ! empty( $meta['exclude_cats'] ) && is_array( $meta['exclude_cats'] ) ? $meta['exclude_cats'] : [],
76 'select_parent_cat' => ! empty( $meta['select_parent_cat'] ) ? $meta['select_parent_cat'] : null,
77 'select_cats' => ! empty( $meta['select_cats'] ) && is_array( $meta['select_cats'] ) ? $meta['select_cats'] : [],
78 'select_cat_ids' => ! empty( $meta['include_cat_ids'] ) ? $meta['include_cat_ids'] : '',
79 'cats_limit' => ( empty( $meta['cats_limit'] ) || '-1' === $meta['cats_limit'] ) ? 10000000 : $meta['cats_limit'],
80 'show_empty' => ! empty( $meta['show_empty'] ),
81 'show_uncategorized' => ! empty( $meta['show_uncategorized'] ),
82 'show_subcats' => ! empty( $meta['show_subcats'] ),
83 'show_top_level_cats' => ! empty( $meta['show_top_level_cats'] ),
84 'cats_order_by' => ! empty( $meta['cats_order_by'] ) ? $meta['cats_order_by'] : 'name',
85 'cats_order' => ! empty( $meta['cats_order'] ) ? $meta['cats_order'] : 'DESC',
86 'rtsb_order' => ! empty( $meta['rtsb_order'] ) ? $meta['rtsb_order'] : 'ASC',
87 'rtsb_orderby' => ! empty( $meta['rtsb_orderby'] ) ? $meta['rtsb_orderby'] : 'menu_order',
88
89 // Pagination.
90 'pagination' => ! empty( $meta['show_pagination'] ),
91 'posts_loading_type' => ! empty( $meta['pagination_type'] ) ? $meta['pagination_type'] : 'pagination',
92 'posts_per_page' => ! empty( $meta['pagination_per_page'] ) ? $meta['pagination_per_page'] : '',
93
94 // Image.
95 'f_img' => ! empty( $meta['show_featured_image'] ),
96 'gallery_img' => ! empty( $meta['show_product_gallery'] ),
97 'c_img' => ! empty( $meta['show_cat_image'] ),
98 'hover_img' => ! empty( $meta['show_hover_image'] ),
99 'f_img_size' => ! empty( $meta['image'] ) ? $meta['image'] : 'medium',
100 'custom_img_size' => ! empty( $c_image_size ) && is_array( $c_image_size ) ? $c_image_size : [],
101 'default_img_id' => ! empty( $meta['default_preview_image']['id'] ) ? $meta['default_preview_image']['id'] : null,
102 'show_overlay' => ! empty( $meta['show_overlay'] ),
103 'hover_animation' => ! empty( $meta['image_hover_animation'] ) ? $meta['image_hover_animation'] : 'none',
104 'show_custom_image' => ! empty( $meta['show_custom_image'] ),
105 'custom_image' => ! empty( $meta['custom_image']['id'] ) ? $meta['custom_image']['id'] : null,
106
107 // Visibility.
108 'visibility' => ! empty( self::content_visibility( $meta ) ) ? self::content_visibility( $meta ) : [],
109
110 // Action Buttons.
111 'btn_preset' => ! empty( $meta['action_btn_preset'] ) ? $meta['action_btn_preset'] : 'preset1',
112 'btn_position' => ! empty( $meta['action_btn_position'] ) ? $meta['action_btn_position'] : 'above',
113 'tooltip_position' => ! empty( $meta['action_btn_tooltip_position'] ) ? $meta['action_btn_tooltip_position'] : 'top',
114
115 // Product Title.
116 'title_tag' => ! empty( $meta['title_tag'] ) ? $meta['title_tag'] : 'h3',
117 'title_hover' => ! empty( $meta['title_hover'] ),
118 'title_limit' => ! empty( $meta['title_limit'] ) ? $meta['title_limit'] : 'default',
119 'title_limit_custom' => ! empty( $meta['title_limit_custom'] ) ? $meta['title_limit_custom'] : null,
120 'show_custom_title' => ! empty( $meta['show_custom_title'] ),
121 'cat_custom_title' => ! empty( $meta['custom_title'] ) ? $meta['custom_title'] : '',
122
123 // Variation Swatches.
124 'swatch_position' => ! empty( $meta['swatch_position'] ) ? $meta['swatch_position'] : 'top',
125 'swatch_type' => ! empty( $meta['swatch_type'] ) ? $meta['swatch_type'] : 'circle',
126
127 // Short Description.
128 'show_custom_excerpt' => ! empty( $meta['show_custom_description'] ),
129 'cat_custom_excerpt' => ! empty( $meta['custom_description'] ) ? $meta['custom_description'] : '',
130 'cat_excerpt_position' => ! empty( $meta['excerpt_position'] ) ? $meta['excerpt_position'] : 'below',
131 'excerpt_limit' => ! empty( $meta['excerpt_limit'] ) ? $meta['excerpt_limit'] : 'default',
132 'excerpt_limit_custom' => ! empty( $meta['excerpt_limit_custom'] ) ? $meta['excerpt_limit_custom'] : 200,
133
134 // Count.
135 'count_position' => ! empty( $meta['count_display_type'] ) ? $meta['count_display_type'] : 'flex',
136 'before_count' => ! empty( $meta['before_count'] ) ? $meta['before_count'] : '',
137 'after_count' => ! empty( $meta['after_count'] ) ? $meta['after_count'] : '',
138
139 // Add to cart.
140 'show_cart_icon' => ! empty( $meta['show_cart_icon'] ),
141 'show_cart_text' => ! empty( $meta['show_cart_text'] ),
142 'add_to_cart_icon' => ! empty( $meta['add_to_cart_icon'] ) ? $meta['add_to_cart_icon'] : [],
143 'add_to_cart_success_icon' => ! empty( $meta['add_to_cart_success_icon'] ) ? $meta['add_to_cart_success_icon'] : [],
144 'add_to_cart_text' => ! empty( $meta['add_to_cart_text'] ) ? $meta['add_to_cart_text'] : esc_html__( 'Add to Cart', 'shopbuilder' ),
145 'add_to_cart_success_text' => ! empty( $meta['add_to_cart_success_text'] ) ? $meta['add_to_cart_success_text'] : '',
146 'add_to_cart_alignment' => ! empty( $meta['cart_icon_alignment'] ) ? $meta['cart_icon_alignment'] : 'left',
147
148 // Action Button Icons.
149 'quick_view_icon' => ! empty( $meta['quick_view_icon'] ) ? $meta['quick_view_icon'] : [],
150 'comparison_icon' => ! empty( $meta['comparison_icon'] ) ? $meta['comparison_icon'] : [],
151 'comparison_icon_added' => ! empty( $meta['comparison_icon_added'] ) ? $meta['comparison_icon_added'] : [],
152 'wishlist_icon' => ! empty( $meta['wishlist_icon'] ) ? $meta['wishlist_icon'] : [],
153 'wishlist_icon_added' => ! empty( $meta['wishlist_icon_added'] ) ? $meta['wishlist_icon_added'] : [],
154
155 // Badges.
156 'sale_badge_type' => ! empty( $meta['sale_badges_type'] ) ? $meta['sale_badges_type'] : 'percentage',
157 'sale_badge_text' => ! empty( $meta['sale_badges_text'] ) ? $meta['sale_badges_text'] : esc_html__( 'Sale', 'shopbuilder' ),
158 'custom_badge_text' => ! empty( $meta['custom_badge_text'] ) ? $meta['custom_badge_text'] : esc_html__( 'Sale', 'shopbuilder' ),
159 'out_of_stock_badge_text' => ! empty( $meta['stock_badges_text'] ) ? $meta['stock_badges_text'] : esc_html__( 'Out of Stock', 'shopbuilder' ),
160 'badge_position' => ! empty( $meta['badges_position'] ) ? $meta['badges_position'] : 'top',
161 'badge_alignment' => ! empty( $meta['badges_alignment'] ) ? $meta['badges_alignment'] : 'left',
162 'badge_preset' => ! empty( $meta['custom_badge_preset'] ) ? $meta['custom_badge_preset'] : 'preset-1',
163
164 // Link.
165 'image_link' => ! empty( $meta['image_link'] ),
166 'title_link' => ! empty( $meta['title_link'] ),
167 'hover_btn_text' => ! empty( $meta['hover_btn_text'] ) ? $meta['hover_btn_text'] : esc_html__( 'See Details', 'shopbuilder' ),
168 'show_hover_btn_icon' => ! empty( $meta['show_hover_btn_icon'] ),
169 'hover_btn_icon' => ! empty( $meta['hover_btn_icon'] ) ? $meta['hover_btn_icon'] : [],
170 'custom_link' => ! empty( $meta['custom_link'] ) ? $meta['custom_link'] : null,
171
172 // Slider.
173 'd_group' => ! empty( $meta['cols_group'] ) ? $meta['cols_group'] : 1,
174 't_group' => ! empty( $meta['cols_group_tablet'] ) ? $meta['cols_group_tablet'] : 1,
175 'm_group' => ! empty( $meta['cols_group_mobile'] ) ? $meta['cols_group_mobile'] : 1,
176 'auto_play' => ! empty( $meta['slide_autoplay'] ),
177 'stop_on_hover' => ! empty( $meta['pause_hover'] ),
178 'slider_nav' => ! empty( $meta['slider_nav'] ),
179 'slider_dot' => ! empty( $meta['slider_pagi'] ),
180 'loop' => ! empty( $meta['slider_loop'] ),
181 'lazy_load' => ! empty( $meta['slider_lazy_load'] ),
182 'auto_height' => ! empty( $meta['slider_auto_height'] ),
183 'speed' => ! empty( $meta['slide_speed'] ) ? $meta['slide_speed'] : 2000,
184 'space_between' => isset( $meta['grid_gap']['size'] ) && strlen( $meta['grid_gap']['size'] ) ? $meta['grid_gap']['size'] : 30,
185 'auto_play_timeout' => ! empty( $meta['autoplay_timeout'] ) ? $meta['autoplay_timeout'] : 5000,
186 'nav_position' => ! empty( $meta['slider_nav_position'] ) ? $meta['slider_nav_position'] : 'top',
187 'left_arrow_icon' => ! empty( $meta['slider_left_arrow_icon'] ) ? $meta['slider_left_arrow_icon'] : [],
188 'right_arrow_icon' => ! empty( $meta['slider_right_arrow_icon'] ) ? $meta['slider_right_arrow_icon'] : [],
189 ],
190 $meta
191 );
192
193 if ( ! empty( $meta['cols_widescreen'] ) ) {
194 $data['w_cols'] = $meta['cols_widescreen'];
195 }
196
197 if ( ! empty( $meta['cols_laptop'] ) ) {
198 $data['l_cols'] = $meta['cols_laptop'];
199 }
200
201 if ( ! empty( $meta['cols_tablet_extra'] ) ) {
202 $data['te_cols'] = $meta['cols_tablet_extra'];
203 }
204
205 if ( ! empty( $meta['cols_mobile_extra'] ) ) {
206 $data['me_cols'] = $meta['cols_mobile_extra'];
207 }
208
209 $queried_obj = get_queried_object();
210
211 if ( is_shop() || is_product_taxonomy() ) {
212 $data['posts_per_page'] = self::get_products_per_page();
213 $data['order_by'] = ! empty( $data['rtsb_orderby'] ) ? esc_html( $data['rtsb_orderby'] ) : $data['orderby'];
214 $data['order'] = ! empty( $data['rtsb_order'] ) ? esc_html( $data['rtsb_order'] ) : $data['order'];
215 }
216
217 if ( ! is_shop() && is_product_taxonomy() ) {
218 if ( ! empty( $queried_obj->taxonomy ) ) {
219 $data['queried_tax'] = esc_html( $queried_obj->taxonomy );
220 }
221
222 if ( ! empty( $queried_obj->term_id ) ) {
223 $data['queried_term'] = esc_html( $queried_obj->term_id );
224 }
225 }
226
227 return apply_filters( 'rtsb/elementor/render/meta_dataset_final', $data, $meta, $raw_settings );
228 }
229
230 /**
231 * Builds an array with field values.
232 *
233 * @param array $meta Field values.
234 * @param string $template Template name.
235 *
236 * @return array
237 */
238 public static function archive_meta_dataset( array $meta, $template = '' ) {
239 $data = apply_filters(
240 'rtsb/elementor/render/archive_meta_dataset',
241 [
242 // Layout.
243 'widget' => 'default',
244 'template' => ! empty( $template ) ? $template : '',
245 'view_mode' => ! empty( $meta['view_mode'] ) ? $meta['view_mode'] : 'grid',
246 'show_flash_sale' => ! empty( $meta['show_flash_sale'] ),
247 'wishlist_button' => ! empty( $meta['wishlist_button'] ),
248 'comparison_button' => ! empty( $meta['comparison_button'] ),
249 'quick_view_button' => ! empty( $meta['quick_view_button'] ),
250 'show_rating' => ! empty( $meta['show_rating'] ),
251 'show_pagination' => ! empty( $meta['show_pagination'] ),
252 'cart_icon' => ! empty( $meta['cart_icon'] ) ? $meta['cart_icon'] : [],
253 'wishlist_icon' => ! empty( $meta['wishlist_icon'] ) ? $meta['wishlist_icon'] : [],
254 'wishlist_icon_added' => ! empty( $meta['wishlist_icon_added'] ) ? $meta['wishlist_icon_added'] : [],
255 'comparison_icon' => ! empty( $meta['comparison_icon'] ) ? $meta['comparison_icon'] : [],
256 'comparison_icon_added' => ! empty( $meta['comparison_icon_added'] ) ? $meta['comparison_icon_added'] : [],
257 'quick_view_icon' => ! empty( $meta['quick_view_icon'] ) ? $meta['quick_view_icon'] : [],
258 'prev_icon' => ! empty( $meta['prev_icon'] ) ? $meta['prev_icon'] : [],
259 'next_icon' => ! empty( $meta['next_icon'] ) ? $meta['next_icon'] : [],
260 'posts_per_page' => self::get_products_per_page(),
261 'rtsb_order' => ! empty( $meta['rtsb_order'] ) ? $meta['rtsb_order'] : 'ASC',
262 'rtsb_orderby' => ! empty( $meta['rtsb_orderby'] ) ? $meta['rtsb_orderby'] : 'menu_order',
263 'tooltip_position' => ! empty( $meta['action_btn_tooltip_position'] ) ? $meta['action_btn_tooltip_position'] : 'top',
264 ],
265 $meta
266 );
267
268 $queried_obj = get_queried_object();
269
270 if ( ! is_shop() && BuilderFns::is_archive() ) {
271 if ( ! empty( $queried_obj->taxonomy ) ) {
272 $data['queried_tax'] = esc_html( $queried_obj->taxonomy );
273 }
274
275 if ( ! empty( $queried_obj->term_id ) ) {
276 $data['queried_term'] = esc_html( $queried_obj->term_id );
277 }
278 }
279
280 return apply_filters( 'rtsb/elementor/render/archive_meta_dataset_final', $data, $meta );
281 }
282
283 /**
284 * Setting up content visibility
285 *
286 * @param array $settings Elementor settings.
287 *
288 * @return array
289 */
290 public static function content_visibility( $settings ) {
291 $visibility = [];
292
293 if ( ! empty( $settings['show_title'] ) ) {
294 $visibility[] = 'title';
295 }
296
297 if ( ! empty( $settings['show_short_desc'] ) ) {
298 $visibility[] = 'excerpt';
299 }
300
301 if ( ! empty( $settings['show_price'] ) ) {
302 $visibility[] = 'price';
303 }
304
305 if ( ! empty( $settings['show_rating'] ) ) {
306 $visibility[] = 'rating';
307 }
308
309 if ( ! empty( $settings['show_badges'] ) ) {
310 $visibility[] = 'badges';
311 }
312
313 if ( ! empty( $settings['show_categories'] ) ) {
314 $visibility[] = 'categories';
315 }
316
317 if ( ! empty( $settings['single_category'] ) ) {
318 $visibility[] = 'single-cat';
319 }
320
321 if ( ! empty( $settings['show_swatches'] ) ) {
322 $visibility[] = 'swatches';
323 }
324
325 if ( ! empty( $settings['show_vs_clear_btn'] ) ) {
326 $visibility[] = 'clear-btn';
327 }
328
329 if ( ! empty( $settings['show_count'] ) ) {
330 $visibility[] = 'count';
331 }
332
333 if ( ! empty( $settings['show_wishlist'] ) ) {
334 $visibility[] = 'wishlist';
335 }
336
337 if ( ! empty( $settings['show_compare'] ) ) {
338 $visibility[] = 'compare';
339 }
340
341 if ( ! empty( $settings['show_quick_view'] ) ) {
342 $visibility[] = 'quick_view';
343 }
344
345 if ( ! empty( $settings['show_add_to_cart'] ) ) {
346 $visibility[] = 'add_to_cart';
347 }
348
349 return $visibility;
350 }
351
352 /**
353 * Set Default Layout.
354 *
355 * @param string $layout Layout.
356 *
357 * @return string
358 */
359 public static function set_default_layout( $layout ) {
360 $is_list = preg_match( '/list/', $layout );
361 $is_cat_single = preg_match( '/category-single/', $layout );
362 $is_cat = preg_match( '/category/', $layout );
363 $is_carousel = preg_match( '/slider/', $layout );
364 $default = 'grid-layout1';
365
366 if ( $is_list ) {
367 $default = 'list-layout1';
368 } elseif ( $is_cat_single ) {
369 $default = 'category-single-layout1';
370 } elseif ( $is_cat ) {
371 $default = 'category-layout1';
372 } elseif ( $is_carousel ) {
373 $default = 'slider-layout1';
374 }
375
376 return $default;
377 }
378
379 /**
380 * Default layout columns.
381 *
382 * @param int $layout Layout.
383 *
384 * @return int
385 */
386 public static function default_columns( $layout ) {
387 switch ( $layout ) {
388 case 'grid-layout2':
389 case 'slider-layout2':
390 $columns = 3;
391 break;
392
393 case 'list-layout1':
394 case 'list-layout2':
395 case 'list-layout3':
396 case 'list-layout5':
397 $columns = 1;
398 break;
399
400 case 'list-layout4':
401 case 'list-layout6':
402 case 'slider-layout5':
403 case 'slider-layout8':
404 $columns = 2;
405 break;
406
407 case 'grid-layout6':
408 $columns = 5;
409 break;
410
411 case 'category-layout1':
412 $columns = 6;
413 break;
414
415 default:
416 $columns = 4;
417 break;
418 }
419
420 return apply_filters( 'rtsb/element/general/default_columns', $columns, $layout );
421 }
422
423 /**
424 * Pagination JSON data.
425 *
426 * @param array $metas Data set.
427 * @param string $template Template name.
428 *
429 * @return string
430 */
431 public static function pagination_data( $metas, $template ) {
432 $el_data = self::meta_dataset( $metas, $template );
433
434 return ' data-rtsb-ajax=\'' . esc_js( wp_json_encode( $el_data ) ) . '\'';
435 }
436
437 /**
438 * Archive JSON data.
439 *
440 * @param array $metas Data set.
441 * @param string $template Template name.
442 *
443 * @return string
444 */
445 public static function archive_data( $metas, $template ) {
446 $el_data = self::archive_meta_dataset( $metas, $template );
447
448 return ' data-rtsb-ajax=\'' . esc_js( wp_json_encode( $el_data ) ) . '\'';
449 }
450
451 /**
452 * Slider options.
453 *
454 * @param array $meta Meta values.
455 * @param array $settings Raw Settings.
456 *
457 * @return array
458 */
459 public static function slider_data( array $meta, $settings = [] ) {
460 $has_dots = $meta['slider_dot'] ? ' has-dot' : ' no-dot';
461 $has_dots .= $meta['slider_nav'] ? ' has-nav' : ' no-nav';
462 $d_col = 0 === $meta['d_cols'] ? self::default_columns( $meta['layout'] ) : $meta['d_cols'];
463 $t_col = 0 === $meta['t_cols'] ? 2 : $meta['t_cols'];
464 $m_col = 0 === $meta['m_cols'] ? 1 : $meta['m_cols'];
465
466 if ( \Elementor\Plugin::$instance->breakpoints->has_custom_breakpoints() ) {
467 // Widescreen.
468 $w_col = ! empty( $settings['cols_widescreen'] ) ? $settings['cols_widescreen'] : null;
469 $w_col = 0 === $w_col ? self::default_columns( $meta['layout'] ) : $w_col;
470 $w_group = ! empty( $settings['cols_group_widescreen'] ) ? $settings['cols_group_widescreen'] : 1;
471
472 // Laptop.
473 $l_col = ! empty( $settings['cols_laptop'] ) ? $settings['cols_laptop'] : null;
474 $l_col = 0 === $l_col ? self::default_columns( $meta['layout'] ) : $l_col;
475 $l_group = ! empty( $settings['cols_group_laptop'] ) ? $settings['cols_group_laptop'] : 1;
476
477 // Tablet Landscape.
478 $te_col = ! empty( $settings['cols_tablet_extra'] ) ? $settings['cols_tablet_extra'] : null;
479 $te_col = 0 === $te_col ? 3 : $te_col;
480 $te_group = ! empty( $settings['cols_group_tablet_extra'] ) ? $settings['cols_group_tablet_extra'] : 1;
481
482 // Mobile Landscape.
483 $me_col = ! empty( $settings['cols_mobile_extra'] ) ? $settings['cols_mobile_extra'] : null;
484 $me_col = 0 === $me_col ? 2 : $me_col;
485 $me_group = ! empty( $settings['cols_group_mobile_extra'] ) ? $settings['cols_group_mobile_extra'] : 1;
486
487 $el_breakpoints = Fns::get_elementor_breakpoints();
488
489 foreach ( $el_breakpoints as $key => $value ) {
490 if ( isset( $value['is_enabled'] ) && ! $value['is_enabled'] ) {
491 unset( $el_breakpoints[ $key ] );
492 }
493 }
494
495 $breakpoints = [
496 0 => [
497 'slidesPerView' => absint( $m_col ),
498 'slidesPerGroup' => absint( $meta['m_group'] ),
499 'pagination' => [
500 'dynamicBullets' => true,
501 ],
502 ],
503 ];
504
505 $desktop = [
506 'desktop' => [
507 'label' => 'Desktop',
508 'value' => 1920,
509 'is_enabled' => 1,
510 ],
511 ];
512
513 if ( ! empty( $el_breakpoints['laptop'] ) && $el_breakpoints['laptop']['is_enabled'] ) {
514 $widescreen_position = array_search( 'widescreen', array_keys( $el_breakpoints ), true );
515 $el_breakpoints = array_merge(
516 array_slice( $el_breakpoints, 0, $widescreen_position ),
517 $desktop,
518 array_slice( $el_breakpoints, $widescreen_position )
519 );
520 } else {
521 $desktop['desktop']['value'] = 1366;
522 $el_breakpoints['desktop'] = $desktop['desktop'];
523 }
524
525 foreach ( $el_breakpoints as $el_breakpoint => $value ) {
526 $breakpoint_value = ! empty( $value['value'] ) ? $value['value'] : $value['default_value'];
527 $dynamic_bullets = false;
528 $slides_per_view = $d_col;
529 $slides_per_group = $meta['d_group'];
530
531 switch ( $el_breakpoint ) {
532 case 'widescreen':
533 $slides_per_view = $w_col;
534 $slides_per_group = $w_group;
535
536 break;
537
538 case 'laptop':
539 $slides_per_view = $l_col;
540 $slides_per_group = $l_group;
541
542 break;
543
544 case 'tablet_extra':
545 $slides_per_view = $l_col;
546 $slides_per_group = $l_group;
547
548 if ( empty( $el_breakpoints['laptop'] ) ) {
549 $slides_per_view = $d_col;
550 $slides_per_group = $meta['d_group'];
551 }
552
553 break;
554
555 case 'tablet':
556 $slides_per_view = $te_col;
557 $slides_per_group = $te_group;
558
559 if ( empty( $el_breakpoints['laptop'] ) && empty( $el_breakpoints['tablet_extra'] ) ) {
560 $slides_per_view = $d_col;
561 $slides_per_group = $meta['d_group'];
562 } elseif ( empty( $el_breakpoints['laptop'] ) && ! empty( $el_breakpoints['tablet_extra'] ) ) {
563 $slides_per_view = $te_col;
564 $slides_per_group = $te_group;
565 } elseif ( ! empty( $el_breakpoints['laptop'] ) && empty( $el_breakpoints['tablet_extra'] ) ) {
566 $slides_per_view = $l_col;
567 $slides_per_group = $l_group;
568 }
569
570 break;
571
572 case 'mobile_extra':
573 $slides_per_view = $t_col;
574 $slides_per_group = $meta['t_group'];
575 $dynamic_bullets = true;
576
577 break;
578
579 case 'mobile':
580 $slides_per_view = $t_col;
581 $slides_per_group = $meta['t_group'];
582 $dynamic_bullets = true;
583
584 if ( ! empty( $el_breakpoints['mobile_extra'] ) ) {
585 $slides_per_view = $me_col;
586 $slides_per_group = $me_group;
587 }
588
589 break;
590 }
591
592 if ( $value['is_enabled'] ) {
593 $br = 'widescreen' !== $el_breakpoint ? $breakpoint_value + 1 : $breakpoint_value;
594
595 $breakpoints[ absint( $br ) ] = [
596 'slidesPerView' => absint( $slides_per_view ),
597 'slidesPerGroup' => absint( $slides_per_group ),
598 'pagination' => [
599 'dynamicBullets' => $dynamic_bullets,
600 ],
601 ];
602 }
603 }
604 } else {
605 $breakpoints = [
606 0 => [
607 'slidesPerView' => absint( $m_col ),
608 'slidesPerGroup' => absint( $meta['m_group'] ),
609 'pagination' => [
610 'dynamicBullets' => true,
611 ],
612 ],
613 768 => [
614 'slidesPerView' => absint( $t_col ),
615 'slidesPerGroup' => absint( $meta['t_group'] ),
616 'pagination' => [
617 'dynamicBullets' => false,
618 ],
619 ],
620 1025 => [
621 'slidesPerView' => absint( $d_col ),
622 'slidesPerGroup' => absint( $meta['d_group'] ),
623 'pagination' => [
624 'dynamicBullets' => false,
625 ],
626 ],
627 ];
628 }
629
630 $slider_options = [
631 'slidesPerView' => absint( $d_col ),
632 'slidesPerGroup' => absint( $meta['d_group'] ),
633 'speed' => absint( $meta['speed'] ),
634 'loop' => $meta['loop'],
635 'autoHeight' => $meta['auto_height'],
636 'preloadImages' => ! $meta['lazy_load'],
637 'lazy' => $meta['lazy_load'],
638 'breakpoints' => $breakpoints,
639 ];
640
641 if ( $meta['auto_play'] ) {
642 $slider_options['autoplay'] = [
643 'delay' => absint( $meta['auto_play_timeout'] ),
644 'pauseOnMouseEnter' => $meta['stop_on_hover'],
645 'disableOnInteraction' => false,
646 ];
647 }
648
649 $slider_options = apply_filters( 'rtsb/elementor/render/slider_dataset', $slider_options, $meta );
650 $carouselClass = 'rtsb-carousel-slider slider-loading rtsb-pos-s ' . $meta['nav_position'] . '-nav' . $has_dots;
651
652 return [
653 'data' => ' data-options=\'' . esc_js( wp_json_encode( $slider_options ) ) . '\'',
654 'class' => $carouselClass,
655 ];
656 }
657
658 /**
659 * Renders pagination
660 *
661 * @param object $wp_query WP_Query object.
662 * @param array $meta Meta values.
663 * @param int $limit Post limit.
664 * @param int $per_page Posts per page.
665 *
666 * @return string
667 */
668 public static function render_pagination( $wp_query, $meta, $limit, $per_page ) {
669 $html_utility = null;
670 $html = null;
671 $ajax = false;
672 $is_grid = preg_match( '/grid-layout/', $meta['layout'] ) || preg_match( '/list-layout/', $meta['layout'] );
673 $posts_per_page = $wp_query->query_vars['posts_per_page'];
674 $total_page = $wp_query->max_num_pages;
675
676 if ( $limit && ( empty( $wp_query->query['tax_query'] ) ) ) {
677 $found_post = $wp_query->found_posts;
678
679 if ( $per_page && $found_post > $per_page ) {
680 $found_post = $limit;
681 $total_page = ceil( $found_post / $per_page );
682 }
683 }
684
685 $total_page = absint( $total_page );
686
687 $args = [
688 'total_page' => $total_page,
689 'posts_per_page' => $posts_per_page,
690 'ajax' => $ajax,
691 ];
692
693 if ( 'pagination' === $meta['posts_loading_type'] ) {
694 if ( $is_grid ) {
695 $html_utility .= Fns::custom_pagination(
696 $total_page,
697 $posts_per_page
698 );
699 }
700 } else {
701 ob_start();
702 do_action( 'rtsb/elementor/render/pagination', $meta, $wp_query, $args );
703 $html_utility .= ob_get_clean();
704 }
705
706 if ( $html_utility ) {
707 $html .= '<div class="rtsb-pagination-wrap element-loading" data-total-pages="' . absint( $total_page ) . '" data-posts-per-page="' . absint( $posts_per_page ) . '" data-type="' . esc_attr( $meta['posts_loading_type'] ) . '">' . $html_utility . '</div>';
708 }
709
710 return $html;
711 }
712
713 /**
714 * Renders products pagination
715 *
716 * @param array $args Pagination args.
717 *
718 * @return string
719 */
720 public static function render_products_pagination( $args ) {
721 list(
722 'query' => $query,
723 'meta' => $meta,
724 'limit' => $limit,
725 'per_page' => $per_page
726 ) = $args;
727
728 $html_utility = null;
729 $html = null;
730 $ajax = false;
731 $is_grid = preg_match( '/grid-layout/', $meta['layout'] ) || preg_match( '/list-layout/', $meta['layout'] );
732 $total_page = $query->get_products()->max_num_pages;
733
734 if ( $limit ) {
735 $found_post = $query->get_products()->total;
736
737 if ( $per_page && $found_post > $per_page ) {
738 $found_post = $limit;
739 $total_page = ceil( $found_post / $per_page );
740 }
741 }
742
743 $total_page = absint( $total_page );
744
745 $args = [
746 'total_page' => $total_page,
747 'posts_per_page' => $per_page,
748 'ajax' => $ajax,
749 ];
750
751 if ( 'pagination' === $meta['posts_loading_type'] ) {
752 if ( $is_grid ) {
753 $html_utility .= Fns::custom_pagination(
754 $total_page,
755 $per_page
756 );
757 }
758 } else {
759 ob_start();
760 do_action( 'rtsb/elementor/render/pagination', $meta, $query, $args );
761 $html_utility .= ob_get_clean();
762 }
763
764 if ( $html_utility ) {
765 $html .= '<div class="rtsb-pagination-wrap element-loading" data-total-pages="' . absint( $total_page ) . '" data-posts-per-page="' . absint( $per_page ) . '" data-type="' . esc_attr( $meta['posts_loading_type'] ) . '">' . $html_utility . '</div>';
766 }
767
768 return $html;
769 }
770
771 /**
772 * Preloader.
773 *
774 * @param string $layout Layout.
775 *
776 * @return string
777 */
778 public static function pre_loader( $layout ) {
779 $loader_class = '';
780
781 $is_carousel = preg_match( '/slider/', $layout );
782
783 if ( $is_carousel ) {
784 $loader_class = ' full-op';
785 }
786
787 return '<div class="rtsb-elements-loading rtsb-ball-clip-rotate"><div></div></div>';
788 }
789
790 /**
791 * Badge class.
792 *
793 * @param string $preset Badge preset.
794 *
795 * @return string|null
796 */
797 public static function badge_class( $preset ) {
798 switch ( $preset ) {
799 case 'preset-default':
800 $class = 'default-badge';
801 break;
802 case 'preset2':
803 $class = 'fill angle-right';
804 break;
805 case 'preset3':
806 $class = 'outline';
807 break;
808
809 case 'preset4':
810 $class = 'outline angle-right';
811 break;
812
813 default:
814 $class = 'fill';
815 break;
816 }
817
818 return $class;
819 }
820
821 /**
822 * Registers required scripts.
823 *
824 * @param array $scripts Scripts to register.
825 *
826 * @return void
827 */
828 public static function register_scripts( $scripts ) {
829 $caro = false;
830 $script = [];
831
832 $script[] = 'jquery';
833
834 foreach ( $scripts as $sc => $value ) {
835 if ( ! empty( $sc ) ) {
836 if ( 'isCarousel' === $sc ) {
837 $caro = $value;
838 }
839 }
840 }
841
842 if ( count( $scripts ) ) {
843 /**
844 * Scripts.
845 */
846 if ( $caro ) {
847 $script[] = 'swiper';
848 }
849
850 $script[] = 'rtsb-imagesloaded';
851 $script[] = 'rtsb-public';
852
853 wp_enqueue_script( $script );
854 }
855 }
856
857 /**
858 * Check if a wrapper is needed based on the current theme.
859 *
860 * @return bool
861 */
862 public static function is_wrapper_needed() {
863 $theme_list = apply_filters(
864 'rtsb/products/inner/wrapper/basedon/themes',
865 [
866 'twentytwentyone',
867 'twentytwentytwo',
868 'twentytwentythree',
869 'storefront',
870 'hello-elementor',
871 'astra',
872 ],
873 rtsb()->current_theme
874 );
875
876 if ( in_array( rtsb()->current_theme, $theme_list, true ) ) {
877 return true;
878 }
879
880 return false;
881 }
882
883 /**
884 * Get the number of products per page based on WooCommerce settings.
885 *
886 * @return int
887 */
888 public static function get_products_per_page() {
889 $products_row = absint( get_option( 'woocommerce_catalog_rows', 4 ) );
890 $products_col = absint( get_option( 'woocommerce_catalog_columns', 4 ) );
891 $products_per_page = apply_filters( 'rtsb/elementor/archive/products_per_page', $products_row * $products_col );
892
893 return ! empty( $products_per_page ) ? $products_per_page : 12;
894 }
895 }
896