PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.1.1
ShopBuilder – WooCommerce Builder For Elementor v1.1.1
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Elementor / Helper / RenderHelpers.php

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

480 lines 18.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor Render Helper Class.
4 *
5 * This class contains render helper logics.
6 *
7 * @package RadiusTheme\SB
8 */
9
10 namespace RadiusTheme\SB\Elementor\Helper;
11
12 use RadiusTheme\SB\Helpers\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 }
480