Selaa lähdekoodia

Import FeedBin (#2228)

* Import FeedBin

https://github.com/FreshRSS/FreshRSS/issues/2227
And more tolerant import

* Mute import fake feed + Changelog

* strtotime for published dates in string
Alexandre Alapetite 7 vuotta sitten
vanhempi
commit
7902d10b3a
3 muutettua tiedostoa jossa 54 lisäystä ja 11 poistoa
  1. 1 0
      CHANGELOG.md
  2. 49 10
      app/Controllers/importExportController.php
  3. 4 1
      app/Models/FeedDAO.php

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@
 * Features
 	* Include articles with custom labels during export [#2196](https://github.com/FreshRSS/FreshRSS/issues/2196)
 	* Export/import articles read/unread state [#2226](https://github.com/FreshRSS/FreshRSS/pull/2226)
+	* Import FeedBin, and more robust general import [#2228](https://github.com/FreshRSS/FreshRSS/pull/2228)
 * Bug fixing
 	* Fix missing HTTP `X-Forwarded-Prefix` in cookie path behind a reverse-proxy [#2201](https://github.com/FreshRSS/FreshRSS/pull/2201)
 * Deployment

+ 49 - 10
app/Controllers/importExportController.php

@@ -435,11 +435,10 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
 			}
 			return false;
 		}
+		$items = isset($article_object['items']) ? $article_object['items'] : $article_object;
 
 		$mark_as_read = FreshRSS_Context::$user_conf->mark_when['reception'] ? 1 : 0;
 
-		$google_compliant = strpos($article_object['id'], 'com.google') !== false;
-
 		$error = false;
 		$article_to_feed = array();
 
@@ -448,9 +447,23 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
 		$limits = FreshRSS_Context::$system_conf->limits;
 
 		// First, we check feeds of articles are in DB (and add them if needed).
-		foreach ($article_object['items'] as $item) {
-			$key = $google_compliant ? 'htmlUrl' : 'feedUrl';
-			$feed = new FreshRSS_Feed($item['origin'][$key]);
+		foreach ($items as $item) {
+			if (!isset($item['origin'])) {
+				$item['origin'] = array('title' => 'Import');
+			}
+			if (!empty($item['origin']['feedUrl'])) {
+				$feedUrl = $item['origin']['feedUrl'];
+			} elseif (!empty($item['origin']['streamId']) && strpos($item['origin']['streamId'], 'feed/') === 0) {
+				$feedUrl = substr($item['origin']['streamId'], 5);	//Google Reader
+				$item['origin']['feedUrl'] = $feedUrl;
+			} elseif (!empty($item['origin']['htmlUrl'])) {
+				$feedUrl = $item['origin']['htmlUrl'];
+			} else {
+				$feedUrl = 'http://import.localhost/import.xml';
+				$item['origin']['feedUrl'] = $feedUrl;
+				$item['origin']['disable'] = true;
+			}
+			$feed = new FreshRSS_Feed($feedUrl);
 			$feed = $this->feedDAO->searchByUrl($feed->url());
 
 			if ($feed == null) {
@@ -498,7 +511,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
 		// Then, articles are imported.
 		$newGuids = array();
 		$this->entryDAO->beginTransaction();
-		foreach ($article_object['items'] as $item) {
+		foreach ($items as $item) {
 			if (empty($article_to_feed[$item['id']])) {
 				// Related feed does not exist for this entry, do nothing.
 				continue;
@@ -508,7 +521,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
 			$author = isset($item['author']) ? $item['author'] : '';
 			$is_starred = false;
 			$is_read = null;
-			$tags = $item['categories'];
+			$tags = empty($item['categories']) ? array() : $item['categories'];
 			$labels = array();
 			for ($i = count($tags) - 1; $i >= 0; $i --) {
 				$tag = trim($tags[$i]);
@@ -536,18 +549,41 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
 				$is_read = $mark_as_read;
 			}
 
-			$url = $item['alternate'][0]['href'];
+			if (isset($item['alternate'][0]['href'])) {
+				$url = $item['alternate'][0]['href'];
+			} elseif (isset($item['url'])) {
+				$url = $item['url'];	//FeedBin
+			} else {
+				$url = '';
+			}
+
 			if (!empty($item['content']['content'])) {
 				$content = $item['content']['content'];
 			} elseif (!empty($item['summary']['content'])) {
 				$content = $item['summary']['content'];
+			} elseif (!empty($item['content'])) {
+				$content = $item['content'];	//FeedBin
+			} else {
+				$content = '';
 			}
 			$content = sanitizeHTML($content, $url);
 
+			if (!empty($item['published'])) {
+				$published = $item['published'];
+			} elseif (!empty($item['timestampUsec'])) {
+				$published = substr($item['timestampUsec'], 0, -6);
+			} elseif (!empty($item['updated'])) {
+				$published = $item['updated'];
+			} else {
+				$published = 0;
+			}
+			if (!ctype_digit('' . $published)) {
+				$published = strtotime($published);
+			}
+
 			$entry = new FreshRSS_Entry(
 				$feed_id, $item['id'], $item['title'], $author,
-				$content, $url,
-				$item['published'], $is_read, $is_starred
+				$content, $url, $published, $is_read, $is_starred
 			);
 			$entry->_id(min(time(), $entry->date(true)) . uSecString());
 			$entry->_tags($tags);
@@ -639,6 +675,9 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
 			$feed->_category(FreshRSS_CategoryDAO::DEFAULTCATEGORYID);
 			$feed->_name($name);
 			$feed->_website($website);
+			if (!empty($origin['disable'])) {
+				$feed->_ttl(-1 * FreshRSS_Context::$user_conf->ttl_default);
+			}
 
 			// Call the extension hook
 			$feed = Minz_ExtensionManager::callHook('feed_before_insert', $feed);

+ 4 - 1
app/Models/FeedDAO.php

@@ -61,7 +61,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
 			$valuesTmp['lastUpdate'],
 			base64_encode($valuesTmp['httpAuth']),
 			FreshRSS_Feed::KEEP_HISTORY_DEFAULT,
-			FreshRSS_Feed::TTL_DEFAULT,
+			isset($valuesTmp['ttl']) ? intval($valuesTmp['ttl']) : FreshRSS_Feed::TTL_DEFAULT,
 			isset($valuesTmp['attributes']) ? json_encode($valuesTmp['attributes']) : '',
 		);
 
@@ -95,6 +95,9 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
 				'httpAuth' => $feed->httpAuth(),
 				'attributes' => $feed->attributes(),
 			);
+			if ($feed->mute() || $feed->ttl() != FreshRSS_Context::$user_conf->ttl_default) {
+				$values['ttl'] = $feed->ttl() * ($feed->mute() ? -1 : 1);
+			}
 
 			$id = $this->addFeed($values);
 			if ($id) {