PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.0
ShopBuilder – WooCommerce Builder For Elementor v2.6.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
shopbuilder / app / Elementor / Render / GeneralAddons.php

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

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