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

672 lines 25.3 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_mobile'] ) ? $meta['cols_group_mobile'] : 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 *
449 * @return array
450 */
451 public static function slider_data( array $meta ) {
452 $has_dots = $meta['slider_dot'] ? ' has-dot' : ' no-dot';
453 $has_dots .= $meta['slider_nav'] ? ' has-nav' : ' no-nav';
454
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 $slider_options = [
460 'slidesPerView' => absint( $d_col ),
461 'slidesPerGroup' => absint( $meta['d_group'] ),
462 'speed' => absint( $meta['speed'] ),
463 'loop' => $meta['loop'],
464 'autoHeight' => $meta['auto_height'],
465 'preloadImages' => ! $meta['lazy_load'],
466 'lazy' => $meta['lazy_load'],
467 'breakpoints' => [
468 0 => [
469 'slidesPerView' => absint( $m_col ),
470 'slidesPerGroup' => absint( $meta['m_group'] ),
471 'pagination' => [
472 'dynamicBullets' => true,
473 ],
474 ],
475 767 => [
476 'slidesPerView' => absint( $t_col ),
477 'slidesPerGroup' => absint( $meta['t_group'] ),
478 'pagination' => [
479 'dynamicBullets' => false,
480 ],
481 ],
482 991 => [
483 'slidesPerView' => absint( $d_col ),
484 'slidesPerGroup' => absint( $meta['d_group'] ),
485 ],
486 ],
487 ];
488
489 if ( $meta['auto_play'] ) {
490 $slider_options['autoplay'] = [
491 'delay' => absint( $meta['auto_play_timeout'] ),
492 'pauseOnMouseEnter' => $meta['stop_on_hover'],
493 'disableOnInteraction' => false,
494 ];
495 }
496
497 $carouselClass = 'rtsb-carousel-slider slider-loading rtsb-pos-s ' . $meta['nav_position'] . '-nav' . $has_dots;
498
499 return [
500 'data' => ' data-options=\'' . esc_js( wp_json_encode( $slider_options ) ) . '\'',
501 'class' => $carouselClass,
502 ];
503 }
504
505 /**
506 * Renders pagination
507 *
508 * @param object $wp_query WP_Query object.
509 * @param array $meta Meta values.
510 * @param int $limit Post limit.
511 * @param int $per_page Posts per page.
512 *
513 * @return string
514 */
515 public static function render_pagination( $wp_query, $meta, $limit, $per_page ) {
516 $html_utility = null;
517 $html = null;
518 $ajax = false;
519 $is_grid = preg_match( '/grid-layout/', $meta['layout'] ) || preg_match( '/list-layout/', $meta['layout'] );
520 $posts_per_page = $wp_query->query_vars['posts_per_page'];
521 $total_page = $wp_query->max_num_pages;
522
523 if ( $limit && ( empty( $wp_query->query['tax_query'] ) ) ) {
524 $found_post = $wp_query->found_posts;
525
526 if ( $per_page && $found_post > $per_page ) {
527 $found_post = $limit;
528 $total_page = ceil( $found_post / $per_page );
529 }
530 }
531
532 $total_page = absint( $total_page );
533
534 $args = [
535 'total_page' => $total_page,
536 'posts_per_page' => $posts_per_page,
537 'ajax' => $ajax,
538 ];
539
540 if ( 'pagination' === $meta['posts_loading_type'] ) {
541 if ( $is_grid ) {
542 $html_utility .= Fns::custom_pagination(
543 $total_page,
544 $posts_per_page
545 );
546 }
547 } else {
548 ob_start();
549 do_action( 'rtsb/elementor/render/pagination', $meta, $wp_query, $args );
550 $html_utility .= ob_get_clean();
551 }
552
553 if ( $html_utility ) {
554 $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>';
555 }
556
557 return $html;
558 }
559
560 /**
561 * Preloader.
562 *
563 * @param string $layout Layout.
564 *
565 * @return string
566 */
567 public static function pre_loader( $layout ) {
568 $loader_class = '';
569
570 $is_carousel = preg_match( '/slider/', $layout );
571
572 if ( $is_carousel ) {
573 $loader_class = ' full-op';
574 }
575
576 return '<div class="rtsb-elements-loading rtsb-ball-clip-rotate"><div></div></div>';
577 }
578
579 /**
580 * Badge class.
581 *
582 * @param string $preset Badge preset.
583 *
584 * @return string|null
585 */
586 public static function badge_class( $preset ) {
587 switch ( $preset ) {
588 case 'preset-default':
589 $class = 'default-badge';
590 break;
591 case 'preset2':
592 $class = 'fill angle-right';
593 break;
594 case 'preset3':
595 $class = 'outline';
596 break;
597
598 case 'preset4':
599 $class = 'outline angle-right';
600 break;
601
602 default:
603 $class = 'fill';
604 break;
605 }
606
607 return $class;
608 }
609
610 /**
611 * Registers required scripts.
612 *
613 * @param array $scripts Scripts to register.
614 *
615 * @return void
616 */
617 public static function register_scripts( $scripts ) {
618 $caro = false;
619 $script = [];
620
621 $script[] = 'jquery';
622
623 foreach ( $scripts as $sc => $value ) {
624 if ( ! empty( $sc ) ) {
625 if ( 'isCarousel' === $sc ) {
626 $caro = $value;
627 }
628 }
629 }
630
631 if ( count( $scripts ) ) {
632 /**
633 * Scripts.
634 */
635 if ( $caro ) {
636 $script[] = 'swiper';
637 }
638
639 $script[] = 'rtsb-imagesloaded';
640 $script[] = 'rtsb-public';
641
642 wp_enqueue_script( $script );
643 }
644 }
645
646 /**
647 * Check if a wrapper is needed based on the current theme.
648 *
649 * @return bool
650 */
651 public static function is_wrapper_needed() {
652 $theme_list = apply_filters(
653 'rtsb/products/inner/wrapper/basedon/themes',
654 [
655 'twentytwentyone',
656 'twentytwentytwo',
657 'twentytwentythree',
658 'storefront',
659 'hello-elementor',
660 'astra',
661 ],
662 rtsb()->current_theme
663 );
664
665 if ( in_array( rtsb()->current_theme, $theme_list, true ) ) {
666 return true;
667 }
668
669 return false;
670 }
671 }
672