| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 |
|
| 5 |
/** |
| 6 |
* PH_Shortcodes class. |
| 7 |
* |
| 8 |
* @class PH_Shortcodes |
| 9 |
* @version 1.0.0 |
| 10 |
* @package PropertyHive/Classes |
| 11 |
* @category Class |
| 12 |
* @author PropertyHive |
| 13 |
*/ |
| 14 |
class PH_Shortcodes { |
| 15 |
|
| 16 |
/** |
| 17 |
* Init shortcodes |
| 18 |
*/ |
| 19 |
public static function init() { |
| 20 |
// Define shortcodes |
| 21 |
$shortcodes = array( |
| 22 |
'properties' => __CLASS__ . '::properties', |
| 23 |
'recent_properties' => __CLASS__ . '::recent_properties', |
| 24 |
'featured_properties' => __CLASS__ . '::featured_properties', |
| 25 |
'similar_properties' => __CLASS__ . '::similar_properties', |
| 26 |
'property_search_form' => __CLASS__ . '::property_search_form', |
| 27 |
'property_map' => __CLASS__ . '::property_map', |
| 28 |
'property_street_view' => __CLASS__ . '::property_street_view', |
| 29 |
'property_office_details' => __CLASS__ . '::property_office_details', |
| 30 |
'applicant_registration_form' => __CLASS__ . '::applicant_registration_form', |
| 31 |
'propertyhive_my_account' => __CLASS__ . '::my_account', |
| 32 |
'propertyhive_login_form' => __CLASS__ . '::login_form', |
| 33 |
); |
| 34 |
|
| 35 |
foreach ( $shortcodes as $shortcode => $function ) { |
| 36 |
add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function ); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Shortcode Wrapper |
| 42 |
* |
| 43 |
* @param mixed $function |
| 44 |
* @param array $atts (default: array()) |
| 45 |
* @return string |
| 46 |
*/ |
| 47 |
public static function shortcode_wrapper( |
| 48 |
$function, |
| 49 |
$atts = array(), |
| 50 |
$wrapper = array( |
| 51 |
'class' => 'propertyhive', |
| 52 |
'before' => null, |
| 53 |
'after' => null |
| 54 |
) |
| 55 |
) { |
| 56 |
ob_start(); |
| 57 |
|
| 58 |
$before = empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before']; |
| 59 |
$after = empty( $wrapper['after'] ) ? '</div>' : $wrapper['after']; |
| 60 |
|
| 61 |
echo $before; |
| 62 |
call_user_func( $function, $atts ); |
| 63 |
echo $after; |
| 64 |
|
| 65 |
return ob_get_clean(); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Output property search form |
| 70 |
* |
| 71 |
* @param array $atts |
| 72 |
* @return string |
| 73 |
*/ |
| 74 |
public static function property_search_form( $atts ) { |
| 75 |
$atts = shortcode_atts( array( |
| 76 |
'id' => 'shortcode' |
| 77 |
), $atts ); |
| 78 |
|
| 79 |
$form_controls = ph_get_search_form_fields(); |
| 80 |
|
| 81 |
$form_controls = apply_filters( 'propertyhive_search_form_fields_' . $atts['id'], $form_controls ); |
| 82 |
|
| 83 |
// We 100% need department so make sure it exists. If it doesn't, set a hidden field |
| 84 |
if ( !isset($form_controls['department']) ) |
| 85 |
{ |
| 86 |
$original_form_controls = ph_get_search_form_fields(); |
| 87 |
$original_department = $original_form_controls['department']; |
| 88 |
$original_department['type'] = 'hidden'; |
| 89 |
|
| 90 |
$form_controls['department'] = $original_department; |
| 91 |
} |
| 92 |
|
| 93 |
ob_start(); |
| 94 |
|
| 95 |
ph_get_template( 'global/search-form.php', array( 'form_controls' => $form_controls, 'id' => $atts['id'] ) ); |
| 96 |
|
| 97 |
return ob_get_clean(); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* List multiple properties shortcode |
| 102 |
* |
| 103 |
* @param array $atts |
| 104 |
* @return string |
| 105 |
*/ |
| 106 |
public static function properties( $atts ) { |
| 107 |
$atts = shortcode_atts( array( |
| 108 |
'columns' => '2', |
| 109 |
'orderby' => 'meta_value_num', |
| 110 |
'order' => 'desc', |
| 111 |
'meta_key' => '_price_actual', |
| 112 |
'ids' => '', |
| 113 |
'department' => '', // residential-sales / residential-lettings / commercial |
| 114 |
'bedrooms' => '', |
| 115 |
'address_keyword' => '', |
| 116 |
'marketing_flag' => '', // Should be marketing_flag_id. Might deprecate this in the future |
| 117 |
'property_type_id' => '', |
| 118 |
'location_id' => '', |
| 119 |
'office_id' => '', |
| 120 |
'posts_per_page' => 10 |
| 121 |
), $atts ); |
| 122 |
|
| 123 |
$meta_query = array( |
| 124 |
array( |
| 125 |
'key' => '_on_market', |
| 126 |
'value' => 'yes', |
| 127 |
) |
| 128 |
); |
| 129 |
|
| 130 |
if ( isset($atts['department']) && in_array($atts['department'], array("residential-sales", "residential-lettings", "commercial")) ) |
| 131 |
{ |
| 132 |
$meta_query[] = array( |
| 133 |
'key' => '_department', |
| 134 |
'value' => $atts['department'], |
| 135 |
'compare' => '=' |
| 136 |
); |
| 137 |
} |
| 138 |
|
| 139 |
if ( isset($atts['bedrooms']) && $atts['bedrooms'] != '' && is_numeric($atts['bedrooms']) ) |
| 140 |
{ |
| 141 |
$meta_query[] = array( |
| 142 |
'key' => '_bedrooms', |
| 143 |
'value' => sanitize_text_field( $atts['bedrooms'] ), |
| 144 |
'compare' => '=' |
| 145 |
); |
| 146 |
} |
| 147 |
|
| 148 |
if ( isset($atts['address_keyword']) && $atts['address_keyword'] != '' ) |
| 149 |
{ |
| 150 |
$atts['address_keyword'] = sanitize_text_field( trim( $atts['address_keyword'] ) ); |
| 151 |
|
| 152 |
$address_keywords = array( $atts['address_keyword'] ); |
| 153 |
|
| 154 |
if ( strpos( $atts['address_keyword'], ' ' ) !== FALSE ) |
| 155 |
{ |
| 156 |
$address_keywords[] = str_replace(" ", "-", $atts['address_keyword']); |
| 157 |
} |
| 158 |
if ( strpos( $atts['address_keyword'], '-' ) !== FALSE ) |
| 159 |
{ |
| 160 |
$address_keywords[] = str_replace("-", " ", $atts['address_keyword']); |
| 161 |
} |
| 162 |
|
| 163 |
$sub_meta_query = array('relation' => 'OR'); |
| 164 |
|
| 165 |
foreach ( $address_keywords as $address_keyword ) |
| 166 |
{ |
| 167 |
$sub_meta_query[] = array( |
| 168 |
'key' => '_reference_number', |
| 169 |
'value' => $address_keyword, |
| 170 |
'compare' => get_option( 'propertyhive_address_keyword_compare', '=' ) |
| 171 |
); |
| 172 |
$sub_meta_query[] = array( |
| 173 |
'key' => '_address_street', |
| 174 |
'value' => $address_keyword, |
| 175 |
'compare' => get_option( 'propertyhive_address_keyword_compare', '=' ) |
| 176 |
); |
| 177 |
$sub_meta_query[] = array( |
| 178 |
'key' => '_address_two', |
| 179 |
'value' => $address_keyword, |
| 180 |
'compare' => get_option( 'propertyhive_address_keyword_compare', '=' ) |
| 181 |
); |
| 182 |
$sub_meta_query[] = array( |
| 183 |
'key' => '_address_three', |
| 184 |
'value' => $address_keyword, |
| 185 |
'compare' => get_option( 'propertyhive_address_keyword_compare', '=' ) |
| 186 |
); |
| 187 |
$sub_meta_query[] = array( |
| 188 |
'key' => '_address_four', |
| 189 |
'value' => $address_keyword, |
| 190 |
'compare' => get_option( 'propertyhive_address_keyword_compare', '=' ) |
| 191 |
); |
| 192 |
} |
| 193 |
if ( strlen($atts['address_keyword']) <= 4 ) |
| 194 |
{ |
| 195 |
$sub_meta_query[] = array( |
| 196 |
'key' => '_address_postcode', |
| 197 |
'value' => sanitize_text_field( $atts['address_keyword'] ), |
| 198 |
'compare' => '=' |
| 199 |
); |
| 200 |
$sub_meta_query[] = array( |
| 201 |
'key' => '_address_postcode', |
| 202 |
'value' => sanitize_text_field( $atts['address_keyword'] ) . '[ ]', |
| 203 |
'compare' => 'RLIKE' |
| 204 |
); |
| 205 |
} |
| 206 |
else |
| 207 |
{ |
| 208 |
$sub_meta_query[] = array( |
| 209 |
'key' => '_address_postcode', |
| 210 |
'value' => sanitize_text_field( $atts['address_keyword'] ), |
| 211 |
'compare' => 'LIKE' |
| 212 |
); |
| 213 |
} |
| 214 |
|
| 215 |
$meta_query[] = $sub_meta_query; |
| 216 |
} |
| 217 |
|
| 218 |
if ( isset($atts['office_id']) && $atts['office_id'] != '' ) |
| 219 |
{ |
| 220 |
$office_ids = explode(",", $atts['office_id']); |
| 221 |
|
| 222 |
$meta_query[] = array( |
| 223 |
'key' => '_office_id', |
| 224 |
'value' => $office_ids, |
| 225 |
'compare' => 'IN' |
| 226 |
); |
| 227 |
} |
| 228 |
|
| 229 |
$tax_query = array(); |
| 230 |
|
| 231 |
if ( isset($atts['marketing_flag']) && $atts['marketing_flag'] != '' ) |
| 232 |
{ |
| 233 |
$tax_query[] = array( |
| 234 |
'taxonomy' => 'marketing_flag', |
| 235 |
'terms' => array( $atts['marketing_flag'] ) |
| 236 |
); |
| 237 |
} |
| 238 |
|
| 239 |
if ( isset($atts['property_type_id']) && $atts['property_type_id'] != '' ) |
| 240 |
{ |
| 241 |
$tax_query[] = array( |
| 242 |
'taxonomy' => 'property_type', |
| 243 |
'terms' => array( $atts['property_type_id'] ) |
| 244 |
); |
| 245 |
} |
| 246 |
|
| 247 |
if ( isset($atts['location_id']) && $atts['location_id'] != '' ) |
| 248 |
{ |
| 249 |
$tax_query[] = array( |
| 250 |
'taxonomy' => 'location', |
| 251 |
'terms' => array( $atts['location_id'] ) |
| 252 |
); |
| 253 |
} |
| 254 |
|
| 255 |
if ( isset($atts['department']) && $atts['department'] == 'commercial' ) |
| 256 |
{ |
| 257 |
$atts['meta_key'] = '_floor_area_from_sqft'; |
| 258 |
} |
| 259 |
|
| 260 |
$args = array( |
| 261 |
'post_type' => 'property', |
| 262 |
'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ), |
| 263 |
'ignore_sticky_posts' => 1, |
| 264 |
'orderby' => $atts['orderby'], |
| 265 |
'order' => $atts['order'], |
| 266 |
'posts_per_page' => $atts['posts_per_page'], |
| 267 |
'meta_query' => $meta_query, |
| 268 |
'tax_query' => $tax_query |
| 269 |
); |
| 270 |
if ( ! empty( $atts['meta_key'] ) ) { |
| 271 |
$args['meta_key'] = $atts['meta_key']; |
| 272 |
} |
| 273 |
|
| 274 |
if ( ! empty( $atts['ids'] ) ) { |
| 275 |
$args['post__in'] = array_map( 'trim', explode( ',', $atts['ids'] ) ); |
| 276 |
} |
| 277 |
|
| 278 |
ob_start(); |
| 279 |
|
| 280 |
$properties = new WP_Query( apply_filters( 'propertyhive_properties_query', $args, $atts ) ); |
| 281 |
|
| 282 |
$propertyhive_loop['columns'] = $atts['columns']; |
| 283 |
|
| 284 |
if ( $properties->have_posts() ) : ?> |
| 285 |
|
| 286 |
<?php propertyhive_property_loop_start(); ?> |
| 287 |
|
| 288 |
<?php while ( $properties->have_posts() ) : $properties->the_post(); ?> |
| 289 |
|
| 290 |
<?php ph_get_template_part( 'content', 'property' ); ?> |
| 291 |
|
| 292 |
<?php endwhile; // end of the loop. ?> |
| 293 |
|
| 294 |
<?php propertyhive_property_loop_end(); ?> |
| 295 |
|
| 296 |
<?php endif; |
| 297 |
|
| 298 |
wp_reset_postdata(); |
| 299 |
|
| 300 |
return '<div class="propertyhive propertyhive-properties-shortcode columns-' . $atts['columns'] . '">' . ob_get_clean() . '</div>'; |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* Recent Properties shortcode |
| 305 |
* |
| 306 |
* @access public |
| 307 |
* @param array $atts |
| 308 |
* @return string |
| 309 |
*/ |
| 310 |
public static function recent_properties( $atts ) { |
| 311 |
global $propertyhive_loop; |
| 312 |
|
| 313 |
$atts = shortcode_atts( array( |
| 314 |
'per_page' => '12', |
| 315 |
'columns' => '4', |
| 316 |
'department' => '', |
| 317 |
'office_id' => '', |
| 318 |
'orderby' => 'date', |
| 319 |
'order' => 'desc' |
| 320 |
), $atts ); |
| 321 |
|
| 322 |
$meta_query = PH()->query->get_meta_query(); |
| 323 |
|
| 324 |
if ( isset($atts['department']) && $atts['department'] != '' ) |
| 325 |
{ |
| 326 |
$meta_query[] = array( |
| 327 |
'key' => '_department', |
| 328 |
'value' => $atts['department'], |
| 329 |
'compare' => '=' |
| 330 |
); |
| 331 |
} |
| 332 |
|
| 333 |
if ( isset($atts['office_id']) && $atts['office_id'] != '' ) |
| 334 |
{ |
| 335 |
$office_ids = explode(",", $atts['office_id']); |
| 336 |
|
| 337 |
$meta_query[] = array( |
| 338 |
'key' => '_office_id', |
| 339 |
'value' => $office_ids, |
| 340 |
'compare' => 'IN' |
| 341 |
); |
| 342 |
} |
| 343 |
|
| 344 |
$args = array( |
| 345 |
'post_type' => 'property', |
| 346 |
'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ), |
| 347 |
'ignore_sticky_posts' => 1, |
| 348 |
'posts_per_page' => $atts['per_page'], |
| 349 |
'orderby' => $atts['orderby'], |
| 350 |
'order' => $atts['order'], |
| 351 |
'meta_query' => $meta_query |
| 352 |
); |
| 353 |
|
| 354 |
ob_start(); |
| 355 |
|
| 356 |
$properties = new WP_Query( apply_filters( 'propertyhive_shortcode_recent_properties_query', $args, $atts ) ); |
| 357 |
|
| 358 |
$propertyhive_loop['columns'] = $atts['columns']; |
| 359 |
|
| 360 |
if ( $properties->have_posts() ) : ?> |
| 361 |
|
| 362 |
<?php propertyhive_property_loop_start(); ?> |
| 363 |
|
| 364 |
<?php while ( $properties->have_posts() ) : $properties->the_post(); ?> |
| 365 |
|
| 366 |
<?php ph_get_template_part( 'content', 'property-recent' ); ?> |
| 367 |
|
| 368 |
<?php endwhile; // end of the loop. ?> |
| 369 |
|
| 370 |
<?php propertyhive_property_loop_end(); ?> |
| 371 |
|
| 372 |
<?php endif; |
| 373 |
|
| 374 |
wp_reset_postdata(); |
| 375 |
|
| 376 |
return '<div class="propertyhive propertyhive-recent-properties-shortcode columns-' . $atts['columns'] . '">' . ob_get_clean() . '</div>'; |
| 377 |
} |
| 378 |
|
| 379 |
/** |
| 380 |
* Output featured properties |
| 381 |
* |
| 382 |
* @access public |
| 383 |
* @param array $atts |
| 384 |
* @return string |
| 385 |
*/ |
| 386 |
public static function featured_properties( $atts ) { |
| 387 |
global $propertyhive_loop; |
| 388 |
|
| 389 |
$atts = shortcode_atts( array( |
| 390 |
'per_page' => '12', |
| 391 |
'columns' => '4', |
| 392 |
'department' => '', |
| 393 |
'office_id' => '', |
| 394 |
'orderby' => 'rand', |
| 395 |
'order' => 'desc', |
| 396 |
'meta_key' => '', |
| 397 |
), $atts ); |
| 398 |
|
| 399 |
$args = array( |
| 400 |
'post_type' => 'property', |
| 401 |
'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ), |
| 402 |
'ignore_sticky_posts' => 1, |
| 403 |
'posts_per_page' => $atts['per_page'], |
| 404 |
'orderby' => $atts['orderby'], |
| 405 |
'order' => $atts['order'], |
| 406 |
); |
| 407 |
|
| 408 |
$meta_query = array( |
| 409 |
array( |
| 410 |
'key' => '_on_market', |
| 411 |
'value' => 'yes', |
| 412 |
), |
| 413 |
array( |
| 414 |
'key' => '_featured', |
| 415 |
'value' => 'yes' |
| 416 |
) |
| 417 |
); |
| 418 |
|
| 419 |
if ( isset($atts['department']) && $atts['department'] != '' ) |
| 420 |
{ |
| 421 |
$meta_query[] = array( |
| 422 |
'key' => '_department', |
| 423 |
'value' => $atts['department'], |
| 424 |
'compare' => '=' |
| 425 |
); |
| 426 |
} |
| 427 |
|
| 428 |
if ( isset($atts['office_id']) && $atts['office_id'] != '' ) |
| 429 |
{ |
| 430 |
$office_ids = explode(",", $atts['office_id']); |
| 431 |
|
| 432 |
$meta_query[] = array( |
| 433 |
'key' => '_office_id', |
| 434 |
'value' => $office_ids, |
| 435 |
'compare' => 'IN' |
| 436 |
); |
| 437 |
} |
| 438 |
|
| 439 |
$args['meta_query'] = $meta_query; |
| 440 |
|
| 441 |
if ( ! empty( $atts['meta_key'] ) ) { |
| 442 |
$args['meta_key'] = $atts['meta_key']; |
| 443 |
} |
| 444 |
|
| 445 |
ob_start(); |
| 446 |
|
| 447 |
$properties = new WP_Query( apply_filters( 'propertyhive_shortcode_featured_properties_query', $args, $atts ) ); |
| 448 |
|
| 449 |
$propertyhive_loop['columns'] = $atts['columns']; |
| 450 |
|
| 451 |
if ( $properties->have_posts() ) : ?> |
| 452 |
|
| 453 |
<?php propertyhive_property_loop_start(); ?> |
| 454 |
|
| 455 |
<?php while ( $properties->have_posts() ) : $properties->the_post(); ?> |
| 456 |
|
| 457 |
<?php ph_get_template_part( 'content', 'property-featured' ); ?> |
| 458 |
|
| 459 |
<?php endwhile; // end of the loop. ?> |
| 460 |
|
| 461 |
<?php propertyhive_property_loop_end(); ?> |
| 462 |
|
| 463 |
<?php endif; |
| 464 |
|
| 465 |
wp_reset_postdata(); |
| 466 |
|
| 467 |
return '<div class="propertyhive propertyhive-featured-properties-shortcode columns-' . $atts['columns'] . '">' . ob_get_clean() . '</div>'; |
| 468 |
} |
| 469 |
|
| 470 |
/** |
| 471 |
* Output similar properties |
| 472 |
* |
| 473 |
* @param array $atts |
| 474 |
* @return string |
| 475 |
*/ |
| 476 |
public static function similar_properties( $atts ) { |
| 477 |
|
| 478 |
$atts = shortcode_atts( array( |
| 479 |
'per_page' => '2', |
| 480 |
'columns' => '2', |
| 481 |
'orderby' => 'rand', |
| 482 |
'order' => 'asc', |
| 483 |
'price_percentage_bounds' => 10, |
| 484 |
'property_id' => '', |
| 485 |
), $atts ); |
| 486 |
|
| 487 |
if ($atts['property_id'] != '') |
| 488 |
{ |
| 489 |
$department = get_post_meta( $atts['property_id'], '_department', true ); |
| 490 |
$price = get_post_meta( $atts['property_id'], '_price_actual', true ); |
| 491 |
$lower_price = $price; |
| 492 |
$higher_price = $price; |
| 493 |
$atts['price_percentage_bounds'] = str_replace("%", "", $atts['price_percentage_bounds']); |
| 494 |
if ( isset($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] != '' && is_numeric($atts['price_percentage_bounds']) && $atts['price_percentage_bounds'] > 0 ) |
| 495 |
{ |
| 496 |
$lower_price = $price - ($price * $atts['price_percentage_bounds'] / 100); |
| 497 |
$higher_price = $price + ($price * $atts['price_percentage_bounds'] / 100); |
| 498 |
} |
| 499 |
$bedrooms = get_post_meta( $atts['property_id'], '_bedrooms', true ); |
| 500 |
|
| 501 |
$args = array( |
| 502 |
'post_type' => 'property', |
| 503 |
'post__not_in' => array($atts['property_id']), |
| 504 |
'post_status' => ( ( is_user_logged_in() && current_user_can( 'manage_propertyhive' ) ) ? array('publish', 'private') : 'publish' ), |
| 505 |
'ignore_sticky_posts' => 1, |
| 506 |
'posts_per_page' => $atts['per_page'], |
| 507 |
'orderby' => $atts['orderby'], |
| 508 |
'order' => $atts['order'], |
| 509 |
); |
| 510 |
|
| 511 |
$meta_query = array(); |
| 512 |
|
| 513 |
$meta_query[] = array( |
| 514 |
'key' => '_department', |
| 515 |
'value' => $department, |
| 516 |
); |
| 517 |
|
| 518 |
$meta_query[] = array( |
| 519 |
'key' => '_on_market', |
| 520 |
'value' => 'yes', |
| 521 |
); |
| 522 |
|
| 523 |
$meta_query[] = array( |
| 524 |
'key' => '_bedrooms', |
| 525 |
'value' => $bedrooms, |
| 526 |
'type' => 'NUMERIC' |
| 527 |
); |
| 528 |
|
| 529 |
$meta_query[] = array( |
| 530 |
'key' => '_price_actual', |
| 531 |
'value' => $lower_price, |
| 532 |
'compare' => '>=', |
| 533 |
'type' => 'NUMERIC' |
| 534 |
); |
| 535 |
|
| 536 |
$meta_query[] = array( |
| 537 |
'key' => '_price_actual', |
| 538 |
'value' => $higher_price, |
| 539 |
'compare' => '<=', |
| 540 |
'type' => 'NUMERIC' |
| 541 |
); |
| 542 |
|
| 543 |
$args['meta_query'] = $meta_query; |
| 544 |
|
| 545 |
ob_start(); |
| 546 |
|
| 547 |
$properties = new WP_Query( apply_filters( 'propertyhive_shortcode_similar_properties_query', $args, $atts ) ); |
| 548 |
|
| 549 |
$propertyhive_loop['columns'] = $atts['columns']; |
| 550 |
|
| 551 |
if ( $properties->have_posts() ) : ?> |
| 552 |
|
| 553 |
<?php propertyhive_property_loop_start(); ?> |
| 554 |
|
| 555 |
<?php while ( $properties->have_posts() ) : $properties->the_post(); ?> |
| 556 |
|
| 557 |
<?php ph_get_template_part( 'content', 'property-featured' ); ?> |
| 558 |
|
| 559 |
<?php endwhile; // end of the loop. ?> |
| 560 |
|
| 561 |
<?php propertyhive_property_loop_end(); ?> |
| 562 |
|
| 563 |
<?php endif; |
| 564 |
|
| 565 |
wp_reset_postdata(); |
| 566 |
} |
| 567 |
else |
| 568 |
{ |
| 569 |
echo 'No property_id passed into similar_properties shortcode'; |
| 570 |
} |
| 571 |
|
| 572 |
return '<div class="propertyhive propertyhive-similar-properties-shortcode columns-' . $atts['columns'] . '">' . ob_get_clean() . '</div>'; |
| 573 |
} |
| 574 |
|
| 575 |
/** |
| 576 |
* Output property map |
| 577 |
* Should only be used on a property page or where the $property var is set |
| 578 |
* |
| 579 |
* @param array $atts |
| 580 |
* @return string |
| 581 |
*/ |
| 582 |
public static function property_map( $atts ) { |
| 583 |
|
| 584 |
global $property; |
| 585 |
|
| 586 |
$atts = shortcode_atts( array( |
| 587 |
'height' => '400', |
| 588 |
'zoom' => '14', |
| 589 |
'scrollwheel' => 'true' |
| 590 |
), $atts ); |
| 591 |
|
| 592 |
ob_start(); |
| 593 |
|
| 594 |
echo get_property_map( $atts ); |
| 595 |
|
| 596 |
return ob_get_clean(); |
| 597 |
} |
| 598 |
|
| 599 |
/** |
| 600 |
* Output property street view |
| 601 |
* Should only be used on a property page or where the $property var is set |
| 602 |
* |
| 603 |
* @param array $atts |
| 604 |
* @return string |
| 605 |
*/ |
| 606 |
public static function property_street_view( $atts ) { |
| 607 |
|
| 608 |
global $property; |
| 609 |
|
| 610 |
$atts = shortcode_atts( array( |
| 611 |
'height' => '400', |
| 612 |
), $atts ); |
| 613 |
|
| 614 |
ob_start(); |
| 615 |
|
| 616 |
echo get_property_street_view( $atts ); |
| 617 |
|
| 618 |
return ob_get_clean(); |
| 619 |
} |
| 620 |
|
| 621 |
/** |
| 622 |
* Output property office details |
| 623 |
* Should only be used on a property page or where the $property var is set |
| 624 |
* |
| 625 |
* @param array $atts |
| 626 |
* @return string |
| 627 |
*/ |
| 628 |
public static function property_office_details( $atts ) { |
| 629 |
|
| 630 |
global $property; |
| 631 |
|
| 632 |
$atts = shortcode_atts( array( |
| 633 |
'address_separator' => '<br>', |
| 634 |
'hyperlink_telephone_number' => true, |
| 635 |
'hyperlink_email_address' => true, |
| 636 |
), $atts ); |
| 637 |
|
| 638 |
$atts['hyperlink_telephone_number'] = (($atts['hyperlink_telephone_number'] === 'true' || $atts['hyperlink_telephone_number'] === true) ? true : false); |
| 639 |
$atts['hyperlink_email_address'] = (($atts['hyperlink_email_address'] === 'true' || $atts['hyperlink_email_address'] === true) ? true : false); |
| 640 |
|
| 641 |
ob_start(); |
| 642 |
|
| 643 |
if ( $property->office_id != '' ) |
| 644 |
{ |
| 645 |
echo '<div class="property-office-details">'; |
| 646 |
|
| 647 |
if ( $property->office_name != '' ) |
| 648 |
{ |
| 649 |
echo '<div class="office-name">' . $property->office_name . '</div>'; |
| 650 |
} |
| 651 |
|
| 652 |
if ( $property->get_office_address( $atts['address_separator'] ) != '' ) |
| 653 |
{ |
| 654 |
echo '<div class="office-address">' . $property->get_office_address( $atts['address_separator'] ) . '</div>'; |
| 655 |
} |
| 656 |
|
| 657 |
if ( $property->office_telephone_number != '' ) |
| 658 |
{ |
| 659 |
echo '<div class="office-telephone-number">' . ( ($atts['hyperlink_telephone_number'] === true) ? '<a href="tel:' . $property->office_telephone_number . '">' : '' ) . $property->office_telephone_number . ( ($atts['hyperlink_telephone_number'] === true) ? '</a>' : '' ) . '</div>'; |
| 660 |
} |
| 661 |
|
| 662 |
if ( $property->office_email_address != '' ) |
| 663 |
{ |
| 664 |
echo '<div class="office-email-address">' . ( ($atts['hyperlink_email_address'] === true) ? '<a href="mailto:' . $property->office_email_address . '">' : '' ) . $property->office_email_address . ( ($atts['hyperlink_email_address'] === true) ? '</a>' : '' ) . '</div>'; |
| 665 |
} |
| 666 |
|
| 667 |
echo '</div>'; |
| 668 |
} |
| 669 |
|
| 670 |
return ob_get_clean(); |
| 671 |
} |
| 672 |
|
| 673 |
/** |
| 674 |
* Output applicant registration form |
| 675 |
* |
| 676 |
* @param array $atts |
| 677 |
* @return string |
| 678 |
*/ |
| 679 |
public static function applicant_registration_form( $atts ) { |
| 680 |
|
| 681 |
$atts = shortcode_atts( array( |
| 682 |
|
| 683 |
), $atts ); |
| 684 |
|
| 685 |
$assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/'; |
| 686 |
wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true ); |
| 687 |
|
| 688 |
ob_start(); |
| 689 |
|
| 690 |
if ( is_user_logged_in() ) |
| 691 |
{ |
| 692 |
ph_get_template( 'account/already-logged-in.php' ); |
| 693 |
return ob_get_clean(); |
| 694 |
} |
| 695 |
|
| 696 |
$form_controls = ph_get_user_details_form_fields(); |
| 697 |
|
| 698 |
$form_controls = apply_filters( 'propertyhive_user_details_form_fields', $form_controls ); |
| 699 |
|
| 700 |
$form_controls_2 = ph_get_applicant_requirements_form_fields(); |
| 701 |
|
| 702 |
$form_controls_2 = apply_filters( 'propertyhive_applicant_requirements_form_fields', $form_controls_2 ); |
| 703 |
|
| 704 |
ph_get_template( 'account/applicant-registration-form.php', array( 'form_controls' => array_merge( $form_controls, $form_controls_2 ) ) ); |
| 705 |
|
| 706 |
return ob_get_clean(); |
| 707 |
} |
| 708 |
|
| 709 |
/** |
| 710 |
* Output 'Login' page |
| 711 |
* |
| 712 |
* @param array $atts |
| 713 |
* @return string |
| 714 |
*/ |
| 715 |
public static function login_form( $atts ) |
| 716 |
{ |
| 717 |
$atts = shortcode_atts( array( |
| 718 |
|
| 719 |
), $atts ); |
| 720 |
|
| 721 |
$assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/'; |
| 722 |
wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true ); |
| 723 |
|
| 724 |
ob_start(); |
| 725 |
|
| 726 |
if ( is_user_logged_in() ) |
| 727 |
{ |
| 728 |
ph_get_template( 'account/already-logged-in.php' ); |
| 729 |
return ob_get_clean(); |
| 730 |
} |
| 731 |
|
| 732 |
// Check 'propertyhive_applicant_users' setting is enabled |
| 733 |
if ( get_option( 'propertyhive_applicant_users', '' ) != 'yes' ) |
| 734 |
{ |
| 735 |
ph_get_template( 'account/invalid-access.php' ); |
| 736 |
return ob_get_clean(); |
| 737 |
} |
| 738 |
|
| 739 |
ph_get_template( 'account/login-form.php' ); |
| 740 |
|
| 741 |
return ob_get_clean(); |
| 742 |
|
| 743 |
} |
| 744 |
|
| 745 |
/** |
| 746 |
* Output 'My Account' page |
| 747 |
* |
| 748 |
* @param array $atts |
| 749 |
* @return string |
| 750 |
*/ |
| 751 |
public static function my_account( $atts ) |
| 752 |
{ |
| 753 |
$atts = shortcode_atts( array( |
| 754 |
|
| 755 |
), $atts ); |
| 756 |
|
| 757 |
$assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/'; |
| 758 |
wp_enqueue_script( 'propertyhive_account', $assets_path . 'js/frontend/account.js', array( 'jquery' ), PH_VERSION, true ); |
| 759 |
|
| 760 |
ob_start(); |
| 761 |
|
| 762 |
// Check user is logged in |
| 763 |
if ( !is_user_logged_in() ) |
| 764 |
{ |
| 765 |
ph_get_template( 'account/invalid-access.php' ); |
| 766 |
return ob_get_clean(); |
| 767 |
} |
| 768 |
|
| 769 |
// Check 'propertyhive_applicant_users' setting is enabled |
| 770 |
if ( get_option( 'propertyhive_applicant_users', '' ) != 'yes' ) |
| 771 |
{ |
| 772 |
ph_get_template( 'account/invalid-access.php' ); |
| 773 |
return ob_get_clean(); |
| 774 |
} |
| 775 |
|
| 776 |
ph_get_template( 'account/my-account.php' ); |
| 777 |
|
| 778 |
return ob_get_clean(); |
| 779 |
|
| 780 |
} |
| 781 |
} |
| 782 |
|