PluginProbe
Property Hive / 1.4.53
Property Hive v1.4.53
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 1.4.62 All 260 releases
propertyhive / includes / class-ph-shortcodes.php

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

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