| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
/**
|
| 4 |
*@file
|
| 5 |
* Allows users to insert kml files into nodes displayed on top of a google map
|
| 6 |
*
|
| 7 |
* Uses a filter to embed a google map overlayed with a kml file using square brackets
|
| 8 |
* like [mykml:http://mapgadgets.googlepages.com/cta.kml (41.88414, -87.63238), 10] or in general [mykml:path-to-kml (lat,lon), zoom]
|
| 9 |
*/
|
| 10 |
|
| 11 |
function mykml_filter_menu($may_cache) {
|
| 12 |
$items = array();
|
| 13 |
if (arg(0)=='admin'){
|
| 14 |
}
|
| 15 |
else {
|
| 16 |
drupal_add_js(drupal_get_path('module', 'mykml_filter') . '/jquery.jmaps.js');
|
| 17 |
drupal_set_html_head('<script src="http://maps.google.com/maps?file=api&v=2&key='.variable_get("mykml_gmaps_key",'ABQIAAAAnfs7bKE82qgb3Zc2YyS-oBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSySz_REpPq-4WZA27OwgbtyR3VcA').'"type="text/javascript"></script>');
|
| 18 |
drupal_set_html_head('<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key='.variable_get("mykml_gmaps_key",'ABQIAAAAnfs7bKE82qgb3Zc2YyS-oBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSySz_REpPq-4WZA27OwgbtyR3VcA').'"type="text/javascript"></script>');
|
| 19 |
}
|
| 20 |
|
| 21 |
if ($may_cache) {
|
| 22 |
$items[] = array(
|
| 23 |
'path' => 'admin/settings/mykml',
|
| 24 |
'title' => t('MyKML Filter'),
|
| 25 |
'description' => t('Allow users to insert their kml files into nodes on top of a google map.'),
|
| 26 |
'callback' => 'drupal_get_form',
|
| 27 |
'callback arguments' => array('mykml_filter_admin_settings'),
|
| 28 |
'access' => user_access('administer site configuration'),
|
| 29 |
);
|
| 30 |
}
|
| 31 |
|
| 32 |
return $items;
|
| 33 |
}
|
| 34 |
|
| 35 |
|
| 36 |
function mykml_filter_admin_settings() {
|
| 37 |
global $base_url;
|
| 38 |
$form = array();
|
| 39 |
|
| 40 |
$form['mykml_gmaps_key'] = array(
|
| 41 |
'#type' => 'textfield',
|
| 42 |
'#title' => t('Gmaps key'),
|
| 43 |
'#default_value' => variable_get("mykml_gmaps_key", 'ABQIAAAAnfs7bKE82qgb3Zc2YyS-oBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSySz_REpPq-4WZA27OwgbtyR3VcA'),
|
| 44 |
'#size' => 64,
|
| 45 |
'#maxlength' => 255,
|
| 46 |
'#description' => t('You need an api key to display Google Maps on your website, visit Google <a href="http://www.google.com/apis/maps/signup.html"> and register for one</a>. (The
|
| 47 |
default key provided only works for localhost)'),
|
| 48 |
);
|
| 49 |
$form['mykml_gmaps_width'] = array(
|
| 50 |
'#type' => 'textfield',
|
| 51 |
'#title' => t('Width'),
|
| 52 |
'#default_value' => variable_get("mykml_gmaps_width", '550'),
|
| 53 |
'#size' => 32,
|
| 54 |
'#maxlength' => 255,
|
| 55 |
'#description' => t('Width of google maps displayed (px)'),
|
| 56 |
);
|
| 57 |
$form['mykml_gmaps_height'] = array(
|
| 58 |
'#type' => 'textfield',
|
| 59 |
'#title' => t('Height'),
|
| 60 |
'#default_value' => variable_get("mykml_gmaps_height", '400'),
|
| 61 |
'#size' => 32,
|
| 62 |
'#maxlength' => 255,
|
| 63 |
'#description' => t('Height of google maps displayed (px)'),
|
| 64 |
);
|
| 65 |
return system_settings_form($form);
|
| 66 |
}
|
| 67 |
|
| 68 |
function mykml_filter_help($section) {
|
| 69 |
if ($section == "admin/modules#description") {
|
| 70 |
return t("Allow users to insert kml files into nodes displayed on top of a google map.");
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
function mykml_filter_long_tip_translated() {
|
| 75 |
return t('<p>Use a filter to embed a google map overlayed with your kml file using square brackets
|
| 76 |
with the following syntax [mykml:http://mapgadgets.googlepages.com/cta.kml (41.88414, -87.63238), 10] or generally [mykml:path-to-kml (lat,lon), zoom]
|
| 77 |
. This also allows you to embed your custom mymaps into your posts, by using the kml link provided on maps.google.com.</p>');
|
| 78 |
}
|
| 79 |
|
| 80 |
|
| 81 |
function mykml_filter_filter_tips($delta, $format, $long = false) {
|
| 82 |
if ($long) {
|
| 83 |
return mykml_filter_long_tip_translated();
|
| 84 |
}
|
| 85 |
else {
|
| 86 |
return t("<p>You may embed a google map overlayed with a kml file by inserting square brackets
|
| 87 |
with the following syntax [mykml:http://www.example.com/cta.kml (41.88414, -87.63238), 10] or generally [mykml:path-to-kml (lat,lon), zoom]. The square brackets will be replaced by the map after submitting your post.</p>");
|
| 88 |
}
|
| 89 |
}
|
| 90 |
|
| 91 |
/**
|
| 92 |
* Hook which handles filtering.
|
| 93 |
*/
|
| 94 |
function mykml_filter_filter($op, $delta = 0, $format = -1, $text = '') {
|
| 95 |
switch ($op) {
|
| 96 |
case 'list':
|
| 97 |
return array(0 => t('MyKML filter'));
|
| 98 |
case 'description':
|
| 99 |
return t('Allow users to insert kml files into nodes displayed on top of a google map.');
|
| 100 |
case 'no cache':
|
| 101 |
return true;
|
| 102 |
case 'settings':
|
| 103 |
global $base_url;
|
| 104 |
|
| 105 |
$form = array();
|
| 106 |
return $form;
|
| 107 |
// don't need "prepare", but need to return text as-is
|
| 108 |
case 'prepare':
|
| 109 |
return $text;
|
| 110 |
// Substitute "[l:URL text]
|
| 111 |
case 'process':
|
| 112 |
return mykml_filter_process($text);
|
| 113 |
default:
|
| 114 |
return $text;
|
| 115 |
}
|
| 116 |
}
|
| 117 |
|
| 118 |
// scan through all of $text, replacing all occurrences of [l:...] tags
|
| 119 |
function mykml_filter_process($string) {
|
| 120 |
|
| 121 |
$replaced = preg_replace_callback("/\[mykml:([^]\s]*)\s*([^]]*)?\]/",
|
| 122 |
create_function('$match',
|
| 123 |
'return(_mykml_filter_tag($match[0], $match[1], $match[2]));'),
|
| 124 |
$string);
|
| 125 |
|
| 126 |
return $replaced;
|
| 127 |
}
|
| 128 |
|
| 129 |
/**
|
| 130 |
* Theme function to render gmap in a node.
|
| 131 |
*/
|
| 132 |
function _mykml_filter_tag($tag, $kml, $latlonzoom) {
|
| 133 |
|
| 134 |
drupal_add_js('$(document).ready(function(){
|
| 135 |
$("#map").jmap();
|
| 136 |
$("#map").addKml("'.$kml.'");
|
| 137 |
$("#map").myMap().setCenter(new GLatLng'.$latlonzoom.');
|
| 138 |
})','inline');
|
| 139 |
|
| 140 |
$gmap = "<div id='map' style='width: ".variable_get("mykml_gmaps_width", '550')."px; height: ".variable_get("mykml_gmaps_height", '400')."px; float:center; border: 1px solid black;'></div>
|
| 141 |
<br clear=\"all\"/>";
|
| 142 |
|
| 143 |
return $gmap;
|
| 144 |
}
|