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/Abstracts/ElementorWidgetBase.php +636 -767 2.2.21.0.0 View file →
@@ -1,767 +1,636 @@
1 -<?php
2 -/**
3 - * Main ElementorWidgetBase class.
4 - *
5 - * @package RadiusTheme\SB
6 - */
7 -
8 -namespace RadiusTheme\SB\Abstracts;
9 -
10 -use Elementor\Plugin;
11 -use Elementor\Repeater;
12 -use Elementor\Widget_Base;
13 -use Elementor\Controls_Manager;
14 -use Elementor\Group_Control_Border;
15 -use RadiusTheme\SB\Controllers\Hooks\FilterHooks;
16 -use RadiusTheme\SB\Helpers\BuilderFns;
17 -use Elementor\Group_Control_Typography;
18 -use Elementor\Group_Control_Background;
19 -use Elementor\Group_Control_Box_Shadow;
20 -use Elementor\Group_Control_Text_Shadow;
21 -use Elementor\Group_Control_Text_Stroke;
22 -use RadiusTheme\SB\Elementor\Helper\ControlSelectors;
23 -
24 -
25 -// Do not allow directly accessing this file.
26 -if ( ! defined( 'ABSPATH' ) ) {
27 - exit( 'This script cannot be accessed directly.' );
28 -}
29 -
30 -/**
31 - * Abstract ElementorWidgetBase Class
32 - *
33 - * Implemented by classes for elementor addons development.
34 - *
35 - * @version 1.0.0
36 - * @package RadiusTheme\SB
37 - */
38 -abstract class ElementorWidgetBase extends Widget_Base {
39 -
40 - /**
41 - * Widget Title.
42 - *
43 - * @var String
44 - */
45 - public $rtsb_name;
46 -
47 - /**
48 - * Widget name.
49 - *
50 - * @var String
51 - */
52 - public $rtsb_base;
53 -
54 - /**
55 - * Widget categories.
56 - *
57 - * @var String
58 - */
59 - public $rtsb_category;
60 -
61 - /**
62 - * Widget icon class
63 - *
64 - * @var String
65 - */
66 - public $rtsb_icon;
67 -
68 - /**
69 - * PRO Label HTML.
70 - *
71 - * @var String
72 - */
73 - public $pro_label = '';
74 -
75 - /**
76 - * PRO content tab.
77 - *
78 - * @var String
79 - */
80 - public $pro_tab;
81 -
82 - /**
83 - * Widget prefix.
84 - *
85 - * @var String
86 - */
87 - public $el_prefix;
88 -
89 - /**
90 - * Widget controls.
91 - *
92 - * @var array
93 - */
94 - public $selectors = [];
95 -
96 - /**
97 - * Class Constructor
98 - *
99 - * @param array $data default data.
100 - * @param array $args default arg.
101 - */
102 - public function __construct( $data = [], $args = null ) {
103 - $this->apply_hooks_before_render();
104 - parent::__construct( $data, $args );
105 - $this->rtsb_category = 'rtsb-shopbuilder';
106 - $this->rtsb_icon = 'rtsb-el-custom rtsb-element icon-' . $this->rtsb_base;
107 - $this->el_prefix = 'rtsb_el_';
108 - $this->pro_label = sprintf(
109 - '<span class="rtsb-pro-label">%s</span>',
110 - esc_html__( 'Pro', 'shopbuilder' )
111 - );
112 - $this->selectors = ControlSelectors::get_widget_selectors( $this );
113 - }
114 -
115 -
116 - /**
117 - * Elementor controls marge all settings
118 - *
119 - * @return array
120 - */
121 - abstract public function widget_fields();
122 -
123 - /**
124 - * Get widget name.
125 - *
126 - * Retrieve widget name.
127 - *
128 - * @access public
129 - *
130 - * @return string Widget name.
131 - */
132 - public function get_name() {
133 - return $this->rtsb_base;
134 - }
135 -
136 - /**
137 - * Set Widget Keyword.
138 - *
139 - * @return array
140 - */
141 - public function get_keywords() {
142 - return [ 'woocommerce', 'shopbuilder' ];
143 - }
144 -
145 - /**
146 - * Get widget title.
147 - *
148 - * Retrieve widget title.
149 - *
150 - * @access public
151 - *
152 - * @return string Widget title.
153 - */
154 - public function get_title() {
155 - return $this->rtsb_name;
156 - }
157 -
158 - /**
159 - * Get widget icon.
160 - *
161 - * Retrieve widget icon.
162 - *
163 - * @return string Widget icon.
164 - * @since 1.0.0
165 - * @access public
166 - */
167 - public function get_icon() {
168 - return $this->rtsb_icon;
169 - }
170 -
171 - /**
172 - * Get widget categories.
173 - *
174 - * Retrieve the list of categories widget belongs to.
175 - *
176 - * @return array Widget categories.
177 - * @since 1.0.0
178 - * @access public
179 - */
180 - public function get_categories() {
181 - return [ $this->rtsb_category ];
182 - }
183 -
184 - /**
185 - * Elementor Promotional section controls.
186 - *
187 - * @return array
188 - */
189 - public function promo_content() {
190 - if ( rtsb()->has_pro() ) {
191 - return [];
192 - }
193 -
194 - $promo_fields = [];
195 -
196 - $promo_fields['pro_alert'] = [
197 - 'mode' => 'section_start',
198 - 'label' => sprintf(
199 - '<span style="color: #f54">%s</span>',
200 - esc_html__( 'Go Premium for More Features', 'shopbuilder' )
201 - ),
202 - ];
203 -
204 - if ( $this->pro_tab ) {
205 - $promo_fields['pro_alert']['tab'] = $this->pro_tab;
206 - }
207 -
208 - $promo_fields['get_pro'] = [
209 - 'type' => 'html',
210 - 'raw' => '<div class="elementor-nerd-box rtsb-promo"><div class="elementor-nerd-box-title" style="margin-top: 0; margin-bottom: 20px;">Unlock more possibilities</div><div class="elementor-nerd-box-message"><span class="pro-feature" style="font-size: 13px;"> Get the <a href="' . esc_url( rtsb()->pro_version_link() ) . '" target="_blank" style="color: #f54">Pro version</a> for more stunning layouts and customization options.</span></div><a class="elementor-nerd-box-link elementor-button elementor-button-default elementor-button-go-pro" href="' . esc_url( rtsb()->pro_version_link() ) . '" target="_blank">Get Pro</a></div>',
211 - 'separator' => 'default',
212 - ];
213 -
214 - $promo_fields['pro_alert_end'] = [
215 - 'mode' => 'section_end',
216 - ];
217 -
218 - return $promo_fields;
219 - }
220 -
221 - /**
222 - * Register widget controls.
223 - *
224 - * Adds different input fields to allow the user to change and customize the widget settings.
225 - *
226 - * @since 1.0.0
227 - * @access protected
228 - */
229 - protected function register_controls() {
230 - $this->theme_support( 'widget_controls' );
231 - $the_widget = $this->widget_fields();
232 - if ( ! is_array( $the_widget ) ) {
233 - return;
234 - }
235 - $fields = array_merge( $the_widget, $this->promo_content() );
236 -
237 - $fields = apply_filters( 'rtsb/elements/elementor/widgets/controls/' . $this->rtsb_base, $fields, $this );
238 -
239 - foreach ( $fields as $id => $field ) {
240 - $field['classes'] = ! empty( $field['classes'] ) ? $field['classes'] . ' elementor-control-rtsb_el' : ' elementor-control-rtsb_el';
241 -
242 - if ( ! empty( $field['type'] ) ) {
243 - $field['type'] = self::el_fields( $field['type'] );
244 - }
245 -
246 - if ( ! empty( $field['tab'] ) ) {
247 - $field['tab'] = self::el_tabs( $field['tab'] );
248 - }
249 -
250 - if ( isset( $field['mode'] ) && 'section_start' === $field['mode'] ) {
251 - unset( $field['mode'] );
252 - unset( $field['separator'] );
253 -
254 - $this->start_controls_section( $id, $field );
255 - } elseif ( isset( $field['mode'] ) && 'section_end' === $field['mode'] ) {
256 - $this->end_controls_section();
257 - } elseif ( isset( $field['mode'] ) && 'tabs_start' === $field['mode'] ) {
258 - unset( $field['mode'] );
259 - unset( $field['separator'] );
260 -
261 - $this->start_controls_tabs( $id );
262 - } elseif ( isset( $field['mode'] ) && 'tabs_end' === $field['mode'] ) {
263 - $this->end_controls_tabs();
264 - } elseif ( isset( $field['mode'] ) && 'tab_start' === $field['mode'] ) {
265 - unset( $field['mode'] );
266 - unset( $field['separator'] );
267 -
268 - $this->start_controls_tab( $id, $field );
269 - } elseif ( isset( $field['mode'] ) && 'tab_end' === $field['mode'] ) {
270 - $this->end_controls_tab();
271 - } elseif ( isset( $field['mode'] ) && 'group' === $field['mode'] ) {
272 - $type = $field['type'];
273 - $field['name'] = $id;
274 - unset( $field['mode'] );
275 - unset( $field['type'] );
276 - $this->add_group_control( $type, $field );
277 - } elseif ( isset( $field['mode'] ) && 'responsive' === $field['mode'] ) {
278 - unset( $field['mode'] );
279 -
280 - $this->add_responsive_control( $id, $field );
281 - } elseif ( isset( $field['mode'] ) && 'popover_start' === $field['mode'] ) {
282 - unset( $field['mode'] );
283 - unset( $field['separator'] );
284 -
285 - $this->add_control( $id, $field );
286 - $this->start_popover();
287 - } elseif ( isset( $field['mode'] ) && 'popover_end' === $field['mode'] ) {
288 - $this->end_popover();
289 - } elseif ( isset( $field['mode'] ) && 'repeater' === $field['mode'] ) {
290 - $repeater = new Repeater();
291 - $repeater_fields = $field['fields'];
292 -
293 - foreach ( $repeater_fields as $rf_id => $value ) {
294 - if ( ! empty( $value['type'] ) ) {
295 - $value['type'] = self::el_fields( $value['type'] );
296 - }
297 - if ( isset( $value['mode'] ) && 'responsive' === $value['mode'] ) {
298 - unset( $value['mode'] );
299 - $repeater->add_responsive_control( $rf_id, $value );
300 - } else {
301 - $repeater->add_control( $rf_id, $value );
302 - }
303 - }
304 -
305 - $field['fields'] = $repeater->get_controls();
306 -
307 - $this->add_control( $id, $field );
308 - } else {
309 - $this->add_control( $id, $field );
310 - }
311 - }
312 -
313 - do_action( 'rtsb/after/register/controls' );
314 - }
315 -
316 - /**
317 - * Elementor Edit mode.
318 - *
319 - * @return mixed
320 - */
321 - public function is_edit_mode() {
322 - return Plugin::$instance->preview->is_preview_mode() || Plugin::$instance->editor->is_edit_mode();
323 - }
324 -
325 - /**
326 - * Elementor Edit preview.
327 - *
328 - * @return mixed
329 - */
330 - public function is_builder_mode() {
331 - return BuilderFns::is_builder_preview() || $this->is_edit_mode();
332 - }
333 -
334 - /**
335 - * Elementor Edit mode need some extra js for isotop reinitialize
336 - *
337 - * @return void
338 - */
339 - public function editor_slider_script() {
340 - if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
341 - $selector = $this->get_unique_selector() . ' .rtsb-carousel-slider';
342 - ?>
343 - <script>
344 - jQuery('<?php echo esc_attr( $selector ); ?>').rtsb_slider();
345 - </script>
346 - <?php
347 - }
348 - }
349 -
350 - /**
351 - * Elementor Edit mode need some extra js for isotop reinitialize
352 - *
353 - * @return void
354 - */
355 - public function editor_cart_icon_script() {
356 - if ( $this->is_edit_mode() ) {
357 - $selector = $this->get_unique_selector() . ' .has-cart-button';
358 - ?>
359 - <script type="text/javascript">
360 - // Product Archive Catelog
361 - (function ($) {
362 - setTimeout( function (){
363 - var cartWrpper = $('body').find('<?php echo esc_attr( $selector ); ?>');
364 - var cartIcon = cartWrpper.attr('data-cart-icon');
365 - var cartButton = cartWrpper.find(
366 - '.product_type_grouped, .add_to_cart_button, .single_add_to_cart_button '
367 - );
368 - if (cartIcon) {
369 - //console.log( cartButton.find('svg') )
370 - cartButton.find('i').remove();
371 - cartButton.find('svg').remove();
372 - cartButton.find('img').remove();
373 - cartButton.prepend(cartIcon);
374 - }
375 - }, 2000);
376 - })(jQuery);
377 - </script>
378 - <?php
379 - }
380 - }
381 -
382 - /**
383 - * Elementor Edit mode script
384 - *
385 - * @return void
386 - */
387 - public function edit_mode_script() {
388 - if ( ! $this->is_edit_mode() ) {
389 - return;
390 - }
391 - $ajaxurl = admin_url( 'admin-ajax.php' );
392 - if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
393 - $ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
394 - }
395 - ?>
396 - <script>
397 - var rtsb = {
398 - ajaxurl: '<?php echo esc_url( $ajaxurl ); ?>',
399 - nonce: '<?php echo esc_attr( wp_create_nonce( rtsb()->nonceId ) ); ?>',
400 - is_pro: '<?php echo esc_attr( rtsb()->has_pro() ? 'true' : 'false' ); ?>'
401 - };
402 -
403 - rtsbElFrontend();
404 -
405 - setTimeout(function() {
406 - rtsbProductPageInit();
407 - }, 1000);
408 - <?php if ( rtsb()->has_pro() ) { ?>
409 - rtsbFilters();
410 - setTimeout( function (){
411 - window.rtsbCountdownApply();
412 - }, 1000 );
413 - <?php } ?>
414 - </script>
415 -
416 - <?php
417 - }
418 -
419 - /**
420 - * Starts an Elementor Section
421 - *
422 - * @param string $label Section label.
423 - * @param object $tab Tab ID.
424 - * @param array $conditions Section Condition.
425 - * @param array $condition Section Conditions.
426 - * @return array
427 - */
428 - public function start_section( $label, $tab, $conditions = [], $condition = [] ) {
429 - $start = [
430 - 'mode' => 'section_start',
431 - 'tab' => $tab,
432 - 'label' => $label,
433 - ];
434 - if ( ! empty( $condition ) ) {
435 - $start['condition'] = $condition;
436 - }
437 - if ( ! empty( $conditions ) ) {
438 - $start['conditions'] = $conditions;
439 - }
440 - return $start;
441 - }
442 -
443 - /**
444 - * Ends an Elementor Section
445 - *
446 - * @return array
447 - */
448 - public function end_section() {
449 - return [
450 - 'mode' => 'section_end',
451 - ];
452 - }
453 -
454 - /**
455 - * Theme Support for render/widget_controls
456 - *
457 - * @param string $support Support for render/widget_controls.
458 - * @return void
459 - */
460 - public function theme_support( $support = 'render' ) {
461 -
462 - if ( empty( $support ) ) {
463 - return;
464 - }
465 - $theme = ucwords( str_replace( [ '_', '-', ' ' ], '', rtsb()->current_theme ) );
466 -
467 - $supportClass = apply_filters(
468 - 'radiustheme/sb/widgetsupport/class',
469 - [
470 - 'ShopbuilderPlugin' => 'RadiusTheme\SB\Controllers\ThemesSupport\\' . $theme . '\\WidgetsSupport',
471 - 'TheTheme' => \WidgetSupport::class,
472 - ]
473 - );
474 -
475 - foreach ( $supportClass as $key => $theClass ) {
476 - $themeWidgetSupport = get_theme_file_path( '/shopbuilder/WidgetSupport.php' );
477 - if ( 'TheTheme' === $key && file_exists( $themeWidgetSupport ) ) {
478 - require_once $themeWidgetSupport;
479 - }
480 - if ( class_exists( $theClass ) ) {
481 - $method = $support . '_' . str_replace( [ '-', ' ' ], '_', $this->rtsb_base );
482 - if ( method_exists( $theClass, $method ) ) {
483 - $theClass::instance( $this )->$method();
484 - }
485 - }
486 - }
487 - }
488 -
489 - /**
490 - * Starts an Elementor tab group.
491 - *
492 - * @param array $conditions Tab condition.
493 - * @param array $condition Tab condition.
494 - * @return array
495 - */
496 - public function start_tab_group( $conditions = [], $condition = [] ) {
497 - return [
498 - 'mode' => 'tabs_start',
499 - 'conditions' => $conditions,
500 - 'condition' => $condition,
501 - ];
502 - }
503 -
504 - /**
505 - * Ends an Elementor tab group.
506 - *
507 - * @param array $conditions Tab condition.
508 - * @param array $condition Tab condition.
509 - * @return array
510 - */
511 - public function end_tab_group( $conditions = [], $condition = [] ) {
512 - return [
513 - 'mode' => 'tabs_end',
514 - 'conditions' => $conditions,
515 - 'condition' => $condition,
516 - ];
517 - }
518 -
519 - /**
520 - * Starts an Elementor tab
521 - *
522 - * @param string $label Section label.
523 - * @param array $conditions Tab condition.
524 - * @param array $condition Tab condition.
525 - * @return array
526 - */
527 - public function start_tab( $label, $conditions = [], $condition = [] ) {
528 - return [
529 - 'mode' => 'tab_start',
530 - 'label' => $label,
531 - 'conditions' => $conditions,
532 - 'condition' => $condition,
533 - ];
534 - }
535 -
536 - /**
537 - * Ends an Elementor tab.
538 - *
539 - * @param array $conditions Tab condition.
540 - * @param array $condition Tab condition.
541 - * @return array
542 - */
543 - public function end_tab( $conditions = [], $condition = [] ) {
544 - return [
545 - 'mode' => 'tab_end',
546 - 'conditions' => $conditions,
547 - 'condition' => $condition,
548 - ];
549 - }
550 -
551 - /**
552 - * Starts an Elementor Section Heading
553 - *
554 - * @param string $label Heading label.
555 - * @param string $separator Section separator.
556 - * @param array $conditions Section Condition.
557 - * @param array $condition Section Conditions.
558 - * @return array
559 - */
560 - public function el_heading( $label, $separator = null, $conditions = [], $condition = [] ) {
561 - return [
562 - 'type' => 'html',
563 - 'raw' => sprintf(
564 - '<h3 class="rtsb-elementor-group-heading">%s</h3>',
565 - $label
566 - ),
567 - 'separator' => $separator,
568 - 'content_classes' => 'elementor-panel-heading-title',
569 - 'conditions' => $conditions,
570 - 'condition' => $condition,
571 - ];
572 - }
573 -
574 - /**
575 - * Prints a control notification.
576 - *
577 - * @param string $label Field label.
578 - * @return string
579 - */
580 - public function is_pro_control( $label ) {
581 - if ( rtsb()->has_pro() ) {
582 - return $label;
583 - }
584 -
585 - return $label . $this->pro_label;
586 - }
587 -
588 - /**
589 - * Adds a class.
590 - *
591 - * @return string
592 - */
593 - public function pro_class() {
594 - return ! rtsb()->has_pro() ? 'rtsb-pro-field' : '';
595 - }
596 -
597 - /**
598 - * Elementor Fields.
599 - *
600 - * @param string $type Control type.
601 - *
602 - * @return string
603 - */
604 - private static function el_fields( $type ) {
605 -
606 - $controls = Controls_Manager::class;
607 -
608 - switch ( $type ) {
609 - case 'link':
610 - $type = $controls::URL;
611 - break;
612 -
613 - case 'image-dimensions':
614 - $type = $controls::IMAGE_DIMENSIONS;
615 - break;
616 -
617 - case 'html':
618 - $type = $controls::RAW_HTML;
619 - break;
620 -
621 - case 'switch':
622 - $type = $controls::SWITCHER;
623 - break;
624 -
625 - case 'popover':
626 - $type = $controls::POPOVER_TOGGLE;
627 - break;
628 -
629 - case 'rtsb-image-selector':
630 - $type = \RadiusTheme\SB\Elementor\Controls\ImageSelectorControl::$controlName;
631 - break;
632 -
633 - case 'rt-select2':
634 - $type = \RadiusTheme\SB\Elementor\Controls\Select2AjaxControl::$controlName;
635 - break;
636 -
637 - case 'typography':
638 - $type = Group_Control_Typography::get_type();
639 - break;
640 -
641 - case 'border':
642 - $type = Group_Control_Border::get_type();
643 - break;
644 -
645 - case 'background':
646 - $type = Group_Control_Background::get_type();
647 - break;
648 -
649 - case 'box-shadow':
650 - $type = Group_Control_Box_Shadow::get_type();
651 - break;
652 -
653 - case 'text-shadow':
654 - $type = Group_Control_Text_Shadow::get_type();
655 - break;
656 -
657 - case 'text-stroke':
658 - $type = Group_Control_Text_Stroke::get_type();
659 - break;
660 - default:
661 - $type = constant( 'Elementor\Controls_Manager::' . strtoupper( $type ) );
662 -
663 - }
664 -
665 - return $type;
666 - }
667 -
668 - /**
669 - * Elementor Fields.
670 - *
671 - * @param string $tab Tab.
672 - *
673 - * @return string
674 - */
675 - private static function el_tabs( $tab ) {
676 - return constant( 'Elementor\Controls_Manager::TAB_' . strtoupper( $tab ) );
677 - }
678 -
679 -
680 - /**
681 - * Init render hooks & functions.
682 - *
683 - * @return void
684 - */
685 - protected function render_start() {
686 - add_filter( 'rtsb/countdown/campaign/parent/class', [ $this, 'countdown_campaign_parent_class' ], 15 );
687 - do_action( 'rtsb/custom/products/before/template/load', $this );
688 - $this->theme_support();
689 -
690 - if ( $this->is_builder_mode() ) {
691 - add_filter( 'wp_kses_allowed_html', [ FilterHooks::class, 'custom_wpkses_post_tags' ], 10, 2 );
692 - }
693 - }
694 - /**
695 - * Archive Custom Layout Widget Rendering.
696 - *
697 - * @return void
698 - */
699 - public function countdown_campaign_parent_class( $classes ) {
700 - $settings = $this->get_settings_for_display();
701 - $layout = $settings['countdown_layout'] ?? 'horizontal';
702 - $v_position = $settings['countdown_vertical_position'] ?? '';
703 - $countdown_preset = $settings['countdown_preset'] ?? '';
704 - $vertical_center = $settings['countdown_vertical_center'] ?? false;
705 -
706 - $remove = [
707 - 'rtsb-countdown-horizontal',
708 - 'rtsb-countdown-vertical',
709 - 'rtsb-vertical-position-top-left',
710 - 'rtsb-vertical-position-top-right',
711 - ];
712 - $classes = array_filter(
713 - $classes,
714 - function ( $item ) use ( $remove ) {
715 - return ! in_array( $item, $remove );
716 - }
717 - );
718 - $new_class = 'rtsb-countdown-' . esc_attr( $countdown_preset );
719 - $new_class .= ' rtsb-countdown-' . esc_attr( $layout );
720 -
721 - if ( $v_position && 'horizontal' !== $layout ) {
722 - $vertical_class = 'rtsb-vertical-position-top-' . esc_attr( $v_position );
723 - $classes[] = $vertical_class;
724 - if ( 'yes' === $vertical_center ) {
725 - $classes[] = 'rtsb-countdown-vertical-middle';
726 - }
727 - }
728 -
729 - $classes[] = $new_class;
730 -
731 - return $classes;
732 - }
733 - /**
734 - * End render hooks & functions.
735 - *
736 - * @return void
737 - */
738 - protected function render_end() {
739 - $this->edit_mode_script();
740 - do_action( 'rtsb/custom/products/after/template/load', $this );
741 - $this->theme_support( 'render_reset' );
742 - remove_filter( 'rtsb/countdown/campaign/parent/class', [ $this, 'countdown_campaign_parent_class' ], 15 );
743 - }
744 -
745 - /**
746 - * Elementor controls marge all settings
747 - *
748 - * @return array
749 - */
750 - protected function apply_hooks_before_render() {
751 - if ( $this->is_edit_mode() ) {
752 - add_filter( 'wp_calculate_image_srcset_meta', '__return_null' );
753 - }
754 - }
755 -
756 - /**
757 - * If checkout registration is disabled and not logged in,
758 - * the user cannot check out.
759 - *
760 - * @return bool
761 - */
762 - protected function has_checkout_restriction() {
763 - $checkout = WC()->checkout();
764 -
765 - return ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in();
766 - }
767 -}
1 +<?php
2 +/**
3 + * Main ElementorWidgetBase class.
4 + *
5 + * @package RadiusTheme\SB
6 + */
7 +
8 +namespace RadiusTheme\SB\Abstracts;
9 +
10 +use Elementor\Plugin;
11 +use Elementor\Repeater;
12 +use Elementor\Widget_Base;
13 +use Elementor\Controls_Manager;
14 +use Elementor\Group_Control_Border;
15 +use RadiusTheme\SB\Helpers\BuilderFns;
16 +use Elementor\Group_Control_Typography;
17 +use Elementor\Group_Control_Background;
18 +use Elementor\Group_Control_Box_Shadow;
19 +use Elementor\Group_Control_Text_Shadow;
20 +use Elementor\Group_Control_Text_Stroke;
21 +use RadiusTheme\SB\Elementor\Helper\ControlSelectors;
22 +
23 +
24 +// Do not allow directly accessing this file.
25 +if ( ! defined( 'ABSPATH' ) ) {
26 + exit( 'This script cannot be accessed directly.' );
27 +}
28 +
29 +/**
30 + * Abstract ElementorWidgetBase Class
31 + *
32 + * Implemented by classes using using for elementor addons development.
33 + *
34 + * @version 1.0.0
35 + * @package RadiusTheme\SB
36 + */
37 +abstract class ElementorWidgetBase extends Widget_Base {
38 + /**
39 + * Widget Title.
40 + *
41 + * @var String
42 + */
43 + public $rtsb_name;
44 +
45 + /**
46 + * Widget name.
47 + *
48 + * @var String
49 + */
50 + public $rtsb_base;
51 +
52 + /**
53 + * Widget categories.
54 + *
55 + * @var String
56 + */
57 + public $rtsb_category;
58 +
59 + /**
60 + * Widget icon class
61 + *
62 + * @var String
63 + */
64 + public $rtsb_icon;
65 +
66 + /**
67 + * PRO Label HTML.
68 + *
69 + * @var String
70 + */
71 + public $pro_label = '';
72 +
73 + /**
74 + * PRO content tab.
75 + *
76 + * @var String
77 + */
78 + public $pro_tab;
79 +
80 + /**
81 + * Widget prefix.
82 + *
83 + * @var String
84 + */
85 + public $el_prefix;
86 +
87 + /**
88 + * Widget controls.
89 + *
90 + * @var array
91 + */
92 + public $selectors = [];
93 +
94 + /**
95 + * Class Constructor
96 + *
97 + * @param array $data default data.
98 + * @param array $args default arg.
99 + */
100 + public function __construct( $data = [], $args = null ) {
101 + parent::__construct( $data, $args );
102 + $this->rtsb_category = 'rtsb-shopbuilder';
103 + $this->rtsb_icon = 'rtsb-el-custom rtsb-element icon-' . $this->rtsb_base;
104 + $this->el_prefix = 'rtsb_el_';
105 + $this->pro_label = sprintf(
106 + '<span class="rtsb-pro-label">%s</span>',
107 + esc_html__( 'Pro', 'shopbuilder' )
108 + );
109 + $this->selectors = ControlSelectors::get_widget_selectors( $this );
110 +
111 + }
112 +
113 + /**
114 + * Elementor controls marge all settings
115 + *
116 + * @return array
117 + */
118 + abstract public function widget_fields();
119 +
120 + /**
121 + * Get widget name.
122 + *
123 + * Retrieve widget name.
124 + *
125 + * @access public
126 + *
127 + * @return string Widget name.
128 + */
129 + public function get_name() {
130 + return $this->rtsb_base;
131 + }
132 +
133 + /**
134 + * Set Widget Keyword.
135 + *
136 + * @return array
137 + */
138 + public function get_keywords() {
139 + return [ 'woocommerce', 'shopbuilder' ];
140 + }
141 +
142 + /**
143 + * Get widget title.
144 + *
145 + * Retrieve widget title.
146 + *
147 + * @access public
148 + *
149 + * @return string Widget title.
150 + */
151 + public function get_title() {
152 + return $this->rtsb_name;
153 + }
154 +
155 + /**
156 + * Get widget icon.
157 + *
158 + * Retrieve widget icon.
159 + *
160 + * @since 1.0.0
161 + * @access public
162 + *
163 + * @return string Widget icon.
164 + */
165 + public function get_icon() {
166 + return $this->rtsb_icon;
167 + }
168 +
169 + /**
170 + * Get widget categories.
171 + *
172 + * Retrieve the list of categories widget belongs to.
173 + *
174 + * @since 1.0.0
175 + * @access public
176 + *
177 + * @return array Widget categories.
178 + */
179 + public function get_categories() {
180 + return [ $this->rtsb_category ];
181 + }
182 +
183 + /**
184 + * Elementor Promotional section controls.
185 + *
186 + * @return array
187 + */
188 + public function promo_content() {
189 + if ( rtsb()->has_pro() ) {
190 + return [];
191 + }
192 +
193 + $promo_fields = [];
194 +
195 + $promo_fields['pro_alert'] = [
196 + 'mode' => 'section_start',
197 + 'label' => sprintf(
198 + '<span style="color: #f54">%s</span>',
199 + esc_html__( 'Go Premium for More Features', 'shopbuilder' )
200 + ),
201 + ];
202 +
203 + if ( $this->pro_tab ) {
204 + $promo_fields['pro_alert']['tab'] = $this->pro_tab;
205 + }
206 +
207 + $promo_fields['get_pro'] = [
208 + 'type' => 'html',
209 + 'raw' => '<div class="elementor-nerd-box"><div class="elementor-nerd-box-title" style="margin-top: 0; margin-bottom: 20px;">Unlock more possibilities</div><div class="elementor-nerd-box-message"><span class="pro-feature" style="font-size: 13px;"> Get the <a href="' . esc_url( rtsb()->pro_version_link() ) . '" target="_blank" style="color: #f54">Pro version</a> for more stunning layouts and customization options.</span></div><a class="elementor-nerd-box-link elementor-button elementor-button-default elementor-button-go-pro" href="' . esc_url( rtsb()->pro_version_link() ) . '" target="_blank">Get Pro</a></div>',
210 + 'separator' => 'default',
211 + ];
212 +
213 + $promo_fields['pro_alert_end'] = [
214 + 'mode' => 'section_end',
215 + ];
216 +
217 +// TODO: Will be activated later.
218 +// return $promo_fields;
219 + return [];
220 + }
221 +
222 + /**
223 + * Register widget controls.
224 + *
225 + * Adds different input fields to allow the user to change and customize the widget settings.
226 + *
227 + * @since 1.0.0
228 + * @access protected
229 + */
230 + protected function register_controls() {
231 +
232 + $this->theme_support( 'widget_controls' );
233 +
234 + $fields = array_merge( $this->widget_fields(), $this->promo_content() );
235 +
236 + $fields = apply_filters( 'rtsb/elements/elementor/widgets/controls/' . $this->rtsb_base, $fields, $this );
237 +
238 + foreach ( $fields as $id => $field ) {
239 + $field['classes'] = ! empty( $field['classes'] ) ? $field['classes'] . ' elementor-control-rtsb_el' : ' elementor-control-rtsb_el';
240 + $field['separator'] = ! empty( $field['separator'] ) ? $field['separator'] : 'before-short';
241 +
242 + if ( ! empty( $field['type'] ) ) {
243 + $field['type'] = self::el_fields( $field['type'] );
244 + }
245 +
246 + if ( ! empty( $field['tab'] ) ) {
247 + $field['tab'] = self::el_tabs( $field['tab'] );
248 + }
249 +
250 + if ( isset( $field['mode'] ) && 'section_start' === $field['mode'] ) {
251 + unset( $field['mode'] );
252 + unset( $field['separator'] );
253 +
254 + $this->start_controls_section( $id, $field );
255 + } elseif ( isset( $field['mode'] ) && 'section_end' === $field['mode'] ) {
256 + $this->end_controls_section();
257 + } elseif ( isset( $field['mode'] ) && 'tabs_start' === $field['mode'] ) {
258 + unset( $field['mode'] );
259 + unset( $field['separator'] );
260 +
261 + $this->start_controls_tabs( $id );
262 + } elseif ( isset( $field['mode'] ) && 'tabs_end' === $field['mode'] ) {
263 + $this->end_controls_tabs();
264 + } elseif ( isset( $field['mode'] ) && 'tab_start' === $field['mode'] ) {
265 + unset( $field['mode'] );
266 + unset( $field['separator'] );
267 +
268 + $this->start_controls_tab( $id, $field );
269 + } elseif ( isset( $field['mode'] ) && 'tab_end' === $field['mode'] ) {
270 + $this->end_controls_tab();
271 + } elseif ( isset( $field['mode'] ) && 'group' === $field['mode'] ) {
272 + $type = $field['type'];
273 + $field['name'] = $id;
274 + unset( $field['mode'] );
275 + unset( $field['type'] );
276 + $this->add_group_control( $type, $field );
277 + } elseif ( isset( $field['mode'] ) && 'responsive' === $field['mode'] ) {
278 + unset( $field['mode'] );
279 +
280 + $this->add_responsive_control( $id, $field );
281 + } elseif ( isset( $field['mode'] ) && 'repeater' === $field['mode'] ) {
282 + $repeater = new Repeater();
283 + $repeater_fields = $field['fields'];
284 +
285 + foreach ( $repeater_fields as $rf_id => $value ) {
286 + $repeater->add_control( $rf_id, $value );
287 + }
288 +
289 + $field['fields'] = $repeater->get_controls();
290 +
291 + $this->add_control( $id, $field );
292 + } else {
293 + $this->add_control( $id, $field );
294 + }
295 + }
296 +
297 + do_action( 'rtsb_after_register_controls' );
298 + }
299 +
300 + /**
301 + * Elementor Edit mode.
302 + *
303 + * @return mixed
304 + */
305 + public function is_edit_mode() {
306 + return Plugin::$instance->preview->is_preview_mode() || Plugin::$instance->editor->is_edit_mode();
307 + }
308 +
309 + /**
310 + * Elementor Edit preview.
311 + *
312 + * @return mixed
313 + */
314 + public function is_builder_mode() {
315 + return BuilderFns::is_builder_preview() || $this->is_edit_mode();
316 + }
317 +
318 + /**
319 + * Elementor Edit mode need some extra js for isotop reinitialize
320 + *
321 + * @return void
322 + */
323 + public function editor_slider_script() {
324 + if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
325 + $selector = $this->get_unique_selector() . ' .rtsb-carousel-slider';
326 + ?>
327 + <script>
328 + jQuery('<?php echo esc_attr( $selector ); ?>').rtsb_slider();
329 + </script>
330 + <?php
331 + }
332 + }
333 + /**
334 + * Elementor Edit mode need some extra js for isotop reinitialize
335 + *
336 + * @return void
337 + */
338 + public function editor_cart_icon_script() {
339 + if ( $this->is_edit_mode() ) {
340 + $selector = $this->get_unique_selector() . ' .has-cart-button';
341 + ?>
342 + <script type="text/javascript">
343 + // Product Archive Catelog
344 + (function ($) {
345 + var cartWrpper = $('<?php echo esc_attr( $selector ); ?>');
346 + var cartIcon = cartWrpper.attr('data-cart-icon');
347 + var cartButton = cartWrpper.find(
348 + '.product_type_grouped, .add_to_cart_button, .single_add_to_cart_button '
349 + );
350 + if( cartIcon ) {
351 + cartButton.find('i').remove();
352 + cartButton.prepend(cartIcon);
353 + }
354 + })(jQuery);
355 + </script>
356 + <?php
357 + }
358 + }
359 +
360 + /**
361 + * Elementor Edit mode script
362 + *
363 + * @return void
364 + */
365 + public function edit_mode_script() {
366 + if ( ! $this->is_edit_mode() ) {
367 + return;
368 + }
369 + $ajaxurl = admin_url( 'admin-ajax.php' );
370 + if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
371 + $ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
372 + }
373 + ?>
374 + <script>
375 + var rtsb = {
376 + ajaxurl: '<?php echo esc_url( $ajaxurl ); ?>',
377 + nonce : '<?php echo esc_attr( wp_create_nonce( rtsb()->nonceId ) ); ?>',
378 + is_pro : '<?php echo esc_attr( rtsb()->has_pro() ? 'true' : 'false' ); ?>'
379 + };
380 + rtsbElFrontend();
381 + </script>
382 +
383 + <?php
384 + }
385 +
386 + /**
387 + * Starts an Elementor Section
388 + *
389 + * @param string $label Section label.
390 + * @param object $tab Tab ID.
391 + * @param array $conditions Section Condition.
392 + * @param array $condition Section Conditions.
393 + * @return array
394 + */
395 + public function start_section( $label, $tab, $conditions = [], $condition = [] ) {
396 + return [
397 + 'mode' => 'section_start',
398 + 'label' => $label,
399 + 'tab' => $tab,
400 + 'condition' => $condition,
401 + 'conditions' => $conditions,
402 + ];
403 + }
404 +
405 + /**
406 + * Ends an Elementor Section
407 + *
408 + * @return array
409 + */
410 + public function end_section() {
411 + return [
412 + 'mode' => 'section_end',
413 + ];
414 + }
415 +
416 + /**
417 + * Theme Support for render/widget_controls
418 + *
419 + * @param string $support Support for render/widget_controls.
420 + * @return void
421 + */
422 + public function theme_support( $support = 'render' ) {
423 +
424 + if ( empty( $support ) ) {
425 + return;
426 + }
427 + $theme = ucwords( str_replace( [ '_', '-', ' ' ], '', rtsb()->current_theme ) );
428 +
429 + $supportClass = apply_filters(
430 + 'radiustheme/sb/widgetsupport/class',
431 + [
432 + 'ShopbuilderPlugin' => 'RadiusTheme\SB\Controllers\ThemesSupport\\' . $theme . '\\WidgetsSupport',
433 + 'TheTheme' => \WidgetSupport::class,
434 + ]
435 + );
436 +
437 + foreach ( $supportClass as $key => $theClass ) {
438 + $themeWidgetSupport = get_theme_file_path( '/shopbuilder/WidgetSupport.php' );
439 + if ( 'TheTheme' === $key && file_exists( $themeWidgetSupport ) ) {
440 + require_once $themeWidgetSupport;
441 + }
442 + if ( class_exists( $theClass ) ) {
443 + $method = $support . '_' . str_replace( [ '-', ' ' ], '_', $this->rtsb_base );
444 + if ( method_exists( $theClass, $method ) ) {
445 + $theClass::instance( $this )->$method();
446 + }
447 + }
448 + }
449 + }
450 +
451 + /**
452 + * Starts an Elementor tab group.
453 + *
454 + * @param array $conditions Tab condition.
455 + * @param array $condition Tab condition.
456 + * @return array
457 + */
458 + public function start_tab_group( $conditions = [], $condition = [] ) {
459 + return [
460 + 'mode' => 'tabs_start',
461 + 'conditions' => $conditions,
462 + 'condition' => $condition,
463 + ];
464 + }
465 +
466 + /**
467 + * Ends an Elementor tab group.
468 + *
469 + * @param array $conditions Tab condition.
470 + * @param array $condition Tab condition.
471 + * @return array
472 + */
473 + public function end_tab_group( $conditions = [], $condition = [] ) {
474 + return [
475 + 'mode' => 'tabs_end',
476 + 'conditions' => $conditions,
477 + 'condition' => $condition,
478 + ];
479 + }
480 +
481 + /**
482 + * Starts an Elementor tab
483 + *
484 + * @param string $label Section label.
485 + * @param array $conditions Tab condition.
486 + * @param array $condition Tab condition.
487 + * @return array
488 + */
489 + public function start_tab( $label, $conditions = [], $condition = [] ) {
490 + return [
491 + 'mode' => 'tab_start',
492 + 'label' => $label,
493 + 'conditions' => $conditions,
494 + 'condition' => $condition,
495 + ];
496 + }
497 +
498 + /**
499 + * Ends an Elementor tab.
500 + *
501 + * @param array $conditions Tab condition.
502 + * @param array $condition Tab condition.
503 + * @return array
504 + */
505 + public function end_tab( $conditions = [], $condition = [] ) {
506 + return [
507 + 'mode' => 'tab_end',
508 + 'conditions' => $conditions,
509 + 'condition' => $condition,
510 + ];
511 + }
512 +
513 + /**
514 + * Starts an Elementor Section Heading
515 + *
516 + * @param string $label Heading label.
517 + * @param string $separator Section separator.
518 + * @param array $conditions Section Condition.
519 + * @param array $condition Section Conditions.
520 + * @return array
521 + */
522 + public function el_heading( $label, $separator = null, $conditions = [], $condition = [] ) {
523 + return [
524 + 'type' => 'html',
525 + 'raw' => sprintf(
526 + '<h3 class="rtsb-elementor-group-heading">%s</h3>',
527 + $label
528 + ),
529 + 'separator' => $separator,
530 + 'content_classes' => 'elementor-panel-heading-title',
531 + 'conditions' => $conditions,
532 + 'condition' => $condition,
533 + ];
534 + }
535 +
536 + /**
537 + * Prints a control notification.
538 + *
539 + * @param string $label Field label.
540 + * @return string
541 + */
542 + public function is_pro_control( $label ) {
543 + if ( rtsb()->has_pro() ) {
544 + return $label;
545 + }
546 +
547 + return $label . $this->pro_label;
548 + }
549 +
550 + /**
551 + * Adds a class.
552 + *
553 + * @return string
554 + */
555 + public function pro_class() {
556 + return ! rtsb()->has_pro() ? 'rtsb-pro-field' : '';
557 + }
558 +
559 + /**
560 + * Elementor Fields.
561 + *
562 + * @param string $type Control type.
563 + *
564 + * @return string
565 + */
566 + private static function el_fields( $type ) {
567 +
568 + $controls = Controls_Manager::class;
569 +
570 + switch ( $type ) {
571 +
572 + case 'link':
573 + $type = $controls::URL;
574 + break;
575 +
576 + case 'image-dimensions':
577 + $type = $controls::IMAGE_DIMENSIONS;
578 + break;
579 +
580 + case 'html':
581 + $type = $controls::RAW_HTML;
582 + break;
583 +
584 + case 'switch':
585 + $type = $controls::SWITCHER;
586 + break;
587 +
588 + case 'rtsb-image-selector':
589 + $type = \RadiusTheme\SB\Elementor\Controls\ImageSelectorControl::$controlName;
590 + break;
591 +
592 + case 'typography':
593 + $type = Group_Control_Typography::get_type();
594 + break;
595 +
596 + case 'border':
597 + $type = Group_Control_Border::get_type();
598 + break;
599 +
600 + case 'background':
601 + $type = Group_Control_Background::get_type();
602 + break;
603 +
604 + case 'box-shadow':
605 + $type = Group_Control_Box_Shadow::get_type();
606 + break;
607 +
608 + case 'text-shadow':
609 + $type = Group_Control_Text_Shadow::get_type();
610 + break;
611 +
612 + case 'text-stroke':
613 + $type = Group_Control_Text_Stroke::get_type();
614 + break;
615 + default:
616 + $type = constant( 'Elementor\Controls_Manager::' . strtoupper( $type ) );
617 +
618 + }
619 +
620 + return $type;
621 + }
622 + /**
623 + * Elementor Fields.
624 + *
625 + * @param string $type Control type.
626 + *
627 + * @return string
628 + */
629 + private static function el_tabs( $tab ) {
630 + return constant( 'Elementor\Controls_Manager::TAB_' . strtoupper( $tab ) );
631 + }
632 +
633 +
634 +
635 +
636 +}