| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | if ( ! defined( 'ABSPATH' ) ) { |
| 12: | exit; |
| 13: | } |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | class EPL_Elementor_Agent_Contact extends \Elementor\Widget_Base { |
| 24: | use EPL_Elementor_Dynamic_Widget; |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | public function get_name() { |
| 31: | return 'epl-agent-contact'; |
| 32: | } |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | public function get_title() { |
| 39: | return esc_html__( 'Contact', 'easy-property-listings' ); |
| 40: | } |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | public function get_icon() { |
| 47: | return 'eicon-tel-field'; |
| 48: | } |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | public function get_categories() { |
| 55: | return array( 'epl-staff', 'epl-author' ); |
| 56: | } |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | public function get_keywords() { |
| 63: | return array( 'agent', 'contact', 'phone', 'mobile', 'email', 'epl' ); |
| 64: | } |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 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: | |
| 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: | |
| 217: | |
| 218: | |
| 219: | |
| 220: | |
| 221: | public function get_style_depends() { |
| 222: | return array( 'elementor-icons-fa-solid' ); |
| 223: | } |
| 224: | |
| 225: | |
| 226: | |
| 227: | |
| 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: | |
| 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: | |
| 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: | |
| 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: | |
| 294: | |
| 295: | |
| 296: | |
| 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: | |