summaryrefslogtreecommitdiffstats
path: root/opmlparser.php
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-01-27 04:15:53 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-01-27 04:15:53 +0100
commitae7393db3d99a7ac223ae917129cccd9f49888e3 (patch)
tree7f54b72b0d01c38afd1378365a67e4f192922423 /opmlparser.php
parent483784caa38bd6131405ac474347a215584e30a5 (diff)
merged the angularjs branch
Diffstat (limited to 'opmlparser.php')
-rw-r--r--opmlparser.php102
1 files changed, 0 insertions, 102 deletions
diff --git a/opmlparser.php b/opmlparser.php
deleted file mode 100644
index 2920c84c3..000000000
--- a/opmlparser.php
+++ /dev/null
@@ -1,102 +0,0 @@
-<?php
-
-/**
-* ownCloud - News app
-*
-* @author Alessandro Cosentino
-* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
-*
-* This file is licensed under the Affero General Public License version 3 or later.
-* See the COPYING-README file
-*
-*/
-
-class OPMLParser {
-
- private $title;
- private $body;
- private $data;
- private $count;
-
- private function __construct() {
- $this->data = array();
- $this->count = 0;
- }
-
- /**
- * @brief
- * @returns the title element from the head section of the OPML file
- */
- public function getTitle() {
- return $this->title;
- }
-
- /**
- * @brief
- * @returns the number of feeds found in the OPML file
- */
- public function getData() {
- return $this->data;
- }
-
- /**
- * @brief
- * @returns the number of feeds found in the file
- */
- public function getCount() {
- return $this->count;
- }
-
- /**
- * @brief This is used as a utility private function by the method OPMLParser::parse
- */
- private static function parseFolder($rawfolder, &$count) {
- $list = array();
- foreach ($rawfolder->outline as $rawcollection) {
- if ($rawcollection['type'] == 'rss') {
- $collection = self::parseFeed($rawcollection);
- $count++;
- }
- else {
- $name = (string)$rawcollection['text'];
- $children = self::parseFolder($rawcollection, $count);
- $collection = new OCA\News\Folder($name);
- $collection->addChildren($children);
- }
- if ($collection !== null) {
- $list[] = $collection;
- }
- }
- return $list;
- }
-
- private static function parseFeed($rawfeed) {
- $url = (string)$rawfeed['xmlUrl'];
- $title = (string)$rawfeed['title'];
-
- $feed = new OCA\News\Feed($url, $title);
- return $feed;
- }
-
- /**
- * @brief
- * @param $raw the XML string to be parsed
- * @return an object of the OPMLParser class itself
- * or null if the parsing failed
- * @throws
- */
- public static function parse($raw) {
- $parsed = new OPMLParser();
-
- $xml_parser = new SimpleXMLElement($raw, LIBXML_NOERROR);
- $parsed->title = (string)$xml_parser->head->title;
- $parsed->body = $xml_parser->body;
-
- if ($parsed->body != null) {
- $parsed->data = self::parseFolder($parsed->body, $parsed->count);
- return $parsed;
- } else {
- return null;
- }
- }
-} \ No newline at end of file