Index: plugins/FeedsParser.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsParser.inc,v retrieving revision 1.17 diff -u -r1.17 FeedsParser.inc --- plugins/FeedsParser.inc 28 Jul 2010 21:12:43 -0000 1.17 +++ plugins/FeedsParser.inc 23 Aug 2010 20:20:49 -0000 @@ -18,6 +18,63 @@ */ public abstract function parse(FeedsImportBatch $batch, FeedsSource $source); + public function inherit(FeedsImportBatch $batch, FeedsSource $source) { + if(!($source->feed_nid)) { + return; + } + $feed_node = node_load($source->feed_nid); + $inheritors = $this->getInheritorSources(); + + $items = array(); + while($item = $batch->shiftItem()) { + foreach ($inheritors as $inheritor) { + if ($inheritor['callback'] && function_exists($inheritor['callback'])) { + $inheritor['callback']($item, $feed_node); + } + } + $items[] = $item; + } + $batch->setItems($items); + } + + protected function getInheritorSources() { + $inheritors = array(); + if (module_exists('og')) { + $inheritors['inherit_og_groups'] = array( + 'name' => t('Feed Node: organic group(s)'), + 'description' => t('Organic group settings from feed node.'), + 'callback' => 'feeds_inherit_og', + ); + } + if (module_exists('locale')) { + $inheritors['inherit_language'] = array( + 'name' => t('Feed Node: language'), + 'description' => t('Language settings from feed node.'), + 'callback' => 'feeds_inherit_translation', + ); + } + if (module_exists('taxonomy')) { + //options to inherit terms for all vocabs I have + $vocabs = taxonomy_get_vocabularies(feeds_importer($this->id)->config['content_type']); + $callback = 'feeds_inherit_taxonomy'; + foreach($vocabs as $vid => $voc) { + $inheritors['inherit_terms_'. $vid] = array( + 'name' => t('Feed Node: Term names: '. $voc->name), + 'description' => t('Taxonomy terms from feed node in given vocabulary.'), + 'callback' => $callback, + ); + $callback = ''; + } + } + $inheritors['inherit_uid'] = array( + 'name' => t('Feed Node: uid'), + 'description' => t('The feed node author uid.'), + 'callback' => 'feeds_inherit_user', + ); + drupal_alter('feeds_parser_inheritors', $inheritors); + return $inheritors; + } + /** * Clear all caches for results for given source. * @@ -47,7 +104,7 @@ * @endcode */ public function getMappingSources() { - return FALSE; + return $this->getInheritorSources(); } /** @@ -523,3 +580,45 @@ return array('year' => $this->format('Y'), 'month' => $this->format('m'), 'day' => $this->format('d'), 'hour' => $this->format('H'), 'minute' => $this->format('i'), 'second' => $this->format('s'), 'zone' => $this->format('e')); } } + + + /** + * @defgroup inheritors Inheritors for Feeds node processor. + * @{ + */ + +/** +* Inherit OG properties. +*/ +function feeds_inherit_og(&$item, $feed_node) { + if (in_array($feed_node->type, og_get_types('group'))) { + $gid = $feed_node->nid; + $item['inherit_og_groups'] = array($gid => $gid); + } else { + $item['inherit_og_groups'] = $feed_node->og_groups; + } +} + +/** + * Inherit translation properties. + */ +function feeds_inherit_translation(&$item, $feed_node) { + $item['inherit_language'] = $feed_node->language; +} + +/** + * Inherit taxonomy properties. + */ +function feeds_inherit_taxonomy(&$item, $feed_node) { + $terms = taxonomy_node_get_terms($feed_node); + foreach($terms as $tid => $term) { + $item['inherit_terms_'. $term->vid][] = $term->name; + } +} + +/** + * Inherit user properties. +*/ +function feeds_inherit_user(&$item, $feed_node) { + $item['inherit_uid'] = $feed_node->uid; +} Index: plugins/FeedsSyndicationParser.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsSyndicationParser.inc,v retrieving revision 1.14 diff -u -r1.14 FeedsSyndicationParser.inc --- plugins/FeedsSyndicationParser.inc 29 Mar 2010 02:55:50 -0000 1.14 +++ plugins/FeedsSyndicationParser.inc 23 Aug 2010 20:20:49 -0000 @@ -20,6 +20,7 @@ if (is_array($result['items'])) { $batch->setItems($result['items']); } + $this->inherit($batch, $source); } /** @@ -59,6 +60,6 @@ 'name' => t('Categories'), 'description' => t('An array of categories that have been assigned to the feed item.'), ), - ); + ) + parent::getMappingSources(); } } Index: plugins/FeedsSimplePieParser.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsSimplePieParser.inc,v retrieving revision 1.12 diff -u -r1.12 FeedsSimplePieParser.inc --- plugins/FeedsSimplePieParser.inc 29 Mar 2010 02:55:50 -0000 1.12 +++ plugins/FeedsSimplePieParser.inc 23 Aug 2010 20:20:49 -0000 @@ -119,6 +119,7 @@ } // Release parser. unset($parser); + $this->inherit($batch, $source); } /** @@ -183,7 +184,7 @@ 'name' => t('Enclosures'), 'description' => t('An array of enclosures attached to the feed item.'), ), - ); + ) + parent::getMappingSources(); } /**