1: <?php
2: /**
3: * Search Widget Fields
4: *
5: * @package EPL
6: * @subpackage Widget/Functions
7: * @copyright Copyright (c) 2019, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 2.0
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: // phpcs:disable WordPress.DB.SlowDBQuery
18:
19: /**
20: * Search widget form fields for search widget
21: *
22: * @since 2.0
23: * @since 3.4.44 Added epl_any_label_status_filter and epl_current_label_status_filter filters for any and current status labels.
24: * @since 3.5 Support for instance_id.
25: * @since 3.5.0 Using the global function to get status labels.
26: */
27: function epl_search_widget_fields() {
28:
29: $post_type_array = array_merge( array( '' => __( 'All', 'easy-property-listings' ) ) + epl_get_active_post_types() );
30: $fields = apply_filters(
31: 'epl_search_widget_fields',
32: array(
33:
34: array(
35: 'key' => 'title',
36: 'label' => __( 'Title', 'easy-property-listings' ),
37: 'type' => 'text',
38: 'default' => '',
39: 'order' => 10,
40: ),
41: array(
42: 'key' => 'post_type',
43: 'label' => __( 'Post Type', 'easy-property-listings' ),
44: 'default' => array( 'property' ),
45: 'type' => 'select',
46: 'multiple' => true,
47: 'options' => $post_type_array,
48: 'order' => 20,
49: ),
50: array(
51: 'key' => 'style',
52: 'label' => __( 'Style', 'easy-property-listings' ),
53: 'default' => 'default',
54: 'type' => 'select',
55: 'options' => array(
56: 'default' => __( 'Default', 'easy-property-listings' ),
57: 'wide' => __( 'Wide', 'easy-property-listings' ),
58: 'slim' => __( 'Slim', 'easy-property-listings' ),
59: 'fixed' => __( 'Fixed Width', 'easy-property-listings' ),
60: ),
61: 'order' => 30,
62: ),
63: array(
64: 'key' => 'show_property_status_frontend',
65: 'label' => __( 'Status', 'easy-property-listings' ),
66: 'default' => 'off',
67: 'type' => 'checkbox',
68: 'order' => 40,
69: ),
70: array(
71: 'key' => 'property_status',
72: 'label' => __( 'Status', 'easy-property-listings' ),
73: 'default' => '',
74: 'type' => 'select',
75: 'options' => array(
76: '' => apply_filters( 'epl_any_label_status_filter', __( 'Any', 'easy-property-listings' ) ),
77: 'current' => apply_filters( 'epl_current_label_status_filter', epl_get_the_status_label( 'current' ) ),
78: 'sold' => apply_filters( 'epl_sold_label_status_filter', epl_get_the_status_label( 'sold' ) ),
79: 'leased' => apply_filters( 'epl_leased_label_status_filter', epl_get_the_status_label( 'leased' ) ),
80: ),
81: 'order' => 50,
82: ),
83: array(
84: 'key' => 'search_id',
85: 'label' => __( 'Property ID', 'easy-property-listings' ),
86: 'default' => 'off',
87: 'type' => 'checkbox',
88: 'order' => 60,
89: ),
90: array(
91: 'key' => 'search_address',
92: 'label' => __( 'Property Address', 'easy-property-listings' ),
93: 'default' => 'off',
94: 'type' => 'checkbox',
95: 'order' => 70,
96: ),
97: array(
98: 'key' => 'search_location',
99: 'label' => epl_tax_location_label(),
100: 'default' => 'on',
101: 'type' => 'checkbox',
102: 'order' => 80,
103: ),
104: array(
105: 'key' => 'search_city',
106: 'label' => epl_labels( 'label_city' ),
107: 'default' => 'off',
108: 'type' => 'checkbox',
109: 'order' => 90,
110: ),
111: array(
112: 'key' => 'search_state',
113: 'label' => epl_labels( 'label_state' ),
114: 'default' => 'off',
115: 'type' => 'checkbox',
116: 'order' => 100,
117: ),
118: array(
119: 'key' => 'search_postcode',
120: 'label' => epl_labels( 'label_postcode' ),
121: 'default' => 'off',
122: 'type' => 'checkbox',
123: 'order' => 110,
124: ),
125: array(
126: 'key' => 'search_country',
127: 'label' => __( 'Country', 'easy-property-listings' ),
128: 'default' => 'off',
129: 'type' => 'checkbox',
130: 'order' => 120,
131: ),
132: array(
133: 'key' => 'search_house_category',
134: 'label' => __( 'Category', 'easy-property-listings' ),
135: 'default' => 'on',
136: 'type' => 'checkbox',
137: 'order' => 130,
138: ),
139: array(
140: 'key' => 'house_category_multiple',
141: 'label' => __( 'Categories: Multi select', 'easy-property-listings' ),
142: 'default' => 'off',
143: 'type' => 'checkbox',
144: 'order' => 140,
145: ),
146: array(
147: 'key' => 'search_price_global',
148: 'label' => __( 'Price Slider', 'easy-property-listings' ),
149: 'default' => 'off',
150: 'type' => 'checkbox',
151: 'order' => 150,
152: ),
153: array(
154: 'key' => 'search_price',
155: 'label' => __( 'Price', 'easy-property-listings' ),
156: 'default' => 'on',
157: 'type' => 'checkbox',
158: 'order' => 160,
159: ),
160:
161: array(
162: 'key' => 'search_bed',
163: 'label' => __( 'Bed', 'easy-property-listings' ),
164: 'default' => 'on',
165: 'type' => 'checkbox',
166: 'order' => 170,
167: ),
168: array(
169: 'key' => 'search_bath',
170: 'label' => __( 'Bath', 'easy-property-listings' ),
171: 'default' => 'on',
172: 'type' => 'checkbox',
173: 'order' => 180,
174: ),
175: array(
176: 'key' => 'search_rooms',
177: 'label' => __( 'Rooms', 'easy-property-listings' ),
178: 'default' => 'off',
179: 'type' => 'checkbox',
180: 'order' => 190,
181: ),
182: array(
183: 'key' => 'search_car',
184: 'label' => __( 'Car', 'easy-property-listings' ),
185: 'default' => 'off',
186: 'type' => 'checkbox',
187: 'order' => 200,
188: ),
189: array(
190: 'key' => 'search_land_area',
191: 'label' => __( 'Land Area', 'easy-property-listings' ),
192: 'default' => 'off',
193: 'type' => 'checkbox',
194: 'order' => 210,
195: ),
196: array(
197: 'key' => 'search_building_area',
198: 'label' => __( 'Building Area', 'easy-property-listings' ),
199: 'default' => 'off',
200: 'type' => 'checkbox',
201: 'order' => 220,
202: ),
203: array(
204: 'key' => 'search_features',
205: 'label' => __( 'Features', 'easy-property-listings' ),
206: 'default' => 'off',
207: 'type' => 'checkbox',
208: 'order' => 230,
209: ),
210:
211: array(
212: 'key' => 'search_other',
213: 'label' => __( 'Other Search Options', 'easy-property-listings' ),
214: 'default' => 'on',
215: 'type' => 'checkbox',
216: 'order' => 240,
217: ),
218: array(
219: 'key' => 'instance_id',
220: 'label' => __( 'Form Instance ID', 'easy-property-listings' ),
221: 'type' => 'number',
222: 'default' => '',
223: 'order' => 290,
224: 'help' => __( 'Leave empty to generate it automatically', 'easy-property-listings' ),
225: ),
226: array(
227: 'key' => 'submit_label',
228: 'label' => __( 'Submit Label', 'easy-property-listings' ),
229: 'type' => 'text',
230: 'default' => __( 'Search', 'easy-property-listings' ),
231: 'order' => 300,
232: ),
233: )
234: );
235:
236: $order = array();
237: foreach ( $fields as $field_key => $field_value ) {
238:
239: $fields[ $field_value['key'] ] = $field_value;
240: $order[ $field_value['key'] ] = isset( $field_value['order'] ) ? $field_value['order'] : 245;
241: unset( $fields[ $field_key ] );
242:
243: }
244:
245: array_multisort( $order, SORT_ASC, $fields );
246:
247: return $fields;
248: }
249:
250: /**
251: * Number Suffix Callback
252: *
253: * @param string $v Value.
254: * @param string $suffix Suffix.
255: *
256: * @return string
257: * @since 2.0.0
258: * @since 3.4.38 Added filter epl_number_suffix for select numbers suffix.
259: */
260: function epl_number_suffix_callback( $v, $suffix = ' +' ) {
261: $suffix = apply_filters( 'epl_number_suffix_callback', $suffix );
262: return $v . '' . $suffix;
263: }
264:
265: /**
266: * Get the price slider default ranges
267: *
268: * @param string $post_type Post type.
269: * @param string $transaction Transaction param may come in handy in commercial search where we have both sale & lease commercial properties.
270: *
271: * @return array|false|mixed|void
272: * @since 3.3
273: */
274: function epl_get_price_slider_array( $post_type = 'property', $transaction = 'default' ) {
275:
276: if ( empty( $post_type ) ) {
277: $range = range( 0, 10000000, 50000 );
278: $price_array = array_combine( $range, array_map( 'epl_currency_formatted_amount', $range ) );
279: $price_array = apply_filters( 'epl_listing_search_price_slider_global', $price_array );
280: } elseif ( is_epl_rental_post( $post_type ) ) {
281: $range = range( 50, 5000, 50 );
282: $price_array = array_combine( $range, array_map( 'epl_currency_formatted_amount', $range ) );
283:
284: // the additional $post_type param passed to apply_filters will enable us to change price range for each post type.
285: $price_array = apply_filters( 'epl_listing_search_price_slider_rental', $price_array, $post_type, $transaction );
286: } else {
287: $range = range( 50000, 10000000, 50000 );
288: $price_array = array_combine( $range, array_map( 'epl_currency_formatted_amount', $range ) );
289: $price_array = apply_filters( 'epl_listing_search_price_slider_sale', $price_array, $post_type, $transaction );
290: }
291:
292: return $price_array;
293: }
294:
295: /**
296: * Get the price array for the price slider
297: *
298: * @param string $post_type Post type.
299: * @param string $transaction Transaction param may come in handy in commercial search where we have both sale & lease commercial properties.
300: *
301: * @return array|false|mixed|void
302: * @since 3.1
303: */
304: function epl_get_price_array( $post_type = 'property', $transaction = 'default' ) {
305:
306: if ( empty( $post_type ) ) {
307:
308: $range = array_merge( range( 0, 1000, 50 ), range( 1100, 2000, 100 ), range( 2500, 5000, 500 ), range( 50000, 1000000, 50000 ), range( 1250000, 3000000, 250000 ), array( 4000000, 5000000, 10000000 ) );
309:
310: $price_array = array_combine( $range, array_map( 'epl_currency_formatted_amount', $range ) );
311:
312: $price_array = apply_filters( 'epl_listing_search_price_global', $price_array );
313: } elseif ( is_epl_rental_post( $post_type ) ) {
314: $range = array_merge( range( 50, 1000, 50 ), range( 1100, 2000, 100 ), range( 2500, 5000, 500 ) );
315: $price_array = array_combine( $range, array_map( 'epl_currency_formatted_amount', $range ) );
316:
317: // the additional $post_type param passed to apply_filters will enable us to change price range for each post type.
318: $price_array = apply_filters( 'epl_listing_search_price_rental', $price_array, $post_type, $transaction );
319: } else {
320: $range = array_merge( range( 50000, 1000000, 50000 ), range( 1250000, 3000000, 250000 ), array( 4000000, 5000000, 10000000 ) );
321: $price_array = array_combine( $range, array_map( 'epl_currency_formatted_amount', $range ) );
322: $price_array = apply_filters( 'epl_listing_search_price_sale', $price_array, $post_type, $transaction );
323: }
324:
325: return $price_array;
326: }
327:
328: /**
329: * Get the price meta key
330: *
331: * @param string $post_type Post type.
332: * @param string $transaction Transaction param may come in handy in commercial search where we have both sale & lease commercial properties.
333: *
334: * @return mixed|void
335: * @since 3.1
336: */
337: function epl_get_price_meta_key( $post_type = 'property', $transaction = 'default' ) {
338:
339: // move from specific to general.
340: if ( 'commercial' === $post_type ) {
341:
342: $price_meta_key = 'lease' === $transaction ? 'property_com_rent' : 'property_price';
343:
344: } elseif ( is_epl_rental_post( $post_type ) ) {
345:
346: $price_meta_key = 'property_rent';
347:
348: } else {
349:
350: $price_meta_key = 'property_price';
351: }
352:
353: // use this filter to change property price meta key on the basis of post type & transaction.
354: return apply_filters( 'epl_price_meta_key', $price_meta_key, $post_type, $transaction );
355: }
356:
357: /**
358: * Search widget form fields for search widget - frontend
359: *
360: * @param string $post_type Post type.
361: * @param string $property_status Listing status.
362: * @param string $transaction_type Transaction param may come in handy in commercial search where we have both sale & lease commercial properties.
363: *
364: * @return mixed|void
365: * @since 2.2
366: * @since 3.5.0 Status labels are coming from global filter epl_opts_property_status_filter.
367: */
368: function epl_search_widget_fields_frontend( $post_type = '', $property_status = '', $transaction_type = 'default' ) {
369:
370: $price_array = epl_get_price_array( $post_type, $transaction_type );
371: $price_slider_array = epl_get_price_slider_array( $post_type, $transaction_type );
372: $price_meta_key = epl_get_price_meta_key( $post_type, $transaction_type );
373:
374: $fields = apply_filters(
375: 'epl_search_widget_fields_frontend',
376: array(
377:
378: array(
379: 'key' => 'post_type',
380: 'meta_key' => 'post_type',
381: 'type' => 'hidden',
382: 'order' => 10,
383: ),
384: array(
385: 'key' => 'property_status',
386: 'meta_key' => 'property_status',
387: 'label' => __( 'Status', 'easy-property-listings' ),
388: 'type' => 'hidden',
389: 'option_filter' => 'property_status',
390: 'options' => epl_get_available_status_list( 'property_status', $post_type ),
391: 'query' => array(
392: 'query' => 'meta',
393: 'compare' => 'IN',
394: ),
395: 'order' => 20,
396: ),
397: array(
398: 'key' => 'search_id',
399: 'meta_key' => 'property_id',
400: 'label' => __( 'Search by Property ID', 'easy-property-listings' ),
401: 'placeholder' => __( 'Search ID', 'easy-property-listings' ),
402: 'type' => 'text',
403: 'class' => 'epl-search-row-full',
404: 'query' => array(
405: 'query' => 'meta',
406: 'key' => 'property_unique_id',
407: ),
408: 'order' => 25,
409: ),
410: array(
411: 'key' => 'search_address',
412: 'meta_key' => 'property_address',
413: 'label' => __( 'Search by Address', 'easy-property-listings' ),
414: 'placeholder' => __( 'Search Address', 'easy-property-listings' ),
415: 'type' => 'text',
416: 'class' => 'epl-search-row-full',
417: 'query' => array( 'query' => 'post' ),
418: 'order' => 30,
419: ),
420: array(
421: 'key' => 'search_location',
422: 'meta_key' => 'property_location',
423: 'label' => epl_tax_location_label(),
424: 'type' => 'select',
425: 'option_filter' => 'location',
426: 'options' => epl_get_available_locations( $post_type, $property_status ),
427: 'query' => array( 'query' => 'tax' ),
428: 'class' => 'epl-search-row-full',
429: 'order' => 40,
430: ),
431: array(
432: 'key' => 'search_city',
433: 'meta_key' => 'property_address_city',
434: 'label' => epl_labels( 'label_city' ),
435: 'type' => 'select',
436: 'option_filter' => 'city',
437: 'options' => epl_get_unique_post_meta_values( 'property_address_city', $post_type, 'publish', $property_status ),
438: 'query' => array( 'query' => 'meta' ),
439: 'class' => 'epl-search-row-half',
440: 'order' => 50,
441: ),
442: array(
443: 'key' => 'search_state',
444: 'meta_key' => 'property_address_state',
445: 'label' => epl_labels( 'label_state' ),
446: 'type' => 'select',
447: 'option_filter' => 'state',
448: 'options' => epl_get_unique_post_meta_values( 'property_address_state', $post_type, 'publish', $property_status ),
449: 'query' => array( 'query' => 'meta' ),
450: 'class' => 'epl-search-row-half',
451: 'order' => 60,
452: ),
453: array(
454: 'key' => 'search_postcode',
455: 'meta_key' => 'property_address_postal_code',
456: 'label' => epl_labels( 'label_postcode' ),
457: 'type' => 'select',
458: 'option_filter' => 'postcode',
459: 'options' => epl_get_unique_post_meta_values( 'property_address_postal_code', $post_type, 'publish', $property_status ),
460: 'query' => array( 'query' => 'meta' ),
461: 'class' => 'epl-search-row-half',
462: 'order' => 70,
463: ),
464: array(
465: 'key' => 'search_country',
466: 'meta_key' => 'property_address_country',
467: 'label' => __( 'Country', 'easy-property-listings' ),
468: 'type' => 'select',
469: 'option_filter' => 'country',
470: 'options' => epl_get_unique_post_meta_values( 'property_address_country', $post_type, 'publish', $property_status ),
471: 'query' => array( 'query' => 'meta' ),
472: 'class' => 'epl-search-row-half',
473: 'order' => 80,
474: ),
475: array(
476: 'key' => 'search_house_category',
477: 'meta_key' => 'property_category',
478: 'label' => __( 'House Category', 'easy-property-listings' ),
479: 'option_filter' => 'category',
480: 'options' => epl_get_meta_values( 'property_category', $post_type ),
481: 'type' => 'select',
482: 'query' => array( 'query' => 'meta' ),
483: 'class' => 'epl-search-row-full',
484: 'exclude' => array( 'rural', 'land', 'commercial', 'commercial_land', 'business' ),
485: 'order' => 90,
486: ),
487: array(
488: 'key' => 'search_house_category',
489: 'meta_key' => 'property_rural_category',
490: 'label' => __( 'Rural Category', 'easy-property-listings' ),
491: 'option_filter' => 'category',
492: 'options' => epl_get_meta_values( 'property_rural_category', $post_type ),
493: 'type' => 'select',
494: 'query' => array( 'query' => 'meta' ),
495: 'class' => 'epl-search-row-full',
496: 'exclude' => array( 'property', 'rental', 'land', 'commercial', 'commercial_land', 'business' ),
497: 'order' => 100,
498: ),
499: array(
500: 'key' => 'search_house_category',
501: 'meta_key' => 'property_land_category',
502: 'label' => __( 'Land Category', 'easy-property-listings' ),
503: 'option_filter' => 'category',
504: 'options' => epl_get_meta_values( 'property_land_category', $post_type ),
505: 'type' => 'select',
506: 'query' => array( 'query' => 'meta' ),
507: 'class' => 'epl-search-row-full',
508: 'exclude' => array( 'property', 'rental', 'rural', 'commercial', 'commercial_land', 'business' ),
509: 'order' => 110,
510: ),
511: array(
512: 'key' => 'search_house_category',
513: 'meta_key' => 'property_commercial_category',
514: 'label' => __( 'Commercial Category', 'easy-property-listings' ),
515: 'option_filter' => 'category',
516: 'options' => epl_get_meta_values( 'property_commercial_category', $post_type ),
517: 'type' => 'select',
518: 'query' => array( 'query' => 'meta' ),
519: 'class' => 'epl-search-row-full',
520: 'exclude' => array( 'property', 'rental', 'land', 'rural', 'business' ),
521: 'order' => 120,
522: ),
523: array(
524: 'key' => 'search_house_category',
525: 'meta_key' => 'property_tax_business_listing',
526: 'label' => __( 'Business Category', 'easy-property-listings' ),
527: 'type' => 'select',
528: 'option_filter' => 'tax_business_listing',
529: 'options' => epl_get_available_terms( 'tax_business_listing', 'business', $property_status ),
530: 'query' => array( 'query' => 'tax' ),
531: 'class' => 'epl-search-row-full',
532: 'exclude' => array( 'property', 'rental', 'land', 'rural', 'commercial', 'commercial_land' ),
533: 'order' => 130,
534: ),
535: array(
536: 'key' => 'search_price_global',
537: 'meta_key' => 'property_price_global_from',
538: 'label' => __( 'Search Price From', 'easy-property-listings' ),
539: 'option_filter' => 'global_price_from',
540: 'options' => $price_slider_array,
541: 'type' => 'select',
542: 'query' => array(
543: 'query' => 'meta',
544: 'key' => 'property_price_global',
545: 'type' => 'numeric',
546: 'compare' => '>=',
547: ),
548: 'class' => 'epl-search-row-half',
549: 'order' => 134,
550: ),
551: array(
552: 'key' => 'search_price_global',
553: 'meta_key' => 'property_price_global_to',
554: 'label' => __( 'Search Price To', 'easy-property-listings' ),
555: 'option_filter' => 'global_price_to',
556: 'options' => $price_slider_array,
557: 'type' => 'select',
558: 'query' => array(
559: 'query' => 'meta',
560: 'key' => 'property_price_global',
561: 'type' => 'numeric',
562: 'compare' => '<=',
563: ),
564: 'class' => 'epl-search-row-half',
565: 'order' => 135,
566: ),
567: array(
568: 'key' => 'search_price',
569: 'meta_key' => 'property_price_from',
570: 'label' => __( 'Price From', 'easy-property-listings' ),
571: 'option_filter' => 'price_from',
572: 'options' => $price_array,
573: 'type' => 'select',
574: 'query' => array(
575: 'query' => 'meta',
576: 'key' => $price_meta_key,
577: 'type' => 'numeric',
578: 'compare' => '>=',
579: ),
580: 'class' => 'epl-search-row-half',
581: 'order' => 140,
582: ),
583: array(
584: 'key' => 'search_price',
585: 'meta_key' => 'property_price_to',
586: 'label' => __( 'Price To', 'easy-property-listings' ),
587: 'option_filter' => 'price_to',
588: 'options' => $price_array,
589: 'type' => 'select',
590: 'query' => array(
591: 'query' => 'meta',
592: 'key' => $price_meta_key,
593: 'type' => 'numeric',
594: 'compare' => '<=',
595: ),
596: 'class' => 'epl-search-row-half',
597: 'order' => 150,
598: ),
599: array(
600: 'key' => 'search_bed',
601: 'meta_key' => 'property_bedrooms_min',
602: 'label' => __( 'Bedrooms Min', 'easy-property-listings' ),
603: 'option_filter' => 'bedrooms_min',
604: 'options' => apply_filters(
605: 'epl_listing_search_bed_select_min',
606: array_combine( range( 1, 10 ), array_map( 'epl_number_suffix_callback', range( 1, 10 ) ) )
607: ),
608: 'type' => 'select',
609: 'exclude' => array( 'land', 'commercial', 'commercial_land', 'business' ),
610: 'query' => array(
611: 'query' => 'meta',
612: 'key' => 'property_bedrooms',
613: 'type' => 'numeric',
614: 'compare' => '>=',
615: ),
616: 'class' => 'epl-search-row-half',
617: 'order' => 160,
618: ),
619: array(
620: 'key' => 'search_bed',
621: 'meta_key' => 'property_bedrooms_max',
622: 'label' => __( 'Bedrooms Max', 'easy-property-listings' ),
623: 'option_filter' => 'bedrooms_max',
624: 'options' => apply_filters(
625: 'epl_listing_search_bed_select_max',
626: array_combine( range( 1, 10 ), array_map( 'epl_number_suffix_callback', range( 1, 10 ) ) )
627: ),
628: 'type' => 'select',
629: 'exclude' => array( 'land', 'commercial', 'commercial_land', 'business' ),
630: 'query' => array(
631: 'query' => 'meta',
632: 'key' => 'property_bedrooms',
633: 'type' => 'numeric',
634: 'compare' => '<=',
635: ),
636: 'class' => 'epl-search-row-half',
637: 'order' => 170,
638: ),
639: array(
640: 'key' => 'search_bath',
641: 'meta_key' => 'property_bathrooms',
642: 'label' => __( 'Bathrooms', 'easy-property-listings' ),
643: 'option_filter' => 'bathrooms',
644: 'options' => apply_filters(
645: 'epl_listing_search_bath_select',
646: array_combine( range( 1, 3 ), array_map( 'epl_number_suffix_callback', range( 1, 3 ) ) )
647: ),
648: 'type' => 'select',
649: 'exclude' => array( 'land', 'commercial', 'commercial_land', 'business' ),
650: 'query' => array(
651: 'query' => 'meta',
652: 'type' => 'numeric',
653: 'compare' => '>=',
654: ),
655: 'class' => 'epl-search-row-half',
656: 'order' => 180,
657: ),
658: array(
659: 'key' => 'search_rooms',
660: 'meta_key' => 'property_rooms',
661: 'label' => __( 'Rooms', 'easy-property-listings' ),
662: 'option_filter' => 'rooms',
663: 'options' => apply_filters(
664: 'epl_listing_search_room_select',
665: array_combine( range( 1, 3 ), array_map( 'epl_number_suffix_callback', range( 1, 3 ) ) )
666: ),
667: 'type' => 'select',
668: 'exclude' => array( 'land', 'commercial', 'commercial_land', 'business' ),
669: 'query' => array(
670: 'query' => 'meta',
671: 'type' => 'numeric',
672: 'compare' => '>=',
673: ),
674: 'class' => 'epl-search-row-half',
675: 'order' => 190,
676: ),
677: array(
678: 'key' => 'search_car',
679: 'meta_key' => 'property_carport',
680: 'label' => __( 'Car Spaces', 'easy-property-listings' ),
681: 'option_filter' => 'carport',
682: 'options' => apply_filters(
683: 'epl_listing_search_parking_select',
684: array_combine( range( 1, 3 ), array_map( 'epl_number_suffix_callback', range( 1, 3 ) ) )
685: ),
686: 'type' => 'select',
687: 'class' => 'epl-search-row-half',
688: 'exclude' => array( 'land', 'commercial', 'commercial_land', 'business' ),
689: 'query' => array(
690: 'multiple' => true,
691: 'query' => 'meta',
692: 'relation' => 'OR',
693: 'sub_queries' => array(
694: array(
695: 'key' => 'property_carport',
696: 'type' => 'numeric',
697: 'compare' => '>=',
698: ),
699: array(
700: 'key' => 'property_garage',
701: 'type' => 'numeric',
702: 'compare' => '>=',
703: ),
704: ),
705: ),
706: 'order' => 200,
707: ),
708: array(
709: 'key' => 'search_features',
710: 'meta_key' => 'property_tax_feature',
711: 'label' => __( 'Features', 'easy-property-listings' ),
712: 'type' => 'select',
713: 'option_filter' => 'tax_feature',
714: 'options' => epl_get_available_terms( 'tax_feature', $post_type, $property_status ),
715: 'query' => array( 'query' => 'tax' ),
716: 'class' => 'epl-search-row-half',
717: 'order' => 205,
718: ),
719: array(
720: 'key' => 'search_land_area',
721: 'meta_key' => 'property_land_area_min',
722: 'label' => __( 'Land Min', 'easy-property-listings' ),
723: 'type' => has_filter( 'epl_property_land_area_min' ) ? apply_filters( 'epl_property_land_area_min', '' ) : 'number',
724: 'query' => array(
725: 'query' => 'meta',
726: 'type' => 'numeric',
727: 'compare' => '>=',
728: 'key' => 'property_land_area',
729: ),
730: 'class' => 'epl-search-row-third',
731: 'placeholder' => __( 'Min', 'easy-property-listings' ),
732: 'wrap_start' => 'epl-search-row epl-search-land-area',
733: 'order' => 210,
734: ),
735: array(
736: 'key' => 'search_land_area',
737: 'meta_key' => 'property_land_area_max',
738: 'label' => __( 'Land Max', 'easy-property-listings' ),
739: 'class' => 'epl-search-row-third',
740: 'placeholder' => __( 'Max', 'easy-property-listings' ),
741: 'type' => has_filter( 'epl_property_land_area_max' ) ? apply_filters( 'epl_property_land_area_max', '' ) : 'number',
742: 'query' => array(
743: 'query' => 'meta',
744: 'type' => 'numeric',
745: 'compare' => '<=',
746: 'key' => 'property_land_area',
747: ),
748: 'order' => 220,
749: ),
750: array(
751: 'key' => 'search_land_area',
752: 'meta_key' => 'property_land_area_unit',
753: 'label' => __( 'Area Unit', 'easy-property-listings' ),
754: 'class' => 'epl-search-row-third',
755: 'type' => 'select',
756: 'option_filter' => 'land_area_unit',
757: 'options' => apply_filters(
758: 'epl_listing_search_land_unit_label',
759: array(
760: 'square' => __( 'Square', 'easy-property-listings' ),
761: 'squareMeter' => __( 'Square Meter', 'easy-property-listings' ),
762: 'acre' => __( 'Acre', 'easy-property-listings' ),
763: 'hectare' => __( 'Hectare', 'easy-property-listings' ),
764: 'sqft' => __( 'Square Feet', 'easy-property-listings' ),
765: )
766: ),
767: 'query' => array( 'query' => 'meta' ),
768: 'wrap_end' => true,
769: 'order' => 230,
770:
771: ),
772: array(
773: 'key' => 'search_building_area',
774: 'meta_key' => 'property_building_area_min',
775: 'label' => __( 'Building Min', 'easy-property-listings' ),
776: 'placeholder' => __( 'Min', 'easy-property-listings' ),
777: 'class' => 'epl-search-row-third',
778: 'type' => has_filter( 'epl_property_building_area_min' ) ? apply_filters( 'epl_property_building_area_min', '' ) : 'number',
779: 'exclude' => array( 'land' ),
780: 'query' => array(
781: 'query' => 'meta',
782: 'type' => 'numeric',
783: 'compare' => '>=',
784: 'key' => 'property_building_area',
785: ),
786: 'wrap_start' => 'epl-search-row epl-search-building-area',
787: 'order' => 240,
788: ),
789: array(
790: 'key' => 'search_building_area',
791: 'meta_key' => 'property_building_area_max',
792: 'label' => __( 'Building Max', 'easy-property-listings' ),
793: 'class' => 'epl-search-row-third',
794: 'placeholder' => __( 'Max', 'easy-property-listings' ),
795: 'type' => has_filter( 'epl_property_building_area_max' ) ? apply_filters( 'epl_property_building_area_max', '' ) : 'number',
796: 'exclude' => array( 'land' ),
797: 'query' => array(
798: 'query' => 'meta',
799: 'type' => 'numeric',
800: 'compare' => '<=',
801: 'key' => 'property_building_area',
802: ),
803: 'order' => 250,
804: ),
805: array(
806: 'key' => 'search_building_area',
807: 'meta_key' => 'property_building_area_unit',
808: 'label' => __( 'Area Unit', 'easy-property-listings' ),
809: 'class' => 'epl-search-row-third',
810: 'type' => 'select',
811: 'option_filter' => 'building_area_unit',
812: 'options' => apply_filters(
813: 'epl_listing_search_building_unit_label',
814: array(
815: 'square' => __( 'Square', 'easy-property-listings' ),
816: 'squareMeter' => __( 'Square Meter', 'easy-property-listings' ),
817: 'acre' => __( 'Acre', 'easy-property-listings' ),
818: 'hectare' => __( 'Hectare', 'easy-property-listings' ),
819: 'sqft' => __( 'Square Feet', 'easy-property-listings' ),
820: )
821: ),
822: 'exclude' => array( 'land' ),
823: 'query' => array( 'query' => 'meta' ),
824: 'wrap_end' => true,
825: 'order' => 260,
826: ),
827: array(
828: 'key' => 'search_other',
829: 'meta_key' => 'property_air_conditioning',
830: 'label' => __( 'Air Conditioning', 'easy-property-listings' ),
831: 'type' => 'checkbox',
832: 'exclude' => array( 'land', 'commercial', 'commercial_land', 'business' ),
833: 'query' => array(
834: 'query' => 'meta',
835: 'compare' => 'IN',
836: 'value' => array( 'yes', '1' ),
837: ),
838: 'class' => 'epl-search-row-half',
839: 'wrap_start' => 'epl-search-row epl-search-other',
840: 'order' => 270,
841: ),
842: array(
843: 'key' => 'search_other',
844: 'meta_key' => 'property_pool',
845: 'label' => __( 'Pool', 'easy-property-listings' ),
846: 'type' => 'checkbox',
847: 'exclude' => array( 'land', 'commercial', 'commercial_land', 'business' ),
848: 'query' => array(
849: 'query' => 'meta',
850: 'compare' => 'IN',
851: 'value' => array( 'yes', '1' ),
852: ),
853: 'class' => 'epl-search-row-half',
854: 'order' => 280,
855: ),
856: array(
857: 'key' => 'search_other',
858: 'meta_key' => 'property_security_system',
859: 'label' => __( 'Security', 'easy-property-listings' ),
860: 'type' => 'checkbox',
861: 'exclude' => array( 'land', 'commercial', 'commercial_land', 'business' ),
862: 'query' => array(
863: 'query' => 'meta',
864: 'compare' => 'IN',
865: 'value' => array( 'yes', '1' ),
866: ),
867: 'class' => 'epl-search-row-half',
868: 'wrap_end' => true,
869: 'order' => 290,
870: ),
871:
872: ),
873: $post_type,
874: $property_status
875: );
876:
877: $order = array();
878: foreach ( $fields as $field_key => $field_value ) {
879: $fields[ $field_value['meta_key'] ] = $field_value;
880: $order[ $field_value['meta_key'] ] = isset( $field_value['order'] ) ? $field_value['order'] : 20;
881: unset( $fields[ $field_key ] );
882: }
883: array_multisort( $order, SORT_ASC, $fields );
884: return $fields;
885: }
886:
887: /**
888: * Search widget form fields defaults
889: *
890: * @since 2.2
891: */
892: function epl_search_get_defaults() {
893:
894: $defaults = array();
895: $fields = epl_search_widget_fields();
896:
897: foreach ( $fields as $field ) {
898: $defaults[ $field['key'] ] = $field['default'];
899: }
900: return $defaults;
901: }
902:
903: /**
904: * Render widget field blocks -- for backend form
905: *
906: * @param array $field Array of field type for the switch.
907: * @param WP_Widget $obj Array of object.
908: * @param string $value Value.
909: *
910: *
911: * @since 2.2
912: * @since 3.5 Added number field type.
913: * @since 3.5.18 Variable renamed.
914: * @since 3.5.19 Fix: Fatal error with widgets and customizer.
915: */
916: function epl_widget_render_backend_field( $field, $obj, $value = '' ) {
917:
918: switch ( $field['type'] ) {
919:
920: // Checkbox.
921: case 'checkbox':
922: ?>
923: <p>
924: <input
925: id="<?php echo esc_attr( $obj->get_field_id( $field['key'] ) ); ?>"
926: name="<?php echo esc_attr( $obj->get_field_name( $field['key'] ) ); ?>"
927: type="checkbox"
928: <?php
929: if ( isset( $value ) && esc_attr( $value ) === 'on' ) {
930: echo 'checked="checked"';
931: }
932: ?>
933: />
934: <label for="<?php echo esc_attr( $obj->get_field_id( $field['key'] ) ); ?>">
935: <?php echo esc_attr( $field['label'] ); ?>
936: </label>
937: </p>
938: <?php
939:
940: break;
941:
942: // Text.
943: case 'text':
944: ?>
945: <p>
946: <label for="<?php echo esc_attr( $obj->get_field_id( $field['key'] ) ); ?>">
947: <?php echo esc_attr( $field['label'] ); ?>
948: </label>
949: <input
950: class="widefat"
951: id="<?php echo esc_attr( $obj->get_field_id( $field['key'] ) ); ?>"
952: name="<?php echo esc_attr( $obj->get_field_name( $field['key'] ) ); ?>"
953: type="text"
954: value="<?php echo esc_attr( $value ); ?>"
955: />
956: </p>
957: <?php
958:
959: break;
960:
961: // Textarea.
962: case 'textarea':
963: ?>
964: <p>
965: <label for="<?php echo esc_attr( $obj->get_field_id( $field['key'] ) ); ?>">
966: <?php echo esc_attr( $field['label'] ); ?>
967: </label>
968: <textarea
969: class="widefat"
970: rows="10"
971: cols="20"
972: id="<?php echo esc_attr( $obj->get_field_id( $field['key'] ) ); ?>"
973: name="<?php echo esc_attr( $obj->get_field_name( $field['key'] ) ); ?>"
974: ><?php echo esc_attr( $value ); ?></textarea>
975: </p>
976: <?php
977:
978: break;
979:
980: // Select.
981: case 'select':
982: $is_multiple = isset( $field['multiple'] ) ? ' multiple ' : ' ';
983: $name = isset( $field['multiple'] ) ? $obj->get_field_name( $field['key'] ) . '[]' : '';
984: ?>
985: <p>
986: <label for="<?php echo esc_attr( $obj->get_field_id( $field['key'] ) ); ?>">
987: <?php echo esc_attr( $field['label'] ); ?>
988: </label>
989:
990: <select
991: <?php echo esc_attr( $is_multiple ); ?>
992: class="widefat"
993: id="<?php echo esc_attr( $obj->get_field_id( $field['key'] ) ); ?>"
994: name="<?php echo esc_attr( $name ); ?>">
995:
996: <?php
997:
998: foreach ( $field['options'] as $k => $v ) {
999: $selected = '';
1000: if ( isset( $field['multiple'] ) ) {
1001: if ( in_array( $k, (array) $value, true ) ) {
1002: $selected = ' selected ';
1003: }
1004: } else {
1005: if ( isset( $value ) && $k == $value ) { // phpcs:ignore
1006: $selected = ' selected ';
1007: }
1008: }
1009: echo '<option value="' . esc_attr( $k ) . '" ' . esc_attr( $selected ) . '>' . esc_attr( $v ) . '</option>';
1010: }
1011: ?>
1012: </select>
1013: </p>
1014: <?php
1015:
1016: break;
1017:
1018: // Number.
1019: case 'number':
1020: ?>
1021: <p>
1022: <label for="<?php echo esc_attr( $obj->get_field_id( $field['key'] ) ); ?>">
1023: <?php echo esc_attr( $field['label'] ); ?>
1024: </label>
1025: <input
1026: class="widefat"
1027: id="<?php echo esc_attr( $obj->get_field_id( $field['key'] ) ); ?>"
1028: name="<?php echo esc_attr( $obj->get_field_name( $field['key'] ) ); ?>"
1029: type="number"
1030: value="<?php echo esc_attr( $value ); ?>"
1031: />
1032: </p>
1033: <?php
1034:
1035: break;
1036: }
1037: }
1038:
1039: /**
1040: * Render widget field blocks -- for front-end form
1041: *
1042: * @since 2.2
1043: * @param array $field Array of options.
1044: * @param string $config Config option.
1045: * @param string $value Value.
1046: * @param string $post_type Post type name.
1047: * @param string $property_status Listing status.
1048: */
1049: function epl_widget_render_frontend_fields( $field, $config = '', $value = '', $post_type = '', $property_status = '' ) {
1050:
1051: if ( 'hidden' !== $field['type'] && 'on' !== $config ) {
1052: if ( 'property_status' !== $field['key'] ) {
1053: return;
1054: }
1055: }
1056:
1057: if ( ! empty( $field['exclude'] ) && in_array( $post_type, $field['exclude'], true ) ) {
1058: return;
1059: }
1060:
1061: do_action( 'epl_frontend_search_field_' . $field['type'], $field, $config, $value, $post_type, $property_status );
1062: }
1063:
1064: /**
1065: * Listings search.
1066: *
1067: * @param WP_Query $query WordPress Query object.
1068: * @param array $data That contains epl search key value pairs and if it's empty it will replace by $_REQUEST.
1069: * @param boolean $get_posts If set to true get_posts of WP_Query will execute on query and returns posts.
1070: *
1071: * @return array posts if query is set.
1072: * @since 2.3.1
1073: */
1074: function epl_search( &$query, array $data = array(), $get_posts = false ) {
1075: // phpcs:disable WordPress.Security.NonceVerification
1076: if ( empty( $data ) ) {
1077: $data = $_REQUEST;
1078: }
1079:
1080: $epl_search = new EPL_SEARCH( $query, $data );
1081:
1082: if ( $get_posts ) {
1083: return $epl_search->get_posts();
1084: }
1085: }
1086:
1087: /**
1088: * Property Search Query
1089: *
1090: * @since 2.3.1
1091: * @param WP_Query $query WordPress Query object.
1092: */
1093: function epl_search_pre_get_posts( $query ) {
1094: if ( is_admin() || ! $query->is_main_query() ) {
1095: return;
1096: }
1097: if ( epl_is_search() ) {
1098: epl_search( $query );
1099: }
1100: }
1101: add_action( 'pre_get_posts', 'epl_search_pre_get_posts' );
1102:
1103: /**
1104: * Can the listing search show this post type?
1105: *
1106: * True when the post type is registered and visitors can view it, so a
1107: * switched off listing type (rentals turned off) or a private one (contacts)
1108: * is left out of the search.
1109: *
1110: * @since 3.6 New: so the search skips switched off and private post types.
1111: *
1112: * @param string $post_type Post type name from the search request.
1113: *
1114: * @return bool
1115: */
1116: function epl_search_can_show_post_type( $post_type ) {
1117: $can_show = is_string( $post_type ) && post_type_exists( $post_type ) && is_post_type_viewable( $post_type );
1118:
1119: return (bool) apply_filters( 'epl_search_can_show_post_type', $can_show, $post_type );
1120: }
1121:
1122: /**
1123: * Is Property Search
1124: *
1125: * @since 2.3.1
1126: */
1127: function epl_is_search() {
1128: if ( isset( $_REQUEST['action'] ) && 'epl_search' === $_REQUEST['action'] ) {
1129: return true;
1130: }
1131: return false;
1132: }
1133:
1134: /**
1135: * Get Meta Values
1136: *
1137: * @param string $key Meta key name.
1138: * @param string $type Post type name.
1139: * @param string $status Status type.
1140: *
1141: * @return mixed|void
1142: * @since 2.3.1
1143: * @since 3.4.40 Fix: Search category options fixed for the all search tab.
1144: * @since 3.5.29 Fix: SQL injection. Post types are limited to registered ones and passed as prepared placeholders.
1145: * @since 3.6 Results are cached until a listing changes (epl_listing_query_cache()).
1146: */
1147: function epl_get_meta_values( $key = '', $type = 'post', $status = 'publish' ) {
1148:
1149: // phpcs:disable WordPress.DB
1150:
1151: if ( empty( $key ) ) {
1152: return;
1153: }
1154:
1155: if ( empty( $type ) || 'all' === $type ) {
1156: $type = epl_get_core_post_types();
1157: }
1158:
1159: $type = (array) $type;
1160: $type = array_map( 'sanitize_text_field', $type );
1161:
1162: // Keep only registered post types and bind each as a prepared placeholder, so
1163: // the post_type value can never break out of the IN() list (SQL injection).
1164: $type = array_values( array_filter( $type, 'post_type_exists' ) );
1165:
1166: if ( empty( $type ) ) {
1167: $type = epl_get_core_post_types();
1168: }
1169:
1170: $type_placeholders = implode( ', ', array_fill( 0, count( $type ), '%s' ) );
1171:
1172: global $wpdb;
1173:
1174: $query = "SELECT distinct(pm.`meta_value`)
1175: FROM {$wpdb->postmeta} pm
1176: LEFT JOIN {$wpdb->posts} p
1177: ON p.`ID` = pm.`post_id`
1178: WHERE pm.`meta_key` = %s
1179: AND p.`post_status` = %s
1180: AND p.`post_type`
1181: IN ( {$type_placeholders} )
1182: AND pm.`meta_value` != ''";
1183:
1184: $prepare_args = array_merge( array( $key, $status ), $type );
1185: $results = epl_listing_query_cache( $wpdb->prepare( $query, $prepare_args ), 'results' );
1186:
1187: if ( ! empty( $results ) ) {
1188:
1189: $return = array();
1190: if ( 'property_category' === $key ) {
1191: $defaults = epl_listing_load_meta_property_category();
1192: }
1193: foreach ( $results as $result ) {
1194: if ( isset( $defaults ) && ! empty( $defaults ) ) {
1195: if ( isset( $defaults[ $result->meta_value ] ) ) {
1196: $return[ $result->meta_value ] = $defaults[ $result->meta_value ];
1197: } else {
1198: $return[ $result->meta_value ] = $result->meta_value;
1199: }
1200: } else {
1201: $return[] = $result->meta_value;
1202: }
1203: }
1204: foreach ( $return as $key => &$elem ) {
1205: $elem = maybe_unserialize( $elem );
1206: if ( ! empty( $elem ) && is_array( $elem ) ) {
1207: foreach ( $elem as $el ) {
1208: $return[] = $el;
1209: }
1210: unset( $return[ $key ] );
1211: }
1212: }
1213:
1214: $return = array_filter( $return );
1215:
1216: if ( isset( $defaults ) ) {
1217:
1218: $values = $return;
1219:
1220: } else {
1221:
1222: $values = array();
1223:
1224: foreach ( $return as $s_res ) {
1225: $values[ $s_res ] = esc_html( ucwords( $s_res ) );
1226: }
1227: }
1228:
1229: return apply_filters( 'epl_get_unique_post_meta_values', $values, $key, $type );
1230: }
1231: }
1232:
1233: /**
1234: * Esc Values
1235: *
1236: * @param string $text String output.
1237: *
1238: * @return string
1239: * @since 2.3.1
1240: */
1241: function epl_esc_like( $text ) {
1242: return addcslashes( $text, '_%\\' );
1243: }
1244:
1245: /**
1246: * Search Where
1247: *
1248: * @param string $where Return where.
1249: * @param array $wp_query WordPress query object.
1250: *
1251: * @return string
1252: * @since 2.3.1
1253: */
1254: function epl_listings_where( $where, $wp_query ) {
1255: global $wpdb;
1256:
1257: $epl_post_title = $wp_query->get( 'epl_post_title' );
1258:
1259: if ( $epl_post_title ) {
1260: $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( epl_esc_like( $epl_post_title ) ) . '%\'';
1261: }
1262: return $where;
1263: }
1264: add_filter( 'posts_where', 'epl_listings_where', 10, 2 );
1265:
1266: /**
1267: * Get available terms based on post type & property status
1268: *
1269: * @param string $tax Taxonomy name.
1270: * @param string $post_type Post type name.
1271: * @param string $property_status Listing status.
1272: * @return mixed terms which is filterable with epl_get_available_terms.
1273: *
1274: * @since 3.5.26 Query values are now escaped with a prepared statement.
1275: * @since 3.6 Fix: Slow query. The listing meta table is only joined when filtering by listing status, on the property_status key, instead of every meta row of every listing (23x faster on 735 rentals). Results are cached until a listing changes (epl_listing_query_cache()).
1276: * @since 3.6 Security: only real listing statuses are used (epl_search_known_statuses()), so a made-up status can't add cache entries.
1277: */
1278: function epl_get_available_terms( $tax = 'location', $post_type = '', $property_status = '' ) {
1279:
1280: // Only real listing statuses: results are cached per status (epl_search_known_statuses()).
1281: $property_status = epl_search_known_statuses( $property_status );
1282: global $wpdb;
1283:
1284: $query_args = array( $tax );
1285:
1286: // The listing meta is only joined when filtering by listing status, on that one key.
1287: // Joining every meta row of every listing (100+ each) made this query slow.
1288: $status_values = array();
1289: if ( ! empty( $property_status ) ) {
1290: $property_status = array_map( 'trim', explode( ',', $property_status ) ); // Passed to the filter as an array, as before.
1291: $status_values = $property_status;
1292: }
1293: $status_join = $status_values ? "INNER JOIN {$wpdb->prefix}postmeta pm ON ( p.ID = pm.post_id AND pm.meta_key = 'property_status' )" : '';
1294:
1295: $available_loc_query = "
1296: SELECT DISTINCT (
1297: tt.term_id
1298: )
1299: FROM {$wpdb->prefix}posts p
1300: {$status_join}
1301: INNER JOIN {$wpdb->prefix}term_relationships tr ON ( p.ID = tr.object_id )
1302: INNER JOIN {$wpdb->prefix}term_taxonomy tt ON ( tr.term_taxonomy_id = tt.term_taxonomy_id ) WHERE
1303: tt.taxonomy = %s
1304: AND p.post_status = 'publish'";
1305:
1306: if ( is_array( $post_type ) && ! empty( $post_type ) ) {
1307: $available_loc_query .= ' AND p.post_type IN (' . implode( ',', array_fill( 0, count( $post_type ), '%s' ) ) . ')';
1308: $query_args = array_merge( $query_args, array_values( $post_type ) );
1309: } else {
1310: $available_loc_query .= ' AND p.post_type = %s';
1311: $query_args[] = is_array( $post_type ) ? '' : (string) $post_type;
1312: }
1313:
1314: if ( $status_values ) {
1315: $available_loc_query .= '
1316: AND pm.meta_value IN (' . implode( ',', array_fill( 0, count( $status_values ), '%s' ) ) . ')';
1317: $query_args = array_merge( $query_args, array_values( $status_values ) );
1318: }
1319:
1320: $sql = $wpdb->prepare( $available_loc_query, $query_args ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
1321:
1322: $available_locs = epl_listing_query_cache( $sql );
1323: $terms = get_terms(
1324: array(
1325: 'taxonomy' => $tax,
1326: 'hide_empty' => true,
1327: 'include' => $available_locs,
1328: )
1329: );
1330: $arr = array();
1331: foreach ( $terms as $term ) {
1332: $arr[ $term->term_id ] = $term->name;
1333: }
1334: return apply_filters( 'epl_get_available_terms', $arr, $tax, $post_type, $property_status );
1335: }
1336:
1337: /**
1338: * Search Get Locations
1339: *
1340: * @param string $post_type Post type name.
1341: * @param string $property_status Listing status.
1342: *
1343: * @return string
1344: * @since 2.3.1
1345: */
1346: function epl_get_available_locations( $post_type = '', $property_status = '' ) {
1347: return epl_get_available_terms( 'location', $post_type, $property_status );
1348: }
1349:
1350: /**
1351: * Pre Process Search Meta
1352: *
1353: * @param array $meta_query Array of meta query.
1354: * @param array $form_fields Form fields.
1355: *
1356: * @return mixed|void
1357: * @since 2.3.1
1358: */
1359: function epl_preprocess_search_meta_query( $meta_query, $form_fields ) {
1360: $range_sep = apply_filters( 'epl_search_field_range_separator', '-' );
1361: $option_sep = apply_filters( 'epl_search_field_option_separator', ',' );
1362: foreach ( $meta_query as $key => &$query ) {
1363:
1364: if ( isset( $query['compare'] ) && isset( $query['value'] )
1365: && in_array( strtoupper( $query['compare'] ), array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ), true )
1366: && ! is_array( $query['value'] ) ) {
1367: $query['value'] = array_map( 'trim', explode( $option_sep, $query['value'] ) );
1368:
1369: if ( isset( $form_fields[ $query['key'] ]['option_type'] ) && 'range' === $form_fields[ $query['key'] ]['option_type'] ) {
1370: $query['value'] = array(
1371: current( explode( $range_sep, current( $query['value'] ) ) ),
1372: next( explode( $range_sep, end( $query['value'] ) ) ),
1373: );
1374: }
1375: }
1376: }
1377: return apply_filters( 'epl_preprocess_search_meta_query', $meta_query );
1378: }
1379:
1380: /**
1381: * Contacts widget form functions
1382: *
1383: * @param array $atts Array of attributes.
1384: *
1385: * @return mixed|void
1386: * @since 3.0
1387: * @since 3.5.25 Support an explicit listing_id attribute and guard the single-listing lookup.
1388: */
1389: function epl_contact_capture_get_widget_fields( $atts ) {
1390: $property_id = 0;
1391: if ( isset( $atts['listing_id'] ) && absint( $atts['listing_id'] ) > 0 ) {
1392: // Listing bound explicitly, eg. [listing_contact listing_id="123"].
1393: $property_id = absint( $atts['listing_id'] );
1394: } elseif ( is_epl_post_single() ) {
1395: global $property;
1396: $property_id = isset( $property->post->ID ) ? absint( $property->post->ID ) : 0;
1397: }
1398: $fields = array(
1399: array(
1400: 'label' => __( 'First Name', 'easy-property-listings' ),
1401: 'name' => 'epl_contact_first_name',
1402: 'id' => 'epl_contact_first_name',
1403: 'type' => 'text',
1404: 'data-default' => 'on',
1405: ),
1406: array(
1407: 'label' => __( 'Last Name', 'easy-property-listings' ),
1408: 'name' => 'epl_contact_last_name',
1409: 'id' => 'epl_contact_last_name',
1410: 'type' => 'text',
1411: 'data-default' => 'on',
1412: ),
1413: array(
1414: 'label' => __( 'Email *', 'easy-property-listings' ),
1415: 'name' => 'epl_contact_email',
1416: 'id' => 'epl_contact_email',
1417: 'type' => 'email',
1418: 'data-default' => 'on',
1419: ),
1420: array(
1421: 'label' => __( 'Phone', 'easy-property-listings' ),
1422: 'name' => 'epl_contact_phone',
1423: 'id' => 'epl_contact_phone',
1424: 'type' => 'text',
1425: 'data-default' => 'off',
1426: ),
1427: array(
1428: 'label' => __( 'Subject', 'easy-property-listings' ),
1429: 'name' => 'epl_contact_title',
1430: 'id' => 'epl_contact_title',
1431: 'type' => 'text',
1432: 'data-default' => 'on',
1433: ),
1434: array(
1435: 'label' => __( 'Message', 'easy-property-listings' ),
1436: 'name' => 'epl_contact_note',
1437: 'id' => 'epl_contact_note',
1438: 'type' => 'textarea',
1439: 'data-default' => 'on',
1440: ),
1441: array(
1442: 'label' => '',
1443: 'name' => 'epl_contact_anti_spam',
1444: 'id' => 'epl_contact_note',
1445: 'type' => 'hidden',
1446: 'data-default' => 'on',
1447: ),
1448: array(
1449: 'name' => 'epl_contact_listing_id',
1450: 'id' => 'epl_contact_listing_id',
1451: 'type' => 'hidden',
1452: 'value' => $property_id,
1453: 'data-default' => 'on',
1454: ),
1455: array(
1456: 'name' => 'epl_contact_submit',
1457: 'id' => 'epl_contact_submit',
1458: 'type' => 'submit',
1459: 'value' => __( 'Submit', 'easy-property-listings' ),
1460: 'data-default' => 'on',
1461: ),
1462: );
1463: // Allow additional fields.
1464: $all_fields = apply_filters( 'epl_contact_capture_get_widget_fields', $fields );
1465: // Filter fields based on attributes.
1466: foreach ( $all_fields as $field_key => &$field ) {
1467:
1468: if ( isset( $atts[ $field['name'] ] ) && 'on' !== $atts[ $field['name'] ] ) {
1469: unset( $all_fields[ $field_key ] );
1470: } else {
1471: $field['data-default'] = 'on';
1472: }
1473: }
1474: return $all_fields;
1475: }
1476:
1477: /**
1478: * Contacts widget form get defaults
1479: *
1480: * @since 3.0
1481: * @since 3.5.25 Added the listing_id default so the shortcode attribute is preserved.
1482: */
1483: function epl_contact_capture_get_widget_defaults() {
1484: $fields = epl_contact_capture_widget_form_fields();
1485: $defaults = array();
1486: foreach ( $fields as $field ) {
1487: if ( 'checkbox' === $field['type'] ) {
1488: $defaults[ $field['key'] ] = ( isset( $field['default'] ) && 'off' === $field['default'] ) ? 'off' : 'on';
1489: } else {
1490: $defaults[ $field['key'] ] = isset( $field['default'] ) ? $field['default'] : '';
1491: }
1492: }
1493: // Allow a listing to be bound explicitly, eg. [listing_contact listing_id="123"].
1494: $defaults['listing_id'] = 0;
1495: return apply_filters( 'epl_contact_capture_get_widget_defaults', $defaults );
1496: }
1497:
1498: /**
1499: * Contacts widget form get fields
1500: *
1501: * @since 3.0
1502: */
1503: function epl_contact_capture_widget_form_fields() {
1504: $fields = array(
1505: array(
1506: 'key' => 'title',
1507: 'label' => __( 'Title', 'easy-property-listings' ),
1508: 'type' => 'text',
1509: 'default' => __( 'Contact Form', 'easy-property-listings' ),
1510: ),
1511: array(
1512: 'key' => 'description',
1513: 'label' => __( 'Description', 'easy-property-listings' ),
1514: 'type' => 'textarea',
1515: 'default' => '',
1516: ),
1517: array(
1518: 'label' => __( 'First Name', 'easy-property-listings' ),
1519: 'key' => 'epl_contact_first_name',
1520: 'type' => 'checkbox',
1521: 'default' => 'on',
1522: ),
1523: array(
1524: 'label' => __( 'Last Name', 'easy-property-listings' ),
1525: 'key' => 'epl_contact_last_name',
1526: 'type' => 'checkbox',
1527: 'default' => 'on',
1528: ),
1529: array(
1530: 'label' => __( 'Email', 'easy-property-listings' ),
1531: 'key' => 'epl_contact_email',
1532: 'type' => 'checkbox',
1533: 'default' => 'on',
1534: ),
1535: array(
1536: 'label' => __( 'Phone', 'easy-property-listings' ),
1537: 'key' => 'epl_contact_phone',
1538: 'id' => 'epl_contact_phone',
1539: 'type' => 'checkbox',
1540: 'default' => 'off',
1541: ),
1542: array(
1543: 'label' => __( 'Subject', 'easy-property-listings' ),
1544: 'key' => 'epl_contact_title',
1545: 'type' => 'checkbox',
1546: 'default' => 'on',
1547: ),
1548: array(
1549: 'label' => __( 'Message', 'easy-property-listings' ),
1550: 'key' => 'epl_contact_note',
1551: 'type' => 'checkbox',
1552: 'default' => 'on',
1553: ),
1554: array(
1555: 'label' => __( 'Anti Spam', 'easy-property-listings' ),
1556: 'key' => 'epl_contact_anti_spam',
1557: 'type' => 'checkbox',
1558: 'default' => 'on',
1559: ),
1560: array(
1561: 'key' => 'submit',
1562: 'label' => __( 'Submit Label', 'easy-property-listings' ),
1563: 'type' => 'text',
1564: 'default' => __( 'Submit', 'easy-property-listings' ),
1565: ),
1566: );
1567: return apply_filters( 'epl_contact_capture_widget_form_fields', $fields );
1568: }
1569:
1570: /**
1571: * Get listing owner
1572: *
1573: * @since 3.3
1574: */
1575: function epl_get_owners() {
1576: $c_array = array();
1577: $contact_ids = (array) epl_get_meta_values( 'property_owner', epl_get_core_post_types() );
1578: foreach ( $contact_ids as $contact ) {
1579: $contact_object = new EPL_Contact( $contact );
1580: $c_array[ $contact ] = $contact_object->name;
1581: }
1582: return $c_array;
1583: }
1584:
1585: /**
1586: * Get price slider
1587: *
1588: * @since 3.3
1589: * @since 3.4.1 Currency support for search field sliders
1590: */
1591: function epl_get_field_sliders() {
1592:
1593: $currency = epl_currency_filter( '' );
1594: $currency_position = epl_get_currency_position();
1595:
1596: $position = ( isset( $currency_position ) && ! empty( $currency_position ) ) ? $currency_position : 'before';
1597:
1598: if ( 'before' === $position ) {
1599: $prefix = $currency;
1600: $suffix = '';
1601: } else {
1602: $suffix = $currency;
1603: $prefix = '';
1604: }
1605:
1606: $sliders = array(
1607: 'epl_field_slider_property_price_global' => array(
1608: 'els' => array( 'property_price_global_from', 'property_price_global_to' ),
1609: 'label' => __( 'Price Search', 'easy-property-listings' ),
1610: 'prefix' => $prefix,
1611: 'suffix' => $suffix,
1612: 'separator' => ' - ',
1613: ), /**
1614: 'epl_field_slider_property_price' => array(
1615: 'els' => array('property_price_from','property_price_to'),
1616: 'label' => __('Price','easy-property-listings'),
1617: 'prefix' => '$',
1618: 'suffix' => '',
1619: 'separator' => ' - '
1620: ),
1621: 'epl_field_slider_property_bedrooms' => array(
1622: 'els' => array('property_bedrooms_min','property_bedrooms_max'),
1623: 'label' => __('Bedrooms','easy-property-listings'),
1624: 'prefix' => '',
1625: 'suffix' => '',
1626: 'separator' => ' - '
1627: ),
1628: 'epl_field_slider_property_land_area' => array(
1629: 'els' => array('property_land_area_min','property_land_area_max'),
1630: 'label' => __('Land Area','easy-property-listings'),
1631: 'prefix' => '',
1632: 'suffix' => 'm<sup>2</sup>',
1633: 'separator' => ' - ',
1634: 'min' => 0,
1635: 'max' => 2000,
1636: 'step' => 10
1637: ),
1638: 'epl_field_slider_property_building_area' => array(
1639: 'els' => array('property_building_area_min','property_building_area_max'),
1640: 'label' => __('Building Area','easy-property-listings'),
1641: 'prefix' => '',
1642: 'suffix' => 'sq',
1643: 'separator' => ' - ',
1644: 'min' => 0,
1645: 'max' => 2000,
1646: 'step' => 10
1647: )
1648: */
1649: );
1650:
1651: return apply_filters( 'epl_search_slider_fields', $sliders );
1652: }
1653: