You are here

function exif_location_nodeapi in Exif 6

implementation of hook_nodeapi

Parameters

stdClass $node:

string $op:

string $a3:

string $a4:

File

exif_location/exif_location.module, line 10

Code

function exif_location_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'update':

      //we are only going to update if we have said so
      if (!variable_get('exif_update', TRUE)) {
        break;
      }
    case 'insert':
      $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;
  }
}