PluginProbe
Property Hive / trunk
Property Hive vtrunk
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 1.4.62 1.4.63 All 259 releases
propertyhive / includes / class-ph-shortcodes.php

class-ph-shortcodes.php in Property Hive trunk, at includes/class-ph-shortcodes.php

2,311 lines 68.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 /**
6 * PH_Shortcodes class.
7 *
8 * @class PH_Shortcodes
9 * @version 1.0.0
10 * @package PropertyHive/Classes
11 * @category Class
12 * @author PropertyHive
13 */
14 class PH_Shortcodes {
15
16 /**
17 * Init shortcodes
18 */
19 public static function init() {
20 // Define shortcodes
21 $shortcodes = array(
22 'properties' => __CLASS__ . '::properties',
23 'recent_properties' => __CLASS__ . '::recent_properties',
24 'featured_properties' => __CLASS__ . '::featured_properties',
25 'similar_properties' => __CLASS__ . '::similar_properties',
26 'property_search_form' => __CLASS__ . '::property_search_form',
27 'property_map' => __CLASS__ . '::property_map',
28 'property_static_map' => __CLASS__ . '::property_static_map',
29 'property_street_view' => __CLASS__ . '::property_street_view',
30 'property_office_details' => __CLASS__ . '::property_office_details',
31 'office_map' => __CLASS__ . '::office_map',
32 'applicant_registration_form' => __CLASS__ . '::applicant_registration_form',
33 'propertyhive_my_account' => __CLASS__ . '::my_account',
34 'propertyhive_login_form' => __CLASS__ . '::login_form',
35 'propertyhive_reset_password_form' => __CLASS__ . '::reset_password_form',
36 );
37
38 foreach ( $shortcodes as $shortcode => $function ) {
39 add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function );
40 }
41 }
42
43 /**
44 * Shortcode Wrapper
45 *
46 * @param mixed $function
47 * @param array $atts (default: array())
48 * @return string
49 */
50 public static function shortcode_wrapper(
51 $function,
52 $atts = array(),
53 $wrapper = array(
54 'class' => 'propertyhive',
55 'before' => null,
56 'after' => null
57 )
58 ) {
59 ob_start();
60
61 $before = empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before'];
62 $after = empty( $wrapper['after'] ) ? '</div>' : $wrapper['after'];
63
64 echo $before;
65 call_user_func( $function, $atts );
66 echo $after;
67
68 return ob_get_clean();
69 }
70
71 /**
72 * Output property search form
73 *
74 * @param array $atts
75 * @return string
76 */
77 public static function property_search_form( $atts ) {
78 $atts = shortcode_atts( array(
79 'id' => 'shortcode',
80 'default_department' => ''
81 ), $atts, 'property_search_form' );
82
83 $form_controls = ph_get_search_form_fields();
84
85 $form_controls = apply_filters( 'propertyhive_search_form_fields_' . $atts['id'], $form_controls, $atts );
86 $form_controls = apply_filters( 'propertyhive_search_form_fields', $form_controls, $atts );
87
88 // We 100% need department so make sure it exists. If it doesn't, set a hidden field
89 if ( !isset($form_controls['department']) )
90 {
91 $original_form_controls = ph_get_search_form_fields();
92 $original_department = $original_form_controls['department'];
93 $original_department['type'] = 'hidden';
94
95 $form_controls['department'] = $original_department;
96 }
97
98 $form_controls = apply_filters( 'propertyhive_search_form_fields_after_' . $atts['id'], $form_controls, $atts );
99 $form_controls = apply_filters( 'propertyhive_search_form_fields_after', $form_controls, $atts );
100
101 if (
102 isset($atts['default_department']) && in_array($atts['default_department'], array_keys( ph_get_departments() )) &&
103 ( !isset($_REQUEST['department']) )
104 )
105 {
106 $form_controls['department']['value'] = $atts['default_department'];
107 }
108
109 ob_start();
110
111 ph_get_template( 'global/search-form.php', array( 'form_controls' => $form_controls, 'id' => $atts['id'] ) );
112
113 return ob_get_clean();
114 }
115
116 /**
117 * List multiple properties shortcode
118 *
119 * @param array $atts
120 * @return string
121 */
122 public static function properties( $atts ) {
123
124 global $propertyhive_loop;
125
126 $atts = shortcode_atts( array(
127 'columns' => '2',
128 'orderby' => 'meta_value_num',
129 'order' => 'desc',
130 'meta_key' => '_price_actual',
131 'ids' => '',
132 'exclude' => '',
133 'department' => '', // residential-sales / residential-lettings / commercial / any custom department
134 'minimum_price' => '',
135 'maximum_price' => '',
136 'bedrooms' => '',
137 'minimum_bedrooms' => '',
138 'keyword' => '',
139 'address_keyword' => '',
140 'country' => '',
141 'country_not' => '',
142 'availability_id' => '',
143 'marketing_flag' => '', // Deprecated. Use marketing_flag_id instead
144 'marketing_flag_id' => '', // Should be marketing_flag_id. Might deprecate this in the future
145 'property_type_id' => '',
146 'sale_by_id' => '',
147 'location_id' => '',
148 'office_id' => '',
149 'negotiator_id' => '',
150 'commercial_for_sale' => '',
151 'commercial_to_rent' => '',
152 'posts_per_page' => 10,
153 'no_results_output' => '',
154 'pagination' => '',
155 'show_order' => '',
156 'show_result_count' => '',
157 'carousel' => '',
158 ), $atts, 'properties' );
159
160 if ( isset($atts['carousel']) && !empty($atts['carousel']) )
161 {
162 $params = array(
163 'items' => 1,
164 'controlsPosition' => 'bottom',
165 'gutter' => 20,
166 'mouseDrag' => true,
167 'nav' => false,
168 'navPosition' => 'bottom',
169 'controlsText' => array("Prev", "Next"),
170 'responsive' => array(
171 640 => array(
172 'items' => (int)$atts['columns']
173 )
174 )
175 );
176 $params = apply_filters( 'propertyhive_carousel_params', $params );
177 $params = apply_filters( 'propertyhive_properties_carousel_params', $params );
178 wp_localize_script( 'propertyhive_carousel', 'propertyhive_carousel_params', $params );
179
180 wp_enqueue_style( 'tiny_slider_css' );
181 wp_enqueue_script( 'tiny_slider' );
182 wp_enqueue_script( 'propertyhive_carousel' );
183 }
184
185 $meta_query = array(
186 array(
187 'key' => '_on_market',
188 'value' => 'yes',
189 )
190 );
191
192 if ( isset($atts['department']) && in_array($atts['department'], array_keys( ph_get_departments() )) )
193 {
194 $departments = explode(",", $atts['department']);
195 $departments = array_map('trim', $departments);
196 $departments = array_filter($departments);
197
198 $meta_query[] = array(
199 'key' => '_department',
200 'value' => $departments,
201 'compare' => 'IN'
202 );
203 }
204
205 if ( isset($atts['bedrooms']) && $atts['bedrooms'] != '' && is_numeric($atts['bedrooms']) )
206 {
207 $meta_query[] = array(
208 'key' => '_bedrooms',
209 'value' => sanitize_text_field( $atts['bedrooms'] ),
210 'compare' => '=',
211 'type' => 'NUMERIC'
212 );
213 }
214
215 if ( isset($atts['minimum_bedrooms']) && $atts['minimum_bedrooms'] != '' && is_numeric($atts['minimum_bedrooms']) )
216 {
217 $meta_query[] = array(
218 'key' => '_bedrooms',
219 'value' => sanitize_text_field( $atts['minimum_bedrooms'] ),
220 'compare' => '>=',
221 'type' => 'NUMERIC'
222 );
223 }
224
225 $base_department = $atts['department'];
226 if ( $atts['department'] !== '' && !in_array($atts['department'], array_keys( ph_get_departments( true ) )) )
227 {
228 $base_department = ph_get_custom_department_based_on($base_department);
229 }
230
231 if ( isset($atts['department']) && ( $base_department == 'residential-sales' || $base_department == 'residential-lettings' ) && isset($atts['minimum_price']) && $atts['minimum_price'] != '' )
232 {
233 $search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' );
234
235 $minimum_price = $atts['minimum_price'];
236 if ( $search_form_currency != 'GBP' )
237 {
238 // Convert $atts['minimum_price'] to GBP
239 $ph_countries = new PH_Countries();
240
241 $minimum_price = $ph_countries->convert_price_to_gbp( $minimum_price, $search_form_currency );
242 }
243
244 $meta_query[] = array(
245 'key' => '_price_actual',
246 'value' => sanitize_text_field( floor( $minimum_price ) ),
247 'compare' => '>=',
248 'type' => 'NUMERIC'
249 );
250 }
251
252 if ( isset($atts['department']) && ( $base_department == 'residential-sales' || $base_department == 'residential-lettings' ) && isset($atts['maximum_price']) && $atts['maximum_price'] != '' )
253 {
254 $search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' );
255
256 $maximum_price = $atts['maximum_price'];
257 if ( $search_form_currency != 'GBP' )
258 {
259 // Convert $atts['maximum_price'] to GBP
260 $ph_countries = new PH_Countries();
261
262 $maximum_price = $ph_countries->convert_price_to_gbp( $maximum_price, $search_form_currency );
263 }
264
265 $meta_query[] = array(
266 'key' => '_price_actual',
267 'value' => sanitize_text_field( ceil( $maximum_price ) ),
268 'compare' => '<=',
269 'type' => 'NUMERIC'
270 );
271 }
272
273 if ( isset($atts['address_keyword']) && $atts['address_keyword'] != '' )
274 {
275 $atts['address_keyword'] = ph_clean( trim( $atts['address_keyword'] ) );
276
277 $address_keywords = array( $atts['address_keyword'] );
278
279 if ( strpos( $atts['address_keyword'], ' ' ) !== FALSE )
280 {
281 $address_keywords[] = str_replace(" ", "-", $atts['address_keyword']);
282 }
283 if ( strpos( $atts['address_keyword'], '-' ) !== FALSE )
284 {
285 $address_keywords[] = str_replace("-", " ", $atts['address_keyword']);
286 }
287 if ( strpos( $atts['address_keyword'], '.' ) !== FALSE )
288 {
289 $address_keywords[] = str_replace(".", "", $atts['address_keyword']);
290 }
291 if ( stripos( $atts['address_keyword'], 'st ' ) !== FALSE )
292 {
293 $address_keywords[] = str_ireplace("st ", "st. ", $atts['address_keyword']);
294 }
295 if ( strpos( $atts['address_keyword'], '\'' ) !== FALSE )
296 {
297 $address_keywords[] = str_replace("'", "", $atts['address_keyword']);
298 }
299
300 $sub_meta_query = array('relation' => 'OR');
301
302 $address_keyword_compare = get_option( 'propertyhive_address_keyword_compare', '=' );
303 if ( $address_keyword_compare == 'polygon' )
304 {
305 $address_keyword_compare = apply_filters('propertyhive_shortcode_address_keyword_compare', '=');
306 }
307
308 foreach ( $address_keywords as $address_keyword )
309 {
310 $sub_meta_query[] = array(
311 'key' => '_reference_number',
312 'value' => $address_keyword,
313 'compare' => $address_keyword_compare
314 );
315 $sub_meta_query[] = array(
316 'key' => '_address_street',
317 'value' => $address_keyword,
318 'compare' => $address_keyword_compare
319 );
320 $sub_meta_query[] = array(
321 'key' => '_address_two',
322 'value' => $address_keyword,
323 'compare' => $address_keyword_compare
324 );
325 $sub_meta_query[] = array(
326 'key' => '_address_three',
327 'value' => $address_keyword,
328 'compare' => $address_keyword_compare
329 );
330 $sub_meta_query[] = array(
331 'key' => '_address_four',
332 'value' => $address_keyword,
333 'compare' => $address_keyword_compare
334 );
335 }
336 if ( strlen($atts['address_keyword']) <= 4 )
337 {
338 $sub_meta_query[] = array(
339 'key' => '_address_postcode',
340 'value' => sanitize_text_field( $atts['address_keyword'] ),
341 'compare' => '='
342 );
343 // Run regex match where given keyword is at the start of the postcode ^
344 // followed by one or zero letters (for WC2E-style postcodes) [a-zA-Z]?
345 // then a single space [ ]
346 $sub_meta_query[] = array(
347 'key' => '_address_postcode',
348 'value' => sanitize_text_field( $atts['address_keyword'] ) . '[a-zA-Z]?[ ]',
349 'compare' => 'RLIKE'
350 );
351 }
352 else
353 {
354 $sub_meta_query[] = array(
355 'key' => '_address_postcode',
356 'value' => sanitize_text_field( $atts['address_keyword'] ),
357 'compare' => 'LIKE'
358 );
359 }
360
361 $meta_query[] = $sub_meta_query;
362 }
363
364 if ( isset($atts['keyword']) && $atts['keyword'] != '' )
365 {
366 $atts['keyword'] = sanitize_text_field( trim( $atts['keyword'] ) );
367
368 $original_keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
369 $_REQUEST['keyword'] = $atts['keyword'];
370
371 add_filter( 'posts_where', array( PH()->query, 'keyword_excerpt_where' ), 10, 2 );
372
373 $keywords = array( $atts['keyword'] );
374
375 if ( strpos( $atts['keyword'], ' ' ) !== FALSE )
376 {
377 $keywords[] = str_replace(" ", "-", $atts['keyword']);
378 }
379 if ( strpos( $atts['keyword'], '-' ) !== FALSE )
380 {
381 $keywords[] = str_replace("-", " ", $atts['keyword']);
382 }
383 if ( strpos( $atts['keyword'], '.' ) !== FALSE )
384 {
385 $keywords[] = str_replace(".", "", $atts['keyword']);
386 }
387 if ( stripos( $atts['keyword'], 'st ' ) !== FALSE )
388 {
389 $keywords[] = str_ireplace("st ", "st. ", $atts['keyword']);
390 }
391 if ( strpos( $atts['keyword'], '\'' ) !== FALSE )
392 {
393 $keywords[] = str_replace("'", "", $atts['keyword']);
394 }
395
396 $sub_meta_query = array('relation' => 'OR');
397
398 $address_keyword_compare = get_option( 'propertyhive_address_keyword_compare', '=' );
399 if ( $address_keyword_compare == 'polygon' )
400 {
401 $address_keyword_compare = apply_filters('propertyhive_shortcode_address_keyword_compare', '=');
402 }
403
404 foreach ( $keywords as $keyword )
405 {
406 $sub_meta_query[] = array(
407 'key' => '_reference_number',
408 'value' => $keyword,
409 'compare' => $address_keyword_compare
410 );
411 $sub_meta_query[] = array(
412 'key' => '_address_street',
413 'value' => $keyword,
414 'compare' => $address_keyword_compare
415 );
416 $sub_meta_query[] = array(
417 'key' => '_address_two',
418 'value' => $keyword,
419 'compare' => $address_keyword_compare
420 );
421 $sub_meta_query[] = array(
422 'key' => '_address_three',
423 'value' => $keyword,
424 'compare' => $address_keyword_compare
425 );
426 $sub_meta_query[] = array(
427 'key' => '_address_four',
428 'value' => $keyword,
429 'compare' => $address_keyword_compare
430 );
431 $sub_meta_query[] = array(
432 'key' => '_features_concatenated',
433 'value' => $keyword,
434 'compare' => 'LIKE'
435 );
436 $sub_meta_query[] = array(
437 'key' => '_descriptions_concatenated',
438 'value' => $keyword,
439 'compare' => 'LIKE'
440 );
441 }
442 if ( strlen($atts['keyword']) <= 4 )
443 {
444 $sub_meta_query[] = array(
445 'key' => '_address_postcode',
446 'value' => sanitize_text_field( $atts['keyword'] ),
447 'compare' => '='
448 );
449 // Run regex match where given keyword is at the start of the postcode ^
450 // followed by one or zero letters (for WC2E-style postcodes) [a-zA-Z]?
451 // then a single space [ ]
452 $sub_meta_query[] = array(
453 'key' => '_address_postcode',
454 'value' => sanitize_text_field( $atts['keyword'] ) . '[a-zA-Z]?[ ]',
455 'compare' => 'RLIKE'
456 );
457 }
458 else
459 {
460 $sub_meta_query[] = array(
461 'key' => '_address_postcode',
462 'value' => sanitize_text_field( $atts['keyword'] ),
463 'compare' => 'LIKE'
464 );
465 }
466
467 $meta_query[] = $sub_meta_query;
468
469 $_REQUEST['keyword'] = $original_keyword; // reset back in case it's used elsewhere
470 }
471
472 if ( isset($atts['country']) && $atts['country'] != '' )
473 {
474 $meta_query[] = array(
475 'key' => '_address_country',
476 'value' => sanitize_text_field( $atts['country'] ),
477 'compare' => '=',
478 );
479 }
480
481 if ( isset($atts['country_not']) && $atts['country_not'] != '' )
482 {
483 $meta_query[] = array(
484 'key' => '_address_country',
485 'value' => sanitize_text_field( $atts['country_not'] ),
486 'compare' => '!=',
487 );
488 }
489
490 if ( isset($atts['office_id']) && $atts['office_id'] != '' )
491 {
492 $meta_query[] = array(
493 'key' => '_office_id',
494 'value' => explode(",", $atts['office_id']),
495 'compare' => 'IN',
496 );
497 }
498
499 if ( isset($atts['negotiator_id']) && $atts['negotiator_id'] != '' )
500 {
501 $meta_query[] = array(
502 'key' => '_negotiator_id',
503 'value' => explode(",", $atts['negotiator_id']),
504 'compare' => 'IN',
505 );
506 }
507
508 if ( isset($atts['commercial_for_sale']) && $atts['commercial_for_sale'] != '' )
509 {
510 $meta_query[] = array(
511 'key' => '_for_sale',
512 'value' => 'yes',
513 'compare' => '=',
514 );
515 }
516
517 if ( isset($atts['commercial_to_rent']) && $atts['commercial_to_rent'] != '' )
518 {
519 $meta_query[] = array(
520 'key' => '_to_rent',
521 'value' => 'yes',
522 'compare' => '=',
523 );
524 }
525
526 $tax_query = array();
527
528 if ( isset($atts['availability_id']) && $atts['availability_id'] != '' )
529 {
530 $tax_query[] = array(
531 'taxonomy' => 'availability',
532 'terms' => explode(",", $atts['availability_id']),
533 'compare' => 'IN',
534 );
535 }
536
537 // Fallback for deprecated marketing_flag
538 if ( isset($atts['marketing_flag']) && $atts['marketing_flag'] != '' )
539 {
540 $atts['marketing_flag_id'] = $atts['marketing_flag'];
541 }
542 if ( isset($atts['marketing_flag_id']) && $atts['marketing_flag_id'] != '' )
543 {
544 $tax_query[] = array(
545 'taxonomy' => 'marketing_flag',
546 'terms' => explode(",", $atts['marketing_flag_id']),
547 'compare' => 'IN',
548 );
549 }
550
551 if ( isset($atts['property_type_id']) && $atts['property_type_id'] != '' )
552 {
553 // Change field to check when department is specified as commercial, or if commercial is the only active department
554 if (
555 ( isset($atts['department']) && $base_department == 'commercial' ) ||
556 (
557 !isset($atts['department']) &&
558 get_option( 'propertyhive_active_departments_sales' ) != 'yes' &&
559 get_option( 'propertyhive_active_departments_lettings' ) != 'yes' &&
560 get_option( 'propertyhive_active_departments_commercial' ) == 'yes'
561 )
562 )
563 {
564 $tax_query[] = array(
565 'taxonomy' => 'commercial_property_type',
566 'terms' => explode(",", $atts['property_type_id']),
567 'compare' => 'IN',
568 );
569 }
570 else
571 {
572 $tax_query[] = array(
573 'taxonomy' => 'property_type',
574 'terms' => explode(",", $atts['property_type_id']),
575 'compare' => 'IN',
576 );
577 }
578 }
579
580 if ( isset($atts['location_id']) && $atts['location_id'] != '' )
581 {
582 $tax_query[] = array(
583 'taxonomy' => 'location',
584 'terms' => explode(",", $atts['location_id']),
585 'compare' => 'IN',
586 );
587 }
588
589 if ( isset($atts['sale_by_id']) && $atts['sale_by_id'] != '' )
590 {
591 $tax_query[] = array(
592 'taxonomy' => 'sale_by',
593 'terms' => explode(",", $atts['sale_by_id']),
594 'compare' => 'IN',
595 );
596 }
597
598 // Change default meta key when department is specified as commercial, or if commercial is the only active department
599 if (
600 ( isset($atts['department']) && $base_department == 'commercial' ) ||
601 (
602 get_option( 'propertyhive_active_departments_sales' ) != 'yes' &&
603 get_option( 'propertyhive_active_departments_lettings' ) != 'yes' &&
604 get_option( 'propertyhive_active_departments_commercial' ) == 'yes'
605 )
606 )
607 {
608 $atts['meta_key'] = '_floor_area_from_sqft';
609 }
610
611 // Get which page we're currently viewing from the URL
612 $paged = max( 1, get_query_var( 'paged' ) );
613
614 $args = array(
615 'post_type' => 'property',
616 'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ),
617 'ignore_sticky_posts' => 1,
618 'orderby' => $atts['orderby'],
619 'order' => $atts['order'],
620 'posts_per_page' => $atts['posts_per_page'],
621 'paged' => $paged,
622 'meta_query' => $meta_query,
623 'tax_query' => $tax_query,
624 'has_password' => false,
625 );
626 if ( ! empty( $atts['meta_key'] ) ) {
627 $args['meta_key'] = $atts['meta_key'];
628 }
629
630 if ( ! empty( $atts['ids'] ) )
631 {
632 $include_ids = array_map( 'absint', explode( ',', $atts['ids'] ) );
633 $include_ids = array_filter( $include_ids );
634 if ( ! empty( $include_ids ) )
635 {
636 $args['post__in'] = $include_ids;
637 }
638 }
639 if ( ! empty( $atts['exclude'] ) )
640 {
641 $exclude_ids = array_map( 'absint', explode( ',', $atts['exclude'] ) );
642 $exclude_ids = array_filter( $exclude_ids );
643 if ( ! empty( $exclude_ids ) ) {
644 $args['post__not_in'] = $exclude_ids;
645 }
646 }
647 if ( isset($atts['orderby']) && $atts['orderby'] == 'date' )
648 {
649 $args['orderby'] = 'meta_value';
650 $args['meta_key'] = '_on_market_change_date';
651 }
652
653 $args['orderby'] .= ' post_title';
654
655 ob_start();
656
657 do_action('propertyhive_shortcode_properties_before_catalog_ordering', $atts);
658
659 if ( isset($atts['show_order']) && $atts['show_order'] != '' )
660 {
661 list( $args, $orderby ) = self::get_show_order_args( $atts, $args );
662
663 propertyhive_catalog_ordering( $atts['department'], $orderby );
664 }
665
666 do_action('propertyhive_shortcode_properties_after_catalog_ordering', $atts);
667
668 $args = apply_filters( 'propertyhive_properties_query', $args, $atts );
669 $args = apply_filters( 'propertyhive_shortcode_properties_query', $args, $atts );
670
671 $properties = new WP_Query( $args );
672
673 if ( isset($atts['show_result_count']) && $atts['show_result_count'] != '' )
674 {
675 $total_posts = $properties->found_posts;
676
677 $first = ( $atts['posts_per_page'] * $paged ) - $atts['posts_per_page'] + 1;
678 $last = min( $total_posts, $atts['posts_per_page'] * $paged );
679
680 propertyhive_result_count( $paged, $atts['posts_per_page'], $total_posts, $first, $last);
681 }
682
683 do_action('propertyhive_shortcode_properties_after_result_count', $atts);
684
685 $propertyhive_loop['columns'] = (int)$atts['columns'];
686
687 if ( $properties->have_posts() ) : ?>
688
689 <?php
690 ob_start();
691 propertyhive_property_loop_start();
692 $loop_start = ob_get_clean();
693 if ( isset($atts['carousel']) && !empty($atts['carousel']) )
694 {
695 $loop_start = str_replace("class=\"properties", "class=\"properties propertyhive-shortcode-carousel", $loop_start);
696 }
697 echo $loop_start;
698 ?>
699
700 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
701
702 <?php ph_get_template_part( 'content', 'property' ); ?>
703
704 <?php endwhile; // end of the loop. ?>
705
706 <?php propertyhive_property_loop_end(); ?>
707
708 <?php else: ?>
709
710 <p class="propertyhive-info no-results-message"><?php echo wp_kses_post($atts['no_results_output']); ?></p>
711
712 <?php endif;
713
714 if ( isset($atts['pagination']) && $atts['pagination'] != '' )
715 {
716 propertyhive_pagination( $properties->max_num_pages );
717 }
718
719 wp_reset_postdata();
720
721 $shortcode_output = ob_get_clean();
722
723 return apply_filters( 'propertyhive_properties_shortcode_output', '<div class="propertyhive propertyhive-properties-shortcode columns-' . (int)$atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
724 }
725
726 /**
727 * Recent Properties shortcode
728 *
729 * @access public
730 * @param array $atts
731 * @return string
732 */
733 public static function recent_properties( $atts ) {
734 global $propertyhive_loop;
735
736 $atts = shortcode_atts( array(
737 'per_page' => '12',
738 'columns' => '4',
739 'department' => '',
740 'minimum_price' => '',
741 'office_id' => '',
742 'negotiator_id' => '',
743 'availability_id' => '',
744 'marketing_flag_id' => '',
745 'property_type_id' => '',
746 'sale_by_id' => '',
747 'location_id' => '',
748 'commercial_for_sale' => '',
749 'commercial_to_rent' => '',
750 'exclude' => '',
751 'orderby' => 'date',
752 'order' => 'desc',
753 'no_results_output' => '',
754 'pagination' => '',
755 'show_order' => '',
756 'show_result_count' => '',
757 'carousel' => '',
758 ), $atts, 'recent_properties' );
759
760 if ( isset($atts['carousel']) && !empty($atts['carousel']) )
761 {
762 $params = array(
763 'items' => 1,
764 'controlsPosition' => 'bottom',
765 'gutter' => 20,
766 'mouseDrag' => true,
767 'nav' => false,
768 'navPosition' => 'bottom',
769 'controlsText' => array("Prev", "Next"),
770 'responsive' => array(
771 640 => array(
772 'items' => (int)$atts['columns']
773 )
774 )
775 );
776 $params = apply_filters( 'propertyhive_carousel_params', $params );
777 $params = apply_filters( 'propertyhive_recent_properties_carousel_params', $params );
778 wp_localize_script( 'propertyhive_carousel', 'propertyhive_carousel_params', $params );
779
780 wp_enqueue_style( 'tiny_slider_css' );
781 wp_enqueue_script( 'tiny_slider' );
782 wp_enqueue_script( 'propertyhive_carousel' );
783 }
784
785 $meta_query = PH()->query->get_meta_query();
786
787 if ( isset($atts['department']) && $atts['department'] != '' )
788 {
789 $departments = explode(",", $atts['department']);
790 $departments = array_map('trim', $departments);
791 $departments = array_filter($departments);
792
793 $meta_query[] = array(
794 'key' => '_department',
795 'value' => $departments,
796 'compare' => 'IN'
797 );
798 }
799
800 $base_department = $atts['department'];
801 if ( $atts['department'] !== '' && !in_array($atts['department'], array_keys( ph_get_departments( true ) )) )
802 {
803 $base_department = ph_get_custom_department_based_on($base_department);
804 }
805
806 if ( isset($atts['department']) && $base_department == 'residential-sales' && isset($atts['minimum_price']) && $atts['minimum_price'] != '' )
807 {
808 $search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' );
809
810 $minimum_price = $atts['minimum_price'];
811 if ( $search_form_currency != 'GBP' )
812 {
813 // Convert $atts['minimum_price'] to GBP
814 $ph_countries = new PH_Countries();
815
816 $minimum_price = $ph_countries->convert_price_to_gbp( $minimum_price, $search_form_currency );
817 }
818
819 $meta_query[] = array(
820 'key' => '_price_actual',
821 'value' => sanitize_text_field( floor( $minimum_price ) ),
822 'compare' => '>=',
823 'type' => 'NUMERIC'
824 );
825 }
826
827 if ( isset($atts['office_id']) && $atts['office_id'] != '' )
828 {
829 $meta_query[] = array(
830 'key' => '_office_id',
831 'value' => explode(",", $atts['office_id']),
832 'compare' => 'IN'
833 );
834 }
835
836 if ( isset($atts['negotiator_id']) && $atts['negotiator_id'] != '' )
837 {
838 $meta_query[] = array(
839 'key' => '_negotiator_id',
840 'value' => explode(",", $atts['negotiator_id']),
841 'compare' => 'IN',
842 );
843 }
844
845 if ( isset($atts['commercial_for_sale']) && $atts['commercial_for_sale'] != '' )
846 {
847 $meta_query[] = array(
848 'key' => '_for_sale',
849 'value' => 'yes',
850 'compare' => '=',
851 );
852 }
853
854 if ( isset($atts['commercial_to_rent']) && $atts['commercial_to_rent'] != '' )
855 {
856 $meta_query[] = array(
857 'key' => '_to_rent',
858 'value' => 'yes',
859 'compare' => '=',
860 );
861 }
862
863 $tax_query = array();
864
865 if ( isset($atts['availability_id']) && $atts['availability_id'] != '' )
866 {
867 $tax_query[] = array(
868 'taxonomy' => 'availability',
869 'terms' => explode(",", $atts['availability_id']),
870 'compare' => 'IN',
871 );
872 }
873
874 if ( isset($atts['marketing_flag_id']) && $atts['marketing_flag_id'] != '' )
875 {
876 $tax_query[] = array(
877 'taxonomy' => 'marketing_flag',
878 'terms' => explode(",", $atts['marketing_flag_id']),
879 'compare' => 'IN',
880 );
881 }
882
883 if ( isset($atts['property_type_id']) && $atts['property_type_id'] != '' )
884 {
885 // Change field to check when department is specified as commercial, or if commercial is the only active department
886 if (
887 ( isset($atts['department']) && $base_department == 'commercial' ) ||
888 (
889 !isset($atts['department']) &&
890 get_option( 'propertyhive_active_departments_sales' ) != 'yes' &&
891 get_option( 'propertyhive_active_departments_lettings' ) != 'yes' &&
892 get_option( 'propertyhive_active_departments_commercial' ) == 'yes'
893 )
894 )
895 {
896 $tax_query[] = array(
897 'taxonomy' => 'commercial_property_type',
898 'terms' => explode(",", $atts['property_type_id']),
899 'compare' => 'IN',
900 );
901 }
902 else
903 {
904 $tax_query[] = array(
905 'taxonomy' => 'property_type',
906 'terms' => explode(",", $atts['property_type_id']),
907 'compare' => 'IN',
908 );
909 }
910 }
911
912 if ( isset($atts['location_id']) && $atts['location_id'] != '' )
913 {
914 $tax_query[] = array(
915 'taxonomy' => 'location',
916 'terms' => explode(",", $atts['location_id']),
917 'compare' => 'IN',
918 );
919 }
920
921 if ( isset($atts['sale_by_id']) && $atts['sale_by_id'] != '' )
922 {
923 $tax_query[] = array(
924 'taxonomy' => 'sale_by',
925 'terms' => explode(",", $atts['sale_by_id']),
926 'compare' => 'IN',
927 );
928 }
929
930 // Get which page we're currently viewing from the URL
931 $paged = max( 1, get_query_var( 'paged' ) );
932
933 $args = array(
934 'post_type' => 'property',
935 'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ),
936 'ignore_sticky_posts' => 1,
937 'posts_per_page' => $atts['per_page'],
938 'paged' => $paged,
939 'orderby' => $atts['orderby'],
940 'order' => $atts['order'],
941 'meta_query' => $meta_query,
942 'tax_query' => $tax_query,
943 'has_password' => false,
944 );
945
946 if ( ! empty( $atts['exclude'] ) )
947 {
948 $exclude_ids = array_map( 'absint', explode( ',', $atts['exclude'] ) );
949 $exclude_ids = array_filter( $exclude_ids );
950 if ( ! empty( $exclude_ids ) ) {
951 $args['post__not_in'] = $exclude_ids;
952 }
953 }
954
955 if ( isset($atts['orderby']) && $atts['orderby'] == 'date' )
956 {
957 $args['orderby'] = 'meta_value';
958 $args['meta_key'] = '_on_market_change_date';
959 }
960
961 $args['orderby'] .= ' post_title';
962
963 ob_start();
964
965 if ( isset($atts['show_order']) && $atts['show_order'] != '' )
966 {
967 list( $args, $orderby ) = self::get_show_order_args( $atts, $args );
968
969 propertyhive_catalog_ordering( $atts['department'], $orderby );
970 }
971
972 $properties = new WP_Query( apply_filters( 'propertyhive_shortcode_recent_properties_query', $args, $atts ) );
973
974 if ( isset($atts['show_result_count']) && $atts['show_result_count'] != '' )
975 {
976 $total_posts = $properties->found_posts;
977
978 $first = ( $atts['per_page'] * $paged ) - $atts['per_page'] + 1;
979 $last = min( $total_posts, $atts['per_page'] * $paged );
980
981 propertyhive_result_count( $paged, $atts['per_page'], $total_posts, $first, $last);
982 }
983
984 $propertyhive_loop['columns'] = (int)$atts['columns'];
985
986 if ( $properties->have_posts() ) : ?>
987
988 <?php
989 ob_start();
990 propertyhive_property_loop_start();
991 $loop_start = ob_get_clean();
992 if ( isset($atts['carousel']) && !empty($atts['carousel']) )
993 {
994 $loop_start = str_replace("class=\"properties", "class=\"properties propertyhive-shortcode-carousel", $loop_start);
995 }
996 echo $loop_start;
997 ?>
998
999 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
1000
1001 <?php ph_get_template_part( 'content', 'property-recent' ); ?>
1002
1003 <?php endwhile; // end of the loop. ?>
1004
1005 <?php propertyhive_property_loop_end(); ?>
1006
1007 <?php else: ?>
1008
1009 <p class="propertyhive-info no-results-message"><?php echo wp_kses_post($atts['no_results_output']); ?></p>
1010
1011 <?php endif;
1012
1013 if ( isset($atts['pagination']) && $atts['pagination'] != '' )
1014 {
1015 propertyhive_pagination( $properties->max_num_pages );
1016 }
1017
1018 wp_reset_postdata();
1019
1020 $shortcode_output = ob_get_clean();
1021
1022 return apply_filters( 'propertyhive_recent_properties_shortcode_output', '<div class="propertyhive propertyhive-recent-properties-shortcode columns-' . (int)$atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
1023
1024 }
1025
1026 /**
1027 * Output featured properties
1028 *
1029 * @access public
1030 * @param array $atts
1031 * @return string
1032 */
1033 public static function featured_properties( $atts ) {
1034 global $propertyhive_loop;
1035
1036 $atts = shortcode_atts( array(
1037 'per_page' => '12',
1038 'columns' => '4',
1039 'department' => '',
1040 'address_keyword' => '',
1041 'office_id' => '',
1042 'negotiator_id' => '',
1043 'availability_id' => '',
1044 'exclude' => '',
1045 'orderby' => 'rand',
1046 'order' => 'desc',
1047 'meta_key' => '',
1048 'no_results_output' => '',
1049 'pagination' => '',
1050 'show_order' => '',
1051 'show_result_count' => '',
1052 'carousel' => '',
1053 ), $atts, 'featured_properties' );
1054
1055 if ( isset($atts['carousel']) && !empty($atts['carousel']) )
1056 {
1057 $params = array(
1058 'items' => 1,
1059 'controlsPosition' => 'bottom',
1060 'gutter' => 20,
1061 'mouseDrag' => true,
1062 'nav' => false,
1063 'navPosition' => 'bottom',
1064 'controlsText' => array("Prev", "Next"),
1065 'responsive' => array(
1066 640 => array(
1067 'items' => (int)$atts['columns']
1068 )
1069 )
1070 );
1071 $params = apply_filters( 'propertyhive_carousel_params', $params );
1072 $params = apply_filters( 'propertyhive_featured_properties_carousel_params', $params );
1073 wp_localize_script( 'propertyhive_carousel', 'propertyhive_carousel_params', $params );
1074
1075 wp_enqueue_style( 'tiny_slider_css' );
1076 wp_enqueue_script( 'tiny_slider' );
1077 wp_enqueue_script( 'propertyhive_carousel' );
1078 }
1079
1080 // Get which page we're currently viewing from the URL
1081 $paged = max( 1, get_query_var( 'paged' ) );
1082
1083 $args = array(
1084 'post_type' => 'property',
1085 'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ),
1086 'ignore_sticky_posts' => 1,
1087 'posts_per_page' => $atts['per_page'],
1088 'paged' => $paged,
1089 'orderby' => $atts['orderby'],
1090 'order' => $atts['order'],
1091 'has_password' => false,
1092 );
1093
1094 $meta_query = array(
1095 array(
1096 'key' => '_on_market',
1097 'value' => 'yes',
1098 ),
1099 array(
1100 'key' => '_featured',
1101 'value' => 'yes'
1102 )
1103 );
1104
1105 if ( isset($atts['department']) && $atts['department'] != '' )
1106 {
1107 $departments = explode(",", $atts['department']);
1108 $departments = array_map('trim', $departments);
1109 $departments = array_filter($departments);
1110
1111 $meta_query[] = array(
1112 'key' => '_department',
1113 'value' => $departments,
1114 'compare' => 'IN'
1115 );
1116 }
1117
1118 if ( isset($atts['address_keyword']) && $atts['address_keyword'] != '' )
1119 {
1120 $atts['address_keyword'] = sanitize_text_field( trim( $atts['address_keyword'] ) );
1121
1122 $address_keywords = array( $atts['address_keyword'] );
1123
1124 if ( strpos( $atts['address_keyword'], ' ' ) !== FALSE )
1125 {
1126 $address_keywords[] = str_replace(" ", "-", $atts['address_keyword']);
1127 }
1128 if ( strpos( $atts['address_keyword'], '-' ) !== FALSE )
1129 {
1130 $address_keywords[] = str_replace("-", " ", $atts['address_keyword']);
1131 }
1132
1133 $sub_meta_query = array('relation' => 'OR');
1134
1135 $address_keyword_compare = get_option( 'propertyhive_address_keyword_compare', '=' );
1136 if ( $address_keyword_compare == 'polygon' )
1137 {
1138 $address_keyword_compare = apply_filters('propertyhive_shortcode_address_keyword_compare', '=');
1139 }
1140
1141 foreach ( $address_keywords as $address_keyword )
1142 {
1143 $sub_meta_query[] = array(
1144 'key' => '_reference_number',
1145 'value' => $address_keyword,
1146 'compare' => $address_keyword_compare
1147 );
1148 $sub_meta_query[] = array(
1149 'key' => '_address_street',
1150 'value' => $address_keyword,
1151 'compare' => $address_keyword_compare
1152 );
1153 $sub_meta_query[] = array(
1154 'key' => '_address_two',
1155 'value' => $address_keyword,
1156 'compare' => $address_keyword_compare
1157 );
1158 $sub_meta_query[] = array(
1159 'key' => '_address_three',
1160 'value' => $address_keyword,
1161 'compare' => $address_keyword_compare
1162 );
1163 $sub_meta_query[] = array(
1164 'key' => '_address_four',
1165 'value' => $address_keyword,
1166 'compare' => $address_keyword_compare
1167 );
1168 }
1169 if ( strlen($atts['address_keyword']) <= 4 )
1170 {
1171 $sub_meta_query[] = array(
1172 'key' => '_address_postcode',
1173 'value' => sanitize_text_field( $atts['address_keyword'] ),
1174 'compare' => '='
1175 );
1176 // Run regex match where given keyword is at the start of the postcode ^
1177 // followed by one or zero letters (for WC2E-style postcodes) [a-zA-Z]?
1178 // then a single space [ ]
1179 $sub_meta_query[] = array(
1180 'key' => '_address_postcode',
1181 'value' => sanitize_text_field( $atts['address_keyword'] ) . '[a-zA-Z]?[ ]',
1182 'compare' => 'RLIKE'
1183 );
1184 }
1185 else
1186 {
1187 $sub_meta_query[] = array(
1188 'key' => '_address_postcode',
1189 'value' => sanitize_text_field( $atts['address_keyword'] ),
1190 'compare' => 'LIKE'
1191 );
1192 }
1193
1194 $meta_query[] = $sub_meta_query;
1195 }
1196
1197 if ( isset($atts['office_id']) && $atts['office_id'] != '' )
1198 {
1199 $meta_query[] = array(
1200 'key' => '_office_id',
1201 'value' => explode(",", $atts['office_id']),
1202 'compare' => 'IN'
1203 );
1204 }
1205
1206 if ( isset($atts['negotiator_id']) && $atts['negotiator_id'] != '' )
1207 {
1208 $meta_query[] = array(
1209 'key' => '_negotiator_id',
1210 'value' => explode(",", $atts['negotiator_id']),
1211 'compare' => 'IN',
1212 );
1213 }
1214
1215 $args['meta_query'] = $meta_query;
1216
1217 if ( ! empty( $atts['meta_key'] ) ) {
1218 $args['meta_key'] = $atts['meta_key'];
1219 }
1220
1221 $tax_query = array();
1222
1223 if ( isset($atts['availability_id']) && $atts['availability_id'] != '' )
1224 {
1225 $tax_query[] = array(
1226 'taxonomy' => 'availability',
1227 'terms' => explode(",", $atts['availability_id']),
1228 'compare' => 'IN',
1229 );
1230 }
1231
1232 if ( ! empty( $tax_query ) ) {
1233 $args['tax_query'] = $tax_query;
1234 }
1235
1236 if ( isset($atts['orderby']) && $atts['orderby'] == 'date' )
1237 {
1238 $args['orderby'] = 'meta_value';
1239 $args['meta_key'] = '_on_market_change_date';
1240 }
1241
1242 $args['orderby'] .= ' post_title';
1243
1244 if ( ! empty( $atts['exclude'] ) )
1245 {
1246 $exclude_ids = array_map( 'absint', explode( ',', $atts['exclude'] ) );
1247 $exclude_ids = array_filter( $exclude_ids );
1248 if ( ! empty( $exclude_ids ) ) {
1249 $args['post__not_in'] = $exclude_ids;
1250 }
1251 }
1252
1253 ob_start();
1254
1255 if ( isset($atts['show_order']) && $atts['show_order'] != '' )
1256 {
1257 list( $args, $orderby ) = self::get_show_order_args( $atts, $args );
1258
1259 propertyhive_catalog_ordering( $atts['department'], $orderby );
1260 }
1261
1262 $properties = new WP_Query( apply_filters( 'propertyhive_shortcode_featured_properties_query', $args, $atts ) );
1263
1264 if ( isset($atts['show_result_count']) && $atts['show_result_count'] != '' )
1265 {
1266 $total_posts = $properties->found_posts;
1267
1268 $first = ( $atts['per_page'] * $paged ) - $atts['per_page'] + 1;
1269 $last = min( $total_posts, $atts['per_page'] * $paged );
1270
1271 propertyhive_result_count( $paged, $atts['per_page'], $total_posts, $first, $last);
1272 }
1273
1274 $propertyhive_loop['columns'] = (int)$atts['columns'];
1275
1276 if ( $properties->have_posts() ) : ?>
1277
1278 <?php
1279 ob_start();
1280 propertyhive_property_loop_start();
1281 $loop_start = ob_get_clean();
1282 if ( isset($atts['carousel']) && !empty($atts['carousel']) )
1283 {
1284 $loop_start = str_replace("class=\"properties", "class=\"properties propertyhive-shortcode-carousel", $loop_start);
1285 }
1286 echo $loop_start;
1287 ?>
1288
1289 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
1290
1291 <?php ph_get_template_part( 'content', 'property-featured' ); ?>
1292
1293 <?php endwhile; // end of the loop. ?>
1294
1295 <?php propertyhive_property_loop_end(); ?>
1296
1297 <?php else: ?>
1298
1299 <p class="propertyhive-info no-results-message"><?php echo wp_kses_post($atts['no_results_output']); ?></p>
1300
1301 <?php endif;
1302
1303 if ( isset($atts['pagination']) && $atts['pagination'] != '' )
1304 {
1305 propertyhive_pagination( $properties->max_num_pages );
1306 }
1307
1308 wp_reset_postdata();
1309
1310 $shortcode_output = ob_get_clean();
1311
1312 return apply_filters( 'propertyhive_featured_properties_shortcode_output', '<div class="propertyhive propertyhive-featured-properties-shortcode columns-' . (int)$atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
1313 }
1314
1315 /**
1316 * Output similar properties
1317 *
1318 * @param array $atts
1319 * @return string
1320 */
1321 public static function similar_properties( $atts ) {
1322
1323 global $property, $propertyhive_loop;
1324
1325 $atts = shortcode_atts( array(
1326 'per_page' => '2',
1327 'columns' => '2',
1328 'orderby' => 'rand',
1329 'order' => 'asc',
1330 'price_percentage_bounds' => 10,
1331 'bedroom_bounds' => 0,
1332 'matching_address_field' => '', // only return fields with matching address field. Options: address_two, address_three, address_four, location
1333 'property_id' => '',
1334 'availability_id' => '',
1335 'property_type_id' => '',
1336 'match_property_type' => '',
1337 'exclude' => '',
1338 'no_results_output' => '',
1339 'carousel' => '',
1340 ), $atts, 'similar_properties' );
1341
1342 if ( isset($atts['carousel']) && !empty($atts['carousel']) )
1343 {
1344 $params = array(
1345 'items' => 1,
1346 'controlsPosition' => 'bottom',
1347 'gutter' => 20,
1348 'mouseDrag' => true,
1349 'nav' => false,
1350 'navPosition' => 'bottom',
1351 'controlsText' => array("Prev", "Next"),
1352 'responsive' => array(
1353 640 => array(
1354 'items' => (int)$atts['columns']
1355 )
1356 )
1357 );
1358 $params = apply_filters( 'propertyhive_carousel_params', $params );
1359 $params = apply_filters( 'propertyhive_similar_properties_carousel_params', $params );
1360 wp_localize_script( 'propertyhive_carousel', 'propertyhive_carousel_params', $params );
1361
1362 wp_enqueue_style( 'tiny_slider_css' );
1363 wp_enqueue_script( 'tiny_slider' );
1364 wp_enqueue_script( 'propertyhive_carousel' );
1365 }
1366
1367 if ( $atts['property_id'] == '' && isset($property->id) )
1368 {
1369 $atts['property_id'] = $property->id;
1370 }
1371
1372 if ($atts['property_id'] != '')
1373 {
1374 $department = get_post_meta( $atts['property_id'], '_department', true );
1375
1376 $args = array(
1377 'post_type' => 'property',
1378 'post__not_in' => array($atts['property_id']),
1379 'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ),
1380 'ignore_sticky_posts' => 1,
1381 'posts_per_page' => $atts['per_page'],
1382 'orderby' => $atts['orderby'],
1383 'order' => $atts['order'],
1384 'has_password' => false,
1385 );
1386
1387 $meta_query = array();
1388
1389 $meta_query[] = array(
1390 'key' => '_department',
1391 'value' => $department,
1392 );
1393
1394 $meta_query[] = array(
1395 'key' => '_on_market',
1396 'value' => 'yes',
1397 );
1398
1399 if ( $department != 'commercial' && ph_get_custom_department_based_on( $department ) != 'commercial' )
1400 {
1401 // residential
1402 $bedrooms = get_post_meta( $atts['property_id'], '_bedrooms', true );
1403 $lower_bedrooms = $bedrooms;
1404 $higher_bedrooms = $bedrooms;
1405 if ( !empty($bedrooms) && isset($atts['bedroom_bounds']) && $atts['bedroom_bounds'] != '' && is_numeric($atts['bedroom_bounds']) && $atts['bedroom_bounds'] > 0 )
1406 {
1407 $lower_bedrooms = $bedrooms - (int)$atts['bedroom_bounds'];
1408 $higher_bedrooms = $bedrooms + (int)$atts['bedroom_bounds'];
1409 }
1410
1411 if ( isset($atts['bedroom_bounds']) && is_numeric($atts['bedroom_bounds']) )
1412 {
1413 $meta_query[] = array(
1414 'key' => '_bedrooms',
1415 'value' => array( $lower_bedrooms, $higher_bedrooms ),
1416 'compare' => 'BETWEEN',
1417 'type' => 'NUMERIC'
1418 );
1419 }
1420
1421 $price = get_post_meta( $atts['property_id'], '_price_actual', true );
1422 $lower_price = $price;
1423 $higher_price = $price;
1424 $atts['price_percentage_bounds'] = str_replace("%", "", $atts['price_percentage_bounds']);
1425 if ( !empty($price) && isset($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] != '' && is_numeric($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] > 0 )
1426 {
1427 $lower_price = $price - ($price * (int)$atts['price_percentage_bounds'] / 100);
1428 $higher_price = $price + ($price * (int)$atts['price_percentage_bounds'] / 100);
1429 }
1430
1431 if ( isset($atts['price_percentage_bounds']) && is_numeric($atts['price_percentage_bounds']) )
1432 {
1433 $meta_query[] = array(
1434 'key' => '_price_actual',
1435 'value' => array( $lower_price, $higher_price ),
1436 'compare' => 'BETWEEN',
1437 'type' => 'NUMERIC'
1438 );
1439 }
1440 }
1441 else
1442 {
1443 // commercial
1444 $for_sale = get_post_meta( $atts['property_id'], '_for_sale', true );
1445 $to_rent = get_post_meta( $atts['property_id'], '_to_rent', true );
1446
1447 if ( $for_sale == 'yes' || $to_rent == 'yes' )
1448 {
1449 $sub_meta_query = array('relation' => 'OR');
1450
1451 if ( $for_sale == 'yes' )
1452 {
1453 $prices_sub_query = array('relation' => 'OR');
1454
1455 $price_from = get_post_meta( $atts['property_id'], '_price_from_actual', true );
1456 $price_to = get_post_meta( $atts['property_id'], '_price_to_actual', true );
1457
1458 if ( !empty($price_from) || !empty($price_to) )
1459 {
1460 if ( empty($price_from) )
1461 {
1462 $price_from = $price_to;
1463 }
1464 if ( empty($price_to) )
1465 {
1466 $price_to = $price_from;
1467 }
1468
1469 $lower_price_from = $price_from;
1470 $higher_price_from = $price_from;
1471 if ( isset($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] != '' && is_numeric($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] > 0 )
1472 {
1473 $lower_price_from = $price_from - ($price_from * (int)$atts['price_percentage_bounds'] / 100);
1474 $higher_price_from = $price_from + ($price_from * (int)$atts['price_percentage_bounds'] / 100);
1475 }
1476
1477 $lower_price_to = $price_to;
1478 $higher_price_to = $price_to;
1479 if ( isset($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] != '' && is_numeric($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] > 0 )
1480 {
1481 $lower_price_to = $price_to - ($price_to * (int)$atts['price_percentage_bounds'] / 100);
1482 $higher_price_to = $price_to + ($price_to * (int)$atts['price_percentage_bounds'] / 100);
1483 }
1484
1485 // where price from and price to not blank and price from -15%
1486 $price_sub_query = array();
1487
1488 $price_sub_query[] = array(
1489 'key' => '_price_from_actual',
1490 'value' => array( '', 0 ),
1491 'compare' => 'NOT IN'
1492 );
1493 $price_sub_query[] = array(
1494 'key' => '_price_to_actual',
1495 'value' => array( '', 0 ),
1496 'compare' => 'NOT IN'
1497 );
1498 $price_sub_query[] = array(
1499 'key' => '_price_to_actual',
1500 'value' => $lower_price_from,
1501 'compare' => '>=',
1502 'type' => 'NUMERIC'
1503 );
1504 $price_sub_query[] = array(
1505 'key' => '_price_from_actual',
1506 'value' => $higher_price_to,
1507 'compare' => '<=',
1508 'type' => 'NUMERIC'
1509 );
1510
1511 $prices_sub_query[] = $price_sub_query;
1512 }
1513
1514 $sub_meta_query[] = array(
1515 array(
1516 'key' => '_for_sale',
1517 'value' => $for_sale,
1518 ),
1519 $prices_sub_query
1520 );
1521 }
1522 elseif ( $to_rent == 'yes' )
1523 {
1524 $prices_sub_query = array('relation' => 'OR');
1525
1526 $price_from = get_post_meta( $atts['property_id'], '_rent_from_actual', true );
1527 $price_to = get_post_meta( $atts['property_id'], '_rent_to_actual', true );
1528
1529 if ( !empty($price_from) || !empty($price_to) )
1530 {
1531 if ( empty($price_from) )
1532 {
1533 $price_from = $price_to;
1534 }
1535 if ( empty($price_to) )
1536 {
1537 $price_to = $price_from;
1538 }
1539
1540 $lower_price_from = $price_from;
1541 $higher_price_from = $price_from;
1542 if ( isset($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] != '' && is_numeric($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] > 0 )
1543 {
1544 $lower_price_from = $price_from - ($price_from * (int)$atts['price_percentage_bounds'] / 100);
1545 $higher_price_from = $price_from + ($price_from * (int)$atts['price_percentage_bounds'] / 100);
1546 }
1547
1548 $lower_price_to = $price_to;
1549 $higher_price_to = $price_to;
1550 if ( isset($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] != '' && is_numeric($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] > 0 )
1551 {
1552 $lower_price_to = $price_to - ($price_to * (int)$atts['price_percentage_bounds'] / 100);
1553 $higher_price_to = $price_to + ($price_to * (int)$atts['price_percentage_bounds'] / 100);
1554 }
1555
1556 // where price from and price to not blank and price from -15%
1557 $price_sub_query = array();
1558
1559 $price_sub_query[] = array(
1560 'key' => '_rent_from_actual',
1561 'value' => array( '', 0 ),
1562 'compare' => 'NOT IN'
1563 );
1564 $price_sub_query[] = array(
1565 'key' => '_rent_to_actual',
1566 'value' => array( '', 0 ),
1567 'compare' => 'NOT IN'
1568 );
1569 $price_sub_query[] = array(
1570 'key' => '_rent_to_actual',
1571 'value' => $lower_price_from,
1572 'compare' => '>=',
1573 'type' => 'NUMERIC'
1574 );
1575 $price_sub_query[] = array(
1576 'key' => '_rent_from_actual',
1577 'value' => $higher_price_to,
1578 'compare' => '<=',
1579 'type' => 'NUMERIC'
1580 );
1581
1582 $prices_sub_query[] = $price_sub_query;
1583 }
1584
1585 $sub_meta_query[] = array(
1586 array(
1587 'key' => '_to_rent',
1588 'value' => $to_rent,
1589 ),
1590 $prices_sub_query
1591 );
1592 }
1593
1594 $meta_query[] = $sub_meta_query;
1595 }
1596 }
1597
1598 if ( isset($atts['matching_address_field']) && in_array($atts['matching_address_field'], array( 'address_two', 'address_three', 'address_four' )) )
1599 {
1600 $address_field = get_post_meta( $atts['property_id'], '_' . $atts['matching_address_field'], true );
1601
1602 $meta_query[] = array(
1603 'key' => '_' . $atts['matching_address_field'],
1604 'value' => $address_field,
1605 );
1606 }
1607
1608 $args['meta_query'] = $meta_query;
1609
1610 $tax_query = array();
1611
1612 if ( isset($atts['availability_id']) && $atts['availability_id'] != '' )
1613 {
1614 $tax_query[] = array(
1615 'taxonomy' => 'availability',
1616 'terms' => explode(",", $atts['availability_id']),
1617 'compare' => 'IN',
1618 );
1619 }
1620
1621 $property_types = array();
1622 if ( isset($atts['property_type_id']) && $atts['property_type_id'] != '' )
1623 {
1624 $property_types = explode(",", $atts['property_type_id']);
1625 }
1626
1627 if ( isset($atts['match_property_type']) && $atts['match_property_type'] != '' )
1628 {
1629 $term_list = wp_get_post_terms((int)$atts['property_id'], ( ( $department == 'commercial' || ph_get_custom_department_based_on( $department ) == 'commercial' ) ? 'commercial_' : '' ) . 'property_type', array("fields" => "ids"));
1630
1631 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
1632 {
1633 $property_types = $term_list;
1634 }
1635 }
1636
1637 if ( !empty($property_types) )
1638 {
1639 $property_types = array_unique($property_types);
1640 $property_types = array_filter($property_types);
1641
1642 if ( $department != 'commercial' && ph_get_custom_department_based_on( $department ) != 'commercial' )
1643 {
1644 $tax_query[] = array(
1645 'taxonomy' => 'property_type',
1646 'terms' => $property_types,
1647 'compare' => 'IN',
1648 );
1649 }
1650 else
1651 {
1652 $tax_query[] = array(
1653 'taxonomy' => 'commercial_property_type',
1654 'terms' => $property_types,
1655 'compare' => 'IN',
1656 );
1657 }
1658 }
1659
1660 if ( isset($atts['matching_address_field']) && $atts['matching_address_field'] == 'location' )
1661 {
1662 $term_list = wp_get_post_terms($atts['property_id'], 'location', array("fields" => "ids"));
1663
1664 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
1665 {
1666 $tax_query[] = array(
1667 'taxonomy' => 'location',
1668 'terms' => $term_list,
1669 'compare' => 'IN',
1670 );
1671 }
1672 }
1673
1674 if ( ! empty( $tax_query ) ) {
1675 $args['tax_query'] = $tax_query;
1676 }
1677
1678 if ( isset($atts['orderby']) && $atts['orderby'] == 'date' )
1679 {
1680 $args['orderby'] = 'meta_value';
1681 $args['meta_key'] = '_on_market_change_date';
1682 }
1683
1684 $args['orderby'] .= ' post_title';
1685
1686 if ( ! empty( $atts['exclude'] ) )
1687 {
1688 $exclude_ids = array_map( 'absint', explode( ',', $atts['exclude'] ) );
1689 $exclude_ids = array_filter( $exclude_ids );
1690 if ( ! empty( $exclude_ids ) ) {
1691 $args['post__not_in'] = $exclude_ids;
1692 }
1693 }
1694
1695 ob_start();
1696
1697 $properties = new WP_Query( apply_filters( 'propertyhive_shortcode_similar_properties_query', $args, $atts ) );
1698
1699 $propertyhive_loop['columns'] = (int)$atts['columns'];
1700
1701 if ( $properties->have_posts() ) : ?>
1702
1703 <?php
1704 ob_start();
1705 propertyhive_property_loop_start();
1706 $loop_start = ob_get_clean();
1707 if ( isset($atts['carousel']) && !empty($atts['carousel']) )
1708 {
1709 $loop_start = str_replace("class=\"properties", "class=\"properties propertyhive-shortcode-carousel", $loop_start);
1710 }
1711 echo $loop_start;
1712 ?>
1713
1714 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
1715
1716 <?php ph_get_template_part( 'content', 'property-featured' ); ?>
1717
1718 <?php endwhile; // end of the loop. ?>
1719
1720 <?php propertyhive_property_loop_end(); ?>
1721
1722 <?php else: ?>
1723
1724 <p class="propertyhive-info no-results-message"><?php echo wp_kses_post($atts['no_results_output']); ?></p>
1725
1726 <?php endif;
1727
1728 wp_reset_postdata();
1729 }
1730 else
1731 {
1732 echo 'No property_id passed into similar_properties shortcode';
1733 }
1734
1735 $shortcode_output = ob_get_clean();
1736
1737 return apply_filters( 'propertyhive_similar_properties_shortcode_output', '<div class="propertyhive propertyhive-similar-properties-shortcode columns-' . (int)$atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
1738 }
1739
1740 /**
1741 * Output property map
1742 * Should only be used on a property page or where the $property var is set
1743 *
1744 * @param array $atts
1745 * @return string
1746 */
1747 public static function property_map( $atts ) {
1748
1749 global $property;
1750
1751 $atts = shortcode_atts( array(
1752 'id' => '',
1753 'height' => '400',
1754 'zoom' => '14',
1755 'scrollwheel' => 'true',
1756 'init_on_load' => 'true',
1757 'embed' => 'false'
1758 ), $atts, 'property_map' );
1759
1760 ob_start();
1761
1762 echo get_property_map( $atts );
1763
1764 return ob_get_clean();
1765 }
1766
1767 /**
1768 * Output static (image) property map
1769 * Should only be used on a property page or where the $property var is set
1770 *
1771 * @param array $atts
1772 * @return string
1773 */
1774 public static function property_static_map( $atts ) {
1775
1776 global $property;
1777
1778 $atts = shortcode_atts( array(
1779 'id' => '',
1780 'height' => '400',
1781 'zoom' => '14',
1782 'link' => 'true',
1783 ), $atts, 'property_static_map' );
1784
1785 ob_start();
1786
1787 echo get_property_static_map( $atts );
1788
1789 return ob_get_clean();
1790 }
1791
1792 /**
1793 * Output property street view
1794 * Should only be used on a property page or where the $property var is set
1795 *
1796 * @param array $atts
1797 * @return string
1798 */
1799 public static function property_street_view( $atts ) {
1800
1801 global $property;
1802
1803 $atts = shortcode_atts( array(
1804 'height' => '400',
1805 'init_on_load' => 'true',
1806 'embed' => 'false'
1807 ), $atts, 'property_street_view' );
1808
1809 ob_start();
1810
1811 echo get_property_street_view( $atts );
1812
1813 return ob_get_clean();
1814 }
1815
1816 /**
1817 * Output property office details
1818 * Should only be used on a property page or where the $property var is set
1819 *
1820 * @param array $atts
1821 * @return string
1822 */
1823 public static function property_office_details( $atts ) {
1824
1825 global $property;
1826
1827 $atts = shortcode_atts( array(
1828 'address_separator' => '<br>',
1829 'hyperlink_telephone_number' => true,
1830 'hyperlink_email_address' => true,
1831 ), $atts, 'property_office_details' );
1832
1833 $atts['hyperlink_telephone_number'] = (($atts['hyperlink_telephone_number'] === 'true' || $atts['hyperlink_telephone_number'] === true) ? true : false);
1834 $atts['hyperlink_email_address'] = (($atts['hyperlink_email_address'] === 'true' || $atts['hyperlink_email_address'] === true) ? true : false);
1835
1836 ob_start();
1837
1838 if ( $property->office_id != '' )
1839 {
1840 echo '<div class="property-office-details">';
1841
1842 if ( $property->office_name != '' )
1843 {
1844 echo '<div class="office-name">' . esc_html($property->office_name) . '</div>';
1845 }
1846
1847 if ( $property->get_office_address( $atts['address_separator'] ) != '' )
1848 {
1849 echo '<div class="office-address">' . $property->get_office_address( $atts['address_separator'] ) . '</div>';
1850 }
1851
1852 if ( $property->office_telephone_number != '' )
1853 {
1854 echo '<div class="office-telephone-number">' . ( ($atts['hyperlink_telephone_number'] === true) ? '<a href="tel:' . esc_attr($property->office_telephone_number) . '">' : '' ) . esc_html($property->office_telephone_number) . ( ($atts['hyperlink_telephone_number'] === true) ? '</a>' : '' ) . '</div>';
1855 }
1856
1857 if ( $property->office_email_address != '' )
1858 {
1859 echo '<div class="office-email-address">' . ( ($atts['hyperlink_email_address'] === true) ? '<a href="mailto:' . esc_attr($property->office_email_address) . '">' : '' ) . esc_html($property->office_email_address) . ( ($atts['hyperlink_email_address'] === true) ? '</a>' : '' ) . '</div>';
1860 }
1861
1862 echo '</div>';
1863 }
1864
1865 return ob_get_clean();
1866 }
1867
1868 /**
1869 * Output office map
1870 *
1871 * @param array $atts
1872 * @return string
1873 */
1874 public static function office_map( $atts ) {
1875
1876 $offices_with_lat_lng = 0;
1877 if ( !isset($atts['office_id']) || ( isset($atts['office_id']) && $atts['office_id'] == '' ) )
1878 {
1879 $args = array(
1880 'post_type' => 'office',
1881 'nopaging' => true
1882 );
1883
1884 $office_query = new WP_Query( $args );
1885
1886 if ( $office_query->have_posts() )
1887 {
1888 while ( $office_query->have_posts() )
1889 {
1890 $office_query->the_post();
1891
1892 $lat = get_post_meta(get_the_ID(), '_office_latitude', TRUE);
1893 $lng = get_post_meta(get_the_ID(), '_office_longitude', TRUE);
1894
1895 if ( $lat != '' && $lng != '' )
1896 {
1897 ++$offices_with_lat_lng;
1898 }
1899 }
1900 }
1901 wp_reset_postdata();
1902 }
1903
1904 $atts = shortcode_atts( array(
1905 'office_id' => '', // if wanting to show map for a particular office
1906 'height' => '400',
1907 'zoom' => ( ( ( !isset($atts['office_id']) || ( isset($atts['office_id']) && $atts['office_id'] == '' ) ) && !isset($atts['zoom']) && $offices_with_lat_lng > 1 ) ? 'auto' : '14' ),
1908 'scrollwheel' => 'true'
1909 ), $atts, 'office_map' );
1910
1911 ob_start();
1912
1913 $api_key = get_option('propertyhive_google_maps_api_key', '');
1914 wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3');
1915 wp_enqueue_script('googlemaps');
1916
1917 echo '<div id="office_map_canvas" style="height:' . str_replace( "px", "", ( ( isset($atts['height']) && !empty($atts['height']) && is_numeric($atts['height']) ) ? (int)$atts['height'] : '400' ) ) . 'px"></div>';
1918 ?>
1919 <script>
1920
1921 // We declare vars globally so developers can access them
1922 var office_map; // Global declaration of the map
1923 var office_marker;
1924 var ph_office_map_lat_lngs = new Array();
1925
1926 function initialize_office_map() {
1927
1928 <?php
1929 $args = array(
1930 'post_type' => 'office',
1931 'posts_per_page' => 1
1932 );
1933
1934 if ( isset($atts['office_id']) && (int)$atts['office_id'] != 0 )
1935 {
1936 $args['p'] = (int)$atts['office_id'];
1937 }
1938 else
1939 {
1940 $args['meta_query'] = array(
1941 array(
1942 'key' => 'primary',
1943 'value' => '1'
1944 )
1945 );
1946 }
1947
1948 $office_query = new WP_Query( $args );
1949
1950 $lat = '';
1951 $lng = '';
1952
1953 if ( $office_query->have_posts() )
1954 {
1955 while ( $office_query->have_posts() )
1956 {
1957 $office_query->the_post();
1958
1959 $lat = get_post_meta(get_the_ID(), '_office_latitude', TRUE);
1960 $lng = get_post_meta(get_the_ID(), '_office_longitude', TRUE);
1961 }
1962 }
1963 if ( $lat == '' || $lng == '' )
1964 {
1965 $lat = '51.509865';
1966 $lng = '-0.118092';
1967 }
1968 ?>
1969 var myLatlng = new google.maps.LatLng(<?php echo (float)$lat; ?>, <?php echo (float)$lng; ?>);
1970 var map_options = {
1971 zoom: <?php echo ( ( isset($atts['zoom']) && !empty($atts['zoom']) && is_numeric($atts['zoom']) && $atts['zoom'] != 'auto' ) ? (int)$atts['zoom'] : '14' ); ?>,
1972 center: myLatlng,
1973 mapTypeId: google.maps.MapTypeId.ROADMAP,
1974 scrollwheel: <?php echo ( ( isset($atts['scrollwheel']) && ($atts['scrollwheel'] === 'false' || $atts['scrollwheel'] === FALSE) ) ? 'false' : 'true' ); ?>
1975 }
1976 <?php
1977 if ( class_exists( 'PH_Map_Search' ) )
1978 {
1979 $map_add_on_settings = get_option( 'propertyhive_map_search', array() );
1980
1981 if ( isset($map_add_on_settings['style_js']) && trim($map_add_on_settings['style_js']) != '' )
1982 {
1983 echo 'map_options.styles = ' . trim($map_add_on_settings['style_js']) . ';';
1984 }
1985 }
1986
1987 do_action( 'propertyhive_office_map_options' );
1988 ?>
1989 office_map = new google.maps.Map(document.getElementById("office_map_canvas"), map_options);
1990
1991 <?php
1992 $args = array(
1993 'post_type' => 'office',
1994 'nopaging' => true
1995 );
1996
1997 if ( isset($atts['office_id']) && (int)$atts['office_id'] != 0 )
1998 {
1999 $args['p'] = (int)$atts['office_id'];
2000 }
2001
2002 $office_query = new WP_Query( $args );
2003
2004 if ( $office_query->have_posts() )
2005 {
2006 while ( $office_query->have_posts() )
2007 {
2008 $office_query->the_post();
2009
2010 $lat = get_post_meta(get_the_ID(), '_office_latitude', TRUE);
2011 $lng = get_post_meta(get_the_ID(), '_office_longitude', TRUE);
2012
2013 if ( $lat != '' && $lng != '' )
2014 {
2015 ?>
2016 var myLatlng = new google.maps.LatLng(<?php echo (float)$lat; ?>, <?php echo (float)$lng; ?>);
2017
2018 var marker_options = {
2019 map: office_map,
2020 position: myLatlng,
2021 title: "<?php echo esc_attr(get_the_title()); ?>"
2022 };
2023
2024 <?php
2025 if ( class_exists( 'PH_Map_Search' ) )
2026 {
2027 $map_add_on_settings = get_option( 'propertyhive_map_search', array() );
2028
2029 if ( isset($map_add_on_settings['icon_type']) && $map_add_on_settings['icon_type'] == 'custom_single' && isset($map_add_on_settings['custom_icon_attachment_id']) && $map_add_on_settings['custom_icon_attachment_id'] != '' )
2030 {
2031 $marker_icon_url = wp_get_attachment_url( $map_add_on_settings['custom_icon_attachment_id'] );
2032 if ( $marker_icon_url !== FALSE )
2033 {
2034 echo 'marker_options.icon = \'' . esc_url($marker_icon_url) . '\';';
2035 }
2036 }
2037 }
2038 ?>
2039
2040 <?php do_action( 'propertyhive_office_map_marker_options' ); ?>
2041
2042 office_marker = new google.maps.Marker(marker_options);
2043 ph_office_map_lat_lngs.push(office_marker.getPosition());
2044 <?php
2045 }
2046 }
2047 }
2048 wp_reset_postdata();
2049
2050 if ( $atts['zoom'] == 'auto' ) { echo 'ph_fit_office_map_to_bounds();'; }
2051 ?>
2052 }
2053
2054 function ph_fit_office_map_to_bounds()
2055 {
2056 var bounds = new google.maps.LatLngBounds();
2057 if ( ph_office_map_lat_lngs.length > 0 )
2058 {
2059 for ( var i = 0; i < ph_office_map_lat_lngs.length; i++ )
2060 {
2061 bounds.extend(ph_office_map_lat_lngs[i]);
2062 }
2063 office_map.fitBounds(bounds);
2064 }
2065 }
2066
2067 if(window.addEventListener) {
2068 window.addEventListener('load', initialize_office_map);
2069 }else{
2070 window.attachEvent('onload', initialize_office_map);
2071 }
2072
2073 </script>
2074 <?php
2075 return ob_get_clean();
2076 }
2077
2078 /**
2079 * Output applicant registration form
2080 *
2081 * @param array $atts
2082 * @return string
2083 */
2084 public static function applicant_registration_form( $atts ) {
2085
2086 $atts = shortcode_atts( array(
2087
2088 ), $atts, 'applicant_registration_form' );
2089
2090 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
2091 wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true );
2092
2093 ob_start();
2094
2095 if ( is_user_logged_in() )
2096 {
2097 ph_get_template( 'account/already-logged-in.php' );
2098 return ob_get_clean();
2099 }
2100
2101 $form_controls = ph_get_user_details_form_fields();
2102
2103 $form_controls = apply_filters( 'propertyhive_user_details_form_fields', $form_controls );
2104
2105 $form_controls_2 = ph_get_applicant_requirements_form_fields();
2106
2107 $form_controls_2 = apply_filters( 'propertyhive_applicant_requirements_form_fields', $form_controls_2, false );
2108
2109 $form_controls = array_merge( $form_controls, $form_controls_2 );
2110
2111 if ( get_option( 'propertyhive_applicant_registration_form_disclaimer', '' ) != '' )
2112 {
2113 $disclaimer = get_option( 'propertyhive_applicant_registration_form_disclaimer', '' );
2114
2115 $form_controls['disclaimer'] = array(
2116 'type' => 'checkbox',
2117 'label' => $disclaimer,
2118 'label_style' => 'width:100%;',
2119 'required' => true
2120 );
2121 }
2122
2123 $form_controls = apply_filters( 'propertyhive_applicant_registration_form_fields', $form_controls );
2124
2125 ph_get_template( 'account/applicant-registration-form.php', array( 'form_controls' => $form_controls ) );
2126
2127 return ob_get_clean();
2128 }
2129
2130 /**
2131 * Output 'Login' page
2132 *
2133 * @param array $atts
2134 * @return string
2135 */
2136 public static function login_form( $atts )
2137 {
2138 $atts = shortcode_atts( array(
2139
2140 ), $atts, 'login_form' );
2141
2142 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
2143 wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true );
2144
2145 ob_start();
2146
2147 if ( is_user_logged_in() )
2148 {
2149 ph_get_template( 'account/already-logged-in.php' );
2150 return ob_get_clean();
2151 }
2152
2153 // Check 'propertyhive_applicant_users' setting is enabled
2154 if ( get_option( 'propertyhive_applicant_users', '' ) != 'yes' )
2155 {
2156 ph_get_template( 'account/invalid-access.php' );
2157 return ob_get_clean();
2158 }
2159
2160 ph_get_template( 'account/login-form.php' );
2161
2162 return ob_get_clean();
2163
2164 }
2165
2166 /**
2167 * Output 'Reset Password' page
2168 *
2169 * @param array $atts
2170 * @return string
2171 */
2172 public static function reset_password_form( $atts )
2173 {
2174 $atts = shortcode_atts( array(
2175
2176 ), $atts, 'reset_password_form' );
2177
2178 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
2179 wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true );
2180
2181 ob_start();
2182
2183 if ( is_user_logged_in() )
2184 {
2185 ph_get_template( 'account/already-logged-in.php' );
2186 return ob_get_clean();
2187 }
2188
2189 // Check 'propertyhive_applicant_users' setting is enabled
2190 if ( get_option( 'propertyhive_applicant_users', '' ) != 'yes' )
2191 {
2192 ph_get_template( 'account/invalid-access.php' );
2193 return ob_get_clean();
2194 }
2195
2196 // check key provided is valid
2197 if ( !isset($_GET['key']) || empty(ph_clean($_GET['key'])) || !isset($_GET['id']) || empty(absint($_GET['id'])) )
2198 {
2199 echo esc_html(__( 'Invalid key or id provided. Please try again', 'propertyhive' ));
2200 return ob_get_clean();
2201 }
2202
2203 $key = ph_clean($_GET['key']);
2204 $user_id = absint($_GET['id']);
2205
2206 $userdata = get_userdata( $user_id );
2207 $user_login = $userdata ? $userdata->user_login : '';
2208
2209 $user = check_password_reset_key( $key, $user_login );
2210
2211 if ( is_wp_error( $user ) )
2212 {
2213 echo esc_html(__( 'This key is invalid or has already been used. Please reset your password again if needed.', 'propertyhive' ));
2214 return ob_get_clean();
2215 }
2216
2217 ph_get_template( 'account/reset-password-form.php', array( 'reset_key' => $key, 'reset_login' => $user_login ) );
2218
2219 return ob_get_clean();
2220
2221 }
2222
2223 /**
2224 * Output 'My Account' page
2225 *
2226 * @param array $atts
2227 * @return string
2228 */
2229 public static function my_account( $atts )
2230 {
2231 $atts = shortcode_atts( array(
2232
2233 ), $atts, 'my_account' );
2234
2235 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
2236 wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true );
2237
2238 ob_start();
2239
2240 // Check user is logged in
2241 if ( !is_user_logged_in() )
2242 {
2243 ph_get_template( 'account/invalid-access.php' );
2244 return ob_get_clean();
2245 }
2246
2247 // Check 'propertyhive_applicant_users' setting is enabled
2248 if ( get_option( 'propertyhive_applicant_users', '' ) != 'yes' )
2249 {
2250 ph_get_template( 'account/invalid-access.php' );
2251 return ob_get_clean();
2252 }
2253
2254 ph_get_template( 'account/my-account.php' );
2255
2256 return ob_get_clean();
2257
2258 }
2259
2260 private static function get_show_order_args( $atts, $args )
2261 {
2262 $orderby = '';
2263
2264 if ( isset( $_GET['orderby'] ) && $_GET['orderby'] != '' )
2265 {
2266 $PH_Query = new PH_Query();
2267 $ordering_args = $PH_Query->get_search_results_ordering_args();
2268
2269 $args['orderby'] = $ordering_args['orderby'];
2270 $args['order'] = $ordering_args['order'];
2271
2272 if ( isset( $ordering_args['meta_key'] ) )
2273 {
2274 $args['meta_key'] = $ordering_args['meta_key'];
2275 }
2276 else
2277 {
2278 unset($args['meta_key']);
2279 }
2280 }
2281 else
2282 {
2283 switch ( $atts['orderby'] )
2284 {
2285 case 'date':
2286 $orderby = 'date';
2287 break;
2288 case 'meta_value_num':
2289
2290 switch ( $atts['meta_key'] )
2291 {
2292 case '_price_actual':
2293 $orderby = 'price';
2294 break;
2295 case '_floor_area_from_sqft':
2296 $orderby = 'floor_area';
2297 break;
2298 }
2299
2300 if ( $orderby != '' && !empty($atts['order']) )
2301 {
2302 $orderby .= '-' . $atts['order'];
2303 }
2304 break;
2305 }
2306 }
2307
2308 return array( $args, $orderby );
2309 }
2310 }
2311