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

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

1,489 lines 42.7 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_tours = $property->get_virtual_tours();
866 if ( !empty( $virtual_tours ) )
867 {
868 foreach ($virtual_tours as $virtual_tour)
869 {
870 $attributes = array('target' => '_blank');
871 if ( strpos($virtual_tour['url'], 'yout') !== FALSE || strpos($virtual_tour['url'], 'vimeo') !== FALSE )
872 {
873 $attributes['data-fancybox'] = '';
874 }
875
876 $actions[] = array(
877 'href' => $virtual_tour['url'],
878 'label' => __( $virtual_tour['label'], 'propertyhive' ),
879 'class' => 'action-virtual-tour',
880 'attributes' => $attributes,
881 );
882 }
883 }
884
885 /*$actions[] = array(
886 'href' => '',
887 'label' => __( 'View on Map', 'propertyhive' ),
888 'class' => 'action-map'
889 );
890
891 $actions[] = array(
892 'href' => '',
893 'label' => __( 'Street View', 'propertyhive' ),
894 'class' => 'action-street-view'
895 );*/
896
897 $actions = apply_filters( 'propertyhive_single_property_actions', $actions );
898
899 ph_get_template( 'single-property/actions.php', array( 'actions' => $actions ) );
900 }
901 }
902
903 if ( ! function_exists( 'propertyhive_template_single_features' ) ) {
904
905 /**
906 * Output the property features.
907 *
908 * @access public
909 * @subpackage Property
910 * @return void
911 */
912 function propertyhive_template_single_features() {
913 ph_get_template( 'single-property/features.php' );
914 }
915 }
916
917 if ( ! function_exists( 'propertyhive_template_single_summary' ) ) {
918
919 /**
920 * Output the product summary description.
921 *
922 * @access public
923 * @subpackage Property
924 * @return void
925 */
926 function propertyhive_template_single_summary() {
927 ph_get_template( 'single-property/summary-description.php' );
928 }
929 }
930
931
932 if ( ! function_exists( 'propertyhive_template_single_description' ) ) {
933
934 /**
935 * Output the product rooms or descriptions to form a full description
936 *
937 * @access public
938 * @subpackage Property
939 * @return void
940 */
941 function propertyhive_template_single_description() {
942 ph_get_template( 'single-property/description.php' );
943 }
944 }
945
946 if ( ! function_exists( 'propertyhive_make_enquiry_button' ) ) {
947
948 /**
949 * Output the make enquiry button and lightbox
950 *
951 * @access public
952 * @subpackage Property
953 * @return void
954 */
955 function propertyhive_make_enquiry_button() {
956 ph_get_template( 'global/make-enquiry.php' );
957 }
958 }
959
960 function propertyhive_my_account_pages()
961 {
962 $user_id = get_current_user_id();
963
964 $contact = new PH_Contact( '', $user_id );
965
966 $pages = array(
967 'dashboard' => array(
968 'name' => __( 'Dashboard', 'propertyhive' )
969 ),
970 'details' => array(
971 'name' => __( 'My Details', 'propertyhive' )
972 ),
973 );
974
975 // Add 'requirements' tab if applicant
976
977 if ( !empty($contact->contact_types) )
978 {
979 $contact_types = $contact->contact_types;
980 if ( !is_array($contact_types) )
981 {
982 $contact_types = array($contact_types);
983 }
984 if ( in_array('applicant', $contact_types) )
985 {
986 $applicant_profiles = $contact->applicant_profiles;
987
988 if ( $applicant_profiles && $applicant_profiles > 0 )
989 {
990 for ( $i = 0; $i < $applicant_profiles; ++$i )
991 {
992 $pages['requirements'] = array(
993 'name' => __( 'Requirements', 'propertyhive' ),
994 );
995
996 break; // At the moment we'll only allow them to manage the first set of requirements
997 }
998 }
999
1000 // Check viewing module is active and that viewings exist, either future or past
1001 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
1002 {
1003 $args = array(
1004 'post_type' => 'viewing',
1005 'posts_per_page' => 1,
1006 'post_status' => 'publish',
1007 'fields' => 'ids',
1008 'meta_query' => array(
1009 array(
1010 'key' => '_applicant_contact_id',
1011 'value' => $contact->id
1012 )
1013 )
1014 );
1015 $viewings_query = new WP_Query( $args );
1016
1017 if ( $viewings_query->have_posts() )
1018 {
1019 $pages['applicant_viewings'] = array(
1020 'name' => __( 'Viewings', 'propertyhive' ),
1021 );
1022 }
1023 wp_reset_postdata();
1024 }
1025 }
1026 if ( in_array('owner', $contact_types) )
1027 {
1028 // Get properties belonging to this owner
1029 $args = array(
1030 'post_type' => 'property',
1031 'nopaging' => true,
1032 'post_status' => 'publish',
1033 'fields' => 'ids',
1034 'meta_query' => array(
1035 'relation' => 'OR',
1036 array(
1037 'key' => '_owner_contact_id',
1038 'value' => ':' . $contact->id . ';',
1039 'compare' => 'LIKE'
1040 ),
1041 array(
1042 'key' => '_owner_contact_id',
1043 'value' => ':"' . $contact->id . '";',
1044 'compare' => 'LIKE'
1045 )
1046 )
1047 );
1048
1049 $properties_query = new WP_Query( $args );
1050
1051 $property_ids = array();
1052
1053 if ( $properties_query->have_posts() )
1054 {
1055 while ( $properties_query->have_posts() )
1056 {
1057 $properties_query->the_post();
1058
1059 $property_ids[] = get_the_id();
1060 }
1061
1062 $pages['owner_properties'] = array(
1063 'name' => __( 'Properties', 'propertyhive' ),
1064 );
1065 }
1066 wp_reset_postdata();
1067
1068 // Check viewing module is active and that viewings exist, either future or past
1069 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
1070 {
1071 $past_viewings = array();
1072 $upcoming_viewings = array();
1073
1074 if ( !empty($property_ids) )
1075 {
1076 $args = array(
1077 'post_type' => 'viewing',
1078 'posts_per_page' => 1,
1079 'post_status' => 'publish',
1080 'fields' => 'ids',
1081 'meta_query' => array(
1082 array(
1083 'key' => '_property_id',
1084 'value' => $property_ids,
1085 'compare' => 'IN'
1086 )
1087 )
1088 );
1089 $viewings_query = new WP_Query( $args );
1090
1091 if ( $viewings_query->have_posts() )
1092 {
1093 $pages['owner_viewings'] = array(
1094 'name' => __( 'Viewings', 'propertyhive' ),
1095 );
1096 }
1097 wp_reset_postdata();
1098 }
1099 }
1100 }
1101 }
1102
1103 $pages = apply_filters( 'propertyhive_my_account_pages', $pages );
1104
1105 /*$pages['delete'] = array(
1106 'name' => __( 'Delete Account', 'propertyhive' )
1107 );*/
1108
1109 $pages['logout'] = array(
1110 'name' => __( 'Logout', 'propertyhive' ),
1111 'href' => home_url() . '?logout=1' // Logout URL
1112 );
1113
1114 return $pages;
1115 }
1116
1117 if ( ! function_exists( 'propertyhive_my_account_navigation' ) ) {
1118
1119 /**
1120 * Output the navigation/tabs within a users 'My Account' page
1121 *
1122 * @access public
1123 * @return void
1124 */
1125 function propertyhive_my_account_navigation() {
1126
1127 $pages = propertyhive_my_account_pages();
1128
1129 ph_get_template( 'account/navigation.php', array( 'pages' => $pages ) );
1130 }
1131 }
1132
1133 if ( ! function_exists( 'propertyhive_my_account_sections' ) ) {
1134
1135 /**
1136 * Output the main sections within a users 'My Account' page that relate to the navigation tabs/links
1137 *
1138 * @access public
1139 * @return void
1140 */
1141 function propertyhive_my_account_sections() {
1142
1143 $pages = propertyhive_my_account_pages();
1144
1145 ph_get_template( 'account/sections.php', array( 'pages' => $pages ) );
1146 }
1147 }
1148
1149 if ( ! function_exists( 'propertyhive_my_account_dashboard' ) ) {
1150
1151 /**
1152 * Output the dashboard section within a users account
1153 *
1154 * @access public
1155 * @return void
1156 */
1157 function propertyhive_my_account_dashboard() {
1158
1159 ph_get_template( 'account/dashboard.php' );
1160 }
1161 }
1162
1163 if ( ! function_exists( 'propertyhive_my_account_details' ) ) {
1164
1165 /**
1166 * Output the details section within a users account
1167 *
1168 * @access public
1169 * @return void
1170 */
1171 function propertyhive_my_account_details() {
1172
1173 $form_controls = ph_get_user_details_form_fields();
1174
1175 $form_controls = apply_filters( 'propertyhive_user_details_form_fields', $form_controls );
1176
1177 // Make sure password fields aren't require
1178 foreach ( $form_controls as $i => $form_control )
1179 {
1180 if ( $form_control['type'] == 'password' )
1181 {
1182 $form_control['required'] = false;
1183
1184 $form_controls[$i] = $form_control;
1185 }
1186 }
1187
1188 ph_get_template( 'account/details.php', array( 'form_controls' => $form_controls ) );
1189 }
1190 }
1191
1192 if ( ! function_exists( 'propertyhive_my_account_requirements' ) ) {
1193
1194 /**
1195 * Output the requirements section within a users account
1196 *
1197 * @access public
1198 * @return void
1199 */
1200 function propertyhive_my_account_requirements() {
1201
1202 $form_controls = ph_get_applicant_requirements_form_fields();
1203
1204 $form_controls = apply_filters( 'propertyhive_applicant_requirements_form_fields', $form_controls );
1205
1206 // Remove office as this is only required on initial sign up (at the moment anyway)
1207 if ( isset($form_controls['office_id']) )
1208 {
1209 unset($form_controls['office_id']);
1210 }
1211
1212 ph_get_template( 'account/requirements.php', array( 'form_controls' => $form_controls ) );
1213 }
1214 }
1215
1216 if ( ! function_exists( 'propertyhive_my_account_applicant_viewings' ) ) {
1217
1218 /**
1219 * Output the applicant viewings section within a users account
1220 *
1221 * @access public
1222 * @return void
1223 */
1224 function propertyhive_my_account_applicant_viewings() {
1225
1226 $user_id = get_current_user_id();
1227
1228 $contact = new PH_Contact( '', $user_id );
1229
1230 $past_viewings = array();
1231 $upcoming_viewings = array();
1232
1233 $args = array(
1234 'post_type' => 'viewing',
1235 'nopaging' => 'true',
1236 'post_status' => 'publish',
1237 'fields' => 'ids',
1238 'orderby' => 'meta_value',
1239 'order' => 'DESC',
1240 'post_status' => 'publish',
1241 'meta_key' => '_start_date_time',
1242 'meta_query' => array(
1243 array(
1244 'key' => '_applicant_contact_id',
1245 'value' => $contact->id
1246 )
1247 )
1248 );
1249
1250 // Do past viewings
1251 $args2 = $args;
1252 $args2['meta_query'][] = array(
1253 'key' => '_start_date_time',
1254 'value' => date("Y-m-d H:i:s"),
1255 'compare' => '<='
1256 );
1257
1258 $viewings_query = new WP_Query( $args2 );
1259
1260 if ( $viewings_query->have_posts() )
1261 {
1262 while ( $viewings_query->have_posts() )
1263 {
1264 $viewings_query->the_post();
1265
1266 $viewing = new PH_Viewing( get_the_ID() );
1267
1268 $past_viewings[] = $viewing;
1269 }
1270 }
1271 wp_reset_postdata();
1272
1273 // Do upcoming viewings
1274 $args2 = $args;
1275 $args2['meta_query'][] = array(
1276 'key' => '_start_date_time',
1277 'value' => date("Y-m-d H:i:s"),
1278 'compare' => '>='
1279 );
1280
1281 $viewings_query = new WP_Query( $args2 );
1282
1283 if ( $viewings_query->have_posts() )
1284 {
1285 while ( $viewings_query->have_posts() )
1286 {
1287 $viewings_query->the_post();
1288
1289 $viewing = new PH_Viewing( get_the_ID() );
1290
1291 $upcoming_viewings[] = $viewing;
1292 }
1293 }
1294 wp_reset_postdata();
1295
1296 ph_get_template( 'account/applicant-viewings.php', array( 'past_viewings' => $past_viewings, 'upcoming_viewings' => $upcoming_viewings ) );
1297 }
1298 }
1299
1300 if ( ! function_exists( 'propertyhive_my_account_owner_properties' ) ) {
1301
1302 /**
1303 * Output the owner properties section within a users account
1304 *
1305 * @access public
1306 * @return void
1307 */
1308 function propertyhive_my_account_owner_properties() {
1309
1310 $user_id = get_current_user_id();
1311
1312 $contact = new PH_Contact( '', $user_id );
1313
1314 // Get properties belonging to this owner
1315 $args = array(
1316 'post_type' => 'property',
1317 'nopaging' => true,
1318 'post_status' => 'publish',
1319 'fields' => 'ids',
1320 'meta_query' => array(
1321 'relation' => 'OR',
1322 array(
1323 'key' => '_owner_contact_id',
1324 'value' => ':' . $contact->id . ';',
1325 'compare' => 'LIKE'
1326 ),
1327 array(
1328 'key' => '_owner_contact_id',
1329 'value' => ':"' . $contact->id . '";',
1330 'compare' => 'LIKE'
1331 )
1332 )
1333 );
1334
1335 $properties_query = new WP_Query( $args );
1336
1337 $properties = array();
1338
1339 if ( $properties_query->have_posts() )
1340 {
1341 while ( $properties_query->have_posts() )
1342 {
1343 $properties_query->the_post();
1344
1345 $properties[] = new PH_Property( get_the_id() );
1346 }
1347 }
1348 wp_reset_postdata();
1349 ph_get_template( 'account/owner-properties.php', array( 'properties' => $properties ) );
1350 }
1351 }
1352
1353 if ( ! function_exists( 'propertyhive_my_account_owner_viewings' ) ) {
1354
1355 /**
1356 * Output the owner viewings section within a users account
1357 *
1358 * @access public
1359 * @return void
1360 */
1361 function propertyhive_my_account_owner_viewings() {
1362
1363 $user_id = get_current_user_id();
1364
1365 $contact = new PH_Contact( '', $user_id );
1366
1367 // Get properties belonging to this owner
1368 $args = array(
1369 'post_type' => 'property',
1370 'nopaging' => true,
1371 'post_status' => 'publish',
1372 'fields' => 'ids',
1373 'meta_query' => array(
1374 'relation' => 'OR',
1375 array(
1376 'key' => '_owner_contact_id',
1377 'value' => ':' . $contact->id . ';',
1378 'compare' => 'LIKE'
1379 ),
1380 array(
1381 'key' => '_owner_contact_id',
1382 'value' => ':"' . $contact->id . '";',
1383 'compare' => 'LIKE'
1384 )
1385 )
1386 );
1387
1388 $properties_query = new WP_Query( $args );
1389
1390 $property_ids = array();
1391
1392 if ( $properties_query->have_posts() )
1393 {
1394 while ( $properties_query->have_posts() )
1395 {
1396 $properties_query->the_post();
1397
1398 $property_ids[] = get_the_id();
1399 }
1400 }
1401 wp_reset_postdata();
1402
1403 $past_viewings = array();
1404 $upcoming_viewings = array();
1405
1406 if ( !empty($property_ids) )
1407 {
1408 $args = array(
1409 'post_type' => 'viewing',
1410 'nopaging' => true,
1411 'post_status' => 'publish',
1412 'fields' => 'ids',
1413 'orderby' => 'meta_value',
1414 'order' => 'DESC',
1415 'post_status' => 'publish',
1416 'meta_key' => '_start_date_time',
1417 'meta_query' => array(
1418 array(
1419 'key' => '_property_id',
1420 'value' => $property_ids,
1421 'compare' => 'IN'
1422 )
1423 )
1424 );
1425
1426 // Do past viewings
1427 $args2 = $args;
1428 $args2['meta_query'][] = array(
1429 'key' => '_start_date_time',
1430 'value' => date("Y-m-d H:i:s"),
1431 'compare' => '<='
1432 );
1433
1434 $viewings_query = new WP_Query( $args2 );
1435
1436 if ( $viewings_query->have_posts() )
1437 {
1438 while ( $viewings_query->have_posts() )
1439 {
1440 $viewings_query->the_post();
1441
1442 $viewing = new PH_Viewing( get_the_ID() );
1443
1444 $past_viewings[] = $viewing;
1445 }
1446 }
1447 wp_reset_postdata();
1448
1449 // Do upcoming viewings
1450 $args2 = $args;
1451 $args2['meta_query'][] = array(
1452 'key' => '_start_date_time',
1453 'value' => date("Y-m-d H:i:s"),
1454 'compare' => '>='
1455 );
1456
1457 $viewings_query = new WP_Query( $args2 );
1458
1459 if ( $viewings_query->have_posts() )
1460 {
1461 while ( $viewings_query->have_posts() )
1462 {
1463 $viewings_query->the_post();
1464
1465 $viewing = new PH_Viewing( get_the_ID() );
1466
1467 $upcoming_viewings[] = $viewing;
1468 }
1469 }
1470 wp_reset_postdata();
1471 }
1472
1473 ph_get_template( 'account/owner-viewings.php', array( 'past_viewings' => $past_viewings, 'upcoming_viewings' => $upcoming_viewings ) );
1474 }
1475 }
1476
1477 if ( ! function_exists( 'propertyhive_my_account_delete' ) ) {
1478
1479 /**
1480 * Output the delete section within a users account
1481 *
1482 * @access public
1483 * @return void
1484 */
1485 function propertyhive_my_account_delete() {
1486
1487 ph_get_template( 'account/delete.php' );
1488 }
1489 }