'map/user', 'type' => MENU_NORMAL_ITEM, 'title' => t('User locations'), 'access' => user_access('show user map'), 'callback' => 'gmap_location_user_page' ); $items[] = array( 'path' => 'map/node', 'type' => MENU_NORMAL_ITEM, 'title' => t('Node locations'), 'access' => user_access('show node map'), 'callback' => 'gmap_location_node_page' ); $items[] = array( 'path' => 'admin/settings/gmap_location', 'type' => MENU_NORMAL_ITEM, 'title' => t('GMap Location'), 'access' => user_access('administer site configuration'), 'callback' => 'drupal_get_form', 'callback arguments' => array('gmap_location_admin_settings'), 'description' => t('Configure GMap Location settings.'), ); } return $items; } /** * Draws a page with a google map that has all of the site users. */ function gmap_location_user_page() { global $user; $locationbyuser = array(); $output ='
'. t(variable_get('gmap_user_map_header', 'This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.')) ."
\n"; // Find default marker $default_marker = variable_get('gmap_user_map_marker', 'drupal'); // Determine if any roles override default setting $roles = user_roles(TRUE); $roles_override = array(); foreach ($roles as $rid => $role) { if (variable_get("gmap_role_map_marker_$rid", $default_marker) != $default_marker) { $roles_override[$rid] = $role; } } $thismap = array_merge( gmap_defaults(), gmap_parse_macro(variable_get('gmap_user_map', '[gmap|id=usermap|center=30,0|zoom=2|width=100%|height=400px]')) ); $result=db_query("SELECT * FROM {location} WHERE (longitude !=0 OR latitude !=0) AND type='user'"); $mode = $thismap['markermode']; while ($u=db_fetch_object($result)) { $account = user_load(array('uid' => $u->eid)); $dupes = array_intersect($account->roles, $roles_override); if (empty($dupes)) { $marker = $default_marker; } else { $key = key($dupes); $marker = variable_get("gmap_role_map_marker_$key", $default_marker); } if (user_access('user locations')) { if ($mode==1) { $newmarker['text'] = theme('gmap_location_user_html', $account); } else if ($mode == 2) { $newmarker['link'] = url('user/'. $account->uid); } $newmarker['latitude'] = $u->latitude; $newmarker['longitude'] = $u->longitude; $newmarker['markername'] = $marker; $newmarker['opts']['title'] = check_plain($account->name); $locationbyuser[$u->eid] = array('latitude' => $u->latitude, 'longitude' => $u->longitude); } else { $newmarker['latitude']= $u->latitude; $newmarker['longitude']= $u->longitude; $newmarker['markername'] = $marker; } $thismap['markers'][]=$newmarker; } if (user_access('user locations') && function_exists('buddylist_get_buddies') && count($locationbyuser)>0) { //create lines for buddies if (!isset($thismap['shapes'])) { $thismap['shapes']=array(); } ksort($locationbyuser); foreach ($locationbyuser as $key => $value) { $buddies= buddylist_get_buddies($key); foreach ($buddies as $bkey => $bvalue) { if ($bkey > $key && isset($locationbyuser[$bkey])) { $thismap['shape'][] = array( 'points' => array($locationbyuser[$key], $locationbyuser[$bkey]), 'type' => 'line' ); } } } } $element = array( '#type' => 'gmap', '#map' => $thismap['id'], '#settings' => $thismap, ); $output .= theme('gmap', $element); if ($user->uid > 0) { $output .= ''. t('To add/change your location to the user map, edit your location.', array('@url' => url('user/'. $user->uid .'/edit/gmap_user'))) .'
'; } return $output; } /** * Draws a page with a google map with the node on it, or if no node is set all of the nodes on it. * * @param $nn * The node number to draw on the map. If this is not set, or is null then all of the nodes will be drawn. */ function gmap_location_node_page($nid = NULL) { if ($nid && ($n = node_load($nid))) { if (node_access('view', $n)) { $output .=''. t(variable_get('gmap_node_map_header', 'This map illustrates the extent of nodes of this website. ')) ."
\n"; $thismap = array_merge(gmap_defaults(), gmap_parse_macro(variable_get('gmap_node_map', '[gmap|id=nodemap|center=30,0|zoom=2|width=100%|height=400px]'))); $thismap = gmap_location_node_map($n, $thismap, TRUE); $output .= ''. theme('gmap', array('#settings' => $thismap)); // @@@ Hey! Wait a second -- Where's the closing
? return $output; } else { //access denied return drupal_access_denied(); } } $output .=''. t(variable_get('gmap_node_map_header', 'This map illustrates the extent of nodes of this website.')) ."
\n"; $result = db_query(db_rewrite_sql("SELECT l.eid, l.longitude, l.latitude FROM {location} l INNER JOIN {node} n ON l.eid = n.vid WHERE (l.longitude!=0 OR l.latitude !=0) AND l.type='node' AND n.status = 1")); $thismap = array_merge(gmap_defaults(), gmap_parse_macro(variable_get('gmap_node_map', '[gmap|id=usermap|center=30,0|zoom=2|width=100%|height=400px]'))); if (empty($thismap['markers'])) { $thismap['markers']=array(); } while ($locn=db_fetch_object($result)) { $n = node_load(array('vid' => $locn->eid)); if ($n && node_access('view', $n)) { $thismap = gmap_location_node_map($n, $thismap, FALSE); } } $output .= ''. theme('gmap', array('#settings' => $thismap)) .'
'; return $output; } /** * Adds the location information from a node for a gmap. * * @param $n * The node object to add to the map. * * @param $thismap * A gmap var with the map that will be used as the basemap * * @param $single * true if this is the only node being looked at (will center the map and possible add * additional information. * * @return * A gmap centred on the */ function gmap_location_node_map($n, $thismap, $single = FALSE) { if ((isset($n->gmap_location_latitude) && isset($n->gmap_location_longitude)) || (isset($n->location['latitude']) && isset($n->location['longitude']))) { $latitude = isset($n->gmap_location_latitude) ? $n->gmap_location_latitude : $n->location['latitude']; $longitude = isset($n->gmap_location_longitude) ? $n->gmap_location_longitude : $n->location['longitude']; $mode = $thismap['markermode']; $newmarker = array(); $width = 0; if ($mode == 1) { if (!($newmarker['text'] = theme(strtr($n->type, '-', '_') .'_gmapnodelabel', $n))) { $newmarker['text'] = theme('gmapnodelabel', $n); if ($single && $mode == 1) { // Autoclick $newmarker['autoclick'] = true; } } } else if ($mode == 2) { $newmarker['link'] = url('node/'. $n->nid); } $newmarker['latitude'] = $latitude; $newmarker['longitude'] = $longitude; $newmarker['markername'] = variable_get('gmap_node_marker_'. $n->type, ''); $newmarker['opts']['title'] = $n->title; switch ($n->type) { case 'acidfree': $newmarker['winwidth'] = (variable_get('acidfree_thumb_dim', IMAGE_THUMB_SIZE) + 40) .'px'; break; } $thismap['markers'][] = $newmarker; if ($single) { $thismap['latitude'] = $latitude; $thismap['longitude'] = $longitude; } } if ($single) { //do special things for certain nodes when it is the only node shown switch ($n->type) { case 'og': $result = db_query(og_list_users_sql(), $n->nid); while ($user = db_fetch_object($result)) { if (isset($user->location['latitude']) && isset($user->location['longitude'])) { if (user_access('user locations')) { $newmarker = array( 'label' => theme('user_picture', $user) . theme('username', $user), 'latitude' => $latitude, 'longitude' => $longitude, 'markername' => variable_get('gmap_user_map_marker', 'drupal'), ); if ($mode==1) { // Autoclick $newmarker['autoclick'] = true; } $thismap['markers'][] = $newmarker; } } else { $newmarker['latitude'] = $u->latitude; $newmarker['longitude'] = $u->longitude; if ($mode==1) { // Autoclick $newmarker['autoclick'] = true; } $thismap['markers'][] = $newmarker; } } break; } } return $thismap; } /** * Admin Settings Page * */ function gmap_location_admin_settings() { $form['geocoding'] = array( '#type' => 'fieldset', '#title' => t('Geocode Locations'), ); $form['geocoding']['gmap_geocode'] = array( '#type' => 'radios', '#title' => t('Enable the Google Map API geocoding'), '#default_value' => variable_get('gmap_geocode', 1), '#options' => array(1 => 'Enabled', 0 => 'Disabled'), ); $form['user'] = array( '#type' => 'fieldset', '#title' => t('Location settings for users'), ); $form['user']['gmap_user'] = array( '#type' => 'checkbox', '#title' => t('Profile map'), '#default_value' => variable_get('gmap_user', TRUE), '#description' => t('Let users set/edit their location in their profile.'), ); $form['user']['gmap_user_profile_category'] = array( '#type' => 'textfield', '#title' => t('Profile category title'), '#default_value' => variable_get('gmap_user_profile_category', "Location map"), '#size' => 50, '#maxlength' => 50, '#description' => t('Let users set/edit their location in their profile.'), ); $form['user']['gmap_user_map'] = array( '#type' => 'textfield', '#title' => t('Default user map'), '#default_value' => variable_get('gmap_user_map', '[gmap |id=usermap|center=40,0|zoom=3|width=100%|height=400px]'), '#size' => 50, '#maxlength' => 500, '#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, ); $form['user']['gmap_user_map_marker'] = array( '#type' => 'gmap_markerchooser', '#title' => t('Marker for users'), '#default_value' => variable_get('gmap_user_map_marker', 'drupal'), ); // Option to use a different marker for each role $form['user']['roles'] = array( '#type' => 'fieldset', '#title' => t('Markers per role'), '#description' => t('Use a different marker to denote users in the following roles.'), ); // Retrieve and sort list of roles, sans anonymous user $roles = user_roles(TRUE); asort($roles); // Create a selection box per role foreach ($roles as $rid => $role) { $form['user']['roles']["gmap_role_map_marker_$rid"] = array( '#type' => 'gmap_markerchooser', '#title' => $role, '#default_value' => variable_get("gmap_role_map_marker_$rid", variable_get('gmap_user_map_marker', 'drupal')), ); } $form['node'] = array( '#type' => 'fieldset', '#title' => t('Location settings for nodes'), ); $form['node']['gmap_node_map'] = array( '#type' => 'textfield', '#title' => t('Default node map'), '#default_value' => variable_get('gmap_node_map', '[gmap |id=nodemap|center=40,0|zoom=3|width=100%|height=400px]'), '#size' => 50, '#maxlength' => 500, '#description' => t('The gmap macro where the user information will be diplayed on.'), ); $form['node']['gmap_node_map_header'] = array( '#type' => 'textarea', '#title' => t('Text at the top of the map/nodes page'), '#default_value' => variable_get('gmap_node_map_header', t('This map illustrates the locations of the nodes on this website. Each marker indicates a node associated with a specific location.')), '#cols' => 50, '#rows' => 6, ); $ntypes=node_get_types(); foreach ($ntypes as $key => $value) { if (intval(variable_get('location_maxnum_'. $key, 0)) !== 0) { $form['node']['gmap_node_marker_'. $key] = array( '#type' => 'gmap_markerchooser', '#title' => t('Marker for '. $value->name), '#default_value' => variable_get('gmap_node_marker_'. $key, ''), ); } } return system_settings_form($form); } /** * Draw block of location for current node. */ function gmap_location_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': $blocks[0]['info'] = t('Location map'); $blocks[1]['info'] = t('Author map'); return $blocks; case 'configure': $form = array(); if ($delta == 0) { $form['gmap_location_block_macro'] = array( '#type' => 'textfield', '#title' => t('Map Macro'), '#size' => 60, '#maxlength' => 500, '#description' => t('A macro to be used as a base map for the location block. This map will be recentered on the location, so the center is not that important.Alternate base map macros can be entered for a specific node type below.'), '#default_value' => variable_get('gmap_location_block_macro', '[gmap |id=block0 |zoom=10 |width=100% |height=200px |control=Small |type=Map] '), ); $ntypes=node_get_types(); foreach ($ntypes as $key => $value) { if (variable_get('location_maxnum_'. $key, 0)) { $form['gmap_location_block_macro_'. $key] = array( '#type' => 'textfield', '#title' => t('Map Macro for '. $value->name), '#size' => 60, '#maxlength' => 500, '#default_value' => variable_get('gmap_location_block_macro_'. $key, ''), ); } } } elseif ($delta == 1) { $form['gmap_location_author_block_macro'] = array( '#type' => 'textfield', '#title' => t('Map Macro'), '#size' => 60, '#maxlength' => 500, '#description' => t('A macro to be used as a base map for the location block author. This map will be recentered on the location, so the center is not that important.'), '#default_value' => variable_get('gmap_location_author_block_macro', '[gmap |zoom=10 |width=100% |height=200px |control=Small |type=Map] '), ); $ntypes = node_get_types(); foreach ($ntypes as $key => $type) { $form['gmap_location_author_block_'. $key] = array( '#type' => 'checkbox', '#title' => t('Author block enabled for %type content type', array('%type' => $type->name)), '#default_value' => variable_get('gmap_location_author_block_'. $key, 0), ); } } return $form; case 'save': if ($delta == 0) { // Have Drupal save the string to the database. variable_set('gmap_location_block_macro', $edit['gmap_location_block_macro']); $ntypes = node_get_types(); foreach ($ntypes as $key => $value) { if (variable_get('location_maxnum_'. $key, 0)) { variable_set('gmap_location_block_macro_'. $key, $edit['gmap_location_block_macro_'. $key]); } } } elseif ($delta == 1) { // Have Drupal save the string to the database. variable_set('gmap_location_author_block_macro', $edit['gmap_location_author_block_macro']); $ntypes = node_get_types(); foreach ($ntypes as $key => $value) { variable_set('gmap_location_author_block_'. $key, $edit['gmap_location_author_block_'. $key]); } } return; case 'view': switch ($delta) { case 0: if (arg(0)=='node' && is_numeric(arg(1))) { return gmap_location_block_view(arg(1)); } break; case 1: if (arg(0)=='node' && is_numeric(arg(1))) { return gmap_location_author_block_view(arg(1)); } break; } } } function _gmap_location_getlatlon($node) { if (isset($node->location['latitude']) && isset($node->location['longitude'])) { return $node->location; } return false; } function gmap_location_block_view($nid) { $block = array(); $node = node_load($nid); if (_gmap_location_getlatlon($node)) { $block['subject'] = t('Location'); if (strlen(variable_get('gmap_location_block_macro_'. $node->type, '')) > 0) { $macro = variable_get('gmap_location_block_macro_'. $node->type, ''); } else { $macro = variable_get('gmap_location_block_macro', '[gmap |id=block0 |zoom=10 |width=100% |height=200px |control=Small |type=Map] '); } $block['content'] = theme('gmap', array('#settings' => gmap_location_map_add_node(gmap_parse_macro($macro), $node))); } return $block; } function gmap_location_author_block_view($nid) { $block = array(); $node = node_load($nid); if (variable_get('gmap_location_author_block_'. $node->type, FALSE)) { $result = db_fetch_array(db_query("SELECT latitude, longitude FROM {location} WHERE eid = %d AND type = 'user'", $node->uid)); if (!$result) { return; } $macro = variable_get('gmap_location_block_macro_'. $node->type, FALSE); if (!$macro) { $macro = variable_get('gmap_location_block_macro', '[gmap |zoom=10 |width=100% |height=200px |control=Small |type=Map]'); } $map = array( '#map' => 'gmap_location_authorblock', '#settings' => gmap_parse_macro($macro), ); $map['#settings']['behavior']['notype'] = TRUE; $map['#settings']['markers'] = array(); $map['#settings']['markers'][] = array( 'latitude' => $result['latitude'], 'longitude' => $result['longitude'], 'markername' => variable_get('gmap_user_map_marker', 'drupal'), 'label' => check_plain($node->name), ); $map['#settings']['latitude'] = $result['latitude']; $map['#settings']['longitude'] = $result['longitude']; $block['subject'] = t('Author Location'); $block['content'] = theme('gmap', $map); } return $block; } function gmap_location_map_add_node($basemap, $node, $label='') { // Count offsets. static $offsets = array(); $location = _gmap_location_getlatlon($node); if (empty($basemap['markers'])) { $thismap['markers']=array(); } $newmarker['latitude'] = $location['latitude']; $newmarker['longitude'] = $location['longitude']; $markername = variable_get('gmap_node_marker_'. $node->type, ''); $newmarker['markername'] = $markername; if (!isset($offsets[$markername])) { $offsets[$markername] = 0; } $newmarker['offset'] = $offsets[$markername]; $offsets[$markername]++; $newmarker['label'] = $label; $basemap['markers'][] = $newmarker; $basemap['latitude'] = $location['latitude']; $basemap['longitude'] = $location['longitude']; return $basemap; } //Any module can create a default theme for the display of nodes of the node type by //creating a function theme_hook_gmapnodelabel a theme could then further specify it //by creating a mytheme_nodetype_gmapnodelabel or could simply create a default //node type by creating a mytheme_gmapnodelabel function theme_acidfree_gmapnodelabel($n) { $out = strtr(theme_acidfree_print_thumb_photo($n), "'\n", '" '); //