PluginProbe
Property Hive / 2.2.4
Property Hive v2.2.4
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 / ph-template-functions.php

ph-template-functions.php in Property Hive 2.2.4, at includes/ph-template-functions.php

2,108 lines 66.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Template
4 *
5 * Functions for the templating system.
6 *
7 * @author PropertyHive
8 * @category Core
9 * @package PropertyHive/Functions
10 * @version 1.0.0
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15 /**
16 * When the_post is called, put property data into a global.
17 *
18 * @param mixed $post
19 * @return PH_Property
20 */
21 function ph_setup_property_data( $post ) {
22 unset( $GLOBALS['property'] );
23
24 if ( is_int( $post ) )
25 $post = get_post( $post );
26
27 if ( empty( $post->post_type ) || ! in_array( $post->post_type, array( 'property' ) ) )
28 return;
29
30 $GLOBALS['property'] = get_property( $post );
31
32 return $GLOBALS['property'];
33 }
34 add_action( 'the_post', 'ph_setup_property_data' );
35
36 /**
37 * Properties RSS Feed.
38 *
39 * @access public
40 * @return void
41 */
42 function ph_properties_rss_feed() {
43 // Property RSS
44 if ( is_post_type_archive( 'property' ) || is_singular( 'property' ) ) {
45
46 $feed = get_post_type_archive_feed_link( 'property' );
47
48 echo '<link rel="alternate" type="application/rss+xml" title="' . esc_attr(__( 'Latest Properties', 'propertyhive' )) . '" href="' . esc_url( $feed ) . '" />';
49
50 }
51 }
52
53 /**
54 * Output generator tag to aid debugging.
55 *
56 * @access public
57 * @return void
58 */
59 function ph_generator_tag( $gen, $type ) {
60 switch ( $type ) {
61 case 'html':
62 $gen .= "\n" . '<meta name="generator" content="PropertyHive ' . esc_attr( PH_VERSION ) . '">';
63 break;
64 case 'xhtml':
65 $gen .= "\n" . '<meta name="generator" content="PropertyHive ' . esc_attr( PH_VERSION ) . '" />';
66 break;
67 }
68 return $gen;
69 }
70
71 /**
72 * Add body classes for PH pages
73 *
74 * @param array $classes
75 * @return array
76 */
77 function ph_body_class( $classes ) {
78 global $wp_query;
79
80 $classes = (array) $classes;
81
82 if ( is_propertyhive() ) {
83 $classes[] = 'propertyhive';
84 $classes[] = 'propertyhive-page';
85 }
86
87 // If we're on a single property, add body classes for taxonomy fields and department
88 if ( is_single() )
89 {
90 $post = $wp_query->get_queried_object();
91 if ( $post->post_type === 'property' )
92 {
93 // Duplication of the code in post-template-php that is done for search results posts in get_post_class()
94 // All public taxonomies.
95 $taxonomies = get_taxonomies( array( 'public' => true ) );
96 foreach ( (array) $taxonomies as $taxonomy ) {
97 if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
98 foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) {
99 if ( empty( $term->slug ) ) {
100 continue;
101 }
102
103 $term_class = sanitize_html_class( $term->slug, $term->term_id );
104 if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
105 $term_class = $term->term_id;
106 }
107
108 // 'post_tag' uses the 'tag' prefix for backward compatibility.
109 if ( 'post_tag' == $taxonomy ) {
110 $classes[] = 'tag-' . $term_class;
111 } else {
112 $classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id );
113 }
114 }
115 }
116 }
117 //
118
119 $property = get_property( $post->ID );
120 $classes[] = 'department-' . $property->department;
121 $classes[] = 'on-market-' . ( $property->on_market == 'yes' ? 'yes' : 'no' );
122 $classes[] = 'featured-' . ( $property->featured == 'yes' ? 'yes' : 'no' );
123 $classes[] = 'office-' . $property->office_id;
124 }
125 }
126
127 return array_unique( $classes );
128 }
129
130 /**
131 * Adds extra post classes for properties
132 *
133 * @since 1.0.0
134 * @param array $classes
135 * @param string|array $class
136 * @param int $post_id
137 * @return array
138 */
139 function ph_property_post_class( $classes, $class = '', $post_id = '' ) {
140 if ( ! $post_id || get_post_type( $post_id ) !== 'property' )
141 return $classes;
142
143 $property = get_property( $post_id );
144
145 if ( $property ) {
146 if ( $property->is_featured() ) {
147 $classes[] = 'featured';
148 }
149 }
150
151 if ( ( $key = array_search( 'hentry', $classes ) ) !== false ) {
152 unset( $classes[ $key ] );
153 }
154
155 // Add 'property' class, removing it first incase it exists
156 // Needed as results loaded with AJAX don't get the property class by default
157 if ( ( $key = array_search( 'property', $classes ) ) !== false ) {
158 unset( $classes[ $key ] );
159 }
160 $classes[] = 'property';
161 $classes[] = 'department-' . $property->department;
162 $classes[] = 'office-' . $property->office_id;
163
164 $classes = array_values($classes);
165
166 return $classes;
167 }
168
169 /** Global ****************************************************************/
170
171 if ( ! function_exists( 'propertyhive_output_content_wrapper' ) ) {
172
173 /**
174 * Output the start of the page wrapper.
175 *
176 * @access public
177 * @return void
178 */
179 function propertyhive_output_content_wrapper() {
180 ph_get_template( 'global/wrapper-start.php' );
181 }
182 }
183
184 if ( ! function_exists( 'propertyhive_output_content_wrapper_end' ) ) {
185
186 /**
187 * Output the end of the page wrapper.
188 *
189 * @access public
190 * @return void
191 */
192 function propertyhive_output_content_wrapper_end() {
193 ph_get_template( 'global/wrapper-end.php' );
194 }
195 }
196
197 /** Loop ******************************************************************/
198
199 if ( ! function_exists( 'propertyhive_page_title' ) ) {
200
201 /**
202 * propertyhive_page_title function.
203 *
204 * @param boolean $echo
205 * @return string
206 */
207 function propertyhive_page_title( $echo = true ) {
208
209 if ( is_search() )
210 {
211 $page_title = sprintf(
212 /* translators: %s: search query */
213 __( 'Search Results: &ldquo;%s&rdquo;', 'propertyhive' ),
214 get_search_query()
215 );
216
217 if ( get_query_var( 'paged' ) )
218 {
219 $page_title .= sprintf(
220 /* translators: %s: page number */
221 __( '&nbsp;&ndash; Page %s', 'propertyhive' ),
222 get_query_var( 'paged' )
223 );
224 }
225
226 }elseif ( is_tax() )
227 {
228 $page_title = single_term_title( "", false );
229 }
230 else
231 {
232 $search_results_page_id = ph_get_page_id( 'search_results' );
233 $page_title = get_the_title( $search_results_page_id );
234 }
235
236 $page_title = apply_filters( 'propertyhive_page_title', $page_title );
237
238 if ( $echo )
239 echo $page_title;
240 else
241 return $page_title;
242 }
243 }
244
245 if ( ! function_exists( 'propertyhive_property_loop_start' ) ) {
246
247 /**
248 * Output the start of a property loop. By default this is a UL
249 *
250 * @access public
251 * @param bool $echo
252 * @return string
253 */
254 function propertyhive_property_loop_start( $echo = true ) {
255 ob_start();
256 ph_get_template( 'search/loop-start.php' );
257 if ( $echo )
258 echo ob_get_clean();
259 else
260 return ob_get_clean();
261 }
262 }
263 if ( ! function_exists( 'propertyhive_property_loop_end' ) ) {
264
265 /**
266 * Output the end of a property loop. By default this is a UL
267 *
268 * @access public
269 * @param bool $echo
270 * @return string
271 */
272 function propertyhive_property_loop_end( $echo = true ) {
273 ob_start();
274
275 ph_get_template( 'search/loop-end.php' );
276
277 if ( $echo )
278 echo ob_get_clean();
279 else
280 return ob_get_clean();
281 }
282 }
283
284 if ( ! function_exists( 'propertyhive_template_loop_property_thumbnail' ) ) {
285
286 /**
287 * Get the property thumbnail for the loop.
288 *
289 * @access public
290 * @subpackage Loop
291 * @return void
292 */
293 function propertyhive_template_loop_property_thumbnail() {
294 echo propertyhive_get_property_thumbnail( apply_filters( 'property_search_results_thumbnail_size', 'medium' ) );
295 }
296 }
297
298 if ( ! function_exists( 'propertyhive_get_property_thumbnail' ) ) {
299
300 /**
301 * Get the property thumbnail, or the placeholder if not set.
302 *
303 * @access public
304 * @subpackage Loop
305 * @param string $size (default: 'medium')
306 * @param int $placeholder_width (default: 0)
307 * @param int $placeholder_height (default: 0)
308 * @return string
309 */
310 function propertyhive_get_property_thumbnail( $size = 'medium', $class = '', $placeholder_width = 0, $placeholder_height = 0 ) {
311 global $post, $property;
312
313 $photo_url = $property->get_main_photo_src( $size );
314
315 if ($photo_url !== FALSE)
316 return '<img src="' . $photo_url . '" alt="' . get_the_title($post->ID) . '" class="' . $class . '">';
317
318 if ( ph_placeholder_img_src() )
319 return ph_placeholder_img( $size );
320 }
321 }
322
323 if ( ! function_exists( 'propertyhive_template_loop_floor_area' ) ) {
324
325 /**
326 * Get the property floor area for the loop.
327 *
328 * @access public
329 * @subpackage Loop
330 * @return void
331 */
332 function propertyhive_template_loop_floor_area() {
333 global $property;
334
335 if ( $property->department == 'commercial' || ph_get_custom_department_based_on( $property->department ) == 'commercial' )
336 {
337 ph_get_template( 'search/floor-area.php' );
338 }
339 }
340 }
341
342 if ( ! function_exists( 'propertyhive_template_loop_price' ) ) {
343
344 /**
345 * Get the property price for the loop.
346 *
347 * @access public
348 * @subpackage Loop
349 * @return void
350 */
351 function propertyhive_template_loop_price() {
352
353 global $property;
354
355 $fees = '';
356 if ( get_option('propertyhive_lettings_fees_display_search_results', '') == 'yes' )
357 {
358 if (
359 $property->department == 'residential-lettings' &&
360 get_option('propertyhive_lettings_fees', '') != ''
361 )
362 {
363 $fees = nl2br(get_option('propertyhive_lettings_fees', ''));
364 }
365 if (
366 $property->department == 'commercial' &&
367 $property->to_rent == 'yes' &&
368 get_option('propertyhive_lettings_fees_commercial', '') != ''
369 )
370 {
371 $fees = nl2br(get_option('propertyhive_lettings_fees_commercial', ''));
372 }
373 }
374
375 $price_qualifier = '';
376 if (
377 (
378 $property->department == 'residential-sales' ||
379 ph_get_custom_department_based_on($property->department) == 'residential-sales' ||
380 $property->department == 'commercial' ||
381 ph_get_custom_department_based_on($property->department) == 'commercial'
382 ) &&
383 $property->price_qualifier != ''
384 )
385 {
386 $price_qualifier = $property->price_qualifier;
387 }
388
389 ph_get_template( 'search/price.php', array( 'price_qualifier' => $price_qualifier, 'fees' => $fees ) );
390 }
391 }
392
393 if ( ! function_exists( 'propertyhive_template_loop_summary' ) ) {
394
395 /**
396 * Get the property summary for the loop.
397 *
398 * @access public
399 * @subpackage Loop
400 * @return void
401 */
402 function propertyhive_template_loop_summary() {
403 ph_get_template( 'search/summary.php' );
404 }
405 }
406
407 if ( ! function_exists( 'propertyhive_template_loop_actions' ) ) {
408
409 /**
410 * Get the actions for the loop (ie More Details).
411 *
412 * @access public
413 * @subpackage Loop
414 * @return void
415 */
416 function propertyhive_template_loop_actions() {
417 ph_get_template( 'search/actions.php' );
418 }
419 }
420
421 if ( ! function_exists( 'propertyhive_search_form' ) ) {
422
423 /**
424 * Output the search form
425 *
426 * @access public
427 * @subpackage Loop
428 * @return void
429 */
430 function propertyhive_search_form($id = 'default') {
431 ph_get_search_form( ( $id != '' ) ? $id : 'default' );
432 }
433 }
434
435 if ( ! function_exists( 'propertyhive_result_count' ) ) {
436
437 /**
438 * Output the result count text (Showing x - x of x results).
439 *
440 * @access public
441 * @subpackage Loop
442 * @return void
443 */
444 function propertyhive_result_count( $paged = '', $per_page = null, $total = null, $first = null, $last = null ) {
445 global $wp_query;
446
447 $paged = $paged !== '' ? (int)$paged : max( 1, (int)$wp_query->get( 'paged' ) );
448 $per_page = $per_page !== null ? (int)$per_page : max( 1, (int)$wp_query->get( 'posts_per_page' ) );
449 $total = $total !== null ? (int)$total : (int)$wp_query->found_posts;
450 $first = $first !== null ? (int)$first : ( $per_page * $paged ) - $per_page + 1;
451 $last = $last !== null ? (int)$last : min( $total, $per_page * $paged );
452
453 $args = array(
454 'paged' => $paged,
455 'per_page' => $per_page,
456 'total' => $total,
457 'first' => $first,
458 'last' => $last,
459 );
460
461 ph_get_template( 'search/result-count.php', $args );
462 }
463 }
464
465 if ( ! function_exists( 'propertyhive_catalog_ordering' ) ) {
466
467 /**
468 * Output the property sorting options.
469 *
470 * @access public
471 * @subpackage Loop
472 * @return void
473 */
474 function propertyhive_catalog_ordering( $department = '', $orderby = '' ) {
475
476 if ( $orderby === '' )
477 {
478 $orderby = isset( $_GET['orderby'] ) ? ph_clean( sanitize_text_field($_GET['orderby']) ) : apply_filters( 'propertyhive_default_search_results_orderby', get_option( 'propertyhive_default_search_results_orderby' ) );
479 }
480
481 $args = array(
482 'department' => $department !== '' ? $department : ( isset($_REQUEST['department']) ? $_REQUEST['department'] : '' ),
483 'orderby' => $orderby,
484 );
485
486 ph_get_template( 'search/orderby.php', $args );
487 }
488 }
489
490 if ( ! function_exists( 'propertyhive_pagination' ) ) {
491
492 /**
493 * Output the pagination.
494 *
495 * @access public
496 * @subpackage Loop
497 * @return void
498 */
499 function propertyhive_pagination( $max_num_pages = '' ) {
500
501 global $wp_query;
502
503 $args = array(
504 'max_num_pages' => $max_num_pages !== '' ? $max_num_pages : $wp_query->max_num_pages,
505 );
506
507 ph_get_template( 'search/pagination.php', $args );
508 }
509 }
510
511 /** Single Property ********************************************************/
512
513 if ( ! function_exists( 'propertyhive_template_not_on_market' ) ) {
514
515 /**
516 * Output a warning/message if property is not on the market
517 *
518 * @access public
519 * @subpackage Property
520 * @return void
521 */
522 function propertyhive_template_not_on_market() {
523 ph_get_template( 'single-property/not-on-market.php' );
524 }
525 }
526
527 if ( get_option('propertyhive_off_market_behaviour', '') == 'redirect' )
528 {
529 function ph_redirect_off_market_properties()
530 {
531 // If we're viewing an off market property, redirect to the search form
532 if (is_singular('property'))
533 {
534 if ( get_post_meta(get_the_ID(), '_on_market', TRUE) === '' )
535 {
536 if ( !is_user_logged_in() || !current_user_can('administrator') && !current_user_can('editor') )
537 {
538 wp_redirect(get_permalink(ph_get_page_id('search_results')), 301);
539 exit;
540 }
541 }
542 }
543 }
544 add_action( 'template_redirect', 'ph_redirect_off_market_properties', 5 );
545 }
546
547 if ( ! function_exists( 'propertyhive_show_property_images' ) ) {
548
549 /**
550 * Output the property image before the single property summary.
551 *
552 * @access public
553 * @subpackage Property
554 * @return void
555 */
556 function propertyhive_show_property_images( $num_images = '' )
557 {
558 global $property;
559
560 $images = array();
561 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
562 {
563 $photo_urls = $property->_photo_urls;
564 if ( !is_array($photo_urls) ) { $photo_urls = array(); }
565
566 if ( !empty($num_images) )
567 {
568 $photo_urls = array_slice($photo_urls, 0, $num_images);
569 }
570
571 foreach ( $photo_urls as $photo )
572 {
573 $images[] = array(
574 'title' => isset($photo['title']) ? $photo['title'] : '',
575 'url' => isset($photo['url']) ? $photo['url'] : '',
576 'image' => '<img src="' . ( isset($photo['url']) ? $photo['url'] : '' ) . '" alt="' . ( isset($photo['title']) ? $photo['title'] : '' ) . '">',
577 );
578 }
579 }
580 else
581 {
582 $gallery_attachments = $property->get_gallery_attachment_ids();
583
584 if ( !empty($gallery_attachments) )
585 {
586 if ( !empty($num_images) )
587 {
588 $gallery_attachments = array_slice($gallery_attachments, 0, $num_images);
589 }
590
591 foreach ($gallery_attachments as $gallery_attachment)
592 {
593 $images[] = array(
594 'title' => esc_attr( get_the_title( $gallery_attachment ) ),
595 'url' => wp_get_attachment_url( $gallery_attachment ),
596 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'original' ) ),
597 'attachment_id' => $gallery_attachment,
598 );
599 }
600 }
601 }
602
603 ph_get_template( 'single-property/property-images.php', array( 'images' => $images ) );
604 }
605 }
606
607 if ( ! function_exists( 'propertyhive_show_property_thumbnails' ) ) {
608
609 /**
610 * Output the property thumbnails.
611 *
612 * @access public
613 * @subpackage Property
614 * @return void
615 */
616 function propertyhive_show_property_thumbnails() {
617
618 global $property;
619
620 $images = array();
621 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
622 {
623 $photo_urls = $property->_photo_urls;
624 if ( !is_array($photo_urls) ) { $photo_urls = array(); }
625
626 foreach ( $photo_urls as $photo )
627 {
628 $images[] = array(
629 'title' => isset($photo['title']) ? $photo['title'] : '',
630 'url' => isset($photo['url']) ? $photo['url'] : '',
631 'image' => '<img src="' . ( isset($photo['url']) ? $photo['url'] : '' ) . '" alt="' . ( isset($photo['title']) ? $photo['title'] : '' ) . '">',
632 );
633 }
634 }
635 else
636 {
637 $gallery_attachments = $property->get_gallery_attachment_ids();
638
639 if ( !empty($gallery_attachments) )
640 {
641 foreach ($gallery_attachments as $gallery_attachment)
642 {
643 $images[] = array(
644 'title' => esc_attr( get_the_title( $gallery_attachment ) ),
645 'url' => wp_get_attachment_url( $gallery_attachment ),
646 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'single_property_small_thumbnail_size', 'thumbnail' ) ),
647 'attachment_id' => $gallery_attachment,
648 );
649 }
650 }
651 }
652
653 ph_get_template( 'single-property/property-thumbnails.php', array( 'images' => $images ) );
654 }
655 }
656
657 if ( ! function_exists( 'propertyhive_template_single_title' ) ) {
658
659 /**
660 * Output the property title.
661 *
662 * @access public
663 * @subpackage Property
664 * @return void
665 */
666 function propertyhive_template_single_title() {
667 ph_get_template( 'single-property/title.php' );
668 }
669 }
670
671 if ( ! function_exists( 'propertyhive_template_single_floor_area' ) ) {
672
673 /**
674 * Output the property floor area.
675 *
676 * @access public
677 * @subpackage Property
678 * @return void
679 */
680 function propertyhive_template_single_floor_area() {
681 global $property;
682
683 if ( $property->department == 'commercial' || ph_get_custom_department_based_on( $property->department ) == 'commercial' )
684 {
685 ph_get_template( 'single-property/floor-area.php' );
686 }
687 }
688 }
689
690 if ( ! function_exists( 'propertyhive_template_single_price' ) ) {
691
692 /**
693 * Output the property price.
694 *
695 * @access public
696 * @subpackage Property
697 * @return void
698 */
699 function propertyhive_template_single_price() {
700
701 global $property;
702
703 $fees = '';
704 if ( get_option('propertyhive_lettings_fees_display_single_property', '') == 'yes' )
705 {
706 if (
707 $property->department == 'residential-lettings' &&
708 get_option('propertyhive_lettings_fees', '') != ''
709 )
710 {
711 $fees = nl2br(get_option('propertyhive_lettings_fees', ''));
712 }
713 if (
714 $property->department == 'commercial' &&
715 $property->to_rent == 'yes' &&
716 get_option('propertyhive_lettings_fees_commercial', '') != ''
717 )
718 {
719 $fees = nl2br(get_option('propertyhive_lettings_fees_commercial', ''));
720 }
721 }
722
723 $price_qualifier = '';
724 if (
725 (
726 $property->department == 'residential-sales' ||
727 ph_get_custom_department_based_on($property->department) == 'residential-sales' ||
728 $property->department == 'commercial' ||
729 ph_get_custom_department_based_on($property->department) == 'commercial'
730 ) &&
731 $property->price_qualifier != ''
732 )
733 {
734 $price_qualifier = $property->price_qualifier;
735 }
736
737 ph_get_template( 'single-property/price.php', array( 'price_qualifier' => $price_qualifier, 'fees' => $fees ) );
738 }
739 }
740
741 if ( ! function_exists( 'propertyhive_template_single_meta' ) ) {
742
743 /**
744 * Output the product meta.
745 *
746 * @access public
747 * @subpackage Property
748 * @return void
749 */
750 function propertyhive_template_single_meta() {
751
752 global $post, $property;
753
754 $meta = array();
755
756 if ( $property->reference_number != '' )
757 {
758 $meta['reference-number'] = array(
759 'label' => __('Ref', 'propertyhive'),
760 'value' => $property->reference_number
761 );
762 }
763
764 if ( $property->property_type != '' )
765 {
766 $meta['property-type'] = array(
767 'label' => __('Type', 'propertyhive'),
768 'value' => $property->property_type
769 );
770 }
771
772 if ( $property->availability != '' )
773 {
774 $meta['availability'] = array(
775 'label' => __('Availability', 'propertyhive'),
776 'value' => $property->availability
777 );
778 }
779
780 if ( $property->department != 'commercial' && ph_get_custom_department_based_on( $property->department ) != 'commercial' )
781 {
782 if ( $property->bedrooms > 0 )
783 {
784 $meta['bedrooms'] = array(
785 'label' => __('Bedrooms', 'propertyhive'),
786 'value' => $property->bedrooms
787 );
788 }
789
790 if ( $property->bathrooms > 0 )
791 {
792 $meta['bathrooms'] = array(
793 'label' => __('Bathrooms', 'propertyhive'),
794 'value' => $property->bathrooms
795 );
796 }
797
798 if ( $property->reception_rooms > 0 )
799 {
800 $meta['reception-rooms'] = array(
801 'label' => __('Reception Rooms', 'propertyhive'),
802 'value' => $property->reception_rooms
803 );
804 }
805
806 if ( $property->parking != '' )
807 {
808 $meta['parking'] = array(
809 'label' => __('Parking', 'propertyhive'),
810 'value' => $property->parking
811 );
812 }
813
814 if ( $property->outside_space != '' )
815 {
816 $meta['outside-space'] = array(
817 'label' => __('Outside Space', 'propertyhive'),
818 'value' => $property->outside_space
819 );
820 }
821
822 if ( $property->council_tax_band != '' )
823 {
824 $meta['council-tax-band'] = array(
825 'label' => __('Council Tax Band', 'propertyhive'),
826 'value' => $property->council_tax_band
827 );
828 }
829 }
830
831 if ( $property->department == 'residential-sales' || ph_get_custom_department_based_on( $property->department ) == 'residential-sales' )
832 {
833 if ( $property->tenure != '' )
834 {
835 $meta['tenure'] = array(
836 'label' => __('Tenure', 'propertyhive'),
837 'value' => $property->tenure
838 );
839
840 if ( in_array( strtolower($property->tenure), apply_filters('propertyhive_leasehold_tenure_names', array( 'leasehold', 'share of freehold' ) ) ) )
841 {
842 if ( $property->leasehold_years_remaining != '' )
843 {
844 $meta['leasehold-years-remaining'] = array(
845 'label' => __('Leasehold Remaining', 'propertyhive'),
846 'value' => $property->leasehold_years_remaining . ' ' . __( 'years', 'propertyhive' )
847 );
848 }
849
850 if ( $property->ground_rent != '' )
851 {
852 $meta['ground-rent'] = array(
853 'label' => __('Ground Rent', 'propertyhive'),
854 'value' => '&pound;' . ph_display_price_field($property->ground_rent, true)
855 );
856 }
857
858 if ( $property->ground_rent_review_years != '' )
859 {
860 $meta['ground-rent-review-years'] = array(
861 'label' => __('Ground Rent Review Period', 'propertyhive'),
862 'value' => $property->ground_rent_review_years . ' ' . __( 'years', 'propertyhive' )
863 );
864 }
865
866 if ( $property->service_charge != '' )
867 {
868 $meta['service-charge'] = array(
869 'label' => __('Service Charge', 'propertyhive'),
870 'value' => '&pound;' . ph_display_price_field($property->service_charge, true)
871 );
872 }
873
874 if ( $property->service_charge_review_years != '' )
875 {
876 $meta['service-charge-review-years'] = array(
877 'label' => __('Service Charge Review Period', 'propertyhive'),
878 'value' => $property->service_charge_review_years . ' ' . __( 'years', 'propertyhive' )
879 );
880 }
881
882 if ( $property->shared_ownership == 'yes' )
883 {
884 $meta['shared-ownership'] = array(
885 'label' => __('Shared Ownership', 'propertyhive'),
886 'value' => $property->shared_ownership . ( $property->shared_ownership_percentage != '' ? ' (' . $property->shared_ownership_percentage . '%)' : '' )
887 );
888 }
889 }
890 }
891 }
892
893 if ( $property->department == 'residential-lettings' || ph_get_custom_department_based_on( $property->department ) == 'residential-lettings' )
894 {
895 if ( $property->furnished != '' )
896 {
897 $meta['furnished'] = array(
898 'label' => __('Furnished', 'propertyhive'),
899 'value' => $property->furnished
900 );
901 }
902
903 if ( $property->deposit > 0 )
904 {
905 $meta['deposit'] = array(
906 'label' => __('Deposit', 'propertyhive'),
907 'value' => $property->get_formatted_deposit()
908 );
909 }
910
911 if ( $property->available_date != '' )
912 {
913 $meta['available-date'] = array(
914 'label' => __('Available', 'propertyhive'),
915 'value' => $property->get_available_date()
916 );
917 }
918 }
919
920 $meta = apply_filters( 'propertyhive_single_property_meta', $meta );
921
922 ph_get_template( 'single-property/meta.php', array( 'meta' => $meta ) );
923 }
924 }
925
926 if ( ! function_exists( 'propertyhive_template_single_sharing' ) ) {
927
928 /**
929 * Output the product sharing.
930 *
931 * @access public
932 * @subpackage Property
933 * @return void
934 */
935 function propertyhive_template_single_sharing() {
936 ph_get_template( 'single-property/share.php' );
937 }
938 }
939
940 if ( ! function_exists( 'propertyhive_get_template_single_floorplans_action' ) ) {
941
942 function propertyhive_get_template_single_floorplans_action() {
943
944 global $post, $property;
945
946 $actions = array();
947
948 if ( get_option('propertyhive_floorplans_stored_as', '') == 'urls' )
949 {
950 $floorplan_urls = $property->_floorplan_urls;
951 if ( is_array($floorplan_urls) && !empty( $floorplan_urls ) )
952 {
953 foreach ($floorplan_urls as $floorplan)
954 {
955 $actions[] = array(
956 'href' => ( ( isset($floorplan['url']) ) ? $floorplan['url'] : '' ),
957 'label' => __( 'Floorplan', 'propertyhive' ),
958 'class' => 'action-floorplans',
959 'attributes' => array(
960 'data-fancybox' => 'floorplans'
961 )
962 );
963 }
964 }
965 }
966 else
967 {
968 $floorplan_ids = $property->get_floorplan_attachment_ids();
969 if ( !empty( $floorplan_ids ) )
970 {
971 foreach ($floorplan_ids as $floorplan_id)
972 {
973 $label = 'Floorplan';
974
975 $attachment_data = wp_prepare_attachment_for_js( $floorplan_id );
976 if ( isset( $attachment_data['caption'] ) && $attachment_data['caption'] != '' )
977 {
978 $label = $attachment_data['caption'];
979 }
980
981
982 $actions[] = array(
983 'href' => wp_get_attachment_url( $floorplan_id ),
984 'label' => __( $label, 'propertyhive' ),
985 'class' => 'action-floorplans',
986 'attributes' => array(
987 'data-fancybox' => 'floorplans'
988 )
989 );
990 }
991 }
992 }
993
994 $actions = apply_filters( 'propertyhive_single_property_floorplans_actions', $actions );
995
996 return $actions;
997 }
998
999 }
1000
1001 if ( ! function_exists( 'propertyhive_get_template_single_brochures_action' ) ) {
1002
1003 function propertyhive_get_template_single_brochures_action() {
1004
1005 global $post, $property;
1006
1007 $actions = array();
1008
1009 if ( get_option('propertyhive_brochures_stored_as', '') == 'urls' )
1010 {
1011 $brochure_urls = $property->_brochure_urls;
1012 if ( is_array($brochure_urls) && !empty( $brochure_urls ) )
1013 {
1014 foreach ($brochure_urls as $brochure)
1015 {
1016 $actions[] = array(
1017 'href' => ( ( isset($brochure['url']) ) ? $brochure['url'] : '' ),
1018 'label' => __( 'View Brochure', 'propertyhive' ),
1019 'class' => 'action-brochure',
1020 'attributes' => array(
1021 'target' => '_blank'
1022 )
1023 );
1024 }
1025 }
1026 }
1027 else
1028 {
1029 $brochure_ids = $property->get_brochure_attachment_ids();
1030 if ( !empty( $brochure_ids ) )
1031 {
1032 foreach ($brochure_ids as $brochure_id)
1033 {
1034 $actions[] = array(
1035 'href' => wp_get_attachment_url( $brochure_id ),
1036 'label' => __( 'View Brochure', 'propertyhive' ),
1037 'class' => 'action-brochure',
1038 'attributes' => array(
1039 'target' => '_blank'
1040 )
1041 );
1042 }
1043 }
1044 }
1045
1046 $actions = apply_filters( 'propertyhive_single_property_brochures_actions', $actions );
1047
1048 return $actions;
1049 }
1050
1051 }
1052
1053 if ( ! function_exists( 'propertyhive_get_template_single_epcs_action' ) ) {
1054
1055 function propertyhive_get_template_single_epcs_action() {
1056
1057 global $post, $property;
1058
1059 $actions = array();
1060
1061 if ( get_option('propertyhive_epcs_stored_as', '') == 'urls' )
1062 {
1063 $epc_urls = $property->_epc_urls;
1064 if ( is_array($epc_urls) && !empty( $epc_urls ) )
1065 {
1066 foreach ($epc_urls as $epc)
1067 {
1068 $actions[] = array(
1069 'href' => ( ( isset($epc['url']) ) ? $epc['url'] : '' ),
1070 'label' => __( 'View EPC', 'propertyhive' ),
1071 'class' => 'action-epc',
1072 'attributes' => array(
1073 'target' => '_blank'
1074 )
1075 );
1076 }
1077 }
1078 }
1079 else
1080 {
1081 $epc_ids = $property->get_epc_attachment_ids();
1082 if ( !empty( $epc_ids ) )
1083 {
1084 foreach ($epc_ids as $epc_id)
1085 {
1086 $attributes = array('target' => '_blank');
1087 if ( wp_attachment_is_image($epc_id) )
1088 {
1089 $attributes = array('data-fancybox' => 'epcs');
1090 }
1091 $actions[] = array(
1092 'href' => wp_get_attachment_url( $epc_id ),
1093 'label' => __( 'View EPC', 'propertyhive' ),
1094 'class' => 'action-epc',
1095 'attributes' => $attributes
1096 );
1097 }
1098 }
1099 }
1100
1101 $actions = apply_filters( 'propertyhive_single_property_epcs_actions', $actions );
1102
1103 return $actions;
1104 }
1105
1106 }
1107
1108 if ( ! function_exists( 'propertyhive_get_template_single_virtual_tours_action' ) ) {
1109
1110 function propertyhive_get_template_single_virtual_tours_action() {
1111
1112 global $post, $property;
1113
1114 $actions = array();
1115
1116 $virtual_tours = $property->get_virtual_tours();
1117 if ( !empty( $virtual_tours ) )
1118 {
1119 foreach ($virtual_tours as $virtual_tour)
1120 {
1121 $attributes = array('target' => '_blank');
1122 if ( strpos($virtual_tour['url'], 'yout') !== FALSE || strpos($virtual_tour['url'], 'vimeo') !== FALSE )
1123 {
1124 $attributes['data-fancybox'] = '';
1125 }
1126
1127 $actions[] = array(
1128 'href' => $virtual_tour['url'],
1129 'label' => __( $virtual_tour['label'], 'propertyhive' ),
1130 'class' => 'action-virtual-tour',
1131 'attributes' => $attributes,
1132 );
1133 }
1134 }
1135
1136 $actions = apply_filters( 'propertyhive_single_property_virtual_tours_actions', $actions );
1137
1138 return $actions;
1139 }
1140
1141 }
1142
1143 if ( ! function_exists( 'propertyhive_get_template_single_material_information_action' ) ) {
1144
1145 function propertyhive_get_template_single_material_information_action() {
1146
1147 global $post, $property;
1148
1149 $actions = array();
1150
1151 $material_information = $property->get_material_information();
1152
1153 // Only show if at least one bit of material information has been completed
1154 if ( empty($material_information) )
1155 {
1156 return $actions;
1157 }
1158
1159 $actions[] = array(
1160 'href' => 'javascript:;',
1161 'label' => __( 'Utilities & More', 'propertyhive' ),
1162 'class' => 'action-material-information',
1163 'attributes' => array(
1164 'data-fancybox' => '',
1165 'data-src' => '#ph_material_information'
1166 ),
1167 );
1168
1169 echo '<div id="ph_material_information" style="display:none;">';
1170
1171 ph_get_template( 'single-property/material-information.php' );
1172
1173 echo '</div>';
1174
1175 $actions = apply_filters( 'propertyhive_single_property_material_information_actions', $actions );
1176
1177 return $actions;
1178 }
1179
1180 }
1181
1182 if ( ! function_exists( 'propertyhive_get_template_single_actions' ) ) {
1183
1184 function propertyhive_get_template_single_actions() {
1185
1186 global $post, $property;
1187
1188 $actions = array_merge(
1189 propertyhive_get_template_single_floorplans_action(),
1190 propertyhive_get_template_single_brochures_action(),
1191 propertyhive_get_template_single_epcs_action(),
1192 propertyhive_get_template_single_virtual_tours_action(),
1193 propertyhive_get_template_single_material_information_action(),
1194 );
1195
1196
1197 $actions = apply_filters( 'propertyhive_single_property_actions', $actions );
1198
1199 return $actions;
1200 }
1201
1202 }
1203
1204 if ( ! function_exists( 'propertyhive_template_single_actions' ) ) {
1205
1206 /**
1207 * Output the product actions (make enquiry etc)
1208 *
1209 * @access public
1210 * @subpackage Property
1211 * @return void
1212 */
1213 function propertyhive_template_single_actions() {
1214
1215 global $post, $property;
1216
1217 $actions = propertyhive_get_template_single_actions();
1218
1219 ph_get_template( 'single-property/actions.php', array( 'actions' => $actions ) );
1220 }
1221 }
1222
1223 if ( ! function_exists( 'propertyhive_template_single_features' ) ) {
1224
1225 /**
1226 * Output the property features.
1227 *
1228 * @access public
1229 * @subpackage Property
1230 * @return void
1231 */
1232 function propertyhive_template_single_features() {
1233 ph_get_template( 'single-property/features.php' );
1234 }
1235 }
1236
1237 if ( ! function_exists( 'propertyhive_template_single_summary' ) ) {
1238
1239 /**
1240 * Output the product summary description.
1241 *
1242 * @access public
1243 * @subpackage Property
1244 * @return void
1245 */
1246 function propertyhive_template_single_summary() {
1247 ph_get_template( 'single-property/summary-description.php' );
1248 }
1249 }
1250
1251
1252 if ( ! function_exists( 'propertyhive_template_single_description' ) ) {
1253
1254 /**
1255 * Output the product rooms or descriptions to form a full description
1256 *
1257 * @access public
1258 * @subpackage Property
1259 * @return void
1260 */
1261 function propertyhive_template_single_description() {
1262 ph_get_template( 'single-property/description.php' );
1263 }
1264 }
1265
1266 if ( ! function_exists( 'propertyhive_make_enquiry_button' ) ) {
1267
1268 /**
1269 * Output the make enquiry button and lightbox
1270 *
1271 * @access public
1272 * @subpackage Property
1273 * @return void
1274 */
1275 function propertyhive_make_enquiry_button() {
1276 ph_get_template( 'global/make-enquiry.php' );
1277 }
1278 }
1279
1280 function propertyhive_my_account_pages()
1281 {
1282 $user_id = get_current_user_id();
1283
1284 $contact = new PH_Contact( '', $user_id );
1285
1286 $pages = array(
1287 'dashboard' => array(
1288 'name' => __( 'Dashboard', 'propertyhive' )
1289 ),
1290 'details' => array(
1291 'name' => __( 'My Details', 'propertyhive' )
1292 ),
1293 );
1294
1295 // Add 'requirements' tab if applicant
1296
1297 if ( !empty($contact->contact_types) )
1298 {
1299 $contact_types = $contact->contact_types;
1300 if ( !is_array($contact_types) )
1301 {
1302 $contact_types = array($contact_types);
1303 }
1304 if ( in_array('applicant', $contact_types) )
1305 {
1306 $applicant_profiles = $contact->applicant_profiles;
1307
1308 $buy_rent = array();
1309
1310 if ( $applicant_profiles && $applicant_profiles > 0 )
1311 {
1312 for ( $i = 0; $i < $applicant_profiles; ++$i )
1313 {
1314 $pages['requirements'] = array(
1315 'name' => __( 'Requirements', 'propertyhive' ),
1316 );
1317
1318 $applicant_profile = $contact->{'applicant_profile_' . $i};
1319
1320 if ( isset($applicant_profile['department']) && $applicant_profile['department'] == 'residential-sales' )
1321 {
1322 $buy_rent[] = 'To Buy';
1323 }
1324 if ( isset($applicant_profile['department']) && $applicant_profile['department'] == 'residential-lettings' )
1325 {
1326 $buy_rent[] = 'To Rent';
1327 }
1328 }
1329 }
1330
1331 $buy_rent = array_unique($buy_rent);
1332
1333 // Check viewing module is active and that viewings exist, either future or past
1334 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
1335 {
1336 $args = array(
1337 'post_type' => 'viewing',
1338 'posts_per_page' => 1,
1339 'post_status' => 'publish',
1340 'fields' => 'ids',
1341 'meta_query' => array(
1342 array(
1343 'key' => '_applicant_contact_id',
1344 'value' => $contact->id
1345 )
1346 )
1347 );
1348 $viewings_query = new WP_Query( $args );
1349
1350 if ( $viewings_query->have_posts() )
1351 {
1352 $pages['applicant_viewings'] = array(
1353 'name' => __( 'Viewings', 'propertyhive' ) . ( !empty($buy_rent) ? ' ' . implode('/', $buy_rent) : '' ),
1354 );
1355 }
1356 wp_reset_postdata();
1357 }
1358 }
1359 if ( in_array('owner', $contact_types) )
1360 {
1361 $sell_let = array();
1362
1363 // Get properties belonging to this owner
1364 $args = array(
1365 'post_type' => 'property',
1366 'nopaging' => true,
1367 'post_status' => 'publish',
1368 'fields' => 'ids',
1369 'meta_query' => array(
1370 'relation' => 'OR',
1371 array(
1372 'key' => '_owner_contact_id',
1373 'value' => ':' . $contact->id . ';',
1374 'compare' => 'LIKE'
1375 ),
1376 array(
1377 'key' => '_owner_contact_id',
1378 'value' => ':"' . $contact->id . '";',
1379 'compare' => 'LIKE'
1380 )
1381 )
1382 );
1383
1384 $properties_query = new WP_Query( $args );
1385
1386 $property_ids = array();
1387
1388 if ( $properties_query->have_posts() )
1389 {
1390 while ( $properties_query->have_posts() )
1391 {
1392 $properties_query->the_post();
1393
1394 $property_ids[] = get_the_ID();
1395
1396 if ( get_post_meta( get_the_ID(), '_department', TRUE ) == 'residential-sales' )
1397 {
1398 $sell_let[] = 'To Sell';
1399 }
1400 if ( get_post_meta( get_the_ID(), '_department', TRUE ) == 'residential-lettings' )
1401 {
1402 $sell_let[] = 'To Let';
1403 }
1404 }
1405
1406 $pages['owner_properties'] = array(
1407 'name' => __( 'Properties', 'propertyhive' ),
1408 );
1409 }
1410 wp_reset_postdata();
1411
1412 $sell_let = array_unique($sell_let);
1413
1414 // Check viewing module is active and that viewings exist, either future or past
1415 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
1416 {
1417 $past_viewings = array();
1418 $upcoming_viewings = array();
1419
1420 if ( !empty($property_ids) )
1421 {
1422 $args = array(
1423 'post_type' => 'viewing',
1424 'posts_per_page' => 1,
1425 'post_status' => 'publish',
1426 'fields' => 'ids',
1427 'meta_query' => array(
1428 array(
1429 'key' => '_property_id',
1430 'value' => $property_ids,
1431 'compare' => 'IN'
1432 )
1433 )
1434 );
1435 $viewings_query = new WP_Query( $args );
1436
1437 if ( $viewings_query->have_posts() )
1438 {
1439 $pages['owner_viewings'] = array(
1440 'name' => __( 'Viewings', 'propertyhive' ) . ( !empty($sell_let) ? ' ' . implode('/', $sell_let) : '' ),
1441 );
1442 }
1443 wp_reset_postdata();
1444 }
1445 }
1446 }
1447 }
1448
1449 $pages = apply_filters( 'propertyhive_my_account_pages', $pages );
1450
1451 /*$pages['delete'] = array(
1452 'name' => __( 'Delete Account', 'propertyhive' )
1453 );*/
1454
1455 $pages['logout'] = array(
1456 'name' => __( 'Logout', 'propertyhive' ),
1457 'href' => home_url() . '?logout=1' // Logout URL
1458 );
1459
1460 return $pages;
1461 }
1462
1463 if ( ! function_exists( 'propertyhive_my_account_navigation' ) ) {
1464
1465 /**
1466 * Output the navigation/tabs within a users 'My Account' page
1467 *
1468 * @access public
1469 * @return void
1470 */
1471 function propertyhive_my_account_navigation() {
1472
1473 $pages = propertyhive_my_account_pages();
1474
1475 ph_get_template( 'account/navigation.php', array( 'pages' => $pages ) );
1476 }
1477 }
1478
1479 if ( ! function_exists( 'propertyhive_my_account_sections' ) ) {
1480
1481 /**
1482 * Output the main sections within a users 'My Account' page that relate to the navigation tabs/links
1483 *
1484 * @access public
1485 * @return void
1486 */
1487 function propertyhive_my_account_sections() {
1488
1489 $pages = propertyhive_my_account_pages();
1490
1491 ph_get_template( 'account/sections.php', array( 'pages' => $pages ) );
1492 }
1493 }
1494
1495 if ( ! function_exists( 'propertyhive_my_account_dashboard' ) ) {
1496
1497 /**
1498 * Output the dashboard section within a users account
1499 *
1500 * @access public
1501 * @return void
1502 */
1503 function propertyhive_my_account_dashboard() {
1504
1505 ph_get_template( 'account/dashboard.php' );
1506 }
1507 }
1508
1509 if ( ! function_exists( 'propertyhive_my_account_details' ) ) {
1510
1511 /**
1512 * Output the details section within a users account
1513 *
1514 * @access public
1515 * @return void
1516 */
1517 function propertyhive_my_account_details() {
1518
1519 $form_controls = ph_get_user_details_form_fields();
1520
1521 $form_controls = apply_filters( 'propertyhive_user_details_form_fields', $form_controls );
1522
1523 // Make sure password fields aren't require
1524 foreach ( $form_controls as $i => $form_control )
1525 {
1526 if ( $form_control['type'] == 'password' )
1527 {
1528 $form_control['required'] = false;
1529
1530 $form_controls[$i] = $form_control;
1531 }
1532 }
1533
1534 ph_get_template( 'account/details.php', array( 'form_controls' => $form_controls ) );
1535 }
1536 }
1537
1538 if ( ! function_exists( 'propertyhive_my_account_requirements' ) ) {
1539
1540 /**
1541 * Output the requirements section within a users account
1542 *
1543 * @access public
1544 * @return void
1545 */
1546 function propertyhive_my_account_requirements() {
1547
1548 $user_id = get_current_user_id();
1549
1550 $contact = new PH_Contact( '', $user_id );
1551
1552 if ( is_array($contact->contact_types) && in_array('applicant', $contact->contact_types) )
1553 {
1554 $applicant_profiles = $contact->applicant_profiles;
1555
1556 for ( $i = 0; $i < $applicant_profiles; ++$i )
1557 {
1558 $form_controls = ph_get_applicant_requirements_form_fields($contact->{'applicant_profile_' . $i});
1559
1560 $form_controls = apply_filters( 'propertyhive_applicant_requirements_form_fields', $form_controls, $contact->{'applicant_profile_' . $i} );
1561
1562 $form_controls['profile_id'] = array(
1563 'type' => 'hidden',
1564 'value' => $i,
1565 );
1566
1567 // Remove office as this is only required on initial sign up (at the moment anyway)
1568 if ( isset($form_controls['office_id']) )
1569 {
1570 unset($form_controls['office_id']);
1571 }
1572
1573 ph_get_template( 'account/requirements.php', array( 'form_controls' => $form_controls ) );
1574 }
1575 }
1576 }
1577 }
1578
1579 if ( ! function_exists( 'propertyhive_my_account_applicant_viewings' ) ) {
1580
1581 /**
1582 * Output the applicant viewings section within a users account
1583 *
1584 * @access public
1585 * @return void
1586 */
1587 function propertyhive_my_account_applicant_viewings() {
1588
1589 $user_id = get_current_user_id();
1590
1591 $contact = new PH_Contact( '', $user_id );
1592
1593 $past_viewings = array();
1594 $upcoming_viewings = array();
1595
1596 $args = array(
1597 'post_type' => 'viewing',
1598 'nopaging' => 'true',
1599 'post_status' => 'publish',
1600 'fields' => 'ids',
1601 'orderby' => 'meta_value',
1602 'order' => 'DESC',
1603 'post_status' => 'publish',
1604 'meta_key' => '_start_date_time',
1605 'meta_query' => array(
1606 array(
1607 'key' => '_applicant_contact_id',
1608 'value' => $contact->id
1609 )
1610 )
1611 );
1612
1613 // Do past viewings
1614 $args2 = $args;
1615 $args2['meta_query'][] = array(
1616 'key' => '_start_date_time',
1617 'value' => date("Y-m-d H:i:s"),
1618 'compare' => '<='
1619 );
1620
1621 $viewings_query = new WP_Query( $args2 );
1622
1623 if ( $viewings_query->have_posts() )
1624 {
1625 while ( $viewings_query->have_posts() )
1626 {
1627 $viewings_query->the_post();
1628
1629 $viewing = new PH_Viewing( get_the_ID() );
1630
1631 $past_viewings[] = $viewing;
1632 }
1633 }
1634 wp_reset_postdata();
1635
1636 // Do upcoming viewings
1637 $args2 = $args;
1638 $args2['meta_query'][] = array(
1639 'key' => '_start_date_time',
1640 'value' => date("Y-m-d H:i:s"),
1641 'compare' => '>='
1642 );
1643
1644 $viewings_query = new WP_Query( $args2 );
1645
1646 if ( $viewings_query->have_posts() )
1647 {
1648 while ( $viewings_query->have_posts() )
1649 {
1650 $viewings_query->the_post();
1651
1652 $viewing = new PH_Viewing( get_the_ID() );
1653
1654 $upcoming_viewings[] = $viewing;
1655 }
1656 }
1657 wp_reset_postdata();
1658
1659 ph_get_template( 'account/applicant-viewings.php', array( 'past_viewings' => $past_viewings, 'upcoming_viewings' => $upcoming_viewings ) );
1660 }
1661 }
1662
1663 if ( ! function_exists( 'propertyhive_my_account_owner_properties' ) ) {
1664
1665 /**
1666 * Output the owner properties section within a users account
1667 *
1668 * @access public
1669 * @return void
1670 */
1671 function propertyhive_my_account_owner_properties() {
1672
1673 $user_id = get_current_user_id();
1674
1675 $contact = new PH_Contact( '', $user_id );
1676
1677 // Get properties belonging to this owner
1678 $args = array(
1679 'post_type' => 'property',
1680 'nopaging' => true,
1681 'post_status' => 'publish',
1682 'fields' => 'ids',
1683 'meta_query' => array(
1684 'relation' => 'OR',
1685 array(
1686 'key' => '_owner_contact_id',
1687 'value' => ':' . $contact->id . ';',
1688 'compare' => 'LIKE'
1689 ),
1690 array(
1691 'key' => '_owner_contact_id',
1692 'value' => ':"' . $contact->id . '";',
1693 'compare' => 'LIKE'
1694 )
1695 )
1696 );
1697
1698 $properties_query = new WP_Query( $args );
1699
1700 $properties = array();
1701
1702 if ( $properties_query->have_posts() )
1703 {
1704 while ( $properties_query->have_posts() )
1705 {
1706 $properties_query->the_post();
1707
1708 $properties[] = new PH_Property( get_the_id() );
1709 }
1710 }
1711 wp_reset_postdata();
1712 ph_get_template( 'account/owner-properties.php', array( 'properties' => $properties ) );
1713 }
1714 }
1715
1716 if ( ! function_exists( 'propertyhive_my_account_owner_viewings' ) ) {
1717
1718 /**
1719 * Output the owner viewings section within a users account
1720 *
1721 * @access public
1722 * @return void
1723 */
1724 function propertyhive_my_account_owner_viewings() {
1725
1726 $user_id = get_current_user_id();
1727
1728 $contact = new PH_Contact( '', $user_id );
1729
1730 // Get properties belonging to this owner
1731 $args = array(
1732 'post_type' => 'property',
1733 'nopaging' => true,
1734 'post_status' => 'publish',
1735 'fields' => 'ids',
1736 'meta_query' => array(
1737 'relation' => 'OR',
1738 array(
1739 'key' => '_owner_contact_id',
1740 'value' => ':' . $contact->id . ';',
1741 'compare' => 'LIKE'
1742 ),
1743 array(
1744 'key' => '_owner_contact_id',
1745 'value' => ':"' . $contact->id . '";',
1746 'compare' => 'LIKE'
1747 )
1748 )
1749 );
1750
1751 $properties_query = new WP_Query( $args );
1752
1753 $property_ids = array();
1754
1755 if ( $properties_query->have_posts() )
1756 {
1757 while ( $properties_query->have_posts() )
1758 {
1759 $properties_query->the_post();
1760
1761 $property_ids[] = get_the_id();
1762 }
1763 }
1764 wp_reset_postdata();
1765
1766 $past_viewings = array();
1767 $upcoming_viewings = array();
1768
1769 if ( !empty($property_ids) )
1770 {
1771 $args = array(
1772 'post_type' => 'viewing',
1773 'nopaging' => true,
1774 'post_status' => 'publish',
1775 'fields' => 'ids',
1776 'orderby' => 'meta_value',
1777 'order' => 'DESC',
1778 'post_status' => 'publish',
1779 'meta_key' => '_start_date_time',
1780 'meta_query' => array(
1781 array(
1782 'key' => '_property_id',
1783 'value' => $property_ids,
1784 'compare' => 'IN'
1785 )
1786 )
1787 );
1788
1789 // Do past viewings
1790 $args2 = $args;
1791 $args2['meta_query'][] = array(
1792 'key' => '_start_date_time',
1793 'value' => date("Y-m-d H:i:s"),
1794 'compare' => '<='
1795 );
1796
1797 $viewings_query = new WP_Query( $args2 );
1798
1799 if ( $viewings_query->have_posts() )
1800 {
1801 while ( $viewings_query->have_posts() )
1802 {
1803 $viewings_query->the_post();
1804
1805 $viewing = new PH_Viewing( get_the_ID() );
1806
1807 $past_viewings[] = $viewing;
1808 }
1809 }
1810 wp_reset_postdata();
1811
1812 // Do upcoming viewings
1813 $args2 = $args;
1814 $args2['meta_query'][] = array(
1815 'key' => '_start_date_time',
1816 'value' => date("Y-m-d H:i:s"),
1817 'compare' => '>='
1818 );
1819
1820 $viewings_query = new WP_Query( $args2 );
1821
1822 if ( $viewings_query->have_posts() )
1823 {
1824 while ( $viewings_query->have_posts() )
1825 {
1826 $viewings_query->the_post();
1827
1828 $viewing = new PH_Viewing( get_the_ID() );
1829
1830 $upcoming_viewings[] = $viewing;
1831 }
1832 }
1833 wp_reset_postdata();
1834 }
1835
1836 ph_get_template( 'account/owner-viewings.php', array( 'past_viewings' => $past_viewings, 'upcoming_viewings' => $upcoming_viewings ) );
1837 }
1838 }
1839
1840 if ( ! function_exists( 'propertyhive_my_account_delete' ) ) {
1841
1842 /**
1843 * Output the delete section within a users account
1844 *
1845 * @access public
1846 * @return void
1847 */
1848 function propertyhive_my_account_delete() {
1849
1850 ph_get_template( 'account/delete.php' );
1851 }
1852 }
1853
1854 add_filter( 'loop_search_results_per_page', 'template_assistant_loop_search_results_per_page', 1 );
1855 function template_assistant_loop_search_results_per_page( $cols )
1856 {
1857 $current_settings = get_option( 'propertyhive_template_assistant', array() );
1858
1859 if ( isset($current_settings['search_result_columns']) && in_array($current_settings['search_result_columns'], array(3,4)) )
1860 {
1861 return 12;
1862 }
1863
1864 return $cols;
1865 }
1866
1867 add_filter( 'loop_search_results_columns', 'template_assistant_search_result_columns', 1 );
1868 function template_assistant_search_result_columns( $cols = 1 )
1869 {
1870 $current_settings = get_option( 'propertyhive_template_assistant', array() );
1871
1872 if ( isset($current_settings['search_result_columns']) && in_array($current_settings['search_result_columns'], array(1,2,3,4)) )
1873 {
1874 return $current_settings['search_result_columns'];
1875 }
1876
1877 return 1;
1878 }
1879
1880 add_filter( 'post_class', 'template_assistant_property_columns_post_class', 20, 3 );
1881 function template_assistant_property_columns_post_class( $classes, $class = '', $post_id = '' )
1882 {
1883 if ( ! $post_id || get_post_type( $post_id ) !== 'property' )
1884 return $classes;
1885
1886 $current_settings = get_option( 'propertyhive_template_assistant', array() );
1887
1888 if ( isset($current_settings['search_result_columns']) && in_array($current_settings['search_result_columns'], array(2,3,4)) )
1889 {
1890 $property = get_property( $post_id );
1891
1892 if ( $property )
1893 {
1894 $classes[] = 'ph-cols-' . $current_settings['search_result_columns'];
1895
1896 if ( ($key = array_search('clear', $classes)) !== false )
1897 {
1898 unset($classes[$key]);
1899 }
1900 }
1901 }
1902
1903 return $classes;
1904 }
1905
1906 add_action( 'wp_head', 'load_template_assistant_styles' );
1907 function load_template_assistant_styles()
1908 {
1909 $current_settings = get_option( 'propertyhive_template_assistant', array() );
1910
1911 if (
1912 is_post_type_archive('property')
1913 ||
1914 ( isset($current_settings['search_result_css_all_pages']) && $current_settings['search_result_css_all_pages'] == 'yes' )
1915 )
1916 {
1917 if ( isset($current_settings['search_result_css']) )
1918 {
1919 echo '<style type="text/css">
1920 ' . $current_settings['search_result_css'] . '
1921 </style>';
1922 }
1923 }
1924 }
1925
1926 add_filter( 'propertyhive_default_search_results_orderby', 'template_assistant_change_default_order' );
1927 function template_assistant_change_default_order( $orderby )
1928 {
1929 $current_settings = get_option( 'propertyhive_template_assistant', array() );
1930
1931 if ( isset($current_settings['search_result_default_order']) && $current_settings['search_result_default_order'] != '' )
1932 {
1933 return $current_settings['search_result_default_order'];
1934 }
1935
1936 return $orderby;
1937 }
1938
1939 add_filter( 'property_search_results_thumbnail_size', 'template_assistant_search_result_image_size_changes' );
1940 function template_assistant_search_result_image_size_changes( $image_size )
1941 {
1942 $current_settings = get_option( 'propertyhive_template_assistant', array() );
1943
1944 if ( isset($current_settings['search_result_image_size']) && $current_settings['search_result_image_size'] != '' )
1945 {
1946 $image_size = $current_settings['search_result_image_size'];
1947 }
1948
1949 return $image_size;
1950 }
1951
1952 add_action( 'wp', 'template_assistant_search_result_field_changes' );
1953 function template_assistant_search_result_field_changes()
1954 {
1955 $current_settings = get_option( 'propertyhive_template_assistant', array() );
1956
1957 if ( isset($current_settings['search_result_fields']) && is_array($current_settings['search_result_fields']) && !empty($current_settings['search_result_fields']) )
1958 {
1959 remove_action( 'propertyhive_after_search_results_loop_item_title', 'propertyhive_template_loop_floor_area', 5 );
1960 remove_action( 'propertyhive_after_search_results_loop_item_title', 'propertyhive_template_loop_price', 10 );
1961 remove_action( 'propertyhive_after_search_results_loop_item_title', 'propertyhive_template_loop_summary', 20 );
1962 remove_action( 'propertyhive_after_search_results_loop_item_title', 'propertyhive_template_loop_actions', 30 );
1963
1964 $priority = 5;
1965 foreach ( $current_settings['search_result_fields'] as $search_result_field )
1966 {
1967 if ( substr($search_result_field, 0, 12) == 'custom_field' )
1968 {
1969 // custom field output here
1970 $custom_field = substr($search_result_field, 12);
1971
1972 add_action( 'propertyhive_after_search_results_loop_item_title', 'propertyhive_template_loop_custom_field', $priority );
1973
1974 $priority += 5;
1975 continue;
1976 }
1977
1978 switch ( $search_result_field )
1979 {
1980 case "price":
1981 case "floor_area":
1982 case "summary":
1983 case "actions":
1984 {
1985 add_action( 'propertyhive_after_search_results_loop_item_title', 'propertyhive_template_loop_' . $search_result_field, $priority );
1986 break;
1987 }
1988 case "availability":
1989 {
1990 add_action( 'propertyhive_after_search_results_loop_item_title', function() { global $property; echo '<div class="availability">' . $property->availability . '</div>'; }, $priority );
1991 break;
1992 }
1993 case "property_type":
1994 {
1995 add_action( 'propertyhive_after_search_results_loop_item_title', function() { global $property; echo '<div class="property-type">' . $property->property_type . '</div>'; }, $priority );
1996 break;
1997 }
1998 case "available_date":
1999 {
2000 add_action( 'propertyhive_after_search_results_loop_item_title', function() { global $property; if ( $property->department == 'residential-lettings' && $property->get_available_date() != '' ) { echo '<div class="available-date">' . $property->get_available_date() . '</div>'; } }, $priority );
2001 break;
2002 }
2003 case "rooms":
2004 {
2005 add_action( 'propertyhive_after_search_results_loop_item_title', function() {
2006 global $property;
2007
2008 if ( ($property->bedrooms != '' && $property->bedrooms != '0') || ($property->bathrooms != '' && $property->bathrooms != '0') || ($property->reception_rooms != '' && $property->reception_rooms != '0') )
2009 {
2010 echo '<div class="rooms">';
2011 if ( $property->bedrooms != '' && $property->bedrooms != '0' ) { echo '<div class="room room-bedrooms"><span class="room-count">' . $property->bedrooms . '</span> <span class="room-label">Bedroom' . ( $property->bedrooms != 1 ? 's' : '' ) . '</span></div>'; }
2012 if ( $property->bathrooms != '' && $property->bathrooms != '0' ) { echo '<div class="room room-bathrooms"><span class="room-count">' . $property->bathrooms . '</span> <span class="room-label">Bathroom' . ( $property->bathrooms != 1 ? 's' : '' ) . '</span></div>'; }
2013 if ( $property->reception_rooms != '' && $property->reception_rooms != '0' ) { echo '<div class="room room-receptions"><span class="room-count">' . $property->reception_rooms . '</span> <span class="room-label">Reception' . ( $property->reception_rooms != 1 ? 's' : '' ) . '</span></div>'; }
2014 echo '</div>';
2015 }
2016 }, $priority );
2017 break;
2018 }
2019 default:
2020 {
2021 echo 'unknown search result field requested';
2022 }
2023 }
2024
2025 $priority += 5;
2026 }
2027 }
2028 }
2029
2030 function propertyhive_template_loop_custom_field()
2031 {
2032 global $property;
2033
2034 $current_settings = get_option( 'propertyhive_template_assistant', array() );
2035
2036 foreach ( $current_settings['search_result_fields'] as $search_result_field )
2037 {
2038 if ( substr($search_result_field, 0, 12) == 'custom_field' )
2039 {
2040 // custom field output here
2041 $custom_field = substr($search_result_field, 12);
2042
2043 $value = $property->{$custom_field};
2044 $value = is_array($value) ? implode(", ", $value) : $value;
2045
2046 if ( $value != '' )
2047 {
2048 echo '<div class="custom-field custom-field-' . sanitize_title(trim($custom_field, "_")) . '">' . $value . '</div>';
2049 }
2050 }
2051 }
2052 }
2053
2054 add_action( 'propertyhive_before_search_results_loop_item_title', 'propertyhive_add_flag' );
2055 function propertyhive_add_flag()
2056 {
2057 global $property;
2058
2059 $current_settings = get_option( 'propertyhive_template_assistant', array() );
2060
2061 if ( isset($current_settings['flags_active']) && $current_settings['flags_active'] == '1' )
2062 {
2063 $flag = propertyhive_get_flag();
2064
2065 if ( $flag != '' )
2066 {
2067 echo '<div class="flag flag-' . sanitize_title($flag) . '" style="position:absolute; text-transform:uppercase; font-size:13px; box-sizing:border-box; padding:7px 20px; ' . $current_settings['flag_position'] . '; color:' . $current_settings['flag_text_color'] . '; background:' . $current_settings['flag_bg_color'] . ';">' . $flag . '</div>';
2068 }
2069 }
2070 }
2071
2072 add_action( 'propertyhive_before_single_property_images', 'propertyhive_add_flag_single', 5 );
2073 function propertyhive_add_flag_single()
2074 {
2075 global $property;
2076
2077 $current_settings = get_option( 'propertyhive_template_assistant', array() );
2078
2079 if ( isset($current_settings['flags_active_single']) && $current_settings['flags_active_single'] == '1' )
2080 {
2081 $flag = propertyhive_get_flag();
2082
2083 if ( $flag != '' )
2084 {
2085 echo '<div class="flag flag-' . sanitize_title($flag) . '" style="position:absolute; z-index:99; text-transform:uppercase; font-size:13px; box-sizing:border-box; padding:7px 20px; ' . $current_settings['flag_position'] . '; color:' . $current_settings['flag_text_color'] . '; background:' . $current_settings['flag_bg_color'] . ';">' . $flag . '</div>';
2086 }
2087 }
2088 }
2089
2090 function propertyhive_get_flag()
2091 {
2092 global $property;
2093
2094 $flag = $property->availability;
2095
2096 if ( $property->marketing_flag != '' )
2097 {
2098 $flag = $property->marketing_flag;
2099 }
2100
2101 $flag = apply_filters( 'propertyhive_template_assistant_flag', $flag );
2102
2103 return $flag;
2104 }
2105
2106
2107
2108