You are here

function filefield_feeds_atom_rdf_map_alter in Feeds Atom 6

Implementation of hook_feeds_atom_rdf_map_alter().

File

./feeds_atom.module, line 127
Contains the main functionality for feeds_atom.

Code

function filefield_feeds_atom_rdf_map_alter(&$target_item, $source_item, FeedsSource $source) {

  // Use static variables in combination with the FeedsEnclosureUnique class
  // to ensure that imported files are not downloaded more than once.
  static $enclosures = array();
  static $files = array();

  // For any filefield in the incoming data, check to see if a full URL to the file
  // is specified.  If so, import it outright.
  foreach ($source_item['rdf'] as $field_name => $field) {
    $target_field =& $target_item->{$field_name};
    $field_info = content_fields($field_name, $target_item->type);
    if (!empty($field['#attributes']['type']) && $field['#attributes']['type'] == 'filefield') {
      foreach ($field as $i => $instance) {

        // This is only the case if the field in question is a filefield and
        // not the #attributes element.
        if (!empty($instance['full_url'])) {
          if (empty($enclosures[$instance['full_url']])) {
            $enclosures[$instance['full_url']] = new FeedsEnclosureUnique($instance['full_url'], $instance['filemime']);
            $files[$instance['full_url']] = $enclosures[$instance['full_url']]
              ->getFile();
          }
          if ($files[$instance['full_url']]) {
            $target_dir = filefield_widget_file_path($field_info, user_load($target_item->uid));
            if ($info = $enclosures[$instance['full_url']]
              ->saveTo($target_dir)) {
              $info['list'] = array();
              $info['data'] = array(
                'description' => '',
              );
              if ($field_info['list_field']) {
                $info['list'] = $field_info['list_default'];
              }
              $target_field[$i] = $info;
            }
          }
        }
      }
    }
  }
}