1: <?php
2: /**
3: * Elementor Agent Bio 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_Bio Class
17: *
18: * Displays the agent biography/description.
19: * Reads from $epl_current_agent context.
20: *
21: * @since 3.6.0
22: */
23: class EPL_Elementor_Agent_Bio 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-bio';
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__( 'Bio', '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-text-area';
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', 'bio', 'biography', 'description', 'about', '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: '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: // Style Section.
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: * Render widget output.
156: * @since 3.6.0 New: Elementor widgets (beta).
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: // When trimming, work from the raw description so the core "Read More"
172: // link markup is not stripped into the counted words.
173: if ( $word_limit > 0 ) {
174: $bio = wp_trim_words( wp_strip_all_tags( (string) $author->get_description() ), $word_limit, '&hellip;' );
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: * Get the current agent from context or fallback.
188: *
189: * @return EPL_Author_Loader|null
190: * @since 3.6.0 New: Elementor widgets (beta).
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: