Feeds w/ constant values

Events happening in the community are now at Drupal community events on www.drupal.org.
bee2b's picture

I have about 20 unique feeds currently running on my site. I would love the ability to map the feed name into a CCK field so I know the node source. It does not appear this is possible. Would this be a wanted feature in the future? The only solution I currently see is to create a unique content type for each feed. Any other ways to solve my problem???

Comments

Same problem here...

mottolini's picture

I tried to dig a little bit on this, but so far I've been unsuccessful.
The way to go, I think, is to subclass the fetcher and the parser (maybe the parser only) and find a way to add a new mappable field that the processor can later use to write that value in the node it creates.
So, I think the steps are:

1) modify the feed content type to add more fields that you want to user later
2) subclass Parser and Fetcher to read those fields from the original feed node (or store those data in feed_source table at the creation of the feed) and pass them along
3) maps accordingly to your own need fields to the destination node, so that the Processor can do its job

Is there any easier way to do it?
I'm really surprised that nobody had this problem in the past and solved it creating a module, a patch or a snippet...

Quick & dirty solution

mottolini's picture

I found a quick and dirty (and easy too) solution for the problem. I made two modifications at the FeedsSimplePieParser.inc file located in feeds/plugins. SimplePie already returns more mappable fields than the standard CSS parser, so I thought it was better to modify it instead of the standard one. I eventually submit a patch in the future to add this feature to SimplePie parser.
Here are the two snippets that you need to add:

Modify the function getMappingSources, near the end (or even in the middle), to add three new mappable fields

      'parent:nid' => array(
        'name' => t('Feed node: nid'),
        'description' => t('The nid of the feed.'),
      ),
      'parent:title' => array(
        'name' => t('Feed node: Title'),
        'description' => t('The title of the feed.'),
      ),
      'parent:link' => array(
        'name' => t('Feed node: link to home'),
        'description' => t('The home link of the feed.'),
      ),

Modifiy the function parse near the end, between the lines $item['raw'] = $simplepie_item->data; and $batch->items[] = $item;

      $item['parent:nid'] = $batch->feed_nid;
      $item['parent:title'] = $batch->title;
      $item['parent:link'] = $batch->link;

After that, clear the cache and try to map these new fields using Simple Pie Parser.

RSS & Aggregation

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: