PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.1.2
ShopBuilder – WooCommerce Builder For Elementor v1.1.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 / Abstracts / ElementorWidgetBase.php

ElementorWidgetBase.php in ShopBuilder – WooCommerce Builder For Elementor 1.1.2, at app/Abstracts/ElementorWidgetBase.php

645 lines 15.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 after pro version released.
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 $the_widget = $this->widget_fields();
234 if( ! is_array( $the_widget ) ){
235 return ;
236 }
237 $fields = array_merge( $the_widget, $this->promo_content() );
238
239 $fields = apply_filters( 'rtsb/elements/elementor/widgets/controls/' . $this->rtsb_base, $fields, $this );
240
241 foreach ( $fields as $id => $field ) {
242 $field['classes'] = ! empty( $field['classes'] ) ? $field['classes'] . ' elementor-control-rtsb_el' : ' elementor-control-rtsb_el';
243 $field['separator'] = ! empty( $field['separator'] ) ? $field['separator'] : 'before-short';
244
245 if ( ! empty( $field['type'] ) ) {
246 $field['type'] = self::el_fields( $field['type'] );
247 }
248
249 if ( ! empty( $field['tab'] ) ) {
250 $field['tab'] = self::el_tabs( $field['tab'] );
251 }
252
253 if ( isset( $field['mode'] ) && 'section_start' === $field['mode'] ) {
254 unset( $field['mode'] );
255 unset( $field['separator'] );
256
257 $this->start_controls_section( $id, $field );
258 } elseif ( isset( $field['mode'] ) && 'section_end' === $field['mode'] ) {
259 $this->end_controls_section();
260 } elseif ( isset( $field['mode'] ) && 'tabs_start' === $field['mode'] ) {
261 unset( $field['mode'] );
262 unset( $field['separator'] );
263
264 $this->start_controls_tabs( $id );
265 } elseif ( isset( $field['mode'] ) && 'tabs_end' === $field['mode'] ) {
266 $this->end_controls_tabs();
267 } elseif ( isset( $field['mode'] ) && 'tab_start' === $field['mode'] ) {
268 unset( $field['mode'] );
269 unset( $field['separator'] );
270
271 $this->start_controls_tab( $id, $field );
272 } elseif ( isset( $field['mode'] ) && 'tab_end' === $field['mode'] ) {
273 $this->end_controls_tab();
274 } elseif ( isset( $field['mode'] ) && 'group' === $field['mode'] ) {
275 $type = $field['type'];
276 $field['name'] = $id;
277 unset( $field['mode'] );
278 unset( $field['type'] );
279 $this->add_group_control( $type, $field );
280 } elseif ( isset( $field['mode'] ) && 'responsive' === $field['mode'] ) {
281 unset( $field['mode'] );
282
283 $this->add_responsive_control( $id, $field );
284 } elseif ( isset( $field['mode'] ) && 'repeater' === $field['mode'] ) {
285 $repeater = new Repeater();
286 $repeater_fields = $field['fields'];
287
288 foreach ( $repeater_fields as $rf_id => $value ) {
289 $repeater->add_control( $rf_id, $value );
290 }
291
292 $field['fields'] = $repeater->get_controls();
293
294 $this->add_control( $id, $field );
295 } else {
296 $this->add_control( $id, $field );
297 }
298 }
299
300 do_action( 'rtsb/after/register/controls' );
301 }
302
303 /**
304 * Elementor Edit mode.
305 *
306 * @return mixed
307 */
308 public function is_edit_mode() {
309 return Plugin::$instance->preview->is_preview_mode() || Plugin::$instance->editor->is_edit_mode();
310 }
311
312 /**
313 * Elementor Edit preview.
314 *
315 * @return mixed
316 */
317 public function is_builder_mode() {
318 return BuilderFns::is_builder_preview() || $this->is_edit_mode();
319 }
320
321 /**
322 * Elementor Edit mode need some extra js for isotop reinitialize
323 *
324 * @return void
325 */
326 public function editor_slider_script() {
327 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
328 $selector = $this->get_unique_selector() . ' .rtsb-carousel-slider';
329 ?>
330 <script>
331 jQuery('<?php echo esc_attr( $selector ); ?>').rtsb_slider();
332 </script>
333 <?php
334 }
335 }
336 /**
337 * Elementor Edit mode need some extra js for isotop reinitialize
338 *
339 * @return void
340 */
341 public function editor_cart_icon_script() {
342 if ( $this->is_edit_mode() ) {
343 $selector = $this->get_unique_selector() . ' .has-cart-button';
344 ?>
345 <script type="text/javascript">
346 // Product Archive Catelog
347 (function ($) {
348 var cartWrpper = $('<?php echo esc_attr( $selector ); ?>');
349 var cartIcon = cartWrpper.attr('data-cart-icon');
350 var cartButton = cartWrpper.find(
351 '.product_type_grouped, .add_to_cart_button, .single_add_to_cart_button '
352 );
353 if( cartIcon ) {
354 cartButton.find('i').remove();
355 cartButton.prepend(cartIcon);
356 }
357 })(jQuery);
358 </script>
359 <?php
360 }
361 }
362
363 /**
364 * Elementor Edit mode script
365 *
366 * @return void
367 */
368 public function edit_mode_script() {
369 if ( ! $this->is_edit_mode() ) {
370 return;
371 }
372 $ajaxurl = admin_url( 'admin-ajax.php' );
373 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
374 $ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
375 }
376 ?>
377 <script>
378 var rtsb = {
379 ajaxurl: '<?php echo esc_url( $ajaxurl ); ?>',
380 nonce : '<?php echo esc_attr( wp_create_nonce( rtsb()->nonceId ) ); ?>',
381 is_pro : '<?php echo esc_attr( rtsb()->has_pro() ? 'true' : 'false' ); ?>'
382 };
383 rtsbElFrontend();
384 </script>
385
386 <?php
387 }
388
389 /**
390 * Starts an Elementor Section
391 *
392 * @param string $label Section label.
393 * @param object $tab Tab ID.
394 * @param array $conditions Section Condition.
395 * @param array $condition Section Conditions.
396 * @return array
397 */
398 public function start_section( $label, $tab, $conditions = [], $condition = [] ) {
399 $start = [
400 'mode' => 'section_start',
401 'tab' => $tab,
402 'label' => $label
403 ];
404 if( ! empty( $condition ) ){
405 $start['condition'] = $condition;
406 }
407 if( ! empty( $conditions ) ){
408 $start['conditions'] = $conditions;
409 }
410 return $start;
411 }
412
413 /**
414 * Ends an Elementor Section
415 *
416 * @return array
417 */
418 public function end_section() {
419 return [
420 'mode' => 'section_end',
421 ];
422 }
423
424 /**
425 * Theme Support for render/widget_controls
426 *
427 * @param string $support Support for render/widget_controls.
428 * @return void
429 */
430 public function theme_support( $support = 'render' ) {
431
432 if ( empty( $support ) ) {
433 return;
434 }
435 $theme = ucwords( str_replace( [ '_', '-', ' ' ], '', rtsb()->current_theme ) );
436
437 $supportClass = apply_filters(
438 'radiustheme/sb/widgetsupport/class',
439 [
440 'ShopbuilderPlugin' => 'RadiusTheme\SB\Controllers\ThemesSupport\\' . $theme . '\\WidgetsSupport',
441 'TheTheme' => \WidgetSupport::class,
442 ]
443 );
444
445 foreach ( $supportClass as $key => $theClass ) {
446 $themeWidgetSupport = get_theme_file_path( '/shopbuilder/WidgetSupport.php' );
447 if ( 'TheTheme' === $key && file_exists( $themeWidgetSupport ) ) {
448 require_once $themeWidgetSupport;
449 }
450 if ( class_exists( $theClass ) ) {
451 $method = $support . '_' . str_replace( [ '-', ' ' ], '_', $this->rtsb_base );
452 if ( method_exists( $theClass, $method ) ) {
453 $theClass::instance( $this )->$method();
454 }
455 }
456 }
457 }
458
459 /**
460 * Starts an Elementor tab group.
461 *
462 * @param array $conditions Tab condition.
463 * @param array $condition Tab condition.
464 * @return array
465 */
466 public function start_tab_group( $conditions = [], $condition = [] ) {
467 return [
468 'mode' => 'tabs_start',
469 'conditions' => $conditions,
470 'condition' => $condition,
471 ];
472 }
473
474 /**
475 * Ends an Elementor tab group.
476 *
477 * @param array $conditions Tab condition.
478 * @param array $condition Tab condition.
479 * @return array
480 */
481 public function end_tab_group( $conditions = [], $condition = [] ) {
482 return [
483 'mode' => 'tabs_end',
484 'conditions' => $conditions,
485 'condition' => $condition,
486 ];
487 }
488
489 /**
490 * Starts an Elementor tab
491 *
492 * @param string $label Section label.
493 * @param array $conditions Tab condition.
494 * @param array $condition Tab condition.
495 * @return array
496 */
497 public function start_tab( $label, $conditions = [], $condition = [] ) {
498 return [
499 'mode' => 'tab_start',
500 'label' => $label,
501 'conditions' => $conditions,
502 'condition' => $condition,
503 ];
504 }
505
506 /**
507 * Ends an Elementor tab.
508 *
509 * @param array $conditions Tab condition.
510 * @param array $condition Tab condition.
511 * @return array
512 */
513 public function end_tab( $conditions = [], $condition = [] ) {
514 return [
515 'mode' => 'tab_end',
516 'conditions' => $conditions,
517 'condition' => $condition,
518 ];
519 }
520
521 /**
522 * Starts an Elementor Section Heading
523 *
524 * @param string $label Heading label.
525 * @param string $separator Section separator.
526 * @param array $conditions Section Condition.
527 * @param array $condition Section Conditions.
528 * @return array
529 */
530 public function el_heading( $label, $separator = null, $conditions = [], $condition = [] ) {
531 return [
532 'type' => 'html',
533 'raw' => sprintf(
534 '<h3 class="rtsb-elementor-group-heading">%s</h3>',
535 $label
536 ),
537 'separator' => $separator,
538 'content_classes' => 'elementor-panel-heading-title',
539 'conditions' => $conditions,
540 'condition' => $condition,
541 ];
542 }
543
544 /**
545 * Prints a control notification.
546 *
547 * @param string $label Field label.
548 * @return string
549 */
550 public function is_pro_control( $label ) {
551 if ( rtsb()->has_pro() ) {
552 return $label;
553 }
554
555 return $label . $this->pro_label;
556 }
557
558 /**
559 * Adds a class.
560 *
561 * @return string
562 */
563 public function pro_class() {
564 return ! rtsb()->has_pro() ? 'rtsb-pro-field' : '';
565 }
566
567 /**
568 * Elementor Fields.
569 *
570 * @param string $type Control type.
571 *
572 * @return string
573 */
574 private static function el_fields( $type ) {
575
576 $controls = Controls_Manager::class;
577
578 switch ( $type ) {
579
580 case 'link':
581 $type = $controls::URL;
582 break;
583
584 case 'image-dimensions':
585 $type = $controls::IMAGE_DIMENSIONS;
586 break;
587
588 case 'html':
589 $type = $controls::RAW_HTML;
590 break;
591
592 case 'switch':
593 $type = $controls::SWITCHER;
594 break;
595
596 case 'rtsb-image-selector':
597 $type = \RadiusTheme\SB\Elementor\Controls\ImageSelectorControl::$controlName;
598 break;
599
600 case 'typography':
601 $type = Group_Control_Typography::get_type();
602 break;
603
604 case 'border':
605 $type = Group_Control_Border::get_type();
606 break;
607
608 case 'background':
609 $type = Group_Control_Background::get_type();
610 break;
611
612 case 'box-shadow':
613 $type = Group_Control_Box_Shadow::get_type();
614 break;
615
616 case 'text-shadow':
617 $type = Group_Control_Text_Shadow::get_type();
618 break;
619
620 case 'text-stroke':
621 $type = Group_Control_Text_Stroke::get_type();
622 break;
623 default:
624 $type = constant( 'Elementor\Controls_Manager::' . strtoupper( $type ) );
625
626 }
627
628 return $type;
629 }
630 /**
631 * Elementor Fields.
632 *
633 * @param string $type Control type.
634 *
635 * @return string
636 */
637 private static function el_tabs( $tab ) {
638 return constant( 'Elementor\Controls_Manager::TAB_' . strtoupper( $tab ) );
639 }
640
641
642
643
644 }
645