You are here

function _exif_node_insert_update in Exif 7

Main entrypoint of the module.

Parameters

$object_type:

$object:

1 call to _exif_node_insert_update()
exif_field_attach_presave in ./exif.module
implementation of hook_field_attach_presave.

File

./exif.module, line 80

Code

function _exif_node_insert_update($object_type, $object, $update = TRUE) {
  $type = $object->type;
  $fields = field_info_instances($object_type, $type);
  if (_exif_check_for_exif_data($type)) {
    $exif = _exif_get_class();
    $ar_exif_fields = _exif_filter_fields_on_widgets($fields);
    $ar_exif_fields = $exif
      ->getMetadataFields($ar_exif_fields);
    if (!$update && property_exists($object, 'original')) {
      $original = $object->original;
      foreach ($ar_exif_fields as $drupal_field => $metadata_field_descriptor) {
        $field_name = $drupal_field;
        if (property_exists($object, $field_name) && property_exists($original, $field_name)) {
          $object->{$field_name} = $original->{$field_name};
        }
      }
    }
    else {
      $image_fields = _exif_get_image_fields($object_type, $object, $fields);
      $metadata_images_fields = _exif_get_image_fields_metadata($object_type, $object, $ar_exif_fields, $image_fields);
      foreach ($ar_exif_fields as $drupal_field => $metadata_field_descriptor) {
        $field_name = $drupal_field;
        $field_type = $fields[$field_name];
        $tmp = NULL;
        if (property_exists($object, $field_name)) {
          $tmp = $object->{$field_name};
        }
        $language = $metadata_field_descriptor['language'];
        if ($tmp == NULL) {
          $tmp = array(
            $language => array(),
          );
        }
        $key = $metadata_field_descriptor['metadata_field']['tag'];
        $section = $metadata_field_descriptor['metadata_field']['section'];
        if (array_key_exists($metadata_field_descriptor['image_field'], $metadata_images_fields)) {
          $values = array();
          foreach ($metadata_images_fields[$metadata_field_descriptor['image_field']] as $metadata_image_fields) {
            if (array_key_exists($section, $metadata_image_fields) && array_key_exists($key, $metadata_image_fields[$section])) {
              $value = $metadata_image_fields[$section][$key];
              if (is_string($value) && isset($metadata_field_descriptor['metadata_field_separator'])) {
                $subValues = explode($metadata_field_descriptor['metadata_field_separator'], $value);
                foreach ($subValues as $index => $subValue) {
                  $values[] = $subValue;
                }
              }
              else {
                $values[] = $value;
              }
            }
          }
          $j = 0;
          foreach ($values as $innerkey => $value) {

            //case for keywords
            if (is_array($value)) {
              foreach ($value as $subkey => $subvalue) {
                _exif_handle_field($j, $language, $field_type, $tmp, $section, $key, $subvalue);
                $j++;
              }

              //others
            }
            else {
              _exif_handle_field($j, $language, $field_type, $tmp, $section, $key, $value);
              $j++;
            }
          }
          $object->{$field_name} = $tmp;
        }
      }
    }
  }
}