PluginProbe
Property Hive / 2.3.1
Property Hive v2.3.1
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / elementor-widgets / property-search-form.php

property-search-form.php in Property Hive 2.3.1, at includes/elementor-widgets/property-search-form.php

417 lines 12.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor Property Search Form Widget.
4 *
5 * @since 1.0.0
6 */
7 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Existing public Elementor widget class; retain its registered name for extension compatibility.
8 class Elementor_Property_Search_Form_Widget extends \Elementor\Widget_Base {
9
10 public function get_name() {
11 return 'property-search-form';
12 }
13
14 public function get_title() {
15 return __( 'Search Form', 'propertyhive' );
16 }
17
18 public function get_icon() {
19 return 'eicon-search';
20 }
21
22 public function get_categories() {
23 return [ 'property-hive' ];
24 }
25
26 public function get_keywords() {
27 return [ 'property hive', 'propertyhive', 'property', 'search', 'form' ];
28 }
29
30 protected function register_controls() {
31
32 $this->start_controls_section(
33 'section_content',
34 [
35 'label' => __( 'Search Form', 'propertyhive' ),
36 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
37 ]
38 );
39
40 $description = sprintf(
41 /* translators: %s: URL to Property Hive settings area */
42 __( 'Search forms can be managed from within \'<a href="%s" target="_blank">Property Hive > Settings > Frontend > Search Forms</a>\'', 'propertyhive' ),
43 esc_url(admin_url('admin.php?page=ph-settings&tab=frontend&section=search-forms'))
44 );
45
46 $this->add_control(
47 'form_id',
48 [
49 'type' => \Elementor\Controls_Manager::TEXT,
50 'label' => esc_html__( 'Form ID', 'propertyhive' ),
51 'placeholder' => esc_html__( 'e.g. default', 'propertyhive' ),
52 'default' => 'default',
53 'description' => $description
54 ]
55 );
56
57 $departments = ph_get_departments();
58
59 $department_options = array();
60
61 foreach ( $departments as $key => $value )
62 {
63 if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' )
64 {
65 $department_options[$key] = $value;
66 }
67 }
68 $this->add_control(
69 'default_department',
70 [
71 'type' => \Elementor\Controls_Manager::SELECT,
72 'label' => esc_html__( 'Default Department', 'propertyhive' ),
73 'options' => $department_options,
74 'default' => get_option( 'propertyhive_primary_department' ),
75 ]
76 );
77
78 $this->end_controls_section();
79
80 $this->start_controls_section(
81 'form_wrapper_style_section',
82 [
83 'label' => __( 'Form Wrapper', 'propertyhive' ),
84 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
85 ]
86 );
87
88 $this->add_control(
89 'form_wrapper_background_color',
90 [
91 'label' => __( 'Background Colour', 'propertyhive' ),
92 'type' => \Elementor\Controls_Manager::COLOR,
93 'global' => [
94 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_PRIMARY,
95 ],
96 'selectors' => [
97 '{{WRAPPER}} .property-search-form' => 'background: {{VALUE}}',
98 ],
99 ]
100 );
101
102 $this->add_control(
103 'form_wrapper_padding',
104 [
105 'label' => __( 'Padding', 'propertyhive' ),
106 'type' => \Elementor\Controls_Manager::DIMENSIONS,
107 'size_units' => [ 'px' ],
108 'selectors' => [
109 '{{WRAPPER}} .property-search-form' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
110 ],
111 ]
112 );
113
114 $this->add_control(
115 'form_wrapper_margin',
116 [
117 'label' => __( 'Margin', 'propertyhive' ),
118 'type' => \Elementor\Controls_Manager::DIMENSIONS,
119 'size_units' => [ 'px' ],
120 'selectors' => [
121 '{{WRAPPER}} .property-search-form' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
122 ],
123 ]
124 );
125
126 $this->end_controls_section();
127
128 $this->start_controls_section(
129 'label_style_section',
130 [
131 'label' => __( 'Labels', 'propertyhive' ),
132 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
133 ]
134 );
135
136 $this->add_group_control(
137 \Elementor\Group_Control_Typography::get_type(),
138 [
139 'name' => 'label_typography',
140 'label' => __( 'Label Typography', 'propertyhive' ),
141 'global' => [
142 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_PRIMARY,
143 ],
144 'selector' => '{{WRAPPER}} .property-search-form label',
145 ]
146 );
147
148 $this->add_control(
149 'label_color',
150 [
151 'label' => __( 'Label Colour', 'propertyhive' ),
152 'type' => \Elementor\Controls_Manager::COLOR,
153 'global' => [
154 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_PRIMARY,
155 ],
156 'selectors' => [
157 '{{WRAPPER}} .property-search-form label' => 'color: {{VALUE}}',
158 ],
159 ]
160 );
161
162 $this->add_control(
163 'label_width',
164 [
165 'label' => esc_html__( 'Label Width', 'propertyhive' ),
166 'type' => \Elementor\Controls_Manager::SELECT,
167 'default' => '',
168 'options' => [
169 '' => esc_html__( 'Default', 'propertyhive' ),
170 'block' => esc_html__( 'Full Width (100%)', 'propertyhive' ),
171 'inline' => esc_html__( 'Inline (auto)', 'propertyhive' ),
172 ],
173 'selectors' => [
174 '{{WRAPPER}} .property-search-form label' => 'display: {{VALUE}};',
175 ],
176 ]
177 );
178
179 $this->add_control(
180 'label_padding',
181 [
182 'label' => __( 'Label Padding', 'propertyhive' ),
183 'type' => \Elementor\Controls_Manager::DIMENSIONS,
184 'size_units' => [ 'px' ],
185 'selectors' => [
186 '{{WRAPPER}} .property-search-form label' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
187 ],
188 ]
189 );
190
191 $this->add_control(
192 'label_margin',
193 [
194 'label' => __( 'Label Margin', 'propertyhive' ),
195 'type' => \Elementor\Controls_Manager::DIMENSIONS,
196 'size_units' => [ 'px' ],
197 'selectors' => [
198 '{{WRAPPER}} .property-search-form label' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
199 ],
200 ]
201 );
202
203 $this->end_controls_section();
204
205 $this->start_controls_section(
206 'input_style_section',
207 [
208 'label' => __( 'Inputs', 'propertyhive' ),
209 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
210 ]
211 );
212
213 $this->add_group_control(
214 \Elementor\Group_Control_Typography::get_type(),
215 [
216 'name' => 'input_typography',
217 'label' => __( 'Input Typography', 'propertyhive' ),
218 'global' => [
219 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_PRIMARY,
220 ],
221 'selector' => '{{WRAPPER}} .property-search-form select, {{WRAPPER}} .property-search-form input[type=\'text\']',
222 ]
223 );
224
225 $this->add_control(
226 'input_color',
227 [
228 'label' => __( 'Input Colour', 'propertyhive' ),
229 'type' => \Elementor\Controls_Manager::COLOR,
230 'global' => [
231 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_PRIMARY,
232 ],
233 'selectors' => [
234 '{{WRAPPER}} .property-search-form select, {{WRAPPER}} .property-search-form input[type=\'text\']' => 'color: {{VALUE}}',
235 ],
236 ]
237 );
238
239 $this->add_control(
240 'input_width',
241 [
242 'label' => esc_html__( 'Input Width', 'propertyhive' ),
243 'type' => \Elementor\Controls_Manager::SELECT,
244 'default' => '',
245 'options' => [
246 '' => esc_html__( 'Default', 'propertyhive' ),
247 'block' => esc_html__( 'Full Width (100%)', 'propertyhive' ),
248 'inline' => esc_html__( 'Inline (auto)', 'propertyhive' ),
249 ],
250 'selectors' => [
251 '{{WRAPPER}} .property-search-form select, {{WRAPPER}} .property-search-form input[type=\'text\']' => 'display: {{VALUE}};',
252 ],
253 ]
254 );
255
256 $this->add_control(
257 'input_padding',
258 [
259 'label' => __( 'Input Padding', 'propertyhive' ),
260 'type' => \Elementor\Controls_Manager::DIMENSIONS,
261 'size_units' => [ 'px' ],
262 'selectors' => [
263 '{{WRAPPER}} .property-search-form select, {{WRAPPER}} .property-search-form input[type=\'text\']' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
264 ],
265 ]
266 );
267
268 $this->add_control(
269 'input_margin',
270 [
271 'label' => __( 'Input Margin', 'propertyhive' ),
272 'type' => \Elementor\Controls_Manager::DIMENSIONS,
273 'size_units' => [ 'px' ],
274 'selectors' => [
275 '{{WRAPPER}} .property-search-form select, {{WRAPPER}} .property-search-form input[type=\'text\']' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
276 ],
277 ]
278 );
279
280 $this->end_controls_section();
281
282 $this->start_controls_section(
283 'button_style_section',
284 [
285 'label' => __( 'Search Button', 'propertyhive' ),
286 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
287 ]
288 );
289
290 $this->add_group_control(
291 \Elementor\Group_Control_Typography::get_type(),
292 [
293 'name' => 'button_typography',
294 'label' => __( 'Button Typography', 'propertyhive' ),
295 'global' => [
296 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_PRIMARY,
297 ],
298 'selector' => '{{WRAPPER}} .property-search-form input[type=\'submit\']',
299 ]
300 );
301
302 $this->add_control(
303 'button_color',
304 [
305 'label' => __( 'Button Colour', 'propertyhive' ),
306 'type' => \Elementor\Controls_Manager::COLOR,
307 'global' => [
308 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_PRIMARY,
309 ],
310 'selectors' => [
311 '{{WRAPPER}} .property-search-form input[type=\'submit\']' => 'color: {{VALUE}}',
312 ],
313 ]
314 );
315
316 $this->add_group_control(
317 \Elementor\Group_Control_Background::get_type(),
318 [
319 'name' => 'button_background',
320 'types' => [ 'classic', 'gradient' ],
321 'selector' => '{{WRAPPER}} .property-search-form input[type=\'submit\']',
322 ]
323 );
324
325 $this->add_control(
326 'button_padding',
327 [
328 'label' => __( 'Button Padding', 'propertyhive' ),
329 'type' => \Elementor\Controls_Manager::DIMENSIONS,
330 'size_units' => [ 'px' ],
331 'selectors' => [
332 '{{WRAPPER}} .property-search-form input[type=\'submit\']' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
333 ],
334 ]
335 );
336
337 $this->add_control(
338 'button_margin',
339 [
340 'label' => __( 'Button Margin', 'propertyhive' ),
341 'type' => \Elementor\Controls_Manager::DIMENSIONS,
342 'size_units' => [ 'px' ],
343 'selectors' => [
344 '{{WRAPPER}} .property-search-form input[type=\'submit\']' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
345 ],
346 ]
347 );
348
349 $this->end_controls_section();
350
351 $this->start_controls_section(
352 'responsive_style_section',
353 [
354 'label' => __( 'Responsive', 'propertyhive' ),
355 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
356 ]
357 );
358
359 $this->add_control(
360 'stack_controls_px',
361 [
362 'type' => \Elementor\Controls_Manager::NUMBER,
363 'label' => esc_html__( 'Stack controls at px', 'propertyhive' ),
364 //'placeholder' => esc_html__( 'e.g. default', 'propertyhive' ),
365 'default' => '',
366 ]
367 );
368
369 $this->end_controls_section();
370 }
371
372 protected function render() {
373
374 $settings = $this->get_settings_for_display();
375
376 if ( isset($settings['stack_controls_px']) && !empty($settings['stack_controls_px']) )
377 {
378 echo '<style type="text/css">
379 @media(max-width:' . (int)$settings['stack_controls_px'] . 'px) {
380 .property-search-form { display:block }
381 .property-search-form .control { display:block; margin-bottom:8px; }
382 .property-search-form input[type=\'submit\'] { width:100%; }
383 }
384 </style>';
385 }
386
387 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Snapshot read-only search state for exact restoration after rendering.
388 $original_get = $_GET;
389 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- GET and REQUEST can differ; preserve each caller's original search state.
390 $original_request = $_REQUEST;
391 $department = isset( $original_get['department'] ) && is_string( $original_get['department'] ) ? sanitize_text_field( wp_unslash( $original_get['department'] ) ) : '';
392 if ( empty( $department ) && isset( $settings['default_department'] ) && is_string( $settings['default_department'] ) ) {
393 $department = sanitize_text_field( $settings['default_department'] );
394 }
395 if ( '' !== $department ) {
396 $_GET['department'] = wp_slash( $department );
397 $_REQUEST['department'] = wp_slash( $department );
398 } else {
399 unset( $_GET['department'], $_REQUEST['department'] );
400 }
401 try {
402 ph_get_search_form( ( isset( $settings['form_id'] ) && ! empty( $settings['form_id'] ) ) ? $settings['form_id'] : 'default' );
403 } finally {
404 if ( array_key_exists( 'department', $original_get ) ) {
405 $_GET['department'] = $original_get['department'];
406 } else {
407 unset( $_GET['department'] );
408 }
409 if ( array_key_exists( 'department', $original_request ) ) {
410 $_REQUEST['department'] = $original_request['department'];
411 } else {
412 unset( $_REQUEST['department'] );
413 }
414 }
415 }
416 }
417