diff options
author | Alessandro Cosentino <cosenal@gmail.com> | 2012-07-30 14:08:36 -0400 |
---|---|---|
committer | Alessandro Cosentino <cosenal@gmail.com> | 2012-07-30 14:08:36 -0400 |
commit | fd5b815e587ccc3642995346cd03eca4e0a0707f (patch) | |
tree | 2cc9bdf3de5e45b8f23e96673f4d8625651f81df /opmlparser.php | |
parent | a5438863a4e88fb5c9e166e8810f493a1feb2cf0 (diff) |
opml parser completed; still needs testing
Diffstat (limited to 'opmlparser.php')
-rw-r--r-- | opmlparser.php | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/opmlparser.php b/opmlparser.php index 4918b87b1..cde55e2dd 100644 --- a/opmlparser.php +++ b/opmlparser.php @@ -15,13 +15,11 @@ class OPMLParser { private $raw; private $body; - private $data; private $title; private $error; public function __construct($raw) { $this->raw = $raw; - $this->data = array(); try { $xml_parser = new SimpleXMLElement($this->raw, LIBXML_NOERROR); $this->title = (string)$xml_parser->head->title; @@ -34,12 +32,38 @@ class OPMLParser { } public function parse(){ - + return self::parseFolder($this->body); + } + + private function parseFolder($rawfolder) { + $list = array(); + foreach ($rawfolder->outline as $rawcollection) { + if ($rawcollection['type'] == 'rss') { + $collection = self::parseFeed($rawcollection); + } + else { + $name = (string)$rawcollection['text']; + $children = self::parseFolder($rawcollection); + $collection = new OC_News_Folder($name); + $collection->addChildren($children); + } + if ($collection !== null) { + $list[] = $collection; + } + } + return $list; } - //TODO: implement an iterator to get data in a fancier way - public function getData() { - return $this->data; + private function parseFeed($rawfeed) { + $url = (string)$rawfeed['xmlUrl']; + + $feed = OC_News_Utils::fetch($url); + if ($feed !== null) { + $title = $rawfeed['title']; + $feed->setTitle($title); + } + + return $feed; } public function getTitle() { |