I'm writing a module to remove some text from feed items. From this (http://groups.drupal.org/node/18980) it seems the correct pattern is to write a processor that modifies the $feed_item and place that before the feedapi_node processor. I've done that with the following code yet it isn't working. The regex is working yet the new node is still being created with the removed text included.
My question then is my code wrong or is the g.d.o wiki page wrong? This issue (http://drupal.org/node/378136) suggests that the wiki page is wrong. If so, what's the recommended way for chopping off text from each new feed item?
My code:
/**
* Implementation of hook_feedapi_item(). Timestamp of each feed_item
* will be parsed from the URL instead of being taken from the timestamp field.
*/
function drupal_cvs_feedapi_filter_feedapi_item($op, $feed_item, $feed_nid) {
switch ($op) {
case 'type':
// Return
return array("XML feed");
case 'save':
// Remove files div.
$feed_item = func_get_arg(1);
$html_string = $feed_item->options->raw['child']['']['description'][0]['data'];
$html_string = preg_replace('/<div\sclass="files".*<\/div>/', '', $html_string);
$feed_item->options->raw['child']['']['description'][0]['data'] = $html_string;
return $feed_item;
case 'update':
break;
case 'delete':
break;
case 'load':
break;
case 'unique':
// Simplest is to make this return true so that we only have to implement the 'save' operation
// and not the 'update' operation.
return true;
case 'fetch':
break;
case 'expire':
break;
case 'purge':
break;
default:
if (function_exists('_feedapi_node_'. $op)) {
$args = array_slice(func_get_args(), 1);
return call_user_func_array('feedapi_node'. $op, $args);
}
}
}
Comments
Comment #1
aron novak"chopping off text from each new feed item" - what about using nodeapi() ? At least only if you use node processor.