/[drupal]/contributions/modules/gmap/gmap_location.module
ViewVC logotype

Contents of /contributions/modules/gmap/gmap_location.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.58 - (show annotations) (download) (as text)
Fri Mar 13 17:10:45 2009 UTC (8 months, 1 week ago) by bdragon
Branch: MAIN
CVS Tags: HEAD
Changes since 1.57: +14 -10 lines
File MIME type: text/x-php
The remainder of #392130, reported by gaele:
Rename permissions:
"show node map" -> "view node map"
"show user map" -> "view user map"
"user locations" -> "view user location details"
1 <?php
2 // $Id: gmap_location.module,v 1.57 2009/03/13 15:53:22 bdragon Exp $
3
4 /**
5 * @file
6 * GMap Location module is a module to add some gmap funcationality based on location.modules information.
7 *
8 * The main functions are to provide a map showing all of the nodes or users that have location information on a map.
9 */
10
11 /**
12 * Implementation of hook_theme().
13 */
14 function gmap_location_theme() {
15 return array(
16 'gmap_location_user_page' => array('arguments' => array('header', 'map', 'footer')),
17 'gmap_location_node_page' => array('arguments' => array('count', 'header', 'map', 'footer')),
18 // @@@ Test this one thoroughly.
19 'gmap_location_infowindow_node' => array(
20 'pattern' => 'gmap_location_infowindow_node__',
21 'arguments' => array('node', 'opt'),
22 ),
23 'gmap_location_infowindow_user' => array('arguments' => array('account')),
24 );
25 }
26
27 /**
28 * Implementation of hook_perm().
29 */
30 function gmap_location_perm() {
31 return array(
32 'view node map',
33 'view user map',
34 'view user location details',
35 );
36 }
37
38 /**
39 * Get the user map variable defaults.
40 */
41 function _gmap_location_user_map_defaults() {
42 return array(
43 'macro' => '[gmap |id=usermap|center=40,0|zoom=3|width=100%|height=400px]',
44 'header' => 'This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.',
45 'footer' => '',
46 'markermode' => 1,
47 );
48 }
49
50 /**
51 * Get the node map variable defaults.
52 */
53 function _gmap_location_node_map_defaults() {
54 return array(
55 'macro' => '[gmap |id=nodemap|center=40,0|zoom=3|width=100%|height=400px]',
56 'header' => 'This map illustrates the locations of the nodes on this website. Each marker indicates a node associated with a specific location.',
57 'footer' => '',
58 'markermode' => 1,
59 );
60 }
61
62 /**
63 * Implementation of hook_menu().
64 */
65 function gmap_location_menu() {
66 $items['map/user'] = array(
67 'type' => MENU_NORMAL_ITEM,
68 'title' => 'User locations',
69 'access arguments' => array('view user map'),
70 'page callback' => 'gmap_location_user_page',
71 );
72 $items['map/user/load'] = array(
73 'type' => MENU_CALLBACK,
74 'access arguments' => array('view user map'),
75 'page callback' => 'gmap_location_user_point',
76 );
77 $items['map/node'] = array(
78 'type' => MENU_NORMAL_ITEM,
79 'title' => 'Node locations',
80 'access arguments' => array('view node map'),
81 'page callback' => 'gmap_location_node_page',
82 );
83 $items['map/node/load/%node/%'] = array(
84 'type' => MENU_CALLBACK,
85 'access arguments' => array('view node map'),
86 'page callback' => 'gmap_location_node_point',
87 'page arguments' => array(3,4),
88 );
89 $items['admin/settings/gmap_location'] = array(
90 'type' => MENU_NORMAL_ITEM,
91 'title' => 'GMap Location',
92 'access arguments' => array('administer site configuration'),
93 'page callback' => 'drupal_get_form',
94 'page arguments' => array('gmap_location_admin_settings'),
95 'description' => 'Configure GMap Location settings.',
96 );
97 return $items;
98 }
99
100 /**
101 * Draws a page with a google map that has all of the site users.
102 */
103 function gmap_location_user_page() {
104 $markertypes = variable_get('gmap_role_markers', array(DRUPAL_AUTHENTICATED_RID => 'drupal'));
105 $usermap = variable_get('gmap_user_map', _gmap_location_user_map_defaults());
106 $map = array_merge(gmap_defaults(), gmap_parse_macro($usermap['macro']));
107 $mode = $usermap['markermode'];
108 $map['rmtcallback'] = url('map/user/load');
109 $map['markermode'] = $usermap['markermode'];
110
111 // Find the highest rid, if available, for each user with a location.
112
113 $result = db_query("
114 SELECT
115 u.name, MAX(r.rid) as role, i.uid, i.lid, l.latitude, l.longitude
116 FROM
117 {users} u
118 INNER JOIN
119 {location_instance} i
120 ON
121 u.uid = i.uid
122 INNER JOIN
123 {location} l
124 ON
125 i.lid = l.lid
126 LEFT JOIN
127 {users_roles} r
128 ON
129 i.uid = r.uid
130 WHERE
131 u.status = 1
132 AND
133 u.access != 0
134 AND
135 (l.latitude != 0 OR l.longitude != 0)
136 GROUP BY
137 i.uid, i.lid, u.name, l.latitude, l.longitude");
138 // The u.name, l.latitude, and l.longitude in the GROUP BY are needed for
139 // PostgreSQL.
140
141 while ($row = db_fetch_object($result)) {
142 // Determine marker type to show.
143 $marker = $markertypes[DRUPAL_AUTHENTICATED_RID];
144 if ($row->role && isset($markertypes[$row->role])) {
145 $marker = $markertypes[$row->role];
146 }
147
148 // Users with the 'view user location details' permission are allowed to see who
149 // each marker represents.
150 if (user_access('view user location details')) {
151 if ($mode == 1) {
152 $newmarker['rmt'] = $row->uid;
153 }
154 else if ($mode == 2) {
155 $newmarker['link'] = url('user/'. $row->uid);
156 }
157 $newmarker['latitude'] = $row->latitude;
158 $newmarker['longitude'] = $row->longitude;
159 $newmarker['markername'] = $marker;
160 $newmarker['opts']['title'] = check_plain($row->name);
161 }
162 else {
163 $newmarker['latitude'] = $row->latitude;
164 $newmarker['longitude'] = $row->longitude;
165 $newmarker['markername'] = $marker;
166 }
167 $map['markers'][] = $newmarker;
168 }
169
170 // @@@ Move to gmap_addons.
171 /*
172 if (user_access('view user location details') && function_exists('buddylist_get_buddies') && count($locationbyuser)>0) {
173 //create lines for buddies
174 if (!isset($thismap['shapes'])) {
175 $thismap['shapes']=array();
176 }
177 ksort($locationbyuser);
178 foreach ($locationbyuser as $key => $value) {
179 $buddies= buddylist_get_buddies($key);
180 foreach ($buddies as $bkey => $bvalue) {
181 if ($bkey > $key && isset($locationbyuser[$bkey])) {
182 $thismap['shape'][] = array(
183 'points' => array($locationbyuser[$key], $locationbyuser[$bkey]),
184 'type' => 'line'
185 );
186 }
187 }
188 }
189 }
190 */
191
192 return theme('gmap_location_user_page',
193 $usermap['header'],
194 theme('gmap', array('#settings' => $map)),
195 $usermap['footer']
196 );
197 }
198
199 /**
200 * AHAH callback for getting the contents of a user point popup.
201 */
202 function gmap_location_user_point() {
203 $uid = arg(3);
204 if (is_numeric($uid) && $account = user_load(array('uid' => $uid))) {
205 echo theme('gmap_location_infowindow_user', $account);
206 exit();
207 }
208 }
209
210 /**
211 * Theme function for displaying the user page.
212 */
213 function theme_gmap_location_user_page($header, $map, $footer) {
214 global $user;
215
216 $output = "<p>$header</p>\n<p>$map</p>\n<p>$footer</p>";
217
218 if ($user->uid > 0) {
219 $output .= '<p>'. t('To add/change your location to the user map, <a href="@url">edit your location</a>.', array('@url' => url('user/'. $user->uid .'/edit'))) .'</p>';
220 }
221
222 return $output;
223 }
224
225 /**
226 * Draws a page with a google map with the node on it, or if no node is set all of the nodes on it.
227 *
228 * @param $nid
229 * The node nid to draw on the map.
230 * If this is not set, or is null then all of the nodes will be drawn.
231 */
232 function gmap_location_node_page($nid = NULL) {
233
234 $nodemap = variable_get('gmap_node_map', _gmap_location_node_map_defaults());
235 $markertypes = variable_get('gmap_node_markers', array());
236
237 $map = array_merge(
238 gmap_defaults(),
239 gmap_parse_macro($nodemap['macro']));
240
241 $mode = $nodemap['markermode'];
242 $map['rmtcallback'] = url('map/node/load');
243 $map['markermode'] = $nodemap['markermode'];
244
245 if (!isset($map['markers']) || !is_array($map['markers'])) {
246 $map['markers'] = array();
247 }
248
249 $marker_sql1 = '';
250 $marker_sql2 = '';
251 if (module_exists('gmap_taxonomy')) {
252 $marker_sql1 = ', m.marker';
253 $marker_sql2 = 'LEFT JOIN {gmap_taxonomy_node} m ON n.vid = m.vid';
254 }
255
256 $add_sql = (is_numeric($nid) && $nid > 0) ? ' AND n.nid = %d' : '';
257 $result = db_query(db_rewrite_sql("
258 SELECT n.nid, n.type, n.title, l.latitude, l.longitude $marker_sql1
259 FROM {node} n
260 INNER JOIN {location_instance} i
261 ON n.vid = i.vid
262 INNER JOIN {location} l
263 ON l.lid = i.lid
264 $marker_sql2
265 WHERE
266 n.status = 1
267 AND
268 (l.latitude != 0 OR l.longitude != 0)
269 ". $add_sql), $nid);
270
271 $count = 0;
272 while ($row = db_fetch_object($result)) {
273 $count++;
274 $newmarker = array();
275 if ($mode == 1) {
276 // Popup
277 $newmarker['rmt'] = $row->nid .'/0';
278 }
279 elseif ($mode == 2) {
280 // Link
281 $newmarker['link'] = url('node/'. $row->nid);
282 }
283
284 $newmarker['latitude'] = $row->latitude;
285 $newmarker['longitude'] = $row->longitude;
286 $newmarker['markername'] = isset($markertypes[$row->type]) ? $markertypes[$row->type] : 'drupal';
287 if (isset($row->marker) && !empty($row->marker)) {
288 $newmarker['markername'] = $row->marker;
289 }
290 $newmarker['opts']['title'] = $row->title;
291 $map['markers'][] = $newmarker;
292 }
293
294 // Special stuff for single marker
295 if ($count == 1) {
296 // Center map on only marker.
297 $map['latitude'] = $map['markers'][0]['latitude'];
298 $map['longitude'] = $map['markers'][0]['longitude'];
299
300 // Autoclick in single marker case.
301 if ($mode == 1) {
302 $map['markers'][0]['autoclick'] = TRUE;
303 }
304 }
305
306 // Special cases for single node view.
307 if (is_numeric($nid) && $node = node_load($nid)) {
308
309 // Organic groups. Group nodes are displayed as a map of the users who belong to the group.
310 if (user_access('view user location details') && function_exists('og_is_group_type') && og_is_group_type($node->type)) {
311 $rolemarkers = variable_get('gmap_role_markers', array());
312
313 $map['markers'] = array(); // Reset markers.
314
315 $result = db_query("
316 SELECT
317 MAX(r.rid) as role, i.uid, l.latitude, l.longitude
318 FROM
319 {og_uid} o
320 INNER JOIN {location_instance} i
321 ON i.uid = o.uid
322 INNER JOIN {location} l
323 ON l.lid = i.lid
324 LEFT JOIN {users_roles} r
325 ON i.uid = r.uid
326 WHERE
327 o.nid = %d
328 AND
329 o.is_active >= 1
330 AND
331 (l.latitude != 0 OR l.longitude != 0)
332 GROUP BY
333 o.uid", $nid, 'user');
334
335 while ($row = db_fetch_object($result)) {
336 $newmarker = array();
337 $newmarker['rmt'] = $nid .'/'. $row->uid;
338
339 // Determine marker type to show.
340 $newmarker['markername'] = $markertypes[DRUPAL_AUTHENTICATED_RID];
341 if ($row->role && isset($rolemarkers[$row->role])) {
342 $newmarker['markername'] = $rolemarkers[$row->role];
343 }
344 $newmarker['latitude'] = $row->latitude;
345 $newmarker['longitude'] = $row->longitude;
346 $map['markers'][] = $newmarker;
347 }
348 }
349 }
350
351 return theme('gmap_location_node_page',
352 $count,
353 $nodemap['header'],
354 theme('gmap', array('#settings' => $map)),
355 $nodemap['footer']
356 );
357 }
358
359 /**
360 * AHAH callback for getting the contents of a node point popup.
361 */
362 function gmap_location_node_point($node, $opt) {
363 $output = '';
364 // @@@ Make sure $node->type is an ok thing to do here..
365 echo theme(array("gmap_location_infowindow_node__$node->type", 'gmap_location_infowindow_node'), $node, $opt);
366 // exit();
367 return;
368 }
369
370 /**
371 * Theme function for displaying the node page.
372 */
373 function theme_gmap_location_node_page($count, $header, $map, $footer) {
374 $output = '';
375 if ($header) {
376 $output .= "<p>$header</p>";
377 }
378 $output .= $map;
379 if ($footer) {
380 $output .= "<p>$footer</p>";
381 }
382 return $output;
383 }
384
385 /**
386 * Admin Settings Page
387 *
388 */
389 function gmap_location_admin_settings() {
390 $form['user'] = array(
391 '#type' => 'fieldset',
392 '#title' => t('User settings'),
393 );
394
395 // gmap_user_map defaults
396 $temp = variable_get('gmap_user_map', _gmap_location_user_map_defaults());
397
398 $form['user']['gmap_user_map'] = array(
399 '#type' => 'fieldset',
400 '#title' => t('User Map (<em>map/user</em>)'),
401 '#tree' => TRUE,
402 );
403 $form['user']['gmap_user_map']['macro'] = array(
404 '#type' => 'textfield',
405 '#title' => t('Macro'),
406 '#default_value' => $temp['macro'],
407 '#size' => 50,
408 '#maxlength' => 500,
409 '#description' => t('The gmap macro where the user information will be diplayed on.'),
410 );
411 $form['user']['gmap_user_map']['header'] = array(
412 '#type' => 'textarea',
413 '#title' => t('Page header'),
414 '#description' => t('Text at the top of the user map.', array('@url' => url('map/user'))),
415 '#default_value' => $temp['header'],
416 '#cols' => 50,
417 '#rows' => 6,
418 );
419 $form['user']['gmap_user_map']['footer'] = array(
420 '#type' => 'textarea',
421 '#title' => t('Page footer'),
422 '#description' => t('Text at the bottom of the user map.'),
423 '#default_value' => $temp['footer'],
424 '#cols' => 50,
425 '#rows' => 6,
426 );
427 $form['user']['gmap_user_map']['markermode'] = array(
428 '#type' => 'radios',
429 '#title' => t('Marker action'),
430 '#description' => t('Perform this action when a marker is clicked.'),
431 '#options' => array(t('Do nothing'), t('Open info window'), t('Open link')),
432 '#default_value' => $temp['markermode'],
433 );
434
435
436 // Option to use a different marker for each role
437 $form['user']['gmap_role_markers'] = array(
438 '#type' => 'fieldset',
439 '#title' => t('Markers per role'),
440 '#description' => t('Choose a marker to represent each user role on the user map. If a user belongs to multiple roles, the marker for the highest Role ID will be used.'),
441 '#tree' => TRUE,
442 );
443
444 // Retrieve and sort list of roles, sans anonymous user
445 $roles = user_roles(TRUE);
446 //asort($roles);
447
448 $defaults = variable_get('gmap_role_markers', array());
449
450 // Create a selection box per role
451 foreach ($roles as $rid => $role) {
452 $form['user']['gmap_role_markers'][$rid] = array(
453 '#type' => 'gmap_markerchooser',
454 '#title' => t('%role (Role ID: %rid)', array('%role' => $role, '%rid' => $rid)),
455 '#default_value' => isset($defaults[$rid]) ? $defaults[$rid] : 'drupal',
456 );
457 }
458
459 $form['node'] = array(
460 '#type' => 'fieldset',
461 '#title' => t('Node settings'),
462 );
463
464 // gmap_node_map defaults
465 $temp = variable_get('gmap_node_map', _gmap_location_node_map_defaults());
466
467 $form['node']['gmap_node_map'] = array(
468 '#type' => 'fieldset',
469 '#title' => t('Node Map (<em>map/node</em>)'),
470 '#tree' => TRUE,
471 );
472 $form['node']['gmap_node_map']['macro'] = array(
473 '#type' => 'textfield',
474 '#title' => t('Macro'),
475 '#default_value' => $temp['macro'],
476 '#size' => 50,
477 '#maxlength' => 500,
478 '#description' => t('The gmap macro where the node information will be diplayed on.'),
479 );
480 $form['node']['gmap_node_map']['header'] = array(
481 '#type' => 'textarea',
482 '#title' => t('Page header'),
483 '#description' => t('Text at the top of the node map.'),
484 '#default_value' => $temp['header'],
485 '#cols' => 50,
486 '#rows' => 6,
487 );
488 $form['node']['gmap_node_map']['footer'] = array(
489 '#type' => 'textarea',
490 '#title' => t('Page footer'),
491 '#description' => t('Text at the bottom of the node map.'),
492 '#default_value' => $temp['footer'],
493 '#cols' => 50,
494 '#rows' => 6,
495 );
496 $form['node']['gmap_node_map']['markermode'] = array(
497 '#type' => 'radios',
498 '#title' => t('Marker action'),
499 '#description' => t('Perform this action when a marker is clicked.'),
500 '#options' => array(t('Do nothing'), t('Open info window'), t('Open link')),
501 '#default_value' => $temp['markermode'],
502 );
503
504 // Option to use a different marker for each content type.
505 $form['node']['gmap_node_markers'] = array(
506 '#type' => 'fieldset',
507 '#title' => t('Markers per content type'),
508 '#description' => t('Choose a marker to represent each type of content on the node map.'),
509 '#tree' => TRUE,
510 );
511
512 $ntypes = node_get_types();
513
514 $defaults = variable_get('gmap_node_markers', array());
515
516 foreach ($ntypes as $key => $value) {
517 $form['node']['gmap_node_markers'][$key] = array(
518 '#type' => 'gmap_markerchooser',
519 '#title' => t('Marker for %type', array('%type' => $value->name)),
520 '#default_value' => isset($defaults[$key]) ? $defaults[$key] : 'drupal',
521 );
522 $settings = variable_get("location_settings_node_$key", FALSE);
523 if (!((isset($settings['multiple']['max']) && $settings['multiple']['max']) || variable_get("location_maxnum_$key", 0))) {
524 $form['node']['gmap_node_markers'][$key]['#description'] = t('This content type is not currently Location enabled.');
525 }
526 }
527 return system_settings_form($form);
528 }
529
530 /**
531 * Draw block of location for current node.
532 */
533 function gmap_location_block($op = 'list', $delta = 0, $edit = array()) {
534 switch ($op) {
535 case 'list':
536 $blocks[0] = array(
537 'info' => t('Location map'),
538 'cache' => BLOCK_NO_CACHE, // As it injects JS.
539 );
540 $blocks[1] = array(
541 'info' => t('Author map'),
542 'cache' => BLOCK_NO_CACHE, // As it injects JS.
543 );
544 return $blocks;
545
546 case 'configure':
547 $form = array();
548 if ($delta == 0) { // Location map
549 $form['gmap_location_block_macro'] = array(
550 '#type' => 'textfield',
551 '#title' => t('Map Macro'),
552 '#size' => 60,
553 '#maxlength' => 500,
554 '#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. <p>Alternate base map macros can be entered for a specific node type below.'),
555 '#default_value' => variable_get('gmap_location_block_macro', '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]'),
556 );
557
558 $ntypes = node_get_types();
559 foreach ($ntypes as $key => $value) {
560 $settings = variable_get("location_settings_node_$key", FALSE);
561 if ((isset($settings['multiple']['max']) && $settings['multiple']['max']) || variable_get("location_maxnum_$key", 0)) {
562 $form["gmap_location_block_macro_$key"] = array(
563 '#type' => 'textfield',
564 '#title' => t('Map Macro for %type', array('%type' => $value->name)),
565 '#size' => 60,
566 '#maxlength' => 500,
567 '#default_value' => variable_get("gmap_location_block_macro_$key", ''),
568 );
569 }
570 }
571 }
572 elseif ($delta == 1) { // Author map
573 $form['gmap_location_author_block_macro'] = array(
574 '#type' => 'textfield',
575 '#title' => t('Map Macro'),
576 '#size' => 60,
577 '#maxlength' => 500,
578 '#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.'),
579 '#default_value' => variable_get('gmap_location_author_block_macro', '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]'),
580 );
581
582 $form['gmap_location_author_block_types'] = array(
583 '#type' => 'checkboxes',
584 '#title' => t('Enable author block for the following content types'),
585 '#options' => array_map('check_plain', node_get_types('names')),
586 '#default_value' => variable_get('gmap_location_author_block_types', array()),
587 );
588
589 $form['gmap_location_author_block_marker'] = array(
590 '#type' => 'gmap_markerchooser',
591 '#title' => t('Marker to use for author map'),
592 '#default_value' => variable_get('gmap_location_author_block_marker', 'drupal'),
593 );
594 }
595 return $form;
596
597 case 'save':
598 if ($delta == 0) {
599 // Save macro, if customized.
600 $macro = trim($edit['gmap_location_block_macro']);
601 if ($macro == '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]' || empty($macro)) {
602 // If the user doesn't customize the variable, don't set it.
603 // This saves a lot of headache in the future.
604 variable_del('gmap_location_block_macro');
605 }
606 else {
607 variable_set('gmap_location_block_macro', $macro);
608 }
609
610 // Save node type specific macros.
611 $ntypes = node_get_types();
612 foreach ($ntypes as $key => $value) {
613 $settings = variable_get("location_settings_node_$key", FALSE);
614 if ((isset($settings['multiple']['max']) && $settings['multiple']['max']) || variable_get("location_maxnum_$key", 0)) {
615 $val = trim($edit["gmap_location_block_macro_$key"]);
616 if (empty($val)) {
617 variable_del("gmap_location_block_macro_$key");
618 }
619 else {
620 variable_set('gmap_location_block_macro_'. $key, $edit['gmap_location_block_macro_'. $key]);
621 }
622 }
623 }
624 }
625 elseif ($delta == 1) {
626 // Save macro, if customized.
627 $macro = trim($edit['gmap_location_author_block_macro']);
628 if ($macro == '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]' || empty($macro)) {
629 // If the user doesn't customize the variable, don't set it.
630 // This saves a lot of headache in the future.
631 variable_del('gmap_location_author_block_macro');
632 }
633 else {
634 variable_set('gmap_location_author_block_macro', $macro);
635 }
636
637 // Save "enabled on" types.
638 variable_set('gmap_location_author_block_types', array_keys(array_filter($edit['gmap_location_author_block_types'])));
639 // Save marker.
640 variable_set('gmap_location_author_block_marker', $edit['gmap_location_author_block_marker']);
641 }
642 return;
643
644 case 'view':
645 switch ($delta) {
646 case 0:
647 if (arg(0)=='node' && is_numeric(arg(1))) {
648 return gmap_location_block_view(arg(1));
649 }
650 break;
651 case 1:
652 if (arg(0)=='node' && is_numeric(arg(1))) {
653 return gmap_location_author_block_view(arg(1));
654 }
655 break;
656 }
657 }
658 }
659
660 function gmap_location_block_view($nid) {
661 $block = array();
662 $node = node_load($nid);
663 if ($node->locations) {
664 $markertypes = variable_get('gmap_node_markers', array());
665 $markers = array();
666 $count = 0;
667 foreach ($node->locations as $loc) {
668 // @@@ Todo: Client side geocoding
669 if (location_has_coordinates($loc)) {
670 $count++;
671 $markername = isset($markertypes[$node->type]) ? $markertypes[$node->type] : 'drupal';
672 if (module_exists('gmap_taxonomy')) {
673 $t = db_result(db_query('SELECT marker FROM {gmap_taxonomy_node} WHERE vid = %d', $node->vid));
674 if (!empty($t)) {
675 $markername = $t;
676 }
677 }
678
679 $markertitle = $node->title;
680 if (!empty($loc['name'])) {
681 $markertitle = $loc['name'];
682 }
683
684 $markers[] = array(
685 'latitude' => $loc['latitude'],
686 'longitude' => $loc['longitude'],
687 'markername' => $markername,
688 'offset' => $count-1,
689 'opts' => array('title' => $markertitle),
690 );
691 }
692 }
693 if (!empty($markers)) {
694 $macro = variable_get('gmap_location_block_macro_'. $node->type, '');
695 if (empty($macro)) {
696 $macro = variable_get('gmap_location_block_macro', '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]');
697 }
698 $map = gmap_parse_macro($macro);
699 $map['latitude'] = $markers[0]['latitude'];
700 $map['longitude'] = $markers[0]['longitude'];
701 $map['markers'] = $markers;
702 $block['subject'] = t('Location');
703 $block['content'] = theme('gmap', array('#settings' => $map)); // @@@ Better theme
704 }
705 }
706 return $block;
707 }
708
709 function gmap_location_author_block_view($nid) {
710 $block = array();
711 $node = node_load($nid);
712 if (in_array($node->type, variable_get('gmap_location_author_block_types', array()))) {
713 $markername = variable_get('gmap_location_author_block_marker', 'drupal');
714 $author = user_load(array('uid' => $node->uid));
715 $markers = array();
716 $count = 0;
717 foreach ($author->locations as $loc) {
718 // @@@ Todo: Client side geocoding
719 if ($loc['latitude'] || $loc['longitude']) {
720 $count++;
721 }
722
723 $markertitle = $author->name;
724 if (!empty($loc['name'])) {
725 $markertitle = $loc['name'];
726 }
727
728 $markers[] = array(
729 'latitude' => $loc['latitude'],
730 'longitude' => $loc['longitude'],
731 'markername' => $markername,
732 'offset' => $count-1,
733 'opts' => array('title' => $markertitle),
734 );
735 }
736 if (!empty($markers)) {
737 $macro = variable_get('gmap_location_author_block_macro', '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]');
738 $map = gmap_parse_macro($macro);
739 $map['latitude'] = $markers[0]['latitude'];
740 $map['longitude'] = $markers[0]['longitude'];
741 $map['markers'] = $markers;
742 $block['subject'] = t('Author Location');
743 $block['content'] = theme('gmap', array('#settings' => $map)); // @@@ Better theme
744 }
745 }
746 return $block;
747 }
748
749 /**
750 * Default theme for image nodes.
751 * @@@ Todo: Move to a tpl.
752 */
753 function theme_gmap_location_infowindow_node__image($node) {
754 $out = '<a href="'. url('node/'. $node->nid) .'">'. check_plain($node->title) .'</a> <br>';
755 $out .= image_display($node, 'thumbnail');
756 return $out;
757 }
758
759 // @@@ This is not thoroughly tested for 5.x yet!
760 // @@@ Or 6.x for that matter!
761 /**
762 * Theme an Organic Groups node info window.
763 */
764 function theme_gmap_location_infowindow_node__og($node, $opt) {
765 if (is_numeric($opt) && $account = user_load(array('uid' => $opt))) {
766 $output = theme('user_picture', $account);
767 $output .= theme('username', $account);
768 echo $output;
769 exit();
770 }
771 }
772
773 // @@@ This is completely wrong.
774 /**
775 * Theme a node info window.
776 * @ingroup themable
777 */
778 function theme_gmap_location_infowindow_node($node) {
779 // Allow a module (where the module name matches the node type name)
780 // to define a custom display for the google map label.
781 // For this to work with flexinode defined data types,
782 // a module called 'flexinode_#.module' in your site's module
783 // directory and add theme_hook_gmapnodelabel($node, $location) to it.
784 // Be sure to enable your 'flexinode_#.module'.
785 return '<div class="gmapnodelabel gmapnodelabel-'. form_clean_id($node->type) .
786 '">'. strtr(node_view($node, TRUE, FALSE, FALSE), "'\n\r", '" ') .'</div>'; // make sure it all goes on one line.
787 }
788
789 /**
790 * Default theme for user infowindows.
791 */
792 function theme_gmap_location_infowindow_user($account) {
793 $returntxt = theme('user_picture', $account);
794 $returntxt .= theme('username', $account);
795 return $returntxt;
796 }
797
798 /**
799 * Implementation of hook_node_type().
800 */
801 function gmap_location_node_type($op, $info) {
802 $temp = variable_get('gmap_node_markers', array());
803 switch ($op) {
804 case 'delete':
805 unset($temp[$info->type]);
806 break;
807 case 'insert':
808 $temp[$info->type] = 'drupal';
809 break;
810 case 'update':
811 if (!empty($info->old_type) && $info->old_type != $info->type) {
812 $temp[$info->type] = $temp[$info->old_type];
813 unset($temp[$info->old_type]);
814 }
815 break;
816 }
817 variable_set('gmap_node_markers', $temp);
818 }

  ViewVC Help
Powered by ViewVC 1.1.2