PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.2.1
Easy Elements for Elementor – Addons & Website Templates v1.2.1
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.2.1, at widgets/contact-box/contact.php

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