| 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_Social extends \Elementor\Widget_Base { |
| 24: | use EPL_Elementor_Dynamic_Widget; |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | public function get_name() { |
| 31: | return 'epl-agent-social'; |
| 32: | } |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | public function get_title() { |
| 39: | return esc_html__( 'Social', 'easy-property-listings' ); |
| 40: | } |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | public function get_icon() { |
| 47: | return 'eicon-social-icons'; |
| 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', 'social', 'facebook', 'twitter', 'linkedin', '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__( 'Social Icons', 'easy-property-listings' ), |
| 76: | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 77: | ) |
| 78: | ); |
| 79: | |
| 80: | $repeater = new \Elementor\Repeater(); |
| 81: | |
| 82: | $repeater->add_control( |
| 83: | 'social_network', |
| 84: | array( |
| 85: | 'label' => esc_html__( 'Network', 'easy-property-listings' ), |
| 86: | 'type' => \Elementor\Controls_Manager::SELECT, |
| 87: | 'default' => 'facebook', |
| 88: | 'options' => array( |
| 89: | 'facebook' => 'Facebook', |
| 90: | 'twitter' => 'Twitter', |
| 91: | 'instagram' => 'Instagram', |
| 92: | 'linkedin' => 'LinkedIn', |
| 93: | 'youtube' => 'YouTube', |
| 94: | 'pinterest' => 'Pinterest', |
| 95: | 'website' => 'Website', |
| 96: | ), |
| 97: | ) |
| 98: | ); |
| 99: | |
| 100: | $repeater->add_control( |
| 101: | 'social_icon', |
| 102: | array( |
| 103: | 'label' => esc_html__( 'Icon', 'easy-property-listings' ), |
| 104: | 'type' => \Elementor\Controls_Manager::ICONS, |
| 105: | 'default' => array( |
| 106: | 'value' => 'fab fa-facebook', |
| 107: | 'library' => 'fa-brands', |
| 108: | ), |
| 109: | ) |
| 110: | ); |
| 111: | |
| 112: | $repeater->add_control( |
| 113: | 'item_icon_color', |
| 114: | array( |
| 115: | 'label' => esc_html__( 'Color', 'easy-property-listings' ), |
| 116: | 'type' => \Elementor\Controls_Manager::COLOR, |
| 117: | 'selectors' => array( |
| 118: | '{{WRAPPER}} {{CURRENT_ITEM}} i' => 'color: {{VALUE}}', |
| 119: | '{{WRAPPER}} {{CURRENT_ITEM}} svg' => 'fill: {{VALUE}}', |
| 120: | ), |
| 121: | ) |
| 122: | ); |
| 123: | |
| 124: | $repeater->add_control( |
| 125: | 'item_icon_hover_color', |
| 126: | array( |
| 127: | 'label' => esc_html__( 'Hover Color', 'easy-property-listings' ), |
| 128: | 'type' => \Elementor\Controls_Manager::COLOR, |
| 129: | 'selectors' => array( |
| 130: | '{{WRAPPER}} {{CURRENT_ITEM}}:hover i' => 'color: {{VALUE}}', |
| 131: | '{{WRAPPER}} {{CURRENT_ITEM}}:hover svg' => 'fill: {{VALUE}}', |
| 132: | ), |
| 133: | ) |
| 134: | ); |
| 135: | |
| 136: | $this->add_control( |
| 137: | 'social_icon_list', |
| 138: | array( |
| 139: | 'label' => esc_html__( 'Social Icons', 'easy-property-listings' ), |
| 140: | 'type' => \Elementor\Controls_Manager::REPEATER, |
| 141: | 'fields' => $repeater->get_controls(), |
| 142: | 'default' => array( |
| 143: | array( |
| 144: | 'social_network' => 'facebook', |
| 145: | 'social_icon' => array( 'value' => 'fab fa-facebook', 'library' => 'fa-brands' ), |
| 146: | ), |
| 147: | array( |
| 148: | 'social_network' => 'twitter', |
| 149: | 'social_icon' => array( 'value' => 'fab fa-twitter', 'library' => 'fa-brands' ), |
| 150: | ), |
| 151: | array( |
| 152: | 'social_network' => 'instagram', |
| 153: | 'social_icon' => array( 'value' => 'fab fa-instagram', 'library' => 'fa-brands' ), |
| 154: | ), |
| 155: | array( |
| 156: | 'social_network' => 'linkedin', |
| 157: | 'social_icon' => array( 'value' => 'fab fa-linkedin', 'library' => 'fa-brands' ), |
| 158: | ), |
| 159: | ), |
| 160: | 'title_field' => '{{{ social_network }}}', |
| 161: | ) |
| 162: | ); |
| 163: | |
| 164: | $this->end_controls_section(); |
| 165: | |
| 166: | |
| 167: | $this->start_controls_section( |
| 168: | 'section_style', |
| 169: | array( |
| 170: | 'label' => esc_html__( 'Style', 'easy-property-listings' ), |
| 171: | 'tab' => \Elementor\Controls_Manager::TAB_STYLE, |
| 172: | ) |
| 173: | ); |
| 174: | |
| 175: | $this->add_control( |
| 176: | 'icon_color', |
| 177: | array( |
| 178: | 'label' => esc_html__( 'Primary Color', 'easy-property-listings' ), |
| 179: | 'type' => \Elementor\Controls_Manager::COLOR, |
| 180: | 'selectors' => array( |
| 181: | '{{WRAPPER}} .epl-agent-social a i' => 'color: {{VALUE}};', |
| 182: | '{{WRAPPER}} .epl-agent-social a svg' => 'fill: {{VALUE}};', |
| 183: | ), |
| 184: | ) |
| 185: | ); |
| 186: | |
| 187: | $this->add_control( |
| 188: | 'icon_hover_color', |
| 189: | array( |
| 190: | 'label' => esc_html__( 'Primary Hover Color', 'easy-property-listings' ), |
| 191: | 'type' => \Elementor\Controls_Manager::COLOR, |
| 192: | 'selectors' => array( |
| 193: | '{{WRAPPER}} .epl-agent-social a:hover i' => 'color: {{VALUE}};', |
| 194: | '{{WRAPPER}} .epl-agent-social a:hover svg' => 'fill: {{VALUE}};', |
| 195: | ), |
| 196: | ) |
| 197: | ); |
| 198: | |
| 199: | $this->add_responsive_control( |
| 200: | 'icon_size', |
| 201: | array( |
| 202: | 'label' => esc_html__( 'Icon Size', 'easy-property-listings' ), |
| 203: | 'type' => \Elementor\Controls_Manager::SLIDER, |
| 204: | 'size_units' => array( 'px', 'em', 'rem' ), |
| 205: | 'range' => array( |
| 206: | 'px' => array( |
| 207: | 'min' => 10, |
| 208: | 'max' => 100, |
| 209: | ), |
| 210: | ), |
| 211: | 'default' => array( |
| 212: | 'size' => 20, |
| 213: | 'unit' => 'px', |
| 214: | ), |
| 215: | 'selectors' => array( |
| 216: | '{{WRAPPER}} .epl-agent-social a' => 'font-size: {{SIZE}}{{UNIT}};', |
| 217: | '{{WRAPPER}} .epl-agent-social a svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};', |
| 218: | ), |
| 219: | ) |
| 220: | ); |
| 221: | |
| 222: | $this->add_responsive_control( |
| 223: | 'icon_gap', |
| 224: | array( |
| 225: | 'label' => esc_html__( 'Gap Between Icons', 'easy-property-listings' ), |
| 226: | 'type' => \Elementor\Controls_Manager::SLIDER, |
| 227: | 'size_units' => array( 'px', 'em' ), |
| 228: | 'range' => array( |
| 229: | 'px' => array( |
| 230: | 'min' => 0, |
| 231: | 'max' => 50, |
| 232: | ), |
| 233: | ), |
| 234: | 'default' => array( |
| 235: | 'size' => 10, |
| 236: | 'unit' => 'px', |
| 237: | ), |
| 238: | 'selectors' => array( |
| 239: | '{{WRAPPER}} .epl-agent-social' => 'gap: {{SIZE}}{{UNIT}};', |
| 240: | ), |
| 241: | ) |
| 242: | ); |
| 243: | |
| 244: | $this->add_responsive_control( |
| 245: | 'alignment', |
| 246: | array( |
| 247: | 'label' => esc_html__( 'Alignment', 'easy-property-listings' ), |
| 248: | 'type' => \Elementor\Controls_Manager::CHOOSE, |
| 249: | 'options' => array( |
| 250: | 'flex-start' => array( |
| 251: | 'title' => esc_html__( 'Left', 'easy-property-listings' ), |
| 252: | 'icon' => 'eicon-text-align-left', |
| 253: | ), |
| 254: | 'center' => array( |
| 255: | 'title' => esc_html__( 'Center', 'easy-property-listings' ), |
| 256: | 'icon' => 'eicon-text-align-center', |
| 257: | ), |
| 258: | 'flex-end' => array( |
| 259: | 'title' => esc_html__( 'Right', 'easy-property-listings' ), |
| 260: | 'icon' => 'eicon-text-align-right', |
| 261: | ), |
| 262: | ), |
| 263: | 'selectors' => array( |
| 264: | '{{WRAPPER}} .epl-agent-social' => 'justify-content: {{VALUE}};', |
| 265: | ), |
| 266: | ) |
| 267: | ); |
| 268: | |
| 269: | $this->end_controls_section(); |
| 270: | } |
| 271: | |
| 272: | |
| 273: | |
| 274: | |
| 275: | |
| 276: | public function get_style_depends() { |
| 277: | return array( 'elementor-icons-fa-brands', 'elementor-icons-fa-solid' ); |
| 278: | } |
| 279: | |
| 280: | |
| 281: | |
| 282: | |
| 283: | |
| 284: | |
| 285: | protected function render() { |
| 286: | $author_loader = $this->get_current_agent(); |
| 287: | |
| 288: | if ( ! $author_loader ) { |
| 289: | if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 290: | echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Agent Social - No agent context.', 'easy-property-listings' ) . '</div>'; |
| 291: | } |
| 292: | return; |
| 293: | } |
| 294: | |
| 295: | |
| 296: | $author = ( isset( $author_loader->object ) ) ? $author_loader->object : $author_loader; |
| 297: | |
| 298: | $settings = $this->get_settings_for_display(); |
| 299: | |
| 300: | if ( empty( $settings['social_icon_list'] ) ) { |
| 301: | return; |
| 302: | } |
| 303: | |
| 304: | echo '<div class="epl-agent-social">'; |
| 305: | |
| 306: | foreach ( $settings['social_icon_list'] as $index => $item ) { |
| 307: | $network = isset( $item['social_network'] ) ? $item['social_network'] : ''; |
| 308: | |
| 309: | if ( ! in_array( $network, array( 'facebook', 'twitter', 'instagram', 'linkedin', 'youtube', 'pinterest', 'website' ), true ) ) { |
| 310: | continue; |
| 311: | } |
| 312: | $method = 'get_' . $network; |
| 313: | |
| 314: | |
| 315: | if ( method_exists( $author, $method ) ) { |
| 316: | $url = call_user_func( array( $author, $method ) ); |
| 317: | |
| 318: | if ( ! empty( $url ) ) { |
| 319: | $label = ucfirst( $network ); |
| 320: | |
| 321: | |
| 322: | $repeater_setting_key = $this->get_repeater_setting_key( 'social_icon', 'social_icon_list', $index ); |
| 323: | $this->add_render_attribute( $repeater_setting_key, 'class', 'epl-social-icon' ); |
| 324: | $this->add_render_attribute( $repeater_setting_key, 'class', 'epl-social-' . esc_attr( $network ) ); |
| 325: | $this->add_render_attribute( $repeater_setting_key, 'class', 'elementor-repeater-item-' . $item['_id'] ); |
| 326: | $this->add_render_attribute( $repeater_setting_key, 'href', esc_url( $url ) ); |
| 327: | $this->add_render_attribute( $repeater_setting_key, 'target', '_blank' ); |
| 328: | $this->add_render_attribute( $repeater_setting_key, 'rel', 'noopener noreferrer' ); |
| 329: | $this->add_render_attribute( $repeater_setting_key, 'aria-label', esc_attr( $label ) ); |
| 330: | |
| 331: | ?> |
| 332: | <a <?php echo $this->get_render_attribute_string( $repeater_setting_key ); ?>> |
| 333: | <?php \Elementor\Icons_Manager::render_icon( $item['social_icon'], array( 'aria-hidden' => 'true' ) ); ?> |
| 334: | </a> |
| 335: | <?php |
| 336: | } |
| 337: | } |
| 338: | } |
| 339: | |
| 340: | echo '</div>'; |
| 341: | } |
| 342: | |
| 343: | |
| 344: | |
| 345: | |
| 346: | |
| 347: | |
| 348: | |
| 349: | private function get_current_agent() { |
| 350: | global $epl_current_agent; |
| 351: | |
| 352: | if ( ! empty( $epl_current_agent ) ) { |
| 353: | return $epl_current_agent; |
| 354: | } |
| 355: | |
| 356: | $property = EPL_Elementor::setup_listing_context(); |
| 357: | |
| 358: | if ( $property ) { |
| 359: | $author = EPL_Elementor::get_listing_agent( $property ); |
| 360: | EPL_Elementor::restore_listing_context(); |
| 361: | return $author; |
| 362: | } |
| 363: | |
| 364: | EPL_Elementor::restore_listing_context(); |
| 365: | return null; |
| 366: | } |
| 367: | } |
| 368: | |