| 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_Bio extends \Elementor\Widget_Base { |
| 24: | use EPL_Elementor_Dynamic_Widget; |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | public function get_name() { |
| 31: | return 'epl-agent-bio'; |
| 32: | } |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | public function get_title() { |
| 39: | return esc_html__( 'Bio', 'easy-property-listings' ); |
| 40: | } |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | public function get_icon() { |
| 47: | return 'eicon-text-area'; |
| 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', 'bio', 'biography', 'description', 'about', '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: | 'word_limit', |
| 82: | array( |
| 83: | 'label' => esc_html__( 'Word Limit', 'easy-property-listings' ), |
| 84: | 'type' => \Elementor\Controls_Manager::NUMBER, |
| 85: | 'min' => 0, |
| 86: | 'max' => 500, |
| 87: | 'default' => 0, |
| 88: | 'description' => esc_html__( 'Set 0 for no limit', 'easy-property-listings' ), |
| 89: | ) |
| 90: | ); |
| 91: | |
| 92: | $this->end_controls_section(); |
| 93: | |
| 94: | |
| 95: | $this->start_controls_section( |
| 96: | 'section_style', |
| 97: | array( |
| 98: | 'label' => esc_html__( 'Style', 'easy-property-listings' ), |
| 99: | 'tab' => \Elementor\Controls_Manager::TAB_STYLE, |
| 100: | ) |
| 101: | ); |
| 102: | |
| 103: | $this->add_control( |
| 104: | 'text_color', |
| 105: | array( |
| 106: | 'label' => esc_html__( 'Color', 'easy-property-listings' ), |
| 107: | 'type' => \Elementor\Controls_Manager::COLOR, |
| 108: | 'selectors' => array( |
| 109: | '{{WRAPPER}} .epl-agent-bio' => 'color: {{VALUE}};', |
| 110: | ), |
| 111: | ) |
| 112: | ); |
| 113: | |
| 114: | $this->add_group_control( |
| 115: | \Elementor\Group_Control_Typography::get_type(), |
| 116: | array( |
| 117: | 'name' => 'typography', |
| 118: | 'selector' => '{{WRAPPER}} .epl-agent-bio', |
| 119: | ) |
| 120: | ); |
| 121: | |
| 122: | $this->add_responsive_control( |
| 123: | 'text_align', |
| 124: | array( |
| 125: | 'label' => esc_html__( 'Alignment', 'easy-property-listings' ), |
| 126: | 'type' => \Elementor\Controls_Manager::CHOOSE, |
| 127: | 'options' => array( |
| 128: | 'left' => array( |
| 129: | 'title' => esc_html__( 'Left', 'easy-property-listings' ), |
| 130: | 'icon' => 'eicon-text-align-left', |
| 131: | ), |
| 132: | 'center' => array( |
| 133: | 'title' => esc_html__( 'Center', 'easy-property-listings' ), |
| 134: | 'icon' => 'eicon-text-align-center', |
| 135: | ), |
| 136: | 'right' => array( |
| 137: | 'title' => esc_html__( 'Right', 'easy-property-listings' ), |
| 138: | 'icon' => 'eicon-text-align-right', |
| 139: | ), |
| 140: | 'justify' => array( |
| 141: | 'title' => esc_html__( 'Justify', 'easy-property-listings' ), |
| 142: | 'icon' => 'eicon-text-align-justify', |
| 143: | ), |
| 144: | ), |
| 145: | 'selectors' => array( |
| 146: | '{{WRAPPER}} .epl-agent-bio' => 'text-align: {{VALUE}};', |
| 147: | ), |
| 148: | ) |
| 149: | ); |
| 150: | |
| 151: | $this->end_controls_section(); |
| 152: | } |
| 153: | |
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: | protected function render() { |
| 159: | $author = $this->get_current_agent(); |
| 160: | |
| 161: | if ( ! $author ) { |
| 162: | if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 163: | echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Agent Bio - No agent context.', 'easy-property-listings' ) . '</div>'; |
| 164: | } |
| 165: | return; |
| 166: | } |
| 167: | |
| 168: | $settings = $this->get_settings_for_display(); |
| 169: | $word_limit = intval( $settings['word_limit'] ); |
| 170: | |
| 171: | |
| 172: | |
| 173: | if ( $word_limit > 0 ) { |
| 174: | $bio = wp_trim_words( wp_strip_all_tags( (string) $author->get_description() ), $word_limit, '…' ); |
| 175: | } else { |
| 176: | $bio = $author->get_description_html(); |
| 177: | } |
| 178: | |
| 179: | if ( empty( $bio ) ) { |
| 180: | return; |
| 181: | } |
| 182: | |
| 183: | echo '<div class="epl-agent-bio">' . wp_kses_post( $bio ) . '</div>'; |
| 184: | } |
| 185: | |
| 186: | |
| 187: | |
| 188: | |
| 189: | |
| 190: | |
| 191: | |
| 192: | private function get_current_agent() { |
| 193: | global $epl_current_agent; |
| 194: | |
| 195: | if ( ! empty( $epl_current_agent ) ) { |
| 196: | return $epl_current_agent; |
| 197: | } |
| 198: | |
| 199: | $property = EPL_Elementor::setup_listing_context(); |
| 200: | |
| 201: | if ( $property ) { |
| 202: | $author = EPL_Elementor::get_listing_agent( $property ); |
| 203: | EPL_Elementor::restore_listing_context(); |
| 204: | return $author; |
| 205: | } |
| 206: | |
| 207: | EPL_Elementor::restore_listing_context(); |
| 208: | return null; |
| 209: | } |
| 210: | } |
| 211: | |