aboutsummaryrefslogtreecommitdiff
path: root/exif_location/exif_location.module
blob: f0d509366a866d49ca30cada6de62e7d676d5d02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

/*
 * Hook nodeapi.
 */
 
function exif_location_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch($op) {
    case 'presave':
      $lid = 0;
      /* Go get the location from EXIF fields */
      if (is_array($node->field_gps_gpslongitude) &&
          is_array($node->field_gps_gpslatitude)) {
        $longitude = $node->field_gps_gpslongitude[0]['value'];
        $latitude = $node->field_gps_gpslatitude[0]['value'];
        if (is_array($node->locations) && array_key_exists($lid, $node->locations)) {
          /*
           * We cannot just overwrite existing locations or they will
           * be created and not ammended by the loction module.
           */
          $node->locations[$lid]['longitude'] = $longitude;
          $node->locations[$lid]['latitude'] = $latitude;
        } else {
          $node->locations[$lid] =
            array(
              'longitude' => $longitude,
              'latitude,' => $latitude,
            );
        }
        $lid++;

        /* Remove any other locations */
        while (array_key_exists($lid, $node->locations)) {
          $node->locations[$lid]['longitude'] = '';
          $node->locations[$lid]['latitude'] = '';
          $lid++;
        }
      }
      break;
  }
}

/*
 * Hook form_alter.
 */

function exif_location_form_alter(&$form, $form_state, $form_id) {
  /* Comment out the return below to enable this */
  return;
  /* Remove the location element from the node form */
  if (isset($form['#node']) &&
      $form['#node']->type == 'image' &&
      $form_id == $form['#node']->type .'_node_form') {
    $form['locations']['#access'] = FALSE;
  }
}

?>