PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.2
ShopBuilder – WooCommerce Builder For Elementor v2.6.2
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 / Render / GeneralAddons.php

GeneralAddons.php in ShopBuilder – WooCommerce Builder For Elementor 2.6.2, at app/Elementor/Render/GeneralAddons.php

554 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor GeneralAddons Class.
4 *
5 * This class contains render logics & output for general addons.
6 *
7 * @package RadiusTheme\SB
8 */
9
10 namespace RadiusTheme\SB\Elementor\Render;
11
12 use RadiusTheme\SB\Elementor\Helper\RenderHelpers;
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 * Elementor Render Class.
22 */
23 class GeneralAddons extends Render {
24 /**
25 * HTML.
26 *
27 * @var string
28 */
29 private $addon_html = null;
30
31 /**
32 * Element ID.
33 *
34 * @var string
35 */
36 private $id = null;
37
38 /**
39 * Unique name.
40 *
41 * @var string
42 */
43 public $unique_name = '';
44
45 /**
46 * Template name.
47 *
48 * @var string
49 */
50 public $template_name = '';
51
52 /**
53 * Settings.
54 *
55 * @var array
56 */
57 public $settings = [];
58
59 /**
60 * Carousel check.
61 *
62 * @var bool
63 */
64 public $is_carousel = false;
65
66 /**
67 * Blog Post check.
68 *
69 * @var bool
70 */
71 public $is_post_query = false;
72
73 /**
74 * Blog Post Pagination.
75 *
76 * @var bool
77 */
78 public $is_post_pagination = false;
79
80 /**
81 * Grid check.
82 *
83 * @var bool
84 */
85 public $is_grid = false;
86
87 /**
88 * Content classes.
89 *
90 * @var bool
91 */
92 public $content_classes = [
93 'rtsb-col-grid',
94 ];
95
96 /**
97 * Renders the addon view.
98 *
99 * @param array $data The addon data.
100 * @param array $settings The addon settings.
101 *
102 * @return string
103 */
104 public function addon_view( $data, $settings = [] ) {
105 $this->id = $data['id'];
106 $this->unique_name = $data['unique_name'];
107 $this->template_name = $data['template'];
108 $this->settings = $settings;
109 $this->is_carousel = $data['is_carousel'] ?? false;
110 $this->is_post_query = $data['is_post_query'] ?? false;
111 $this->is_grid = $data['is_grid'] ?? false;
112 $this->is_post_pagination = $data['is_post_pagination'] ?? false;
113 $content = $data['content'];
114
115 if ( ! ( $this->is_grid || empty( $data['content_class'] ) ) ) {
116 $this->content_classes[] = $data['content_class'];
117 $this->content_classes = implode( ' ', $this->content_classes );
118 }
119
120 // Container.
121 $this->addon_container( $content, $data );
122
123 return $this->addon_html;
124 }
125
126 /**
127 * Generates the container HTML.
128 *
129 * @param string $content The content inside the container.
130 * @param array $args Additional arguments for the container.
131 *
132 * @return string
133 */
134 public function addon_container( $content, $args = [] ) {
135 $container_id = 'rtsb-container-' . $this->id;
136 $container_classes = $this->get_container_classes( $args['container_class'] ?? '' );
137 $raw_layout = $args['layout'] ?? '';
138 $template = $args['template'];
139 $layout = RenderHelpers::filter_layout( $raw_layout, $template );
140 $style_attr = '--rtsb-default-columns: ' . esc_attr( RenderHelpers::default_columns( $layout ) );
141 $container_attributes = [
142 'id' => $container_id,
143 'class' => $container_classes,
144 'data-layout' => $layout,
145 ];
146 if ( $this->is_grid ) {
147 $container_attributes['style'] = apply_filters( 'rtsb/general_widget/container/attr', $style_attr, $this->settings );
148 }
149
150 if ( ! empty( $args['container_attr'] ) ) {
151 $container_attributes = array_merge( $container_attributes, $args['container_attr'] );
152 }
153
154 $row_args = wp_parse_args(
155 $this->get_row_args(),
156 [
157 'layout' => $raw_layout,
158 'template' => $template,
159 'content_class' => $args['content_class'] ?? '',
160 'post_query' => $args['post_query'] ?? '',
161 ]
162 );
163
164 // Adding render attributes.
165 $this->add_attribute( 'rtsb_addon_container_attr_' . $this->id, $container_attributes );
166
167 // Generate HTML for the container.
168 $this->addon_html = '<div ' . $this->get_attribute_string( 'rtsb_addon_container_attr_' . $this->id ) . '>';
169 $this->addon_row( $content, $row_args );
170 $this->addon_html .= '</div><!-- .rtsb-container -->';
171
172 return $this->addon_html;
173 }
174
175 /**
176 * Generates the row HTML.
177 *
178 * @param string $content The content inside the row.
179 * @param array $args Additional arguments for the row.
180 *
181 * @return string
182 */
183 public function addon_row( $content, $args = [] ) {
184 $layout = RenderHelpers::filter_layout( $args['layout'] ?? '' );
185 $row_classes = $this->get_row_classes( $layout );
186
187 // Adding render attributes.
188 $this->add_attribute( 'rtsb_addon_row_attr_' . $this->id, 'class', $row_classes );
189
190 // Start rendering the row.
191 $this->addon_html .= '<div ' . $this->get_attribute_string( 'rtsb_addon_row_attr_' . $this->id ) . '>';
192 if ( $this->is_carousel ) {
193 $this->slider_wrapper_start();
194 }
195
196 // Rendering the content.
197 $this->get_content( $content, $args );
198
199 if ( $this->is_carousel ) {
200 $this->slider_wrapper_end();
201 }
202 $this->addon_html .= '</div><!-- .rtsb-row -->';
203
204 if ( $this->is_post_query && $this->is_post_pagination && ! empty( $args['post_query'] ) ) {
205 $this->addon_html .= $this->render_posts_pagination( $args );
206 }
207 // Preloader.
208
209 $this->addon_html .= $this->pre_loader();
210
211 return $this->addon_html;
212 }
213
214 /**
215 * Renders the content inside the row.
216 *
217 * @param string $content The content.
218 * @param array $args Additional arguments for the content.
219 *
220 * @return void
221 */
222 protected function get_content( $content, $args = [] ) {
223 // Adding render attributes.
224 $this->add_attribute( 'rtsb_addon_content_attr_' . $this->id, 'class', $this->content_classes );
225
226 // Render content HTML.
227 $this->addon_html .= ! $this->is_grid ? '<div ' . $this->get_attribute_string( 'rtsb_addon_content_attr_' . $this->id ) . '>' : '';
228 $this->addon_html .= $content;
229 $this->addon_html .= ! $this->is_grid ? '</div><!-- .rtsb-col-grid -->' : '';
230 }
231
232 /**
233 * Gets container classes.
234 *
235 * @param string $custom Optional custom classes.
236 *
237 * @return string
238 */
239 protected function get_container_classes( $custom = '' ) {
240 $classes = [
241 'rtsb-elementor-container',
242 'rtsb-pos-r',
243 $this->unique_name,
244 ];
245
246 if ( ! empty( $custom ) ) {
247 $classes[] = $custom;
248 }
249 if ( ! empty( $this->settings['slider_slide_animation'] ) ) {
250 $classes[] = 'has-slide-animation';
251 }
252 $classes = implode( ' ', $classes );
253
254 return apply_filters( 'rtsb/general/addon_container/class', $classes, $this->settings );
255 }
256
257 /**
258 * Gets row classes.
259 *
260 * @param string $layout Optional layout name.
261 *
262 * @return string
263 */
264 protected function get_row_classes( $layout = '' ) {
265 $classes = [
266 'rtsb-row',
267 'rtsb-content-loader',
268 ];
269
270 if ( ! empty( $layout ) ) {
271 $classes[] = $layout;
272 }
273
274 if ( $this->is_carousel ) {
275 $classes[] = 'rtsb-slider-layout';
276 }
277 if ( $this->is_carousel && ! empty( $this->settings['always_show_nav'] ) ) {
278 $classes[] = 'always-show-nav';
279 }
280 if ( ! empty( $this->settings['cols_mobile'] ) && '1' == $this->settings['cols_mobile'] ) {
281 $classes[] = ' rtsb-mobile-flex-row';
282 }
283 $classes = implode( ' ', $classes );
284
285 return apply_filters( 'rtsb/general/addon_row/class', $classes, $this->settings );
286 }
287
288 /**
289 * Gets row arguments.
290 *
291 * @return array Row arguments.
292 */
293 protected function get_row_args() {
294 return [];
295 }
296
297 /**
298 * Starts the carousel slider wrapper.
299 *
300 * @return void
301 */
302 private function slider_wrapper_start() {
303 $slider_data = $this->get_slider_data();
304 $slider_options = $slider_data['data'] ?? '';
305 $slider_classes = $slider_data['class'] ?? '';
306 $slider_data = [
307 'class' => 'rtsb-carousel-slider swiper ' . $slider_classes,
308 'data' => $slider_options,
309 ];
310
311 // Adding slider attributes.
312 $this->add_attribute(
313 'rtsb_slider_attr_' . $this->id,
314 [
315 'class' => 'rtsb-col-grid ' . $slider_data['class'],
316 'data-options' => $slider_data['data'],
317 ]
318 );
319
320 // Render slider wrapper.
321 $this->addon_html .= '<div ' . $this->get_attribute_string( 'rtsb_slider_attr_' . $this->id ) . '>';
322 $this->addon_html .= '<div class="swiper-wrapper">';
323 }
324
325 /**
326 * Ends the carousel slider wrapper.
327 *
328 * @return void
329 */
330 private function slider_wrapper_end() {
331 $this->addon_html .= '</div><!-- .swiper-wrapper -->';
332 $this->addon_html .= $this->slider_buttons( $this->settings );
333 $this->addon_html .= '</div><!-- .rtsb-carousel-slider -->';
334 }
335
336 /**
337 * Gets slider data for the carousel.
338 *
339 * @return array
340 */
341 protected function get_slider_data() {
342 $metas = $this->get_slider_meta_dataset( $this->settings, $this->template_name, $this->settings );
343
344 return RenderHelpers::slider_data( (array) $metas, $this->settings );
345 }
346 /**
347 * Gets slider data for the carousel.
348 *
349 * @return string
350 */
351 protected function get_slider_meta_dataset( array $meta, $template = '', $raw_settings = [] ) {
352 $data = [
353 'widget' => 'custom',
354 'template' => RenderHelpers::get_data( $template, '', '' ),
355 'raw_settings' => $raw_settings,
356 'd_cols' => RenderHelpers::get_data( $meta, 'cols', 0 ),
357 't_cols' => RenderHelpers::get_data( $meta, 'cols_tablet', 2 ),
358 'm_cols' => RenderHelpers::get_data( $meta, 'cols_mobile', 1 ),
359 'd_group' => RenderHelpers::get_data( $meta, 'cols_group', 1 ),
360 't_group' => RenderHelpers::get_data( $meta, 'cols_group_tablet', 1 ),
361 'm_group' => RenderHelpers::get_data( $meta, 'cols_group_mobile', 1 ),
362 'layout' => RenderHelpers::get_data( $meta, 'layout_style', 'layout1' ),
363 'auto_play' => ! empty( $meta['slide_autoplay'] ),
364 'stop_on_hover' => ! empty( $meta['pause_hover'] ),
365 'slider_nav' => ! empty( $meta['slider_nav'] ),
366 'slider_dot' => ! empty( $meta['slider_pagi'] ),
367 'slider_dynamic_dot' => ! empty( $meta['slider_dynamic_pagi'] ),
368 'loop' => ! empty( $meta['slider_loop'] ),
369 'lazy_load' => ! empty( $meta['slider_lazy_load'] ),
370 'auto_height' => ! empty( $meta['slider_auto_height'] ),
371 'speed' => RenderHelpers::get_data( $meta, 'slide_speed', 2000 ),
372 'space_between' => isset( $meta['grid_gap']['size'] ) && strlen( $meta['grid_gap']['size'] ) ? $meta['grid_gap']['size'] : 30,
373 'auto_play_timeout' => RenderHelpers::get_data( $meta, 'autoplay_timeout', 5000 ),
374 'nav_position' => RenderHelpers::get_data( $meta, 'slider_nav_position', 'top' ),
375 'left_arrow_icon' => RenderHelpers::get_data( $meta, 'slider_left_arrow_icon', [] ),
376 'right_arrow_icon' => RenderHelpers::get_data( $meta, 'slider_right_arrow_icon', [] ),
377 ];
378 if ( ! empty( $meta['cols_widescreen'] ) ) {
379 $data['w_cols'] = $meta['cols_widescreen'];
380 }
381
382 if ( ! empty( $meta['cols_laptop'] ) ) {
383 $data['l_cols'] = $meta['cols_laptop'];
384 }
385
386 if ( ! empty( $meta['cols_tablet_extra'] ) ) {
387 $data['te_cols'] = $meta['cols_tablet_extra'];
388 }
389
390 if ( ! empty( $meta['cols_mobile_extra'] ) ) {
391 $data['me_cols'] = $meta['cols_mobile_extra'];
392 }
393 return apply_filters( 'rtsb/elementor/render/slider_dataset_final', $data, $meta, $raw_settings );
394 }
395
396
397 /**
398 * Renders the carousel slider buttons.
399 *
400 * @return string
401 */
402 protected function slider_buttons( $settings ) {
403 $html = '';
404 $left_icon = $settings['slider_left_arrow_icon'];
405 $right_icon = $settings['slider_right_arrow_icon'];
406
407 if ( ! empty( $settings['slider_nav'] ) ) {
408 $html .=
409 '<div class="swiper-nav">
410 <div class="swiper-arrow swiper-button-next">
411 ' . Fns::icons_manager( $right_icon ) . '
412 </div>
413 <div class="swiper-arrow swiper-button-prev">
414 ' . Fns::icons_manager( $left_icon ) . '
415 </div>
416 </div>';
417 }
418
419 $html .= ! empty( $settings['slider_pagi'] ) ? '<div class="swiper-pagination rtsb-pos-s"></div>' : '';
420
421 return $html;
422 }
423 /**
424 * Preloader.
425 *
426 * @return string
427 */
428 public function pre_loader() {
429 if ( $this->is_carousel ) {
430 return '<div class="rtsb-elements-loading rtsb-ball-clip-rotate"><div></div></div>';
431 }
432 return '';
433 }
434 /**
435 * No posts message.
436 *
437 * @return string
438 */
439 public function no_posts_msg() {
440 return '<div class="rtsb-notice">
441 <div class="woocommerce-info">' . esc_html__( 'No posts were found matching your selection.', 'shopbuilder' ) . '</div>
442 </div>';
443 }
444 /**
445 * Renders posts pagination
446 *
447 * @param array $args Pagination args.
448 *
449 * @return string
450 */
451 public function render_posts_pagination( $args ) {
452 list(
453 'post_query' => $query,
454 'posts_limit' => $limit,
455 'posts_per_page' => $per_page
456 ) = $args;
457 $html_utility = null;
458 $html = null;
459 $posts_per_page = $query->query_vars['posts_per_page'];
460 $found_posts = $query->found_posts;
461 $total_page = $query->max_num_pages;
462 if ( $limit ) {
463 if ( ( empty( $wp_query->query['tax_query'] ) ) ) {
464 $found_posts = $query->found_posts;
465 }
466
467 if ( $per_page && $found_posts > $per_page ) {
468 $found_posts = $limit;
469 $total_page = ceil( $found_posts / $per_page );
470 }
471 }
472
473 $total_page = absint( $total_page );
474
475 $html_utility .= Fns::custom_pagination(
476 $total_page,
477 $posts_per_page
478 );
479
480 if ( $html_utility ) {
481 $rand = wp_rand();
482
483 // Adding pagination render attributes.
484 $this->add_attribute(
485 'rtsb_pagination_attr_' . $rand,
486 [
487 'class' => 'rtsb-pagination-wrap element-loading',
488 'data-total-pages' => $total_page,
489 'data-posts-per-page' => $posts_per_page,
490 'data-type' => 'pagination',
491 ]
492 );
493
494 // Start rendering.
495 $html = '<div ' . $this->get_attribute_string( 'rtsb_pagination_attr_' . $rand ) . '>';
496 $html .= $html_utility;
497 $html .= '</div><!-- .rtsb-pagination-wrap -->';
498 }
499
500 return $html;
501 }
502
503 /**
504 * Function to render buttom html.
505 *
506 * @param array $args Button Arguments.
507 *
508 * @return void
509 */
510 public static function render_buttom_html( $args ) {
511 $default_args = [
512 'button_attributes' => '',
513 'sb_button_icon' => '',
514 'sb_button_icon_position' => 'right',
515 'sb_button_content' => esc_html__( 'ShopBuilder Button', 'shopbuilder' ),
516 ];
517 $args = wp_parse_args( $args, $default_args );
518 ?>
519 <a <?php Fns::print_html( $args['button_attributes'] ); ?>>
520 <span class="text-wrap <?php echo esc_attr( 'icon-' . $args['sb_button_icon_position'] ); ?>">
521 <?php
522 Fns::print_html( self::render_button_icon( 'left', $args['sb_button_icon'], $args['sb_button_icon_position'] ) );
523 Fns::print_html( '<span class="text">' );
524 Fns::print_html( $args['sb_button_content'] );
525 Fns::print_html( '</span>' );
526 Fns::print_html( '<span class="hover-text">' );
527 Fns::print_html( $args['sb_button_content'] );
528 Fns::print_html( '</span>' );
529 Fns::print_html( self::render_button_icon( 'right', $args['sb_button_icon'], $args['sb_button_icon_position'] ) );
530 ?>
531 </span>
532 </a>
533 <?php
534 }
535 /**
536 * Function to render icon.
537 *
538 * @param string $position icon position ('left' or 'right').
539 * @param array $icon Position of the separator in settings.
540 *
541 * @return string
542 */
543 public static function render_button_icon( $position, $icon, $icon_position ) {
544 $html = '';
545
546 // Render the left icon.
547 if ( $position === $icon_position ) {
548 $html .= '<span class="icon">' . Fns::icons_manager( $icon ) . '</span>';
549 }
550
551 return $html;
552 }
553 }
554