PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.0.0
ShopBuilder – WooCommerce Builder For Elementor v1.0.0
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
← All changes | app/Elementor/Helper/RenderHelpers.php +477 -1003 2.2.21.0.0 View file →
@@ -1,1003 +1,477 @@
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 - case 'grid-layout9':
435 - $columns = 5;
436 - break;
437 -
438 - case 'category-layout1':
439 - $columns = 6;
440 - break;
441 -
442 - default:
443 - $columns = 4;
444 - break;
445 - }
446 -
447 - return apply_filters( 'rtsb/element/general/default_columns', $columns, $layout );
448 - }
449 -
450 - /**
451 - * Pagination JSON data.
452 - *
453 - * @param array $metas Data set.
454 - * @param string $template Template name.
455 - *
456 - * @return string
457 - */
458 - public static function pagination_data( $metas, $template ) {
459 - $el_data = self::meta_dataset( $metas, $template );
460 -
461 - return esc_js( wp_json_encode( $el_data, JSON_UNESCAPED_UNICODE ) );
462 - }
463 -
464 - /**
465 - * Container classes
466 - *
467 - * @param array $metas Meta data.
468 - * @param array $settings Settings array.
469 - * @param string $custom_class Custom class.
470 - *
471 - * @return mixed|null
472 - */
473 - public static function prepare_container_classes( $metas = [], $settings = [], $custom_class = '' ) {
474 - $classes = 'rtsb-elementor-container products rtsb-pos-r ';
475 - $classes .= $custom_class;
476 -
477 - $raw_layout = esc_html( $metas['layout'] );
478 - $layout = self::filter_layout( $raw_layout );
479 - $is_cat = preg_match( '/category/', $layout );
480 - $cart_txt_class = '';
481 -
482 - $animation = $metas['hover_animation'];
483 -
484 - if ( ! $is_cat ) {
485 - $cart_txt_class = $metas['show_cart_text'] ? ' has-cart-text' : ' no-cart-text';
486 - $animation .= ' gallery-hover-' . ( ! empty( $settings['gallery_hover_animation'] ) ? $settings['gallery_hover_animation'] : 'fade' );
487 - }
488 -
489 - $badge_class = [
490 - 'position' => $metas['badge_position'],
491 - 'alignment' => $metas['badge_alignment'],
492 - ];
493 -
494 - if ( ! in_array( 'clear-btn', $metas['visibility'], true ) ) {
495 - $classes .= ' no-clear-btn';
496 - }
497 -
498 - $classes .= ! empty( $metas['pagination'] ) ? ' rtsb-has-pagination' : ' rtsb-no-pagination';
499 - $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'] );
500 -
501 - if ( $metas['show_overlay'] ) {
502 - $classes .= ' has-overlay';
503 - }
504 -
505 - if ( in_array( 'single-cat', $metas['visibility'], true ) ) {
506 - $classes .= ' show-single-cat';
507 - }
508 -
509 - if ( ! $is_cat ) {
510 - $action_btn_classes = [
511 - 'show_compare_text' => 'has-compare-text',
512 - 'show_quick_view_text' => 'has-quick-view-text',
513 - 'show_wishlist_text' => 'has-wishlist-text',
514 - 'show_compare_icon' => 'no-compare-icon',
515 - 'show_quick_view_icon' => 'no-quick-view-icon',
516 - 'show_wishlist_icon' => 'no-wishlist-icon',
517 - 'show_quick_checkout_icon' => 'no-quick_checkout-icon',
518 - ];
519 -
520 - foreach ( $action_btn_classes as $setting_key => $class ) {
521 - if ( strpos( $setting_key, 'icon' ) !== false ) {
522 - $classes .= empty( $settings[ $setting_key ] ) ? ' ' . $class : '';
523 - } else {
524 - $classes .= ! empty( $settings[ $setting_key ] ) ? ' ' . $class : '';
525 - }
526 - }
527 -
528 - if ( rtsb()->has_pro() && ! empty( $settings['custom_ordering'] ) ) {
529 - $classes .= ' has-custom-ordering';
530 - }
531 - }
532 - if ( rtsb()->has_pro() && ! empty( $settings['slider_slide_animation'] ) ) {
533 - $classes .= ' has-slide-animation';
534 - }
535 -
536 - return apply_filters( 'rtsb/product/container/class', $classes, $settings );
537 - }
538 -
539 - /**
540 - * Function to filter and validate the layout against allowed patterns.
541 - *
542 - * @param string $layout The layout string to be filtered.
543 - * @param string $template The template to be checked.
544 - *
545 - * @return string
546 - */
547 - public static function filter_layout( $layout, $template = '' ) {
548 - $allowed_patterns = apply_filters( 'rtsb/elementor/custom_layout', [ 'grid', 'list', 'slider', 'category', 'toyup', 'zilly' ] );
549 - $layout_part = explode( '-', $layout );
550 - $default = 'grid-layout1';
551 -
552 - if ( empty( $layout_part[0] ) ) {
553 - return $default;
554 - }
555 -
556 - if ( in_array( $layout_part[0], $allowed_patterns, true ) ) {
557 - return $layout;
558 - } else {
559 - if ( ! empty( $template ) ) {
560 - $grid = preg_match( '/grid/', $template );
561 - $list = preg_match( '/list/', $template );
562 - $slider = preg_match( '/slider/', $template );
563 - $category = preg_match( '/category/', $template );
564 -
565 - if ( $grid ) {
566 - return $default;
567 - } elseif ( $list ) {
568 - return 'list-layout1';
569 - } elseif ( $slider ) {
570 - return 'slider-layout1';
571 - } elseif ( $category ) {
572 - return 'category-layout1';
573 - } else {
574 - return $default;
575 - }
576 - } else {
577 - return $default;
578 - }
579 - }
580 - }
581 -
582 - /**
583 - * Row classes
584 - *
585 - * @param array $settings Settings array.
586 - *
587 - * @return mixed|null
588 - */
589 - public static function prepare_row_classes( $settings = [] ) {
590 - $masonry_class = null;
591 - $classes = 'rtsb-row rtsb-content-loader element-loading';
592 - $loader_class = ' rtsb-pre-loader';
593 -
594 - $raw_layout = esc_html( $settings['layout'] );
595 - $layout = self::filter_layout( $raw_layout );
596 - $grid_type = $settings['grid_type'];
597 - $is_carousel = preg_match( '/slider/', $layout );
598 -
599 - if ( preg_match( '/category/', $layout ) && ! empty( $settings['active_cat_slider'] ) ) {
600 - $classes .= ' rtsb-slider-layout';
601 - }
602 -
603 - if ( 'even' === $grid_type ) {
604 - $masonry_class = ' rtsb-even';
605 - } elseif ( 'masonry' === $grid_type ) {
606 - $masonry_class = ' rtsb-masonry';
607 - }
608 -
609 - if ( ! rtsb()->has_pro() || $is_carousel ) {
610 - $masonry_class = ' rtsb-even';
611 - }
612 - if ( $is_carousel && ! empty( $settings['raw_settings']['always_show_nav'] ) ) {
613 - $classes .= ' always-show-nav';
614 - }
615 - if ( ! empty( $settings['raw_settings']['inner_slider_always_show_nav'] ) ) {
616 - $classes .= ' inner-slider-always-show-nav';
617 - }
618 -
619 - $classes .= ' rtsb-' . $layout . $masonry_class . $loader_class;
620 -
621 - return apply_filters( 'rtsb/elementor/row/classes', $classes, $settings );
622 - }
623 -
624 - /**
625 - * Prepare pagination attributes.
626 - *
627 - * @param string $layout The layout type.
628 - * @param bool $has_filters Whether the widget has filters.
629 - * @param string $template The template name.
630 - * @param array $settings The widget settings.
631 - * @param bool $ajax Whether to enable AJAX pagination.
632 - *
633 - * @return string
634 - */
635 - public static function prepare_pagination_attr( $layout, $has_filters, $template, $settings, $ajax ) {
636 - $is_cat = preg_match( '/category/', $layout );
637 - $is_carousel = preg_match( '/slider/', $layout );
638 -
639 - if ( $is_carousel ) {
640 - return $has_filters ? self::pagination_data( $settings, $template ) : '';
641 - } elseif ( $is_cat ) {
642 - return '';
643 - } else {
644 - $ajax_pagination = ! empty( $settings['show_pagination'] ) && 'pagination' !== $settings['pagination_type'];
645 - $page = Fns::product_filters_has_ajax( apply_filters( 'rtsb/builder/set/current/page/type', '' ) );
646 - $condition = rtsb()->has_pro() && $ajax && ( $ajax_pagination || $has_filters || $page );
647 -
648 - return $condition ? self::pagination_data( $settings, $template ) : '';
649 - }
650 - }
651 -
652 - /**
653 - * Archive JSON data.
654 - *
655 - * @param array $metas Data set.
656 - * @param string $template Template name.
657 - *
658 - * @return string
659 - */
660 - public static function archive_data( $metas, $template ) {
661 - $el_data = self::archive_meta_dataset( $metas, $template );
662 -
663 - return ' data-rtsb-ajax=\'' . esc_js( wp_json_encode( $el_data ) ) . '\'';
664 - }
665 -
666 - /**
667 - * Slider options.
668 - *
669 - * @param array $meta Meta values.
670 - * @param array $settings Raw Settings.
671 - *
672 - * @return array
673 - */
674 - public static function slider_data( array $meta, $settings = [] ) {
675 - $has_dots = $meta['slider_dot'] ? ' has-dot' : ' no-dot';
676 - $has_dots .= $meta['slider_nav'] ? ' has-nav' : ' no-nav';
677 - $has_dynamic_dots = $meta['slider_dynamic_dot'] ? true : false;
678 - $d_col = 0 === $meta['d_cols'] ? self::default_columns( $meta['layout'] ) : $meta['d_cols'];
679 - $t_col = 0 === $meta['t_cols'] ? 2 : $meta['t_cols'];
680 - $m_col = 0 === $meta['m_cols'] ? 1 : $meta['m_cols'];
681 -
682 - if ( \Elementor\Plugin::$instance->breakpoints->has_custom_breakpoints() ) {
683 - // Widescreen.
684 - $w_col = self::get_data( $settings, 'cols_widescreen' );
685 - $w_col = 0 === $w_col ? self::default_columns( $meta['layout'] ) : $w_col;
686 - $w_group = self::get_data( $settings, 'cols_group_widescreen', 1 );
687 -
688 - // Laptop.
689 - $l_col = self::get_data( $settings, 'cols_laptop' );
690 - $l_col = 0 === $l_col ? self::default_columns( $meta['layout'] ) : $l_col;
691 - $l_group = self::get_data( $settings, 'cols_group_laptop', 1 );
692 -
693 - // Tablet Landscape.
694 - $te_col = self::get_data( $settings, 'cols_tablet_extra' );
695 - $te_col = 0 === $te_col ? 3 : $te_col;
696 - $te_group = self::get_data( $settings, 'cols_group_tablet_extra', 1 );
697 -
698 - // Mobile Landscape.
699 - $me_col = self::get_data( $settings, 'cols_mobile_extra' );
700 - $me_col = 0 === $me_col ? 2 : $me_col;
701 - $me_group = self::get_data( $settings, 'cols_group_mobile_extra', 1 );
702 -
703 - $el_breakpoints = Fns::get_elementor_breakpoints();
704 -
705 - foreach ( $el_breakpoints as $key => $value ) {
706 - if ( isset( $value['is_enabled'] ) && ! $value['is_enabled'] ) {
707 - unset( $el_breakpoints[ $key ] );
708 - }
709 - }
710 -
711 - $breakpoints = [
712 - 0 => [
713 - 'slidesPerView' => absint( $m_col ),
714 - 'slidesPerGroup' => absint( $meta['m_group'] ),
715 - 'pagination' => [
716 - 'dynamicBullets' => $has_dynamic_dots,
717 - ],
718 - ],
719 - ];
720 -
721 - $desktop = [
722 - 'desktop' => [
723 - 'label' => 'Desktop',
724 - 'value' => 1920,
725 - 'is_enabled' => 1,
726 - ],
727 - ];
728 -
729 - if ( ! empty( $el_breakpoints['laptop'] ) && $el_breakpoints['laptop']['is_enabled'] ) {
730 - $widescreen_position = array_search( 'widescreen', array_keys( $el_breakpoints ), true );
731 - $el_breakpoints = array_merge(
732 - array_slice( $el_breakpoints, 0, $widescreen_position ),
733 - $desktop,
734 - array_slice( $el_breakpoints, $widescreen_position )
735 - );
736 - } else {
737 - $desktop['desktop']['value'] = 1366;
738 - $el_breakpoints['desktop'] = $desktop['desktop'];
739 - }
740 -
741 - foreach ( $el_breakpoints as $el_breakpoint => $value ) {
742 - $breakpoint_value = ! empty( $value['value'] ) ? $value['value'] : $value['default_value'];
743 - $dynamic_bullets = $has_dynamic_dots;
744 - $slides_per_view = $d_col;
745 - $slides_per_group = $meta['d_group'];
746 -
747 - switch ( $el_breakpoint ) {
748 - case 'widescreen':
749 - $slides_per_view = $w_col;
750 - $slides_per_group = $w_group;
751 -
752 - break;
753 -
754 - case 'laptop':
755 - $slides_per_view = $l_col;
756 - $slides_per_group = $l_group;
757 -
758 - break;
759 -
760 - case 'tablet_extra':
761 - $slides_per_view = $l_col;
762 - $slides_per_group = $l_group;
763 -
764 - if ( empty( $el_breakpoints['laptop'] ) ) {
765 - $slides_per_view = $d_col;
766 - $slides_per_group = $meta['d_group'];
767 - }
768 -
769 - break;
770 -
771 - case 'tablet':
772 - $slides_per_view = $te_col;
773 - $slides_per_group = $te_group;
774 -
775 - if ( empty( $el_breakpoints['laptop'] ) && empty( $el_breakpoints['tablet_extra'] ) ) {
776 - $slides_per_view = $d_col;
777 - $slides_per_group = $meta['d_group'];
778 - } elseif ( empty( $el_breakpoints['laptop'] ) && ! empty( $el_breakpoints['tablet_extra'] ) ) {
779 - $slides_per_view = $te_col;
780 - $slides_per_group = $te_group;
781 - } elseif ( ! empty( $el_breakpoints['laptop'] ) && empty( $el_breakpoints['tablet_extra'] ) ) {
782 - $slides_per_view = $l_col;
783 - $slides_per_group = $l_group;
784 - }
785 -
786 - break;
787 -
788 - case 'mobile_extra':
789 - $slides_per_view = $t_col;
790 - $slides_per_group = $meta['t_group'];
791 - $dynamic_bullets = $has_dynamic_dots;
792 -
793 - break;
794 -
795 - case 'mobile':
796 - $slides_per_view = $t_col;
797 - $slides_per_group = $meta['t_group'];
798 - $dynamic_bullets = $has_dynamic_dots;
799 -
800 - if ( ! empty( $el_breakpoints['mobile_extra'] ) ) {
801 - $slides_per_view = $me_col;
802 - $slides_per_group = $me_group;
803 - }
804 -
805 - break;
806 - }
807 -
808 - if ( $value['is_enabled'] ) {
809 - $br = 'widescreen' !== $el_breakpoint ? $breakpoint_value + 1 : $breakpoint_value;
810 -
811 - $breakpoints[ absint( $br ) ] = [
812 - 'slidesPerView' => absint( $slides_per_view ),
813 - 'slidesPerGroup' => absint( $slides_per_group ),
814 - 'pagination' => [
815 - 'dynamicBullets' => $dynamic_bullets,
816 - ],
817 - ];
818 - }
819 - }
820 - } else {
821 - $breakpoints = [
822 - 0 => [
823 - 'slidesPerView' => absint( $m_col ),
824 - 'slidesPerGroup' => absint( $meta['m_group'] ),
825 - 'pagination' => [
826 - 'dynamicBullets' => $has_dynamic_dots,
827 - ],
828 - ],
829 - 768 => [
830 - 'slidesPerView' => absint( $t_col ),
831 - 'slidesPerGroup' => absint( $meta['t_group'] ),
832 - 'pagination' => [
833 - 'dynamicBullets' => $has_dynamic_dots,
834 - ],
835 - ],
836 - 1025 => [
837 - 'slidesPerView' => absint( $d_col ),
838 - 'slidesPerGroup' => absint( $meta['d_group'] ),
839 - 'pagination' => [
840 - 'dynamicBullets' => $has_dynamic_dots,
841 - ],
842 - ],
843 - ];
844 - }
845 -
846 - $slider_options = [
847 - 'slidesPerView' => absint( $d_col ),
848 - 'slidesPerGroup' => absint( $meta['d_group'] ),
849 - 'speed' => absint( $meta['speed'] ),
850 - 'loop' => $meta['loop'],
851 - 'autoHeight' => $meta['auto_height'],
852 - 'preloadImages' => ! $meta['lazy_load'],
853 - 'lazy' => $meta['lazy_load'],
854 - 'breakpoints' => $breakpoints,
855 - ];
856 -
857 - if ( ! empty( $meta['raw_settings']['slider_slide_animation'] ) ) {
858 - $slider_options['watchSlidesProgress'] = true;
859 - }
860 - if ( $meta['auto_play'] ) {
861 - $slider_options['autoplay'] = [
862 - 'delay' => absint( $meta['auto_play_timeout'] ),
863 - 'pauseOnMouseEnter' => $meta['stop_on_hover'],
864 - 'disableOnInteraction' => false,
865 - ];
866 - }
867 -
868 - $slider_options = apply_filters( 'rtsb/elementor/render/slider_dataset', $slider_options, $meta );
869 - $carouselClass = 'rtsb-carousel-slider slider-loading rtsb-pos-s ' . $meta['nav_position'] . '-nav' . $has_dots;
870 -
871 - return [
872 - 'data' => esc_js( wp_json_encode( $slider_options ) ),
873 - 'class' => $carouselClass,
874 - ];
875 - }
876 -
877 - /**
878 - * Preloader.
879 - *
880 - * @param string $layout Layout.
881 - *
882 - * @return string
883 - */
884 - public static function pre_loader( $layout ) {
885 - $loader_class = '';
886 -
887 - $is_carousel = preg_match( '/slider/', $layout );
888 -
889 - if ( $is_carousel ) {
890 - $loader_class = ' full-op';
891 - }
892 -
893 - return '<div class="rtsb-elements-loading rtsb-ball-clip-rotate"><div></div></div>';
894 - }
895 -
896 - /**
897 - * Badge class.
898 - *
899 - * @param string $preset Badge preset.
900 - *
901 - * @return string|null
902 - */
903 - public static function badge_class( $preset ) {
904 - switch ( $preset ) {
905 - case 'preset-default':
906 - $class = 'default-badge';
907 - break;
908 - case 'preset2':
909 - $class = 'fill angle-right';
910 - break;
911 - case 'preset3':
912 - $class = 'outline';
913 - break;
914 -
915 - case 'preset4':
916 - $class = 'outline angle-right';
917 - break;
918 -
919 - default:
920 - $class = 'fill';
921 - break;
922 - }
923 -
924 - return $class;
925 - }
926 -
927 - /**
928 - * Registers required scripts.
929 - *
930 - * @param array $scripts Scripts to register.
931 - *
932 - * @return void
933 - */
934 - public static function register_scripts( $scripts ) {
935 - $caro = false;
936 - $script = [];
937 -
938 - $script[] = 'jquery';
939 -
940 - foreach ( $scripts as $sc => $value ) {
941 - if ( ! empty( $sc ) ) {
942 - if ( 'isCarousel' === $sc ) {
943 - $caro = $value;
944 - }
945 - }
946 - }
947 -
948 - if ( count( $scripts ) ) {
949 - /**
950 - * Scripts.
951 - */
952 - if ( $caro ) {
953 - $script[] = 'swiper';
954 - }
955 -
956 - $script[] = 'rtsb-imagesloaded';
957 - $script[] = 'rtsb-public';
958 -
959 - foreach ( $script as $sc ) {
960 - wp_enqueue_script( $sc );
961 - }
962 - }
963 - }
964 -
965 - /**
966 - * Check if a wrapper is needed based on the current theme.
967 - *
968 - * @return bool
969 - */
970 - public static function is_wrapper_needed() {
971 - $theme_list = apply_filters(
972 - 'rtsb/products/inner/wrapper/basedon/themes',
973 - [
974 - 'twentytwentyone',
975 - 'twentytwentytwo',
976 - 'twentytwentythree',
977 - 'storefront',
978 - 'hello-elementor',
979 - 'astra',
980 - ],
981 - rtsb()->current_theme
982 - );
983 -
984 - if ( in_array( rtsb()->current_theme, $theme_list, true ) ) {
985 - return true;
986 - }
987 -
988 - return false;
989 - }
990 -
991 - /**
992 - * Get the number of products per page based on WooCommerce settings.
993 - *
994 - * @return int
995 - */
996 - public static function get_products_per_page() {
997 - $products_row = absint( get_option( 'woocommerce_catalog_rows', 4 ) );
998 - $products_col = absint( get_option( 'woocommerce_catalog_columns', 4 ) );
999 - $products_per_page = apply_filters( 'rtsb/elementor/archive/products_per_page', $products_row * $products_col );
1000 -
1001 - return ! empty( $products_per_page ) ? $products_per_page : 12;
1002 - }
1003 -}
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 'preset2':
424 + $class = 'fill angle-right';
425 + break;
426 +
427 + case 'preset3':
428 + $class = 'outline';
429 + break;
430 +
431 + case 'preset4':
432 + $class = 'outline angle-right';
433 + break;
434 +
435 + default:
436 + $class = 'fill';
437 + break;
438 + }
439 +
440 + return $class;
441 + }
442 +
443 + /**
444 + * Registers required scripts.
445 + *
446 + * @param array $scripts Scripts to register.
447 + * @return void
448 + */
449 + public static function register_scripts( $scripts ) {
450 + $caro = false;
451 + $script = [];
452 +
453 + $script[] = 'jquery';
454 +
455 + foreach ( $scripts as $sc => $value ) {
456 + if ( ! empty( $sc ) ) {
457 + if ( 'isCarousel' === $sc ) {
458 + $caro = $value;
459 + }
460 + }
461 + }
462 +
463 + if ( count( $scripts ) ) {
464 + /**
465 + * Scripts.
466 + */
467 + if ( $caro ) {
468 + $script[] = 'swiper';
469 + }
470 +
471 + $script[] = 'rtsb-imagesloaded';
472 + $script[] = 'rtsb-public';
473 +
474 + wp_enqueue_script( $script );
475 + }
476 + }
477 +}