1: <?php
2: /**
3: * SHORTCODE :: Simple Google Map
4: *
5: * @package EPL
6: * @subpackage Shortcode/Map
7: * @copyright Copyright (c) 2020, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 1.0
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: /**
18: * Listing Google Map [listing_map]
19: *
20: * @param array $atts Shortcode attributes.
21: * @param array $content Content.
22: *
23: * @return string
24: * @since 1.0.0
25: * @since 3.4.18 Added wrapper class epl-section-map.
26: * @since 3.5.0 Fixed warnings. Added width, height and zoop options, allowed usage on any page and renamed file.
27: */
28: function epl_shortcode_googlemap_callback( $atts, $content = null ) {
29: global $property;
30:
31: $id = 0;
32:
33: if ( ! is_null( $property ) ) {
34: $id = $property->post->ID;
35: }
36:
37: $defaults = array(
38: 'width' => '100%', // Pass the width.
39: 'height' => '350px', // Pass the height.
40: 'zoom' => '17', // Map zoom level.
41: 'q' => '', // The Address to query.
42: 'cord' => '', // Lat/Long coordinates.
43: 'suburb_mode' => 0, // Suburb mode.
44: );
45:
46: $attributes = shortcode_atts(
47: $defaults,
48: $atts
49: );
50:
51: if ( empty( $attributes['cord'] ) && empty( $attributes['q'] ) ) {
52: return '';
53: }
54:
55: if ( ! is_epl_post() ) {
56: // Enqueue the Google Maps script if the shortcode is loaded on a page.
57: epl_shortcode_googlemap_enqueue();
58: }
59:
60: return '<div class="epl-tab-section epl-section-map epl-default-map-wrapper">
61: <div style="width:' . esc_attr( $attributes['width'] ) . '; height:' . esc_attr( $attributes['height'] ) . '" data-suburb_mode="' . esc_attr( $attributes['suburb_mode'] ) . '" data-cord="' . esc_attr( $attributes['cord'] ) . '" data-zoom="' . esc_attr( $attributes['zoom'] ) . '" data-id="' . esc_attr( $id ) . '" data-address="' . esc_attr( $attributes['q'] ) . '" class="epl-map-shortcode" id="epl-default-map"></div>
62: </div>';
63: }
64: add_shortcode( 'listing_map', 'epl_shortcode_googlemap_callback' );
65:
66:
67: /**
68: * Loads google map script on non EPL pages if listing_map shortcode is called.
69: *
70: * @since 3.5.0
71: * @since 3.5.3 Google Maps async. Prefix added.
72: */
73: function epl_shortcode_googlemap_enqueue() {
74:
75: $googleapiurl = 'https://maps.googleapis.com/maps/api/js?v=3.exp&callback=Function.prototype&loading=async';
76: $epl_google_api_key = epl_get_option( 'epl_google_api_key' );
77: if ( ! empty( $epl_google_api_key ) ) {
78: $googleapiurl = $googleapiurl . '&key=' . epl_get_option( 'epl_google_api_key' );
79: }
80:
81: if ( epl_get_option( 'epl_disable_google_api' ) !== 'on' ) {
82: wp_enqueue_script( 'epl-google-map-v-3', $googleapiurl, array(), EPL_PROPERTY_VER, false );
83: }
84: }
85: