PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.0.1
ShopBuilder – WooCommerce Builder For Elementor v2.0.1
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.0.1, at app/Elementor/Helper/RenderHelpers.php

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