1: <?php
2: /**
3: * Elementor Staff Listings Widget.
4: *
5: * @package EPL
6: * @subpackage PageBuilders/Elementor/Widgets/Elements
7: * @since 3.6.0
8: */
9:
10: if ( ! defined( 'ABSPATH' ) ) {
11: exit;
12: }
13:
14: /** Displays the Staff Directory extension's listings for the current staff member. */
15: class EPL_Elementor_Staff_Listings extends \Elementor\Widget_Base {
16: use EPL_Elementor_Dynamic_Widget;
17:
18: /**
19: * Widget name.
20: *
21: * @since 3.6.0 New: Elementor widgets (beta).
22: */
23: public function get_name() {
24: return 'epl-staff-listings';
25: }
26:
27: /**
28: * Widget title shown in the Elementor panel.
29: *
30: * @since 3.6.0 New: Elementor widgets (beta).
31: */
32: public function get_title() {
33: return esc_html__( 'Staff Listings', 'easy-property-listings' );
34: }
35:
36: /**
37: * Widget icon.
38: *
39: * @since 3.6.0 New: Elementor widgets (beta).
40: */
41: public function get_icon() {
42: return 'eicon-posts-grid';
43: }
44:
45: /**
46: * Widget categories.
47: *
48: * @since 3.6.0 New: Elementor widgets (beta).
49: */
50: public function get_categories() {
51: return array( 'epl-staff' );
52: }
53:
54: /**
55: * Search keywords for the Elementor panel.
56: *
57: * @since 3.6.0 New: Elementor widgets (beta).
58: */
59: public function get_keywords() {
60: return array( 'staff', 'agent', 'listings', 'properties', 'tabs', 'directory', 'epl' );
61: }
62:
63: /**
64: * Register the widget controls.
65: *
66: * @since 3.6.0 New: Elementor widgets (beta).
67: */
68: protected function register_controls() {
69: $this->start_controls_section(
70: 'section_content',
71: array(
72: 'label' => esc_html__( 'Staff Listings', 'easy-property-listings' ),
73: 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
74: )
75: );
76:
77: $this->add_control(
78: 'display_mode',
79: array(
80: 'label' => esc_html__( 'Layout', 'easy-property-listings' ),
81: 'type' => \Elementor\Controls_Manager::SELECT,
82: 'default' => '',
83: 'options' => array(
84: '' => esc_html__( 'Staff Directory Setting', 'easy-property-listings' ),
85: 'list' => esc_html__( 'Combined List', 'easy-property-listings' ),
86: 'tabbed' => esc_html__( 'Tabbed', 'easy-property-listings' ),
87: 'section' => esc_html__( 'Separate Sections', 'easy-property-listings' ),
88: ),
89: )
90: );
91:
92: $this->add_control(
93: 'tab_style',
94: array(
95: 'label' => esc_html__( 'Tab Style', 'easy-property-listings' ),
96: 'type' => \Elementor\Controls_Manager::SELECT,
97: 'default' => '',
98: 'options' => array(
99: '' => esc_html__( 'Staff Directory Setting', 'easy-property-listings' ),
100: 'horizontal' => esc_html__( 'Horizontal', 'easy-property-listings' ),
101: 'vertical' => esc_html__( 'Vertical', 'easy-property-listings' ),
102: ),
103: 'condition' => array( 'display_mode' => array( '', 'tabbed' ) ),
104: )
105: );
106:
107: $this->add_control(
108: 'custom_title',
109: array(
110: 'label' => esc_html__( 'Title', 'easy-property-listings' ),
111: 'type' => \Elementor\Controls_Manager::TEXT,
112: 'placeholder' => esc_html__( 'Use Staff Directory setting', 'easy-property-listings' ),
113: 'label_block' => true,
114: )
115: );
116:
117: $this->end_controls_section();
118:
119: $this->start_controls_section(
120: 'section_title_style',
121: array(
122: 'label' => esc_html__( 'Headings', 'easy-property-listings' ),
123: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
124: )
125: );
126: $this->add_control(
127: 'title_color',
128: array(
129: 'label' => esc_html__( 'Color', 'easy-property-listings' ),
130: 'type' => \Elementor\Controls_Manager::COLOR,
131: 'selectors' => array( '{{WRAPPER}} .epl-sd-section-title, {{WRAPPER}} .epl-section__title' => 'color: {{VALUE}};' ),
132: )
133: );
134: $this->add_group_control(
135: \Elementor\Group_Control_Typography::get_type(),
136: array(
137: 'name' => 'title_typography',
138: 'selector' => '{{WRAPPER}} .epl-sd-section-title, {{WRAPPER}} .epl-section__title',
139: )
140: );
141: $this->end_controls_section();
142:
143: $this->start_controls_section(
144: 'section_tabs_style',
145: array(
146: 'label' => esc_html__( 'Tabs', 'easy-property-listings' ),
147: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
148: )
149: );
150: $this->add_control(
151: 'tab_text_color',
152: array(
153: 'label' => esc_html__( 'Text Color', 'easy-property-listings' ),
154: 'type' => \Elementor\Controls_Manager::COLOR,
155: 'selectors' => array( '{{WRAPPER}} [class*="epl-sd-tabs-"] > ul a' => 'color: {{VALUE}};' ),
156: )
157: );
158: $this->add_control(
159: 'tab_background',
160: array(
161: 'label' => esc_html__( 'Background', 'easy-property-listings' ),
162: 'type' => \Elementor\Controls_Manager::COLOR,
163: 'selectors' => array( '{{WRAPPER}} [class*="epl-sd-tabs-"] > ul a' => 'background-color: {{VALUE}};' ),
164: )
165: );
166: $this->add_control(
167: 'tab_active_color',
168: array(
169: 'label' => esc_html__( 'Active Text Color', 'easy-property-listings' ),
170: 'type' => \Elementor\Controls_Manager::COLOR,
171: 'selectors' => array( '{{WRAPPER}} [class*="epl-sd-tabs-"] > ul .ui-tabs-active a' => 'color: {{VALUE}};' ),
172: )
173: );
174: $this->add_control(
175: 'tab_active_background',
176: array(
177: 'label' => esc_html__( 'Active Background', 'easy-property-listings' ),
178: 'type' => \Elementor\Controls_Manager::COLOR,
179: 'selectors' => array( '{{WRAPPER}} [class*="epl-sd-tabs-"] > ul .ui-tabs-active a' => 'background-color: {{VALUE}};' ),
180: )
181: );
182: $this->end_controls_section();
183: }
184:
185: /**
186: * Render the widget output.
187: *
188: * @since 3.6.0 New: Elementor widgets (beta).
189: */
190: protected function render() {
191: if ( ! class_exists( 'EPL_SD_Listings' ) ) {
192: $this->render_placeholder( esc_html__( 'The EPL Staff Directory extension is required.', 'easy-property-listings' ) );
193: return;
194: }
195:
196: global $epl_author;
197: $property = EPL_Elementor::setup_listing_context();
198: $author = $property ? EPL_Elementor::get_listing_agent( $property ) : null;
199:
200: if ( ! $author ) {
201: EPL_Elementor::restore_listing_context();
202: $this->render_placeholder( esc_html__( 'Select a staff member as the preview context.', 'easy-property-listings' ) );
203: return;
204: }
205:
206: $settings = $this->get_settings_for_display();
207: $epl_author = $author; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Required by Staff Directory's renderer and restored below.
208: $title = isset( $settings['custom_title'] ) ? trim( (string) $settings['custom_title'] ) : '';
209: $filter = static function ( $existing ) use ( $title ) {
210: return '' !== $title ? $title : $existing;
211: };
212:
213: if ( '' !== $title ) {
214: add_filter( 'epl_sd_single_listing_title', $filter );
215: }
216:
217: echo '<div class="epl-elementor-staff-listings">';
218: EPL_SD_Listings::instance()->render_single_staff_listings( $settings['display_mode'], $settings['tab_style'] );
219: echo '</div>';
220:
221: if ( '' !== $title ) {
222: remove_filter( 'epl_sd_single_listing_title', $filter );
223: }
224: EPL_Elementor::restore_listing_context();
225: }
226:
227: /**
228: * Placeholder shown in the editor when there is nothing to show.
229: *
230: * @since 3.6.0 New: Elementor widgets (beta).
231: */
232: private function render_placeholder( $message ) {
233: if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
234: echo '<div class="epl-elementor-placeholder">' . esc_html( $message ) . '</div>';
235: }
236: }
237: }
238: