PluginProbe
Property Hive / 1.4.55
Property Hive v1.4.55
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 / ph-form-functions.php

ph-form-functions.php in Property Hive 1.4.55, at includes/ph-form-functions.php

1,339 lines 47.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Form Functions
4 *
5 * Functions related to drawing forms on the frontend.
6 *
7 * @author PropertyHive
8 * @category Core
9 * @package PropertyHive/Functions
10 * @version 1.0.0
11 */
12
13 /**
14 * Main function for drawing entire property search form. We give the ability for an ID to be passed so differently formatted forms can be used
15 * (ie. a homepage search form might be different from a search form on search results)
16 *
17 * @param string $id
18 * @return void
19 */
20 function ph_get_search_form( $id = 'default' ) {
21
22 $form_controls = ph_get_search_form_fields();
23
24 $form_controls = apply_filters( 'propertyhive_search_form_fields_' . $id, $form_controls );
25 $form_controls = apply_filters( 'propertyhive_search_form_fields', $form_controls );
26
27 // We 100% need department so make sure it exists. If it doesn't, set a hidden field
28 if ( !isset($form_controls['department']) )
29 {
30 $original_form_controls = ph_get_search_form_fields();
31 $original_department = $original_form_controls['department'];
32 $original_department['type'] = 'hidden';
33
34 $form_controls['department'] = $original_department;
35 }
36
37 // append hidden order and view fields so these are maintained should a new search be performed
38 foreach ( $_REQUEST as $key => $value )
39 {
40 if ( isset($form_controls[$key]) )
41 continue;
42
43 if ( $key == 'officeID' && isset($form_controls['office']) )
44 continue;
45
46 if ( $key == 'paged' )
47 continue;
48
49 // we've received a field that isn't a standard form control so let's store it in a hidden field so it's not lost
50 if ( is_array($value) )
51 {
52 foreach ( $value as $i => $val )
53 {
54 $form_controls[$key . '-' . $i] = array('type' => 'hidden', 'name' => $key . '[]', 'value' => stripslashes( ph_clean( $val) ));
55 }
56 }
57 else
58 {
59 $form_controls[$key] = array('type' => 'hidden', 'value' => stripslashes( ph_clean( $value) ));
60 }
61 }
62
63 ph_get_template( 'global/search-form.php', array( 'form_controls' => $form_controls, 'id' => $id ) );
64
65 }
66
67 /**
68 * Get default fields to be shown on search forms
69 *
70 * @return array
71 */
72 function ph_get_search_form_fields()
73 {
74 $fields = array();
75
76 $departments = ph_get_departments();
77
78 $department_options = array();
79 $default_value = '';
80
81 foreach ( $departments as $key => $value )
82 {
83 if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' )
84 {
85 $department_options[$key] = $value;
86
87 if ($default_value == '' && get_option( 'propertyhive_primary_department' ) == $key )
88 {
89 $default_value = $key;
90 }
91 }
92 }
93
94 $fields['department'] = array(
95 'type' => 'radio',
96 'options' => $department_options,
97 'value' => $default_value
98 );
99
100 if ( array_key_exists('residential-sales', $departments) || array_key_exists('residential-lettings', $departments) )
101 {
102 if ( array_key_exists('residential-sales', $departments) )
103 {
104 $prices = array(
105 '' => __( 'No preference', 'propertyhive' ),
106 '100000' => '&pound;100,000',
107 '150000' => '&pound;150,000',
108 '200000' => '&pound;200,000',
109 '250000' => '&pound;250,000',
110 '300000' => '&pound;300,000',
111 '500000' => '&pound;500,000',
112 '750000' => '&pound;750,000',
113 '1000000' => '&pound;1,000,000'
114 );
115
116 $fields['minimum_price'] = array(
117 'type' => 'select',
118 'show_label' => true,
119 'label' => __( 'Min Price', 'propertyhive' ),
120 'before' => '<div class="control control-minimum_price sales-only">',
121 'options' => $prices
122 );
123
124 $fields['maximum_price'] = array(
125 'type' => 'select',
126 'show_label' => true,
127 'label' => __( 'Max Price', 'propertyhive' ),
128 'before' => '<div class="control control-maximum_price sales-only">',
129 'options' => $prices
130 );
131 }
132
133 if ( array_key_exists('residential-lettings', $departments) )
134 {
135 $prices = array(
136 '' => __( 'No preference', 'propertyhive' ),
137 '500' => '&pound;500 PCM',
138 '600' => '&pound;600 PCM',
139 '750' => '&pound;750 PCM',
140 '1000' => '&pound;1000 PCM',
141 '1250' => '&pound;1250 PCM',
142 '1500' => '&pound;1500 PCM',
143 '2000' => '&pound;2000 PCM'
144 );
145
146 $fields['minimum_rent'] = array(
147 'type' => 'select',
148 'show_label' => true,
149 'label' => __( 'Min Rent', 'propertyhive' ),
150 'before' => '<div class="control control-minimum_rent lettings-only">',
151 'options' => $prices
152 );
153
154 $fields['maximum_rent'] = array(
155 'type' => 'select',
156 'show_label' => true,
157 'label' => __( 'Max Rent', 'propertyhive' ),
158 'before' => '<div class="control control-maximum_rent lettings-only">',
159 'options' => $prices
160 );
161 }
162
163 $fields['minimum_bedrooms'] = array(
164 'type' => 'select',
165 'show_label' => true,
166 'label' => __( 'Min Beds', 'propertyhive' ),
167 'before' => '<div class="control control-minimum_bedrooms residential-only">',
168 'options' => array( '' => __( 'No preference', 'propertyhive' ), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5)
169 );
170
171 $fields['property_type'] = array(
172 'type' => 'property_type',
173 'show_label' => true,
174 'before' => '<div class="control control-property_type residential-only">',
175 'label' => __( 'Type', 'propertyhive' ),
176 );
177 }
178
179 if ( array_key_exists('commercial', $departments) )
180 {
181 $sizes = array(
182 '' => __( 'No preference', 'propertyhive' ),
183 '250' => '250 sq ft',
184 '500' => '500 sq ft',
185 '1000' => '1,000 sq ft',
186 '2500' => '2,500 sq ft',
187 '5000' => '5,000 sq ft',
188 '10000' => '10,000 sq ft',
189 '25000' => '25,000 sq ft',
190 '50000' => '50,000 sq ft'
191 );
192
193 $fields['minimum_floor_area'] = array(
194 'type' => 'select',
195 'show_label' => true,
196 'label' => __( 'Min Floor Area', 'propertyhive' ),
197 'before' => '<div class="control control-minimum_floor_area commercial-only">',
198 'options' => $sizes
199 );
200
201 $fields['maximum_floor_area'] = array(
202 'type' => 'select',
203 'show_label' => true,
204 'label' => __( 'Max Floor Area', 'propertyhive' ),
205 'before' => '<div class="control control-maximum_floor_area commercial-only">',
206 'options' => $sizes
207 );
208
209 // Property Type
210 $options = array( '' => __( 'No preference', 'propertyhive' ) );
211 $args = array(
212 'hide_empty' => false,
213 'parent' => 0
214 );
215 $terms = get_terms( 'commercial_property_type', $args );
216
217 $selected_value = '';
218 if ( !empty( $terms ) && !is_wp_error( $terms ) )
219 {
220 foreach ($terms as $term)
221 {
222 $options[$term->term_id] = $term->name;
223
224 $args = array(
225 'hide_empty' => false,
226 'parent' => $term->term_id
227 );
228 $subterms = get_terms( 'commercial_property_type', $args );
229
230 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
231 {
232 foreach ($subterms as $term)
233 {
234 $options[$term->term_id] = '- ' . $term->name;
235 }
236 }
237 }
238 }
239
240 $fields['commercial_property_type'] = array(
241 'type' => 'select',
242 'show_label' => true,
243 'before' => '<div class="control control-commercial_property_type commercial-only">',
244 'label' => __( 'Type', 'propertyhive' ),
245 'options' => $options
246 );
247 }
248
249 return $fields;
250 }
251
252 /**
253 * Main function for drawing property enquiry form.
254 *
255 * @param string $id
256 * @return void
257 */
258 function propertyhive_enquiry_form( $property_id = '' )
259 {
260 $form_controls = ph_get_property_enquiry_form_fields( $property_id );
261
262 $form_controls = apply_filters( 'propertyhive_property_enquiry_form_fields', $form_controls );
263
264 ph_get_template( 'global/make-enquiry-form.php',array( 'form_controls' => $form_controls ) );
265 }
266
267 /**
268 * Get default fields to be shown on search forms
269 *
270 * @return array
271 */
272 function ph_get_property_enquiry_form_fields( $property_id = '' )
273 {
274 global $post;
275
276 $fields = array();
277
278 $fields['property_id'] = array(
279 'type' => 'hidden',
280 'value' => ( $property_id != '' ? $property_id : $post->ID )
281 );
282
283 $fields['name'] = array(
284 'type' => 'text',
285 'label' => __( 'Full Name', 'propertyhive' ),
286 'required' => true
287 );
288 if ( is_user_logged_in() )
289 {
290 $current_user = wp_get_current_user();
291
292 $fields['name']['value'] = $current_user->display_name;
293 }
294
295 $fields['email_address'] = array(
296 'type' => 'email',
297 'label' => __( 'Email Address', 'propertyhive' ),
298 'required' => true
299 );
300 if ( is_user_logged_in() )
301 {
302 $current_user = wp_get_current_user();
303
304 $fields['email_address']['value'] = $current_user->user_email;
305 }
306
307 $fields['telephone_number'] = array(
308 'type' => 'text',
309 'label' => __( 'Number', 'propertyhive' ),
310 'required' => true
311 );
312
313 $fields['message'] = array(
314 'type' => 'textarea',
315 'label' => __( 'Message', 'propertyhive' ),
316 'required' => true
317 );
318
319 if ( get_option( 'propertyhive_property_enquiry_form_disclaimer', '' ) != '' )
320 {
321 $disclaimer = get_option( 'propertyhive_property_enquiry_form_disclaimer', '' );
322
323 $fields['disclaimer'] = array(
324 'type' => 'checkbox',
325 'label' => $disclaimer,
326 'label_style' => 'width:100%;',
327 'required' => true
328 );
329 }
330
331 return $fields;
332 }
333
334 /**
335 * Get default fields to be shown on applicant registration forms
336 *
337 * @return array
338 */
339 function ph_get_user_details_form_fields()
340 {
341 global $post;
342
343 if ( is_user_logged_in() )
344 {
345 $current_user = wp_get_current_user();
346
347 if ( $current_user instanceof WP_User )
348 {
349 $contact = new PH_Contact( '', $current_user->ID );
350 }
351 }
352
353 $fields = array();
354
355 $fields['name'] = array(
356 'type' => 'text',
357 'label' => __( 'Full Name', 'propertyhive' ),
358 'required' => true
359 );
360 if ( is_user_logged_in() && $current_user instanceof WP_User )
361 {
362 $fields['name']['value'] = $current_user->display_name;
363 }
364
365 $fields['email_address'] = array(
366 'type' => 'email',
367 'label' => __( 'Email Address', 'propertyhive' ),
368 'required' => true
369 );
370 if ( is_user_logged_in() && $current_user instanceof WP_User )
371 {
372 $fields['email_address']['value'] = $current_user->user_email;
373 }
374
375 $fields['telephone_number'] = array(
376 'type' => 'text',
377 'label' => __( 'Telephone Number', 'propertyhive' ),
378 'required' => false
379 );
380 if ( is_user_logged_in() && $current_user instanceof WP_User )
381 {
382 $fields['telephone_number']['value'] = $contact->telephone_number;
383 }
384
385 if ( get_option( 'propertyhive_applicant_users', '' ) == 'yes' )
386 {
387 $fields['password'] = array(
388 'type' => 'password',
389 'label' => __( 'Password', 'propertyhive' ),
390 'required' => true
391 );
392
393 $fields['password2'] = array(
394 'type' => 'password',
395 'label' => __( 'Confirm Password', 'propertyhive' ),
396 'required' => true
397 );
398 }
399
400 return $fields;
401 }
402
403 /**
404 * Get default fields to be shown on applicant registration forms
405 *
406 * @return array
407 */
408 function ph_get_applicant_requirements_form_fields()
409 {
410 global $post;
411
412 if ( is_user_logged_in() )
413 {
414 $current_user = wp_get_current_user();
415 $applicant_profile = false;
416
417 if ( $current_user instanceof WP_User )
418 {
419 $contact = new PH_Contact( '', $current_user->ID );
420
421 if ( is_array($contact->contact_types) && in_array('applicant', $contact->contact_types) )
422 {
423 if (
424 $contact->applicant_profiles != '' &&
425 $contact->applicant_profiles > 0 &&
426 $contact->applicant_profile_0 != '' &&
427 is_array($contact->applicant_profile_0)
428 )
429 {
430 $applicant_profile = $contact->applicant_profile_0;
431 }
432 }
433 }
434 }
435
436 $fields = array();
437
438 $offices = array();
439 $value = '';
440
441 $args = array(
442 'post_type' => 'office',
443 'nopaging' => true,
444 'orderby' => 'title',
445 'order' => 'ASC'
446 );
447
448 $office_query = new WP_Query( $args );
449
450 if ( $office_query->have_posts() )
451 {
452 while ( $office_query->have_posts() )
453 {
454 $office_query->the_post();
455
456 $offices[get_the_ID()] = get_the_title();
457
458 if ( get_post_meta(get_the_ID(), 'primary', TRUE) == 1 )
459 {
460 $value = get_the_ID();
461 }
462 }
463 }
464 wp_reset_postdata();
465
466 $fields['office_id'] = array(
467 'type' => ( (count($offices) <= 1) ? 'hidden' : 'select' ),
468 'label' => __( 'Office', 'propertyhive' ),
469 'required' => false,
470 'show_label' => true,
471 'value' => $value,
472 'options' => $offices
473 );
474
475 $departments = array();
476 $value = '';
477 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' )
478 {
479 $departments['residential-sales'] = __( 'Properties To Buy', 'propertyhive' );
480 if ($value == '' && (get_option( 'propertyhive_primary_department' ) == 'residential-sales' || get_option( 'propertyhive_primary_department' ) === FALSE) )
481 {
482 $value = 'residential-sales';
483 }
484 }
485 if ( get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
486 {
487 $departments['residential-lettings'] = __( 'Properties For Rent', 'propertyhive' );
488 if ($value == '' && get_option( 'propertyhive_primary_department' ) == 'residential-lettings')
489 {
490 $value = 'residential-lettings';
491 }
492 }
493 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
494 {
495 $departments['commercial'] = __( 'Commercial Properties', 'propertyhive' );
496 if ($value == '' && get_option( 'propertyhive_primary_department' ) == 'commercial')
497 {
498 $value = 'commercial';
499 }
500 }
501 $fields['department'] = array(
502 'type' => 'radio',
503 'label' => __( 'Looking For', 'propertyhive' ),
504 'required' => true,
505 'show_label' => true,
506 'value' => $value,
507 'options' => $departments
508 );
509 if ( is_user_logged_in() && isset($applicant_profile['department']) )
510 {
511 $fields['department']['value'] = $applicant_profile['department'];
512 }
513 if ( count($departments) == 1 )
514 {
515 $fields['department']['type'] = 'hidden';
516 }
517
518 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' || get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
519 {
520 $fields['maximum_price'] = array(
521 'type' => 'number',
522 'label' => __( 'Maximum Price', 'propertyhive' ),
523 'style' => 'max-width:150px;',
524 'before' => '<div class="control control-minimum_price sales-only">',
525 'required' => false
526 );
527 if ( is_user_logged_in() && isset($applicant_profile['max_price']) )
528 {
529 $fields['maximum_price']['value'] = $applicant_profile['max_price'];
530 }
531
532 $fields['maximum_rent'] = array(
533 'type' => 'number',
534 'label' => __( 'Maximum Rent', 'propertyhive' ) . ' (PCM)',
535 'style' => 'max-width:150px;',
536 'before' => '<div class="control control-minimum_price lettings-only">',
537 'required' => false
538 );
539 if ( is_user_logged_in() && isset($applicant_profile['max_rent']) )
540 {
541 $fields['maximum_rent']['value'] = $applicant_profile['max_rent'];
542 }
543
544 $fields['minimum_bedrooms'] = array(
545 'type' => 'number',
546 'label' => __( 'Minimum Bedrooms', 'propertyhive' ),
547 'style' => 'max-width:80px;',
548 'before' => '<div class="control control-minimum_bedrooms residential-only">',
549 'required' => false
550 );
551 if ( is_user_logged_in() && isset($applicant_profile['min_beds']) )
552 {
553 $fields['minimum_bedrooms']['value'] = $applicant_profile['min_beds'];
554 }
555
556 $args = array(
557 'hide_empty' => false,
558 'parent' => 0
559 );
560 $terms = get_terms( 'property_type', $args );
561
562 $options = array();
563
564 $selected_value = '';
565 if ( !empty( $terms ) && !is_wp_error( $terms ) )
566 {
567 $options = array( '' => __( 'All Property Types', 'properthive' ) );
568
569 foreach ($terms as $term)
570 {
571 $options[$term->term_id] = $term->name;
572
573 $args = array(
574 'hide_empty' => false,
575 'parent' => $term->term_id
576 );
577 $subterms = get_terms( 'property_type', $args );
578
579 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
580 {
581 foreach ($subterms as $term)
582 {
583 $options[$term->term_id] = '- ' . $term->name;
584 }
585 }
586 }
587 }
588
589 if ( !empty($options) )
590 {
591 $fields['property_type'] = array(
592 'type' => 'select',
593 'label' => __( 'Property Type', 'propertyhive' ),
594 'before' => '<div class="control control-property_type residential-only">',
595 'required' => false,
596 'options' => $options,
597 );
598
599 if ( is_user_logged_in() && isset($applicant_profile['property_types']) && is_array($applicant_profile['property_types']) && !empty($applicant_profile['property_types']) )
600 {
601 $fields['property_type']['value'] = $applicant_profile['property_types'][0];
602 }
603 }
604 }
605
606 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
607 {
608 $fields['available_as_sale'] = array(
609 'type' => 'checkbox',
610 'label' => __( 'For Sale', 'propertyhive' ),
611 'before' => '<div class="control control-available_as_sale commercial-only">',
612 'required' => false,
613 );
614 if ( is_user_logged_in() && isset($applicant_profile['available_as']) && in_array('sale', $applicant_profile['available_as']) )
615 {
616 $fields['available_as_sale']['checked'] = true;
617 }
618
619 $fields['available_as_rent'] = array(
620 'type' => 'checkbox',
621 'label' => __( 'To Rent', 'propertyhive' ),
622 'before' => '<div class="control control-available_as_rent commercial-only">',
623 'required' => false,
624 );
625 if ( is_user_logged_in() && isset($applicant_profile['available_as']) && in_array('rent', $applicant_profile['available_as']) )
626 {
627 $fields['available_as_rent']['checked'] = true;
628 }
629
630 $fields['minimum_floor_area'] = array(
631 'type' => 'number',
632 'label' => __( 'Min Floor Area (Sq Ft)', 'propertyhive' ),
633 'style' => 'max-width:150px;',
634 'before' => '<div class="control control-minimum_floor_area commercial-only">',
635 'required' => false
636 );
637 if ( is_user_logged_in() && isset($applicant_profile['min_floor_area']) )
638 {
639 $fields['minimum_floor_area']['value'] = $applicant_profile['min_floor_area'];
640 }
641
642 $fields['maximum_floor_area'] = array(
643 'type' => 'number',
644 'label' => __( 'Max Floor Area (Sq Ft)', 'propertyhive' ),
645 'style' => 'max-width:150px;',
646 'before' => '<div class="control control-maximum_floor_area commercial-only">',
647 'required' => false
648 );
649 if ( is_user_logged_in() && isset($applicant_profile['max_floor_area']) )
650 {
651 $fields['maximum_floor_area']['value'] = $applicant_profile['max_floor_area'];
652 }
653
654 $args = array(
655 'hide_empty' => false,
656 'parent' => 0
657 );
658 $terms = get_terms( 'commercial_property_type', $args );
659
660 $options = array();
661
662 $selected_value = '';
663 if ( !empty( $terms ) && !is_wp_error( $terms ) )
664 {
665 $options = array( '' => __( 'All Property Types', 'properthive' ) );
666
667 foreach ($terms as $term)
668 {
669 $options[$term->term_id] = $term->name;
670
671 $args = array(
672 'hide_empty' => false,
673 'parent' => $term->term_id
674 );
675 $subterms = get_terms( 'commercial_property_type', $args );
676
677 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
678 {
679 foreach ($subterms as $term)
680 {
681 $options[$term->term_id] = '- ' . $term->name;
682 }
683 }
684 }
685 }
686
687 if ( !empty($options) )
688 {
689 $fields['commercial_property_type'] = array(
690 'type' => 'select',
691 'label' => __( 'Property Type', 'propertyhive' ),
692 'before' => '<div class="control control-commercial_property_type commercial-only">',
693 'required' => false,
694 'options' => $options,
695 );
696
697 if ( is_user_logged_in() && isset($applicant_profile['commercial_property_types']) && is_array($applicant_profile['commercial_property_types']) && !empty($applicant_profile['commercial_property_types']) )
698 {
699 $fields['commercial_property_type']['value'] = $applicant_profile['commercial_property_types'][0];
700 }
701 }
702 }
703
704 $args = array(
705 'hide_empty' => false,
706 'parent' => 0
707 );
708 $terms = get_terms( 'location', $args );
709
710 $options = array();
711
712 $selected_value = '';
713 if ( !empty( $terms ) && !is_wp_error( $terms ) )
714 {
715 $options = array( '' => __( 'All Locations', 'properthive' ) );
716
717 foreach ($terms as $term)
718 {
719 $options[$term->term_id] = $term->name;
720
721 $args = array(
722 'hide_empty' => false,
723 'parent' => $term->term_id
724 );
725 $subterms = get_terms( 'location', $args );
726
727 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
728 {
729 foreach ($subterms as $term)
730 {
731 $options[$term->term_id] = '- ' . $term->name;
732 }
733 }
734 }
735 }
736
737 if ( !empty($options) )
738 {
739 $fields['location'] = array(
740 'type' => 'select',
741 'label' => __( 'Location', 'propertyhive' ),
742 'required' => false,
743 'options' => $options,
744 );
745
746 if ( is_user_logged_in() && isset($applicant_profile['locations']) && is_array($applicant_profile['locations']) && !empty($applicant_profile['locations']) )
747 {
748 $fields['location']['value'] = $applicant_profile['locations'][0];
749 }
750 }
751
752 $fields['additional_requirements'] = array(
753 'type' => 'textarea',
754 'label' => __( 'Additional Requirements', 'propertyhive' ),
755 'required' => false
756 );
757 if ( is_user_logged_in() && isset($applicant_profile['notes']) )
758 {
759 $fields['additional_requirements']['value'] = $applicant_profile['notes'];
760 }
761
762 return $fields;
763 }
764
765 /**
766 * Output individual field
767 *
768 * @return void
769 */
770 function ph_form_field( $key, $field )
771 {
772 global $post;
773
774 $output = '';
775
776 switch ($field['type'])
777 {
778 case "text":
779 case "email":
780 case "date":
781 case "number":
782 case "password":
783 {
784 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
785 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
786 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
787 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
788 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
789 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ( ( $field['type'] == 'date' ) ? 'dd/mm/yyyy' : '' );
790 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
791 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
792
793 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
794 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
795 {
796 $field['value'] = sanitize_text_field( wp_unslash( $_GET[$key] ) );
797 }
798 else
799 {
800 if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) )
801 {
802 $value = get_post_meta( $post->ID, '_' . $key, true );
803 if ( $value != '' )
804 {
805 $field['value'] = $value;
806 }
807 }
808 }
809
810 $output .= $field['before'];
811
812 if ($field['show_label'])
813 {
814 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
815 if ($field['required'])
816 {
817 $output .= '<span class="required"> *</span>';
818 }
819 $output .= '</label>';
820 }
821
822 $output .= '<input
823 type="' . esc_attr( $field['type'] ) . '"
824 name="' . esc_attr( $key ) . '"
825 id="' . esc_attr( $key ) . '"
826 value="' . esc_attr( $field['value'] ) . '"
827 placeholder="' . esc_attr( $field['placeholder'] ) . '"
828 class="' . esc_attr( $field['class'] ) . '"
829 style="' . esc_attr( $field['style'] ) . '"
830 ' . ( ($field['required']) ? 'required' : '' ) . '
831 >';
832
833 $output .= $field['after'];
834
835 break;
836 }
837 case "textarea":
838 {
839 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
840 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
841 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
842 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
843 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
844 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
845 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
846
847 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
848 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
849 {
850 $field['value'] = sanitize_textarea_field( wp_unslash( $_GET[$key] ) );
851 }
852 else
853 {
854 if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) )
855 {
856 $value = get_post_meta( $post->ID, '_' . $key, true );
857 if ( $value != '' )
858 {
859 $field['value'] = $value;
860 }
861 }
862 }
863
864 $output .= $field['before'];
865
866 if ($field['show_label'])
867 {
868 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
869 if ($field['required'])
870 {
871 $output .= '<span class="required"> *</span>';
872 }
873 $output .= '</label>';
874 }
875
876 $output .= '<textarea
877 name="' . esc_attr( $key ) . '"
878 id="' . esc_attr( $key ) . '"
879 placeholder="' . esc_attr( $field['placeholder'] ) . '"
880 class="' . esc_attr( $field['class'] ) . '"
881 ' . ( ($field['required']) ? 'required' : '' ) . '
882 >' . esc_attr( $field['value'] ) . '</textarea>';
883
884 $output .= $field['after'];
885
886 break;
887 }
888 case "checkbox":
889 {
890 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
891 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
892 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
893 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
894 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
895 $field['label_style'] = isset( $field['label_style'] ) ? $field['label_style'] : '';
896 $field['value'] = isset( $field['value'] ) ? $field['value'] : 'yes';
897 $field['checked'] = isset( $field['checked'] ) ? $field['checked'] : false;
898 if ( isset( $_GET[$key] ) && sanitize_text_field(wp_unslash($_GET[$key])) == $field['value'] )
899 {
900 $field['checked'] = true;
901 }
902 else
903 {
904 if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) )
905 {
906 $value = get_post_meta( $post->ID, '_' . $key, true );
907 if ( $value == 'yes' )
908 {
909 $field['checked'] = true;
910 }
911 }
912 }
913
914 $output .= $field['before'];
915
916 $output .= '<label style="' . esc_attr( $field['label_style'] ) . '"><input
917 type="' . esc_attr( $field['type'] ) . '"
918 name="' . esc_attr( $key ) . '"
919 value="' . esc_attr( $field['value'] ) . '"
920 class="' . esc_attr( $field['class'] ) . '"
921 ' . checked( $field['checked'], true, false ) . '
922 >';
923 if ($field['show_label'])
924 {
925 $output .= ' <span>' . $field['label'] . '</span>';
926 }
927 $output .= '</label>';
928
929 $output .= $field['after'];
930
931 break;
932 }
933 case "radio":
934 {
935 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
936 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
937 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
938 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : false;
939 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
940
941 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
942 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
943 {
944 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
945 }
946
947 $output .= $field['before'];
948
949 if ($field['show_label'])
950 {
951 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
952 }
953
954 foreach ( $field['options'] as $option_key => $value )
955 {
956 $output .= '<label><input
957 type="' . esc_attr( $field['type'] ) . '"
958 name="' . esc_attr( $key ) . '"
959 value="' . esc_attr( $option_key ) . '"
960 class="' . esc_attr( $field['class'] ) . '"
961 ' . checked( esc_attr( $field['value'] ), esc_attr( $option_key ), false ) . '
962 > ' . esc_html( $value ) . '</label>';
963 }
964
965 $output .= $field['after'];
966
967 break;
968 }
969 case "select":
970 {
971 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
972 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
973 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
974 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
975 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
976 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
977 $field['options'] = ( isset( $field['options'] ) && is_array( $field['options'] ) ) ? $field['options'] : array();
978 $field['multiselect'] = isset( $field['multiselect'] ) ? $field['multiselect'] : false;
979
980 if ( $field['multiselect'] )
981 {
982 wp_enqueue_script( 'multiselect' );
983 }
984
985 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
986 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
987 {
988 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
989 }
990 else
991 {
992 if ( !is_post_type_archive('property') && isset($post->ID) )
993 {
994 $value = get_post_meta( $post->ID, '_' . $key, true );
995 if ( $value != '' )
996 {
997 $field['value'] = $value;
998 }
999 }
1000 }
1001
1002 $output .= $field['before'];
1003
1004 if ($field['show_label'])
1005 {
1006 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
1007 if ($field['required'])
1008 {
1009 $output .= '<span class="required"> *</span>';
1010 }
1011 $output .= '</label>';
1012 }
1013
1014 $blank_option = '';
1015 foreach ( $field['options'] as $option_key => $value )
1016 {
1017 if ( $field['multiselect'] && $option_key == '' )
1018 {
1019 $blank_option = $value;
1020 continue;
1021 }
1022 }
1023
1024 $output .= '<select
1025 name="' . esc_attr( $key ) . ( $field['multiselect'] ? '[]' : '' ) . '"
1026 id="' . esc_attr( $key ) . '"
1027 class="' . esc_attr( $field['class'] ) . ( $field['multiselect'] ? ' ph-form-multiselect' : '' ) . '"
1028 ' . ( $field['multiselect'] ? ' multiple="multiple"' : '' ) . '
1029 data-blank-option="' . esc_attr($blank_option) . '"
1030 >';
1031
1032 foreach ( $field['options'] as $option_key => $value )
1033 {
1034 if ( $field['multiselect'] && $option_key == '' )
1035 {
1036 // Skip because we don't want a blank option in the multiselect. Instead use $value as the placeholder
1037 continue;
1038 }
1039
1040 $output .= '<option
1041 value="' . esc_attr( $option_key ) . '"';
1042 if ( !$field['multiselect'] )
1043 {
1044 $output .= selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false );
1045 }
1046 else
1047 {
1048 if ( isset($_REQUEST[$key]) && is_array($_REQUEST[$key]) && in_array($option_key, $_REQUEST[$key]) )
1049 {
1050 $output .= ' selected';
1051 }
1052 }
1053 $output .= '>' . esc_html( $value ) . '</option>';
1054 }
1055
1056 $output .= '</select>';
1057
1058 $output .= $field['after'];
1059
1060 break;
1061 }
1062 case "office":
1063 {
1064 $key = 'officeID';
1065
1066 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1067 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1068 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1069 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1070 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1071
1072 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1073 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1074 {
1075 $field['value'] = (int)$_GET[$key];
1076 }
1077
1078 $output .= $field['before'];
1079
1080 if ($field['show_label'])
1081 {
1082 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1083 }
1084
1085 $output .= '<select
1086 name="' . esc_attr( $key ) . '"
1087 id="' . esc_attr( $key ) . '"
1088 class="' . esc_attr( $field['class'] ) . '"
1089 >';
1090
1091 $output .= '<option
1092 value=""
1093 ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '
1094 >' . esc_html( __( 'No preference', 'propertyhive' ) ) . '</option>';
1095
1096 $args = array(
1097 'post_type' => 'office',
1098 'nopaging' => true,
1099 'orderby' => 'title',
1100 'order' => 'ASC'
1101 );
1102 $office_query = new WP_Query($args);
1103
1104 if ($office_query->have_posts())
1105 {
1106 while ($office_query->have_posts())
1107 {
1108 $office_query->the_post();
1109
1110 $output .= '<option
1111 value="' . esc_attr( $post->ID ) . '"
1112 ' . selected( esc_attr( $field['value'] ), esc_attr( $post->ID ), false ) . '
1113 >' . esc_html( get_the_title() ) . '</option>';
1114
1115 }
1116 }
1117 wp_reset_postdata();
1118
1119 $output .= '</select>';
1120
1121 $output .= $field['after'];
1122
1123 break;
1124 }
1125 case "country":
1126 {
1127 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1128 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1129 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1130 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1131 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1132
1133 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1134 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1135 {
1136 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1137 }
1138
1139 $output .= $field['before'];
1140
1141 if ($field['show_label'])
1142 {
1143 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1144 }
1145
1146 $output .= '<select
1147 name="' . esc_attr( $key ) . '"
1148 id="' . esc_attr( $key ) . '"
1149 class="' . esc_attr( $field['class'] ) . '"
1150 >';
1151
1152 $output .= '<option
1153 value=""
1154 ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '
1155 >' . esc_html( __( 'No preference', 'propertyhive' ) ) . '</option>';
1156
1157 $countries = get_option( 'propertyhive_countries', array() );
1158 if ( is_array($countries) && !empty($countries) )
1159 {
1160 $ph_countries = new PH_Countries;
1161
1162 foreach ( $countries as $country )
1163 {
1164 $ph_country = $ph_countries->get_country( $country );
1165
1166 if ( $ph_country !== FALSE )
1167 {
1168 $output .= '<option
1169 value="' . esc_attr( $country ) . '"
1170 ' . selected( esc_attr( $field['value'] ), esc_attr( $country ), false ) . '
1171 >' . esc_html( $ph_country['name'] ) . '</option>';
1172 }
1173 }
1174 }
1175
1176 $output .= '</select>';
1177
1178 $output .= $field['after'];
1179
1180 break;
1181 }
1182 case "hidden":
1183 {
1184 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1185 $field['name'] = isset( $field['name'] ) ? $field['name'] : $key;
1186 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1187 {
1188 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1189 }
1190
1191 $output .= '<input type="hidden" name="' . esc_attr( $field['name'] ) . '" value="' . $field['value'] . '">';
1192 break;
1193 }
1194 case "html":
1195 {
1196 $field['html'] = isset( $field['html'] ) ? $field['html'] : '';
1197 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1198 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1199
1200 $output .= $field['before'];
1201 $output .= $field['html'];
1202 $output .= $field['after'];
1203
1204 break;
1205 }
1206 case "recaptcha":
1207 {
1208 $field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : '';
1209
1210 $output .= '<script src="https://www.google.com/recaptcha/api.js"></script>
1211 <div class="g-recaptcha" data-sitekey="' . $field['site_key'] . '"></div>';
1212 break;
1213 }
1214 default:
1215 {
1216 if ( taxonomy_exists($field['type']) )
1217 {
1218 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1219 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1220 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1221 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1222 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1223 $field['blank_option'] = isset( $field['blank_option'] ) ? $field['blank_option'] : __( 'No preference', 'propertyhive' );
1224 $field['parent_terms_only'] = isset( $field['parent_terms_only'] ) ? $field['parent_terms_only'] : false;
1225 $field['multiselect'] = isset( $field['multiselect'] ) ? $field['multiselect'] : false;
1226
1227 if ( $field['multiselect'] )
1228 {
1229 wp_enqueue_script( 'multiselect' );
1230 }
1231
1232 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1233 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1234 {
1235 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1236 }
1237
1238 $output .= $field['before'];
1239
1240 if ($field['show_label'])
1241 {
1242 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1243 }
1244
1245 $output .= '<select
1246 name="' . esc_attr( $key ) . ( $field['multiselect'] ? '[]' : '' ) . '"
1247 id="' . esc_attr( $key ) . '"
1248 class="' . esc_attr( $field['class'] ) . ( $field['multiselect'] ? ' ph-form-multiselect' : '' ) . '"
1249 ' . ( $field['multiselect'] ? ' multiple="multiple"' : '' ) . '
1250 data-blank-option="' . esc_attr($field['blank_option']) . '"
1251 >';
1252
1253 $options = array( '' => $field['blank_option'] );
1254 $args = array(
1255 'hide_empty' => false,
1256 'parent' => 0
1257 );
1258 $terms = get_terms( $field['type'], $args );
1259
1260 $selected_value = '';
1261 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1262 {
1263 foreach ($terms as $term)
1264 {
1265 $options[$term->term_id] = $term->name;
1266
1267 if (
1268 !isset($field['parent_terms_only'])
1269 ||
1270 (
1271 isset($field['parent_terms_only']) &&
1272 $field['parent_terms_only'] === false
1273 )
1274 )
1275 {
1276 $args = array(
1277 'hide_empty' => false,
1278 'parent' => $term->term_id
1279 );
1280 $subterms = get_terms( $field['type'], $args );
1281
1282 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
1283 {
1284 foreach ($subterms as $term)
1285 {
1286 $options[$term->term_id] = '- ' . $term->name;
1287
1288 $args = array(
1289 'hide_empty' => false,
1290 'parent' => $term->term_id
1291 );
1292 $subsubterms = get_terms( $field['type'], $args );
1293
1294 if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
1295 {
1296 foreach ($subsubterms as $term)
1297 {
1298 $options[$term->term_id] = '- ' . $term->name;
1299 }
1300 }
1301 }
1302 }
1303 }
1304 }
1305 }
1306
1307 foreach ( $options as $option_key => $value )
1308 {
1309 if ( $field['multiselect'] && $option_key == '' )
1310 {
1311 // Skip because we don't want a blank option in the multiselect. Instead use $value as the placeholder
1312 continue;
1313 }
1314
1315 $output .= '<option
1316 value="' . esc_attr( $option_key ) . '"';
1317 if ( !$field['multiselect'] )
1318 {
1319 $output .= selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false );
1320 }
1321 else
1322 {
1323 if ( isset($_REQUEST[$key]) && is_array($_REQUEST[$key]) && in_array($option_key, $_REQUEST[$key]) )
1324 {
1325 $output .= ' selected';
1326 }
1327 }
1328 $output .= '>' . esc_html( $value ) . '</option>';
1329 }
1330
1331 $output .= '</select>';
1332
1333 $output .= $field['after'];
1334 }
1335 }
1336 }
1337
1338 echo $output;
1339 }