PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.7
Easy Elements for Elementor – Addons & Website Templates v1.3.7
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / contact-box / contact.php

contact.php in Easy Elements for Elementor – Addons & Website Templates 1.3.7, at widgets/contact-box/contact.php

699 lines 24.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Easyel\EasyElements\Widgets;
3 use Elementor\Utils;
4 use Elementor\Controls_Manager;
5 use Elementor\Responsive_Control;
6 use Elementor\Group_Control_Image_Size;
7
8 defined( 'ABSPATH' ) || die();
9 class Easyel_Contact_Box__Widget extends \Elementor\Widget_Base {
10
11
12
13 public function get_name() {
14 return 'eel-contact-box';
15 }
16
17 public function get_title() {
18 return esc_html__( 'Contact Box', 'easy-elements' );
19 }
20
21 public function get_icon() {
22 return 'easyicon easyelIcon-contact-box';
23 }
24
25 public function get_categories() {
26 return [ 'easyelements_category' ];
27 }
28
29 public function get_keywords() {
30 return [ 'contact', 'text', 'info', 'address' ];
31 }
32
33 public function get_style_depends() {
34 return [
35 'eel-contact-box',
36 ];
37 }
38
39 protected function register_controls() {
40 $this->start_controls_section(
41 '_section_logo',
42 [
43 'label' => esc_html__( 'Contact Box Settings', 'easy-elements' ),
44 'tab' => Controls_Manager::TAB_CONTENT,
45 ]
46 );
47
48
49 $this->add_control(
50 'info_type',
51 [
52 'label' => esc_html__('Select Info Type', 'easy-elements'),
53 'type' => \Elementor\Controls_Manager::SELECT,
54 'default' => 'address',
55 'options' => [
56 'address' => esc_html__('Address', 'easy-elements'),
57 'phone' => esc_html__('Phone', 'easy-elements'),
58 'email' => esc_html__('Email', 'easy-elements'),
59 'hours' => esc_html__('Hours', 'easy-elements'),
60 'website' => esc_html__('Website', 'easy-elements'),
61 ],
62 ]
63 );
64
65
66 $this->add_control(
67 'icon_box_off',
68 [
69 'label' => esc_html__('Icon Box Disable', 'easy-elements'),
70 'type' => \Elementor\Controls_Manager::SWITCHER,
71 'label_on' => esc_html__('Yes', 'easy-elements'),
72 'label_off' => esc_html__('No', 'easy-elements'),
73 'return_value' => 'yes',
74 'default' => 'yes',
75 ]
76 );
77
78 $this->add_control(
79 'icon',
80 [
81 'label' => esc_html__( 'Icon', 'easy-elements' ),
82 'type' => \Elementor\Controls_Manager::ICONS,
83 'label_block' => true,
84 'default' => [
85 'value' => 'fas fa-star',
86 'library' => 'fa-solid',
87 ],
88 'condition' => [
89 'icon_box_off' => 'yes',
90 ],
91 ]
92 );
93
94 $this->add_control(
95 'eel_title',
96 [
97 'label' => esc_html__( 'Label', 'easy-elements' ),
98 'type' => \Elementor\Controls_Manager::TEXT,
99 'default' => esc_html__( 'Headquarters', 'easy-elements' ),
100 'label_block' => true,
101 ]
102 );
103
104 $this->add_control(
105 'title_position',
106 [
107 'label' => esc_html__('Label Position', 'easy-elements'),
108 'type' => \Elementor\Controls_Manager::SELECT,
109 'default' => 'top',
110 'options' => [
111 'top' => esc_html__('Top', 'easy-elements'),
112 'bottom' => esc_html__('Bottom', 'easy-elements'),
113 ],
114 ]
115 );
116
117 $this->add_control(
118 'address',
119 [
120 'label' => esc_html__( 'Information', 'easy-elements' ),
121 'type' => \Elementor\Controls_Manager::TEXTAREA,
122 'default' => esc_html__( 'Apt 1010 Business Avenue, Toronto, Canada', 'easy-elements' ),
123 'condition' => [
124 'info_type' => 'address',
125 ],
126 ]
127 );
128
129 $this->add_control(
130 'hours',
131 [
132 'label' => esc_html__( 'Hours', 'easy-elements' ),
133 'type' => \Elementor\Controls_Manager::TEXTAREA,
134 'default' => esc_html__( 'Monday-Friday:8:30 AM - 5:30 PM', 'easy-elements' ),
135 'condition' => [
136 'info_type' => 'hours',
137 ],
138 ]
139 );
140
141 $this->add_control(
142 '_phone',
143 [
144 'label' => esc_html__( 'Phone Number 01', 'easy-elements' ),
145 'type' => \Elementor\Controls_Manager::TEXT,
146 'default' => esc_html__( '+99 254 36587', 'easy-elements' ),
147 'condition' => [
148 'info_type' => 'phone',
149 ],
150 ]
151 );
152
153 $this->add_control(
154 'phone2',
155 [
156 'label' => esc_html__( 'Phone Number 02', 'easy-elements' ),
157 'type' => \Elementor\Controls_Manager::TEXT,
158 'default' => esc_html__( '+99 254 36587', 'easy-elements' ),
159 'condition' => [
160 'info_type' => 'phone',
161 ],
162 ]
163 );
164
165 $this->add_control(
166 'email',
167 [
168 'label' => esc_html__( 'Email 01', 'easy-elements' ),
169 'type' => \Elementor\Controls_Manager::TEXT,
170 'default' => esc_html__( 'example@gmail.com', 'easy-elements' ),
171 'condition' => [
172 'info_type' => 'email',
173 ],
174 ]
175 );
176
177 $this->add_control(
178 'email2',
179 [
180 'label' => esc_html__( 'Email 02', 'easy-elements' ),
181 'type' => \Elementor\Controls_Manager::TEXT,
182 'default' => esc_html__( 'example2@gmail.com', 'easy-elements' ),
183 'condition' => [
184 'info_type' => 'email',
185 ],
186 ]
187 );
188
189 $this->add_control(
190 'website',
191 [
192 'label' => esc_html__( 'Website', 'easy-elements' ),
193 'type' => \Elementor\Controls_Manager::TEXT,
194 'default' => esc_html__( 'https://example.com', 'easy-elements' ),
195 'condition' => [
196 'info_type' => 'website',
197 ],
198 ]
199 );
200
201 $this->add_control(
202 'website_link',
203 [
204 'label' => esc_html__('Website URL', 'easy-elements'),
205 'type' => \Elementor\Controls_Manager::URL,
206 'placeholder' => 'https://example.com',
207 'show_external' => true,
208 'condition' => [
209 'info_type' => 'website',
210 ],
211 ]
212 );
213
214 $this->add_control(
215 'full_box_link',
216 [
217 'label' => esc_html__('Make Full Box Clickable', 'easy-elements'),
218 'type' => \Elementor\Controls_Manager::SWITCHER,
219 'label_on' => esc_html__('Yes', 'easy-elements'),
220 'label_off' => esc_html__('No', 'easy-elements'),
221 'return_value' => 'yes',
222 'default' => 'no',
223 'description' => esc_html__('This option will not work if you use a second phone or second email field.', 'easy-elements'),
224 ]
225 );
226
227 $this->add_control(
228 'link',
229 [
230 'label' => esc_html__('Custom Link', 'easy-elements'),
231 'type' => Controls_Manager::URL,
232 'placeholder' => 'https://example.com',
233 'description' => esc_html__('Custom link to be used for full box or manual overrides.', 'easy-elements'),
234 'condition' => [
235 'full_box_link' => 'yes',
236 'info_type' => ['address', 'hours'],
237 ],
238 ]
239 );
240
241 $this->add_control(
242 'icon_direction',
243 [
244 'label' => esc_html__( 'Direction', 'easy-elements' ),
245 'type' => \Elementor\Controls_Manager::CHOOSE,
246 'default' => 'top',
247 'options' => [
248 'left' => [
249 'title' => esc_html__( 'Left', 'easy-elements' ),
250 'icon' => 'eicon-h-align-left',
251 ],
252 'top' => [
253 'title' => esc_html__( 'Top', 'easy-elements' ),
254 'icon' => 'eicon-v-align-top',
255 ],
256 'right' => [
257 'title' => esc_html__( 'Right', 'easy-elements' ),
258 'icon' => 'eicon-h-align-right',
259 ],
260 ],
261 'toggle' => false,
262 'condition' => [
263 'icon_box_off' => 'yes',
264 ],
265 ]
266 );
267
268
269 $this->add_responsive_control(
270 '_text_align',
271 [
272 'label' => esc_html__( 'Alignment', 'easy-elements' ),
273 'type' => \Elementor\Controls_Manager::CHOOSE,
274 'options' => [
275 'left' => [
276 'title' => esc_html__( 'Left', 'easy-elements' ),
277 'icon' => 'eicon-text-align-left',
278 ],
279 'center' => [
280 'title' => esc_html__( 'Center', 'easy-elements' ),
281 'icon' => 'eicon-text-align-center',
282 ],
283 'right' => [
284 'title' => esc_html__( 'Right', 'easy-elements' ),
285 'icon' => 'eicon-text-align-right',
286 ],
287 ],
288 'default' => 'center',
289 'selectors' => [
290 '{{WRAPPER}} .ee--contact-box' => 'text-align: {{VALUE}};',
291 ],
292 ]
293 );
294
295 $this->add_control(
296 'title_tag',
297 [
298 'label' => esc_html__( 'Title HTML Tag', 'easy-elements' ),
299 'type' => \Elementor\Controls_Manager::SELECT,
300 'default' => 'h3',
301 'options' => [
302 'h1' => 'H1',
303 'h2' => 'H2',
304 'h3' => 'H3',
305 'h4' => 'H4',
306 'h5' => 'H5',
307 'h6' => 'H6',
308 'div' => 'div',
309 'span' => 'span',
310 'p' => 'p',
311 ],
312 ]
313 );
314
315 $this->end_controls_section();
316
317 $this->start_controls_section(
318 'section_style_icon',
319 [
320 'label' => esc_html__( 'Icon', 'easy-elements' ),
321 'tab' => Controls_Manager::TAB_STYLE,
322 ]
323 );
324
325 $this->add_control(
326 'icon_color',
327 [
328 'label' => esc_html__( 'Color', 'easy-elements' ),
329 'type' => Controls_Manager::COLOR,
330 'selectors' => [
331 '{{WRAPPER}} .ee--contact-box .eel-icon' => 'color: {{VALUE}};',
332 '{{WRAPPER}} .ee--contact-box .eel-icon svg' => 'fill: {{VALUE}};',
333 '{{WRAPPER}} .ee--contact-box .eel-icon svg path' => 'fill: {{VALUE}};',
334 ],
335 ]
336 );
337
338 $this->add_control(
339 'icon_bg_color',
340 [
341 'label' => esc_html__( 'Background', 'easy-elements' ),
342 'type' => Controls_Manager::COLOR,
343 'selectors' => [
344 '{{WRAPPER}} .ee--contact-box .eel-icon' => 'background-color: {{VALUE}};',
345 ],
346 ]
347 );
348
349 $this->add_group_control(
350 \Elementor\Group_Control_Typography::get_type(),
351 [
352 'name' => 'icon_typography',
353 'label' => esc_html__( 'Icon Typography', 'easy-elements' ),
354 'selector' => '{{WRAPPER}} .ee--contact-box .eel-icon',
355 ]
356 );
357
358 $this->add_group_control(
359 \Elementor\Group_Control_Border::get_type(),
360 [
361 'name' => 'icon_border',
362 'selector' => '{{WRAPPER}} .ee--contact-box .eel-icon',
363 ]
364 );
365
366 $this->add_control(
367 'icon__border_radius',
368 [
369 'label' => esc_html__( 'Border Radius', 'easy-elements' ),
370 'type' => \Elementor\Controls_Manager::DIMENSIONS,
371 'size_units' => [ 'px', '%' ],
372 'selectors' => [
373 '{{WRAPPER}} .ee--contact-box .eel-icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
374 ],
375 ]
376 );
377
378 $this->add_responsive_control(
379 'icon_margin',
380 [
381 'label' => esc_html__( 'Margin', 'easy-elements' ),
382 'type' => \Elementor\Controls_Manager::DIMENSIONS,
383 'size_units' => [ 'px', '%', 'em', 'rem' ],
384 'selectors' => [
385 '{{WRAPPER}} .ee--contact-box .eel-icon' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
386 ],
387 ]
388 );
389 $this->add_responsive_control(
390 'icon_width',
391 [
392 'label' => esc_html__('Icon Area Width', 'easy-elements'),
393 'type' => \Elementor\Controls_Manager::SLIDER,
394 'size_units' => [ 'px', '%', 'em', 'rem' ],
395 'selectors' => [
396 '{{WRAPPER}} .ee--contact-box .eel-icon' => 'min-width: {{SIZE}}{{UNIT}};',
397 ],
398 ]
399 );
400 $this->add_responsive_control(
401 'icon_height',
402 [
403 'label' => esc_html__('Icon Area Height', 'easy-elements'),
404 'type' => \Elementor\Controls_Manager::SLIDER,
405 'size_units' => [ 'px', '%', 'em', 'rem' ],
406 'selectors' => [
407 '{{WRAPPER}} .ee--contact-box .eel-icon' => 'height: {{SIZE}}{{UNIT}};',
408 ],
409 ]
410 );
411
412 $this->end_controls_section();
413
414 $this->start_controls_section(
415 'section_style_title',
416 [
417 'label' => esc_html__( 'Label', 'easy-elements' ),
418 'tab' => Controls_Manager::TAB_STYLE,
419 ]
420 );
421
422 $this->add_control(
423 'title_color',
424 [
425 'label' => esc_html__( 'Color', 'easy-elements' ),
426 'type' => Controls_Manager::COLOR,
427 'selectors' => [
428 '{{WRAPPER}} .contact-box-title' => 'color: {{VALUE}};',
429 ],
430 ]
431 );
432
433 $this->add_group_control(
434 \Elementor\Group_Control_Typography::get_type(),
435 [
436 'name' => '_title_typography',
437 'label' => esc_html__( 'Typography', 'easy-elements' ),
438 'selector' => '{{WRAPPER}} .contact-box-title',
439 ]
440 );
441
442 $this->add_responsive_control(
443 'title_margin',
444 [
445 'label' => esc_html__( 'Margin', 'easy-elements' ),
446 'type' => \Elementor\Controls_Manager::DIMENSIONS,
447 'size_units' => [ 'px', '%', 'em', 'rem' ],
448 'selectors' => [
449 '{{WRAPPER}} .ee--contact-box .contact-box-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
450 ],
451 ]
452 );
453
454 $this->end_controls_section();
455
456 $this->start_controls_section(
457 'section_style_description',
458 [
459 'label' => esc_html__( 'Information', 'easy-elements' ),
460 'tab' => Controls_Manager::TAB_STYLE,
461 ]
462 );
463
464 $this->add_control(
465 'desc_color',
466 [
467 'label' => esc_html__( 'Color', 'easy-elements' ),
468 'type' => Controls_Manager::COLOR,
469 'selectors' => [
470 '{{WRAPPER}} .contact-box-description' => 'color: {{VALUE}};',
471 ],
472 ]
473 );
474
475 $this->add_control(
476 'desc_hover_color',
477 [
478 'label' => esc_html__( 'Hover Color', 'easy-elements' ),
479 'type' => Controls_Manager::COLOR,
480 'selectors' => [
481 '{{WRAPPER}} .contact-box-description a:hover' => 'color: {{VALUE}};',
482 ],
483 ]
484 );
485
486 $this->add_group_control(
487 \Elementor\Group_Control_Typography::get_type(),
488 [
489 'name' => 'box_desc_typography',
490 'label' => esc_html__( 'Typography', 'easy-elements' ),
491 'selector' => '{{WRAPPER}} .contact-box-description',
492 ]
493 );
494
495
496 $this->end_controls_section();
497 }
498
499 protected function render() {
500 $settings = $this->get_settings_for_display();
501
502 $icon_direction = $settings['icon_direction'] ?? '';
503 $full_box_link = $settings['full_box_link'] ?? 'no';
504 $type = $settings['info_type'] ?? '';
505
506 $type_map = [
507 'phone' => ['_phone', 'phone2'],
508 'email' => ['email', 'email2'],
509 'website' => ['website'],
510 'hours' => ['hours'],
511 'address' => ['address'],
512 ];
513
514 $value = $second_value = '';
515 if (isset($type_map[$type])) {
516 $keys = $type_map[$type];
517 $value = $settings[$keys[0]] ?? '';
518 $second_value = isset($keys[1]) ? ($settings[$keys[1]] ?? '') : '';
519 }
520
521 $link = '';
522 $target = $nofollow = '';
523
524 if (in_array($type, ['phone', 'email', 'website']) && !empty($value)) {
525 if ($type === 'phone') {
526 $link = 'tel:' . $value;
527 } elseif ($type === 'email') {
528 $link = 'mailto:' . $value;
529 } elseif ($type === 'website' && !empty($settings['website_link']['url'])) {
530 $link = $settings['website_link']['url'];
531 $target = !empty($settings['website_link']['is_external']) ? ' target="_blank"' : '';
532 $nofollow = ' rel="noopener noreferrer"';
533 }
534 }
535
536 if (empty($link) && !empty($settings['link']['url'])) {
537 $link = $settings['link']['url'];
538 $target = !empty($settings['link']['is_external']) ? ' target="_blank"' : '';
539 $nofollow = !empty($settings['link']['nofollow']) ? ' rel="nofollow"' : '';
540 }
541
542 $title_tag = $settings['title_tag'] ?? 'h3';
543 $title_position = $settings['title_position'] ?? 'top';
544
545 if ($full_box_link === 'yes' && !empty($link)) :
546 echo wp_kses_post( '<a href="' . esc_url($link) . '"' . $target . $nofollow . ' class="eel-full-link-wrap">');
547 endif;
548 ?>
549
550 <div class="ee--contact-box <?php echo esc_attr($icon_direction); ?>">
551
552 <?php if (!empty($settings['icon']) && ($settings['icon_box_off'] ?? '') === 'yes') : ?>
553 <span class="eel-icon">
554 <?php \Elementor\Icons_Manager::render_icon($settings['icon'], ['aria-hidden' => 'true']); ?>
555 </span>
556 <?php endif; ?>
557
558 <?php if ($icon_direction === 'left' || $icon_direction === 'right') : ?>
559 <div class="eel-title-content-wrap">
560 <?php endif; ?>
561
562 <?php
563 if ($title_position === 'top') {
564 $this->render_title($settings['eel_title'] ?? '', $title_tag);
565 }
566 ?>
567
568 <?php if (!empty($value)) : ?>
569 <div class="contact-box-description">
570 <?php $this->render_contact_description($value, $second_value, $full_box_link, $type, $settings, $target, $nofollow); ?>
571 </div>
572 <?php endif; ?>
573
574 <?php
575 if ($title_position === 'bottom') {
576 $this->render_title($settings['eel_title'] ?? '', $title_tag);
577 }
578 ?>
579
580 <?php if ($icon_direction === 'left' || $icon_direction === 'right') : ?>
581 </div>
582 <?php endif; ?>
583
584 </div>
585
586 <?php
587 if ($full_box_link === 'yes' && !empty($link)) :
588 echo '</a>';
589 endif;
590 }
591
592 protected function render_contact_description($value, $second_value, $full_box_link, $type, $settings, $target = '', $nofollow = '') {
593 if ($full_box_link === 'yes') {
594 echo esc_html($value);
595 if (!empty($second_value)) {
596 echo '<br>' . esc_html($second_value);
597 }
598 return;
599 }
600
601 switch ( $type ) {
602 case 'phone':
603 $this->render_phone_with_text( $value );
604 if ( ! empty( $second_value ) ) {
605 echo '<br>';
606 $this->render_phone_with_text( $second_value );
607 }
608 break;
609
610 case 'email':
611 if ( is_email( $value ) ) {
612 $email1 = sprintf(
613 '<a href="mailto:%1$s">%2$s</a>',
614 antispambot( esc_attr( $value ) ),
615 esc_html( antispambot( $value ) )
616 );
617 echo wp_kses(
618 $email1,
619 [
620 'a' => [ 'href' => [] ],
621 ]
622 );
623 }
624
625 if ( ! empty( $second_value ) && is_email( $second_value ) ) {
626 $email2 = sprintf(
627 '<br><a href="mailto:%1$s">%2$s</a>',
628 antispambot( esc_attr( $second_value ) ),
629 esc_html( antispambot( $second_value ) )
630 );
631 echo wp_kses(
632 $email2,
633 [
634 'br' => [],
635 'a' => [ 'href' => [] ],
636 ]
637 );
638 }
639 break;
640
641 case 'website':
642 if ( ! empty( $settings['website_link']['url'] ) ) {
643 $href = esc_url( $settings['website_link']['url'] );
644 $target = ! empty( $settings['website_link']['is_external'] ) ? ' target="_blank"' : '';
645 $rel_attr = ' rel="' . esc_attr(
646 ! empty( $settings['website_link']['nofollow'] ) ? 'nofollow noopener noreferrer' : 'noopener noreferrer'
647 ) . '"';
648
649 $link_html = sprintf(
650 '<a href="%1$s"%2$s%3$s>%4$s</a>',
651 $href,
652 $target,
653 $rel_attr,
654 esc_html( $value )
655 );
656
657 echo wp_kses(
658 $link_html,
659 [
660 'a' => [
661 'href' => [],
662 'target' => [],
663 'rel' => [],
664 ],
665 ]
666 );
667 } else {
668 echo esc_html( $value );
669 }
670 break;
671
672 default:
673 echo wp_kses_post( $value );
674 break;
675 }
676 }
677
678 protected function render_phone_with_text($value) {
679 if (preg_match('/([+]?\d[\d\s\-().]{6,})/', $value, $matches, PREG_OFFSET_CAPTURE)) {
680 $number = trim($matches[1][0]);
681 $start = $matches[1][1];
682 $end = $start + strlen($number);
683 $before = substr($value, 0, $start);
684 $after = substr($value, $end);
685 echo esc_html($before);
686 echo '<a href="tel:' . esc_attr(preg_replace('/\D+/', '', $number)) . '">' . esc_html($number) . '</a>';
687 echo esc_html($after);
688 } else {
689 echo esc_html($value);
690 }
691 }
692
693 protected function render_title($title, $tag) {
694 if (!empty($title)) {
695 printf('<%1$s class="contact-box-title">%2$s</%1$s>', esc_attr($tag), esc_html($title));
696 }
697 }
698
699 }