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