| @@ -1,5 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit; | |
| 5 | +} | |
| 6 | + | |
| 2 | 7 | /** |
| 3 | 8 | * PropertyHive Property Functions |
| 4 | 9 | * |
| 5 | 10 | * Functions for property specific things. |
| @@ -16,8 +21,9 @@ | ||
| 16 | 21 | * @param mixed $the_property Post object or post ID of the property. |
| 17 | 22 | * @param array $args (default: array()) Contains all arguments to be used to get this property. |
| 18 | 23 | * @return PH_Property |
| 19 | 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. | |
| 20 | 26 | function get_property( $the_property = false, $args = array() ) { |
| 21 | 27 | return new PH_Property( $the_property ); |
| 22 | 28 | } |
| 23 | 29 | |
| @@ -26,8 +32,9 @@ | ||
| 26 | 32 | * |
| 27 | 33 | * @access public |
| 28 | 34 | * @return array |
| 29 | 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. | |
| 30 | 37 | function ph_get_featured_property_ids() { |
| 31 | 38 | |
| 32 | 39 | // Load from cache |
| 33 | 40 | $featured_property_ids = get_transient( 'ph_featured_properties' ); |
| @@ -39,8 +46,9 @@ | ||
| 39 | 46 | $featured = get_posts( array( |
| 40 | 47 | 'post_type' => 'property', |
| 41 | 48 | 'posts_per_page' => -1, |
| 42 | 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. | |
| 43 | 51 | 'meta_query' => array( |
| 44 | 52 | array( |
| 45 | 53 | 'key' => '_on_market', |
| 46 | 54 | 'value' => 'yes' |
| @@ -65,8 +73,9 @@ | ||
| 65 | 73 | * |
| 66 | 74 | * @access public |
| 67 | 75 | * @return string |
| 68 | 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. | |
| 69 | 78 | function ph_placeholder_img_src() { |
| 70 | 79 | return apply_filters( 'propertyhive_placeholder_img_src', PH()->plugin_url() . '/assets/images/placeholder.png' ); |
| 71 | 80 | } |
| 72 | 81 | |
| @@ -75,17 +84,19 @@ | ||
| 75 | 84 | * |
| 76 | 85 | * @access public |
| 77 | 86 | * @return string |
| 78 | 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. | |
| 79 | 89 | function ph_placeholder_img( $size = 'thumbnail' ) { |
| 80 | 90 | $dimensions = ph_get_image_size( $size ); |
| 81 | 91 | |
| 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'] ) . '" />' ); | |
| 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'] ) . '" />' ); | |
| 83 | 93 | } |
| 84 | 94 | |
| 85 | 95 | /** |
| 86 | 96 | * Track property views |
| 87 | 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. | |
| 88 | 99 | function ph_track_property_view() { |
| 89 | 100 | if ( ! is_singular( 'property' ) ) |
| 90 | 101 | return; |
| 91 | 102 | |
| @@ -93,18 +104,22 @@ | ||
| 93 | 104 | |
| 94 | 105 | // Track in cookie |
| 95 | 106 | if ( apply_filters( 'propertyhive_store_in_recently_viewed_cookie', true ) ) |
| 96 | 107 | { |
| 97 | - if ( empty( $_COOKIE['propertyhive_recently_viewed'] ) ) | |
| 98 | - $viewed_properties = array(); | |
| 99 | - else | |
| 100 | - $viewed_properties = (array) explode( '|', $_COOKIE['propertyhive_recently_viewed'] ); | |
| 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 ) ); | |
| 101 | 116 | |
| 102 | 117 | if ( ! in_array( $post->ID, $viewed_properties ) ) |
| 103 | 118 | $viewed_properties[] = $post->ID; |
| 104 | 119 | |
| 105 | - if ( sizeof( $viewed_properties ) > 15 ) | |
| 106 | - array_shift( $viewed_properties ); | |
| 120 | + if ( count( $viewed_properties ) > 15 ) | |
| 121 | + $viewed_properties = array_slice( $viewed_properties, -15 ); | |
| 107 | 122 | |
| 108 | 123 | // Store for session only |
| 109 | 124 | ph_setcookie( 'propertyhive_recently_viewed', implode( '|', $viewed_properties ) ); |
| 110 | 125 | } |
| @@ -120,14 +135,14 @@ | ||
| 120 | 135 | { |
| 121 | 136 | $view_counts = array(); |
| 122 | 137 | } |
| 123 | 138 | |
| 124 | - if ( !isset($view_counts[date("Y-m-d")]) ) | |
| 139 | + if ( !isset($view_counts[gmdate("Y-m-d")]) ) | |
| 125 | 140 | { |
| 126 | - $view_counts[date("Y-m-d")] = 0; | |
| 141 | + $view_counts[gmdate("Y-m-d")] = 0; | |
| 127 | 142 | } |
| 128 | 143 | |
| 129 | - ++$view_counts[date("Y-m-d")]; | |
| 144 | + ++$view_counts[gmdate("Y-m-d")]; | |
| 130 | 145 | |
| 131 | 146 | update_post_meta( $post->ID, '_view_statistics', $view_counts ); |
| 132 | 147 | } |
| 133 | 148 | } |
| @@ -133,8 +148,9 @@ | ||
| 133 | 148 | } |
| 134 | 149 | |
| 135 | 150 | add_action( 'template_redirect', 'ph_track_property_view', 20 ); |
| 136 | 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. | |
| 137 | 153 | function get_property_map( $args = array() ) |
| 138 | 154 | { |
| 139 | 155 | global $property; |
| 140 | 156 | |
| @@ -139,27 +155,247 @@ | ||
| 139 | 155 | global $property; |
| 140 | 156 | |
| 141 | 157 | if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' ) |
| 142 | 158 | { |
| 143 | - $api_key = get_option('propertyhive_google_maps_api_key'); | |
| 144 | - wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3'); | |
| 145 | - wp_enqueue_script('googlemaps'); | |
| 159 | + $id_suffix = ( ( isset($args['id']) && $args['id'] != '' ) ? '_' . $args['id'] : '' ); | |
| 146 | 160 | |
| 147 | - $id_suffix = ( ( isset($args['id']) && $args['id'] != '' ) ? '_' . $args['id'] : '' ); | |
| 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>'; | |
| 148 | 164 | |
| 149 | - echo '<div id="property_map_canvas' . $id_suffix . '" style="height:' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) ) ? $args['height'] : '400' ) ) . 'px"></div>'; | |
| 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'); | |
| 150 | 172 | ?> |
| 151 | 173 | <script> |
| 152 | 174 | |
| 153 | - // We declare vars globally so developers can access them | |
| 154 | - var property_map<?php echo $id_suffix; ?>; // Global declaration of the map | |
| 155 | - var property_marker<?php echo $id_suffix; ?>; // Global declaration of the marker | |
| 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); ?>; | |
| 156 | 392 | |
| 157 | - function initialize_property_map<?php echo $id_suffix; ?>() { | |
| 393 | + function initialize_property_map<?php echo esc_js($id_suffix); ?>() { | |
| 158 | 394 | |
| 159 | - var myLatlng = new google.maps.LatLng(<?php echo $property->latitude; ?>, <?php echo $property->longitude; ?>); | |
| 395 | + var myLatlng = new google.maps.LatLng(<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>); | |
| 160 | 396 | var map_options = { |
| 161 | - zoom: <?php echo ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? $args['zoom'] : '14' ); ?>, | |
| 397 | + zoom: <?php echo ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? (int)$args['zoom'] : '14' ); ?>, | |
| 162 | 398 | center: myLatlng, |
| 163 | 399 | mapTypeId: google.maps.MapTypeId.ROADMAP, |
| 164 | 400 | scrollwheel: <?php echo ( ( isset($args['scrollwheel']) && ($args['scrollwheel'] === 'false' || $args['scrollwheel'] === FALSE) ) ? 'false' : 'true' ); ?> |
| 165 | 401 | } |
| @@ -167,22 +403,26 @@ | ||
| 167 | 403 | if ( class_exists( 'PH_Map_Search' ) ) |
| 168 | 404 | { |
| 169 | 405 | $map_add_on_settings = get_option( 'propertyhive_map_search', array() ); |
| 170 | 406 | |
| 171 | - if ( isset($map_add_on_settings['style_js']) && trim($map_add_on_settings['style_js']) != '' ) | |
| 407 | + if ( isset($map_add_on_settings['style_js']) && is_string($map_add_on_settings['style_js']) && trim($map_add_on_settings['style_js']) != '' ) | |
| 172 | 408 | { |
| 173 | - echo 'map_options.styles = ' . trim($map_add_on_settings['style_js']) . ';'; | |
| 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 | + } | |
| 174 | 414 | } |
| 175 | 415 | } |
| 176 | 416 | |
| 177 | - do_action( 'propertyhive_property_map_options' ); | |
| 417 | + do_action( 'propertyhive_property_map_options', $property, $args, $id_suffix ); | |
| 178 | 418 | ?> |
| 179 | - property_map<?php echo $id_suffix; ?> = new google.maps.Map(document.getElementById("property_map_canvas<?php echo $id_suffix; ?>"), map_options); | |
| 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); | |
| 180 | 420 | |
| 181 | - var myLatlng = new google.maps.LatLng(<?php echo $property->latitude; ?>, <?php echo $property->longitude; ?>); | |
| 421 | + var myLatlng = new google.maps.LatLng(<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>); | |
| 182 | 422 | |
| 183 | 423 | var marker_options = { |
| 184 | - map: property_map<?php echo $id_suffix; ?>, | |
| 424 | + map: property_map<?php echo esc_js($id_suffix); ?>, | |
| 185 | 425 | position: myLatlng |
| 186 | 426 | }; |
| 187 | 427 | |
| 188 | 428 | <?php |
| @@ -194,9 +434,20 @@ | ||
| 194 | 434 | { |
| 195 | 435 | $marker_icon_url = wp_get_attachment_url( $map_add_on_settings['custom_icon_attachment_id'] ); |
| 196 | 436 | if ( $marker_icon_url !== FALSE ) |
| 197 | 437 | { |
| 198 | - echo 'marker_options.icon = \'' . $marker_icon_url . '\';'; | |
| 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;'; | |
| 199 | 450 | } |
| 200 | 451 | } |
| 201 | 452 | } |
| 202 | 453 | ?> |
| @@ -202,76 +453,477 @@ | ||
| 202 | 453 | ?> |
| 203 | 454 | |
| 204 | 455 | <?php do_action( 'propertyhive_property_map_marker_options' ); ?> |
| 205 | 456 | |
| 206 | - property_marker<?php echo $id_suffix; ?> = new google.maps.Marker(marker_options); | |
| 457 | + property_marker<?php echo esc_js($id_suffix); ?> = new google.maps.Marker(marker_options); | |
| 458 | + | |
| 459 | + <?php do_action( 'propertyhive_property_map_actions' ); ?> | |
| 207 | 460 | } |
| 208 | 461 | |
| 462 | + <?php if ( !isset($args['init_on_load']) || ( isset($args['init_on_load']) && ($args['init_on_load'] === 'true' || $args['init_on_load'] === TRUE) ) ) { ?> | |
| 209 | 463 | if(window.addEventListener) { |
| 210 | - window.addEventListener('load', initialize_property_map<?php echo $id_suffix; ?>); | |
| 464 | + window.addEventListener('load', initialize_property_map<?php echo esc_js($id_suffix); ?>); | |
| 211 | 465 | }else{ |
| 212 | - window.attachEvent('onload', initialize_property_map<?php echo $id_suffix; ?>); | |
| 466 | + window.attachEvent('onload', initialize_property_map<?php echo esc_js($id_suffix); ?>); | |
| 213 | 467 | } |
| 468 | + <?php } ?> | |
| 214 | 469 | |
| 215 | 470 | </script> |
| 216 | 471 | <?php |
| 472 | + } | |
| 473 | + } | |
| 474 | + do_action( 'propertyhive_property_map_after' ); | |
| 217 | 475 | } |
| 218 | 476 | } |
| 219 | 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. | |
| 220 | 530 | function get_property_street_view( $args = array() ) |
| 221 | 531 | { |
| 222 | 532 | global $property; |
| 223 | 533 | |
| 224 | - if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' ) | |
| 534 | + if ( get_option('propertyhive_maps_provider') == 'osm' || get_option('propertyhive_maps_provider') == 'mapbox' ) | |
| 225 | 535 | { |
| 226 | - $api_key = get_option('propertyhive_google_maps_api_key'); | |
| 227 | - wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3'); | |
| 228 | - wp_enqueue_script('googlemaps'); | |
| 229 | 536 | |
| 230 | - echo '<div id="property_street_view_canvas" style="height:' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) ) ? $args['height'] : '400' ) ) . 'px"></div>'; | |
| 231 | -?> | |
| 232 | -<script> | |
| 233 | 537 | |
| 234 | - // We declare vars globally so developers can access them | |
| 235 | - var property_street_view; // Global declaration of the map | |
| 236 | - | |
| 237 | - function initialize_property_street_view() { | |
| 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 | |
| 238 | 567 | |
| 239 | - var myLatlng = new google.maps.LatLng(<?php echo $property->latitude; ?>, <?php echo $property->longitude; ?>); | |
| 240 | - var map_options = { | |
| 241 | - center: myLatlng | |
| 242 | - } | |
| 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 | + } | |
| 243 | 574 | |
| 244 | - <?php do_action( 'propertyhive_property_street_view_map_options' ); ?> | |
| 575 | + <?php do_action( 'propertyhive_property_street_view_map_options' ); ?> | |
| 245 | 576 | |
| 246 | - property_street_view = new google.maps.Map(document.getElementById("property_street_view_canvas"), map_options); | |
| 247 | - | |
| 248 | - var streetViewOptions = { | |
| 249 | - position: myLatlng, | |
| 250 | - pov: { | |
| 251 | - heading: 90, | |
| 252 | - pitch: 0, | |
| 253 | - zoom: 0 | |
| 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 | |
| 254 | 601 | } |
| 255 | - }; | |
| 602 | + } | |
| 603 | + ?> | |
| 256 | 604 | |
| 257 | - <?php do_action( 'propertyhive_property_street_view_options' ); ?> | |
| 605 | + </script> | |
| 606 | + <?php | |
| 607 | + } | |
| 608 | + } | |
| 609 | +} | |
| 258 | 610 | |
| 259 | - var streetView = new google.maps.StreetViewPanorama(document.getElementById("property_street_view_canvas"), streetViewOptions); | |
| 260 | - streetView.setVisible(true); | |
| 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]; | |
| 261 | 638 | } |
| 262 | - | |
| 263 | - if(window.addEventListener) { | |
| 264 | - window.addEventListener('load', initialize_property_street_view); | |
| 265 | - }else{ | |
| 266 | - window.attachEvent('onload', initialize_property_street_view); | |
| 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]; | |
| 267 | 668 | } |
| 268 | 669 | |
| 269 | -</script> | |
| 270 | -<?php | |
| 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]; | |
| 271 | 701 | } |
| 702 | + | |
| 703 | + return ''; | |
| 272 | 704 | } |
| 273 | 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 | + | |
| 274 | 926 | add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single ) |
| 275 | 927 | { |
| 276 | 928 | static $is_recursing = false; // Used to prevent infinite loop |
| 277 | 929 | |
| @@ -283,15 +935,15 @@ | ||
| 283 | 935 | $value = get_post_thumbnail_id( $post_id ); |
| 284 | 936 | |
| 285 | 937 | $is_recursing = false; |
| 286 | 938 | |
| 287 | - if ( $value == '' ) // If we haven't already get a thumbnail ID (i.e. in the case where someone has added theme support) | |
| 939 | + if ( empty($value) ) // If we haven't already get a thumbnail ID (i.e. in the case where someone has added theme support) | |
| 288 | 940 | { |
| 289 | 941 | $photos = get_post_meta( $post_id, '_photos', TRUE ); |
| 290 | 942 | if ( is_array($photos) && !empty($photos) ) |
| 291 | 943 | { |
| 292 | 944 | $photos = array_filter( $photos ); |
| 293 | - $value = $photos[0]; | |
| 945 | + if ( !empty($photos) ) { $value = $photos[0]; } | |
| 294 | 946 | } |
| 295 | 947 | } |
| 296 | 948 | |
| 297 | 949 | if ( ! $single ) |
| @@ -299,5 +951,29 @@ | ||
| 299 | 951 | $value = array( $value ); |
| 300 | 952 | } |
| 301 | 953 | } |
| 302 | 954 | return $value; |
| 303 | -}, 10, 4); | |
| 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 | +}); | |