Google Map Shortcode - Version 1.1

Version Description

Download this release

Release Info

Developer alaingg
Plugin Icon wp plugin Google Map Shortcode
Version 1.1
Comparing to
See all releases

Version 1.1

google-map-sc-style.css ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Google Map Shortcode
3
+ * Version: 1.1
4
+ * Author: Alain Gonzalez
5
+ * Author URI: http://web-argument.com/
6
+ */
7
+
8
+ .gm_info_cont{
9
+ width:250px;
10
+ height:200px;
11
+ padding-right:10px;
12
+ }
13
+
14
+ .gm_info_title{
15
+ margin:0;
16
+ font-weight:bold;
17
+ }
18
+
19
+ .gm_info_address{
20
+ font-size:10px;
21
+ text-align:left;
22
+ font-weight:bold;
23
+ }
24
+
25
+ .gm_info_img{
26
+ width:100px;
27
+ padding-right:15px
28
+ }
google-map-sc.js ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Google Map Shortcode
3
+ * Version: 1.1
4
+ * Author: Alain Gonzalez
5
+ * Author URI: http://web-argument.com/
6
+ */
7
+
8
+ function gmshc_render(id,GMpointsArray,zoom) {
9
+
10
+ var map = new GMap2(document.getElementById(id));
11
+
12
+
13
+ var customUI = map.getDefaultUI();
14
+
15
+ // Remove MapType.G_HYBRID_MAP
16
+ customUI.maptypes.hybrid = false;
17
+
18
+ map.setUI(customUI);
19
+
20
+
21
+ this.findPoint = findPoint;
22
+ this.placing = placing;
23
+
24
+
25
+
26
+ for (var i = 0; i <= GMpointsArray.length - 1; i++){
27
+
28
+ this.placing(GMpointsArray[i]);
29
+
30
+ }
31
+
32
+ function placing (single, showinfo){
33
+
34
+ var latlng = new GLatLng(single.point.lat,single.point.long);
35
+ map.setCenter(latlng, zoom);
36
+ var marker = new GMarker(latlng);
37
+ map.addOverlay(marker);
38
+
39
+ if(showinfo){
40
+
41
+ map.openInfoWindowHtml(latlng, single.info);
42
+
43
+ }
44
+ if (single.info != null){
45
+ GEvent.addListener(marker, "click", function() {
46
+
47
+ map.openInfoWindowHtml(latlng, single.info);
48
+
49
+ });
50
+ }
51
+
52
+ }
53
+
54
+
55
+ function findPoint(which) {
56
+
57
+ this.placing(GMpointsArray[which], true);
58
+
59
+ }
60
+
61
+ }
62
+
63
+ function addLoadEvent(func) {
64
+ var oldonload = window.onload;
65
+ if (typeof window.onload != 'function') {
66
+ window.onload = func;
67
+ }
68
+ else {
69
+ window.onload = function() {
70
+ oldonload();
71
+ func();
72
+ }
73
+ }
74
+ }
75
+
76
+
77
+ function addEvent(elm, evType, fn, useCapture) {
78
+ if (elm.addEventListener) {
79
+ elm.addEventListener(evType, fn, useCapture);
80
+ return true;
81
+ }
82
+ else if (elm.attachEvent) {
83
+ var r = elm.attachEvent('on' + evType, fn);
84
+ return r;
85
+ }
86
+ else {
87
+ elm['on' + evType] = fn;
88
+ }
89
+ }
google-map-shortcode.php ADDED
@@ -0,0 +1,780 @@
1
+ <?php
2
+ /*
3
+ Plugin Name: Google Map Shortcode
4
+ Plugin URI: http://web-argument.com/google-map-shortcode-version-11/
5
+ Description: Include Google Map in your blog displaying your post address using differents parameters.
6
+ Version: 1.1
7
+ Author: Alain Gonzalez
8
+ Author URI: http://web-argument.com/
9
+ */
10
+
11
+
12
+ // to find latitud longitud http://www.batchgeocode.com/lookup/
13
+
14
+
15
+ /**
16
+ * Inserting files on the header
17
+ */
18
+ function gmshc_head() {
19
+
20
+ $options = get_option('gmshc_op');
21
+ $gmshc_key = $options['gmshc_key'];
22
+
23
+ $wpchkt_header = "\n<!-- Google Map Shortcode -->\n";
24
+ $wpchkt_header .= "<script src=\"http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=".$gmshc_key."\" type=\"text/javascript\"></script>\n";
25
+ $wpchkt_header .= "<script type=\"text/javascript\" src=\"".get_bloginfo('url')."/wp-content/plugins/google-map-shortcode/google-map-sc.js\"></script>\n";
26
+ $wpchkt_header .= "<link href=\"".get_bloginfo('url')."/wp-content/plugins/google-map-shortcode/google-map-sc-style.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
27
+ $wpchkt_header .= "\n<!-- Google Map Shortcode-->\n";
28
+
29
+ print($wpchkt_header);
30
+
31
+ }
32
+
33
+ add_action('wp_head', 'gmshc_head');
34
+
35
+
36
+ /**
37
+ * Default Open Window Html
38
+ */
39
+
40
+ $defaul_gmshc_windowhtml = "<div class='gm_info_cont'>\n";
41
+ $defaul_gmshc_windowhtml .= "<p class='gm_info_title'><a class='title' href='%link%'>%title%</a></p>\n";
42
+ $defaul_gmshc_windowhtml .= "<p class='gm_info_address'>%address%</p>\n";
43
+ $defaul_gmshc_windowhtml .= "<table border='0' cellspacing='0' cellpadding='5' height='80'>\n";
44
+ $defaul_gmshc_windowhtml .= "<tr>\n";
45
+ $defaul_gmshc_windowhtml .= "<td valign='top' align='left'><a href='%link%'><img src='%thubnail%' class='gm_info_img' /></a></td>\n";
46
+ $defaul_gmshc_windowhtml .= "<td valign='top' align='left'>\n";
47
+ $defaul_gmshc_windowhtml .= "%excerpt%\n";
48
+ $defaul_gmshc_windowhtml .= "<p><a href='%link%'>more &raquo;</a></p>\n";
49
+ $defaul_gmshc_windowhtml .= "</td>\n";
50
+ $defaul_gmshc_windowhtml .= "</tr>\n";
51
+ $defaul_gmshc_windowhtml .= "</table>\n";
52
+ $defaul_gmshc_windowhtml .= "</div>\n";
53
+
54
+ /**
55
+ * The Sortcode
56
+ */
57
+
58
+ add_shortcode('google-map-sc', 'gmshc_sc');
59
+
60
+ function gmshc_sc($atts) {
61
+
62
+ global $post;
63
+
64
+ $address_meta = get_post_meta(get_the_ID(), 'google-map-sc-address');
65
+ $point_meta = get_post_meta(get_the_ID(), 'google-map-sc-latlng');
66
+
67
+ $the_address = $address_meta[0];
68
+ $point = $point_meta[0];
69
+ $the_item = '';
70
+
71
+ extract(shortcode_atts(array(
72
+ 'address' => '',
73
+ 'id' => '',
74
+ 'cat' => '',
75
+ 'number' => '',
76
+ 'zoom' => '10',
77
+ 'width' => '400',
78
+ 'height' => '400',
79
+ 'external_links' => false
80
+ ), $atts));
81
+
82
+
83
+ if (!empty($address)) {
84
+
85
+ $the_item = gmshc_fill_items('',$address, '');
86
+ if (!empty($the_item)) $gm_item[0] = $the_item;
87
+
88
+
89
+ }
90
+
91
+ else if (
92
+
93
+ (
94
+
95
+ (!empty($id)) || (!empty($point)) || (!empty($the_address))
96
+
97
+ )
98
+
99
+ & (empty($cat))
100
+ & (empty($number))
101
+ & (!($external_links))
102
+
103
+ )
104
+
105
+ {
106
+
107
+ if (empty($id)) $id = $post->ID;
108
+
109
+ $gm_item = gmshc_items($id,'', '');
110
+
111
+ }
112
+
113
+ else {
114
+
115
+
116
+ $gm_item = gmshc_items('',$number, $cat);
117
+
118
+
119
+ }
120
+
121
+ $canvas = "canvas_".wp_generate_password(4, false);
122
+
123
+
124
+ $i = 0;
125
+
126
+
127
+ if (!empty($gm_item )){
128
+
129
+ $output ='<div id="'.$canvas.'" style="width:'.$width.'px; height:'.$height.'px" class="google-map-sc-canvas"></div>';
130
+ $output .= "<script type=\"text/javascript\">\n";
131
+
132
+ $output .= "var map_".$canvas.";\n";
133
+ $output .= "var map_points_".$canvas." = new Array();\n";
134
+
135
+ foreach ($gm_item as $item){
136
+
137
+ global $defaul_gmshc_windowhtml;
138
+
139
+ $options = get_option('gmshc_op');
140
+ $gmshc_windowhtml = $options['gmshc_windowhtml'];
141
+
142
+ if (empty($gmshc_windowhtml)) $gmshc_windowhtml = $defaul_gmshc_windowhtml;
143
+
144
+ $find = array("\r","\n","\\","\"","%title%","%link%","%thubnail%", "%excerpt%","%address%");
145
+ $replace = array("","","","'",$item['title'],$item['link'],$item['img'],$item['excerpt'],$item['address']);
146
+
147
+ $info = str_replace( $find,$replace, $gmshc_windowhtml);
148
+
149
+
150
+ list($lat, $long) = split(",",$item['point']);
151
+
152
+
153
+ if ( (empty($item['title'])) & (empty($item['link'])) & (empty($item['img'])) & (empty($item['excerpt'])) & (empty($item['address'])) )
154
+
155
+ $output .= "map_points_".$canvas."[".$i."] = {'point':{'lat':\"".$lat."\",'long':\"".$long."\"}};\n";
156
+
157
+ else
158
+
159
+ $output .= "map_points_".$canvas."[".$i."] = {'point':{'lat':\"".$lat."\",'long':\"".$long."\"},'info':\"".$info."\"};\n";
160
+
161
+ if ($external_links){
162
+
163
+ $external_links_items .= "<li><a href='#' onclick='map_".$canvas.".findPoint(".$i."); return false'>".$item['title']."</a></li>";
164
+ }
165
+
166
+ $i ++;
167
+ }
168
+
169
+ $output .= "addLoadEvent(function(){\n";
170
+ $output .= "map_".$canvas." = new gmshc_render(\"".$canvas."\",map_points_".$canvas.", ".$zoom.");\n";
171
+ $output .= "});\n";
172
+ $output .= "addEvent(window,'unload',GUnload,false);\n";
173
+ $output .= "</script>\n";
174
+
175
+ if ($external_links){
176
+
177
+ $output .= "<div class='map_links'>";
178
+ $output .= "<ul>";
179
+ $output .= $external_links_items;
180
+ $output .= "</ul>";
181
+ $output .= "</div";
182
+
183
+ }
184
+
185
+ }
186
+
187
+
188
+
189
+ return $output;
190
+
191
+ }
192
+
193
+
194
+ function gmshc_get_excerpt($text) { // Fakes an excerpt if needed
195
+ if ( '' != $text ) {
196
+
197
+ $text = strip_shortcodes( $text );
198
+
199
+ $text = apply_filters('the_content', $text);
200
+ $text = str_replace(']]>', ']]&gt;', $text);
201
+ $text = strip_tags($text);
202
+ $excerpt_length = 10;
203
+ $words = explode(' ', $text, $excerpt_length + 1);
204
+ if (count($words) > $excerpt_length) {
205
+ array_pop($words);
206
+ array_push($words, '[...]');
207
+ $text = implode(' ', $words);
208
+ }
209
+ }
210
+ return $text;
211
+ }
212
+
213
+
214
+
215
+ /**
216
+ * Get the items
217
+ */
218
+
219
+
220
+ function gmshc_items($id,$number, $categories){
221
+
222
+ $i = 0;
223
+ $the_item = '';
224
+
225
+ //to avoid exceed the google request limit
226
+ if (empty($number)) $number = 100;
227
+
228
+ if (!empty($id)) {
229
+ $my_query = get_posts(array('include'=>$id));
230
+ $number = 1;
231
+ }
232
+
233
+
234
+
235
+ else if (empty($categories)){
236
+
237
+ $my_query = get_posts(array('numberposts'=>-1));
238
+ }
239
+
240
+ else {
241
+
242
+ $cat = split (",",$categories);
243
+
244
+ $my_query = get_posts(array('category__in'=>$cat,'numberposts'=>-1));
245
+
246
+ }
247
+
248
+ foreach ($my_query as $post) {
249
+
250
+ if ($i == $number) break;
251
+
252
+ $address_meta = get_post_meta($post -> ID, 'google-map-sc-address');
253
+ $point_meta = get_post_meta($post -> ID, 'google-map-sc-latlng');
254
+
255
+
256
+ if ($number > 1){
257
+
258
+ $address = $address_meta[0];
259
+ $point = $point_meta[0];
260
+
261
+ $the_item = gmshc_fill_items($post,$address,$point);
262
+
263
+ if (!empty($the_item)) {
264
+ $item[$i] = $the_item;
265
+ $i ++;
266
+ }
267
+
268
+
269
+ } else {
270
+
271
+ if (count($address_meta) > 1) {
272
+
273
+ $j = 0;
274
+
275
+ foreach ($address_meta as $address) {
276
+
277
+ $the_item = gmshc_fill_items('',$address,'');
278
+
279
+ if (!empty($the_item)) {
280
+ $item[$j] = $the_item;
281
+ $j ++;
282
+ }
283
+ }
284
+ $i ++;
285
+
286
+
287
+ } else if (count($point_meta) > 1) {
288
+
289
+ $j = 0;
290
+
291
+ foreach ($point_meta as $point) {
292
+
293
+ $the_item = gmshc_fill_items('','',$point);
294
+
295
+ if (!empty($the_item)) {
296
+ $item[$j] = $the_item;
297
+ $j ++;
298
+ }
299
+
300
+ }
301
+ $i ++;
302
+
303
+
304
+ } else {
305
+
306
+ $address = $address_meta[0];
307
+ $point = $point_meta[0];
308
+
309
+ $the_item = gmshc_fill_items($post,$address,$point);
310
+ if (!empty($the_item)) {
311
+ $item[0] = $the_item;
312
+ }
313
+
314
+ }
315
+
316
+ }
317
+
318
+
319
+ }
320
+
321
+ return $item;
322
+
323
+ }
324
+
325
+
326
+
327
+ function gmshc_fill_items($post,$address, $point){
328
+
329
+ if ((empty($point)) & (!empty($address))){
330
+
331
+ $response = gmshc_point($address);
332
+
333
+ $point = $response['point'];
334
+ $address = $response['address'];
335
+
336
+ if (!empty($point)) {
337
+ if (!empty($post)){
338
+ update_post_meta($post -> ID, 'google-map-sc-latlng', $point);
339
+ update_post_meta($post -> ID, 'google-map-sc-address', $address);
340
+ }
341
+ }
342
+
343
+ }
344
+
345
+ if (!empty($point)) {
346
+
347
+ if (!empty($post)){
348
+ $the_image = gmshc_post_thumb($post -> ID);
349
+ $the_title = $post -> post_title;
350
+ $the_link = $post -> guid;
351
+
352
+ $find = array("\"", "[", "]", "\n","\r");
353
+ $replace = array("'","","","","");
354
+
355
+
356
+ $the_excerpt = str_replace( $find,$replace, gmshc_get_excerpt($post -> post_content));
357
+
358
+ $item = array("point"=>$point,"img" => $the_image,"title" => $the_title,"link" => $the_link, "excerpt" => $the_excerpt, "address" => $address);
359
+
360
+
361
+ } else {
362
+
363
+ $item = array("point"=>$point);
364
+
365
+ }
366
+
367
+ return $item;
368
+
369
+ }
370
+
371
+ }
372
+
373
+
374
+
375
+ /**
376
+ * Get the thumbnail
377
+ */
378
+ function gmshc_post_thumb($the_parent){
379
+
380
+ $attachments = get_children( array(
381
+ 'post_parent' => $the_parent,
382
+ 'post_type' => 'attachment',
383
+ 'post_mime_type' => 'image',
384
+ 'order' => 'DESC',
385
+ 'numberposts' => 1) );
386
+
387
+ if($attachments == true) :
388
+ foreach($attachments as $id => $attachment) :
389
+ $img = wp_get_attachment_image_src($id, 'thumbnail');
390
+ endforeach;
391
+ endif;
392
+
393
+ return $img[0];
394
+
395
+ }
396
+
397
+
398
+ /**
399
+ * Settings
400
+ */
401
+
402
+ add_action('admin_menu', 'gmshc_set');
403
+
404
+ function gmshc_set() {
405
+ add_options_page('Google Map Shortcode', 'Google Map Shortcode', 10, 'google-map-shortcode', 'gmshc_options_page');
406
+ }
407
+
408
+ function gmshc_options_page() {
409
+
410
+ global $defaul_gmshc_windowhtml;
411
+
412
+ $options = get_option('gmshc_op');
413
+
414
+
415
+ if(isset($_POST['Submit'])){
416
+
417
+ ?>
418
+ <script type="text/javascript">
419
+ var KillAlerts = true;
420
+ var realAlert = alert;
421
+ var alert = new Function('a', 'if(!KillAlerts){realAlert(a)}');
422
+ </script>
423
+
424
+ <script src="http://maps.google.com/maps?file=api&v=2.105&key=<?php echo $_POST['gmshc_key'] ?>" type="text/javascript"></script>
425
+
426
+
427
+ <script type="text/javascript">
428
+ KillAlerts = false;
429
+
430
+ if (GBrowserIsCompatible()) {
431
+ document.write("<div class='updated'><p><strong><?php _e('Options saved.', 'mt_trans_domain' ); ?></strong></p></div>");
432
+
433
+ <?php
434
+ $newoptions['gmshc_key'] = $_POST['gmshc_key'];
435
+ $newoptions['gmshc_windowhtml'] = $_POST['gmshc_windowhtml'];
436
+
437
+ if ( $options != $newoptions ) {
438
+ $options = $newoptions;
439
+ update_option('gmshc_op', $options);
440
+ }
441
+
442
+ //Adding Meta Key
443
+ $meta_key = get_post_meta(1, 'google-map-sc-address');
444
+ $meta_key2 = get_post_meta(1, 'google-map-sc-latlng');
445
+
446
+ if(empty($meta_key) || (empty($meta_key2))) {
447
+
448
+ add_post_meta(1, 'google-map-sc-address', '');
449
+ add_post_meta(1, 'google-map-sc-latlng', '');
450
+
451
+ }
452
+ ?>
453
+
454
+ } else {
455
+ if (G_INCOMPAT) {
456
+ document.write("<div class='error'><p><strong><?php _e('Error: Bad Google API Key.', 'mt_trans_domain' ); ?></strong></p></div>");
457
+ <?php
458
+ $newoptions['gmshc_key'] = "";
459
+ ?>
460
+ } else {
461
+ alert("Incompatible browser");
462
+ }
463
+ }
464
+ </script>
465
+
466
+ <?php
467
+
468
+
469
+ }
470
+
471
+ if(isset($_POST['Use_Default'])){
472
+
473
+
474
+
475
+ $newoptions['gmshc_key'] = $_POST['gmshc_key'];
476
+ $newoptions['gmshc_windowhtml'] = $defaul_gmshc_windowhtml;
477
+
478
+
479
+ if ( $options != $newoptions ) {
480
+ $options = $newoptions;
481
+ update_option('gmshc_op', $options);
482
+ }
483
+
484
+
485
+ }
486
+
487
+ $gmshc_key = $options['gmshc_key'];
488
+ $gmshc_windowhtml = $options['gmshc_windowhtml'];
489
+ ?>
490
+
491
+
492
+ <div class="wrap">
493
+
494
+ <form method="post" name="options" target="_self">
495
+
496
+ <h2>Google Map Shortcode Settings</h2>
497
+
498
+ <h3>Enter your Google Map Api Key. You can get it <a href="http://code.google.com/apis/maps/signup.html" target="_blank">here</a></h3>
499
+
500
+ <p><input name="gmshc_key" type="text" value="<?php echo $gmshc_key ?>" size="105"/>
501
+
502
+ <p class="submit">
503
+ <input type="submit" name="Submit" value="Update" class="button-primary" />
504
+ </p>
505
+
506
+ <h3 style="padding-top:30px; margin-top:30px; border-top:1px solid #CCCCCC;">Open Window Html</h3>
507
+
508
+ <p>This is the html inside of the Map Info Window opened after clicking on the markers, you can include the following tags.</p>
509
+
510
+ <table width="80%%" border="0" cellspacing="10" cellpadding="0">
511
+ <tr>
512
+ <td width="150" align="right"><strong>%title%</strong></td>
513
+ <td>The title of your post</td>
514
+ </tr>
515
+ <tr>
516
+ <td align="right"><strong>%link%</strong></td>
517
+ <td>The link to your post</td>
518
+ </tr>
519
+ <tr>
520
+ <td align="right"><strong>%thubnail%</strong></td>
521
+ <td>The thubnail of the last image attached to your post</td>
522
+ </tr>
523
+ <tr>
524
+ <td align="right"><strong>%excerpt%</strong></td>
525
+ <td>The excerpt of your post</td>
526
+ </tr>
527
+ <tr>
528
+ <td align="right"><strong>%address%</strong></td>
529
+ <td>The address of this point in the map</td>
530
+ </tr>
531
+ </table>
532
+ <br />
533
+
534
+
535
+ <textarea name="gmshc_windowhtml" cols="110" rows="12" id="gmshc_windowhtml">
536
+ <?php
537
+ if (empty($gmshc_windowhtml)) echo $defaul_gmshc_windowhtml;
538
+ else echo str_replace("\\", "",$gmshc_windowhtml);
539
+
540
+ ?>
541
+ </textarea>
542
+
543
+ <p align="right" style="width:800px; padding:0">
544
+ <input type="submit" name="Use_Default" value="Restore Default"/>
545
+ </p>
546
+
547
+ <p class="submit">
548
+ <input type="submit" name="Submit" value="Update" class="button-primary" />
549
+ </p>
550
+
551
+ <h3 style="padding-top:30px; margin-top:30px; border-top:1px solid #CCCCCC;">Use</h3>
552
+ <p>You can include a Google Map Shortcode everywhere</p>
553
+
554
+ <p>In your post using: <strong>[google-map-sc option = "option value"]</strong></p>
555
+ <p>In your theme files using: <strong> < ?php echo do_shortcode [google-map-sc option = "option value"] ? ></strong></p>
556
+
557
+ <h3 style="padding-top:30px; margin-top:30px; border-top:1px solid #CCCCCC;">Options</h3>
558
+
559
+ <table width="80%%" border="0" cellspacing="10" cellpadding="0">
560
+ <tr>
561
+ <td width="150"><div align="right"><strong>address</strong></div></td>
562
+ <td>Specific address</td>
563
+ </tr>
564
+ <tr>
565
+ <td><div align="right"><strong>id</strong></div></td>
566
+ <td>Specific post ID</td>
567
+ </tr>
568
+ <tr>
569
+ <td><div align="right"><strong>cat</strong></div></td>
570
+ <td>Include post under this categories. (category number separated by comma)</td>
571
+ </tr>
572
+ <tr>
573
+ <td><div align="right"><strong>number</strong></div></td>
574
+ <td>Number of points/post on your map (Default 10)</td>
575
+ </tr>
576
+ <tr>
577
+ <td><div align="right"><strong>zoom</strong></div></td>
578
+ <td>Inicial zoom (Default 10)</td>
579
+ </tr>
580
+ <tr>
581
+ <td><div align="right"><strong>width</strong></div></td>
582
+ <td>Width of your map</td>
583
+ </tr>
584
+ <tr>
585
+ <td><div align="right"><strong>height</strong></div></td>
586
+ <td>Height of your map</td>
587
+ </tr>
588
+ <tr>
589
+ <td><div align="right"><strong>external_links</strong></div></td>
590
+ <td>Include the links to the map points outside of the map</td>
591
+ </tr>
592
+
593
+ </table>
594
+
595
+
596
+ <h3 style="padding-top:30px; margin-top:30px; border-top:1px solid #CCCCCC;">Feedback</h3>
597
+
598
+ <p>For more details and examples visite the <a href="http://web-argument.com/google-map-shortcode/">Plugin Page</a>. All the comments are welcome.</p>
599
+
600
+
601
+ <p class="submit">
602
+ <input type="submit" name="Submit" value="Update" class="button-primary" />
603
+ </p>
604
+ </form>
605
+ </div>
606
+
607
+ <?php }
608
+
609
+
610
+ function gmshc_point ($address){
611
+
612
+
613
+ $find = array("\n","\r"," ");
614
+ $replace = array("","","+");
615
+
616
+ $address = str_replace( $find,$replace, $address);
617
+
618
+ $url = 'http://maps.google.com/maps/geo?q='.$address.'&key='.$gmshc_key.'&sensor=false&output=xml&oe=utf8';
619
+
620
+
621
+ $response = gmshc_xml2array($url);
622
+
623
+ $coordinates = $response['kml']['Response']['Placemark']['Point']['coordinates'];
624
+ $address = $response['kml']['Response']['Placemark']['address'];
625
+
626
+ if (!empty($coordinates)) {
627
+
628
+ $point_array = split(",",$coordinates);
629
+
630
+ $point = $point_array[1].",".$point_array[0];
631
+
632
+ $response = array('point'=>$point,'address'=>$address);
633
+
634
+ return $response;
635
+
636
+ }
637
+
638
+ }
639
+
640
+ //from http://us3.php.net/manual/en/function.xml-parse.php
641
+ function gmshc_xml2array($url, $get_attributes = 1, $priority = 'tag')
642
+ {
643
+ $contents = "";
644
+ if (!function_exists('xml_parser_create'))
645
+ {
646
+ return array ();
647
+ }
648
+ $parser = xml_parser_create('');
649
+ if (!($fp = @ fopen($url, 'rb')))
650
+ {
651
+ return array ();
652
+ }
653
+ while (!feof($fp))
654
+ {
655
+ $contents .= fread($fp, 8192);
656
+ }
657
+ fclose($fp);
658
+ xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
659
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
660
+ xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
661
+ xml_parse_into_struct($parser, trim($contents), $xml_values);
662
+ xml_parser_free($parser);
663
+ if (!$xml_values)
664
+ return; //Hmm...
665
+ $xml_array = array ();
666
+ $parents = array ();
667
+ $opened_tags = array ();
668
+ $arr = array ();
669
+ $current = & $xml_array;
670
+ $repeated_tag_index = array ();
671
+ foreach ($xml_values as $data)
672
+ {
673
+ unset ($attributes, $value);
674
+ extract($data);
675
+ $result = array ();
676
+ $attributes_data = array ();
677
+ if (isset ($value))
678
+ {
679
+ if ($priority == 'tag')
680
+ $result = $value;
681
+ else
682
+ $result['value'] = $value;
683
+ }
684
+ if (isset ($attributes) and $get_attributes)
685
+ {
686
+ foreach ($attributes as $attr => $val)
687
+ {
688
+ if ($priority == 'tag')
689
+ $attributes_data[$attr] = $val;
690
+ else
691
+ $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
692
+ }
693
+ }
694
+ if ($type == "open")
695
+ {
696
+ $parent[$level -1] = & $current;
697
+ if (!is_array($current) or (!in_array($tag, array_keys($current))))
698
+ {
699
+ $current[$tag] = $result;
700
+ if ($attributes_data)
701
+ $current[$tag . '_attr'] = $attributes_data;
702
+ $repeated_tag_index[$tag . '_' . $level] = 1;
703
+ $current = & $current[$tag];
704
+ }
705
+ else
706
+ {
707
+ if (isset ($current[$tag][0]))
708
+ {
709
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
710
+ $repeated_tag_index[$tag . '_' . $level]++;
711
+ }
712
+ else
713
+ {
714
+ $current[$tag] = array (
715
+ $current[$tag],
716
+ $result
717
+ );
718
+ $repeated_tag_index[$tag . '_' . $level] = 2;
719
+ if (isset ($current[$tag . '_attr']))
720
+ {
721
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
722
+ unset ($current[$tag . '_attr']);
723
+ }
724
+ }
725
+ $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
726
+ $current = & $current[$tag][$last_item_index];
727
+ }
728
+ }
729
+ elseif ($type == "complete")
730
+ {
731
+ if (!isset ($current[$tag]))
732
+ {
733
+ $current[$tag] = $result;
734
+ $repeated_tag_index[$tag . '_' . $level] = 1;
735
+ if ($priority == 'tag' and $attributes_data)
736
+ $current[$tag . '_attr'] = $attributes_data;
737
+ }
738
+ else
739
+ {
740
+ if (isset ($current[$tag][0]) and is_array($current[$tag]))
741
+ {
742
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
743
+ if ($priority == 'tag' and $get_attributes and $attributes_data)
744
+ {
745
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
746
+ }
747
+ $repeated_tag_index[$tag . '_' . $level]++;
748
+ }
749
+ else
750
+ {
751
+ $current[$tag] = array (
752
+ $current[$tag],
753
+ $result
754
+ );
755
+ $repeated_tag_index[$tag . '_' . $level] = 1;
756
+ if ($priority == 'tag' and $get_attributes)
757
+ {
758
+ if (isset ($current[$tag . '_attr']))
759
+ {
760
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
761
+ unset ($current[$tag . '_attr']);
762
+ }
763
+ if ($attributes_data)
764
+ {
765
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
766
+ }
767
+ }
768
+ $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
769
+ }
770
+ }
771
+ }
772
+ elseif ($type == 'close')
773
+ {
774
+ $current = & $parent[$level -1];
775
+ }
776
+ }
777
+ return ($xml_array);
778
+ }
779
+
780
+ ?>
readme.txt ADDED
@@ -0,0 +1,52 @@
1
+ === Google Map Shortcode ===
2
+ Contributors: Alaingg
3
+ Donate link: http://web-argument.com/google-map-shortcode-version-11/
4
+ Tags: google map, shortcode, map, categories, widget, post map, point, marker, list, location
5
+ Requires at least: 2.5
6
+ Tested up to: 2.8
7
+ Stable tag: 1.1
8
+
9
+ Friendly integration of Google Map instances in your blogs. Allows to display multiples map on your pages. Insert points on maps using a custon field.
10
+
11
+ == Description ==
12
+
13
+ This plugin allows you to include instances of Google Map in your blogs using the shortcode API. You can insert maps everywhere: in your theme files, posts and pages. The use of a custom field allows you to insert posts/pages on your maps as points.
14
+
15
+ Special Features:
16
+
17
+ * Allows to include more than one google map instance on your pages.
18
+ * You can use the shortcode on your post, pages and theme files.
19
+ * When you click on a point in the map the window box opened shows part of the content of your posts (post title, thumbnails, excerpt)
20
+ * You can customize the html of the info window box on your maps
21
+ * One custom field defines the address of a post
22
+ * The shortcode allows different options to customize your maps like: inicial zoom, width, height, under categories, show external links, post ID, number of points, specific address
23
+
24
+ For more details and examples visit the <a href="http://web-argument.com/google-map-shortcode-version-11/">plugin page</a>.
25
+
26
+ == Installation ==
27
+
28
+ 1. Upload 'Google Map Short Code' folder to the '/wp-content/plugins/' directory.
29
+ 2. Activate the plugin through the �Plugins� menu in WordPress.
30
+ 3. Go to the Google Map Shortcode Options page under settings and Insert your Google Api Key.
31
+
32
+
33
+ == Screenshots ==
34
+
35
+ 1. Google Map Shortcode
36
+ 2. Settings
37
+ 3. Custom Field
38
+ 4. Shortcode example
39
+ 5. Custom Html por window box
40
+
41
+
42
+ == Changelog ==
43
+
44
+ = 1.0.0 =
45
+ * Inicial release.
46
+
47
+ = 1.1 =
48
+ * Loops related bugs fixed.
49
+ * More than 10 points allows per page fixed.
50
+ * New custom field included in order to cache the Latitude and Longitude and avoid extra Google Geocoder requests.
51
+ * More than one point per post fixed.
52
+
screenshot-1.jpg ADDED
Binary file
screenshot-2.jpg ADDED
Binary file
screenshot-3.jpg ADDED
Binary file
screenshot-4.jpg ADDED
Binary file
screenshot-5.jpg ADDED
Binary file