View source
<?php
define('FEEDS_ATOM_TOMBSTONE_NAMESPACE', 'http://purl.org/atompub/tombstones/1.0');
function feeds_atom_ctools_plugin_api($owner, $api) {
if ($owner == 'feeds' && $api == 'plugins') {
return array(
'version' => 1,
);
}
}
function feeds_atom_feeds_plugins() {
$path = drupal_get_path('module', 'feeds_atom') . '/plugins';
$info['FeedsAtomRDFParser'] = array(
'name' => 'FeedsAtomRDF parser',
'description' => 'Parse data in Atom RDF format.',
'handler' => array(
'parent' => 'FeedsParser',
'class' => 'FeedsAtomRDFParser',
'file' => 'FeedsAtomRDFParser.inc',
'path' => $path,
),
);
$info['FeedsAtomRDFProcessor'] = array(
'name' => 'FeedsAtomRDF Processing Stage',
'description' => 'Process my stuff.',
'help' => 'Processing stage of parsed data.',
'handler' => array(
'parent' => 'FeedsNodeProcessor',
'class' => 'FeedsAtomRDFProcessor',
'file' => 'FeedsAtomRDFProcessor.inc',
'path' => $path,
),
);
return $info;
}
function taxonomy_feeds_atom_rdf_map_alter(&$target_item, $source_item) {
if (empty($source_item['rdf']['taxonomy']) || !is_array($source_item['rdf']['taxonomy'])) {
return;
}
$target_item->taxonomy = array();
foreach ($source_item['rdf']['taxonomy'] as $source_term) {
$vid = NULL;
$tid = NULL;
if (!empty($source_term['vocabulary'])) {
if (module_exists('features')) {
$machine_name = !empty($source_term['machine']) ? $source_term['machine'] : $source_term['vocabulary'];
if (strpos($machine_name, 'features_') !== 0) {
$machine_name = 'features_' . $machine_name;
}
$vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module = '%s'", strtolower($machine_name)));
}
if (empty($vid)) {
$vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE lower(name) = '%s'", strtolower($source_term['vocabulary'])));
}
}
foreach (taxonomy_get_term_by_name($source_term['title']) as $term) {
if (empty($vid) || $vid == $term->vid) {
$tid = $term->tid;
}
}
if (empty($tid) && !empty($vid)) {
$new_term = array(
'vid' => $vid,
'name' => $source_term['title'],
'description' => $source_term['description'],
);
taxonomy_save_term($new_term);
$tid = $new_term['tid'];
}
if (!empty($tid)) {
$term = taxonomy_get_term($tid, TRUE);
$target_item->taxonomy[$term->tid] = $term;
}
}
}
function filefield_feeds_atom_rdf_map_alter(&$target_item, $source_item, FeedsSource $source) {
static $enclosures = array();
static $files = array();
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) {
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;
}
}
}
}
}
}
}
function feeds_atom_file_delete($file) {
db_query("DELETE FROM {feeds_atom_file_import} WHERE fid = %d", $file->fid);
}