| 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: “%s”', 'propertyhive' ), get_search_query() ); |
| 165 |
|
| 166 |
if ( get_query_var( 'paged' ) ) |
| 167 |
$page_title .= sprintf( __( ' – 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 |
if ( in_array('owner', $contact_types) ) |
| 704 |
{ |
| 705 |
// Get properties belonging to this owner |
| 706 |
$args = array( |
| 707 |
'post_type' => 'property', |
| 708 |
'posts_per_page' => 1, |
| 709 |
'post_status' => 'publish', |
| 710 |
'fields' => 'ids', |
| 711 |
'meta_query' => array( |
| 712 |
array( |
| 713 |
'key' => '_owner_contact_id', |
| 714 |
'value' => ':' . $contact->id . ';', |
| 715 |
'compare' => 'LIKE' |
| 716 |
) |
| 717 |
) |
| 718 |
); |
| 719 |
|
| 720 |
$properties_query = new WP_Query( $args ); |
| 721 |
|
| 722 |
$property_ids = array(); |
| 723 |
|
| 724 |
if ( $properties_query->have_posts() ) |
| 725 |
{ |
| 726 |
while ( $properties_query->have_posts() ) |
| 727 |
{ |
| 728 |
$properties_query->the_post(); |
| 729 |
|
| 730 |
$property_ids[] = get_the_id(); |
| 731 |
} |
| 732 |
|
| 733 |
$pages['owner_properties'] = array( |
| 734 |
'name' => __( 'Properties', 'propertyhive' ), |
| 735 |
); |
| 736 |
} |
| 737 |
wp_reset_postdata(); |
| 738 |
|
| 739 |
// Check viewing module is active and that viewings exist, either future or past |
| 740 |
if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' ) |
| 741 |
{ |
| 742 |
$past_viewings = array(); |
| 743 |
$upcoming_viewings = array(); |
| 744 |
|
| 745 |
if ( !empty($property_ids) ) |
| 746 |
{ |
| 747 |
$args = array( |
| 748 |
'post_type' => 'viewing', |
| 749 |
'posts_per_page' => 1, |
| 750 |
'post_status' => 'publish', |
| 751 |
'fields' => 'ids', |
| 752 |
'meta_query' => array( |
| 753 |
array( |
| 754 |
'key' => '_property_id', |
| 755 |
'value' => $property_ids, |
| 756 |
'compare' => 'IN' |
| 757 |
) |
| 758 |
) |
| 759 |
); |
| 760 |
$viewings_query = new WP_Query( $args ); |
| 761 |
|
| 762 |
if ( $viewings_query->have_posts() ) |
| 763 |
{ |
| 764 |
$pages['owner_viewings'] = array( |
| 765 |
'name' => __( 'Viewings', 'propertyhive' ), |
| 766 |
); |
| 767 |
} |
| 768 |
wp_reset_postdata(); |
| 769 |
} |
| 770 |
} |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
// In future we'll add things like 'My properties', viewings if landlord/vendor, documents etc |
| 775 |
|
| 776 |
$pages['logout'] = array( |
| 777 |
'name' => __( 'Logout', 'propertyhive' ), |
| 778 |
'href' => home_url() . '?logout=1' // Logout URL |
| 779 |
); |
| 780 |
|
| 781 |
$pages = apply_filters( 'propertyhive_my_account_pages', $pages ); |
| 782 |
|
| 783 |
return $pages; |
| 784 |
} |
| 785 |
|
| 786 |
if ( ! function_exists( 'propertyhive_my_account_navigation' ) ) { |
| 787 |
|
| 788 |
/** |
| 789 |
* Output the navigation/tabs within a users 'My Account' page |
| 790 |
* |
| 791 |
* @access public |
| 792 |
* @return void |
| 793 |
*/ |
| 794 |
function propertyhive_my_account_navigation() { |
| 795 |
|
| 796 |
$pages = propertyhive_my_account_pages(); |
| 797 |
|
| 798 |
ph_get_template( 'account/navigation.php', array( 'pages' => $pages ) ); |
| 799 |
} |
| 800 |
} |
| 801 |
|
| 802 |
if ( ! function_exists( 'propertyhive_my_account_sections' ) ) { |
| 803 |
|
| 804 |
/** |
| 805 |
* Output the main sections within a users 'My Account' page that relate to the navigation tabs/links |
| 806 |
* |
| 807 |
* @access public |
| 808 |
* @return void |
| 809 |
*/ |
| 810 |
function propertyhive_my_account_sections() { |
| 811 |
|
| 812 |
$pages = propertyhive_my_account_pages(); |
| 813 |
|
| 814 |
ph_get_template( 'account/sections.php', array( 'pages' => $pages ) ); |
| 815 |
} |
| 816 |
} |
| 817 |
|
| 818 |
if ( ! function_exists( 'propertyhive_my_account_dashboard' ) ) { |
| 819 |
|
| 820 |
/** |
| 821 |
* Output the dashboard section within a users account |
| 822 |
* |
| 823 |
* @access public |
| 824 |
* @return void |
| 825 |
*/ |
| 826 |
function propertyhive_my_account_dashboard() { |
| 827 |
|
| 828 |
ph_get_template( 'account/dashboard.php' ); |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
if ( ! function_exists( 'propertyhive_my_account_details' ) ) { |
| 833 |
|
| 834 |
/** |
| 835 |
* Output the details section within a users account |
| 836 |
* |
| 837 |
* @access public |
| 838 |
* @return void |
| 839 |
*/ |
| 840 |
function propertyhive_my_account_details() { |
| 841 |
|
| 842 |
$form_controls = ph_get_user_details_form_fields(); |
| 843 |
|
| 844 |
$form_controls = apply_filters( 'propertyhive_user_details_form_fields', $form_controls ); |
| 845 |
|
| 846 |
// Make sure password fields aren't require |
| 847 |
foreach ( $form_controls as $i => $form_control ) |
| 848 |
{ |
| 849 |
if ( $form_control['type'] == 'password' ) |
| 850 |
{ |
| 851 |
$form_control['required'] = false; |
| 852 |
|
| 853 |
$form_controls[$i] = $form_control; |
| 854 |
} |
| 855 |
} |
| 856 |
|
| 857 |
ph_get_template( 'account/details.php', array( 'form_controls' => $form_controls ) ); |
| 858 |
} |
| 859 |
} |
| 860 |
|
| 861 |
if ( ! function_exists( 'propertyhive_my_account_requirements' ) ) { |
| 862 |
|
| 863 |
/** |
| 864 |
* Output the requirements section within a users account |
| 865 |
* |
| 866 |
* @access public |
| 867 |
* @return void |
| 868 |
*/ |
| 869 |
function propertyhive_my_account_requirements() { |
| 870 |
|
| 871 |
$form_controls = ph_get_applicant_requirements_form_fields(); |
| 872 |
|
| 873 |
$form_controls = apply_filters( 'propertyhive_applicant_requirements_form_fields', $form_controls ); |
| 874 |
|
| 875 |
// Remove office as this is only required on initial sign up (at the moment anyway) |
| 876 |
if ( isset($form_controls['office_id']) ) |
| 877 |
{ |
| 878 |
unset($form_controls['office_id']); |
| 879 |
} |
| 880 |
|
| 881 |
ph_get_template( 'account/requirements.php', array( 'form_controls' => $form_controls ) ); |
| 882 |
} |
| 883 |
} |
| 884 |
|
| 885 |
if ( ! function_exists( 'propertyhive_my_account_applicant_viewings' ) ) { |
| 886 |
|
| 887 |
/** |
| 888 |
* Output the applicant viewings section within a users account |
| 889 |
* |
| 890 |
* @access public |
| 891 |
* @return void |
| 892 |
*/ |
| 893 |
function propertyhive_my_account_applicant_viewings() { |
| 894 |
|
| 895 |
$user_id = get_current_user_id(); |
| 896 |
|
| 897 |
$contact = new PH_Contact( '', $user_id ); |
| 898 |
|
| 899 |
$past_viewings = array(); |
| 900 |
$upcoming_viewings = array(); |
| 901 |
|
| 902 |
$args = array( |
| 903 |
'post_type' => 'viewing', |
| 904 |
'nopaging' => 'true', |
| 905 |
'post_status' => 'publish', |
| 906 |
'fields' => 'ids', |
| 907 |
'orderby' => 'meta_value', |
| 908 |
'order' => 'DESC', |
| 909 |
'post_status' => 'publish', |
| 910 |
'meta_key' => '_start_date_time', |
| 911 |
'meta_query' => array( |
| 912 |
array( |
| 913 |
'key' => '_applicant_contact_id', |
| 914 |
'value' => $contact->id |
| 915 |
) |
| 916 |
) |
| 917 |
); |
| 918 |
|
| 919 |
// Do past viewings |
| 920 |
$args2 = $args; |
| 921 |
$args2['meta_query'][] = array( |
| 922 |
'key' => '_start_date_time', |
| 923 |
'value' => date("Y-m-d H:i:s"), |
| 924 |
'compare' => '<=' |
| 925 |
); |
| 926 |
|
| 927 |
$viewings_query = new WP_Query( $args2 ); |
| 928 |
|
| 929 |
if ( $viewings_query->have_posts() ) |
| 930 |
{ |
| 931 |
while ( $viewings_query->have_posts() ) |
| 932 |
{ |
| 933 |
$viewings_query->the_post(); |
| 934 |
|
| 935 |
$viewing = new PH_Viewing( get_the_ID() ); |
| 936 |
|
| 937 |
$past_viewings[] = $viewing; |
| 938 |
} |
| 939 |
} |
| 940 |
wp_reset_postdata(); |
| 941 |
|
| 942 |
// Do upcoming viewings |
| 943 |
$args2 = $args; |
| 944 |
$args2['meta_query'][] = array( |
| 945 |
'key' => '_start_date_time', |
| 946 |
'value' => date("Y-m-d H:i:s"), |
| 947 |
'compare' => '>=' |
| 948 |
); |
| 949 |
|
| 950 |
$viewings_query = new WP_Query( $args2 ); |
| 951 |
|
| 952 |
if ( $viewings_query->have_posts() ) |
| 953 |
{ |
| 954 |
while ( $viewings_query->have_posts() ) |
| 955 |
{ |
| 956 |
$viewings_query->the_post(); |
| 957 |
|
| 958 |
$viewing = new PH_Viewing( get_the_ID() ); |
| 959 |
|
| 960 |
$upcoming_viewings[] = $viewing; |
| 961 |
} |
| 962 |
} |
| 963 |
wp_reset_postdata(); |
| 964 |
|
| 965 |
ph_get_template( 'account/applicant-viewings.php', array( 'past_viewings' => $past_viewings, 'upcoming_viewings' => $upcoming_viewings ) ); |
| 966 |
} |
| 967 |
} |
| 968 |
|
| 969 |
if ( ! function_exists( 'propertyhive_my_account_owner_properties' ) ) { |
| 970 |
|
| 971 |
/** |
| 972 |
* Output the owner properties section within a users account |
| 973 |
* |
| 974 |
* @access public |
| 975 |
* @return void |
| 976 |
*/ |
| 977 |
function propertyhive_my_account_owner_properties() { |
| 978 |
|
| 979 |
$user_id = get_current_user_id(); |
| 980 |
|
| 981 |
$contact = new PH_Contact( '', $user_id ); |
| 982 |
|
| 983 |
// Get properties belonging to this owner |
| 984 |
$args = array( |
| 985 |
'post_type' => 'property', |
| 986 |
'nopaging' => true, |
| 987 |
'post_status' => 'publish', |
| 988 |
'fields' => 'ids', |
| 989 |
'meta_query' => array( |
| 990 |
array( |
| 991 |
'key' => '_owner_contact_id', |
| 992 |
'value' => ':' . $contact->id . ';', |
| 993 |
'compare' => 'LIKE' |
| 994 |
) |
| 995 |
) |
| 996 |
); |
| 997 |
|
| 998 |
$properties_query = new WP_Query( $args ); |
| 999 |
|
| 1000 |
$properties = array(); |
| 1001 |
|
| 1002 |
if ( $properties_query->have_posts() ) |
| 1003 |
{ |
| 1004 |
while ( $properties_query->have_posts() ) |
| 1005 |
{ |
| 1006 |
$properties_query->the_post(); |
| 1007 |
|
| 1008 |
$properties[] = new PH_Property( get_the_id() ); |
| 1009 |
} |
| 1010 |
} |
| 1011 |
wp_reset_postdata(); |
| 1012 |
ph_get_template( 'account/owner-properties.php', array( 'properties' => $properties ) ); |
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
if ( ! function_exists( 'propertyhive_my_account_owner_viewings' ) ) { |
| 1017 |
|
| 1018 |
/** |
| 1019 |
* Output the owner viewings section within a users account |
| 1020 |
* |
| 1021 |
* @access public |
| 1022 |
* @return void |
| 1023 |
*/ |
| 1024 |
function propertyhive_my_account_owner_viewings() { |
| 1025 |
|
| 1026 |
$user_id = get_current_user_id(); |
| 1027 |
|
| 1028 |
$contact = new PH_Contact( '', $user_id ); |
| 1029 |
|
| 1030 |
// Get properties belonging to this owner |
| 1031 |
$args = array( |
| 1032 |
'post_type' => 'property', |
| 1033 |
'nopaging' => true, |
| 1034 |
'post_status' => 'publish', |
| 1035 |
'fields' => 'ids', |
| 1036 |
'meta_query' => array( |
| 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 |
wp_reset_postdata(); |
| 1059 |
|
| 1060 |
$past_viewings = array(); |
| 1061 |
$upcoming_viewings = array(); |
| 1062 |
|
| 1063 |
if ( !empty($property_ids) ) |
| 1064 |
{ |
| 1065 |
$args = array( |
| 1066 |
'post_type' => 'viewing', |
| 1067 |
'nopaging' => true, |
| 1068 |
'post_status' => 'publish', |
| 1069 |
'fields' => 'ids', |
| 1070 |
'orderby' => 'meta_value', |
| 1071 |
'order' => 'DESC', |
| 1072 |
'post_status' => 'publish', |
| 1073 |
'meta_key' => '_start_date_time', |
| 1074 |
'meta_query' => array( |
| 1075 |
array( |
| 1076 |
'key' => '_property_id', |
| 1077 |
'value' => $property_ids, |
| 1078 |
'compare' => 'IN' |
| 1079 |
) |
| 1080 |
) |
| 1081 |
); |
| 1082 |
|
| 1083 |
// Do past viewings |
| 1084 |
$args2 = $args; |
| 1085 |
$args2['meta_query'][] = array( |
| 1086 |
'key' => '_start_date_time', |
| 1087 |
'value' => date("Y-m-d H:i:s"), |
| 1088 |
'compare' => '<=' |
| 1089 |
); |
| 1090 |
|
| 1091 |
$viewings_query = new WP_Query( $args2 ); |
| 1092 |
|
| 1093 |
if ( $viewings_query->have_posts() ) |
| 1094 |
{ |
| 1095 |
while ( $viewings_query->have_posts() ) |
| 1096 |
{ |
| 1097 |
$viewings_query->the_post(); |
| 1098 |
|
| 1099 |
$viewing = new PH_Viewing( get_the_ID() ); |
| 1100 |
|
| 1101 |
$past_viewings[] = $viewing; |
| 1102 |
} |
| 1103 |
} |
| 1104 |
wp_reset_postdata(); |
| 1105 |
|
| 1106 |
// Do upcoming viewings |
| 1107 |
$args2 = $args; |
| 1108 |
$args2['meta_query'][] = array( |
| 1109 |
'key' => '_start_date_time', |
| 1110 |
'value' => date("Y-m-d H:i:s"), |
| 1111 |
'compare' => '>=' |
| 1112 |
); |
| 1113 |
|
| 1114 |
$viewings_query = new WP_Query( $args2 ); |
| 1115 |
|
| 1116 |
if ( $viewings_query->have_posts() ) |
| 1117 |
{ |
| 1118 |
while ( $viewings_query->have_posts() ) |
| 1119 |
{ |
| 1120 |
$viewings_query->the_post(); |
| 1121 |
|
| 1122 |
$viewing = new PH_Viewing( get_the_ID() ); |
| 1123 |
|
| 1124 |
$upcoming_viewings[] = $viewing; |
| 1125 |
} |
| 1126 |
} |
| 1127 |
wp_reset_postdata(); |
| 1128 |
} |
| 1129 |
|
| 1130 |
ph_get_template( 'account/owner-viewings.php', array( 'past_viewings' => $past_viewings, 'upcoming_viewings' => $upcoming_viewings ) ); |
| 1131 |
} |
| 1132 |
} |