function _feedapi_import_opml_process in FeedAPI 5
Imports from OPML XML file
1 call to _feedapi_import_opml_process()
- feedapi_import_feeds_form_submit in ./
feedapi.module - Handle the submission of the OPML import form
File
- ./
feedapi.module, line 1421 - Handle the submodules (for feed and item processing) Provide a basic management of feeds
Code
function _feedapi_import_opml_process($opml, $args = array()) {
$feeds = array();
$count = 0;
$parser = drupal_xml_parser_create($opml);
//Some OPML Files don't have the xml tag, which causes parsing to fail. Hence, using the appended version as a fallback parse
if (xml_parse_into_struct($parser, $opml, $vals, $index) || xml_parse_into_struct($parser, '<?xml version="1.0"?>' . $opml, $vals, $index)) {
foreach ($vals as $entry) {
if ($entry['tag'] == 'OUTLINE') {
$feeds[] = $entry['attributes'];
}
}
foreach ($feeds as $feed) {
if (strlen($feed['XMLURL']) > 1) {
// check if feed url is already in the list
$dupe = db_result(db_query("SELECT nid FROM {feedapi} WHERE url = '%s'", $feed['XMLURL']));
// If the feed is not already in the list, add it
if ($dupe === FALSE) {
// Generate a feed structure
$node = new stdClass();
$node->type = $args['feed_type'];
if ($args['override_title']) {
$node->title = $feed['TITLE'];
}
if ($args['override_body']) {
$node->body = $feed['TEXT'];
}
$node->og_groups = $args['og_groups'];
$node->og_public = (int) $args['og_public'];
$node = feedapi_create_node($node, $feed['XMLURL']);
$count++;
}
}
}
}
return $count;
}