PluginProbe
Property Hive / 1.4.53
Property Hive v1.4.53
2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 1.4.62 All 260 releases
propertyhive / includes / ph-template-functions.php

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

1,485 lines 42.5 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="' . __( 'Latest Properties', 'propertyhive' ) . '" href="' . esc_attr( $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 $classes = (array) $classes;
79
80 if ( is_propertyhive() ) {
81 $classes[] = 'propertyhive';
82 $classes[] = 'propertyhive-page';
83 }
84
85 return array_unique( $classes );
86 }
87
88 /**
89 * Adds extra post classes for properties
90 *
91 * @since 1.0.0
92 * @param array $classes
93 * @param string|array $class
94 * @param int $post_id
95 * @return array
96 */
97 function ph_property_post_class( $classes, $class = '', $post_id = '' ) {
98 if ( ! $post_id || get_post_type( $post_id ) !== 'property' )
99 return $classes;
100
101 $property = get_property( $post_id );
102
103 if ( $property ) {
104 if ( $property->is_featured() ) {
105 $classes[] = 'featured';
106 }
107 }
108
109 if ( ( $key = array_search( 'hentry', $classes ) ) !== false ) {
110 unset( $classes[ $key ] );
111 }
112
113 // Add 'property' class, removing it first incase it exists
114 // Needed as results loaded with AJAX don't get the property class by default
115 if ( ( $key = array_search( 'property', $classes ) ) !== false ) {
116 unset( $classes[ $key ] );
117 }
118 $classes[] = 'property';
119 $classes[] = 'department-' . $property->department;
120
121 return $classes;
122 }
123
124 /** Global ****************************************************************/
125
126 if ( ! function_exists( 'propertyhive_output_content_wrapper' ) ) {
127
128 /**
129 * Output the start of the page wrapper.
130 *
131 * @access public
132 * @return void
133 */
134 function propertyhive_output_content_wrapper() {
135 ph_get_template( 'global/wrapper-start.php' );
136 }
137 }
138
139 if ( ! function_exists( 'propertyhive_output_content_wrapper_end' ) ) {
140
141 /**
142 * Output the end of the page wrapper.
143 *
144 * @access public
145 * @return void
146 */
147 function propertyhive_output_content_wrapper_end() {
148 ph_get_template( 'global/wrapper-end.php' );
149 }
150 }
151
152 /** Loop ******************************************************************/
153
154 if ( ! function_exists( 'propertyhive_page_title' ) ) {
155
156 /**
157 * propertyhive_page_title function.
158 *
159 * @param boolean $echo
160 * @return string
161 */
162 function propertyhive_page_title( $echo = true ) {
163
164 if ( is_search() ) {
165 $page_title = sprintf( __( 'Search Results: &ldquo;%s&rdquo;', 'propertyhive' ), get_search_query() );
166
167 if ( get_query_var( 'paged' ) )
168 $page_title .= sprintf( __( '&nbsp;&ndash; Page %s', 'propertyhive' ), get_query_var( 'paged' ) );
169
170 } elseif ( is_tax() ) {
171
172 $page_title = single_term_title( "", false );
173
174 } else {
175
176 $search_results_page_id = ph_get_page_id( 'search_results' );
177 $page_title = get_the_title( $search_results_page_id );
178
179 }
180
181 $page_title = apply_filters( 'propertyhive_page_title', $page_title );
182
183 if ( $echo )
184 echo $page_title;
185 else
186 return $page_title;
187 }
188 }
189
190 if ( ! function_exists( 'propertyhive_property_loop_start' ) ) {
191
192 /**
193 * Output the start of a property loop. By default this is a UL
194 *
195 * @access public
196 * @param bool $echo
197 * @return string
198 */
199 function propertyhive_property_loop_start( $echo = true ) {
200 ob_start();
201 ph_get_template( 'search/loop-start.php' );
202 if ( $echo )
203 echo ob_get_clean();
204 else
205 return ob_get_clean();
206 }
207 }
208 if ( ! function_exists( 'propertyhive_property_loop_end' ) ) {
209
210 /**
211 * Output the end of a property loop. By default this is a UL
212 *
213 * @access public
214 * @param bool $echo
215 * @return string
216 */
217 function propertyhive_property_loop_end( $echo = true ) {
218 ob_start();
219
220 ph_get_template( 'search/loop-end.php' );
221
222 if ( $echo )
223 echo ob_get_clean();
224 else
225 return ob_get_clean();
226 }
227 }
228
229 if ( ! function_exists( 'propertyhive_template_loop_property_thumbnail' ) ) {
230
231 /**
232 * Get the property thumbnail for the loop.
233 *
234 * @access public
235 * @subpackage Loop
236 * @return void
237 */
238 function propertyhive_template_loop_property_thumbnail() {
239 echo propertyhive_get_property_thumbnail();
240 }
241 }
242
243 if ( ! function_exists( 'propertyhive_get_property_thumbnail' ) ) {
244
245 /**
246 * Get the property thumbnail, or the placeholder if not set.
247 *
248 * @access public
249 * @subpackage Loop
250 * @param string $size (default: 'medium')
251 * @param int $placeholder_width (default: 0)
252 * @param int $placeholder_height (default: 0)
253 * @return string
254 */
255 function propertyhive_get_property_thumbnail( $size = 'medium', $class = '', $placeholder_width = 0, $placeholder_height = 0 ) {
256 global $post, $property;
257
258 $photo_url = $property->get_main_photo_src( $size );
259
260 if ($photo_url !== FALSE)
261 return '<img src="' . $photo_url . '" alt="' . get_the_title($post->ID) . '" class="' . $class . '">';
262
263 if ( ph_placeholder_img_src() )
264 return ph_placeholder_img( $size );
265 }
266 }
267
268 if ( ! function_exists( 'propertyhive_template_loop_floor_area' ) ) {
269
270 /**
271 * Get the property floor area for the loop.
272 *
273 * @access public
274 * @subpackage Loop
275 * @return void
276 */
277 function propertyhive_template_loop_floor_area() {
278 ph_get_template( 'search/floor-area.php' );
279 }
280 }
281
282 if ( ! function_exists( 'propertyhive_template_loop_price' ) ) {
283
284 /**
285 * Get the property price for the loop.
286 *
287 * @access public
288 * @subpackage Loop
289 * @return void
290 */
291 function propertyhive_template_loop_price() {
292
293 global $property;
294
295 $fees = '';
296 if ( get_option('propertyhive_lettings_fees_display_search_results', '') == 'yes' )
297 {
298 if (
299 $property->department == 'residential-lettings' &&
300 get_option('propertyhive_lettings_fees', '') != ''
301 )
302 {
303 $fees = nl2br(get_option('propertyhive_lettings_fees', ''));
304 }
305 if (
306 $property->department == 'commercial' &&
307 $property->to_rent == 'yes' &&
308 get_option('propertyhive_lettings_fees_commercial', '') != ''
309 )
310 {
311 $fees = nl2br(get_option('propertyhive_lettings_fees_commercial', ''));
312 }
313 }
314
315
316 ph_get_template( 'search/price.php', array( 'fees' => $fees ) );
317 }
318 }
319
320 if ( ! function_exists( 'propertyhive_template_loop_summary' ) ) {
321
322 /**
323 * Get the property summary for the loop.
324 *
325 * @access public
326 * @subpackage Loop
327 * @return void
328 */
329 function propertyhive_template_loop_summary() {
330 ph_get_template( 'search/summary.php' );
331 }
332 }
333
334 if ( ! function_exists( 'propertyhive_template_loop_actions' ) ) {
335
336 /**
337 * Get the actions for the loop (ie More Details).
338 *
339 * @access public
340 * @subpackage Loop
341 * @return void
342 */
343 function propertyhive_template_loop_actions() {
344 ph_get_template( 'search/actions.php' );
345 }
346 }
347
348 if ( ! function_exists( 'propertyhive_search_form' ) ) {
349
350 /**
351 * Output the search form
352 *
353 * @access public
354 * @subpackage Loop
355 * @return void
356 */
357 function propertyhive_search_form($id = 'default') {
358 ph_get_search_form( ( $id != '' ) ? $id : 'default' );
359 }
360 }
361
362 if ( ! function_exists( 'propertyhive_result_count' ) ) {
363
364 /**
365 * Output the result count text (Showing x - x of x results).
366 *
367 * @access public
368 * @subpackage Loop
369 * @return void
370 */
371 function propertyhive_result_count() {
372 ph_get_template( 'search/result-count.php' );
373 }
374 }
375
376 if ( ! function_exists( 'propertyhive_catalog_ordering' ) ) {
377
378 /**
379 * Output the property sorting options.
380 *
381 * @access public
382 * @subpackage Loop
383 * @return void
384 */
385 function propertyhive_catalog_ordering() {
386 $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' ) );
387
388 ph_get_template( 'search/orderby.php', array( 'orderby' => $orderby ) );
389 }
390 }
391
392 if ( ! function_exists( 'propertyhive_pagination' ) ) {
393
394 /**
395 * Output the pagination.
396 *
397 * @access public
398 * @subpackage Loop
399 * @return void
400 */
401 function propertyhive_pagination() {
402 ph_get_template( 'search/pagination.php' );
403 }
404 }
405
406 /** Single Property ********************************************************/
407
408 if ( ! function_exists( 'propertyhive_template_not_on_market' ) ) {
409
410 /**
411 * Output a warning/message if property is not on the market
412 *
413 * @access public
414 * @subpackage Property
415 * @return void
416 */
417 function propertyhive_template_not_on_market() {
418 ph_get_template( 'single-property/not-on-market.php' );
419 }
420 }
421
422 if ( ! function_exists( 'propertyhive_show_property_images' ) ) {
423
424 /**
425 * Output the property image before the single property summary.
426 *
427 * @access public
428 * @subpackage Property
429 * @return void
430 */
431 function propertyhive_show_property_images()
432 {
433 global $property;
434
435 $images = array();
436 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
437 {
438 $photo_urls = $property->_photo_urls;
439 if ( !is_array($photo_urls) ) { $photo_urls = array(); }
440
441 foreach ( $photo_urls as $photo )
442 {
443 $images[] = array(
444 'title' => isset($photo['title']) ? $photo['title'] : '',
445 'url' => isset($photo['url']) ? $photo['url'] : '',
446 'image' => '<img src="' . ( isset($photo['url']) ? $photo['url'] : '' ) . '" alt="' . ( isset($photo['title']) ? $photo['title'] : '' ) . '">',
447 );
448 }
449 }
450 else
451 {
452 $gallery_attachments = $property->get_gallery_attachment_ids();
453
454 if ( !empty($gallery_attachments) )
455 {
456 foreach ($gallery_attachments as $gallery_attachment)
457 {
458 $images[] = array(
459 'title' => esc_attr( get_the_title( $gallery_attachment ) ),
460 'url' => wp_get_attachment_url( $gallery_attachment ),
461 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'original' ) ),
462 'attachment_id' => $gallery_attachment,
463 );
464 }
465 }
466 }
467
468 ph_get_template( 'single-property/property-images.php', array( 'images' => $images ) );
469 }
470 }
471
472 if ( ! function_exists( 'propertyhive_show_property_thumbnails' ) ) {
473
474 /**
475 * Output the property thumbnails.
476 *
477 * @access public
478 * @subpackage Property
479 * @return void
480 */
481 function propertyhive_show_property_thumbnails() {
482
483 global $property;
484
485 $images = array();
486 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
487 {
488 $photo_urls = $property->_photo_urls;
489 if ( !is_array($photo_urls) ) { $photo_urls = array(); }
490
491 foreach ( $photo_urls as $photo )
492 {
493 $images[] = array(
494 'title' => isset($photo['title']) ? $photo['title'] : '',
495 'url' => isset($photo['url']) ? $photo['url'] : '',
496 'image' => '<img src="' . ( isset($photo['url']) ? $photo['url'] : '' ) . '" alt="' . ( isset($photo['title']) ? $photo['title'] : '' ) . '">',
497 );
498 }
499 }
500 else
501 {
502 $gallery_attachments = $property->get_gallery_attachment_ids();
503
504 if ( !empty($gallery_attachments) )
505 {
506 foreach ($gallery_attachments as $gallery_attachment)
507 {
508 $images[] = array(
509 'title' => esc_attr( get_the_title( $gallery_attachment ) ),
510 'url' => wp_get_attachment_url( $gallery_attachment ),
511 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'single_property_small_thumbnail_size', 'thumbnail' ) ),
512 'attachment_id' => $gallery_attachment,
513 );
514 }
515 }
516 }
517
518 ph_get_template( 'single-property/property-thumbnails.php', array( 'images' => $images ) );
519 }
520 }
521
522 if ( ! function_exists( 'propertyhive_template_single_title' ) ) {
523
524 /**
525 * Output the property title.
526 *
527 * @access public
528 * @subpackage Property
529 * @return void
530 */
531 function propertyhive_template_single_title() {
532 ph_get_template( 'single-property/title.php' );
533 }
534 }
535
536 if ( ! function_exists( 'propertyhive_template_single_floor_area' ) ) {
537
538 /**
539 * Output the property floor area.
540 *
541 * @access public
542 * @subpackage Property
543 * @return void
544 */
545 function propertyhive_template_single_floor_area() {
546 ph_get_template( 'single-property/floor-area.php' );
547 }
548 }
549
550 if ( ! function_exists( 'propertyhive_template_single_price' ) ) {
551
552 /**
553 * Output the property price.
554 *
555 * @access public
556 * @subpackage Property
557 * @return void
558 */
559 function propertyhive_template_single_price() {
560
561 global $property;
562
563 $fees = '';
564 if ( get_option('propertyhive_lettings_fees_display_single_property', '') == 'yes' )
565 {
566 if (
567 $property->department == 'residential-lettings' &&
568 get_option('propertyhive_lettings_fees', '') != ''
569 )
570 {
571 $fees = nl2br(get_option('propertyhive_lettings_fees', ''));
572 }
573 if (
574 $property->department == 'commercial' &&
575 $property->to_rent == 'yes' &&
576 get_option('propertyhive_lettings_fees_commercial', '') != ''
577 )
578 {
579 $fees = nl2br(get_option('propertyhive_lettings_fees_commercial', ''));
580 }
581 }
582
583 ph_get_template( 'single-property/price.php', array( 'fees' => $fees ) );
584 }
585 }
586
587 if ( ! function_exists( 'propertyhive_template_single_meta' ) ) {
588
589 /**
590 * Output the product meta.
591 *
592 * @access public
593 * @subpackage Property
594 * @return void
595 */
596 function propertyhive_template_single_meta() {
597
598 global $post, $property;
599
600 $meta = array();
601
602 if ( $property->reference_number != '' )
603 {
604 $meta['reference-number'] = array(
605 'label' => __('Ref', 'propertyhive'),
606 'value' => $property->reference_number
607 );
608 }
609
610 if ( $property->property_type != '' )
611 {
612 $meta['property-type'] = array(
613 'label' => __('Type', 'propertyhive'),
614 'value' => $property->property_type
615 );
616 }
617
618 if ( $property->availability != '' )
619 {
620 $meta['availability'] = array(
621 'label' => __('Availability', 'propertyhive'),
622 'value' => $property->availability
623 );
624 }
625
626 if ( $property->department != 'commercial' )
627 {
628 if ( $property->bedrooms > 0 )
629 {
630 $meta['bedrooms'] = array(
631 'label' => __('Bedrooms', 'propertyhive'),
632 'value' => $property->bedrooms
633 );
634 }
635
636 if ( $property->bathrooms > 0 )
637 {
638 $meta['bathrooms'] = array(
639 'label' => __('Bathrooms', 'propertyhive'),
640 'value' => $property->bathrooms
641 );
642 }
643
644 if ( $property->reception_rooms > 0 )
645 {
646 $meta['reception-rooms'] = array(
647 'label' => __('Reception Rooms', 'propertyhive'),
648 'value' => $property->reception_rooms
649 );
650 }
651
652 if ( $property->parking != '' )
653 {
654 $meta['parking'] = array(
655 'label' => __('Parking', 'propertyhive'),
656 'value' => $property->parking
657 );
658 }
659
660 if ( $property->outside_space != '' )
661 {
662 $meta['outside-space'] = array(
663 'label' => __('Outside Space', 'propertyhive'),
664 'value' => $property->outside_space
665 );
666 }
667 }
668
669 if ( $property->department == 'residential-sales' )
670 {
671 if ( $property->tenure != '' )
672 {
673 $meta['tenure'] = array(
674 'label' => __('Tenure', 'propertyhive'),
675 'value' => $property->tenure
676 );
677 }
678 }
679
680 if ( $property->department == 'residential-lettings' )
681 {
682 if ( $property->furnished != '' )
683 {
684 $meta['furnished'] = array(
685 'label' => __('Furnished', 'propertyhive'),
686 'value' => $property->furnished
687 );
688 }
689
690 if ( $property->deposit > 0 )
691 {
692 $meta['deposit'] = array(
693 'label' => __('Deposit', 'propertyhive'),
694 'value' => $property->get_formatted_deposit()
695 );
696 }
697
698 if ( $property->available_date != '' )
699 {
700 $meta['available-date'] = array(
701 'label' => __('Available', 'propertyhive'),
702 'value' => $property->get_available_date()
703 );
704 }
705 }
706
707 $meta = apply_filters( 'propertyhive_single_property_meta', $meta );
708
709 ph_get_template( 'single-property/meta.php', array( 'meta' => $meta ) );
710 }
711 }
712
713 if ( ! function_exists( 'propertyhive_template_single_sharing' ) ) {
714
715 /**
716 * Output the product sharing.
717 *
718 * @access public
719 * @subpackage Property
720 * @return void
721 */
722 function propertyhive_template_single_sharing() {
723 ph_get_template( 'single-property/share.php' );
724 }
725 }
726
727 if ( ! function_exists( 'propertyhive_template_single_actions' ) ) {
728
729 /**
730 * Output the product actions (make enquiry etc)
731 *
732 * @access public
733 * @subpackage Property
734 * @return void
735 */
736 function propertyhive_template_single_actions() {
737
738 global $post, $property;
739
740 $actions = array();
741
742 if ( get_option('propertyhive_floorplans_stored_as', '') == 'urls' )
743 {
744 $floorplan_urls = $property->_floorplan_urls;
745 if ( is_array($floorplan_urls) && !empty( $floorplan_urls ) )
746 {
747 foreach ($floorplan_urls as $floorplan)
748 {
749 $actions[] = array(
750 'href' => ( ( isset($floorplan['url']) ) ? $floorplan['url'] : '' ),
751 'label' => __( 'Floorplan', 'propertyhive' ),
752 'class' => 'action-floorplans',
753 'attributes' => array(
754 'data-fancybox' => 'floorplans'
755 )
756 );
757 }
758 }
759 }
760 else
761 {
762 $floorplan_ids = $property->get_floorplan_attachment_ids();
763 if ( !empty( $floorplan_ids ) )
764 {
765 foreach ($floorplan_ids as $floorplan_id)
766 {
767 $label = 'Floorplan';
768
769 $attachment_data = wp_prepare_attachment_for_js( $floorplan_id );
770 if ( isset( $attachment_data['caption'] ) && $attachment_data['caption'] != '' )
771 {
772 $label = $attachment_data['caption'];
773 }
774
775
776 $actions[] = array(
777 'href' => wp_get_attachment_url( $floorplan_id ),
778 'label' => __( $label, 'propertyhive' ),
779 'class' => 'action-floorplans',
780 'attributes' => array(
781 'data-fancybox' => 'floorplans'
782 )
783 );
784 }
785 }
786 }
787
788 if ( get_option('propertyhive_brochures_stored_as', '') == 'urls' )
789 {
790 $brochure_urls = $property->_brochure_urls;
791 if ( is_array($brochure_urls) && !empty( $brochure_urls ) )
792 {
793 foreach ($brochure_urls as $brochure)
794 {
795 $actions[] = array(
796 'href' => ( ( isset($brochure['url']) ) ? $brochure['url'] : '' ),
797 'label' => __( 'View Brochure', 'propertyhive' ),
798 'class' => 'action-brochure',
799 'attributes' => array(
800 'target' => '_blank'
801 )
802 );
803 }
804 }
805 }
806 else
807 {
808 $brochure_ids = $property->get_brochure_attachment_ids();
809 if ( !empty( $brochure_ids ) )
810 {
811 foreach ($brochure_ids as $brochure_id)
812 {
813 $actions[] = array(
814 'href' => wp_get_attachment_url( $brochure_id ),
815 'label' => __( 'View Brochure', 'propertyhive' ),
816 'class' => 'action-brochure',
817 'attributes' => array(
818 'target' => '_blank'
819 )
820 );
821 }
822 }
823 }
824
825 if ( get_option('propertyhive_epcs_stored_as', '') == 'urls' )
826 {
827 $epc_urls = $property->_epc_urls;
828 if ( is_array($epc_urls) && !empty( $epc_urls ) )
829 {
830 foreach ($epc_urls as $epc)
831 {
832 $actions[] = array(
833 'href' => ( ( isset($epc['url']) ) ? $epc['url'] : '' ),
834 'label' => __( 'View EPC', 'propertyhive' ),
835 'class' => 'action-epc',
836 'attributes' => array(
837 'target' => '_blank'
838 )
839 );
840 }
841 }
842 }
843 else
844 {
845 $epc_ids = $property->get_epc_attachment_ids();
846 if ( !empty( $epc_ids ) )
847 {
848 foreach ($epc_ids as $epc_id)
849 {
850 $attributes = array('target' => '_blank');
851 if ( wp_attachment_is_image($epc_id) )
852 {
853 $attributes = array('data-fancybox' => 'epcs');
854 }
855 $actions[] = array(
856 'href' => wp_get_attachment_url( $epc_id ),
857 'label' => __( 'View EPC', 'propertyhive' ),
858 'class' => 'action-epc',
859 'attributes' => $attributes
860 );
861 }
862 }
863 }
864
865 $virtual_tour_urls = $property->get_virtual_tour_urls();
866 if ( !empty( $virtual_tour_urls ) )
867 {
868 foreach ($virtual_tour_urls as $virtual_tour_url)
869 {
870 $actions[] = array(
871 'href' => $virtual_tour_url,
872 'label' => __( 'Virtual Tour', 'propertyhive' ),
873 'class' => 'action-virtual-tour',
874 'attributes' => array(
875 'target' => '_blank'
876 )
877 );
878 }
879 }
880
881 /*$actions[] = array(
882 'href' => '',
883 'label' => __( 'View on Map', 'propertyhive' ),
884 'class' => 'action-map'
885 );
886
887 $actions[] = array(
888 'href' => '',
889 'label' => __( 'Street View', 'propertyhive' ),
890 'class' => 'action-street-view'
891 );*/
892
893 $actions = apply_filters( 'propertyhive_single_property_actions', $actions );
894
895 ph_get_template( 'single-property/actions.php', array( 'actions' => $actions ) );
896 }
897 }
898
899 if ( ! function_exists( 'propertyhive_template_single_features' ) ) {
900
901 /**
902 * Output the property features.
903 *
904 * @access public
905 * @subpackage Property
906 * @return void
907 */
908 function propertyhive_template_single_features() {
909 ph_get_template( 'single-property/features.php' );
910 }
911 }
912
913 if ( ! function_exists( 'propertyhive_template_single_summary' ) ) {
914
915 /**
916 * Output the product summary description.
917 *
918 * @access public
919 * @subpackage Property
920 * @return void
921 */
922 function propertyhive_template_single_summary() {
923 ph_get_template( 'single-property/summary-description.php' );
924 }
925 }
926
927
928 if ( ! function_exists( 'propertyhive_template_single_description' ) ) {
929
930 /**
931 * Output the product rooms or descriptions to form a full description
932 *
933 * @access public
934 * @subpackage Property
935 * @return void
936 */
937 function propertyhive_template_single_description() {
938 ph_get_template( 'single-property/description.php' );
939 }
940 }
941
942 if ( ! function_exists( 'propertyhive_make_enquiry_button' ) ) {
943
944 /**
945 * Output the make enquiry button and lightbox
946 *
947 * @access public
948 * @subpackage Property
949 * @return void
950 */
951 function propertyhive_make_enquiry_button() {
952 ph_get_template( 'global/make-enquiry.php' );
953 }
954 }
955
956 function propertyhive_my_account_pages()
957 {
958 $user_id = get_current_user_id();
959
960 $contact = new PH_Contact( '', $user_id );
961
962 $pages = array(
963 'dashboard' => array(
964 'name' => __( 'Dashboard', 'propertyhive' )
965 ),
966 'details' => array(
967 'name' => __( 'My Details', 'propertyhive' )
968 ),
969 );
970
971 // Add 'requirements' tab if applicant
972
973 if ( !empty($contact->contact_types) )
974 {
975 $contact_types = $contact->contact_types;
976 if ( !is_array($contact_types) )
977 {
978 $contact_types = array($contact_types);
979 }
980 if ( in_array('applicant', $contact_types) )
981 {
982 $applicant_profiles = $contact->applicant_profiles;
983
984 if ( $applicant_profiles && $applicant_profiles > 0 )
985 {
986 for ( $i = 0; $i < $applicant_profiles; ++$i )
987 {
988 $pages['requirements'] = array(
989 'name' => __( 'Requirements', 'propertyhive' ),
990 );
991
992 break; // At the moment we'll only allow them to manage the first set of requirements
993 }
994 }
995
996 // Check viewing module is active and that viewings exist, either future or past
997 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
998 {
999 $args = array(
1000 'post_type' => 'viewing',
1001 'posts_per_page' => 1,
1002 'post_status' => 'publish',
1003 'fields' => 'ids',
1004 'meta_query' => array(
1005 array(
1006 'key' => '_applicant_contact_id',
1007 'value' => $contact->id
1008 )
1009 )
1010 );
1011 $viewings_query = new WP_Query( $args );
1012
1013 if ( $viewings_query->have_posts() )
1014 {
1015 $pages['applicant_viewings'] = array(
1016 'name' => __( 'Viewings', 'propertyhive' ),
1017 );
1018 }
1019 wp_reset_postdata();
1020 }
1021 }
1022 if ( in_array('owner', $contact_types) )
1023 {
1024 // Get properties belonging to this owner
1025 $args = array(
1026 'post_type' => 'property',
1027 'nopaging' => true,
1028 'post_status' => 'publish',
1029 'fields' => 'ids',
1030 'meta_query' => array(
1031 'relation' => 'OR',
1032 array(
1033 'key' => '_owner_contact_id',
1034 'value' => ':' . $contact->id . ';',
1035 'compare' => 'LIKE'
1036 ),
1037 array(
1038 'key' => '_owner_contact_id',
1039 'value' => ':"' . $contact->id . '";',
1040 'compare' => 'LIKE'
1041 )
1042 )
1043 );
1044
1045 $properties_query = new WP_Query( $args );
1046
1047 $property_ids = array();
1048
1049 if ( $properties_query->have_posts() )
1050 {
1051 while ( $properties_query->have_posts() )
1052 {
1053 $properties_query->the_post();
1054
1055 $property_ids[] = get_the_id();
1056 }
1057
1058 $pages['owner_properties'] = array(
1059 'name' => __( 'Properties', 'propertyhive' ),
1060 );
1061 }
1062 wp_reset_postdata();
1063
1064 // Check viewing module is active and that viewings exist, either future or past
1065 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
1066 {
1067 $past_viewings = array();
1068 $upcoming_viewings = array();
1069
1070 if ( !empty($property_ids) )
1071 {
1072 $args = array(
1073 'post_type' => 'viewing',
1074 'posts_per_page' => 1,
1075 'post_status' => 'publish',
1076 'fields' => 'ids',
1077 'meta_query' => array(
1078 array(
1079 'key' => '_property_id',
1080 'value' => $property_ids,
1081 'compare' => 'IN'
1082 )
1083 )
1084 );
1085 $viewings_query = new WP_Query( $args );
1086
1087 if ( $viewings_query->have_posts() )
1088 {
1089 $pages['owner_viewings'] = array(
1090 'name' => __( 'Viewings', 'propertyhive' ),
1091 );
1092 }
1093 wp_reset_postdata();
1094 }
1095 }
1096 }
1097 }
1098
1099 $pages = apply_filters( 'propertyhive_my_account_pages', $pages );
1100
1101 /*$pages['delete'] = array(
1102 'name' => __( 'Delete Account', 'propertyhive' )
1103 );*/
1104
1105 $pages['logout'] = array(
1106 'name' => __( 'Logout', 'propertyhive' ),
1107 'href' => home_url() . '?logout=1' // Logout URL
1108 );
1109
1110 return $pages;
1111 }
1112
1113 if ( ! function_exists( 'propertyhive_my_account_navigation' ) ) {
1114
1115 /**
1116 * Output the navigation/tabs within a users 'My Account' page
1117 *
1118 * @access public
1119 * @return void
1120 */
1121 function propertyhive_my_account_navigation() {
1122
1123 $pages = propertyhive_my_account_pages();
1124
1125 ph_get_template( 'account/navigation.php', array( 'pages' => $pages ) );
1126 }
1127 }
1128
1129 if ( ! function_exists( 'propertyhive_my_account_sections' ) ) {
1130
1131 /**
1132 * Output the main sections within a users 'My Account' page that relate to the navigation tabs/links
1133 *
1134 * @access public
1135 * @return void
1136 */
1137 function propertyhive_my_account_sections() {
1138
1139 $pages = propertyhive_my_account_pages();
1140
1141 ph_get_template( 'account/sections.php', array( 'pages' => $pages ) );
1142 }
1143 }
1144
1145 if ( ! function_exists( 'propertyhive_my_account_dashboard' ) ) {
1146
1147 /**
1148 * Output the dashboard section within a users account
1149 *
1150 * @access public
1151 * @return void
1152 */
1153 function propertyhive_my_account_dashboard() {
1154
1155 ph_get_template( 'account/dashboard.php' );
1156 }
1157 }
1158
1159 if ( ! function_exists( 'propertyhive_my_account_details' ) ) {
1160
1161 /**
1162 * Output the details section within a users account
1163 *
1164 * @access public
1165 * @return void
1166 */
1167 function propertyhive_my_account_details() {
1168
1169 $form_controls = ph_get_user_details_form_fields();
1170
1171 $form_controls = apply_filters( 'propertyhive_user_details_form_fields', $form_controls );
1172
1173 // Make sure password fields aren't require
1174 foreach ( $form_controls as $i => $form_control )
1175 {
1176 if ( $form_control['type'] == 'password' )
1177 {
1178 $form_control['required'] = false;
1179
1180 $form_controls[$i] = $form_control;
1181 }
1182 }
1183
1184 ph_get_template( 'account/details.php', array( 'form_controls' => $form_controls ) );
1185 }
1186 }
1187
1188 if ( ! function_exists( 'propertyhive_my_account_requirements' ) ) {
1189
1190 /**
1191 * Output the requirements section within a users account
1192 *
1193 * @access public
1194 * @return void
1195 */
1196 function propertyhive_my_account_requirements() {
1197
1198 $form_controls = ph_get_applicant_requirements_form_fields();
1199
1200 $form_controls = apply_filters( 'propertyhive_applicant_requirements_form_fields', $form_controls );
1201
1202 // Remove office as this is only required on initial sign up (at the moment anyway)
1203 if ( isset($form_controls['office_id']) )
1204 {
1205 unset($form_controls['office_id']);
1206 }
1207
1208 ph_get_template( 'account/requirements.php', array( 'form_controls' => $form_controls ) );
1209 }
1210 }
1211
1212 if ( ! function_exists( 'propertyhive_my_account_applicant_viewings' ) ) {
1213
1214 /**
1215 * Output the applicant viewings section within a users account
1216 *
1217 * @access public
1218 * @return void
1219 */
1220 function propertyhive_my_account_applicant_viewings() {
1221
1222 $user_id = get_current_user_id();
1223
1224 $contact = new PH_Contact( '', $user_id );
1225
1226 $past_viewings = array();
1227 $upcoming_viewings = array();
1228
1229 $args = array(
1230 'post_type' => 'viewing',
1231 'nopaging' => 'true',
1232 'post_status' => 'publish',
1233 'fields' => 'ids',
1234 'orderby' => 'meta_value',
1235 'order' => 'DESC',
1236 'post_status' => 'publish',
1237 'meta_key' => '_start_date_time',
1238 'meta_query' => array(
1239 array(
1240 'key' => '_applicant_contact_id',
1241 'value' => $contact->id
1242 )
1243 )
1244 );
1245
1246 // Do past viewings
1247 $args2 = $args;
1248 $args2['meta_query'][] = array(
1249 'key' => '_start_date_time',
1250 'value' => date("Y-m-d H:i:s"),
1251 'compare' => '<='
1252 );
1253
1254 $viewings_query = new WP_Query( $args2 );
1255
1256 if ( $viewings_query->have_posts() )
1257 {
1258 while ( $viewings_query->have_posts() )
1259 {
1260 $viewings_query->the_post();
1261
1262 $viewing = new PH_Viewing( get_the_ID() );
1263
1264 $past_viewings[] = $viewing;
1265 }
1266 }
1267 wp_reset_postdata();
1268
1269 // Do upcoming viewings
1270 $args2 = $args;
1271 $args2['meta_query'][] = array(
1272 'key' => '_start_date_time',
1273 'value' => date("Y-m-d H:i:s"),
1274 'compare' => '>='
1275 );
1276
1277 $viewings_query = new WP_Query( $args2 );
1278
1279 if ( $viewings_query->have_posts() )
1280 {
1281 while ( $viewings_query->have_posts() )
1282 {
1283 $viewings_query->the_post();
1284
1285 $viewing = new PH_Viewing( get_the_ID() );
1286
1287 $upcoming_viewings[] = $viewing;
1288 }
1289 }
1290 wp_reset_postdata();
1291
1292 ph_get_template( 'account/applicant-viewings.php', array( 'past_viewings' => $past_viewings, 'upcoming_viewings' => $upcoming_viewings ) );
1293 }
1294 }
1295
1296 if ( ! function_exists( 'propertyhive_my_account_owner_properties' ) ) {
1297
1298 /**
1299 * Output the owner properties section within a users account
1300 *
1301 * @access public
1302 * @return void
1303 */
1304 function propertyhive_my_account_owner_properties() {
1305
1306 $user_id = get_current_user_id();
1307
1308 $contact = new PH_Contact( '', $user_id );
1309
1310 // Get properties belonging to this owner
1311 $args = array(
1312 'post_type' => 'property',
1313 'nopaging' => true,
1314 'post_status' => 'publish',
1315 'fields' => 'ids',
1316 'meta_query' => array(
1317 'relation' => 'OR',
1318 array(
1319 'key' => '_owner_contact_id',
1320 'value' => ':' . $contact->id . ';',
1321 'compare' => 'LIKE'
1322 ),
1323 array(
1324 'key' => '_owner_contact_id',
1325 'value' => ':"' . $contact->id . '";',
1326 'compare' => 'LIKE'
1327 )
1328 )
1329 );
1330
1331 $properties_query = new WP_Query( $args );
1332
1333 $properties = array();
1334
1335 if ( $properties_query->have_posts() )
1336 {
1337 while ( $properties_query->have_posts() )
1338 {
1339 $properties_query->the_post();
1340
1341 $properties[] = new PH_Property( get_the_id() );
1342 }
1343 }
1344 wp_reset_postdata();
1345 ph_get_template( 'account/owner-properties.php', array( 'properties' => $properties ) );
1346 }
1347 }
1348
1349 if ( ! function_exists( 'propertyhive_my_account_owner_viewings' ) ) {
1350
1351 /**
1352 * Output the owner viewings section within a users account
1353 *
1354 * @access public
1355 * @return void
1356 */
1357 function propertyhive_my_account_owner_viewings() {
1358
1359 $user_id = get_current_user_id();
1360
1361 $contact = new PH_Contact( '', $user_id );
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 }
1397 wp_reset_postdata();
1398
1399 $past_viewings = array();
1400 $upcoming_viewings = array();
1401
1402 if ( !empty($property_ids) )
1403 {
1404 $args = array(
1405 'post_type' => 'viewing',
1406 'nopaging' => true,
1407 'post_status' => 'publish',
1408 'fields' => 'ids',
1409 'orderby' => 'meta_value',
1410 'order' => 'DESC',
1411 'post_status' => 'publish',
1412 'meta_key' => '_start_date_time',
1413 'meta_query' => array(
1414 array(
1415 'key' => '_property_id',
1416 'value' => $property_ids,
1417 'compare' => 'IN'
1418 )
1419 )
1420 );
1421
1422 // Do past viewings
1423 $args2 = $args;
1424 $args2['meta_query'][] = array(
1425 'key' => '_start_date_time',
1426 'value' => date("Y-m-d H:i:s"),
1427 'compare' => '<='
1428 );
1429
1430 $viewings_query = new WP_Query( $args2 );
1431
1432 if ( $viewings_query->have_posts() )
1433 {
1434 while ( $viewings_query->have_posts() )
1435 {
1436 $viewings_query->the_post();
1437
1438 $viewing = new PH_Viewing( get_the_ID() );
1439
1440 $past_viewings[] = $viewing;
1441 }
1442 }
1443 wp_reset_postdata();
1444
1445 // Do upcoming viewings
1446 $args2 = $args;
1447 $args2['meta_query'][] = array(
1448 'key' => '_start_date_time',
1449 'value' => date("Y-m-d H:i:s"),
1450 'compare' => '>='
1451 );
1452
1453 $viewings_query = new WP_Query( $args2 );
1454
1455 if ( $viewings_query->have_posts() )
1456 {
1457 while ( $viewings_query->have_posts() )
1458 {
1459 $viewings_query->the_post();
1460
1461 $viewing = new PH_Viewing( get_the_ID() );
1462
1463 $upcoming_viewings[] = $viewing;
1464 }
1465 }
1466 wp_reset_postdata();
1467 }
1468
1469 ph_get_template( 'account/owner-viewings.php', array( 'past_viewings' => $past_viewings, 'upcoming_viewings' => $upcoming_viewings ) );
1470 }
1471 }
1472
1473 if ( ! function_exists( 'propertyhive_my_account_delete' ) ) {
1474
1475 /**
1476 * Output the delete section within a users account
1477 *
1478 * @access public
1479 * @return void
1480 */
1481 function propertyhive_my_account_delete() {
1482
1483 ph_get_template( 'account/delete.php' );
1484 }
1485 }