PluginProbe
Property Hive / 1.4.48
Property Hive v1.4.48
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.48, at includes/class-ph-shortcodes.php

1,224 lines 34.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_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 );
80
81 $form_controls = ph_get_search_form_fields();
82
83 $form_controls = apply_filters( 'propertyhive_search_form_fields_' . $atts['id'], $form_controls );
84 $form_controls = apply_filters( 'propertyhive_search_form_fields', $form_controls );
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 $properties = new WP_Query( apply_filters( 'propertyhive_properties_query', $args, $atts ) );
403
404 $propertyhive_loop['columns'] = $atts['columns'];
405
406 if ( $properties->have_posts() ) : ?>
407
408 <?php propertyhive_property_loop_start(); ?>
409
410 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
411
412 <?php ph_get_template_part( 'content', 'property' ); ?>
413
414 <?php endwhile; // end of the loop. ?>
415
416 <?php propertyhive_property_loop_end(); ?>
417
418 <?php else: ?>
419
420 <?php echo $atts['no_results_output']; ?>
421
422 <?php endif;
423
424 wp_reset_postdata();
425
426 $shortcode_output = ob_get_clean();
427
428 return apply_filters( 'propertyhive_properties_shortcode_output', '<div class="propertyhive propertyhive-properties-shortcode columns-' . $atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
429 }
430
431 /**
432 * Recent Properties shortcode
433 *
434 * @access public
435 * @param array $atts
436 * @return string
437 */
438 public static function recent_properties( $atts ) {
439 global $propertyhive_loop;
440
441 $atts = shortcode_atts( array(
442 'per_page' => '12',
443 'columns' => '4',
444 'department' => '',
445 'office_id' => '',
446 'availability_id' => '',
447 'orderby' => 'date',
448 'order' => 'desc',
449 'no_results_output' => '',
450 ), $atts, 'recent_properties' );
451
452 $meta_query = PH()->query->get_meta_query();
453
454 if ( isset($atts['department']) && $atts['department'] != '' )
455 {
456 $meta_query[] = array(
457 'key' => '_department',
458 'value' => $atts['department'],
459 'compare' => '='
460 );
461 }
462
463 if ( isset($atts['office_id']) && $atts['office_id'] != '' )
464 {
465 $meta_query[] = array(
466 'key' => '_office_id',
467 'value' => explode(",", $atts['office_id']),
468 'compare' => 'IN'
469 );
470 }
471
472 $tax_query = array();
473
474 if ( isset($atts['availability_id']) && $atts['availability_id'] != '' )
475 {
476 $tax_query[] = array(
477 'taxonomy' => 'availability',
478 'terms' => explode(",", $atts['availability_id']),
479 'compare' => 'IN',
480 );
481 }
482
483 $args = array(
484 'post_type' => 'property',
485 'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ),
486 'ignore_sticky_posts' => 1,
487 'posts_per_page' => $atts['per_page'],
488 'orderby' => $atts['orderby'],
489 'order' => $atts['order'],
490 'meta_query' => $meta_query,
491 'tax_query' => $tax_query,
492 );
493
494 ob_start();
495
496 $properties = new WP_Query( apply_filters( 'propertyhive_shortcode_recent_properties_query', $args, $atts ) );
497
498 $propertyhive_loop['columns'] = $atts['columns'];
499
500 if ( $properties->have_posts() ) : ?>
501
502 <?php propertyhive_property_loop_start(); ?>
503
504 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
505
506 <?php ph_get_template_part( 'content', 'property-recent' ); ?>
507
508 <?php endwhile; // end of the loop. ?>
509
510 <?php propertyhive_property_loop_end(); ?>
511
512 <?php else: ?>
513
514 <?php echo $atts['no_results_output']; ?>
515
516 <?php endif;
517
518 wp_reset_postdata();
519
520 $shortcode_output = ob_get_clean();
521
522 return apply_filters( 'propertyhive_recent_properties_shortcode_output', '<div class="propertyhive propertyhive-recent-properties-shortcode columns-' . $atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
523
524 }
525
526 /**
527 * Output featured properties
528 *
529 * @access public
530 * @param array $atts
531 * @return string
532 */
533 public static function featured_properties( $atts ) {
534 global $propertyhive_loop;
535
536 $atts = shortcode_atts( array(
537 'per_page' => '12',
538 'columns' => '4',
539 'department' => '',
540 'office_id' => '',
541 'availability_id' => '',
542 'orderby' => 'rand',
543 'order' => 'desc',
544 'meta_key' => '',
545 'no_results_output' => '',
546 ), $atts, 'featured_properties' );
547
548 $args = array(
549 'post_type' => 'property',
550 'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ),
551 'ignore_sticky_posts' => 1,
552 'posts_per_page' => $atts['per_page'],
553 'orderby' => $atts['orderby'],
554 'order' => $atts['order'],
555 );
556
557 $meta_query = array(
558 array(
559 'key' => '_on_market',
560 'value' => 'yes',
561 ),
562 array(
563 'key' => '_featured',
564 'value' => 'yes'
565 )
566 );
567
568 if ( isset($atts['department']) && $atts['department'] != '' )
569 {
570 $meta_query[] = array(
571 'key' => '_department',
572 'value' => $atts['department'],
573 'compare' => '='
574 );
575 }
576
577 if ( isset($atts['office_id']) && $atts['office_id'] != '' )
578 {
579 $meta_query[] = array(
580 'key' => '_office_id',
581 'value' => explode(",", $atts['office_id']),
582 'compare' => 'IN'
583 );
584 }
585
586 $args['meta_query'] = $meta_query;
587
588 if ( ! empty( $atts['meta_key'] ) ) {
589 $args['meta_key'] = $atts['meta_key'];
590 }
591
592 $tax_query = array();
593
594 if ( isset($atts['availability_id']) && $atts['availability_id'] != '' )
595 {
596 $tax_query[] = array(
597 'taxonomy' => 'availability',
598 'terms' => explode(",", $atts['availability_id']),
599 'compare' => 'IN',
600 );
601 }
602
603 if ( ! empty( $tax_query ) ) {
604 $args['tax_query'] = $tax_query;
605 }
606
607 ob_start();
608
609 $properties = new WP_Query( apply_filters( 'propertyhive_shortcode_featured_properties_query', $args, $atts ) );
610
611 $propertyhive_loop['columns'] = $atts['columns'];
612
613 if ( $properties->have_posts() ) : ?>
614
615 <?php propertyhive_property_loop_start(); ?>
616
617 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
618
619 <?php ph_get_template_part( 'content', 'property-featured' ); ?>
620
621 <?php endwhile; // end of the loop. ?>
622
623 <?php propertyhive_property_loop_end(); ?>
624
625 <?php else: ?>
626
627 <?php echo $atts['no_results_output']; ?>
628
629 <?php endif;
630
631 wp_reset_postdata();
632
633 $shortcode_output = ob_get_clean();
634
635 return apply_filters( 'propertyhive_featured_properties_shortcode_output', '<div class="propertyhive propertyhive-featured-properties-shortcode columns-' . $atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
636 }
637
638 /**
639 * Output similar properties
640 *
641 * @param array $atts
642 * @return string
643 */
644 public static function similar_properties( $atts ) {
645
646 $atts = shortcode_atts( array(
647 'per_page' => '2',
648 'columns' => '2',
649 'orderby' => 'rand',
650 'order' => 'asc',
651 'price_percentage_bounds' => 10,
652 'bedroom_bounds' => 0,
653 'property_id' => '',
654 'availability_id' => '',
655 'no_results_output' => '',
656 ), $atts, 'similar_properties' );
657
658 if ($atts['property_id'] != '')
659 {
660 $department = get_post_meta( $atts['property_id'], '_department', true );
661
662 $price = get_post_meta( $atts['property_id'], '_price_actual', true );
663 $lower_price = $price;
664 $higher_price = $price;
665 $atts['price_percentage_bounds'] = str_replace("%", "", $atts['price_percentage_bounds']);
666 if ( isset($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] != '' && is_numeric($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] > 0 )
667 {
668 $lower_price = $price - ($price * $atts['price_percentage_bounds'] / 100);
669 $higher_price = $price + ($price * $atts['price_percentage_bounds'] / 100);
670 }
671
672 $bedrooms = get_post_meta( $atts['property_id'], '_bedrooms', true );
673 $lower_bedrooms = $bedrooms;
674 $higher_bedrooms = $bedrooms;
675 if ( isset($atts['bedroom_bounds']) && $atts['bedroom_bounds'] != '' && is_numeric($atts['bedroom_bounds']) && $atts['bedroom_bounds'] > 0 )
676 {
677 $lower_bedrooms = $bedrooms - $atts['bedroom_bounds'];
678 $higher_bedrooms = $bedrooms + $atts['bedroom_bounds'];
679 }
680
681 $args = array(
682 'post_type' => 'property',
683 'post__not_in' => array($atts['property_id']),
684 'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ),
685 'ignore_sticky_posts' => 1,
686 'posts_per_page' => $atts['per_page'],
687 'orderby' => $atts['orderby'],
688 'order' => $atts['order'],
689 );
690
691 $meta_query = array();
692
693 $meta_query[] = array(
694 'key' => '_department',
695 'value' => $department,
696 );
697
698 $meta_query[] = array(
699 'key' => '_on_market',
700 'value' => 'yes',
701 );
702
703 if ( isset($atts['bedroom_bounds']) && is_numeric($atts['bedroom_bounds']) )
704 {
705 $meta_query[] = array(
706 'key' => '_bedrooms',
707 'value' => $lower_bedrooms,
708 'compare' => '>=',
709 'type' => 'NUMERIC'
710 );
711
712 $meta_query[] = array(
713 'key' => '_bedrooms',
714 'value' => $higher_bedrooms,
715 'compare' => '<=',
716 'type' => 'NUMERIC'
717 );
718 }
719
720 if ( isset($atts['price_percentage_bounds']) && is_numeric($atts['price_percentage_bounds']) )
721 {
722 $meta_query[] = array(
723 'key' => '_price_actual',
724 'value' => $lower_price,
725 'compare' => '>=',
726 'type' => 'NUMERIC'
727 );
728
729 $meta_query[] = array(
730 'key' => '_price_actual',
731 'value' => $higher_price,
732 'compare' => '<=',
733 'type' => 'NUMERIC'
734 );
735 }
736
737 $args['meta_query'] = $meta_query;
738
739 $tax_query = array();
740
741 if ( isset($atts['availability_id']) && $atts['availability_id'] != '' )
742 {
743 $tax_query[] = array(
744 'taxonomy' => 'availability',
745 'terms' => explode(",", $atts['availability_id']),
746 'compare' => 'IN',
747 );
748 }
749
750 if ( ! empty( $tax_query ) ) {
751 $args['tax_query'] = $tax_query;
752 }
753
754 ob_start();
755
756 $properties = new WP_Query( apply_filters( 'propertyhive_shortcode_similar_properties_query', $args, $atts ) );
757
758 $propertyhive_loop['columns'] = $atts['columns'];
759
760 if ( $properties->have_posts() ) : ?>
761
762 <?php propertyhive_property_loop_start(); ?>
763
764 <?php while ( $properties->have_posts() ) : $properties->the_post(); ?>
765
766 <?php ph_get_template_part( 'content', 'property-featured' ); ?>
767
768 <?php endwhile; // end of the loop. ?>
769
770 <?php propertyhive_property_loop_end(); ?>
771
772 <?php else: ?>
773
774 <?php echo $atts['no_results_output']; ?>
775
776 <?php endif;
777
778 wp_reset_postdata();
779 }
780 else
781 {
782 echo 'No property_id passed into similar_properties shortcode';
783 }
784
785 $shortcode_output = ob_get_clean();
786
787 return apply_filters( 'propertyhive_similar_properties_shortcode_output', '<div class="propertyhive propertyhive-similar-properties-shortcode columns-' . $atts['columns'] . '">' . $shortcode_output . '</div>', $shortcode_output );
788 }
789
790 /**
791 * Output property map
792 * Should only be used on a property page or where the $property var is set
793 *
794 * @param array $atts
795 * @return string
796 */
797 public static function property_map( $atts ) {
798
799 global $property;
800
801 $atts = shortcode_atts( array(
802 'id' => '',
803 'height' => '400',
804 'zoom' => '14',
805 'scrollwheel' => 'true'
806 ), $atts, 'property_map' );
807
808 ob_start();
809
810 echo get_property_map( $atts );
811
812 return ob_get_clean();
813 }
814
815 /**
816 * Output property street view
817 * Should only be used on a property page or where the $property var is set
818 *
819 * @param array $atts
820 * @return string
821 */
822 public static function property_street_view( $atts ) {
823
824 global $property;
825
826 $atts = shortcode_atts( array(
827 'height' => '400',
828 ), $atts, 'property_street_view' );
829
830 ob_start();
831
832 echo get_property_street_view( $atts );
833
834 return ob_get_clean();
835 }
836
837 /**
838 * Output property office details
839 * Should only be used on a property page or where the $property var is set
840 *
841 * @param array $atts
842 * @return string
843 */
844 public static function property_office_details( $atts ) {
845
846 global $property;
847
848 $atts = shortcode_atts( array(
849 'address_separator' => '<br>',
850 'hyperlink_telephone_number' => true,
851 'hyperlink_email_address' => true,
852 ), $atts, 'property_office_details' );
853
854 $atts['hyperlink_telephone_number'] = (($atts['hyperlink_telephone_number'] === 'true' || $atts['hyperlink_telephone_number'] === true) ? true : false);
855 $atts['hyperlink_email_address'] = (($atts['hyperlink_email_address'] === 'true' || $atts['hyperlink_email_address'] === true) ? true : false);
856
857 ob_start();
858
859 if ( $property->office_id != '' )
860 {
861 echo '<div class="property-office-details">';
862
863 if ( $property->office_name != '' )
864 {
865 echo '<div class="office-name">' . $property->office_name . '</div>';
866 }
867
868 if ( $property->get_office_address( $atts['address_separator'] ) != '' )
869 {
870 echo '<div class="office-address">' . $property->get_office_address( $atts['address_separator'] ) . '</div>';
871 }
872
873 if ( $property->office_telephone_number != '' )
874 {
875 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>';
876 }
877
878 if ( $property->office_email_address != '' )
879 {
880 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>';
881 }
882
883 echo '</div>';
884 }
885
886 return ob_get_clean();
887 }
888
889 /**
890 * Output office map
891 *
892 * @param array $atts
893 * @return string
894 */
895 public static function office_map( $atts ) {
896
897 $offices_with_lat_lng = 0;
898 if ( !isset($atts['office_id']) || ( isset($atts['office_id']) && $atts['office_id'] == '' ) )
899 {
900 $args = array(
901 'post_type' => 'office',
902 'nopaging' => true
903 );
904
905 $office_query = new WP_Query( $args );
906
907 if ( $office_query->have_posts() )
908 {
909 while ( $office_query->have_posts() )
910 {
911 $office_query->the_post();
912
913 $lat = get_post_meta(get_the_ID(), '_office_latitude', TRUE);
914 $lng = get_post_meta(get_the_ID(), '_office_longitude', TRUE);
915
916 if ( $lat != '' && $lng != '' )
917 {
918 ++$offices_with_lat_lng;
919 }
920 }
921 }
922 wp_reset_postdata();
923 }
924
925 $atts = shortcode_atts( array(
926 'office_id' => '', // if wanting to show map for a particular office
927 'height' => '400',
928 'zoom' => ( ( ( !isset($atts['office_id']) || ( isset($atts['office_id']) && $atts['office_id'] == '' ) ) && !isset($atts['zoom']) && $offices_with_lat_lng > 1 ) ? 'auto' : '14' ),
929 'scrollwheel' => 'true'
930 ), $atts, 'office_map' );
931
932 ob_start();
933
934 $api_key = get_option('propertyhive_google_maps_api_key', '');
935 wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3');
936 wp_enqueue_script('googlemaps');
937
938 echo '<div id="office_map_canvas" style="height:' . str_replace( "px", "", ( ( isset($atts['height']) && !empty($atts['height']) ) ? $atts['height'] : '400' ) ) . 'px"></div>';
939 ?>
940 <script>
941
942 // We declare vars globally so developers can access them
943 var office_map; // Global declaration of the map
944 var office_marker;
945 var ph_office_map_lat_lngs = new Array();
946
947 function initialize_office_map() {
948
949 <?php
950 $args = array(
951 'post_type' => 'office',
952 'posts_per_page' => 1
953 );
954
955 if ( isset($atts['office_id']) && (int)$atts['office_id'] != 0 )
956 {
957 $args['p'] = (int)$atts['office_id'];
958 }
959 else
960 {
961 $args['meta_query'] = array(
962 array(
963 'key' => 'primary',
964 'value' => '1'
965 )
966 );
967 }
968
969 $office_query = new WP_Query( $args );
970
971 $lat = '';
972 $lng = '';
973
974 if ( $office_query->have_posts() )
975 {
976 while ( $office_query->have_posts() )
977 {
978 $office_query->the_post();
979
980 $lat = get_post_meta(get_the_ID(), '_office_latitude', TRUE);
981 $lng = get_post_meta(get_the_ID(), '_office_longitude', TRUE);
982 }
983 }
984 if ( $lat == '' || $lng == '' )
985 {
986 $lat = '51.509865';
987 $lng = '-0.118092';
988 }
989 ?>
990 var myLatlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $lng; ?>);
991 var map_options = {
992 zoom: <?php echo ( ( isset($atts['zoom']) && !empty($atts['zoom']) && $atts['zoom'] != 'auto' ) ? $atts['zoom'] : '14' ); ?>,
993 center: myLatlng,
994 mapTypeId: google.maps.MapTypeId.ROADMAP,
995 scrollwheel: <?php echo ( ( isset($atts['scrollwheel']) && ($atts['scrollwheel'] === 'false' || $atts['scrollwheel'] === FALSE) ) ? 'false' : 'true' ); ?>
996 }
997 <?php
998 if ( class_exists( 'PH_Map_Search' ) )
999 {
1000 $map_add_on_settings = get_option( 'propertyhive_map_search', array() );
1001
1002 if ( isset($map_add_on_settings['style_js']) && trim($map_add_on_settings['style_js']) != '' )
1003 {
1004 echo 'map_options.styles = ' . trim($map_add_on_settings['style_js']) . ';';
1005 }
1006 }
1007
1008 do_action( 'propertyhive_office_map_options' );
1009 ?>
1010 office_map = new google.maps.Map(document.getElementById("office_map_canvas"), map_options);
1011
1012 <?php
1013 $args = array(
1014 'post_type' => 'office',
1015 'nopaging' => true
1016 );
1017
1018 if ( isset($atts['office_id']) && (int)$atts['office_id'] != 0 )
1019 {
1020 $args['p'] = (int)$atts['office_id'];
1021 }
1022
1023 $office_query = new WP_Query( $args );
1024
1025 if ( $office_query->have_posts() )
1026 {
1027 while ( $office_query->have_posts() )
1028 {
1029 $office_query->the_post();
1030
1031 $lat = get_post_meta(get_the_ID(), '_office_latitude', TRUE);
1032 $lng = get_post_meta(get_the_ID(), '_office_longitude', TRUE);
1033
1034 if ( $lat != '' && $lng != '' )
1035 {
1036 ?>
1037 var myLatlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $lng; ?>);
1038
1039 var marker_options = {
1040 map: office_map,
1041 position: myLatlng,
1042 title: "<?php echo esc_attr(get_the_title()); ?>"
1043 };
1044
1045 <?php
1046 if ( class_exists( 'PH_Map_Search' ) )
1047 {
1048 $map_add_on_settings = get_option( 'propertyhive_map_search', array() );
1049
1050 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'] != '' )
1051 {
1052 $marker_icon_url = wp_get_attachment_url( $map_add_on_settings['custom_icon_attachment_id'] );
1053 if ( $marker_icon_url !== FALSE )
1054 {
1055 echo 'marker_options.icon = \'' . $marker_icon_url . '\';';
1056 }
1057 }
1058 }
1059 ?>
1060
1061 <?php do_action( 'propertyhive_office_map_marker_options' ); ?>
1062
1063 office_marker = new google.maps.Marker(marker_options);
1064 ph_office_map_lat_lngs.push(office_marker.getPosition());
1065 <?php
1066 }
1067 }
1068 }
1069 wp_reset_postdata();
1070
1071 if ( $atts['zoom'] == 'auto' ) { echo 'ph_fit_office_map_to_bounds();'; }
1072 ?>
1073 }
1074
1075 function ph_fit_office_map_to_bounds()
1076 {
1077 var bounds = new google.maps.LatLngBounds();
1078 if ( ph_office_map_lat_lngs.length > 0 )
1079 {
1080 for ( var i = 0; i < ph_office_map_lat_lngs.length; i++ )
1081 {
1082 bounds.extend(ph_office_map_lat_lngs[i]);
1083 }
1084 office_map.fitBounds(bounds);
1085 }
1086 }
1087
1088 if(window.addEventListener) {
1089 window.addEventListener('load', initialize_office_map);
1090 }else{
1091 window.attachEvent('onload', initialize_office_map);
1092 }
1093
1094 </script>
1095 <?php
1096 return ob_get_clean();
1097 }
1098
1099 /**
1100 * Output applicant registration form
1101 *
1102 * @param array $atts
1103 * @return string
1104 */
1105 public static function applicant_registration_form( $atts ) {
1106
1107 $atts = shortcode_atts( array(
1108
1109 ), $atts, 'applicant_registration_form' );
1110
1111 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
1112 wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true );
1113
1114 ob_start();
1115
1116 if ( is_user_logged_in() )
1117 {
1118 ph_get_template( 'account/already-logged-in.php' );
1119 return ob_get_clean();
1120 }
1121
1122 $form_controls = ph_get_user_details_form_fields();
1123
1124 $form_controls = apply_filters( 'propertyhive_user_details_form_fields', $form_controls );
1125
1126 $form_controls_2 = ph_get_applicant_requirements_form_fields();
1127
1128 $form_controls_2 = apply_filters( 'propertyhive_applicant_requirements_form_fields', $form_controls_2 );
1129
1130 $form_controls = array_merge( $form_controls, $form_controls_2 );
1131
1132 if ( get_option( 'propertyhive_applicant_registration_form_disclaimer', '' ) != '' )
1133 {
1134 $disclaimer = get_option( 'propertyhive_applicant_registration_form_disclaimer', '' );
1135
1136 $form_controls['disclaimer'] = array(
1137 'type' => 'checkbox',
1138 'label' => $disclaimer,
1139 'label_style' => 'width:100%;',
1140 'required' => true
1141 );
1142 }
1143
1144 $form_controls = apply_filters( 'propertyhive_applicant_registration_form_fields', $form_controls );
1145
1146 ph_get_template( 'account/applicant-registration-form.php', array( 'form_controls' => $form_controls ) );
1147
1148 return ob_get_clean();
1149 }
1150
1151 /**
1152 * Output 'Login' page
1153 *
1154 * @param array $atts
1155 * @return string
1156 */
1157 public static function login_form( $atts )
1158 {
1159 $atts = shortcode_atts( array(
1160
1161 ), $atts, 'login_form' );
1162
1163 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
1164 wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true );
1165
1166 ob_start();
1167
1168 if ( is_user_logged_in() )
1169 {
1170 ph_get_template( 'account/already-logged-in.php' );
1171 return ob_get_clean();
1172 }
1173
1174 // Check 'propertyhive_applicant_users' setting is enabled
1175 if ( get_option( 'propertyhive_applicant_users', '' ) != 'yes' )
1176 {
1177 ph_get_template( 'account/invalid-access.php' );
1178 return ob_get_clean();
1179 }
1180
1181 ph_get_template( 'account/login-form.php' );
1182
1183 return ob_get_clean();
1184
1185 }
1186
1187 /**
1188 * Output 'My Account' page
1189 *
1190 * @param array $atts
1191 * @return string
1192 */
1193 public static function my_account( $atts )
1194 {
1195 $atts = shortcode_atts( array(
1196
1197 ), $atts, 'my_account' );
1198
1199 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
1200 wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true );
1201
1202 ob_start();
1203
1204 // Check user is logged in
1205 if ( !is_user_logged_in() )
1206 {
1207 ph_get_template( 'account/invalid-access.php' );
1208 return ob_get_clean();
1209 }
1210
1211 // Check 'propertyhive_applicant_users' setting is enabled
1212 if ( get_option( 'propertyhive_applicant_users', '' ) != 'yes' )
1213 {
1214 ph_get_template( 'account/invalid-access.php' );
1215 return ob_get_clean();
1216 }
1217
1218 ph_get_template( 'account/my-account.php' );
1219
1220 return ob_get_clean();
1221
1222 }
1223 }
1224