PluginProbe
Property Hive / 2.2.4
Property Hive v2.2.4
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.2.4, at includes/elementor-widgets/property-search-form.php

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