PluginProbe
Property Hive / 1.4.49
Property Hive v1.4.49
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.49, at includes/ph-form-functions.php

1,270 lines 44.2 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
979 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
980 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
981 {
982 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
983 }
984 else
985 {
986 if ( !is_post_type_archive('property') && isset($post->ID) )
987 {
988 $value = get_post_meta( $post->ID, '_' . $key, true );
989 if ( $value != '' )
990 {
991 $field['value'] = $value;
992 }
993 }
994 }
995
996 $output .= $field['before'];
997
998 if ($field['show_label'])
999 {
1000 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
1001 if ($field['required'])
1002 {
1003 $output .= '<span class="required"> *</span>';
1004 }
1005 $output .= '</label>';
1006 }
1007
1008 $output .= '<select
1009 name="' . esc_attr( $key ) . '"
1010 id="' . esc_attr( $key ) . '"
1011 class="' . esc_attr( $field['class'] ) . '"
1012 >';
1013
1014 foreach ( $field['options'] as $option_key => $value )
1015 {
1016 $output .= '<option
1017 value="' . esc_attr( $option_key ) . '"
1018 ' . selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false ) . '
1019 >' . esc_html( $value ) . '</option>';
1020 }
1021
1022 $output .= '</select>';
1023
1024 $output .= $field['after'];
1025
1026 break;
1027 }
1028 case "office":
1029 {
1030 $key = 'officeID';
1031
1032 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1033 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1034 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1035 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1036 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1037
1038 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1039 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1040 {
1041 $field['value'] = (int)$_GET[$key];
1042 }
1043
1044 $output .= $field['before'];
1045
1046 if ($field['show_label'])
1047 {
1048 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1049 }
1050
1051 $output .= '<select
1052 name="' . esc_attr( $key ) . '"
1053 id="' . esc_attr( $key ) . '"
1054 class="' . esc_attr( $field['class'] ) . '"
1055 >';
1056
1057 $output .= '<option
1058 value=""
1059 ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '
1060 >' . esc_html( __( 'No preference', 'propertyhive' ) ) . '</option>';
1061
1062 $args = array(
1063 'post_type' => 'office',
1064 'nopaging' => true,
1065 'orderby' => 'title',
1066 'order' => 'ASC'
1067 );
1068 $office_query = new WP_Query($args);
1069
1070 if ($office_query->have_posts())
1071 {
1072 while ($office_query->have_posts())
1073 {
1074 $office_query->the_post();
1075
1076 $output .= '<option
1077 value="' . esc_attr( $post->ID ) . '"
1078 ' . selected( esc_attr( $field['value'] ), esc_attr( $post->ID ), false ) . '
1079 >' . esc_html( get_the_title() ) . '</option>';
1080
1081 }
1082 }
1083 wp_reset_postdata();
1084
1085 $output .= '</select>';
1086
1087 $output .= $field['after'];
1088
1089 break;
1090 }
1091 case "country":
1092 {
1093 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1094 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1095 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1096 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1097 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1098
1099 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1100 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1101 {
1102 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1103 }
1104
1105 $output .= $field['before'];
1106
1107 if ($field['show_label'])
1108 {
1109 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1110 }
1111
1112 $output .= '<select
1113 name="' . esc_attr( $key ) . '"
1114 id="' . esc_attr( $key ) . '"
1115 class="' . esc_attr( $field['class'] ) . '"
1116 >';
1117
1118 $output .= '<option
1119 value=""
1120 ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '
1121 >' . esc_html( __( 'No preference', 'propertyhive' ) ) . '</option>';
1122
1123 $countries = get_option( 'propertyhive_countries', array() );
1124 if ( is_array($countries) && !empty($countries) )
1125 {
1126 $ph_countries = new PH_Countries;
1127
1128 foreach ( $countries as $country )
1129 {
1130 $ph_country = $ph_countries->get_country( $country );
1131
1132 if ( $ph_country !== FALSE )
1133 {
1134 $output .= '<option
1135 value="' . esc_attr( $country ) . '"
1136 ' . selected( esc_attr( $field['value'] ), esc_attr( $country ), false ) . '
1137 >' . esc_html( $ph_country['name'] ) . '</option>';
1138 }
1139 }
1140 }
1141
1142 $output .= '</select>';
1143
1144 $output .= $field['after'];
1145
1146 break;
1147 }
1148 case "hidden":
1149 {
1150 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1151 $field['name'] = isset( $field['name'] ) ? $field['name'] : $key;
1152 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1153 {
1154 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1155 }
1156
1157 $output .= '<input type="hidden" name="' . esc_attr( $field['name'] ) . '" value="' . $field['value'] . '">';
1158 break;
1159 }
1160 case "html":
1161 {
1162 $field['html'] = isset( $field['html'] ) ? $field['html'] : '';
1163 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1164 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1165
1166 $output .= $field['before'];
1167 $output .= $field['html'];
1168 $output .= $field['after'];
1169
1170 break;
1171 }
1172 case "recaptcha":
1173 {
1174 $field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : '';
1175
1176 $output .= '<script src="https://www.google.com/recaptcha/api.js"></script>
1177 <div class="g-recaptcha" data-sitekey="' . $field['site_key'] . '"></div>';
1178 break;
1179 }
1180 default:
1181 {
1182 if ( taxonomy_exists($field['type']) )
1183 {
1184 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1185 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1186 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1187 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1188 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1189 $field['blank_option'] = isset( $field['blank_option'] ) ? $field['blank_option'] : __( 'No preference', 'propertyhive' );
1190
1191 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1192 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1193 {
1194 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1195 }
1196
1197 $output .= $field['before'];
1198
1199 if ($field['show_label'])
1200 {
1201 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1202 }
1203
1204 $output .= '<select
1205 name="' . esc_attr( $key ) . '"
1206 id="' . esc_attr( $key ) . '"
1207 class="' . esc_attr( $field['class'] ) . '"
1208 >';
1209
1210 $options = array( '' => $field['blank_option'] );
1211 $args = array(
1212 'hide_empty' => false,
1213 'parent' => 0
1214 );
1215 $terms = get_terms( $field['type'], $args );
1216
1217 $selected_value = '';
1218 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1219 {
1220 foreach ($terms as $term)
1221 {
1222 $options[$term->term_id] = $term->name;
1223
1224 $args = array(
1225 'hide_empty' => false,
1226 'parent' => $term->term_id
1227 );
1228 $subterms = get_terms( $field['type'], $args );
1229
1230 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
1231 {
1232 foreach ($subterms as $term)
1233 {
1234 $options[$term->term_id] = '- ' . $term->name;
1235
1236 $args = array(
1237 'hide_empty' => false,
1238 'parent' => $term->term_id
1239 );
1240 $subsubterms = get_terms( $field['type'], $args );
1241
1242 if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
1243 {
1244 foreach ($subsubterms as $term)
1245 {
1246 $options[$term->term_id] = '- ' . $term->name;
1247 }
1248 }
1249 }
1250 }
1251 }
1252 }
1253
1254 foreach ( $options as $option_key => $value )
1255 {
1256 $output .= '<option
1257 value="' . esc_attr( $option_key ) . '"
1258 ' . selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false ) . '
1259 >' . esc_html( $value ) . '</option>';
1260 }
1261
1262 $output .= '</select>';
1263
1264 $output .= $field['after'];
1265 }
1266 }
1267 }
1268
1269 echo $output;
1270 }