I'm just starting to learn how to use FeedAPI. I'm having trouble figuring out how to change what goes into node body from the full text of the field content:encoded to the shorter description field often present in feeds. I don't want to accidentally cause any copyright violations by using full text feeds. Is their a simple way to either use the Description field or restrict the length of item contents?

Comments

garamvideos’s picture

I have a similar concern, any way to restrict length of node body to say x# of words would be great.

dankey’s picture

I am also concerned, as we can do?

xamount’s picture

I'm looking to do the opposite actually. I want the feed node body to contain the full body of the feed. how do i do this?

NeuZeitgeist’s picture

I'm also looking for sollution. I want to show on my site only teasers or titles of articles but I can't find how to configure feedapi to do it.

mrkistic’s picture

I was looking to do something similar myself. I discovered that unfortunately with FeedAPI using the SimplePie parser, if you have both 'description' and 'content:encoded' tags in your feed, FeedAPI will only store the content:encoded tag and discard the description. It then creates a teaser by shortening the full content of the node. What I wanted was to store the description as the node teaser and user the content:encoded tag as the full content.

I should point out that this is my first time using Drupal, I had a quick job I needed to do with an incredibly short deadline and I've found that the documentation on how to customise Drupal has so far seemed to rely on me already having an intimate knowledge of the entire system before I can find the exact hook I need to use :( Also, I didn't want to write a new module, so...

I have modified two core files in the FeedAPI module to solve my problem. In parser_simplepie.module I have added the following line to the function _parser_simplepie_feedapi_parse:

$curr_item->simple_description = $simplepie_item->get_description(true);

directly below where $curr_item->description is set. This gets only the 'description' tag from the feed item and stores it into a 'simple_description' property.

I've also changed the line (260) in feedapi_node.module in the function _feedapi_node_save where the teaser property is set:

$node->teaser = !empty($feed_item->simple_description)?$feed_item->simple_description:node_teaser($feed_item->description);

This now takes the original description tag from the feed item via our simple_description property and stores it as the teaser. If the simple_description property is empty (i.e. no 'description' tag was found), it reverts to its original behaviour of creating a teaser from the body content.

Is there a better way to do this other than writing a whole new module? Seems like overkill...

Personally, I think it is wrong that the description is overwritten with the content when in fact the feed writer has clearly decided that there is a description tag and it is different to the content, making it essentially a summary of the whole post. While the various states of RSS specs don't clearly define it as such, the case is they can be different and the parser should treat them as such and provide both items for the site maintainer to do as they please. I might submit it as an issue.

Not sure if that helped anyone other than me ;) In terms of displaying a shorter version of the body as a teaser, look into the node_teaser function, it returns the passed text parameter into a shortened teaser version.

summit’s picture

Component: Code » Code feedapi (core module)

Subscribing, looking for a feedapi-core solution.
Greetings,
Martijn

barkam’s picture

subscribing

boris mann’s picture

Category: support » feature

I'll make this a feature request. It would be great to truncate on input.

FYI, on Drupal 5, the common parser will not be able to correctly parse WordPress RSS2 feeds -- it will always grab the "description" field, which is an auto-generated teaser.

The full content is in content:encoded. Install the simple pie parser if you want the full text.

This might be consider a feature :P -- if you only use the common parser on WordPress feeds, you'll only get that partial content.

nmridul’s picture

Here is what I did and it works...

In the file feedapi/feedapi_node/feedapi_node.module , there is a function _feedapi_node_save. It is somewhere around Line 265 and could vary according to the version you have.

If you go down, you can see the lines where $node->body and $node->teaser are given values.

  $node->body = $feed_item->description; 
  $node->teaser =node_teaser($feed_item->description);  

Modify those lines to

  $node->body = truncate_utf8(strip_tags($feed_item->description), 100, TRUE, TRUE); 
  $node->teaser = truncate_utf8(strip_tags($feed_item->description), 100, TRUE, TRUE);

You can change the value 100 to the length of your choice.

I Feel, this value 100 should be something that feed api should make as configurable.

doompal’s picture

I've just done something similar, thanks. Now I hope to find out if this can be done without editing an existing module.

I added the lines:
$node->abstract = truncate_utf8(strip_tags($feed_item->description), 100, TRUE, TRUE);
$node->publish_date = time();
$node->expiration_date = time() ;

and created a node of type announcement (contributed module). These nodes are quite small, perhaps suitable for the original poster?

doompal’s picture

Following a visit to this page http://2bits.com/articles/changing-your-rss-feed-to-include-image-node-t... I created a custom module (name not important) and moved my code there. The point is that function custom_nodeapi(&$node, $op, $teaser, $page) will get called for all nodes, as will function foo_nodeapi(&$node, $op, $teaser, $page) etc. Great for customisation but you can seriously foul up.

aron novak’s picture

I'd like to ask to do not hack feedapi to achieve this.
This feature can be implemented elegantly via the nodeapi.
The approach of doompal is good.

aron novak’s picture

Status: Active » Closed (fixed)