1: <?php
2: /**
3: * Elementor Agent Box Widget
4: *
5: * @package EPL
6: * @subpackage PageBuilders/Elementor/Widgets/Elements
7: * @since 3.6.0
8: */
9:
10: // Exit if accessed directly.
11: if ( ! defined( 'ABSPATH' ) ) {
12: exit;
13: }
14:
15: /**
16: * EPL_Elementor_Agent_Box Class
17: *
18: * Displays the listing agent/author information.
19: *
20: * @since 3.6.0
21: */
22: class EPL_Elementor_Agent_Box extends \Elementor\Widget_Base {
23: use EPL_Elementor_Dynamic_Widget;
24:
25: /**
26: * Get widget name.
27: *
28: * @return string
29: * @since 3.6.0 New: Elementor widgets (beta).
30: */
31: public function get_name() {
32: return 'epl-agent-box';
33: }
34:
35: /**
36: * Get widget title.
37: *
38: * @return string
39: * @since 3.6.0 New: Elementor widgets (beta).
40: */
41: public function get_title() {
42: return esc_html__( 'Author Box', 'easy-property-listings' );
43: }
44:
45: /**
46: * Get widget icon.
47: *
48: * @return string
49: * @since 3.6.0 New: Elementor widgets (beta).
50: */
51: public function get_icon() {
52: return 'eicon-person';
53: }
54:
55: /**
56: * Get widget categories.
57: *
58: * @return array
59: * @since 3.6.0 New: Elementor widgets (beta).
60: */
61: public function get_categories() {
62: return array( 'epl-staff', 'epl-author' );
63: }
64:
65: /**
66: * Get widget keywords.
67: *
68: * @return array
69: * @since 3.6.0 New: Elementor widgets (beta).
70: */
71: public function get_keywords() {
72: return array( 'property', 'agent', 'author', 'realtor', 'epl' );
73: }
74:
75: /**
76: * Register widget controls.
77: * @since 3.6.0 New: Elementor widgets (beta).
78: */
79: protected function register_controls() {
80:
81: // Content Section - Layout.
82: $this->start_controls_section(
83: 'section_layout',
84: array(
85: 'label' => esc_html__( 'Layout', 'easy-property-listings' ),
86: 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
87: )
88: );
89:
90: $this->add_control(
91: 'layout',
92: array(
93: 'label' => esc_html__( 'Layout', 'easy-property-listings' ),
94: 'type' => \Elementor\Controls_Manager::SELECT,
95: 'options' => array(
96: 'vertical' => esc_html__( 'Vertical (Stacked)', 'easy-property-listings' ),
97: 'horizontal' => esc_html__( 'Horizontal (Side by Side)', 'easy-property-listings' ),
98: ),
99: 'default' => 'vertical',
100: )
101: );
102:
103: $this->end_controls_section();
104:
105: // Content Section - Elements.
106: $this->start_controls_section(
107: 'section_elements',
108: array(
109: 'label' => esc_html__( 'Elements', 'easy-property-listings' ),
110: 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
111: )
112: );
113:
114: $this->add_control(
115: 'show_photo',
116: array(
117: 'label' => esc_html__( 'Show Photo', 'easy-property-listings' ),
118: 'type' => \Elementor\Controls_Manager::SWITCHER,
119: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
120: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
121: 'return_value' => 'yes',
122: 'default' => 'yes',
123: )
124: );
125:
126: $this->add_control(
127: 'photo_size',
128: array(
129: 'label' => esc_html__( 'Photo Size', 'easy-property-listings' ),
130: 'type' => \Elementor\Controls_Manager::SLIDER,
131: 'range' => array(
132: 'px' => array(
133: 'min' => 50,
134: 'max' => 300,
135: ),
136: ),
137: 'default' => array(
138: 'size' => 150,
139: 'unit' => 'px',
140: ),
141: 'condition' => array(
142: 'show_photo' => 'yes',
143: ),
144: )
145: );
146:
147: $this->add_control(
148: 'show_name',
149: array(
150: 'label' => esc_html__( 'Show Name', 'easy-property-listings' ),
151: 'type' => \Elementor\Controls_Manager::SWITCHER,
152: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
153: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
154: 'return_value' => 'yes',
155: 'default' => 'yes',
156: )
157: );
158:
159: $this->add_control(
160: 'link_name',
161: array(
162: 'label' => esc_html__( 'Link Name to Author Page', 'easy-property-listings' ),
163: 'type' => \Elementor\Controls_Manager::SWITCHER,
164: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
165: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
166: 'return_value' => 'yes',
167: 'default' => 'yes',
168: 'condition' => array(
169: 'show_name' => 'yes',
170: ),
171: )
172: );
173:
174: $this->add_control(
175: 'show_position',
176: array(
177: 'label' => esc_html__( 'Show Position/Title', 'easy-property-listings' ),
178: 'type' => \Elementor\Controls_Manager::SWITCHER,
179: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
180: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
181: 'return_value' => 'yes',
182: 'default' => 'yes',
183: )
184: );
185:
186: $this->add_control(
187: 'show_mobile',
188: array(
189: 'label' => esc_html__( 'Show Mobile', 'easy-property-listings' ),
190: 'type' => \Elementor\Controls_Manager::SWITCHER,
191: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
192: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
193: 'return_value' => 'yes',
194: 'default' => 'yes',
195: )
196: );
197:
198: $this->add_control(
199: 'show_office_phone',
200: array(
201: 'label' => esc_html__( 'Show Office Phone', 'easy-property-listings' ),
202: 'type' => \Elementor\Controls_Manager::SWITCHER,
203: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
204: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
205: 'return_value' => 'yes',
206: 'default' => '',
207: )
208: );
209:
210: $this->add_control(
211: 'show_email',
212: array(
213: 'label' => esc_html__( 'Show Email', 'easy-property-listings' ),
214: 'type' => \Elementor\Controls_Manager::SWITCHER,
215: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
216: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
217: 'return_value' => 'yes',
218: 'default' => 'yes',
219: )
220: );
221:
222: $this->add_control(
223: 'show_social_icons',
224: array(
225: 'label' => esc_html__( 'Show Social Icons', 'easy-property-listings' ),
226: 'type' => \Elementor\Controls_Manager::SWITCHER,
227: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
228: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
229: 'return_value' => 'yes',
230: 'default' => 'yes',
231: )
232: );
233:
234: $this->add_control(
235: 'show_bio',
236: array(
237: 'label' => esc_html__( 'Show Bio', 'easy-property-listings' ),
238: 'type' => \Elementor\Controls_Manager::SWITCHER,
239: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
240: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
241: 'return_value' => 'yes',
242: 'default' => '',
243: )
244: );
245:
246: $this->end_controls_section();
247:
248: // Style Section - Container.
249: $this->start_controls_section(
250: 'section_style_container',
251: array(
252: 'label' => esc_html__( 'Container', 'easy-property-listings' ),
253: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
254: )
255: );
256:
257: $this->add_control(
258: 'container_bg_color',
259: array(
260: 'label' => esc_html__( 'Background Color', 'easy-property-listings' ),
261: 'type' => \Elementor\Controls_Manager::COLOR,
262: 'selectors' => array(
263: '{{WRAPPER}} .epl-agent-box' => 'background-color: {{VALUE}};',
264: ),
265: )
266: );
267:
268: $this->add_responsive_control(
269: 'container_padding',
270: array(
271: 'label' => esc_html__( 'Padding', 'easy-property-listings' ),
272: 'type' => \Elementor\Controls_Manager::DIMENSIONS,
273: 'size_units' => array( 'px', 'em' ),
274: 'selectors' => array(
275: '{{WRAPPER}} .epl-agent-box' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
276: ),
277: )
278: );
279:
280: $this->add_group_control(
281: \Elementor\Group_Control_Border::get_type(),
282: array(
283: 'name' => 'container_border',
284: 'selector' => '{{WRAPPER}} .epl-agent-box',
285: )
286: );
287:
288: $this->add_responsive_control(
289: 'container_border_radius',
290: array(
291: 'label' => esc_html__( 'Border Radius', 'easy-property-listings' ),
292: 'type' => \Elementor\Controls_Manager::DIMENSIONS,
293: 'size_units' => array( 'px', '%' ),
294: 'selectors' => array(
295: '{{WRAPPER}} .epl-agent-box' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
296: ),
297: )
298: );
299:
300: $this->add_group_control(
301: \Elementor\Group_Control_Box_Shadow::get_type(),
302: array(
303: 'name' => 'container_box_shadow',
304: 'selector' => '{{WRAPPER}} .epl-agent-box',
305: )
306: );
307:
308: $this->end_controls_section();
309:
310: // Style Section - Photo.
311: $this->start_controls_section(
312: 'section_style_photo',
313: array(
314: 'label' => esc_html__( 'Photo', 'easy-property-listings' ),
315: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
316: 'condition' => array(
317: 'show_photo' => 'yes',
318: ),
319: )
320: );
321:
322: $this->add_responsive_control(
323: 'photo_border_radius',
324: array(
325: 'label' => esc_html__( 'Border Radius', 'easy-property-listings' ),
326: 'type' => \Elementor\Controls_Manager::DIMENSIONS,
327: 'size_units' => array( 'px', '%' ),
328: 'default' => array(
329: 'top' => '50',
330: 'right' => '50',
331: 'bottom' => '50',
332: 'left' => '50',
333: 'unit' => '%',
334: ),
335: 'selectors' => array(
336: '{{WRAPPER}} .epl-agent-photo img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
337: ),
338: )
339: );
340:
341: $this->add_group_control(
342: \Elementor\Group_Control_Border::get_type(),
343: array(
344: 'name' => 'photo_border',
345: 'selector' => '{{WRAPPER}} .epl-agent-photo img',
346: )
347: );
348:
349: $this->end_controls_section();
350:
351: // Style Section - Name.
352: $this->start_controls_section(
353: 'section_style_name',
354: array(
355: 'label' => esc_html__( 'Name', 'easy-property-listings' ),
356: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
357: 'condition' => array(
358: 'show_name' => 'yes',
359: ),
360: )
361: );
362:
363: $this->add_control(
364: 'name_color',
365: array(
366: 'label' => esc_html__( 'Color', 'easy-property-listings' ),
367: 'type' => \Elementor\Controls_Manager::COLOR,
368: 'selectors' => array(
369: '{{WRAPPER}} .epl-agent-name' => 'color: {{VALUE}};',
370: '{{WRAPPER}} .epl-agent-name a' => 'color: {{VALUE}};',
371: ),
372: )
373: );
374:
375: $this->add_group_control(
376: \Elementor\Group_Control_Typography::get_type(),
377: array(
378: 'name' => 'name_typography',
379: 'selector' => '{{WRAPPER}} .epl-agent-name',
380: )
381: );
382:
383: $this->add_responsive_control(
384: 'name_spacing',
385: array(
386: 'label' => esc_html__( 'Spacing', 'easy-property-listings' ),
387: 'type' => \Elementor\Controls_Manager::SLIDER,
388: 'size_units' => array( 'px' ),
389: 'range' => array(
390: 'px' => array(
391: 'min' => 0,
392: 'max' => 50,
393: ),
394: ),
395: 'selectors' => array(
396: '{{WRAPPER}} .epl-agent-name' => 'margin-bottom: {{SIZE}}{{UNIT}};',
397: ),
398: )
399: );
400:
401: $this->end_controls_section();
402:
403: // Style Section - Contact Info.
404: $this->start_controls_section(
405: 'section_style_contact',
406: array(
407: 'label' => esc_html__( 'Contact Info', 'easy-property-listings' ),
408: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
409: )
410: );
411:
412: $this->add_control(
413: 'contact_color',
414: array(
415: 'label' => esc_html__( 'Color', 'easy-property-listings' ),
416: 'type' => \Elementor\Controls_Manager::COLOR,
417: 'selectors' => array(
418: '{{WRAPPER}} .epl-agent-contact' => 'color: {{VALUE}};',
419: '{{WRAPPER}} .epl-agent-contact a' => 'color: {{VALUE}};',
420: ),
421: )
422: );
423:
424: $this->add_group_control(
425: \Elementor\Group_Control_Typography::get_type(),
426: array(
427: 'name' => 'contact_typography',
428: 'selector' => '{{WRAPPER}} .epl-agent-contact',
429: )
430: );
431:
432: $this->end_controls_section();
433:
434: // Style Section - Social Icons.
435: $this->start_controls_section(
436: 'section_style_social',
437: array(
438: 'label' => esc_html__( 'Social Icons', 'easy-property-listings' ),
439: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
440: 'condition' => array(
441: 'show_social_icons' => 'yes',
442: ),
443: )
444: );
445:
446: $this->add_control(
447: 'social_icon_color',
448: array(
449: 'label' => esc_html__( 'Icon Color', 'easy-property-listings' ),
450: 'type' => \Elementor\Controls_Manager::COLOR,
451: 'selectors' => array(
452: '{{WRAPPER}} .epl-agent-social a' => 'color: {{VALUE}};',
453: ),
454: )
455: );
456:
457: $this->add_responsive_control(
458: 'social_icon_size',
459: array(
460: 'label' => esc_html__( 'Icon Size', 'easy-property-listings' ),
461: 'type' => \Elementor\Controls_Manager::SLIDER,
462: 'size_units' => array( 'px' ),
463: 'range' => array(
464: 'px' => array(
465: 'min' => 10,
466: 'max' => 50,
467: ),
468: ),
469: 'selectors' => array(
470: '{{WRAPPER}} .epl-agent-social a' => 'font-size: {{SIZE}}{{UNIT}};',
471: ),
472: )
473: );
474:
475: $this->add_responsive_control(
476: 'social_icon_gap',
477: array(
478: 'label' => esc_html__( 'Gap Between Icons', 'easy-property-listings' ),
479: 'type' => \Elementor\Controls_Manager::SLIDER,
480: 'size_units' => array( 'px' ),
481: 'range' => array(
482: 'px' => array(
483: 'min' => 0,
484: 'max' => 30,
485: ),
486: ),
487: 'selectors' => array(
488: '{{WRAPPER}} .epl-agent-social' => 'gap: {{SIZE}}{{UNIT}};',
489: ),
490: )
491: );
492:
493: $this->end_controls_section();
494:
495: // Style Section - Bio.
496: $this->start_controls_section(
497: 'section_style_bio',
498: array(
499: 'label' => esc_html__( 'Bio', 'easy-property-listings' ),
500: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
501: 'condition' => array(
502: 'show_bio' => 'yes',
503: ),
504: )
505: );
506:
507: $this->add_control(
508: 'bio_color',
509: array(
510: 'label' => esc_html__( 'Color', 'easy-property-listings' ),
511: 'type' => \Elementor\Controls_Manager::COLOR,
512: 'selectors' => array(
513: '{{WRAPPER}} .epl-agent-bio' => 'color: {{VALUE}};',
514: ),
515: )
516: );
517:
518: $this->add_group_control(
519: \Elementor\Group_Control_Typography::get_type(),
520: array(
521: 'name' => 'bio_typography',
522: 'selector' => '{{WRAPPER}} .epl-agent-bio',
523: )
524: );
525:
526: $this->end_controls_section();
527: }
528:
529: /**
530: * Render widget output.
531: * @since 3.6.0 New: Elementor widgets (beta).
532: */
533: protected function render() {
534: $property = EPL_Elementor::setup_listing_context();
535: $is_editor = \Elementor\Plugin::$instance->editor->is_edit_mode();
536:
537: if ( ! $property ) {
538: if ( $is_editor ) {
539: echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Agent Box - No listings found.', 'easy-property-listings' ) . '</div>';
540: }
541: EPL_Elementor::restore_listing_context();
542: return;
543: }
544:
545: $settings = $this->get_settings_for_display();
546:
547: // Always resolve against this listing. Elementor nested loops can leave
548: // the core global author pointing at the previous loop item.
549: $agent = EPL_Elementor::get_listing_agent( $property );
550:
551: if ( ! $agent ) {
552: EPL_Elementor::restore_listing_context();
553: return;
554: }
555:
556: $author_id = $agent->author_id;
557:
558: $layout_class = 'horizontal' === $settings['layout'] ? 'epl-agent-horizontal' : 'epl-agent-vertical';
559:
560: echo '<div class="epl-agent-box ' . esc_attr( $layout_class ) . '">';
561:
562: if ( 'yes' === $settings['show_photo'] ) {
563: $photo_size = isset( $settings['photo_size']['size'] ) ? intval( $settings['photo_size']['size'] ) : 150;
564: echo '<div class="epl-agent-photo">';
565: echo wp_kses_post( EPL_Elementor::get_agent_image( $agent, $photo_size ) );
566: echo '</div>';
567: }
568:
569: echo '<div class="epl-agent-details">';
570:
571: // Name.
572: if ( 'yes' === $settings['show_name'] ) {
573: $display_name = $agent->get_author_name();
574: echo '<div class="epl-agent-name">';
575: if ( 'yes' === $settings['link_name'] ) {
576: $permalink = apply_filters( 'epl_author_profile_link', get_author_posts_url( $author_id ), $agent );
577: echo '<a href="' . esc_url( $permalink ) . '">' . esc_html( $display_name ) . '</a>';
578: } else {
579: echo esc_html( $display_name );
580: }
581: echo '</div>';
582: }
583:
584: // Position.
585: if ( 'yes' === $settings['show_position'] ) {
586: $position = $agent->get_author_position();
587: if ( ! empty( $position ) ) {
588: echo '<div class="epl-agent-position">' . esc_html( $position ) . '</div>';
589: }
590: }
591:
592: // Contact Info.
593: echo '<div class="epl-agent-contact">';
594:
595: // Mobile.
596: if ( 'yes' === $settings['show_mobile'] ) {
597: $mobile = $agent->get_author_mobile();
598: if ( ! empty( $mobile ) ) {
599: echo '<div class="epl-agent-mobile">';
600: echo '<span class="epl-agent-label">' . esc_html__( 'Mobile:', 'easy-property-listings' ) . '</span> ';
601: echo '<a href="tel:' . esc_attr( $mobile ) . '">' . esc_html( $mobile ) . '</a>';
602: echo '</div>';
603: }
604: }
605:
606: // Office Phone.
607: if ( 'yes' === $settings['show_office_phone'] ) {
608: $office_phone = $agent->get_author_office_phone();
609: if ( ! empty( $office_phone ) ) {
610: echo '<div class="epl-agent-office-phone">';
611: echo '<span class="epl-agent-label">' . esc_html__( 'Office:', 'easy-property-listings' ) . '</span> ';
612: echo '<a href="tel:' . esc_attr( $office_phone ) . '">' . esc_html( $office_phone ) . '</a>';
613: echo '</div>';
614: }
615: }
616:
617: // Email.
618: if ( 'yes' === $settings['show_email'] ) {
619: $email = $agent->email;
620: if ( ! empty( $email ) ) {
621: echo '<div class="epl-agent-email">';
622: echo '<span class="epl-agent-label">' . esc_html__( 'Email:', 'easy-property-listings' ) . '</span> ';
623: echo '<a href="mailto:' . esc_attr( $email ) . '">' . esc_html( $email ) . '</a>';
624: echo '</div>';
625: }
626: }
627:
628: echo '</div>'; // End contact.
629:
630: // Social Icons.
631: if ( 'yes' === $settings['show_social_icons'] ) {
632: $social_icons = array( 'facebook', 'twitter', 'instagram', 'linkedin', 'youtube', 'pinterest' );
633:
634: // The loader proxies methods via __call, which method_exists() cannot
635: // see — check against the wrapped author object instead.
636: $author_object = $agent instanceof EPL_Author_Loader ? $agent->object : $agent;
637:
638: $social_html = '';
639: foreach ( $social_icons as $social ) {
640: $method = 'get_' . $social . '_html';
641: if ( $author_object && is_callable( array( $author_object, $method ) ) ) {
642: $social_html .= (string) call_user_func( array( $author_object, $method ) );
643: }
644: }
645:
646: if ( '' !== trim( $social_html ) ) {
647: echo '<div class="epl-agent-social">' . wp_kses_post( $social_html ) . '</div>';
648: }
649: }
650:
651: // Bio.
652: if ( 'yes' === $settings['show_bio'] ) {
653: $bio = $agent->get_description_html();
654: if ( ! empty( $bio ) ) {
655: echo '<div class="epl-agent-bio">' . wp_kses_post( $bio ) . '</div>';
656: }
657: }
658:
659: echo '</div>'; // End details.
660: echo '</div>'; // End agent-box.
661:
662: EPL_Elementor::restore_listing_context();
663: }
664: }
665: