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