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 -948 2.1.31.1.4 View file →
@@ -1,948 +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 -
183 - // Link.
184 - 'image_link' => ! empty( $meta['image_link'] ),
185 - 'title_link' => ! empty( $meta['title_link'] ),
186 - 'hover_btn_text' => self::get_data( $meta, 'hover_btn_text', esc_html__( 'See Details', 'shopbuilder' ) ),
187 - 'show_hover_btn_icon' => ! empty( $meta['show_hover_btn_icon'] ),
188 - 'hover_btn_icon' => self::get_data( $meta, 'hover_btn_icon', [] ),
189 - 'custom_link' => self::get_data( $meta, 'custom_link' ),
190 -
191 - // Slider.
192 - 'd_group' => self::get_data( $meta, 'cols_group', 1 ),
193 - 't_group' => self::get_data( $meta, 'cols_group_tablet', 1 ),
194 - 'm_group' => self::get_data( $meta, 'cols_group_mobile', 1 ),
195 - 'auto_play' => ! empty( $meta['slide_autoplay'] ),
196 - 'stop_on_hover' => ! empty( $meta['pause_hover'] ),
197 - 'slider_nav' => ! empty( $meta['slider_nav'] ),
198 - 'slider_dot' => ! empty( $meta['slider_pagi'] ),
199 - 'loop' => ! empty( $meta['slider_loop'] ),
200 - 'lazy_load' => ! empty( $meta['slider_lazy_load'] ),
201 - 'auto_height' => ! empty( $meta['slider_auto_height'] ),
202 - 'speed' => self::get_data( $meta, 'slide_speed', 2000 ),
203 - 'space_between' => isset( $meta['grid_gap']['size'] ) && strlen( $meta['grid_gap']['size'] ) ? $meta['grid_gap']['size'] : 30,
204 - 'auto_play_timeout' => self::get_data( $meta, 'autoplay_timeout', 5000 ),
205 - 'nav_position' => self::get_data( $meta, 'slider_nav_position', 'top' ),
206 - 'left_arrow_icon' => self::get_data( $meta, 'slider_left_arrow_icon', [] ),
207 - 'right_arrow_icon' => self::get_data( $meta, 'slider_right_arrow_icon', [] ),
208 - ],
209 - $meta
210 - );
211 -
212 - if ( ! empty( $meta['active_cat_slider'] ) ) {
213 - $data['active_cat_slider'] = true;
214 - }
215 -
216 - if ( ! empty( $meta['cols_widescreen'] ) ) {
217 - $data['w_cols'] = $meta['cols_widescreen'];
218 - }
219 -
220 - if ( ! empty( $meta['cols_laptop'] ) ) {
221 - $data['l_cols'] = $meta['cols_laptop'];
222 - }
223 -
224 - if ( ! empty( $meta['cols_tablet_extra'] ) ) {
225 - $data['te_cols'] = $meta['cols_tablet_extra'];
226 - }
227 -
228 - if ( ! empty( $meta['cols_mobile_extra'] ) ) {
229 - $data['me_cols'] = $meta['cols_mobile_extra'];
230 - }
231 -
232 - $queried_obj = get_queried_object();
233 -
234 - if ( is_shop() || is_product_taxonomy() ) {
235 - $data['posts_per_page'] = self::get_products_per_page();
236 - $data['order_by'] = self::get_data( $data, 'rtsb_orderby', $data['order_by'] );
237 - $data['order'] = self::get_data( $data, 'rtsb_order', $data['order'] );
238 - }
239 -
240 - if ( ! is_shop() && is_product_taxonomy() ) {
241 - if ( ! empty( $queried_obj->taxonomy ) ) {
242 - $data['queried_tax'] = esc_html( $queried_obj->taxonomy );
243 - }
244 -
245 - if ( ! empty( $queried_obj->term_id ) ) {
246 - $data['queried_term'] = esc_html( $queried_obj->term_id );
247 - }
248 - }
249 -
250 - return apply_filters( 'rtsb/elementor/render/meta_dataset_final', $data, $meta, $raw_settings );
251 - }
252 -
253 - /**
254 - * Builds an array with field values.
255 - *
256 - * @param array $meta Field values.
257 - * @param string $template Template name.
258 - *
259 - * @return array
260 - */
261 - public static function archive_meta_dataset( array $meta, $template = '' ) {
262 - $data = apply_filters(
263 - 'rtsb/elementor/render/archive_meta_dataset',
264 - [
265 - // Layout.
266 - 'widget' => 'default',
267 - 'template' => self::get_data( $template, '', '' ),
268 - 'view_mode' => self::get_data( $meta, 'view_mode', 'grid' ),
269 - 'show_flash_sale' => ! empty( $meta['show_flash_sale'] ),
270 - 'wishlist_button' => ! empty( $meta['wishlist_button'] ),
271 - 'comparison_button' => ! empty( $meta['comparison_button'] ),
272 - 'quick_view_button' => ! empty( $meta['quick_view_button'] ),
273 - 'show_rating' => ! empty( $meta['show_rating'] ),
274 - 'show_pagination' => ! empty( $meta['show_pagination'] ),
275 - 'cart_icon' => self::get_data( $meta, 'cart_icon', [] ),
276 - 'wishlist_icon' => self::get_data( $meta, 'wishlist_icon', [] ),
277 - 'wishlist_icon_added' => self::get_data( $meta, 'wishlist_icon_added', [] ),
278 - 'comparison_icon' => self::get_data( $meta, 'comparison_icon', [] ),
279 - 'comparison_icon_added' => self::get_data( $meta, 'comparison_icon_added', [] ),
280 - 'quick_view_icon' => self::get_data( $meta, 'quick_view_icon', [] ),
281 - 'prev_icon' => self::get_data( $meta, 'prev_icon', [] ),
282 - 'next_icon' => self::get_data( $meta, 'next_icon', [] ),
283 - 'posts_per_page' => self::get_products_per_page(),
284 - 'rtsb_order' => self::get_data( $meta, 'rtsb_order', 'ASC' ),
285 - 'rtsb_orderby' => self::get_data( $meta, 'rtsb_orderby', 'menu_order' ),
286 - 'tooltip_position' => self::get_data( $meta, 'action_btn_tooltip_position', 'top' ),
287 - ],
288 - $meta
289 - );
290 -
291 - $queried_obj = get_queried_object();
292 -
293 - if ( ! is_shop() && BuilderFns::is_archive() ) {
294 - if ( ! empty( $queried_obj->taxonomy ) ) {
295 - $data['queried_tax'] = esc_html( $queried_obj->taxonomy );
296 - }
297 -
298 - if ( ! empty( $queried_obj->term_id ) ) {
299 - $data['queried_term'] = esc_html( $queried_obj->term_id );
300 - }
301 - }
302 -
303 - return apply_filters( 'rtsb/elementor/render/archive_meta_dataset_final', $data, $meta );
304 - }
305 -
306 - /**
307 - * Setting up content visibility
308 - *
309 - * @param array $settings Elementor settings.
310 - *
311 - * @return array
312 - */
313 - public static function content_visibility( $settings ) {
314 - $visibility = [];
315 -
316 - if ( ! empty( $settings['show_title'] ) ) {
317 - $visibility[] = 'title';
318 - }
319 -
320 - if ( ! empty( $settings['show_short_desc'] ) ) {
321 - $visibility[] = 'excerpt';
322 - }
323 -
324 - if ( ! empty( $settings['show_price'] ) ) {
325 - $visibility[] = 'price';
326 - }
327 -
328 - if ( ! empty( $settings['show_rating'] ) ) {
329 - $visibility[] = 'rating';
330 - }
331 -
332 - if ( ! empty( $settings['show_badges'] ) ) {
333 - $visibility[] = 'badges';
334 - }
335 -
336 - if ( ! empty( $settings['show_categories'] ) ) {
337 - $visibility[] = 'categories';
338 - }
339 -
340 - if ( ! empty( $settings['single_category'] ) ) {
341 - $visibility[] = 'single-cat';
342 - }
343 -
344 - if ( ! empty( $settings['show_swatches'] ) ) {
345 - $visibility[] = 'swatches';
346 - }
347 -
348 - if ( ! empty( $settings['show_vs_clear_btn'] ) ) {
349 - $visibility[] = 'clear-btn';
350 - }
351 -
352 - if ( ! empty( $settings['show_count'] ) ) {
353 - $visibility[] = 'count';
354 - }
355 -
356 - if ( ! empty( $settings['show_wishlist'] ) ) {
357 - $visibility[] = 'wishlist';
358 - }
359 -
360 - if ( ! empty( $settings['show_compare'] ) ) {
361 - $visibility[] = 'compare';
362 - }
363 -
364 - if ( ! empty( $settings['show_quick_view'] ) ) {
365 - $visibility[] = 'quick_view';
366 - }
367 -
368 - if ( ! empty( $settings['show_add_to_cart'] ) ) {
369 - $visibility[] = 'add_to_cart';
370 - }
371 -
372 - return $visibility;
373 - }
374 -
375 - /**
376 - * Set Default Layout.
377 - *
378 - * @param string $layout Layout.
379 - *
380 - * @return string
381 - */
382 - public static function set_default_layout( $layout ) {
383 - $is_list = preg_match( '/list/', $layout );
384 - $is_cat_single = preg_match( '/category-single/', $layout );
385 - $is_cat = preg_match( '/category/', $layout );
386 - $is_carousel = preg_match( '/slider/', $layout );
387 - $default = 'grid-layout1';
388 -
389 - if ( $is_list ) {
390 - $default = 'list-layout1';
391 - } elseif ( $is_cat_single ) {
392 - $default = 'category-single-layout1';
393 - } elseif ( $is_cat ) {
394 - $default = 'category-layout1';
395 - } elseif ( $is_carousel ) {
396 - $default = 'slider-layout1';
397 - }
398 -
399 - return $default;
400 - }
401 -
402 - /**
403 - * Default layout columns.
404 - *
405 - * @param int $layout Layout.
406 - *
407 - * @return int
408 - */
409 - public static function default_columns( $layout ) {
410 - switch ( $layout ) {
411 - case 'grid-layout2':
412 - case 'slider-layout2':
413 - $columns = 3;
414 - break;
415 -
416 - case 'list-layout1':
417 - case 'list-layout2':
418 - case 'list-layout3':
419 - case 'list-layout7':
420 - case 'list-layout5':
421 - $columns = 1;
422 - break;
423 -
424 - case 'list-layout4':
425 - case 'list-layout6':
426 - case 'slider-layout5':
427 - case 'slider-layout8':
428 - $columns = 2;
429 - break;
430 -
431 - case 'grid-layout6':
432 - $columns = 5;
433 - break;
434 -
435 - case 'category-layout1':
436 - $columns = 6;
437 - break;
438 -
439 - default:
440 - $columns = 4;
441 - break;
442 - }
443 -
444 - return apply_filters( 'rtsb/element/general/default_columns', $columns, $layout );
445 - }
446 -
447 - /**
448 - * Pagination JSON data.
449 - *
450 - * @param array $metas Data set.
451 - * @param string $template Template name.
452 - *
453 - * @return string
454 - */
455 - public static function pagination_data( $metas, $template ) {
456 - $el_data = self::meta_dataset( $metas, $template );
457 -
458 - return esc_js( wp_json_encode( $el_data, JSON_UNESCAPED_UNICODE ) );
459 - }
460 -
461 - /**
462 - * Container classes
463 - *
464 - * @param array $metas Meta data.
465 - * @param array $settings Settings array.
466 - * @param string $custom_class Custom class.
467 - *
468 - * @return mixed|null
469 - */
470 - public static function prepare_container_classes( $metas = [], $settings = [], $custom_class = '' ) {
471 - $classes = 'rtsb-elementor-container products rtsb-pos-r ';
472 - $classes .= $custom_class;
473 -
474 - $layout = $metas['layout'];
475 - $is_cat = preg_match( '/category/', $layout );
476 - $cart_txt_class = '';
477 -
478 - $animation = $metas['hover_animation'];
479 -
480 - if ( ! $is_cat ) {
481 - $cart_txt_class = $metas['show_cart_text'] ? ' has-cart-text' : ' no-cart-text';
482 - $animation .= ' gallery-hover-' . ( ! empty( $settings['gallery_hover_animation'] ) ? $settings['gallery_hover_animation'] : 'fade' );
483 - }
484 -
485 - $badge_class = [
486 - 'position' => $metas['badge_position'],
487 - 'alignment' => $metas['badge_alignment'],
488 - ];
489 -
490 - if ( ! in_array( 'clear-btn', $metas['visibility'], true ) ) {
491 - $classes .= ' no-clear-btn';
492 - }
493 -
494 - $classes .= ! empty( $metas['pagination'] ) ? ' rtsb-has-pagination' : ' rtsb-no-pagination';
495 - $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'] );
496 -
497 - if ( $metas['show_overlay'] ) {
498 - $classes .= ' has-overlay';
499 - }
500 -
501 - if ( in_array( 'single-cat', $metas['visibility'], true ) ) {
502 - $classes .= ' show-single-cat';
503 - }
504 -
505 - if ( ! $is_cat ) {
506 - $action_btn_classes = [
507 - 'show_compare_text' => 'has-compare-text',
508 - 'show_quick_view_text' => 'has-quick-view-text',
509 - 'show_wishlist_text' => 'has-wishlist-text',
510 - 'show_compare_icon' => 'no-compare-icon',
511 - 'show_quick_view_icon' => 'no-quick-view-icon',
512 - 'show_wishlist_icon' => 'no-wishlist-icon',
513 - 'show_quick_checkout_icon' => 'no-quick_checkout-icon',
514 - ];
515 -
516 - foreach ( $action_btn_classes as $setting_key => $class ) {
517 - if ( strpos( $setting_key, 'icon' ) !== false ) {
518 - $classes .= empty( $settings[ $setting_key ] ) ? ' ' . $class : '';
519 - } else {
520 - $classes .= ! empty( $settings[ $setting_key ] ) ? ' ' . $class : '';
521 - }
522 - }
523 -
524 - if ( rtsb()->has_pro() && ! empty( $settings['custom_ordering'] ) ) {
525 - $classes .= ' has-custom-ordering';
526 - }
527 - }
528 - if ( rtsb()->has_pro() && ! empty( $settings['slider_slide_animation'] ) ) {
529 - $classes .= ' has-slide-animation';
530 - }
531 -
532 - return apply_filters( 'rtsb/product/container/class', $classes, $settings );
533 - }
534 -
535 - /**
536 - * Row classes
537 - *
538 - * @param array $settings Settings array.
539 - *
540 - * @return mixed|null
541 - */
542 - public static function prepare_row_classes( $settings = [] ) {
543 - $masonry_class = null;
544 - $classes = 'rtsb-row rtsb-content-loader element-loading';
545 - $loader_class = ' rtsb-pre-loader';
546 -
547 - $layout = $settings['layout'];
548 - $grid_type = $settings['grid_type'];
549 - $is_carousel = preg_match( '/slider/', $layout );
550 -
551 - if ( preg_match( '/category/', $layout ) && ! empty( $settings['active_cat_slider'] ) ) {
552 - $classes .= ' rtsb-slider-layout';
553 - }
554 -
555 - if ( 'even' === $grid_type ) {
556 - $masonry_class = ' rtsb-even';
557 - } elseif ( 'masonry' === $grid_type ) {
558 - $masonry_class = ' rtsb-masonry';
559 - }
560 -
561 - if ( ! rtsb()->has_pro() || $is_carousel ) {
562 - $masonry_class = ' rtsb-even';
563 - }
564 -
565 - $classes .= ' rtsb-' . $layout . $masonry_class . $loader_class;
566 -
567 - return apply_filters( 'rtsb/elementor/row/classes', $classes, $settings );
568 - }
569 -
570 - /**
571 - * Prepare pagination attributes.
572 - *
573 - * @param string $layout The layout type.
574 - * @param bool $has_filters Whether the widget has filters.
575 - * @param string $template The template name.
576 - * @param array $settings The widget settings.
577 - * @param bool $ajax Whether to enable AJAX pagination.
578 - *
579 - * @return string
580 - */
581 - public static function prepare_pagination_attr( $layout, $has_filters, $template, $settings, $ajax ) {
582 - $is_cat = preg_match( '/category/', $layout );
583 - $is_carousel = preg_match( '/slider/', $layout );
584 -
585 - if ( $is_carousel ) {
586 - return $has_filters ? self::pagination_data( $settings, $template ) : '';
587 - } elseif ( $is_cat ) {
588 - return '';
589 - } else {
590 - $ajax_pagination = ! empty( $settings['show_pagination'] ) && 'pagination' !== $settings['pagination_type'];
591 - $page = Fns::product_filters_has_ajax( 'shop' ) || Fns::product_filters_has_ajax( 'archive' );
592 - $condition = rtsb()->has_pro() && $ajax && ( $ajax_pagination || $has_filters || $page );
593 -
594 - return $condition ? self::pagination_data( $settings, $template ) : '';
595 - }
596 - }
597 -
598 - /**
599 - * Archive JSON data.
600 - *
601 - * @param array $metas Data set.
602 - * @param string $template Template name.
603 - *
604 - * @return string
605 - */
606 - public static function archive_data( $metas, $template ) {
607 - $el_data = self::archive_meta_dataset( $metas, $template );
608 -
609 - return ' data-rtsb-ajax=\'' . esc_js( wp_json_encode( $el_data ) ) . '\'';
610 - }
611 -
612 - /**
613 - * Slider options.
614 - *
615 - * @param array $meta Meta values.
616 - * @param array $settings Raw Settings.
617 - *
618 - * @return array
619 - */
620 - public static function slider_data( array $meta, $settings = [] ) {
621 - $has_dots = $meta['slider_dot'] ? ' has-dot' : ' no-dot';
622 - $has_dots .= $meta['slider_nav'] ? ' has-nav' : ' no-nav';
623 - $d_col = 0 === $meta['d_cols'] ? self::default_columns( $meta['layout'] ) : $meta['d_cols'];
624 - $t_col = 0 === $meta['t_cols'] ? 2 : $meta['t_cols'];
625 - $m_col = 0 === $meta['m_cols'] ? 1 : $meta['m_cols'];
626 -
627 - if ( \Elementor\Plugin::$instance->breakpoints->has_custom_breakpoints() ) {
628 - // Widescreen.
629 - $w_col = self::get_data( $settings, 'cols_widescreen' );
630 - $w_col = 0 === $w_col ? self::default_columns( $meta['layout'] ) : $w_col;
631 - $w_group = self::get_data( $settings, 'cols_group_widescreen', 1 );
632 -
633 - // Laptop.
634 - $l_col = self::get_data( $settings, 'cols_laptop' );
635 - $l_col = 0 === $l_col ? self::default_columns( $meta['layout'] ) : $l_col;
636 - $l_group = self::get_data( $settings, 'cols_group_laptop', 1 );
637 -
638 - // Tablet Landscape.
639 - $te_col = self::get_data( $settings, 'cols_tablet_extra' );
640 - $te_col = 0 === $te_col ? 3 : $te_col;
641 - $te_group = self::get_data( $settings, 'cols_group_tablet_extra', 1 );
642 -
643 - // Mobile Landscape.
644 - $me_col = self::get_data( $settings, 'cols_mobile_extra' );
645 - $me_col = 0 === $me_col ? 2 : $me_col;
646 - $me_group = self::get_data( $settings, 'cols_group_mobile_extra', 1 );
647 -
648 - $el_breakpoints = Fns::get_elementor_breakpoints();
649 -
650 - foreach ( $el_breakpoints as $key => $value ) {
651 - if ( isset( $value['is_enabled'] ) && ! $value['is_enabled'] ) {
652 - unset( $el_breakpoints[ $key ] );
653 - }
654 - }
655 -
656 - $breakpoints = [
657 - 0 => [
658 - 'slidesPerView' => absint( $m_col ),
659 - 'slidesPerGroup' => absint( $meta['m_group'] ),
660 - 'pagination' => [
661 - 'dynamicBullets' => true,
662 - ],
663 - ],
664 - ];
665 -
666 - $desktop = [
667 - 'desktop' => [
668 - 'label' => 'Desktop',
669 - 'value' => 1920,
670 - 'is_enabled' => 1,
671 - ],
672 - ];
673 -
674 - if ( ! empty( $el_breakpoints['laptop'] ) && $el_breakpoints['laptop']['is_enabled'] ) {
675 - $widescreen_position = array_search( 'widescreen', array_keys( $el_breakpoints ), true );
676 - $el_breakpoints = array_merge(
677 - array_slice( $el_breakpoints, 0, $widescreen_position ),
678 - $desktop,
679 - array_slice( $el_breakpoints, $widescreen_position )
680 - );
681 - } else {
682 - $desktop['desktop']['value'] = 1366;
683 - $el_breakpoints['desktop'] = $desktop['desktop'];
684 - }
685 -
686 - foreach ( $el_breakpoints as $el_breakpoint => $value ) {
687 - $breakpoint_value = ! empty( $value['value'] ) ? $value['value'] : $value['default_value'];
688 - $dynamic_bullets = false;
689 - $slides_per_view = $d_col;
690 - $slides_per_group = $meta['d_group'];
691 -
692 - switch ( $el_breakpoint ) {
693 - case 'widescreen':
694 - $slides_per_view = $w_col;
695 - $slides_per_group = $w_group;
696 -
697 - break;
698 -
699 - case 'laptop':
700 - $slides_per_view = $l_col;
701 - $slides_per_group = $l_group;
702 -
703 - break;
704 -
705 - case 'tablet_extra':
706 - $slides_per_view = $l_col;
707 - $slides_per_group = $l_group;
708 -
709 - if ( empty( $el_breakpoints['laptop'] ) ) {
710 - $slides_per_view = $d_col;
711 - $slides_per_group = $meta['d_group'];
712 - }
713 -
714 - break;
715 -
716 - case 'tablet':
717 - $slides_per_view = $te_col;
718 - $slides_per_group = $te_group;
719 -
720 - if ( empty( $el_breakpoints['laptop'] ) && empty( $el_breakpoints['tablet_extra'] ) ) {
721 - $slides_per_view = $d_col;
722 - $slides_per_group = $meta['d_group'];
723 - } elseif ( empty( $el_breakpoints['laptop'] ) && ! empty( $el_breakpoints['tablet_extra'] ) ) {
724 - $slides_per_view = $te_col;
725 - $slides_per_group = $te_group;
726 - } elseif ( ! empty( $el_breakpoints['laptop'] ) && empty( $el_breakpoints['tablet_extra'] ) ) {
727 - $slides_per_view = $l_col;
728 - $slides_per_group = $l_group;
729 - }
730 -
731 - break;
732 -
733 - case 'mobile_extra':
734 - $slides_per_view = $t_col;
735 - $slides_per_group = $meta['t_group'];
736 - $dynamic_bullets = true;
737 -
738 - break;
739 -
740 - case 'mobile':
741 - $slides_per_view = $t_col;
742 - $slides_per_group = $meta['t_group'];
743 - $dynamic_bullets = true;
744 -
745 - if ( ! empty( $el_breakpoints['mobile_extra'] ) ) {
746 - $slides_per_view = $me_col;
747 - $slides_per_group = $me_group;
748 - }
749 -
750 - break;
751 - }
752 -
753 - if ( $value['is_enabled'] ) {
754 - $br = 'widescreen' !== $el_breakpoint ? $breakpoint_value + 1 : $breakpoint_value;
755 -
756 - $breakpoints[ absint( $br ) ] = [
757 - 'slidesPerView' => absint( $slides_per_view ),
758 - 'slidesPerGroup' => absint( $slides_per_group ),
759 - 'pagination' => [
760 - 'dynamicBullets' => $dynamic_bullets,
761 - ],
762 - ];
763 - }
764 - }
765 - } else {
766 - $breakpoints = [
767 - 0 => [
768 - 'slidesPerView' => absint( $m_col ),
769 - 'slidesPerGroup' => absint( $meta['m_group'] ),
770 - 'pagination' => [
771 - 'dynamicBullets' => true,
772 - ],
773 - ],
774 - 768 => [
775 - 'slidesPerView' => absint( $t_col ),
776 - 'slidesPerGroup' => absint( $meta['t_group'] ),
777 - 'pagination' => [
778 - 'dynamicBullets' => false,
779 - ],
780 - ],
781 - 1025 => [
782 - 'slidesPerView' => absint( $d_col ),
783 - 'slidesPerGroup' => absint( $meta['d_group'] ),
784 - 'pagination' => [
785 - 'dynamicBullets' => false,
786 - ],
787 - ],
788 - ];
789 - }
790 -
791 - $slider_options = [
792 - 'slidesPerView' => absint( $d_col ),
793 - 'slidesPerGroup' => absint( $meta['d_group'] ),
794 - 'speed' => absint( $meta['speed'] ),
795 - 'loop' => $meta['loop'],
796 - 'autoHeight' => $meta['auto_height'],
797 - 'preloadImages' => ! $meta['lazy_load'],
798 - 'lazy' => $meta['lazy_load'],
799 - 'breakpoints' => $breakpoints,
800 - ];
801 -
802 - if ( ! empty( $meta['raw_settings']['slider_slide_animation'] ) ) {
803 - $slider_options['watchSlidesProgress'] = true;
804 - }
805 - if ( $meta['auto_play'] ) {
806 - $slider_options['autoplay'] = [
807 - 'delay' => absint( $meta['auto_play_timeout'] ),
808 - 'pauseOnMouseEnter' => $meta['stop_on_hover'],
809 - 'disableOnInteraction' => false,
810 - ];
811 - }
812 -
813 - $slider_options = apply_filters( 'rtsb/elementor/render/slider_dataset', $slider_options, $meta );
814 - $carouselClass = 'rtsb-carousel-slider slider-loading rtsb-pos-s ' . $meta['nav_position'] . '-nav' . $has_dots;
815 -
816 - return [
817 - 'data' => esc_js( wp_json_encode( $slider_options ) ),
818 - 'class' => $carouselClass,
819 - ];
820 - }
821 -
822 - /**
823 - * Preloader.
824 - *
825 - * @param string $layout Layout.
826 - *
827 - * @return string
828 - */
829 - public static function pre_loader( $layout ) {
830 - $loader_class = '';
831 -
832 - $is_carousel = preg_match( '/slider/', $layout );
833 -
834 - if ( $is_carousel ) {
835 - $loader_class = ' full-op';
836 - }
837 -
838 - return '<div class="rtsb-elements-loading rtsb-ball-clip-rotate"><div></div></div>';
839 - }
840 -
841 - /**
842 - * Badge class.
843 - *
844 - * @param string $preset Badge preset.
845 - *
846 - * @return string|null
847 - */
848 - public static function badge_class( $preset ) {
849 - switch ( $preset ) {
850 - case 'preset-default':
851 - $class = 'default-badge';
852 - break;
853 - case 'preset2':
854 - $class = 'fill angle-right';
855 - break;
856 - case 'preset3':
857 - $class = 'outline';
858 - break;
859 -
860 - case 'preset4':
861 - $class = 'outline angle-right';
862 - break;
863 -
864 - default:
865 - $class = 'fill';
866 - break;
867 - }
868 -
869 - return $class;
870 - }
871 -
872 - /**
873 - * Registers required scripts.
874 - *
875 - * @param array $scripts Scripts to register.
876 - *
877 - * @return void
878 - */
879 - public static function register_scripts( $scripts ) {
880 - $caro = false;
881 - $script = [];
882 -
883 - $script[] = 'jquery';
884 -
885 - foreach ( $scripts as $sc => $value ) {
886 - if ( ! empty( $sc ) ) {
887 - if ( 'isCarousel' === $sc ) {
888 - $caro = $value;
889 - }
890 - }
891 - }
892 -
893 - if ( count( $scripts ) ) {
894 - /**
895 - * Scripts.
896 - */
897 - if ( $caro ) {
898 - $script[] = 'swiper';
899 - }
900 -
901 - $script[] = 'rtsb-imagesloaded';
902 - $script[] = 'rtsb-public';
903 -
904 - foreach ( $script as $sc ) {
905 - wp_enqueue_script( $sc );
906 - }
907 - }
908 - }
909 -
910 - /**
911 - * Check if a wrapper is needed based on the current theme.
912 - *
913 - * @return bool
914 - */
915 - public static function is_wrapper_needed() {
916 - $theme_list = apply_filters(
917 - 'rtsb/products/inner/wrapper/basedon/themes',
918 - [
919 - 'twentytwentyone',
920 - 'twentytwentytwo',
921 - 'twentytwentythree',
922 - 'storefront',
923 - 'hello-elementor',
924 - 'astra',
925 - ],
926 - rtsb()->current_theme
927 - );
928 -
929 - if ( in_array( rtsb()->current_theme, $theme_list, true ) ) {
930 - return true;
931 - }
932 -
933 - return false;
934 - }
935 -
936 - /**
937 - * Get the number of products per page based on WooCommerce settings.
938 - *
939 - * @return int
940 - */
941 - public static function get_products_per_page() {
942 - $products_row = absint( get_option( 'woocommerce_catalog_rows', 4 ) );
943 - $products_col = absint( get_option( 'woocommerce_catalog_columns', 4 ) );
944 - $products_per_page = apply_filters( 'rtsb/elementor/archive/products_per_page', $products_row * $products_col );
945 -
946 - return ! empty( $products_per_page ) ? $products_per_page : 12;
947 - }
948 -}
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 +}