PluginProbe
Property Hive / 1.4.47
Property Hive v1.4.47
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.47, at includes/ph-form-functions.php

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