\n"; $outtext.='
"; return $outtext; } /** * * Cleans the gmap variables to prevent javascript interjection * * @param $gmap * A Gmap variable * * @return * A GMap variable with any dangerous text removed. * * This does not really do much of anything right now. */ function gmap_sanitize(&$gmap){ //sanitizes the gmap variables to reduce the possibility of javascript inserts reset($gmap); $value=current($gmap); do { if (key($gmap)=='id') { $out = array(); preg_match('([a-zA-Z1-9_-]*)', $value, $out); if (strlen($out[0])==0) $out[0]='map'; $gmap[key($gmap)]=$out[0]; } else { $gmap[key($gmap)]=str_replace(';','',$value); } } while ($value=next($gmap)); } /** * * Returns a variable based on . * * @param $instring * A string with the settings of gmap insertion in the format var=setting|var2=setting2 * The possible variables are * id - the id of the map every map on a page must have a unique id * width - width of the map * height - height of the map * center - a string of the longitude and latitude of the centre of the map * zoom - the zoom factor of the google map * align - the alignment of the map 'right', 'left' or 'center' * control - the control shown on the map 'Large', 'Small', or 'None' * type - 'Map', 'Hybrid' or 'Satellite' * points/markers - a string of points to mark on the map with + between * each point * line - the line is defined by a set of points separated by a + * track - Draws a line based on the points in the .plt file * The following shape types require XMaps: * circle - a circle based on a center point and a radius in km separated * by a + and optionally can include the number of sizes. * rpolygon - a regular polygon is defined by the center point and a point * on the permiter separated by a + * polygon - a polygon is defined by a set of points * * Each of the shapes types can optionally have charecteristics of colour, * width, opacity, pattern, text, fill colour, fill opacity. Pattern, text * and fill are all only used by xmaps. * color - hexadecimal for the colour include the '#' * * * @return * A string with the google map ready to be inserted into a node. * */ function gmap_parse_macro($instring,$ver=2) { $statements=explode('|', $instring); $j=0; while (isset($statements[$j])) { unset($tt); $t=explode('=', $statements[$j],2); switch (trim($t[0])) { case 'center': $gmap['center']=gmap_dopoint(trim($t[1]),$ver); break; case 'points': case 'markers': unset($markername); if (strpos($t[1],'::')) { // note: we don't care about case starting with ':' list($markername,$t[1])=explode('::',$t[1],2); } unset($ttt); $ttt = explode('+',$t[1]); for ($i =0; $i'.variable_get('gmap_user_map_header', t('This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.'))."
\n"; $result=db_query("SELECT * FROM {location} WHERE (longitude !=0 OR latitude !=0) AND type='user'"); $thismap = gmap_parse_macro(variable_get('gmap_user_map', '[gmap|id=usermap|center=0,30|zoom=16|width=100%|height=400px]')); if (empty($thismap['markers'])) { $thismap['markers']=array(); } while ($u=db_fetch_object($result)) { if (user_access('user locations')) { $account = user_load(array('uid' => $u->oid)); $newmarker['label'] = theme('user_picture', $account); $newmarker['label'] .= theme('username', $account); $newmarker['point']= $u->longitude.','.$u->latitude; // $newmarker['markername']='usermarker'; } else { $newmarker['point']= $u->longitude.','.$u->latitude; } $thismap['markers'][]=$newmarker; } $output .= ''.gmap_draw_map($thismap);
return $output;
}
function gmap_user($op, &$edit, &$user, $category = NULL) {
if (variable_get('gmap_user',0)) {
switch ($op) {
case 'categories':
return array(array('name'=>'gmap_user', 'title'=> t('location map'),'weight'=>5));
case 'validate':
if (isset($edit['gmap_latitude'])){
if (!is_numeric($edit['gmap_latitude']) || abs($edit['gmap_latitude'])>90) {
form_set_error('gmap_latitude', t('Latitude must be between -90 and 90'));
}
}
if (isset($edit['gmap_longitude'])){
if (!is_numeric($edit['gmap_longitude']) || abs($edit['gmap_longitude'])>180) {
form_set_error('gmap_longitude', t('Longitude must be between -180 and 180'));
}
}
return;
case 'load':
$res=db_query("SELECT * FROM {location} WHERE oid=%d AND type='user'",$user->uid);
if ($gmap_user=db_fetch_array($res)) {
$user->latitude=$gmap_user['latitude'];
$user->longitude=$gmap_user['longitude'];
$user->location=TRUE;
}
return;
case 'insert':
if ((isset($edit['gmap_latitude']) && $edit['gmap_latitude'] !=0) && (isset($edit['gmap_longitude']) && $edit['gmap_longitude'] !=0)) {
db_query("INSERT INTO {location} (oid, type, latitude, longitude, source) VALUES (%d, 'user', %f, %f, %d)", $user->uid, $edit['gmap_latitude'],$edit['gmap_longitude'], 1); // based on location.module LOCATION_LATLON_USER_SUBMITTED=1
}
return;
case 'update':
if ((isset($edit['gmap_latitude']) && $edit['gmap_latitude'] !=0) && (isset($edit['gmap_longitude']) && $edit['gmap_longitude'] !=0)) {
if (isset($user->location)) {
db_query("UPDATE {location} SET latitude='%f', longitude='%f', source='%d' WHERE oid='%d' AND type='user'", $edit['gmap_latitude'],$edit['gmap_longitude'], 1,$user->uid);
// debug message
// drupal_set_message(sprintf("UPDATE {location} SET latitude='%f', longitude='%f', source='%d' WHERE oid='%d' AND type='user'", $edit['gmap_latitude'],$edit['gmap_longitude'], 1,$user->uid));
}
else {
db_query("INSERT INTO {location} (oid, type, latitude, longitude, source) VALUES (%d, 'user', '%f', '%f', '%d')", $user->uid, $edit['gmap_latitude'],$edit['gmap_longitude'], 1); // based on location.module LOCATION_LATLON_USER_SUBMITTED=1
}
}
return;
//db_query ("UPDATE {gmap_user} SET latitude='%f', longitude='%f', zoom=%d WHERE uid=%d", $user->uid, $edit['gmap_latitude'],$edit['gmap_longitude'], $edit['gmap_zoom']);
//return;
case 'delete':
db_query ("DELETE from {location} WHERE oid=%d AND type='user'", $user->uid);
return;
case 'form':
if ($category=='gmap_user') {
// if (isset($user->latitude) && isset($user->longitude)) {
// $usermap=_gmap_user_form($user->longitude,$user->latitude, $user->gmap_zoom);
// }
// else {
// $usermap = _gmap_user_form();
// }
$form['map']=array('#type' => 'fieldset','#title' => t('Google Map'));
$form['map']['gmap_user']=array('#type'=>'markup','#value'=>'');
$form['coordinates']=array('#type' => 'fieldset','#title' => t('Coordinates'));
$form['coordinates']['gmap_latitude']=array('#type'=>'textfield',
'#id'=>'gmap-latitude',
'#title'=>t('Latitude'),
'#default_value'=>$user->latitude,
'#size'=>30,
'#maxlength'=>120,
'#description'=>t('The latitude will automatically be entered here (or you can do it manually).'),
'#attributes'=>array('onchange'=>'gmap_textchange();'));
$form['coordinates']['gmap_longitude']=array('#type'=>'textfield',
'#title'=>t('Longitude'),
'#default_value'=>$user->longitude,
'#size'=>30,
'#maxlength'=>120,
'#description'=>t('The longitude will automatically be entered here (or you can do it manually).'),
'#attributes'=>array('onchange'=>'gmap_textchange();'));
$form['map']['gmap_user']['#value']= gmap_set_location(variable_get('gmap_user_map', '[gmap|id=usermap|center=0,30|control=Large|zoom=16|width=100%|height=400px]'),
$form['coordinates']['gmap_longitude'],
$form['coordinates']['gmap_latitude']);
return $form;
/*
$form2 = form_textfield(t('Latitude'), 'gmap_latitude', $user->latitude, 30,120, t('The latitude will automatically be entered here (or you can do it manually).'), array('onchange'=>'gmap_textchange();') );
$form2 .= form_textfield(t('Longitude'), 'gmap_longitude', $user->longitude, 30,120, t('The longitude will automatically be entered here (or you can do it manually).'), array('onchange'=>'gmap_textchange();') );
$form2 .= form_hidden('gmap_zoom', variable_get('gmap_user_zoom', 15));
return array(array('title'=>t('Google Map'), 'data'=>$form, 'weight'=>0),array('title'=>t('Coordinates'), 'data'=>$form2, 'weight'=>1));
*/
}
}
}
}
function gmap_settings() {
//note the same google api key variable name as in the googlemap module is used
//note the name of the variable for center of the map is latlong although the format is actually longitude, latitude
$form['initialization']=array('#type' => 'fieldset','#title' => t('Google Map Initialize'));
$form['initialization']['googlemap_api_key']=array('#type' => 'textfield', '#title' => t('Google map API key'), '#default_value'=>variable_get('googlemap_api_key', ''), '#size' => 50, '#maxlength' => 255,'#description' => t('Your personal Googlemaps API key. You must get this for each separate website at Google Map API website.'));
$form['initialization']['gmap_method']=array('#type' => 'select', '#title' => t('Google map method'), '#options'=> array('Static'=>t('Static'), 'Dynamic'=>t('Dynamic'), 'None'=>t('None')),'#default_value'=>GMAP_LOAD_METHOD,'#description' => t('How is the Google Map initialization script run:
Static - Loaded on every page,
Dynamic - Initialization script runs only on pages with google maps, but all pages with the gmap filter will not be cached.
None - Google map initialization script must be loaded some other way.'));
// xmaps not compatible with v2 of the Google Map API
// $form['initialization']['gmap_xmaps']=array('#type'=>'checkbox', '#title'=>t('Enable Xmaps features (circles and polygons)'), '#default_value'=>GMAP_XMAPS,'#description'=>t('Enables XMaps features. XMaps is currently a beta release available from xmaps.busmonser.com. '));
// $form['initialization']['gmap_xmaps_script']=array('#type' => 'textfield', '#title' => t('Location of XMaps script'), '#default_value'=>GMAP_XMAPS_SCRIPT, '#size' => 25, '#maxlength' => 50);
$form['initialization']['gmap_cluster']=array('#type'=>'checkbox', '#title'=>t('Enable clusterer.js'), '#default_value'=>GMAP_CLUSTER,'#description'=>t('Enables Jef Poskanzer\'s excellent clusterer.js script. (useful for a large number of markers on a single map)'));
$form['defaults']=array('#type' => 'fieldset', '#title' => t('Default map settings'));
$form['defaults']['gmap_default_width']=array('#type'=>'textfield', '#title'=>t('Default width'), '#default_value'=>GMAP_WIDTH, '#size'=>25, '#maxlength'=>6, '#description'=>t('The default width of a Google map.'));
$form['defaults']['gmap_default_height']=array('#type'=>'textfield', '#title'=>t('Default height'), '#default_value'=>GMAP_HEIGHT, '#size'=>25, '#maxlength'=>6, '#description'=>t('The default height of a Google map.'));
$form['defaults']['gmap_default_latlong']=array('#type'=>'textfield', '#title'=>t('Default center'), '#default_value'=>GMAP_LONGLAT, '#size'=>50, '#maxlength'=>255, '#description'=>t('The default longitude, latitude of a Google map.'));
$form['defaults']['gmap_default_zoom']=array('#type'=>'select', '#title'=>t('Default zoom'), '#default_value'=>GMAP_ZOOM, '#options' => drupal_map_assoc(range(0, 17)), '#description'=>t('The default zoom level of a Google map.'));
$form['defaults']['gmap_default_control']=array('#type'=>'select', '#title'=>t('Default control type'), '#default_value'=>GMAP_CONTROL, '#options'=>array('None'=>t('None'),'Small'=>t('Small'),'Large'=>t('Large')));
$form['defaults']['gmap_default_type']=array('#type'=>'select', '#title'=>t('Default map type'), '#default_value'=>GMAP_TYPE, '#options'=>array('Map'=>t('Map'),'Satellite'=>t('Satellite'),'Hybrid'=>t('Hybrid')));
$form['defaults']['gmap_default_line1_color']=array('#type'=>'textfield', '#title'=>t('Default Line 1 Color'), '#default_value'=>GMAP_LINECOLOR1, '#size'=>25, '#maxlength'=>7 );
$form['defaults']['gmap_default_line2_color']=array('#type'=>'textfield', '#title'=>t('Default Line 2 Color'), '#default_value'=>GMAP_LINECOLOR2, '#size'=>25, '#maxlength'=>7 );
$form['defaults']['gmap_default_line3_color']=array('#type'=>'textfield', '#title'=>t('Default Line 3 Color'), '#default_value'=>GMAP_LINECOLOR3, '#size'=>25, '#maxlength'=>7 );
$form['user']=array('#type' => 'fieldset', '#title' => t('User map settings'));
$form['user']['gmap_user']=array('#type'=>'checkbox', '#title'=>t('Enable Mapping of user locations'), '#default_value'=>variable_get('gmap_user',0),'#description'=>t('Ensure that the database table gmap_user is created before turning on the user location mapping functions.'));
$form['user']['gmap_user_map']=array('#type'=>'textfield', '#title'=>t('Default user map'), '#default_value'=>variable_get('gmap_user_map', '[gmap|id=usermap|center=0,40|zoom=16|width=100%|height=400px]'), '#size'=>50, '#description'=>t('The gmap macro where the user information will be diplayed on.'));
$form['user']['gmap_user_map_header']=array('#type'=>'textarea', '#title'=>t('Text at the top of the map/users page'), '#default_value'=>variable_get('gmap_user_map_header', t('This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.')), '#cols'=>50, '#rows'=>6 );
return $form;
}
function gmap_macro_page() {
drupal_add_js(drupal_get_path('module','gmap'). '/gmapmacro.js');
_gmap_doheader();
return gmap_macro_form();
}
function gmap_macro_form() {
$form['macroform'] = array(
'#type' => 'fieldset',
'#title' => t('Gmap macro creation'),
'#theme' => 'gmap_macro',
);
$linecolors = array(GMAP_LINECOLOR1, GMAP_LINECOLOR2, GMAP_LINECOLOR3);
$form['macroform']['mapdiv']=array('#type'=>'markup','#value'=>'