If an item is being processed with the Node processor and has no title, the processor will take the first 3 words of the body and use them as the node title.
But if the body starts with an image, the node title ends up being html markup gibberish.
The magic happen in the feedapi_node.module file on line 287 (1.3)
$node->title = $feed_item->title;
if (empty($node->title) && !empty($feed_item->description)) {
// Explode to words and use the first 3 words.
$words = preg_split("/[\s,]+/", $feed_item->description);
$node->title = $words[0] .' '. $words[1] .' '. $words[2];
}
An easy solution would be to add a strip_tags function to $feed_item->description
It would look like this
$node->title = $feed_item->title;
if (empty($node->title) && !empty($feed_item->description)) {
// Explode to words and use the first 3 words.
$words = preg_split("/[\s,]+/", strip_tags($feed_item->description));
$node->title = $words[0] .' '. $words[1] .' '. $words[2];
}
Comments
Comment #1
zis commentedAfter 2 days of testing it seems to be working fine.
Anyone else can confirm?
Comment #2
Antinoo commentedI agree to submit your piece of code.
I noticed nodes from a feed were taken with an ugly title, made of html tags.
Initially, I thought the feed was giving me an html title.
Then, I realized it was giving me no title at all.
This is the code I'm running at the moment:
It's quite the same of your one.
I've used filter_xss with an empty array as 2nd arg. But strip_tags should be a better choice, I think.
Ciao, Giovanni
Comment #3
Antinoo commentedbetter title, I was missing this issue
Comment #4
zis commentedStrip tags is more efficient, filter_xss is overkill. But a filter_xss should be added in the first instance (if a title already exists)
Comment #5
Antinoo commentedI think
filter_xss($string, array())andstrip_tags($string)would return the same string.Hence, I can't see why we should use filter_xss() for the title, if strip_tags() is more efficient. ;)
It would be useful to have an option to change the 2nd argument passed to filter_xss(), which lists the allowed tags (I want no tags in the title, that's why I used an empty array).
Anyway, I think all the filtering code should be put in the hook_filter().
Comment #6
aron novakA different method (but strip tags) is committed into both parsers. (see the parser files, this functionality is moved!)
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.