| 1 |
<?php |
| 2 |
/** |
| 3 |
* PropertyHive Property Functions |
| 4 |
* |
| 5 |
* Functions for property specific things. |
| 6 |
* |
| 7 |
* @author BISOTALL |
| 8 |
* @category Core |
| 9 |
* @package PropertyHive/Functions |
| 10 |
* @version 1.0.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
/** |
| 14 |
* Main function for returning properties, uses the PH_Property_Factory class. |
| 15 |
* |
| 16 |
* @param mixed $the_property Post object or post ID of the property. |
| 17 |
* @param array $args (default: array()) Contains all arguments to be used to get this property. |
| 18 |
* @return PH_Property |
| 19 |
*/ |
| 20 |
function get_property( $the_property = false, $args = array() ) { |
| 21 |
return new PH_Property( $the_property ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Function that returns an array containing the IDs of the featured properties. |
| 26 |
* |
| 27 |
* @access public |
| 28 |
* @return array |
| 29 |
*/ |
| 30 |
function ph_get_featured_property_ids() { |
| 31 |
|
| 32 |
// Load from cache |
| 33 |
$featured_property_ids = get_transient( 'ph_featured_properties' ); |
| 34 |
|
| 35 |
// Valid cache found |
| 36 |
if ( false !== $featured_property_ids ) |
| 37 |
return $featured_property_ids; |
| 38 |
|
| 39 |
$featured = get_posts( array( |
| 40 |
'post_type' => 'property', |
| 41 |
'posts_per_page' => -1, |
| 42 |
'post_status' => 'publish', |
| 43 |
'meta_query' => array( |
| 44 |
array( |
| 45 |
'key' => '_on_market', |
| 46 |
'value' => 'yes' |
| 47 |
), |
| 48 |
array( |
| 49 |
'key' => '_featured', |
| 50 |
'value' => 'yes' |
| 51 |
) |
| 52 |
), |
| 53 |
'fields' => 'id=>parent' |
| 54 |
) ); |
| 55 |
|
| 56 |
$featured_property_ids = array_keys( $featured ); |
| 57 |
|
| 58 |
set_transient( 'ph_featured_properties', $featured_property_ids, YEAR_IN_SECONDS ); |
| 59 |
|
| 60 |
return $featured_property_ids; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Get the placeholder image URL for properties |
| 65 |
* |
| 66 |
* @access public |
| 67 |
* @return string |
| 68 |
*/ |
| 69 |
function ph_placeholder_img_src() { |
| 70 |
return apply_filters( 'propertyhive_placeholder_img_src', PH()->plugin_url() . '/assets/images/placeholder.png' ); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Get the placeholder image |
| 75 |
* |
| 76 |
* @access public |
| 77 |
* @return string |
| 78 |
*/ |
| 79 |
function ph_placeholder_img( $size = 'thumbnail' ) { |
| 80 |
$dimensions = ph_get_image_size( $size ); |
| 81 |
|
| 82 |
return apply_filters('propertyhive_placeholder_img', '<img src="' . ph_placeholder_img_src() . '" alt="Placeholder" width="' . esc_attr( $dimensions['width'] ) . '" class="property-placeholder wp-post-image" height="' . esc_attr( $dimensions['height'] ) . '" />' ); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Track property views |
| 87 |
*/ |
| 88 |
function ph_track_property_view() { |
| 89 |
if ( ! is_singular( 'property' ) ) |
| 90 |
return; |
| 91 |
|
| 92 |
global $post; |
| 93 |
|
| 94 |
// Track in cookie |
| 95 |
if ( apply_filters( 'propertyhive_store_in_recently_viewed_cookie', true ) ) |
| 96 |
{ |
| 97 |
if ( empty( $_COOKIE['propertyhive_recently_viewed'] ) ) |
| 98 |
$viewed_properties = array(); |
| 99 |
else |
| 100 |
$viewed_properties = (array) explode( '|', $_COOKIE['propertyhive_recently_viewed'] ); |
| 101 |
|
| 102 |
if ( ! in_array( $post->ID, $viewed_properties ) ) |
| 103 |
$viewed_properties[] = $post->ID; |
| 104 |
|
| 105 |
if ( sizeof( $viewed_properties ) > 15 ) |
| 106 |
array_shift( $viewed_properties ); |
| 107 |
|
| 108 |
// Store for session only |
| 109 |
ph_setcookie( 'propertyhive_recently_viewed', implode( '|', $viewed_properties ) ); |
| 110 |
} |
| 111 |
|
| 112 |
// Track in database |
| 113 |
if ( !is_user_logged_in() || ( is_user_logged_in() && !current_user_can('manage_propertyhive') ) ) |
| 114 |
{ |
| 115 |
// User isn't logged in |
| 116 |
|
| 117 |
$view_counts = get_post_meta( $post->ID, '_view_statistics', TRUE ); |
| 118 |
|
| 119 |
if ( $view_counts == '' || !is_array($view_counts) ) |
| 120 |
{ |
| 121 |
$view_counts = array(); |
| 122 |
} |
| 123 |
|
| 124 |
if ( !isset($view_counts[date("Y-m-d")]) ) |
| 125 |
{ |
| 126 |
$view_counts[date("Y-m-d")] = 0; |
| 127 |
} |
| 128 |
|
| 129 |
++$view_counts[date("Y-m-d")]; |
| 130 |
|
| 131 |
update_post_meta( $post->ID, '_view_statistics', $view_counts ); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
add_action( 'template_redirect', 'ph_track_property_view', 20 ); |
| 136 |
|
| 137 |
function get_property_map( $args = array() ) |
| 138 |
{ |
| 139 |
global $property; |
| 140 |
|
| 141 |
if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' ) |
| 142 |
{ |
| 143 |
$id_suffix = ( ( isset($args['id']) && $args['id'] != '' ) ? '_' . $args['id'] : '' ); |
| 144 |
|
| 145 |
if ( get_option('propertyhive_maps_provider') == 'mapbox' ) |
| 146 |
{ |
| 147 |
echo '<div id="property_map_canvas' . esc_attr($id_suffix) . '" style="background:#EEE; height:' . esc_attr( str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : '400' ) ) ) . 'px"></div>'; |
| 148 |
|
| 149 |
$assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/js/mapbox/'; |
| 150 |
|
| 151 |
wp_register_style('mapbox', $assets_path . 'mapbox-gl.css', array(), '3.8.0'); |
| 152 |
wp_enqueue_style('mapbox'); |
| 153 |
|
| 154 |
wp_register_script('mapbox', $assets_path . 'mapbox-gl.js', array(), '3.8.0', false); |
| 155 |
wp_enqueue_script('mapbox'); |
| 156 |
?> |
| 157 |
<script> |
| 158 |
|
| 159 |
var property_map<?php echo esc_js($id_suffix); ?>; |
| 160 |
|
| 161 |
function initialize_property_map<?php echo esc_js($id_suffix); ?>() |
| 162 |
{ |
| 163 |
if ( property_map<?php echo esc_js($id_suffix); ?> != undefined ) { property_map<?php echo esc_js($id_suffix); ?>.remove(); } |
| 164 |
|
| 165 |
mapboxgl.accessToken = '<?php echo esc_js(get_option( 'propertyhive_mapbox_api_key', '' )); ?>'; |
| 166 |
property_map<?php echo esc_js($id_suffix); ?> = new mapboxgl.Map({ |
| 167 |
container: "property_map_canvas<?php echo esc_js($id_suffix); ?>", // container ID |
| 168 |
center: [<?php echo (float)$property->longitude; ?>, <?php echo (float)$property->latitude; ?>], // starting position [lng, lat]. Note that lat must be set between -90 and 90 |
| 169 |
zoom: <?php echo ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? (int)$args['zoom'] : '14' ); ?> // starting zoom |
| 170 |
}); |
| 171 |
|
| 172 |
<?php |
| 173 |
$marker_set = false; |
| 174 |
if ( class_exists( 'PH_Map_Search' ) ) |
| 175 |
{ |
| 176 |
$map_add_on_settings = get_option( 'propertyhive_map_search', array() ); |
| 177 |
|
| 178 |
if ( isset($map_add_on_settings['icon_type']) && $map_add_on_settings['icon_type'] == 'custom_single' && isset($map_add_on_settings['custom_icon_attachment_id']) && $map_add_on_settings['custom_icon_attachment_id'] != '' ) |
| 179 |
{ |
| 180 |
$marker_icon_url = wp_get_attachment_url( $map_add_on_settings['custom_icon_attachment_id'] ); |
| 181 |
if ( $marker_icon_url !== FALSE ) |
| 182 |
{ |
| 183 |
$size = getimagesize( get_attached_file( $map_add_on_settings['custom_icon_attachment_id'] ) ); |
| 184 |
if ( $size !== FALSE && !empty($size) ) |
| 185 |
{ |
| 186 |
$icon_anchor_width = $size[0]; |
| 187 |
$icon_anchor_height = $size[1]; |
| 188 |
|
| 189 |
/*if (isset($map_add_on_settings['custom_icon_anchor_position']) && $map_add_on_settings['custom_icon_anchor_position'] == 'center') |
| 190 |
{ |
| 191 |
$icon_anchor_width = floor($size[0] / 2); |
| 192 |
$icon_anchor_height = floor($size[1] / 2); |
| 193 |
} |
| 194 |
else |
| 195 |
{ |
| 196 |
$icon_anchor_width = floor($size[0] / 2); |
| 197 |
$icon_anchor_height = $size[1]; |
| 198 |
}*/ |
| 199 |
?> |
| 200 |
const el = document.createElement('div'); |
| 201 |
el.className = 'marker'; |
| 202 |
el.style.backgroundImage = 'url(<?php echo esc_url($marker_icon_url); ?>)'; |
| 203 |
el.style.width = '<?php echo (int)$icon_anchor_width; ?>px'; |
| 204 |
el.style.height = '<?php echo (int)$icon_anchor_height; ?>px'; |
| 205 |
el.style.backgroundSize = '100%'; |
| 206 |
|
| 207 |
new mapboxgl.Marker(el, {<?php if (isset($map_add_on_settings['custom_icon_anchor_position']) && $map_add_on_settings['custom_icon_anchor_position'] == 'center') { echo 'anchor:\'center\''; }else{ echo 'anchor:\'bottom\''; } ?>}) |
| 208 |
.setLngLat([<?php echo (float)$property->longitude; ?>, <?php echo (float)$property->latitude; ?>]) |
| 209 |
.addTo(property_map<?php echo esc_js($id_suffix); ?>); |
| 210 |
<?php |
| 211 |
$marker_set = true; |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
if ( !$marker_set ) |
| 217 |
{ |
| 218 |
?> |
| 219 |
marker = new mapboxgl.Marker({ |
| 220 |
//color: "#FFFFFF", |
| 221 |
draggable: false |
| 222 |
}).setLngLat([<?php echo (float)$property->longitude; ?>, <?php echo (float)$property->latitude; ?>]) |
| 223 |
.addTo(property_map<?php echo esc_js($id_suffix); ?>); |
| 224 |
<?php |
| 225 |
} |
| 226 |
do_action( 'propertyhive_property_map_actions', $property, $args, $id_suffix ); |
| 227 |
?> |
| 228 |
|
| 229 |
} |
| 230 |
|
| 231 |
<?php if ( !isset($args['init_on_load']) || ( isset($args['init_on_load']) && ($args['init_on_load'] === 'true' || $args['init_on_load'] === TRUE) ) ) { ?> |
| 232 |
if (window.addEventListener) { |
| 233 |
window.addEventListener('load', initialize_property_map<?php echo esc_js($id_suffix); ?>); |
| 234 |
}else{ |
| 235 |
window.attachEvent('onload', initialize_property_map<?php echo esc_js($id_suffix); ?>); |
| 236 |
} |
| 237 |
<?php } ?> |
| 238 |
|
| 239 |
</script> |
| 240 |
<?php |
| 241 |
} |
| 242 |
elseif ( get_option('propertyhive_maps_provider') == 'osm' ) |
| 243 |
{ |
| 244 |
echo '<div id="property_map_canvas' . esc_attr($id_suffix) . '" style="background:#EEE; height:' . esc_attr( str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : '400' ) ) ) . 'px"></div>'; |
| 245 |
|
| 246 |
$assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/js/leaflet/'; |
| 247 |
|
| 248 |
wp_register_style('leaflet', $assets_path . 'leaflet.css', array(), '1.9.4'); |
| 249 |
wp_enqueue_style('leaflet'); |
| 250 |
|
| 251 |
wp_register_script('leaflet', $assets_path . 'leaflet.js', array(), '1.9.4', false); |
| 252 |
wp_enqueue_script('leaflet'); |
| 253 |
?> |
| 254 |
<script> |
| 255 |
|
| 256 |
var property_map<?php echo esc_js($id_suffix); ?>; |
| 257 |
|
| 258 |
function initialize_property_map<?php echo esc_js($id_suffix); ?>() |
| 259 |
{ |
| 260 |
if ( property_map<?php echo esc_js($id_suffix); ?> != undefined ) { property_map<?php echo esc_js($id_suffix); ?>.remove(); } |
| 261 |
|
| 262 |
L.Icon.Default.imagePath = '<?php echo esc_url($assets_path); ?>/images/'; |
| 263 |
|
| 264 |
property_map<?php echo esc_js($id_suffix); ?> = L.map("property_map_canvas<?php echo esc_js($id_suffix); ?>"<?php echo ( ( isset($args['scrollwheel']) && ($args['scrollwheel'] === 'false' || $args['scrollwheel'] === FALSE) ) ? ', { scrollWheelZoom: false, dragging: !L.Browser.mobile }' : '' ); ?>).setView([<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>], <?php echo ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? (int)$args['zoom'] : '14' ); ?>); |
| 265 |
|
| 266 |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
| 267 |
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' |
| 268 |
}).addTo(property_map<?php echo esc_js($id_suffix); ?>); |
| 269 |
|
| 270 |
<?php |
| 271 |
$icon_code = ''; |
| 272 |
if ( class_exists( 'PH_Map_Search' ) ) |
| 273 |
{ |
| 274 |
$map_add_on_settings = get_option( 'propertyhive_map_search', array() ); |
| 275 |
|
| 276 |
if ( isset($map_add_on_settings['icon_type']) && $map_add_on_settings['icon_type'] == 'custom_single' && isset($map_add_on_settings['custom_icon_attachment_id']) && $map_add_on_settings['custom_icon_attachment_id'] != '' ) |
| 277 |
{ |
| 278 |
$marker_icon_url = wp_get_attachment_url( $map_add_on_settings['custom_icon_attachment_id'] ); |
| 279 |
if ( $marker_icon_url !== FALSE ) |
| 280 |
{ |
| 281 |
?> |
| 282 |
var icon_options = { iconUrl: '<?php echo esc_url($marker_icon_url); ?>' } |
| 283 |
<?php |
| 284 |
$icon_width = ''; |
| 285 |
$icon_height = ''; |
| 286 |
|
| 287 |
$icon_anchor_width = ''; |
| 288 |
$icon_anchor_height = ''; |
| 289 |
|
| 290 |
$size = getimagesize( get_attached_file( $map_add_on_settings['custom_icon_attachment_id'] ) ); |
| 291 |
if ( $size !== FALSE && !empty($size) ) |
| 292 |
{ |
| 293 |
$icon_width = (int)$size[0]; |
| 294 |
$icon_height = (int)$size[1]; |
| 295 |
|
| 296 |
if (isset($map_add_on_settings['custom_icon_anchor_position']) && $map_add_on_settings['custom_icon_anchor_position'] == 'center') |
| 297 |
{ |
| 298 |
$icon_anchor_width = floor($size[0] / 2); |
| 299 |
$icon_anchor_height = floor($size[1] / 2); |
| 300 |
} |
| 301 |
else |
| 302 |
{ |
| 303 |
$icon_anchor_width = floor($size[0] / 2); |
| 304 |
$icon_anchor_height = $size[1]; |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
$icon_width = apply_filters( 'propertyhive_property_map_osm_icon_width', $icon_width ); |
| 309 |
$icon_height = apply_filters( 'propertyhive_property_map_osm_icon_height', $icon_height ); |
| 310 |
|
| 311 |
$icon_anchor_width = apply_filters( 'propertyhive_property_map_osm_icon_anchor_width', $icon_anchor_width ); |
| 312 |
$icon_anchor_height = apply_filters( 'propertyhive_property_map_osm_icon_anchor_height', $icon_anchor_height ); |
| 313 |
|
| 314 |
if ( !empty($icon_width) && !empty($icon_height) ) |
| 315 |
{ |
| 316 |
?> |
| 317 |
icon_options.iconSize = [<?php echo (int)$icon_width; ?>, <?php echo (int)$icon_height; ?>]; |
| 318 |
<?php |
| 319 |
} |
| 320 |
if ( $icon_anchor_width != '' && $icon_anchor_height != '' ) |
| 321 |
{ |
| 322 |
?> |
| 323 |
icon_options.iconAnchor = [<?php echo (int)$icon_anchor_width; ?>, <?php echo (int)$icon_anchor_height; ?>]; |
| 324 |
<?php |
| 325 |
} |
| 326 |
?> |
| 327 |
var custom_icon = L.icon(icon_options); |
| 328 |
<?php |
| 329 |
$icon_code = ', { icon: custom_icon }'; |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
do_action( 'propertyhive_property_map_actions', $property, $args, $id_suffix ); |
| 334 |
?> |
| 335 |
|
| 336 |
L.marker([<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>]<?php echo $icon_code; ?>).addTo(property_map<?php echo esc_js($id_suffix); ?>); |
| 337 |
} |
| 338 |
|
| 339 |
<?php if ( !isset($args['init_on_load']) || ( isset($args['init_on_load']) && ($args['init_on_load'] === 'true' || $args['init_on_load'] === TRUE) ) ) { ?> |
| 340 |
if (window.addEventListener) { |
| 341 |
window.addEventListener('load', initialize_property_map<?php echo esc_js($id_suffix); ?>); |
| 342 |
}else{ |
| 343 |
window.attachEvent('onload', initialize_property_map<?php echo esc_js($id_suffix); ?>); |
| 344 |
} |
| 345 |
<?php } ?> |
| 346 |
|
| 347 |
</script> |
| 348 |
<?php |
| 349 |
} |
| 350 |
else |
| 351 |
{ |
| 352 |
$api_key = get_option('propertyhive_google_maps_api_key'); |
| 353 |
if ( isset($args['embed']) && ($args['embed'] === 'true' || $args['embed'] === TRUE) ) |
| 354 |
{ |
| 355 |
echo '<iframe |
| 356 |
width="100%" |
| 357 |
height="' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : '400' ) ) . '" |
| 358 |
style="border:0" |
| 359 |
loading="lazy" |
| 360 |
allowfullscreen |
| 361 |
referrerpolicy="no-referrer-when-downgrade" |
| 362 |
src="' . esc_url( 'https://www.google.com/maps/embed/v1/place?key=' . $api_key . '&q=' . $property->latitude . ',' . $property->longitude ) . '"> |
| 363 |
</iframe>'; |
| 364 |
} |
| 365 |
else |
| 366 |
{ |
| 367 |
echo '<div id="property_map_canvas' . esc_attr($id_suffix) . '" style="background:#EEE; height:' . esc_attr( str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : '400' ) ) ) . 'px"></div>'; |
| 368 |
|
| 369 |
wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3'); |
| 370 |
wp_enqueue_script('googlemaps'); |
| 371 |
?> |
| 372 |
<script> |
| 373 |
|
| 374 |
var property_map<?php echo esc_js($id_suffix); ?>; |
| 375 |
var property_marker<?php echo esc_js($id_suffix); ?>; |
| 376 |
|
| 377 |
function initialize_property_map<?php echo esc_js($id_suffix); ?>() { |
| 378 |
|
| 379 |
var myLatlng = new google.maps.LatLng(<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>); |
| 380 |
var map_options = { |
| 381 |
zoom: <?php echo ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? (int)$args['zoom'] : '14' ); ?>, |
| 382 |
center: myLatlng, |
| 383 |
mapTypeId: google.maps.MapTypeId.ROADMAP, |
| 384 |
scrollwheel: <?php echo ( ( isset($args['scrollwheel']) && ($args['scrollwheel'] === 'false' || $args['scrollwheel'] === FALSE) ) ? 'false' : 'true' ); ?> |
| 385 |
} |
| 386 |
<?php |
| 387 |
if ( class_exists( 'PH_Map_Search' ) ) |
| 388 |
{ |
| 389 |
$map_add_on_settings = get_option( 'propertyhive_map_search', array() ); |
| 390 |
|
| 391 |
if ( isset($map_add_on_settings['style_js']) && trim($map_add_on_settings['style_js']) != '' ) |
| 392 |
{ |
| 393 |
echo 'map_options.styles = ' . trim($map_add_on_settings['style_js']) . ';'; |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
do_action( 'propertyhive_property_map_options', $property, $args, $id_suffix ); |
| 398 |
?> |
| 399 |
property_map<?php echo esc_js($id_suffix); ?> = new google.maps.Map(document.getElementById("property_map_canvas<?php echo esc_js($id_suffix); ?>"), map_options); |
| 400 |
|
| 401 |
var myLatlng = new google.maps.LatLng(<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>); |
| 402 |
|
| 403 |
var marker_options = { |
| 404 |
map: property_map<?php echo esc_js($id_suffix); ?>, |
| 405 |
position: myLatlng |
| 406 |
}; |
| 407 |
|
| 408 |
<?php |
| 409 |
if ( class_exists( 'PH_Map_Search' ) ) |
| 410 |
{ |
| 411 |
$map_add_on_settings = get_option( 'propertyhive_map_search', array() ); |
| 412 |
|
| 413 |
if ( isset($map_add_on_settings['icon_type']) && $map_add_on_settings['icon_type'] == 'custom_single' && isset($map_add_on_settings['custom_icon_attachment_id']) && $map_add_on_settings['custom_icon_attachment_id'] != '' ) |
| 414 |
{ |
| 415 |
$marker_icon_url = wp_get_attachment_url( $map_add_on_settings['custom_icon_attachment_id'] ); |
| 416 |
if ( $marker_icon_url !== FALSE ) |
| 417 |
{ |
| 418 |
echo 'var ph_map_icon = { |
| 419 |
url: \'' . esc_url($marker_icon_url) . '\''; |
| 420 |
if ( isset($map_add_on_settings['custom_icon_anchor_position']) && $map_add_on_settings['custom_icon_anchor_position'] == 'center' ) |
| 421 |
{ |
| 422 |
$size = getimagesize( get_attached_file( $map_add_on_settings['custom_icon_attachment_id'] ) ); |
| 423 |
if ( $size !== FALSE && !empty($size) ) |
| 424 |
{ |
| 425 |
echo ', anchor: new google.maps.Point(' . floor( (int)$size[0] / 2 ) . ', ' . floor( (int)$size[1] / 2 ) . ')'; |
| 426 |
} |
| 427 |
} |
| 428 |
echo '};'; |
| 429 |
echo 'marker_options.icon = ph_map_icon;'; |
| 430 |
} |
| 431 |
} |
| 432 |
} |
| 433 |
?> |
| 434 |
|
| 435 |
<?php do_action( 'propertyhive_property_map_marker_options' ); ?> |
| 436 |
|
| 437 |
property_marker<?php echo esc_js($id_suffix); ?> = new google.maps.Marker(marker_options); |
| 438 |
|
| 439 |
<?php do_action( 'propertyhive_property_map_actions' ); ?> |
| 440 |
} |
| 441 |
|
| 442 |
<?php if ( !isset($args['init_on_load']) || ( isset($args['init_on_load']) && ($args['init_on_load'] === 'true' || $args['init_on_load'] === TRUE) ) ) { ?> |
| 443 |
if(window.addEventListener) { |
| 444 |
window.addEventListener('load', initialize_property_map<?php echo esc_js($id_suffix); ?>); |
| 445 |
}else{ |
| 446 |
window.attachEvent('onload', initialize_property_map<?php echo esc_js($id_suffix); ?>); |
| 447 |
} |
| 448 |
<?php } ?> |
| 449 |
|
| 450 |
</script> |
| 451 |
<?php |
| 452 |
} |
| 453 |
} |
| 454 |
do_action( 'propertyhive_property_map_after' ); |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
function get_property_static_map( $args = array() ) |
| 459 |
{ |
| 460 |
global $property; |
| 461 |
|
| 462 |
if ( get_option('propertyhive_maps_provider') == 'osm' ) |
| 463 |
{ |
| 464 |
|
| 465 |
|
| 466 |
} |
| 467 |
else |
| 468 |
{ |
| 469 |
if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' ) |
| 470 |
{ |
| 471 |
$api_key = get_option('propertyhive_google_maps_api_key'); |
| 472 |
|
| 473 |
$id_suffix = ( ( isset($args['id']) && $args['id'] != '' ) ? '_' . $args['id'] : '' ); |
| 474 |
|
| 475 |
$link = ( ( isset($args['link']) && ($args['link'] === 'false' || $args['link'] === FALSE) ) ? 'false' : 'true' ); |
| 476 |
|
| 477 |
$map_url = 'https://maps.googleapis.com/maps/api/staticmap?' . |
| 478 |
'center=' . (float)$property->latitude . ',' . (float)$property->longitude . |
| 479 |
'&size=1024x' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : '400' ) ) . |
| 480 |
'&zoom=' . ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? (int)$args['zoom'] : '14' ) . |
| 481 |
'&maptype=roadmap' . |
| 482 |
'&markers=%7C%7C' . (float)$property->latitude . ',' . (float)$property->longitude . |
| 483 |
'&key=' . urlencode($api_key); |
| 484 |
|
| 485 |
echo '<style type="text/css"> |
| 486 |
#property_static_map' . esc_attr($id_suffix) . ' { |
| 487 |
height:' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : '400' ) ) . 'px; |
| 488 |
display: block; |
| 489 |
background-image: url("' . esc_url($map_url) . '"); |
| 490 |
background-repeat: no-repeat; |
| 491 |
background-position: 50% 50%; |
| 492 |
line-height: 0; |
| 493 |
} |
| 494 |
</style>'; |
| 495 |
|
| 496 |
if ( $link === true ) |
| 497 |
{ |
| 498 |
echo '<a id="property_static_map' . esc_attr($id_suffix) . '" href="https://maps.google.com?q=' . (float)$property->latitude . ',' . (float)$property->longitude . '" target="_blank" rel="nofollow"></a>'; |
| 499 |
} |
| 500 |
else |
| 501 |
{ |
| 502 |
echo '<div id="property_static_map' . esc_attr($id_suffix) . '" ></div>'; |
| 503 |
} |
| 504 |
} |
| 505 |
} |
| 506 |
} |
| 507 |
|
| 508 |
function get_property_street_view( $args = array() ) |
| 509 |
{ |
| 510 |
global $property; |
| 511 |
|
| 512 |
if ( get_option('propertyhive_maps_provider') == 'osm' || get_option('propertyhive_maps_provider') == 'mapbox' ) |
| 513 |
{ |
| 514 |
|
| 515 |
|
| 516 |
} |
| 517 |
else |
| 518 |
{ |
| 519 |
if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' ) |
| 520 |
{ |
| 521 |
$api_key = get_option('propertyhive_google_maps_api_key'); |
| 522 |
if ( isset($args['embed']) && ($args['embed'] === 'true' || $args['embed'] === TRUE) ) |
| 523 |
{ |
| 524 |
echo '<iframe |
| 525 |
width="100%" |
| 526 |
height="' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : '400' ) ) . '" |
| 527 |
style="border:0" |
| 528 |
loading="lazy" |
| 529 |
allowfullscreen |
| 530 |
referrerpolicy="no-referrer-when-downgrade" |
| 531 |
src="' . esc_url( 'https://www.google.com/maps/embed/v1/streetview?key=' . $api_key . '&location=' . $property->latitude . ',' . $property->longitude ) . '"> |
| 532 |
</iframe>'; |
| 533 |
} |
| 534 |
else |
| 535 |
{ |
| 536 |
wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3'); |
| 537 |
wp_enqueue_script('googlemaps'); |
| 538 |
|
| 539 |
echo '<div id="property_street_view_canvas" style="height:' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : '400' ) ) . 'px"></div>'; |
| 540 |
?> |
| 541 |
<script> |
| 542 |
|
| 543 |
// We declare vars globally so developers can access them |
| 544 |
var property_street_view; // Global declaration of the map |
| 545 |
|
| 546 |
function initialize_property_street_view() { |
| 547 |
|
| 548 |
var myLatlng = new google.maps.LatLng(<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>); |
| 549 |
var map_options = { |
| 550 |
center: myLatlng |
| 551 |
} |
| 552 |
|
| 553 |
<?php do_action( 'propertyhive_property_street_view_map_options' ); ?> |
| 554 |
|
| 555 |
property_street_view = new google.maps.Map(document.getElementById("property_street_view_canvas"), map_options); |
| 556 |
|
| 557 |
var streetViewOptions = { |
| 558 |
position: myLatlng, |
| 559 |
pov: { |
| 560 |
heading: 90, |
| 561 |
pitch: 0, |
| 562 |
zoom: 0 |
| 563 |
} |
| 564 |
}; |
| 565 |
|
| 566 |
<?php do_action( 'propertyhive_property_street_view_options' ); ?> |
| 567 |
|
| 568 |
var streetView = new google.maps.StreetViewPanorama(document.getElementById("property_street_view_canvas"), streetViewOptions); |
| 569 |
streetView.setVisible(true); |
| 570 |
} |
| 571 |
|
| 572 |
<?php if ( !isset($args['init_on_load']) || ( isset($args['init_on_load']) && ($args['init_on_load'] === 'true' || $args['init_on_load'] === TRUE) ) ) { ?> |
| 573 |
if(window.addEventListener) { |
| 574 |
window.addEventListener('load', initialize_property_street_view); |
| 575 |
}else{ |
| 576 |
window.attachEvent('onload', initialize_property_street_view); |
| 577 |
} |
| 578 |
<?php |
| 579 |
} |
| 580 |
} |
| 581 |
?> |
| 582 |
|
| 583 |
</script> |
| 584 |
<?php |
| 585 |
} |
| 586 |
} |
| 587 |
} |
| 588 |
|
| 589 |
function get_electricity_types() |
| 590 |
{ |
| 591 |
$types = array( |
| 592 |
'mains_supply' => __( 'Mains Supply', 'propertyhive' ), |
| 593 |
'wind_turbine' => __( 'Wind Turbine', 'propertyhive' ), |
| 594 |
'solar_pv_panels' => __( 'Solar PV Panels', 'propertyhive' ), |
| 595 |
'private_supply' => __( 'Private Supply', 'propertyhive' ), |
| 596 |
); |
| 597 |
|
| 598 |
$types = apply_filters( 'propertyhive_electricity_types', $types ); |
| 599 |
|
| 600 |
asort($types); |
| 601 |
|
| 602 |
$types['other'] = __( 'Other', 'propertyhive' ); |
| 603 |
|
| 604 |
return $types; |
| 605 |
} |
| 606 |
|
| 607 |
function get_electricity_type( $type ) |
| 608 |
{ |
| 609 |
$types = get_electricity_types(); |
| 610 |
|
| 611 |
if ( isset($types[$type]) ) |
| 612 |
{ |
| 613 |
return $types[$type]; |
| 614 |
} |
| 615 |
|
| 616 |
return ''; |
| 617 |
} |
| 618 |
|
| 619 |
function get_water_types() |
| 620 |
{ |
| 621 |
$types = array( |
| 622 |
'mains_supply' => __( 'Mains Supply', 'propertyhive' ), |
| 623 |
'private_supply' => __( 'Private Supply', 'propertyhive' ), |
| 624 |
); |
| 625 |
|
| 626 |
$types = apply_filters( 'propertyhive_water_types', $types ); |
| 627 |
|
| 628 |
asort($types); |
| 629 |
|
| 630 |
$types['other'] = __( 'Other', 'propertyhive' ); |
| 631 |
|
| 632 |
return $types; |
| 633 |
} |
| 634 |
|
| 635 |
function get_water_type( $type ) |
| 636 |
{ |
| 637 |
$types = get_water_types(); |
| 638 |
|
| 639 |
if ( isset($types[$type]) ) |
| 640 |
{ |
| 641 |
return $types[$type]; |
| 642 |
} |
| 643 |
|
| 644 |
return ''; |
| 645 |
} |
| 646 |
|
| 647 |
function get_broadband_types() |
| 648 |
{ |
| 649 |
$types = array( |
| 650 |
'adsl' => __( 'ADSL', 'propertyhive' ), |
| 651 |
'cable' => __( 'Cable', 'propertyhive' ), |
| 652 |
'fttc' => __( 'FTTC (Fibre to the Cabinet)', 'propertyhive' ), |
| 653 |
'fttp' => __( 'FTTP (Fibre to the Premises)', 'propertyhive' ), |
| 654 |
'none' => __( 'None', 'propertyhive' ), |
| 655 |
); |
| 656 |
|
| 657 |
$types = apply_filters( 'propertyhive_broadband_types', $types ); |
| 658 |
|
| 659 |
asort($types); |
| 660 |
|
| 661 |
$types['other'] = __( 'Other', 'propertyhive' ); |
| 662 |
|
| 663 |
return $types; |
| 664 |
} |
| 665 |
|
| 666 |
function get_broadband_type( $type ) |
| 667 |
{ |
| 668 |
$types = get_broadband_types(); |
| 669 |
|
| 670 |
if ( isset($types[$type]) ) |
| 671 |
{ |
| 672 |
return $types[$type]; |
| 673 |
} |
| 674 |
|
| 675 |
return ''; |
| 676 |
} |
| 677 |
|
| 678 |
function get_heating_types() |
| 679 |
{ |
| 680 |
$types = array( |
| 681 |
'air_conditioning' => __( 'Air Conditioning', 'propertyhive' ), |
| 682 |
'central' => __( 'Central Heating', 'propertyhive' ), |
| 683 |
'double_glazing' => __( 'Double Glazing', 'propertyhive' ), |
| 684 |
'eco_friendly' => __( 'Eco-Friendly', 'propertyhive' ), |
| 685 |
'electric' => __( 'Electric Heating', 'propertyhive' ), |
| 686 |
'gas' => __( 'Gas Heating', 'propertyhive' ), |
| 687 |
'gas_central' => __( 'Gas Central Heating', 'propertyhive' ), |
| 688 |
'night_storage' => __( 'Night Storage Heating', 'propertyhive' ), |
| 689 |
'oil' => __( 'Oil Heating', 'propertyhive' ), |
| 690 |
'solar' => __( 'Solar Panels', 'propertyhive' ), |
| 691 |
'solar_water' => __( 'Solar Water Heating', 'propertyhive' ), |
| 692 |
'under_floor' => __( 'Underfloor Heating', 'propertyhive' ), |
| 693 |
'wood_burner' => __( 'Wood Burner', 'propertyhive' ), |
| 694 |
'open_fire' => __( 'Open Fire', 'propertyhive' ), |
| 695 |
'biomass_boiler' => __( 'Biomass Boiler', 'propertyhive' ), |
| 696 |
'ground_source_heat_pump' => __( 'Ground Source Heat Pump', 'propertyhive' ), |
| 697 |
'air_source_heat_pump' => __( 'Air Source Heat Pump', 'propertyhive' ), |
| 698 |
'solar_pv_thermal' => __( 'Solar PV Thermal', 'propertyhive' ), |
| 699 |
'solar_thermal' => __( 'Solar Thermal Heating', 'propertyhive' ), |
| 700 |
); |
| 701 |
|
| 702 |
$types = apply_filters( 'propertyhive_heating_types', $types ); |
| 703 |
|
| 704 |
asort($types); |
| 705 |
|
| 706 |
$types['other'] = __( 'Other', 'propertyhive' ); |
| 707 |
|
| 708 |
return $types; |
| 709 |
} |
| 710 |
|
| 711 |
function get_heating_type( $type ) |
| 712 |
{ |
| 713 |
$types = get_heating_types(); |
| 714 |
|
| 715 |
if ( isset($types[$type]) ) |
| 716 |
{ |
| 717 |
return $types[$type]; |
| 718 |
} |
| 719 |
|
| 720 |
return ''; |
| 721 |
} |
| 722 |
|
| 723 |
function get_sewerage_types() |
| 724 |
{ |
| 725 |
$types = array( |
| 726 |
'mains_supply' => __( 'Mains Supply', 'propertyhive' ), |
| 727 |
'private_supply' => __( 'Private Supply', 'propertyhive' ), |
| 728 |
); |
| 729 |
|
| 730 |
$types = apply_filters( 'propertyhive_sewerage_types', $types ); |
| 731 |
|
| 732 |
asort($types); |
| 733 |
|
| 734 |
$types['other'] = __( 'Other', 'propertyhive' ); |
| 735 |
|
| 736 |
return $types; |
| 737 |
} |
| 738 |
|
| 739 |
function get_sewerage_type( $type ) |
| 740 |
{ |
| 741 |
$types = get_sewerage_types(); |
| 742 |
|
| 743 |
if ( isset($types[$type]) ) |
| 744 |
{ |
| 745 |
return $types[$type]; |
| 746 |
} |
| 747 |
|
| 748 |
return ''; |
| 749 |
} |
| 750 |
|
| 751 |
function get_flooding_source_types() |
| 752 |
{ |
| 753 |
$types = array( |
| 754 |
'river' => __( 'River', 'propertyhive' ), |
| 755 |
'sea' => __( 'Sea', 'propertyhive' ), |
| 756 |
'groundwater' => __( 'Groundwater', 'propertyhive' ), |
| 757 |
'lake' => __( 'Lake', 'propertyhive' ), |
| 758 |
'reservoir' => __( 'Reservoir', 'propertyhive' ), |
| 759 |
); |
| 760 |
|
| 761 |
$types = apply_filters( 'propertyhive_flooding_source_types', $types ); |
| 762 |
|
| 763 |
asort($types); |
| 764 |
|
| 765 |
$types['other'] = __( 'Other', 'propertyhive' ); |
| 766 |
|
| 767 |
return $types; |
| 768 |
} |
| 769 |
|
| 770 |
function get_flooding_source_type( $type ) |
| 771 |
{ |
| 772 |
$types = get_flooding_source_types(); |
| 773 |
|
| 774 |
if ( isset($types[$type]) ) |
| 775 |
{ |
| 776 |
return $types[$type]; |
| 777 |
} |
| 778 |
|
| 779 |
return ''; |
| 780 |
} |
| 781 |
|
| 782 |
function get_accessibility_types() |
| 783 |
{ |
| 784 |
$types = array( |
| 785 |
'lateral_living' => __( 'Lateral Living', 'propertyhive' ), |
| 786 |
'level_access' => __( 'Level Access', 'propertyhive' ), |
| 787 |
'lift_access' => __( 'Lift Access', 'propertyhive' ), |
| 788 |
'step_free_access' => __( 'Step-Free Access', 'propertyhive' ), |
| 789 |
'wet_room' => __( 'Wet Room', 'propertyhive' ), |
| 790 |
'level_access_shower' => __( 'Level Access Shower', 'propertyhive' ), |
| 791 |
'wide_doorways' => __( 'Wide Doorways', 'propertyhive' ), |
| 792 |
'ramped_access' => __( 'Ramped Access', 'propertyhive' ), |
| 793 |
'unsuitableForWheelchairs' => __( 'Unsuitable for Wheelchairs', 'propertyhive' ), |
| 794 |
); |
| 795 |
|
| 796 |
$types = apply_filters( 'propertyhive_accessibility_types', $types ); |
| 797 |
|
| 798 |
asort($types); |
| 799 |
|
| 800 |
$types['other'] = __( 'Other', 'propertyhive' ); |
| 801 |
|
| 802 |
return $types; |
| 803 |
} |
| 804 |
|
| 805 |
function get_accessibility_type( $type ) |
| 806 |
{ |
| 807 |
$types = get_accessibility_types(); |
| 808 |
|
| 809 |
if ( isset($types[$type]) ) |
| 810 |
{ |
| 811 |
return $types[$type]; |
| 812 |
} |
| 813 |
|
| 814 |
return ''; |
| 815 |
} |
| 816 |
|
| 817 |
function get_restrictions() |
| 818 |
{ |
| 819 |
$types = array( |
| 820 |
'conservation_area' => __( 'Restrictions due to being in a conservation area', 'propertyhive' ), |
| 821 |
'lease_restrictions' => __( 'Restrictions in the lease', 'propertyhive' ), |
| 822 |
'listed_building' => __( 'Restrictions due to being listed', 'propertyhive' ), |
| 823 |
'permitted_development' => __( 'Restrictions on property development', 'propertyhive' ), |
| 824 |
'real_burdens' => __( 'A real burden applies to this property (Scotland only)', 'propertyhive' ), |
| 825 |
'holiday_home_rental' => __( 'Holiday home rental restrictions', 'propertyhive' ), |
| 826 |
'restrictive_covenant' => __( 'Restrictive covenants', 'propertyhive' ), |
| 827 |
'business_from_property' => __( 'Restrictions on running a business', 'propertyhive' ), |
| 828 |
'property_subletting' => __( 'Restrictions regarding subletting', 'propertyhive' ), |
| 829 |
'tree_preservation_order' => __( 'Tree preservation orders', 'propertyhive' ), |
| 830 |
); |
| 831 |
|
| 832 |
$types = apply_filters( 'propertyhive_restrictions', $types ); |
| 833 |
|
| 834 |
asort($types); |
| 835 |
|
| 836 |
$types['other'] = __( 'Other', 'propertyhive' ); |
| 837 |
|
| 838 |
return $types; |
| 839 |
} |
| 840 |
|
| 841 |
function get_restriction( $type ) |
| 842 |
{ |
| 843 |
$types = get_restrictions(); |
| 844 |
|
| 845 |
if ( isset($types[$type]) ) |
| 846 |
{ |
| 847 |
return $types[$type]; |
| 848 |
} |
| 849 |
|
| 850 |
return ''; |
| 851 |
} |
| 852 |
|
| 853 |
function get_rights() |
| 854 |
{ |
| 855 |
$types = array( |
| 856 |
'right_of_way_public' => __( 'Public rights of way', 'propertyhive' ), |
| 857 |
'right_of_way_private' => __( 'Private rights of way', 'propertyhive' ), |
| 858 |
'registered_easements_hmlr' => __( 'Registered easements/rights with the HMLR (Land Registry)', 'propertyhive' ), |
| 859 |
'servitudes' => __( 'Servitudes (Scotland only)', 'propertyhive' ), |
| 860 |
'shared_driveway' => __( 'Shared driveway', 'propertyhive' ), |
| 861 |
'loft_access' => __( 'Loft access', 'propertyhive' ), |
| 862 |
'drain_access' => __( 'Drain access', 'propertyhive' ), |
| 863 |
); |
| 864 |
|
| 865 |
$types = apply_filters( 'propertyhive_rights', $types ); |
| 866 |
|
| 867 |
asort($types); |
| 868 |
|
| 869 |
$types['other'] = __( 'Other', 'propertyhive' ); |
| 870 |
|
| 871 |
return $types; |
| 872 |
} |
| 873 |
|
| 874 |
function get_right( $type ) |
| 875 |
{ |
| 876 |
$types = get_rights(); |
| 877 |
|
| 878 |
if ( isset($types[$type]) ) |
| 879 |
{ |
| 880 |
return $types[$type]; |
| 881 |
} |
| 882 |
|
| 883 |
return ''; |
| 884 |
} |
| 885 |
|
| 886 |
add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single ) |
| 887 |
{ |
| 888 |
static $is_recursing = false; // Used to prevent infinite loop |
| 889 |
|
| 890 |
// Only filter if we're not recursing and if it is a post thumbnail ID |
| 891 |
if ( ! $is_recursing && $meta_key === '_thumbnail_id' && get_post_type( $post_id ) == 'property' ) |
| 892 |
{ |
| 893 |
$is_recursing = true; |
| 894 |
|
| 895 |
$value = get_post_thumbnail_id( $post_id ); |
| 896 |
|
| 897 |
$is_recursing = false; |
| 898 |
|
| 899 |
if ( empty($value) ) // If we haven't already get a thumbnail ID (i.e. in the case where someone has added theme support) |
| 900 |
{ |
| 901 |
$photos = get_post_meta( $post_id, '_photos', TRUE ); |
| 902 |
if ( is_array($photos) && !empty($photos) ) |
| 903 |
{ |
| 904 |
$photos = array_filter( $photos ); |
| 905 |
if ( !empty($photos) ) { $value = $photos[0]; } |
| 906 |
} |
| 907 |
} |
| 908 |
|
| 909 |
if ( ! $single ) |
| 910 |
{ |
| 911 |
$value = array( $value ); |
| 912 |
} |
| 913 |
} |
| 914 |
return $value; |
| 915 |
}, 10, 4); |
| 916 |
|
| 917 |
add_filter( 'wpseo_add_opengraph_images', function ( $object ) |
| 918 |
{ |
| 919 |
if ( get_option('propertyhive_images_stored_as', '') != 'urls' ) |
| 920 |
{ |
| 921 |
return $object; |
| 922 |
} |
| 923 |
|
| 924 |
global $post; |
| 925 |
|
| 926 |
if ( isset($post->post_type) && $post->post_type == 'property' ) |
| 927 |
{ |
| 928 |
$property = new PH_Property($post->ID); |
| 929 |
$photos = $property->_photo_urls; |
| 930 |
|
| 931 |
if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]) && isset($photos[0]['url'])) |
| 932 |
{ |
| 933 |
$secondary_image = array( 'url' => $photos[0]['url']/*, 'height' => 768, 'width' => 1024*/ ); |
| 934 |
$object->add_image( $secondary_image ); |
| 935 |
} |
| 936 |
} |
| 937 |
|
| 938 |
return $object; |
| 939 |
}); |