PluginProbe
Property Hive / 1.4.57
Property Hive v1.4.57
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / class-ph-shortcodes.php

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

1,250 lines 35.3 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_street_view' => __CLASS__ . '::property_street_view',
29 'property_office_details' => __CLASS__ . '::property_office_details',
30 'office_map' => __CLASS__ . '::office_map',
31 'applicant_registration_form' => __CLASS__ . '::applicant_registration_form',
32 'propertyhive_my_account' => __CLASS__ . '::my_account',
33 'propertyhive_login_form' => __CLASS__ . '::login_form',
34 );
35
36 foreach ( $shortcodes as $shortcode => $function ) {
37 add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function );
38 }
39 }
40
41 /**
42 * Shortcode Wrapper
43 *
44 * @param mixed $function
45 * @param array $atts (default: array())
46 * @return string
47 */
48 public static function shortcode_wrapper(
49 $function,
50 $atts = array(),
51 $wrapper = array(
52 'class' => 'propertyhive',
53 'before' => null,
54 'after' => null
55 )
56 ) {
57 ob_start();
58
59 $before = empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before'];
60 $after = empty( $wrapper['after'] ) ? '</div>' : $wrapper['after'];
61
62 echo $before;
63 call_user_func( $function, $atts );
64 echo $after;
65
66 return ob_get_clean();
67 }
68
69 /**
70 * Output property search form
71 *
72 * @param array $atts
73 * @return string
74 */
75 public static function property_search_form( $atts ) {
76 $atts = shortcode_atts( array(
77 'id' => 'shortcode',
78 'default_department' => ''
79 ), $atts, 'property_search_form' );
80
81 $form_controls = ph_get_search_form_fields();
82
83 $form_controls = apply_filters( 'propertyhive_search_form_fields_' . $atts['id'], $form_controls, $atts );
84 $form_controls = apply_filters( 'propertyhive_search_form_fields', $form_controls, $atts );
85
86 // We 100% need department so make sure it exists. If it doesn't, set a hidden field
87 if ( !isset($form_controls['department']) )
88 {
89 $original_form_controls = ph_get_search_form_fields();
90 $original_department = $original_form_controls['department'];
91 $original_department['type'] = 'hidden';
92
93 $form_controls['department'] = $original_department;
94 }
95
96 $form_controls = apply_filters( 'propertyhive_search_form_fields_after_' . $atts['id'], $form_controls, $atts );
97 $form_controls = apply_filters( 'propertyhive_search_form_fields_after', $form_controls, $atts );
98
99 if (
100 isset($atts['default_department']) && in_array($atts['default_department'], array('residential-sales', 'residential-lettings', 'commercial')) &&
101 ( !isset($_REQUEST['department']) )
102 )
103 {
104 $form_controls['department']['value'] = $atts['default_department'];
105 }
106
107 ob_start();
108
109 ph_get_template( 'global/search-form.php', array( 'form_controls' => $form_controls, 'id' => $atts['id'] ) );
110
111 return ob_get_clean();
112 }
113
114 /**
115 * List multiple properties shortcode
116 *
117 * @param array $atts
118 * @return string
119 */
120 public static function properties( $atts ) {
121 $atts = shortcode_atts( array(
122 'columns' => '2',
123 'orderby' => 'meta_value_num',
124 'order' => 'desc',
125 'meta_key' => '_price_actual',
126 'ids' => '',
127 'department' => '', // residential-sales / residential-lettings / commercial
128 'minimum_price' => '',
129 'maximum_price' => '',
130 'bedrooms' => '',
131 'address_keyword' => '',
132 'availability_id' => '',
133 'marketing_flag' => '', // Deprecated. Use marketing_flag_id instead
134 'marketing_flag_id' => '', // Should be marketing_flag_id. Might deprecate this in the future
135 'property_type_id' => '',
136 'location_id' => '',
137 'office_id' => '',
138 'negotiator_id' => '',
139 'commercial_for_sale' => '',
140 'commercial_to_rent' => '',
141 'posts_per_page' => 10,
142 'no_results_output' => '',
143 ), $atts, 'properties' );
144
145 $meta_query = array(
146 array(
147 'key' => '_on_market',
148 'value' => 'yes',
149 )
150 );
151
152 if ( isset($atts['department']) && in_array($atts['department'], array("residential-sales", "residential-lettings", "commercial")) )
153 {
154 $meta_query[] = array(
155 'key' => '_department',
156 'value' => $atts['department'],
157 'compare' => '='
158 );
159 }
160
161 if ( isset($atts['bedrooms']) && $atts['bedrooms'] != '' && is_numeric($atts['bedrooms']) )
162 {
163 $meta_query[] = array(
164 'key' => '_bedrooms',
165 'value' => sanitize_text_field( $atts['bedrooms'] ),
166 'compare' => '='
167 );
168 }
169
170 if ( isset($atts['department']) && $atts['department'] == 'residential-sales' && isset($atts['minimum_price']) && $atts['minimum_price'] != '' )
171 {
172 $search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' );
173
174 $minimum_price = $atts['minimum_price'];
175 if ( $search_form_currency != 'GBP' )
176 {
177 // Convert $atts['minimum_price'] to GBP
178 $ph_countries = new PH_Countries();
179
180 $minimum_price = $ph_countries->convert_price_to_gbp( $minimum_price, $search_form_currency );
181 }
182
183 $meta_query[] = array(
184 'key' => '_price_actual',
185 'value' => sanitize_text_field( floor( $minimum_price ) ),
186 'compare' => '>=',
187 'type' => 'NUMERIC'
188 );
189 }
190
191 if ( isset($atts['department']) && $atts['department'] == 'residential-sales' && isset($atts['maximum_price']) && $atts['maximum_price'] != '' )
192 {
193 $search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' );
194
195 $maximum_price = $atts['maximum_price'];
196 if ( $search_form_currency != 'GBP' )
197 {
198 // Convert $atts['maximum_price'] to GBP
199 $ph_countries = new PH_Countries();
200
201 $maximum_price = $ph_countries->convert_price_to_gbp( $maximum_price, $search_form_currency );
202 }
203
204 $meta_query[] = array(
205 'key' => '_price_actual',
206 'value' => sanitize_text_field( ceil( $maximum_price ) ),
207 'compare' => '<=',
208 'type' => 'NUMERIC'
209 );
210 }
211
212 if ( isset($atts['address_keyword']) && $atts['address_keyword'] != '' )
213 {
214 $atts['address_keyword'] = sanitize_text_field( trim( $atts['address_keyword'] ) );
215
216 $address_keywords = array( $atts['address_keyword'] );
217
218 if ( strpos( $atts['address_keyword'], ' ' ) !== FALSE )
219 {
220 $address_keywords[] = str_replace(" ", "-", $atts['address_keyword']);
221 }
222 if ( strpos( $atts['address_keyword'], '-' ) !== FALSE )
223 {
224 $address_keywords[] = str_replace("-", " ", $atts['address_keyword']);
225 }
226
227 $sub_meta_query = array('relation' => 'OR');
228
229 foreach ( $address_keywords as $address_keyword )
230 {
231 $sub_meta_query[] = array(
232 'key' => '_reference_number',
233 'value' => $address_keyword,
234 'compare' => get_option( 'propertyhive_address_keyword_compare', '=' )
235 );
236 $sub_meta_query[] = array(
237 'key' => '_address_street',
238 'value' => $address_keyword,
239 'compare' => get_option( 'propertyhive_address_keyword_compare', '=' )
240 );
241 $sub_meta_query[] = array(
242 'key' => '_address_two',
243 'value' => $address_keyword,
244 'compare' => get_option( 'propertyhive_address_keyword_compare', '=' )
245 );
246 $sub_meta_query[] = array(
247 'key' => '_address_three',
248 'value' => $address_keyword,
249 'compare' => get_option( 'propertyhive_address_keyword_compare', '=' )
250 );
251 $sub_meta_query[] = array(
252 'key' => '_address_four',
253 'value' => $address_keyword,
254 'compare' => get_option( 'propertyhive_address_keyword_compare', '=' )
255 );
256 }
257 if ( strlen($atts['address_keyword']) <= 4 )
258 {
259 $sub_meta_query[] = array(
260 'key' => '_address_postcode',
261 'value' => sanitize_text_field( $atts['address_keyword'] ),
262 'compare' => '='
263 );
264 $sub_meta_query[] = array(
265 'key' => '_address_postcode',
266 'value' => sanitize_text_field( $atts['address_keyword'] ) . '[ ]',
267 'compare' => 'RLIKE'
268 );
269 }
270 else
271 {
272 $sub_meta_query[] = array(
273 'key' => '_address_postcode',
274 'value' => sanitize_text_field( $atts['address_keyword'] ),
275 'compare' => 'LIKE'
276 );
277 }
278
279 $meta_query[] = $sub_meta_query;
280 }
281
282 if ( isset($atts['office_id']) && $atts['office_id'] != '' )
283 {
284 $meta_query[] = array(
285 'key' => '_office_id',
286 'value' => explode(",", $atts['office_id']),
287 'compare' => 'IN',
288 );
289 }
290
291 if ( isset($atts['negotiator_id']) && $atts['negotiator_id'] != '' )
292 {
293 $meta_query[] = array(
294 'key' => '_negotiator_id',
295 'value' => explode(",", $atts['negotiator_id']),
296 'compare' => 'IN',
297 );
298 }
299
300 if ( isset($atts['commercial_for_sale']) && $atts['commercial_for_sale'] != '' )
301 {
302 $meta_query[] = array(
303 'key' => '_for_sale',
304 'value' => 'yes',
305 'compare' => '=',
306 );
307 }
308
309 if ( isset($atts['commercial_to_rent']) && $atts['commercial_to_rent'] != '' )
310 {
311 $meta_query[] = array(
312 'key' => '_to_rent',
313 'value' => 'yes',
314 'compare' => '=',
315 );
316 }
317
318 $tax_query = array();
319
320 if ( isset($atts['availability_id']) && $atts['availability_id'] != '' )
321 {
322 $tax_query[] = array(
323 'taxonomy' => 'availability',
324 'terms' => explode(",", $atts['availability_id']),
325 'compare' => 'IN',
326 );
327 }
328
329 // Fallback for deprecated marketing_flag
330 if ( isset($atts['marketing_flag']) && $atts['marketing_flag'] != '' )
331 {
332 $atts['marketing_flag_id'] = $atts['marketing_flag'];
333 }
334 if ( isset($atts['marketing_flag_id']) && $atts['marketing_flag_id'] != '' )
335 {
336 $tax_query[] = array(
337 'taxonomy' => 'marketing_flag',
338 'terms' => explode(",", $atts['marketing_flag_id']),
339 'compare' => 'IN',
340 );
341 }
342
343 if ( isset($atts['property_type_id']) && $atts['property_type_id'] != '' )
344 {
345 if ( isset($atts['department']) && $atts['department'] == 'commercial' )
346 {
347 $tax_query[] = array(
348 'taxonomy' => 'commercial_property_type',
349 'terms' => explode(",", $atts['property_type_id']),
350 'compare' => 'IN',
351 );
352 }
353 else
354 {
355 $tax_query[] = array(
356 'taxonomy' => 'property_type',
357 'terms' => explode(",", $atts['property_type_id']),
358 'compare' => 'IN',
359 );
360 }
361 }
362
363 if ( isset($atts['location_id']) && $atts['location_id'] != '' )
364 {
365 $tax_query[] = array(
366 'taxonomy' => 'location',
367 'terms' => explode(",", $atts['location_id']),
368 'compare' => 'IN',
369 );
370 }
371
372 // Change default meta key when department is specified as commercial, or if commercial is the only active department
373 if (
374 ( isset($atts['department']) && $atts['department'] == 'commercial' ) ||
375 (
376 get_option( 'propertyhive_active_departments_sales' ) != 'yes' &&
377 get_option( 'propertyhive_active_departments_lettings' ) != 'yes' &&
378 get_option( 'propertyhive_active_departments_commercial' ) == 'yes'
379 )
380 )
381 {
382 $atts['meta_key'] = '_floor_area_from_sqft';
383 }
384
385 $args = array(
386 'post_type' => 'property',
387 'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ),
388 'ignore_sticky_posts' => 1,
389 'orderby' => $atts['orderby'],
390 'order' => $atts['order'],
391 'posts_per_page' => $atts['posts_per_page'],
392 'meta_query' => $meta_query,
393 'tax_query' => $tax_query
394 );
395 if ( ! empty( $atts['meta_key'] ) ) {
396 $args['meta_key'] = $atts['meta_key'];
397 }
398
399 if ( ! empty( $atts['ids'] ) ) {
400 $args['post__in'] = array_map( 'trim', explode( ',', $atts['ids'] ) );
401 }
402
403 ob_start();
404
405 $args = apply_filters( 'propertyhive_properties_query', $args, $atts );
406 $args = apply_filters( 'propertyhive_shortcode_properties_query', $args, $atts );
407
408 $properties = new WP_Query( $args );
409
410 $propertyhive_loop['columns'] = $atts['columns'];
411
412 if ( $properties->have_posts() ) : ?>
413
414 <?php propertyhive_property_loop_start(); ?>
415
416 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
417
418 <?php ph_get_template_part( 'content', 'property' ); ?>
419
420 <?php endwhile; // end of the loop. ?>
421
422 <?php propertyhive_property_loop_end(); ?>
423
424 <?php else: ?>
425
426 <?php echo $atts['no_results_output']; ?>
427
428 <?php endif;
429
430 wp_reset_postdata();
431
432 $shortcode_output = ob_get_clean();
433
434 return apply_filters( 'propertyhive_properties_shortcode_output', '<div class="propertyhive propertyhive-properties-shortcode columns-' . $atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
435 }
436
437 /**
438 * Recent Properties shortcode
439 *
440 * @access public
441 * @param array $atts
442 * @return string
443 */
444 public static function recent_properties( $atts ) {
445 global $propertyhive_loop;
446
447 $atts = shortcode_atts( array(
448 'per_page' => '12',
449 'columns' => '4',
450 'department' => '',
451 'office_id' => '',
452 'negotiator_id' => '',
453 'availability_id' => '',
454 'orderby' => 'date',
455 'order' => 'desc',
456 'no_results_output' => '',
457 ), $atts, 'recent_properties' );
458
459 $meta_query = PH()->query->get_meta_query();
460
461 if ( isset($atts['department']) && $atts['department'] != '' )
462 {
463 $meta_query[] = array(
464 'key' => '_department',
465 'value' => $atts['department'],
466 'compare' => '='
467 );
468 }
469
470 if ( isset($atts['office_id']) && $atts['office_id'] != '' )
471 {
472 $meta_query[] = array(
473 'key' => '_office_id',
474 'value' => explode(",", $atts['office_id']),
475 'compare' => 'IN'
476 );
477 }
478
479 if ( isset($atts['negotiator_id']) && $atts['negotiator_id'] != '' )
480 {
481 $meta_query[] = array(
482 'key' => '_negotiator_id',
483 'value' => explode(",", $atts['negotiator_id']),
484 'compare' => 'IN',
485 );
486 }
487
488 $tax_query = array();
489
490 if ( isset($atts['availability_id']) && $atts['availability_id'] != '' )
491 {
492 $tax_query[] = array(
493 'taxonomy' => 'availability',
494 'terms' => explode(",", $atts['availability_id']),
495 'compare' => 'IN',
496 );
497 }
498
499 $args = array(
500 'post_type' => 'property',
501 'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ),
502 'ignore_sticky_posts' => 1,
503 'posts_per_page' => $atts['per_page'],
504 'orderby' => $atts['orderby'],
505 'order' => $atts['order'],
506 'meta_query' => $meta_query,
507 'tax_query' => $tax_query,
508 );
509
510 ob_start();
511
512 $properties = new WP_Query( apply_filters( 'propertyhive_shortcode_recent_properties_query', $args, $atts ) );
513
514 $propertyhive_loop['columns'] = $atts['columns'];
515
516 if ( $properties->have_posts() ) : ?>
517
518 <?php propertyhive_property_loop_start(); ?>
519
520 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
521
522 <?php ph_get_template_part( 'content', 'property-recent' ); ?>
523
524 <?php endwhile; // end of the loop. ?>
525
526 <?php propertyhive_property_loop_end(); ?>
527
528 <?php else: ?>
529
530 <?php echo $atts['no_results_output']; ?>
531
532 <?php endif;
533
534 wp_reset_postdata();
535
536 $shortcode_output = ob_get_clean();
537
538 return apply_filters( 'propertyhive_recent_properties_shortcode_output', '<div class="propertyhive propertyhive-recent-properties-shortcode columns-' . $atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
539
540 }
541
542 /**
543 * Output featured properties
544 *
545 * @access public
546 * @param array $atts
547 * @return string
548 */
549 public static function featured_properties( $atts ) {
550 global $propertyhive_loop;
551
552 $atts = shortcode_atts( array(
553 'per_page' => '12',
554 'columns' => '4',
555 'department' => '',
556 'office_id' => '',
557 'negotiator_id' => '',
558 'availability_id' => '',
559 'orderby' => 'rand',
560 'order' => 'desc',
561 'meta_key' => '',
562 'no_results_output' => '',
563 ), $atts, 'featured_properties' );
564
565 $args = array(
566 'post_type' => 'property',
567 'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ),
568 'ignore_sticky_posts' => 1,
569 'posts_per_page' => $atts['per_page'],
570 'orderby' => $atts['orderby'],
571 'order' => $atts['order'],
572 );
573
574 $meta_query = array(
575 array(
576 'key' => '_on_market',
577 'value' => 'yes',
578 ),
579 array(
580 'key' => '_featured',
581 'value' => 'yes'
582 )
583 );
584
585 if ( isset($atts['department']) && $atts['department'] != '' )
586 {
587 $meta_query[] = array(
588 'key' => '_department',
589 'value' => $atts['department'],
590 'compare' => '='
591 );
592 }
593
594 if ( isset($atts['office_id']) && $atts['office_id'] != '' )
595 {
596 $meta_query[] = array(
597 'key' => '_office_id',
598 'value' => explode(",", $atts['office_id']),
599 'compare' => 'IN'
600 );
601 }
602
603 if ( isset($atts['negotiator_id']) && $atts['negotiator_id'] != '' )
604 {
605 $meta_query[] = array(
606 'key' => '_negotiator_id',
607 'value' => explode(",", $atts['negotiator_id']),
608 'compare' => 'IN',
609 );
610 }
611
612 $args['meta_query'] = $meta_query;
613
614 if ( ! empty( $atts['meta_key'] ) ) {
615 $args['meta_key'] = $atts['meta_key'];
616 }
617
618 $tax_query = array();
619
620 if ( isset($atts['availability_id']) && $atts['availability_id'] != '' )
621 {
622 $tax_query[] = array(
623 'taxonomy' => 'availability',
624 'terms' => explode(",", $atts['availability_id']),
625 'compare' => 'IN',
626 );
627 }
628
629 if ( ! empty( $tax_query ) ) {
630 $args['tax_query'] = $tax_query;
631 }
632
633 ob_start();
634
635 $properties = new WP_Query( apply_filters( 'propertyhive_shortcode_featured_properties_query', $args, $atts ) );
636
637 $propertyhive_loop['columns'] = $atts['columns'];
638
639 if ( $properties->have_posts() ) : ?>
640
641 <?php propertyhive_property_loop_start(); ?>
642
643 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
644
645 <?php ph_get_template_part( 'content', 'property-featured' ); ?>
646
647 <?php endwhile; // end of the loop. ?>
648
649 <?php propertyhive_property_loop_end(); ?>
650
651 <?php else: ?>
652
653 <?php echo $atts['no_results_output']; ?>
654
655 <?php endif;
656
657 wp_reset_postdata();
658
659 $shortcode_output = ob_get_clean();
660
661 return apply_filters( 'propertyhive_featured_properties_shortcode_output', '<div class="propertyhive propertyhive-featured-properties-shortcode columns-' . $atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
662 }
663
664 /**
665 * Output similar properties
666 *
667 * @param array $atts
668 * @return string
669 */
670 public static function similar_properties( $atts ) {
671
672 $atts = shortcode_atts( array(
673 'per_page' => '2',
674 'columns' => '2',
675 'orderby' => 'rand',
676 'order' => 'asc',
677 'price_percentage_bounds' => 10,
678 'bedroom_bounds' => 0,
679 'property_id' => '',
680 'availability_id' => '',
681 'no_results_output' => '',
682 ), $atts, 'similar_properties' );
683
684 if ($atts['property_id'] != '')
685 {
686 $department = get_post_meta( $atts['property_id'], '_department', true );
687
688 $price = get_post_meta( $atts['property_id'], '_price_actual', true );
689 $lower_price = $price;
690 $higher_price = $price;
691 $atts['price_percentage_bounds'] = str_replace("%", "", $atts['price_percentage_bounds']);
692 if ( isset($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] != '' && is_numeric($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] > 0 )
693 {
694 $lower_price = $price - ($price * $atts['price_percentage_bounds'] / 100);
695 $higher_price = $price + ($price * $atts['price_percentage_bounds'] / 100);
696 }
697
698 $bedrooms = get_post_meta( $atts['property_id'], '_bedrooms', true );
699 $lower_bedrooms = $bedrooms;
700 $higher_bedrooms = $bedrooms;
701 if ( isset($atts['bedroom_bounds']) && $atts['bedroom_bounds'] != '' && is_numeric($atts['bedroom_bounds']) && $atts['bedroom_bounds'] > 0 )
702 {
703 $lower_bedrooms = $bedrooms - $atts['bedroom_bounds'];
704 $higher_bedrooms = $bedrooms + $atts['bedroom_bounds'];
705 }
706
707 $args = array(
708 'post_type' => 'property',
709 'post__not_in' => array($atts['property_id']),
710 'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ),
711 'ignore_sticky_posts' => 1,
712 'posts_per_page' => $atts['per_page'],
713 'orderby' => $atts['orderby'],
714 'order' => $atts['order'],
715 );
716
717 $meta_query = array();
718
719 $meta_query[] = array(
720 'key' => '_department',
721 'value' => $department,
722 );
723
724 $meta_query[] = array(
725 'key' => '_on_market',
726 'value' => 'yes',
727 );
728
729 if ( isset($atts['bedroom_bounds']) && is_numeric($atts['bedroom_bounds']) )
730 {
731 $meta_query[] = array(
732 'key' => '_bedrooms',
733 'value' => $lower_bedrooms,
734 'compare' => '>=',
735 'type' => 'NUMERIC'
736 );
737
738 $meta_query[] = array(
739 'key' => '_bedrooms',
740 'value' => $higher_bedrooms,
741 'compare' => '<=',
742 'type' => 'NUMERIC'
743 );
744 }
745
746 if ( isset($atts['price_percentage_bounds']) && is_numeric($atts['price_percentage_bounds']) )
747 {
748 $meta_query[] = array(
749 'key' => '_price_actual',
750 'value' => $lower_price,
751 'compare' => '>=',
752 'type' => 'NUMERIC'
753 );
754
755 $meta_query[] = array(
756 'key' => '_price_actual',
757 'value' => $higher_price,
758 'compare' => '<=',
759 'type' => 'NUMERIC'
760 );
761 }
762
763 $args['meta_query'] = $meta_query;
764
765 $tax_query = array();
766
767 if ( isset($atts['availability_id']) && $atts['availability_id'] != '' )
768 {
769 $tax_query[] = array(
770 'taxonomy' => 'availability',
771 'terms' => explode(",", $atts['availability_id']),
772 'compare' => 'IN',
773 );
774 }
775
776 if ( ! empty( $tax_query ) ) {
777 $args['tax_query'] = $tax_query;
778 }
779
780 ob_start();
781
782 $properties = new WP_Query( apply_filters( 'propertyhive_shortcode_similar_properties_query', $args, $atts ) );
783
784 $propertyhive_loop['columns'] = $atts['columns'];
785
786 if ( $properties->have_posts() ) : ?>
787
788 <?php propertyhive_property_loop_start(); ?>
789
790 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
791
792 <?php ph_get_template_part( 'content', 'property-featured' ); ?>
793
794 <?php endwhile; // end of the loop. ?>
795
796 <?php propertyhive_property_loop_end(); ?>
797
798 <?php else: ?>
799
800 <?php echo $atts['no_results_output']; ?>
801
802 <?php endif;
803
804 wp_reset_postdata();
805 }
806 else
807 {
808 echo 'No property_id passed into similar_properties shortcode';
809 }
810
811 $shortcode_output = ob_get_clean();
812
813 return apply_filters( 'propertyhive_similar_properties_shortcode_output', '<div class="propertyhive propertyhive-similar-properties-shortcode columns-' . $atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
814 }
815
816 /**
817 * Output property map
818 * Should only be used on a property page or where the $property var is set
819 *
820 * @param array $atts
821 * @return string
822 */
823 public static function property_map( $atts ) {
824
825 global $property;
826
827 $atts = shortcode_atts( array(
828 'id' => '',
829 'height' => '400',
830 'zoom' => '14',
831 'scrollwheel' => 'true'
832 ), $atts, 'property_map' );
833
834 ob_start();
835
836 echo get_property_map( $atts );
837
838 return ob_get_clean();
839 }
840
841 /**
842 * Output property street view
843 * Should only be used on a property page or where the $property var is set
844 *
845 * @param array $atts
846 * @return string
847 */
848 public static function property_street_view( $atts ) {
849
850 global $property;
851
852 $atts = shortcode_atts( array(
853 'height' => '400',
854 ), $atts, 'property_street_view' );
855
856 ob_start();
857
858 echo get_property_street_view( $atts );
859
860 return ob_get_clean();
861 }
862
863 /**
864 * Output property office details
865 * Should only be used on a property page or where the $property var is set
866 *
867 * @param array $atts
868 * @return string
869 */
870 public static function property_office_details( $atts ) {
871
872 global $property;
873
874 $atts = shortcode_atts( array(
875 'address_separator' => '<br>',
876 'hyperlink_telephone_number' => true,
877 'hyperlink_email_address' => true,
878 ), $atts, 'property_office_details' );
879
880 $atts['hyperlink_telephone_number'] = (($atts['hyperlink_telephone_number'] === 'true' || $atts['hyperlink_telephone_number'] === true) ? true : false);
881 $atts['hyperlink_email_address'] = (($atts['hyperlink_email_address'] === 'true' || $atts['hyperlink_email_address'] === true) ? true : false);
882
883 ob_start();
884
885 if ( $property->office_id != '' )
886 {
887 echo '<div class="property-office-details">';
888
889 if ( $property->office_name != '' )
890 {
891 echo '<div class="office-name">' . $property->office_name . '</div>';
892 }
893
894 if ( $property->get_office_address( $atts['address_separator'] ) != '' )
895 {
896 echo '<div class="office-address">' . $property->get_office_address( $atts['address_separator'] ) . '</div>';
897 }
898
899 if ( $property->office_telephone_number != '' )
900 {
901 echo '<div class="office-telephone-number">' . ( ($atts['hyperlink_telephone_number'] === true) ? '<a href="tel:' . $property->office_telephone_number . '">' : '' ) . $property->office_telephone_number . ( ($atts['hyperlink_telephone_number'] === true) ? '</a>' : '' ) . '</div>';
902 }
903
904 if ( $property->office_email_address != '' )
905 {
906 echo '<div class="office-email-address">' . ( ($atts['hyperlink_email_address'] === true) ? '<a href="mailto:' . $property->office_email_address . '">' : '' ) . $property->office_email_address . ( ($atts['hyperlink_email_address'] === true) ? '</a>' : '' ) . '</div>';
907 }
908
909 echo '</div>';
910 }
911
912 return ob_get_clean();
913 }
914
915 /**
916 * Output office map
917 *
918 * @param array $atts
919 * @return string
920 */
921 public static function office_map( $atts ) {
922
923 $offices_with_lat_lng = 0;
924 if ( !isset($atts['office_id']) || ( isset($atts['office_id']) && $atts['office_id'] == '' ) )
925 {
926 $args = array(
927 'post_type' => 'office',
928 'nopaging' => true
929 );
930
931 $office_query = new WP_Query( $args );
932
933 if ( $office_query->have_posts() )
934 {
935 while ( $office_query->have_posts() )
936 {
937 $office_query->the_post();
938
939 $lat = get_post_meta(get_the_ID(), '_office_latitude', TRUE);
940 $lng = get_post_meta(get_the_ID(), '_office_longitude', TRUE);
941
942 if ( $lat != '' && $lng != '' )
943 {
944 ++$offices_with_lat_lng;
945 }
946 }
947 }
948 wp_reset_postdata();
949 }
950
951 $atts = shortcode_atts( array(
952 'office_id' => '', // if wanting to show map for a particular office
953 'height' => '400',
954 'zoom' => ( ( ( !isset($atts['office_id']) || ( isset($atts['office_id']) && $atts['office_id'] == '' ) ) && !isset($atts['zoom']) && $offices_with_lat_lng > 1 ) ? 'auto' : '14' ),
955 'scrollwheel' => 'true'
956 ), $atts, 'office_map' );
957
958 ob_start();
959
960 $api_key = get_option('propertyhive_google_maps_api_key', '');
961 wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3');
962 wp_enqueue_script('googlemaps');
963
964 echo '<div id="office_map_canvas" style="height:' . str_replace( "px", "", ( ( isset($atts['height']) && !empty($atts['height']) ) ? $atts['height'] : '400' ) ) . 'px"></div>';
965 ?>
966 <script>
967
968 // We declare vars globally so developers can access them
969 var office_map; // Global declaration of the map
970 var office_marker;
971 var ph_office_map_lat_lngs = new Array();
972
973 function initialize_office_map() {
974
975 <?php
976 $args = array(
977 'post_type' => 'office',
978 'posts_per_page' => 1
979 );
980
981 if ( isset($atts['office_id']) && (int)$atts['office_id'] != 0 )
982 {
983 $args['p'] = (int)$atts['office_id'];
984 }
985 else
986 {
987 $args['meta_query'] = array(
988 array(
989 'key' => 'primary',
990 'value' => '1'
991 )
992 );
993 }
994
995 $office_query = new WP_Query( $args );
996
997 $lat = '';
998 $lng = '';
999
1000 if ( $office_query->have_posts() )
1001 {
1002 while ( $office_query->have_posts() )
1003 {
1004 $office_query->the_post();
1005
1006 $lat = get_post_meta(get_the_ID(), '_office_latitude', TRUE);
1007 $lng = get_post_meta(get_the_ID(), '_office_longitude', TRUE);
1008 }
1009 }
1010 if ( $lat == '' || $lng == '' )
1011 {
1012 $lat = '51.509865';
1013 $lng = '-0.118092';
1014 }
1015 ?>
1016 var myLatlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $lng; ?>);
1017 var map_options = {
1018 zoom: <?php echo ( ( isset($atts['zoom']) && !empty($atts['zoom']) && $atts['zoom'] != 'auto' ) ? $atts['zoom'] : '14' ); ?>,
1019 center: myLatlng,
1020 mapTypeId: google.maps.MapTypeId.ROADMAP,
1021 scrollwheel: <?php echo ( ( isset($atts['scrollwheel']) && ($atts['scrollwheel'] === 'false' || $atts['scrollwheel'] === FALSE) ) ? 'false' : 'true' ); ?>
1022 }
1023 <?php
1024 if ( class_exists( 'PH_Map_Search' ) )
1025 {
1026 $map_add_on_settings = get_option( 'propertyhive_map_search', array() );
1027
1028 if ( isset($map_add_on_settings['style_js']) && trim($map_add_on_settings['style_js']) != '' )
1029 {
1030 echo 'map_options.styles = ' . trim($map_add_on_settings['style_js']) . ';';
1031 }
1032 }
1033
1034 do_action( 'propertyhive_office_map_options' );
1035 ?>
1036 office_map = new google.maps.Map(document.getElementById("office_map_canvas"), map_options);
1037
1038 <?php
1039 $args = array(
1040 'post_type' => 'office',
1041 'nopaging' => true
1042 );
1043
1044 if ( isset($atts['office_id']) && (int)$atts['office_id'] != 0 )
1045 {
1046 $args['p'] = (int)$atts['office_id'];
1047 }
1048
1049 $office_query = new WP_Query( $args );
1050
1051 if ( $office_query->have_posts() )
1052 {
1053 while ( $office_query->have_posts() )
1054 {
1055 $office_query->the_post();
1056
1057 $lat = get_post_meta(get_the_ID(), '_office_latitude', TRUE);
1058 $lng = get_post_meta(get_the_ID(), '_office_longitude', TRUE);
1059
1060 if ( $lat != '' && $lng != '' )
1061 {
1062 ?>
1063 var myLatlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $lng; ?>);
1064
1065 var marker_options = {
1066 map: office_map,
1067 position: myLatlng,
1068 title: "<?php echo esc_attr(get_the_title()); ?>"
1069 };
1070
1071 <?php
1072 if ( class_exists( 'PH_Map_Search' ) )
1073 {
1074 $map_add_on_settings = get_option( 'propertyhive_map_search', array() );
1075
1076 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'] != '' )
1077 {
1078 $marker_icon_url = wp_get_attachment_url( $map_add_on_settings['custom_icon_attachment_id'] );
1079 if ( $marker_icon_url !== FALSE )
1080 {
1081 echo 'marker_options.icon = \'' . $marker_icon_url . '\';';
1082 }
1083 }
1084 }
1085 ?>
1086
1087 <?php do_action( 'propertyhive_office_map_marker_options' ); ?>
1088
1089 office_marker = new google.maps.Marker(marker_options);
1090 ph_office_map_lat_lngs.push(office_marker.getPosition());
1091 <?php
1092 }
1093 }
1094 }
1095 wp_reset_postdata();
1096
1097 if ( $atts['zoom'] == 'auto' ) { echo 'ph_fit_office_map_to_bounds();'; }
1098 ?>
1099 }
1100
1101 function ph_fit_office_map_to_bounds()
1102 {
1103 var bounds = new google.maps.LatLngBounds();
1104 if ( ph_office_map_lat_lngs.length > 0 )
1105 {
1106 for ( var i = 0; i < ph_office_map_lat_lngs.length; i++ )
1107 {
1108 bounds.extend(ph_office_map_lat_lngs[i]);
1109 }
1110 office_map.fitBounds(bounds);
1111 }
1112 }
1113
1114 if(window.addEventListener) {
1115 window.addEventListener('load', initialize_office_map);
1116 }else{
1117 window.attachEvent('onload', initialize_office_map);
1118 }
1119
1120 </script>
1121 <?php
1122 return ob_get_clean();
1123 }
1124
1125 /**
1126 * Output applicant registration form
1127 *
1128 * @param array $atts
1129 * @return string
1130 */
1131 public static function applicant_registration_form( $atts ) {
1132
1133 $atts = shortcode_atts( array(
1134
1135 ), $atts, 'applicant_registration_form' );
1136
1137 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
1138 wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true );
1139
1140 ob_start();
1141
1142 if ( is_user_logged_in() )
1143 {
1144 ph_get_template( 'account/already-logged-in.php' );
1145 return ob_get_clean();
1146 }
1147
1148 $form_controls = ph_get_user_details_form_fields();
1149
1150 $form_controls = apply_filters( 'propertyhive_user_details_form_fields', $form_controls );
1151
1152 $form_controls_2 = ph_get_applicant_requirements_form_fields();
1153
1154 $form_controls_2 = apply_filters( 'propertyhive_applicant_requirements_form_fields', $form_controls_2 );
1155
1156 $form_controls = array_merge( $form_controls, $form_controls_2 );
1157
1158 if ( get_option( 'propertyhive_applicant_registration_form_disclaimer', '' ) != '' )
1159 {
1160 $disclaimer = get_option( 'propertyhive_applicant_registration_form_disclaimer', '' );
1161
1162 $form_controls['disclaimer'] = array(
1163 'type' => 'checkbox',
1164 'label' => $disclaimer,
1165 'label_style' => 'width:100%;',
1166 'required' => true
1167 );
1168 }
1169
1170 $form_controls = apply_filters( 'propertyhive_applicant_registration_form_fields', $form_controls );
1171
1172 ph_get_template( 'account/applicant-registration-form.php', array( 'form_controls' => $form_controls ) );
1173
1174 return ob_get_clean();
1175 }
1176
1177 /**
1178 * Output 'Login' page
1179 *
1180 * @param array $atts
1181 * @return string
1182 */
1183 public static function login_form( $atts )
1184 {
1185 $atts = shortcode_atts( array(
1186
1187 ), $atts, 'login_form' );
1188
1189 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
1190 wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true );
1191
1192 ob_start();
1193
1194 if ( is_user_logged_in() )
1195 {
1196 ph_get_template( 'account/already-logged-in.php' );
1197 return ob_get_clean();
1198 }
1199
1200 // Check 'propertyhive_applicant_users' setting is enabled
1201 if ( get_option( 'propertyhive_applicant_users', '' ) != 'yes' )
1202 {
1203 ph_get_template( 'account/invalid-access.php' );
1204 return ob_get_clean();
1205 }
1206
1207 ph_get_template( 'account/login-form.php' );
1208
1209 return ob_get_clean();
1210
1211 }
1212
1213 /**
1214 * Output 'My Account' page
1215 *
1216 * @param array $atts
1217 * @return string
1218 */
1219 public static function my_account( $atts )
1220 {
1221 $atts = shortcode_atts( array(
1222
1223 ), $atts, 'my_account' );
1224
1225 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
1226 wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true );
1227
1228 ob_start();
1229
1230 // Check user is logged in
1231 if ( !is_user_logged_in() )
1232 {
1233 ph_get_template( 'account/invalid-access.php' );
1234 return ob_get_clean();
1235 }
1236
1237 // Check 'propertyhive_applicant_users' setting is enabled
1238 if ( get_option( 'propertyhive_applicant_users', '' ) != 'yes' )
1239 {
1240 ph_get_template( 'account/invalid-access.php' );
1241 return ob_get_clean();
1242 }
1243
1244 ph_get_template( 'account/my-account.php' );
1245
1246 return ob_get_clean();
1247
1248 }
1249 }
1250