summaryrefslogtreecommitdiffstats
path: root/utility
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-22 18:24:31 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-22 18:24:31 +0200
commitdf18314b32b05f10720936831ed43573e1792ae6 (patch)
treea2b8e28e165727e7a88d7ac3529f64d5f6b938e2 /utility
parent366c1b15545b4da69bc8e236ba4350c28ad24e77 (diff)
added import from google reader, fix #80
Diffstat (limited to 'utility')
-rw-r--r--utility/importparser.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/utility/importparser.php b/utility/importparser.php
new file mode 100644
index 000000000..acf52381c
--- /dev/null
+++ b/utility/importparser.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Cosentino
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Utility;
+
+use \OCA\AppFramework\Utility\TimeFactory;
+
+use \OCA\News\Db\Item;
+
+
+class ImportParser {
+
+ private $timeFactory;
+
+ public function __construct(TimeFactory $timeFactory) {
+ $this->timeFactor = $timeFactory;
+ }
+
+ public function parse($json){
+ $items = array();
+
+ if(array_key_exists('items', $json)) {
+ foreach($json['items'] as $entry) {
+ $item = new Item();
+ $id = $entry['id'];
+ $item->setGuid($id);
+ $item->setGuidHash(md5($id));
+ $item->setTitle($entry['title']);
+ $item->setPubDate($entry['published']);
+ if(array_key_exists('summary', $entry)) {
+ $item->setBody($entry['summary']['content']);
+ } elseif(array_key_exists('content', $entry)) {
+ $item->setBody($entry['content']['content']);
+ }
+
+ $item->setUrl($entry['alternate'][0]['href']);
+ $item->setStatus(0);
+ $item->setStarred();
+ $item->setUnread();
+
+ array_push($items, $item);
+ }
+ }
+
+ return $items;
+ }
+
+}