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

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

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