1: <?php
2: /**
3: * Elementor Property Excerpt 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_Property_Excerpt Class
17: *
18: * @since 3.6.0
19: */
20: class EPL_Elementor_Property_Excerpt extends \Elementor\Widget_Base {
21: use EPL_Elementor_Dynamic_Widget;
22:
23: /**
24: * Get widget name.
25: *
26: * @return string
27: * @since 3.6.0 New: Elementor widgets (beta).
28: */
29: public function get_name() {
30: return 'epl-property-excerpt';
31: }
32:
33: /**
34: * Get widget title.
35: *
36: * @return string
37: * @since 3.6.0 New: Elementor widgets (beta).
38: */
39: public function get_title() {
40: return esc_html__( 'Excerpt', 'easy-property-listings' );
41: }
42:
43: /**
44: * Get widget icon.
45: *
46: * @return string
47: * @since 3.6.0 New: Elementor widgets (beta).
48: */
49: public function get_icon() {
50: return 'eicon-post-excerpt';
51: }
52:
53: /**
54: * Get widget categories.
55: *
56: * @return array
57: * @since 3.6.0 New: Elementor widgets (beta).
58: */
59: public function get_categories() {
60: return array( 'epl-elements' );
61: }
62:
63: /**
64: * Get widget keywords.
65: *
66: * @return array
67: * @since 3.6.0 New: Elementor widgets (beta).
68: */
69: public function get_keywords() {
70: return array( 'property', 'excerpt', 'summary', 'epl' );
71: }
72:
73: /**
74: * Register widget controls.
75: * @since 3.6.0 New: Elementor widgets (beta).
76: */
77: protected function register_controls() {
78:
79: $this->start_controls_section(
80: 'section_content',
81: array(
82: 'label' => esc_html__( 'Content', 'easy-property-listings' ),
83: 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
84: )
85: );
86:
87: $this->add_control(
88: 'excerpt_length',
89: array(
90: 'label' => esc_html__( 'Excerpt Length (words)', 'easy-property-listings' ),
91: 'type' => \Elementor\Controls_Manager::NUMBER,
92: 'min' => 5,
93: 'max' => 200,
94: 'default' => 20,
95: )
96: );
97:
98: $this->end_controls_section();
99:
100: // Style Section.
101: $this->start_controls_section(
102: 'section_style',
103: array(
104: 'label' => esc_html__( 'Style', 'easy-property-listings' ),
105: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
106: )
107: );
108:
109: $this->add_control(
110: 'text_color',
111: array(
112: 'label' => esc_html__( 'Color', 'easy-property-listings' ),
113: 'type' => \Elementor\Controls_Manager::COLOR,
114: 'selectors' => array(
115: '{{WRAPPER}} .epl-property-excerpt' => 'color: {{VALUE}};',
116: ),
117: )
118: );
119:
120: $this->add_group_control(
121: \Elementor\Group_Control_Typography::get_type(),
122: array(
123: 'name' => 'typography',
124: 'selector' => '{{WRAPPER}} .epl-property-excerpt',
125: )
126: );
127:
128: $this->add_responsive_control(
129: 'text_align',
130: array(
131: 'label' => esc_html__( 'Alignment', 'easy-property-listings' ),
132: 'type' => \Elementor\Controls_Manager::CHOOSE,
133: 'options' => array(
134: 'left' => array(
135: 'title' => esc_html__( 'Left', 'easy-property-listings' ),
136: 'icon' => 'eicon-text-align-left',
137: ),
138: 'center' => array(
139: 'title' => esc_html__( 'Center', 'easy-property-listings' ),
140: 'icon' => 'eicon-text-align-center',
141: ),
142: 'right' => array(
143: 'title' => esc_html__( 'Right', 'easy-property-listings' ),
144: 'icon' => 'eicon-text-align-right',
145: ),
146: ),
147: 'selectors' => array(
148: '{{WRAPPER}} .epl-property-excerpt' => 'text-align: {{VALUE}};',
149: ),
150: )
151: );
152:
153: $this->end_controls_section();
154: }
155:
156: /**
157: * Render widget output.
158: * @since 3.6.0 New: Elementor widgets (beta).
159: */
160: protected function render() {
161: $property = EPL_Elementor::setup_listing_context();
162: $is_editor = \Elementor\Plugin::$instance->editor->is_edit_mode();
163:
164: if ( ! $property ) {
165: if ( $is_editor ) {
166: echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Property Excerpt - No listings found.', 'easy-property-listings' ) . '</div>';
167: }
168: EPL_Elementor::restore_listing_context();
169: return;
170: }
171:
172: $settings = $this->get_settings_for_display();
173: $length = absint( $settings['excerpt_length'] );
174:
175: echo '<div class="epl-property-excerpt">';
176: echo esc_html( wp_trim_words( get_the_excerpt( $property->post->ID ), $length ) );
177: echo '</div>';
178:
179: EPL_Elementor::restore_listing_context();
180: }
181: }
182: