PluginProbe
Property Hive / 1.4.5
Property Hive v1.4.5
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.5, at includes/ph-template-functions.php

898 lines 23.4 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
120 return $classes;
121 }
122
123 /** Global ****************************************************************/
124
125 if ( ! function_exists( 'propertyhive_output_content_wrapper' ) ) {
126
127 /**
128 * Output the start of the page wrapper.
129 *
130 * @access public
131 * @return void
132 */
133 function propertyhive_output_content_wrapper() {
134 ph_get_template( 'global/wrapper-start.php' );
135 }
136 }
137
138 if ( ! function_exists( 'propertyhive_output_content_wrapper_end' ) ) {
139
140 /**
141 * Output the end of the page wrapper.
142 *
143 * @access public
144 * @return void
145 */
146 function propertyhive_output_content_wrapper_end() {
147 ph_get_template( 'global/wrapper-end.php' );
148 }
149 }
150
151 /** Loop ******************************************************************/
152
153 if ( ! function_exists( 'propertyhive_page_title' ) ) {
154
155 /**
156 * propertyhive_page_title function.
157 *
158 * @param boolean $echo
159 * @return string
160 */
161 function propertyhive_page_title( $echo = true ) {
162
163 if ( is_search() ) {
164 $page_title = sprintf( __( 'Search Results: &ldquo;%s&rdquo;', 'propertyhive' ), get_search_query() );
165
166 if ( get_query_var( 'paged' ) )
167 $page_title .= sprintf( __( '&nbsp;&ndash; Page %s', 'propertyhive' ), get_query_var( 'paged' ) );
168
169 } elseif ( is_tax() ) {
170
171 $page_title = single_term_title( "", false );
172
173 } else {
174
175 $search_results_page_id = ph_get_page_id( 'search_results' );
176 $page_title = get_the_title( $search_results_page_id );
177
178 }
179
180 $page_title = apply_filters( 'propertyhive_page_title', $page_title );
181
182 if ( $echo )
183 echo $page_title;
184 else
185 return $page_title;
186 }
187 }
188
189 if ( ! function_exists( 'propertyhive_property_loop_start' ) ) {
190
191 /**
192 * Output the start of a property loop. By default this is a UL
193 *
194 * @access public
195 * @param bool $echo
196 * @return string
197 */
198 function propertyhive_property_loop_start( $echo = true ) {
199 ob_start();
200 ph_get_template( 'search/loop-start.php' );
201 if ( $echo )
202 echo ob_get_clean();
203 else
204 return ob_get_clean();
205 }
206 }
207 if ( ! function_exists( 'propertyhive_property_loop_end' ) ) {
208
209 /**
210 * Output the end of a property loop. By default this is a UL
211 *
212 * @access public
213 * @param bool $echo
214 * @return string
215 */
216 function propertyhive_property_loop_end( $echo = true ) {
217 ob_start();
218
219 ph_get_template( 'search/loop-end.php' );
220
221 if ( $echo )
222 echo ob_get_clean();
223 else
224 return ob_get_clean();
225 }
226 }
227
228 if ( ! function_exists( 'propertyhive_template_loop_property_thumbnail' ) ) {
229
230 /**
231 * Get the property thumbnail for the loop.
232 *
233 * @access public
234 * @subpackage Loop
235 * @return void
236 */
237 function propertyhive_template_loop_property_thumbnail() {
238 echo propertyhive_get_property_thumbnail();
239 }
240 }
241
242 if ( ! function_exists( 'propertyhive_get_property_thumbnail' ) ) {
243
244 /**
245 * Get the property thumbnail, or the placeholder if not set.
246 *
247 * @access public
248 * @subpackage Loop
249 * @param string $size (default: 'shop_catalog')
250 * @param int $placeholder_width (default: 0)
251 * @param int $placeholder_height (default: 0)
252 * @return string
253 */
254 function propertyhive_get_property_thumbnail( $size = 'medium', $class = '', $placeholder_width = 0, $placeholder_height = 0 ) {
255 global $post, $property;
256
257 $photo_url = $property->get_main_photo_src( $size);
258
259 if ($photo_url !== FALSE)
260 return '<img src="' . $photo_url . '" alt="' . get_the_title($post->ID) . '" class="' . $class . '">';
261
262 if ( ph_placeholder_img_src() )
263 return ph_placeholder_img( $size );
264 }
265 }
266
267 if ( ! function_exists( 'propertyhive_template_loop_floor_area' ) ) {
268
269 /**
270 * Get the property floor area for the loop.
271 *
272 * @access public
273 * @subpackage Loop
274 * @return void
275 */
276 function propertyhive_template_loop_floor_area() {
277 ph_get_template( 'search/floor-area.php' );
278 }
279 }
280
281 if ( ! function_exists( 'propertyhive_template_loop_price' ) ) {
282
283 /**
284 * Get the property price for the loop.
285 *
286 * @access public
287 * @subpackage Loop
288 * @return void
289 */
290 function propertyhive_template_loop_price() {
291 ph_get_template( 'search/price.php' );
292 }
293 }
294
295 if ( ! function_exists( 'propertyhive_template_loop_summary' ) ) {
296
297 /**
298 * Get the property summary for the loop.
299 *
300 * @access public
301 * @subpackage Loop
302 * @return void
303 */
304 function propertyhive_template_loop_summary() {
305 ph_get_template( 'search/summary.php' );
306 }
307 }
308
309 if ( ! function_exists( 'propertyhive_template_loop_actions' ) ) {
310
311 /**
312 * Get the actions for the loop (ie More Details).
313 *
314 * @access public
315 * @subpackage Loop
316 * @return void
317 */
318 function propertyhive_template_loop_actions() {
319 ph_get_template( 'search/actions.php' );
320 }
321 }
322
323 if ( ! function_exists( 'propertyhive_search_form' ) ) {
324
325 /**
326 * Output the search form
327 *
328 * @access public
329 * @subpackage Loop
330 * @return void
331 */
332 function propertyhive_search_form($id = 'default') {
333 ph_get_search_form( ( $id != '' ) ? $id : 'default' );
334 }
335 }
336
337 if ( ! function_exists( 'propertyhive_result_count' ) ) {
338
339 /**
340 * Output the result count text (Showing x - x of x results).
341 *
342 * @access public
343 * @subpackage Loop
344 * @return void
345 */
346 function propertyhive_result_count() {
347 ph_get_template( 'search/result-count.php' );
348 }
349 }
350
351 if ( ! function_exists( 'propertyhive_catalog_ordering' ) ) {
352
353 /**
354 * Output the property sorting options.
355 *
356 * @access public
357 * @subpackage Loop
358 * @return void
359 */
360 function propertyhive_catalog_ordering() {
361 $orderby = isset( $_GET['orderby'] ) ? ph_clean( $_GET['orderby'] ) : apply_filters( 'propertyhive_default_catalog_orderby', get_option( 'propertyhive_default_catalog_orderby' ) );
362
363 ph_get_template( 'search/orderby.php', array( 'orderby' => $orderby ) );
364 }
365 }
366
367 if ( ! function_exists( 'propertyhive_pagination' ) ) {
368
369 /**
370 * Output the pagination.
371 *
372 * @access public
373 * @subpackage Loop
374 * @return void
375 */
376 function propertyhive_pagination() {
377 ph_get_template( 'search/pagination.php' );
378 }
379 }
380
381 /** Single Product ********************************************************/
382
383 if ( ! function_exists( 'propertyhive_show_property_images' ) ) {
384
385 /**
386 * Output the property image before the single property summary.
387 *
388 * @access public
389 * @subpackage Property
390 * @return void
391 */
392 function propertyhive_show_property_images() {
393 ph_get_template( 'single-property/property-images.php' );
394 }
395 }
396
397 if ( ! function_exists( 'propertyhive_show_property_thumbnails' ) ) {
398
399 /**
400 * Output the property thumbnails.
401 *
402 * @access public
403 * @subpackage Property
404 * @return void
405 */
406 function propertyhive_show_property_thumbnails() {
407 ph_get_template( 'single-property/property-thumbnails.php' );
408 }
409 }
410
411 if ( ! function_exists( 'propertyhive_template_single_title' ) ) {
412
413 /**
414 * Output the property title.
415 *
416 * @access public
417 * @subpackage Property
418 * @return void
419 */
420 function propertyhive_template_single_title() {
421 ph_get_template( 'single-property/title.php' );
422 }
423 }
424
425 if ( ! function_exists( 'propertyhive_template_single_floor_area' ) ) {
426
427 /**
428 * Output the property floor area.
429 *
430 * @access public
431 * @subpackage Property
432 * @return void
433 */
434 function propertyhive_template_single_floor_area() {
435 ph_get_template( 'single-property/floor-area.php' );
436 }
437 }
438
439 if ( ! function_exists( 'propertyhive_template_single_price' ) ) {
440
441 /**
442 * Output the property price.
443 *
444 * @access public
445 * @subpackage Property
446 * @return void
447 */
448 function propertyhive_template_single_price() {
449 ph_get_template( 'single-property/price.php' );
450 }
451 }
452
453 if ( ! function_exists( 'propertyhive_template_single_meta' ) ) {
454
455 /**
456 * Output the product meta.
457 *
458 * @access public
459 * @subpackage Property
460 * @return void
461 */
462 function propertyhive_template_single_meta() {
463 ph_get_template( 'single-property/meta.php' );
464 }
465 }
466
467 if ( ! function_exists( 'propertyhive_template_single_sharing' ) ) {
468
469 /**
470 * Output the product sharing.
471 *
472 * @access public
473 * @subpackage Property
474 * @return void
475 */
476 function propertyhive_template_single_sharing() {
477 ph_get_template( 'single-property/share.php' );
478 }
479 }
480
481 if ( ! function_exists( 'propertyhive_template_single_actions' ) ) {
482
483 /**
484 * Output the product actions (make enquiry etc)
485 *
486 * @access public
487 * @subpackage Property
488 * @return void
489 */
490 function propertyhive_template_single_actions() {
491
492 global $post, $property;
493
494 $actions = array();
495
496 $floorplan_ids = $property->get_floorplan_attachment_ids();
497 if ( !empty( $floorplan_ids ) )
498 {
499 $floorplans_urls = array();
500 foreach ($floorplan_ids as $floorplan_id)
501 {
502 $floorplans_urls[] = wp_get_attachment_url( $floorplan_id );
503 }
504 $actions[] = array(
505 'href' => '',
506 'label' => __( 'Floorplans', 'propertyhive' ),
507 'class' => 'action-floorplans',
508 'attributes' => array(
509 'data-floorplan-urls' => implode("|", $floorplans_urls)
510 )
511 );
512 }
513
514 $brochure_ids = $property->get_brochure_attachment_ids();
515 if ( !empty( $brochure_ids ) )
516 {
517 foreach ($brochure_ids as $brochure_id)
518 {
519 $actions[] = array(
520 'href' => wp_get_attachment_url( $brochure_id ),
521 'label' => __( 'View Brochure', 'propertyhive' ),
522 'class' => 'action-brochure',
523 'attributes' => array(
524 'target' => '_blank'
525 )
526 );
527 }
528 }
529
530 $epc_ids = $property->get_epc_attachment_ids();
531 if ( !empty( $epc_ids ) )
532 {
533 foreach ($epc_ids as $epc_id)
534 {
535 $actions[] = array(
536 'href' => wp_get_attachment_url( $epc_id ),
537 'label' => __( 'View EPC', 'propertyhive' ),
538 'class' => 'action-epc',
539 'attributes' => array(
540 'target' => '_blank'
541 )
542 );
543 }
544 }
545
546 $virtual_tour_urls = $property->get_virtual_tour_urls();
547 if ( !empty( $virtual_tour_urls ) )
548 {
549 foreach ($virtual_tour_urls as $virtual_tour_url)
550 {
551 $actions[] = array(
552 'href' => $virtual_tour_url,
553 'label' => __( 'Virtual Tour', 'propertyhive' ),
554 'class' => 'action-virtual-tour',
555 'attributes' => array(
556 'target' => '_blank'
557 )
558 );
559 }
560 }
561
562 /*$actions[] = array(
563 'href' => '',
564 'label' => __( 'View on Map', 'propertyhive' ),
565 'class' => 'action-map'
566 );
567
568 $actions[] = array(
569 'href' => '',
570 'label' => __( 'Street View', 'propertyhive' ),
571 'class' => 'action-street-view'
572 );*/
573
574 $actions = apply_filters( 'propertyhive_single_property_actions', $actions );
575
576 ph_get_template( 'single-property/actions.php', array( 'actions' => $actions ) );
577 }
578 }
579
580 if ( ! function_exists( 'propertyhive_template_single_features' ) ) {
581
582 /**
583 * Output the property features.
584 *
585 * @access public
586 * @subpackage Property
587 * @return void
588 */
589 function propertyhive_template_single_features() {
590 ph_get_template( 'single-property/features.php' );
591 }
592 }
593
594 if ( ! function_exists( 'propertyhive_template_single_summary' ) ) {
595
596 /**
597 * Output the product summary description.
598 *
599 * @access public
600 * @subpackage Property
601 * @return void
602 */
603 function propertyhive_template_single_summary() {
604 ph_get_template( 'single-property/summary-description.php' );
605 }
606 }
607
608
609 if ( ! function_exists( 'propertyhive_template_single_description' ) ) {
610
611 /**
612 * Output the product rooms or descriptions to form a full description
613 *
614 * @access public
615 * @subpackage Property
616 * @return void
617 */
618 function propertyhive_template_single_description() {
619 ph_get_template( 'single-property/description.php' );
620 }
621 }
622
623 if ( ! function_exists( 'propertyhive_make_enquiry_button' ) ) {
624
625 /**
626 * Output the make enquiry button and lightbox
627 *
628 * @access public
629 * @subpackage Property
630 * @return void
631 */
632 function propertyhive_make_enquiry_button() {
633 ph_get_template( 'global/make-enquiry.php' );
634 }
635 }
636
637 function propertyhive_my_account_pages()
638 {
639 $user_id = get_current_user_id();
640
641 $contact = new PH_Contact( '', $user_id );
642
643 $pages = array(
644 'dashboard' => array(
645 'name' => __( 'Dashboard', 'propertyhive' )
646 ),
647 'details' => array(
648 'name' => __( 'My Details', 'propertyhive' )
649 ),
650 );
651
652 // Add 'requirements' tab if applicant
653
654 if ( !empty($contact->contact_types) )
655 {
656 $contact_types = $contact->contact_types;
657 if ( !is_array($contact_types) )
658 {
659 $contact_types = array($contact_types);
660 }
661 if ( in_array('applicant', $contact_types) )
662 {
663 $applicant_profiles = $contact->applicant_profiles;
664
665 if ( $applicant_profiles && $applicant_profiles > 0 )
666 {
667 for ( $i = 0; $i < $applicant_profiles; ++$i )
668 {
669 $pages['requirements'] = array(
670 'name' => __( 'Requirements', 'propertyhive' ),
671 );
672
673 break; // At the moment we'll only allow them to manage the first set of requirements
674 }
675 }
676
677 // Check viewing module is active and that viewings exist, either future or past
678 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
679 {
680 $args = array(
681 'post_type' => 'viewing',
682 'posts_per_page' => 1,
683 'post_status' => 'publish',
684 'fields' => 'ids',
685 'meta_query' => array(
686 array(
687 'key' => '_applicant_contact_id',
688 'value' => $contact->id
689 )
690 )
691 );
692 $viewings_query = new WP_Query( $args );
693
694 if ( $viewings_query->have_posts() )
695 {
696 $pages['applicant_viewings'] = array(
697 'name' => __( 'Viewings', 'propertyhive' ),
698 );
699 }
700 wp_reset_postdata();
701 }
702 }
703 }
704
705 // In future we'll add things like 'My properties', viewings if landlord/vendor, documents etc
706
707 $pages['logout'] = array(
708 'name' => __( 'Logout', 'propertyhive' ),
709 'href' => home_url() . '?logout=1' // Logout URL
710 );
711
712 $pages = apply_filters( 'propertyhive_my_account_pages', $pages );
713
714 return $pages;
715 }
716
717 if ( ! function_exists( 'propertyhive_my_account_navigation' ) ) {
718
719 /**
720 * Output the navigation/tabs within a users 'My Account' page
721 *
722 * @access public
723 * @return void
724 */
725 function propertyhive_my_account_navigation() {
726
727 $pages = propertyhive_my_account_pages();
728
729 ph_get_template( 'account/navigation.php', array( 'pages' => $pages ) );
730 }
731 }
732
733 if ( ! function_exists( 'propertyhive_my_account_sections' ) ) {
734
735 /**
736 * Output the main sections within a users 'My Account' page that relate to the navigation tabs/links
737 *
738 * @access public
739 * @return void
740 */
741 function propertyhive_my_account_sections() {
742
743 $pages = propertyhive_my_account_pages();
744
745 ph_get_template( 'account/sections.php', array( 'pages' => $pages ) );
746 }
747 }
748
749 if ( ! function_exists( 'propertyhive_my_account_dashboard' ) ) {
750
751 /**
752 * Output the dashboard section within a users account
753 *
754 * @access public
755 * @return void
756 */
757 function propertyhive_my_account_dashboard() {
758
759 ph_get_template( 'account/dashboard.php' );
760 }
761 }
762
763 if ( ! function_exists( 'propertyhive_my_account_details' ) ) {
764
765 /**
766 * Output the details section within a users account
767 *
768 * @access public
769 * @return void
770 */
771 function propertyhive_my_account_details() {
772
773 $form_controls = ph_get_user_details_form_fields();
774
775 $form_controls = apply_filters( 'propertyhive_user_details_form_fields', $form_controls );
776
777 // Make sure password fields aren't require
778 foreach ( $form_controls as $i => $form_control )
779 {
780 if ( $form_control['type'] == 'password' )
781 {
782 $form_control['required'] = false;
783
784 $form_controls[$i] = $form_control;
785 }
786 }
787
788 ph_get_template( 'account/details.php', array( 'form_controls' => $form_controls ) );
789 }
790 }
791
792 if ( ! function_exists( 'propertyhive_my_account_requirements' ) ) {
793
794 /**
795 * Output the requirements section within a users account
796 *
797 * @access public
798 * @return void
799 */
800 function propertyhive_my_account_requirements() {
801
802 $form_controls = ph_get_applicant_requirements_form_fields();
803
804 $form_controls = apply_filters( 'propertyhive_applicant_requirements_form_fields', $form_controls );
805
806 // Remove office as this is only required on initial sign up (at the moment anyway)
807 if ( isset($form_controls['office_id']) )
808 {
809 unset($form_controls['office_id']);
810 }
811
812 ph_get_template( 'account/requirements.php', array( 'form_controls' => $form_controls ) );
813 }
814 }
815
816 if ( ! function_exists( 'propertyhive_my_account_applicant_viewings' ) ) {
817
818 /**
819 * Output the applicant viewings section within a users account
820 *
821 * @access public
822 * @return void
823 */
824 function propertyhive_my_account_applicant_viewings() {
825
826 $user_id = get_current_user_id();
827
828 $contact = new PH_Contact( '', $user_id );
829
830 $past_viewings = array();
831 $upcoming_viewings = array();
832
833 $args = array(
834 'post_type' => 'viewing',
835 'nopaging' => 'true',
836 'post_status' => 'publish',
837 'fields' => 'ids',
838 'orderby' => 'meta_value',
839 'order' => 'DESC',
840 'post_status' => 'publish',
841 'meta_key' => '_start_date_time',
842 'meta_query' => array(
843 array(
844 'key' => '_applicant_contact_id',
845 'value' => $contact->id
846 )
847 )
848 );
849
850 // Do past viewings
851 $args2 = $args;
852 $args2['meta_query'][] = array(
853 'key' => '_start_date_time',
854 'value' => date("Y-m-d H:i:s"),
855 'compare' => '<='
856 );
857
858 $viewings_query = new WP_Query( $args2 );
859
860 if ( $viewings_query->have_posts() )
861 {
862 while ( $viewings_query->have_posts() )
863 {
864 $viewings_query->the_post();
865
866 $viewing = new PH_Viewing( get_the_ID() );
867
868 $past_viewings[] = $viewing;
869 }
870 }
871 wp_reset_postdata();
872
873 // Do upcoming viewings
874 $args2 = $args;
875 $args2['meta_query'][] = array(
876 'key' => '_start_date_time',
877 'value' => date("Y-m-d H:i:s"),
878 'compare' => '>='
879 );
880
881 $viewings_query = new WP_Query( $args2 );
882
883 if ( $viewings_query->have_posts() )
884 {
885 while ( $viewings_query->have_posts() )
886 {
887 $viewings_query->the_post();
888
889 $viewing = new PH_Viewing( get_the_ID() );
890
891 $upcoming_viewings[] = $viewing;
892 }
893 }
894 wp_reset_postdata();
895
896 ph_get_template( 'account/applicant-viewings.php', array( 'past_viewings' => $past_viewings, 'upcoming_viewings' => $upcoming_viewings ) );
897 }
898 }