1: <?php
2: /**
3: * Elementor Agent Position 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_Position Class
17: *
18: * Displays the agent position/title.
19: * Reads from $epl_current_agent context.
20: *
21: * @since 3.6.0
22: */
23: class EPL_Elementor_Agent_Position 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-position';
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__( 'Position', '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';
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', 'position', 'title', 'job', '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: // Style Section.
73: $this->start_controls_section(
74: 'section_style',
75: array(
76: 'label' => esc_html__( 'Style', 'easy-property-listings' ),
77: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
78: )
79: );
80:
81: $this->add_control(
82: 'text_color',
83: array(
84: 'label' => esc_html__( 'Color', 'easy-property-listings' ),
85: 'type' => \Elementor\Controls_Manager::COLOR,
86: 'selectors' => array(
87: '{{WRAPPER}} .epl-agent-position' => 'color: {{VALUE}};',
88: ),
89: )
90: );
91:
92: $this->add_group_control(
93: \Elementor\Group_Control_Typography::get_type(),
94: array(
95: 'name' => 'typography',
96: 'selector' => '{{WRAPPER}} .epl-agent-position',
97: )
98: );
99:
100: $this->add_responsive_control(
101: 'text_align',
102: array(
103: 'label' => esc_html__( 'Alignment', 'easy-property-listings' ),
104: 'type' => \Elementor\Controls_Manager::CHOOSE,
105: 'options' => array(
106: 'left' => array(
107: 'title' => esc_html__( 'Left', 'easy-property-listings' ),
108: 'icon' => 'eicon-text-align-left',
109: ),
110: 'center' => array(
111: 'title' => esc_html__( 'Center', 'easy-property-listings' ),
112: 'icon' => 'eicon-text-align-center',
113: ),
114: 'right' => array(
115: 'title' => esc_html__( 'Right', 'easy-property-listings' ),
116: 'icon' => 'eicon-text-align-right',
117: ),
118: ),
119: 'selectors' => array(
120: '{{WRAPPER}} .epl-agent-position' => 'text-align: {{VALUE}};',
121: ),
122: )
123: );
124:
125: $this->end_controls_section();
126: }
127:
128: /**
129: * Render widget output.
130: * @since 3.6.0 New: Elementor widgets (beta).
131: */
132: protected function render() {
133: $author = $this->get_current_agent();
134:
135: if ( ! $author ) {
136: if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
137: echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Agent Position - No agent context.', 'easy-property-listings' ) . '</div>';
138: }
139: return;
140: }
141:
142: $position = $author->get_author_position();
143:
144: if ( empty( $position ) ) {
145: return;
146: }
147:
148: echo '<div class="epl-agent-position">' . esc_html( $position ) . '</div>';
149: }
150:
151: /**
152: * Get the current agent from context or fallback.
153: *
154: * @return EPL_Author_Loader|null
155: * @since 3.6.0 New: Elementor widgets (beta).
156: */
157: private function get_current_agent() {
158: global $epl_current_agent;
159:
160: if ( ! empty( $epl_current_agent ) ) {
161: return $epl_current_agent;
162: }
163:
164: $property = EPL_Elementor::setup_listing_context();
165:
166: if ( $property ) {
167: $author = EPL_Elementor::get_listing_agent( $property );
168: EPL_Elementor::restore_listing_context();
169: return $author;
170: }
171:
172: EPL_Elementor::restore_listing_context();
173: return null;
174: }
175: }
176: