summaryrefslogtreecommitdiffstats
path: root/utility
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-22 18:38:29 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-22 18:38:29 +0200
commit830398682f93ea76a35d542ac65f944fe5aa9f38 (patch)
treea7110ea259aaaa8f135b1dc1818a441c8967a49c /utility
parentd72ddb277f2d03ddd9700dd640350dcebc6b1cc8 (diff)
dont add items with no title or guid or url and handle non existent pubdate
Diffstat (limited to 'utility')
-rw-r--r--utility/importparser.php28
1 files changed, 22 insertions, 6 deletions
diff --git a/utility/importparser.php b/utility/importparser.php
index acf52381c..4babefda5 100644
--- a/utility/importparser.php
+++ b/utility/importparser.php
@@ -35,7 +35,7 @@ class ImportParser {
private $timeFactory;
public function __construct(TimeFactory $timeFactory) {
- $this->timeFactor = $timeFactory;
+ $this->timeFactory = $timeFactory;
}
public function parse($json){
@@ -43,22 +43,38 @@ class ImportParser {
if(array_key_exists('items', $json)) {
foreach($json['items'] as $entry) {
+ // we require title, guid and url
+ if(!array_key_exists('title', $entry)
+ || !array_key_exists('id', $entry)
+ || !array_key_exists('alternate', $entry)
+ || !count($entry['alternate']) > 0
+ || !array_key_exists('href', $entry['alternate'][0])) {
+ continue;
+ }
+
$item = new Item();
+
$id = $entry['id'];
$item->setGuid($id);
$item->setGuidHash(md5($id));
$item->setTitle($entry['title']);
- $item->setPubDate($entry['published']);
+ $item->setUrl($entry['alternate'][0]['href']);
+ $item->setStatus(0);
+ $item->setStarred();
+ $item->setUnread();
+
+ if(array_key_exists('published', $entry)) {
+ $item->setPubDate($entry['published']);
+ } else {
+ $item->setPubDate($this->timeFactory->getTime());
+ }
+
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);
}