Changeset 1868734
- Timestamp:
- 05/04/2018 02:51:09 PM (8 years ago)
- Location:
- gmaps-google-maps-shortcode/trunk
- Files:
-
- 1 edited
- 1 moved
-
GMaps.php (modified) (23 diffs)
-
README.txt (moved) (moved from gmaps-google-maps-shortcode/trunk/README.md) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gmaps-google-maps-shortcode/trunk/GMaps.php
r1868733 r1868734 32 32 * in the form of 'map_'.uniqid(). 33 33 */ 34 function do_gmaps_maps ($attrs, $content = null) {34 function do_gmaps_maps_5ae9fcc8cf7e2($attrs, $content = null) { 35 35 $type = isset($attrs["type"]) ? $attrs["type"] : 'roadmap'; 36 36 $lat = isset($attrs["lat"]) ? $attrs["lat"] : 0; … … 70 70 71 71 // Generate the map and push it onto the global maps array. 72 array_push($GLOBALS[" gmaps-maps"], "72 array_push($GLOBALS["5ae9fcc8cf7e2-gmaps-maps"], " 73 73 var $mapId = new google.maps.Map(document.getElementById('$mapId'), { 74 74 center: {lat: $lat, lng: $lng}, … … 93 93 // Create a global variable to store our map id, 94 94 // so any child element's will know what map they belong too. 95 $GLOBALS[" current-gmaps-map-id"] = $mapId;95 $GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"] = $mapId; 96 96 97 97 // Parse for nested shortcode. … … 99 99 do_shortcode($content); 100 100 } 101 unset($GLOBALS[" current-gmaps-map-id"]);101 unset($GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"]); 102 102 return $out."id='$mapId'></div>"; 103 103 } … … 109 109 * format 'marker_'.uniqid(). 110 110 */ 111 function do_gmaps_marker ($attrs) {111 function do_gmaps_marker_5ae9fcc8cf7e2($attrs) { 112 112 if(!isset($attrs["lng"]) || !isset($attrs['lat'])) { 113 113 echo "Google Maps Markers require Long & lang param's"; … … 115 115 } else { 116 116 117 if(isset($GLOBALS[" current-gmaps-map-id"])) {118 $current_map = $GLOBALS[" current-gmaps-map-id"];117 if(isset($GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"])) { 118 $current_map = $GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"]; 119 119 } 120 120 … … 139 139 });"; 140 140 141 array_push($GLOBALS[" gmaps-markers"], $marker);141 array_push($GLOBALS["5ae9fcc8cf7e2-gmaps-markers"], $marker); 142 142 } 143 143 } … … 147 147 * The `path` attribute is required 148 148 */ 149 function do_gmaps_polygon ($attrs) {149 function do_gmaps_polygon_5ae9fcc8cf7e2($attrs) { 150 150 if(!isset($attrs["path"])) { 151 151 echo "gmaps-polygon requires the 'path' attribute"; … … 183 183 } 184 184 185 if(isset($GLOBALS[" current-gmaps-map-id"])) {185 if(isset($GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"])) { 186 186 $out = $out." 187 187 strokeColor: '$stroke_color', … … 197 197 fillOpacity: $fill_opacity 198 198 }); 199 $gone_id.setMap(".$GLOBALS[" current-gmaps-map-id"].");";200 } 201 202 array_push($GLOBALS[" gmaps-polygons"], $out);199 $gone_id.setMap(".$GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"].");"; 200 } 201 202 array_push($GLOBALS["5ae9fcc8cf7e2-gmaps-polygons"], $out); 203 203 } 204 204 } … … 207 207 * Generate a Polyline JavaScript Object, the `path` attribute is required. 208 208 */ 209 function do_gmaps_polyline ($attrs) {209 function do_gmaps_polyline_5ae9fcc8cf7e2($attrs) { 210 210 if(!isset($attrs["path"])) { 211 211 echo "gmaps-polyline requires the 'path' attribute"; … … 232 232 233 233 if(sizeof($points) <=1 ) { 234 echo "gmaps-polyline requires more th eone point";234 echo "gmaps-polyline requires more than one point"; 235 235 return; 236 236 } else { … … 244 244 } 245 245 } 246 if(isset($GLOBALS[" current-gmaps-map-id"])) {246 if(isset($GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"])) { 247 247 $out = $out." 248 248 strokeColor: '$stroke_color', … … 256 256 clickable: $clickable 257 257 }); 258 $line_id.setMap(".$GLOBALS["current-gmaps-map-id"].");"; 258 $line_id.setMap(".$GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"].");"; 259 array_push($GLOBALS["5ae9fcc8cf7e2-gmaps-polylines"], $out); 259 260 } 260 261 array_push($GLOBALS["gmaps-polylines"], $out);262 261 } 263 262 } … … 269 268 * pass the marker id in via the `marker` attribute. 270 269 */ 271 function do_gmaps_info_window ($attrs, $content = null) {270 function do_gmaps_info_window_5ae9fcc8cf7e2($attrs, $content = null) { 272 271 $winId = 'info_window_'.uniqid(); 273 272 if(!isset($attrs["marker"])) { … … 277 276 $marker = $attrs["marker"]; 278 277 } 279 if(isset($GLOBALS[" current-gmaps-map-id"])) {280 $current_map = $GLOBALS[" current-gmaps-map-id"];278 if(isset($GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"])) { 279 $current_map = $GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"]; 281 280 } 282 281 … … 293 292 "; 294 293 295 array_push($GLOBALS[" gmaps-info-windows"], $out);294 array_push($GLOBALS["5ae9fcc8cf7e2-gmaps-info-windows"], $out); 296 295 } 297 296 … … 302 301 * google maps api. 303 302 */ 304 function include_google_maps () {305 306 $maps = implode('', $GLOBALS[" gmaps-maps"]);307 $markers = implode('', $GLOBALS[" gmaps-markers"]);308 $polylines = implode('', $GLOBALS[" gmaps-polylines"]);309 $polygons = implode('', $GLOBALS[" gmaps-polygons"]);310 $info_windows = implode('', $GLOBALS[" gmaps-info-windows"]);311 $key = get_option("google_maps_api_key ");303 function include_google_maps_5ae9fcc8cf7e2() { 304 305 $maps = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-maps"]); 306 $markers = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-markers"]); 307 $polylines = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-polylines"]); 308 $polygons = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-polygons"]); 309 $info_windows = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-info-windows"]); 310 $key = get_option("google_maps_api_key_5ae9fcc8cf7e2"); 312 311 313 312 if(!$key) { 314 313 echo "<div class='notice notice-error'>Google Maps Require an api key be set in Settings > General</div>"; 315 314 } 316 317 echo " 318 <script> 319 function gmaps_init() { 315 $script = " 316 function gmaps_init_5ae9fcc8cf7e2() { 320 317 $maps 321 318 $markers … … 323 320 $polygons 324 321 $info_windows 325 } 326 </script> 327 <script src='https://maps.googleapis.com/maps/api/js?key=".$key."&callback=gmaps_init' async defer></script>"; 328 322 }"; 323 wp_enqueue_script('gmaps-includes-5ae9fcc8cf7e2', "https://maps.googleapis.com/maps/api/js?key=".$key."&callback=gmaps_init_5ae9fcc8cf7e2", array(), "1.0", false); 324 wp_add_inline_script("gmaps-includes-5ae9fcc8cf7e2", $script, 'before'); 329 325 // Unset Global variables. 330 unset($GLOBALS[" gmaps-maps"]);331 unset($GLOBALS[" gmaps-markers"]);332 unset($GLOBALS[" gmaps-polylines"]);333 unset($GLOBALS[" gmaps-polygons"]);326 unset($GLOBALS["5ae9fcc8cf7e2-gmaps-maps"]); 327 unset($GLOBALS["5ae9fcc8cf7e2-gmaps-markers"]); 328 unset($GLOBALS["5ae9fcc8cf7e2-gmaps-polylines"]); 329 unset($GLOBALS["5ae9fcc8cf7e2-gmaps-polygons"]); 334 330 } 335 331 … … 337 333 * Ensure global variables exist and are empty 338 334 */ 339 function create_gmaps_global_vars () {340 $GLOBALS[" gmaps-maps"] = [];341 $GLOBALS[" gmaps-markers"] = [];342 $GLOBALS[" gmaps-polylines"] = [];343 $GLOBALS[" gmaps-polygons"] = [];344 $GLOBALS[" gmaps-info-windows"] = [];335 function create_gmaps_global_vars_5ae9fcc8cf7e2() { 336 $GLOBALS["5ae9fcc8cf7e2-gmaps-maps"] = []; 337 $GLOBALS["5ae9fcc8cf7e2-gmaps-markers"] = []; 338 $GLOBALS["5ae9fcc8cf7e2-gmaps-polylines"] = []; 339 $GLOBALS["5ae9fcc8cf7e2-gmaps-polygons"] = []; 340 $GLOBALS["5ae9fcc8cf7e2-gmaps-info-windows"] = []; 345 341 } 346 342 … … 348 344 Callback generate the GoogleMaps Api key input element. 349 345 */ 350 function generate_setting() {351 $value = get_option('google_maps_api_key ');352 echo "<input type='text' name='google_maps_api_key ' id='google_maps_api_key' style='width:25%' value='$value'/>";346 function vstek_generate_gmaps_setting_5ae9fcc8cf7e2() { 347 $value = get_option('google_maps_api_key_5ae9fcc8cf7e2'); 348 echo "<input type='text' name='google_maps_api_key_5ae9fcc8cf7e2' id='google_maps_api_key_5ae9fcc8cf7e2' style='width:25%' value='$value'/>"; 353 349 } 354 350 … … 356 352 Register the GoogleMaps Api key setting to the 'General' settings page. 357 353 */ 358 function register_setting_field() {354 function gmaps_register_setting_field_5ae9fcc8cf7e2() { 359 355 register_setting( 360 356 'general', 361 'google_maps_api_key '357 'google_maps_api_key_5ae9fcc8cf7e2' 362 358 ); 363 359 add_settings_field( 364 360 'html_guidelines_message', 365 361 'Google Maps Api Key', 366 ' generate_setting',362 'vstek_generate_gmaps_setting_5ae9fcc8cf7e2', 367 363 'general' 368 364 ); … … 370 366 371 367 // Add shortcode handlers 372 add_shortcode('gmaps', 'do_gmaps_maps ');373 add_shortcode('gmaps-marker', 'do_gmaps_marker ');374 add_shortcode('gmaps-polyline', 'do_gmaps_polyline ');375 add_shortcode('gmaps-polygon', 'do_gmaps_polygon ');376 add_shortcode('gmaps-info-window', 'do_gmaps_info_window ');368 add_shortcode('gmaps', 'do_gmaps_maps_5ae9fcc8cf7e2'); 369 add_shortcode('gmaps-marker', 'do_gmaps_marker_5ae9fcc8cf7e2'); 370 add_shortcode('gmaps-polyline', 'do_gmaps_polyline_5ae9fcc8cf7e2'); 371 add_shortcode('gmaps-polygon', 'do_gmaps_polygon_5ae9fcc8cf7e2'); 372 add_shortcode('gmaps-info-window', 'do_gmaps_info_window_5ae9fcc8cf7e2'); 377 373 378 374 // Add request actions. 379 add_action('wp_head', 'create_gmaps_global_vars ');380 add_action('wp_footer', 'include_google_maps ');375 add_action('wp_head', 'create_gmaps_global_vars_5ae9fcc8cf7e2'); 376 add_action('wp_footer', 'include_google_maps_5ae9fcc8cf7e2'); 381 377 382 378 // Add custom admin settings field. 383 add_filter('admin_init', ' register_setting_field');379 add_filter('admin_init', 'gmaps_register_setting_field_5ae9fcc8cf7e2'); -
gmaps-google-maps-shortcode/trunk/README.txt
r1868733 r1868734 1 1 # GMaps Google Maps Shortcode 2 Tags: maps, google 3 Contributors: vsteks 4 Requires at least: 4.0.0 5 Tested up to: 4.9.5 6 Requires PHP: 7.1 7 Stable tag: trunk 8 License: GPLv2 9 LICENSE URI: http://gnu.org/license/gpl-2.0.html 2 10 3 11 A simple wordpress plugin to insert Google Maps into posts/pages using the javascript API. Can be used to create markers, lines, and arbitrary shapes. … … 413 421 414 422 ## Multi Marker 415 Create a map showing 423 Create a map showing many markers connected by a Polyline. 424 425 ``` 426 [gmaps lat=13.4125 lng=103.8670] 427 [gmaps-marker lat=13.4125 lng=103.8670] 428 [gmaps-marker lat=13.0 lng=103] 429 [/gmaps] 430 ``` 431 432 # Changelog 433 434 # Frequently Asked Questions 435 436 # Upgrade Notice 437 438 # Screenshots 416 439 417 440 [google-api-key]:https://developers.google.com/maps/documentation/javascript/get-api-key
Note: See TracChangeset
for help on using the changeset viewer.