1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed.'); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* EEH_Maps |
7
|
|
|
* This is a helper utility class that provides different helpers related to mapping and displaying location related |
8
|
|
|
* data. |
9
|
|
|
* |
10
|
|
|
* @package Event Espresso |
11
|
|
|
* @subpackage /helpers/EEH_Maps.helper.php |
12
|
|
|
* @author Hugo Ashmore, Brent Christensen, Darren Ethier |
13
|
|
|
*/ |
14
|
|
|
class EEH_Maps |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
// array of map settings |
18
|
|
|
public static $gmap_vars = array(); |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* google_map - creates a Google Map Link |
23
|
|
|
* |
24
|
|
|
* @param array $ee_gmaps_opts array of attributes required for the map link generation |
25
|
|
|
* @return string (link to map!) |
26
|
|
|
*/ |
27
|
|
|
public static function google_map($ee_gmaps_opts) |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
$ee_map_width = ! empty($ee_gmaps_opts['ee_map_width']) ? $ee_gmaps_opts['ee_map_width'] : '300'; |
31
|
|
|
$ee_map_height = ! empty($ee_gmaps_opts['ee_map_height']) ? $ee_gmaps_opts['ee_map_height'] : '185'; |
32
|
|
|
$ee_map_zoom = ! empty($ee_gmaps_opts['ee_map_zoom']) ? $ee_gmaps_opts['ee_map_zoom'] : '12'; |
33
|
|
|
$ee_map_nav_display = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false'; |
34
|
|
|
$ee_map_nav_size = ! empty($ee_gmaps_opts['ee_map_nav_size']) |
35
|
|
|
? $ee_gmaps_opts['ee_map_nav_size'] |
36
|
|
|
: 'default'; |
37
|
|
|
$ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control']) |
38
|
|
|
? $ee_gmaps_opts['ee_map_type_control'] |
39
|
|
|
: 'default'; |
40
|
|
|
$static_url = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false; |
41
|
|
|
|
42
|
|
|
if (! empty($ee_gmaps_opts['ee_map_align'])) { |
43
|
|
|
switch ($ee_gmaps_opts['ee_map_align']) { |
44
|
|
|
case "left": |
45
|
|
|
$map_align = 'ee-gmap-align-left left'; |
46
|
|
|
break; |
47
|
|
|
case "right": |
48
|
|
|
$map_align = 'ee-gmap-align-right right'; |
49
|
|
|
break; |
50
|
|
|
case "center": |
51
|
|
|
$map_align = 'ee-gmap-align-center center'; |
52
|
|
|
break; |
53
|
|
|
case "none": |
54
|
|
|
default: |
55
|
|
|
$map_align = 'ee-gmap-align-none'; |
56
|
|
|
} |
57
|
|
|
} else { |
58
|
|
|
$map_align = 'ee-gmap-align-none'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
// Determine whether user has set a hardoded url to use and |
63
|
|
|
// if so display a Google static iframe map else run V3 api |
64
|
|
|
if ($static_url) { |
65
|
|
|
$html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">'; |
66
|
|
|
$html .= '<iframe src="' . $static_url . '&output=embed"' |
67
|
|
|
. ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"' |
68
|
|
|
. ' frameborder="0" scrolling="no">'; |
69
|
|
|
$html .= '</iframe>'; |
70
|
|
|
$html .= '<a href="' . $static_url . '">View Large map</a>'; |
71
|
|
|
$html .= '</div>'; |
72
|
|
|
return $html; |
73
|
|
|
|
74
|
|
|
} else { |
75
|
|
|
EEH_Maps::$gmap_vars[$ee_gmaps_opts['map_ID']] = array( |
76
|
|
|
'map_ID' => $ee_gmaps_opts['map_ID'], |
77
|
|
|
'ee_map_zoom' => $ee_map_zoom, |
78
|
|
|
'ee_map_nav_display' => $ee_map_nav_display, |
79
|
|
|
'ee_map_nav_size' => $ee_map_nav_size, |
80
|
|
|
'ee_map_type_control' => $ee_map_type_control, |
81
|
|
|
'location' => $ee_gmaps_opts['location'], |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;'; |
85
|
|
|
$html = '<div class="ee-gmap-wrapper ' . $map_align . '">' |
86
|
|
|
. '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"' |
87
|
|
|
. ' style="' . $style . '"></div>' |
88
|
|
|
. '</div>'; |
89
|
|
|
|
90
|
|
|
wp_enqueue_script('gmap_api'); |
91
|
|
|
wp_enqueue_script('ee_gmap'); |
92
|
|
|
add_action('wp_footer', array('EEH_Maps', 'footer_enqueue_script')); |
93
|
|
|
|
94
|
|
|
return $html; |
95
|
|
|
} // end auto map or static url map check |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* enqueue_script |
101
|
|
|
* |
102
|
|
|
* @return void |
103
|
|
|
*/ |
104
|
|
|
public static function footer_enqueue_script() |
105
|
|
|
{ |
106
|
|
|
wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* registers scripts for maps |
112
|
|
|
*/ |
113
|
|
|
public static function espresso_google_map_js() |
114
|
|
|
{ |
115
|
|
|
$api_url = sprintf( |
116
|
|
|
"https://maps.googleapis.com/maps/api/js?key=%s", |
117
|
|
|
apply_filters( |
118
|
|
|
'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
119
|
|
|
EE_Registry::instance()->CFG->map_settings->google_map_api_key |
120
|
|
|
) |
121
|
|
|
); |
122
|
|
|
wp_register_script('gmap_api', $api_url, array('jquery'), null, true); |
123
|
|
|
wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* creates a Google Map Link |
128
|
|
|
* |
129
|
|
|
* @param array $atts array of attributes required for the map link generation |
130
|
|
|
* @return string (link to map!) |
131
|
|
|
*/ |
132
|
|
|
public static function google_map_link($atts) |
133
|
|
|
{ |
134
|
|
|
do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
135
|
|
|
extract($atts); |
136
|
|
|
/** @var string $address */ |
137
|
|
|
/** @var string $city */ |
138
|
|
|
/** @var string $state */ |
139
|
|
|
/** @var string $zip */ |
140
|
|
|
/** @var string $country */ |
141
|
|
|
$address = "{$address}"; |
142
|
|
|
$city = "{$city}"; |
143
|
|
|
$state = "{$state}"; |
144
|
|
|
$zip = "{$zip}"; |
145
|
|
|
$country = "{$country}"; |
146
|
|
|
$text = isset($text) ? "{$text}" : ""; |
147
|
|
|
$type = isset($type) ? "{$type}" : ""; |
148
|
|
|
$map_w = isset($map_w) ? "{$map_w}" : 400; |
|
|
|
|
149
|
|
|
$map_h = isset($map_h) ? "{$map_h}" : 400; |
|
|
|
|
150
|
|
|
$id = isset($id) ? $id : 'not_set'; |
|
|
|
|
151
|
|
|
$map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view'; |
|
|
|
|
152
|
|
|
|
153
|
|
|
$address_string = ($address != '' ? $address : '') |
154
|
|
|
. ($city != '' ? ',' . $city : '') |
155
|
|
|
. ($state != '' ? ',' . $state : '') |
156
|
|
|
. ($zip != '' ? ',' . $zip : '') |
157
|
|
|
. ($country != '' ? ',' . $country : ''); |
158
|
|
|
|
159
|
|
|
$google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string)); |
160
|
|
|
|
161
|
|
|
switch ($type) { |
162
|
|
|
case 'text': |
163
|
|
|
default: |
164
|
|
|
$text = $text == '' ? __('Map and Directions', 'event_espresso') : $text; |
165
|
|
|
break; |
166
|
|
|
|
167
|
|
|
case 'url_only': |
168
|
|
|
case 'url': |
169
|
|
|
$text = $google_map; |
170
|
|
|
break; |
171
|
|
|
|
172
|
|
|
case 'map': |
173
|
|
|
$scheme = is_ssl() ? 'https://' : 'http://'; |
174
|
|
|
|
175
|
|
|
$api_key = apply_filters( |
176
|
|
|
'FHEE__EEH_Maps__espresso_google_maps_link__api_key', |
177
|
|
|
EE_Registry::instance()->CFG->map_settings->google_map_api_key |
178
|
|
|
); |
179
|
|
|
|
180
|
|
|
return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&zoom=14&size=' . $map_w . 'x' . $map_h . '&markers=color:green|label:|' . urlencode($address_string) . '&sensor=false&key=' . $api_key) . '" /></a>'; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
return $type === 'url_only' |
184
|
|
|
? $text |
185
|
|
|
: '<a href="' . $google_map . '" target="_blank">' . $text . '</a>'; |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
// End of file EEH_Maps.helper.php |
189
|
|
|
// Location: /helpers/EEH_Maps.helper.php |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.