Google_Maps_Builder_Engine   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 101
rs 10
c 0
b 0
f 0
wmc 19
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
D google_maps_shortcode() 0 76 18
1
<?php
2
3
/**
4
 * Maps Builder Engine
5
 *
6
 * The Google Maps engine class for WordPress Google Maps Builder
7
 *
8
 * @package   Google_Maps_Builder
9
 * @author    Devin Walker <[email protected]>
10
 * @license   GPL-2.0+
11
 * @link      http://wordimpress.com
12
 * @copyright 2015 WordImpress, Devin Walker
13
 */
14
15
/**
16
 * Class Google_Maps_Builder_Engine
17
 */
18
class Google_Maps_Builder_Engine extends Google_Maps_Builder_Core_Engine {
19
20
21
	/**
22
	 * Google_Maps_Builder_Engine constructor.
23
	 */
24
	public function __construct() {
25
26
		parent::__construct();
27
28
	}
29
30
31
	/**
32
	 * Google Maps Builder Shortcode
33
	 *
34
	 * Google Maps output relies on the shortcode to display
35
	 *
36
	 * @param $atts
37
	 *
38
	 * @return string
39
	 */
40
	public function google_maps_shortcode( $atts ) {
41
42
		$atts = shortcode_atts(
43
			array(
44
				'title'     => '',
45
				'id'        => '',
46
				'reference' => '',
47
			), $atts, 'google_maps'
48
		);
49
50
		//gather data for this shortcode
51
		$post     = get_post( $atts['id'] );
52
		$all_meta = get_post_custom( $atts['id'] );
53
54
		$visual_info = maybe_unserialize( $all_meta['gmb_width_height'][0] );
55
		$lat_lng     = maybe_unserialize( $all_meta['gmb_lat_lng'][0] );
56
57
		//Put markers into an array for JS usage
58
		$map_marker_array   = array();
59
		$markers_repeatable = isset( $all_meta['gmb_markers_group'][0] ) ? maybe_unserialize( $all_meta['gmb_markers_group'][0] ) : '';
60
61
		if ( is_array( $markers_repeatable ) ) {
62
			foreach ( $markers_repeatable as $marker ) {
63
				array_push( $map_marker_array, $marker );
64
			}
65
		}
66
67
		//Send data for AJAX usage
68
		//Add params to AJAX for Shortcode Usage
69
		//@see: http://benjaminrojas.net/using-wp_localize_script-dynamically/
70
		$localized_data = apply_filters( 'gmb_localized_data', array(
71
			$post->ID => array(
72
				'id'               => $atts['id'],
73
				'map_params'       => array(
74
					'title'          => $post->post_title,
75
					'width'          => $visual_info['width'],
76
					'height'         => $visual_info['height'],
77
					'latitude'       => $lat_lng['latitude'],
78
					'longitude'      => $lat_lng['longitude'],
79
					'zoom'           => ! empty( $all_meta['gmb_zoom'][0] ) ? $all_meta['gmb_zoom'][0] : '15',
80
					'default_marker' => apply_filters( 'gmb_default_marker', GMB_PLUGIN_URL . 'assets/img/spotlight-poi.png' ),
81
				),
82
				'map_controls'     => array(
83
					'zoom_control'      => ! empty( $all_meta['gmb_zoom_control'][0] ) ? strtoupper( $all_meta['gmb_zoom_control'][0] ) : 'STANDARD',
84
					'pan_control'       => ! empty( $all_meta['gmb_pan'][0] ) ? $all_meta['gmb_pan'][0] : 'none',
85
					'map_type_control'  => ! empty( $all_meta['gmb_map_type_control'][0] ) ? $all_meta['gmb_map_type_control'][0] : 'none',
86
					'draggable'         => ! empty( $all_meta['gmb_draggable'][0] ) ? $all_meta['gmb_draggable'][0] : 'none',
87
					'double_click_zoom' => ! empty( $all_meta['gmb_double_click'][0] ) ? $all_meta['gmb_double_click'][0] : 'none',
88
					'wheel_zoom'        => ! empty( $all_meta['gmb_wheel_zoom'][0] ) ? $all_meta['gmb_wheel_zoom'][0] : 'none',
89
					'street_view'       => ! empty( $all_meta['gmb_street_view'][0] ) ? $all_meta['gmb_street_view'][0] : 'none',
90
				),
91
				'map_theme'        => array(
92
					'map_type'       => ! empty( $all_meta['gmb_type'][0] ) ? $all_meta['gmb_type'][0] : 'RoadMap',
93
					'map_theme_json' => ! empty( $all_meta['gmb_theme_json'][0] ) ? $all_meta['gmb_theme_json'][0] : 'none',
94
95
				),
96
				'map_markers'      => $map_marker_array,
97
				'plugin_url'       => GMB_PLUGIN_URL,
98
				'places_api'       => array(
99
					'show_places'   => ! empty( $all_meta['gmb_show_places'][0] ) ? $all_meta['gmb_show_places'][0] : 'no',
100
					'search_radius' => ! empty( $all_meta['gmb_search_radius'][0] ) ? $all_meta['gmb_search_radius'][0] : '3000',
101
					'search_places' => ! empty( $all_meta['gmb_places_search_multicheckbox'][0] ) ? maybe_unserialize( $all_meta['gmb_places_search_multicheckbox'][0] ) : '',
102
				),
103
				'map_markers_icon' => ! empty( $all_meta['gmb_map_marker'] ) ? $all_meta['gmb_map_marker'][0] : 'none',
104
			)
105
		) );
106
107
		$this->array_push_localized_script( $localized_data );
108
109
		ob_start();
110
111
		include $this->get_google_maps_template( 'public.php' );
112
113
		return apply_filters( 'gmb_shortcode_output', ob_get_clean() );
114
115
	}
116
117
118
}
119