1: <?php
2: /**
3: * Outputs a property map onto the property template using a hook
4: * This allows us to filter the hook and replace it with a different map
5: *
6: * @package EPL
7: * @subpackage Hooks/Map
8: * @copyright Copyright (c) 2020, Merv Barrett
9: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10: * @since 1.0.0
11: */
12:
13: // Exit if accessed directly.
14: if ( ! defined( 'ABSPATH' ) ) {
15: exit;
16: }
17:
18: /**
19: * Pulls the address details so the map can be generated
20: *
21: * @param array $args Shortcode options.
22: *
23: * @since 1.0.0
24: * @since 3.5.0 Tweak: [listing_map] Shortcode Added width, height and zoom options and allowed usage on any page. Filter: epl_map_display_defaults added.
25: */
26: function epl_property_map_default_callback( $args ) {
27:
28: $defaults = array(
29: 'width' => '100%',
30: 'height' => '350px',
31: 'zoom' => '17',
32: );
33:
34: $args = wp_parse_args( $args, apply_filters( 'epl_map_display_defaults', $defaults ) );
35:
36: global $property;
37:
38: $api_key = epl_get_option( 'epl_google_api_key' );
39: $show_warning = apply_filters( 'epl_show_map_key_warning', true );
40:
41: if ( empty( $api_key ) ) {
42: if ( $show_warning && is_user_logged_in() && current_user_can( 'administrator' ) ) {
43: epl_map_api_key_warning();
44: }
45: return;
46: }
47:
48: // Only show map if address display is set to true.
49: if ( 'yes' === $property->get_property_meta( 'property_address_display' ) ) {
50:
51: $address = epl_property_get_the_full_address();
52: $address = apply_filters( 'epl_map_address', $address );
53:
54: // Use coordinates if they are already present.
55: $coordinates = $property->get_property_meta( 'property_address_coordinates' );
56:
57: echo do_shortcode( '[listing_map zoom=14 width="' . $args['width'] . '" height="' . $args['height'] . '" zoom="' . $args['zoom'] . '" cord="' . $coordinates . '" q="' . $address . '"]' );
58: } else {
59:
60: $address = $property->get_property_meta( 'property_address_suburb' ) . ', ';
61: $address .= $property->get_property_meta( 'property_address_state' ) . ', ';
62: $address .= $property->get_property_meta( 'property_address_postal_code' );
63: $address = apply_filters( 'epl_map_address', $address );
64: echo do_shortcode( '[listing_map zoom=14 suburb_mode=1 q="' . $address . '"]' );
65: }
66: }
67: add_action( 'epl_property_map', 'epl_property_map_default_callback' );
68:
69: /**
70: * Missing map key warning message
71: *
72: * @since 3.3.0
73: */
74: function epl_map_api_key_warning() {
75: ?>
76:
77: <div class="epl-danger epl-warning-map-key">
78: <p><?php esc_html_e( 'Ensure you have set a Google Maps API Key from Dashboard > Easy Property Listings > Settings.', 'easy-property-listings' ); ?>
79: <em><?php esc_html_e( 'Note: This message is only displayed to logged in administrators.', 'easy-property-listings' ); ?></em>
80: </p>
81: </div>
82: <?php
83: }
84: