function opml_parser_parse in Feeds 7.2
Same name and namespace in other branches
- 8.2 libraries/opml_parser.inc \opml_parser_parse()
- 6 libraries/opml_parser.inc \opml_parser_parse()
- 7 libraries/opml_parser.inc \opml_parser_parse()
Parse OPML file.
Parameters
$raw: File contents.
Return value
array An array of the parsed OPML file.
1 call to opml_parser_parse()
- FeedsOPMLParser::parse in plugins/
FeedsOPMLParser.inc - Implements FeedsParser::parse().
File
- libraries/
opml_parser.inc, line 17 - OPML Parser.
Code
function opml_parser_parse($raw) {
$feeds = $items = array();
$xml = @new SimpleXMLElement($raw);
$feeds['title'] = (string) current($xml
->xpath('//head/title'));
// @todo Make xpath case insensitive.
$outlines = $xml
->xpath('//outline[@xmlUrl]');
foreach ($outlines as $outline) {
$item = array();
foreach ($outline
->attributes() as $k => $v) {
if (in_array(strtolower($k), array(
'title',
'text',
'xmlurl',
))) {
$item[strtolower($k)] = (string) $v;
}
}
// If no title, forge it from text.
if (!isset($item['title']) && isset($item['text'])) {
if (strlen($item['text']) < 40) {
$item['title'] = $item['text'];
}
else {
$item['title'] = trim(substr($item['text'], 0, 30)) . ' ...';
}
}
if (isset($item['title']) && isset($item['xmlurl'])) {
$items[] = $item;
}
}
$feeds['items'] = $items;
return $feeds;
}