1: <?php
2: /**
3: * Elementor Agent Contact 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_Contact Class
17: *
18: * Displays agent contact info (mobile, office phone, email).
19: * Reads from $epl_current_agent context.
20: *
21: * @since 3.6.0
22: */
23: class EPL_Elementor_Agent_Contact extends \Elementor\Widget_Base {
24: use EPL_Elementor_Dynamic_Widget;
25:
26: /**
27: * Get widget name.
28: * @since 3.6.0 New: Elementor widgets (beta).
29: */
30: public function get_name() {
31: return 'epl-agent-contact';
32: }
33:
34: /**
35: * Get widget title.
36: * @since 3.6.0 New: Elementor widgets (beta).
37: */
38: public function get_title() {
39: return esc_html__( 'Contact', 'easy-property-listings' );
40: }
41:
42: /**
43: * Get widget icon.
44: * @since 3.6.0 New: Elementor widgets (beta).
45: */
46: public function get_icon() {
47: return 'eicon-tel-field';
48: }
49:
50: /**
51: * Get widget categories.
52: * @since 3.6.0 New: Elementor widgets (beta).
53: */
54: public function get_categories() {
55: return array( 'epl-staff', 'epl-author' );
56: }
57:
58: /**
59: * Get widget keywords.
60: * @since 3.6.0 New: Elementor widgets (beta).
61: */
62: public function get_keywords() {
63: return array( 'agent', 'contact', 'phone', 'mobile', 'email', 'epl' );
64: }
65:
66: /**
67: * Register widget controls.
68: * @since 3.6.0 New: Elementor widgets (beta).
69: */
70: protected function register_controls() {
71:
72: $this->start_controls_section(
73: 'section_content',
74: array(
75: 'label' => esc_html__( 'Content', 'easy-property-listings' ),
76: 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
77: )
78: );
79:
80: $this->add_control(
81: 'show_mobile',
82: array(
83: 'label' => esc_html__( 'Show Mobile', 'easy-property-listings' ),
84: 'type' => \Elementor\Controls_Manager::SWITCHER,
85: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
86: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
87: 'return_value' => 'yes',
88: 'default' => 'yes',
89: )
90: );
91:
92: $this->add_control(
93: 'show_office_phone',
94: array(
95: 'label' => esc_html__( 'Show Office Phone', 'easy-property-listings' ),
96: 'type' => \Elementor\Controls_Manager::SWITCHER,
97: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
98: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
99: 'return_value' => 'yes',
100: 'default' => '',
101: )
102: );
103:
104: $this->add_control(
105: 'show_email',
106: array(
107: 'label' => esc_html__( 'Show Email', 'easy-property-listings' ),
108: 'type' => \Elementor\Controls_Manager::SWITCHER,
109: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
110: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
111: 'return_value' => 'yes',
112: 'default' => 'yes',
113: )
114: );
115:
116: $this->add_control(
117: 'show_labels',
118: array(
119: 'label' => esc_html__( 'Show Labels', 'easy-property-listings' ),
120: 'type' => \Elementor\Controls_Manager::SWITCHER,
121: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
122: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
123: 'return_value' => 'yes',
124: 'default' => 'yes',
125: )
126: );
127:
128: $this->add_control(
129: 'show_icons',
130: array(
131: 'label' => esc_html__( 'Show Icons', 'easy-property-listings' ),
132: 'type' => \Elementor\Controls_Manager::SWITCHER,
133: 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ),
134: 'label_off' => esc_html__( 'No', 'easy-property-listings' ),
135: 'return_value' => 'yes',
136: 'default' => '',
137: )
138: );
139:
140: $this->add_control(
141: 'layout',
142: array(
143: 'label' => esc_html__( 'Layout', 'easy-property-listings' ),
144: 'type' => \Elementor\Controls_Manager::SELECT,
145: 'options' => array(
146: 'stacked' => esc_html__( 'Stacked', 'easy-property-listings' ),
147: 'inline' => esc_html__( 'Inline', 'easy-property-listings' ),
148: ),
149: 'default' => 'stacked',
150: )
151: );
152:
153: $this->end_controls_section();
154:
155: // Style Section.
156: $this->start_controls_section(
157: 'section_style',
158: array(
159: 'label' => esc_html__( 'Style', 'easy-property-listings' ),
160: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
161: )
162: );
163:
164: $this->add_control(
165: 'text_color',
166: array(
167: 'label' => esc_html__( 'Text Color', 'easy-property-listings' ),
168: 'type' => \Elementor\Controls_Manager::COLOR,
169: 'selectors' => array(
170: '{{WRAPPER}} .epl-agent-contact' => 'color: {{VALUE}};',
171: ),
172: )
173: );
174:
175: $this->add_control(
176: 'link_color',
177: array(
178: 'label' => esc_html__( 'Link Color', 'easy-property-listings' ),
179: 'type' => \Elementor\Controls_Manager::COLOR,
180: 'selectors' => array(
181: '{{WRAPPER}} .epl-agent-contact a' => 'color: {{VALUE}};',
182: ),
183: )
184: );
185:
186: $this->add_group_control(
187: \Elementor\Group_Control_Typography::get_type(),
188: array(
189: 'name' => 'typography',
190: 'selector' => '{{WRAPPER}} .epl-agent-contact',
191: )
192: );
193:
194: $this->add_responsive_control(
195: 'item_gap',
196: array(
197: 'label' => esc_html__( 'Gap Between Items', 'easy-property-listings' ),
198: 'type' => \Elementor\Controls_Manager::SLIDER,
199: 'size_units' => array( 'px' ),
200: 'range' => array(
201: 'px' => array(
202: 'min' => 0,
203: 'max' => 30,
204: ),
205: ),
206: 'selectors' => array(
207: '{{WRAPPER}} .epl-agent-contact' => 'gap: {{SIZE}}{{UNIT}};',
208: ),
209: )
210: );
211:
212: $this->end_controls_section();
213: }
214:
215: /**
216: * Get style dependencies so the Font Awesome icons always load.
217: *
218: * @return array
219: * @since 3.6.0 New: Elementor widgets (beta).
220: */
221: public function get_style_depends() {
222: return array( 'elementor-icons-fa-solid' );
223: }
224:
225: /**
226: * Render widget output.
227: * @since 3.6.0 New: Elementor widgets (beta).
228: */
229: protected function render() {
230: $author = $this->get_current_agent();
231:
232: if ( ! $author ) {
233: if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
234: echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Agent Contact - No agent context.', 'easy-property-listings' ) . '</div>';
235: }
236: return;
237: }
238:
239: $settings = $this->get_settings_for_display();
240: $show_labels = 'yes' === $settings['show_labels'];
241: $show_icons = 'yes' === $settings['show_icons'];
242: $layout_class = 'inline' === $settings['layout'] ? 'epl-contact-inline' : 'epl-contact-stacked';
243:
244: $mobile = $author->get_author_mobile();
245: $office_phone = $author->get_author_office_phone();
246: $email = $author->email;
247:
248: echo '<div class="epl-agent-contact ' . esc_attr( $layout_class ) . '">';
249:
250: // Mobile.
251: if ( 'yes' === $settings['show_mobile'] && ! empty( $mobile ) ) {
252: echo '<div class="epl-contact-item epl-contact-mobile">';
253: if ( $show_icons ) {
254: echo '<i class="fas fa-mobile-alt"></i> ';
255: }
256: if ( $show_labels ) {
257: echo '<span class="epl-contact-label">' . esc_html__( 'Mobile:', 'easy-property-listings' ) . '</span> ';
258: }
259: echo '<a href="tel:' . esc_attr( $mobile ) . '">' . esc_html( $mobile ) . '</a>';
260: echo '</div>';
261: }
262:
263: // Office Phone.
264: if ( 'yes' === $settings['show_office_phone'] && ! empty( $office_phone ) ) {
265: echo '<div class="epl-contact-item epl-contact-office">';
266: if ( $show_icons ) {
267: echo '<i class="fas fa-phone"></i> ';
268: }
269: if ( $show_labels ) {
270: echo '<span class="epl-contact-label">' . esc_html__( 'Office:', 'easy-property-listings' ) . '</span> ';
271: }
272: echo '<a href="tel:' . esc_attr( $office_phone ) . '">' . esc_html( $office_phone ) . '</a>';
273: echo '</div>';
274: }
275:
276: // Email.
277: if ( 'yes' === $settings['show_email'] && ! empty( $email ) ) {
278: echo '<div class="epl-contact-item epl-contact-email">';
279: if ( $show_icons ) {
280: echo '<i class="fas fa-envelope"></i> ';
281: }
282: if ( $show_labels ) {
283: echo '<span class="epl-contact-label">' . esc_html__( 'Email:', 'easy-property-listings' ) . '</span> ';
284: }
285: echo '<a href="mailto:' . esc_attr( $email ) . '">' . esc_html( $email ) . '</a>';
286: echo '</div>';
287: }
288:
289: echo '</div>';
290: }
291:
292: /**
293: * Get the current agent from context or fallback.
294: *
295: * @return EPL_Author_Loader|null
296: * @since 3.6.0 New: Elementor widgets (beta).
297: */
298: private function get_current_agent() {
299: global $epl_current_agent;
300:
301: if ( ! empty( $epl_current_agent ) ) {
302: return $epl_current_agent;
303: }
304:
305: $property = EPL_Elementor::setup_listing_context();
306:
307: if ( $property ) {
308: $author = EPL_Elementor::get_listing_agent( $property );
309: EPL_Elementor::restore_listing_context();
310: return $author;
311: }
312:
313: EPL_Elementor::restore_listing_context();
314: return null;
315: }
316: }
317: