Переглянути джерело

Fetch feed name / website / description if empty (#3071)

#fix https://github.com/FreshRSS/FreshRSS/issues/3067
Alexandre Alapetite 5 роки тому
батько
коміт
b9d2e6457a
1 змінених файлів з 24 додано та 1 видалено
  1. 24 1
      app/Controllers/feedController.php

+ 24 - 1
app/Controllers/feedController.php

@@ -430,6 +430,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 				$entryDAO->commit();
 			}
 
+			$feedProperties = [];
+
 			if ($pubsubhubbubEnabledGeneral && $feed->hubUrl() && $feed->selfUrl()) {	//selfUrl has priority for WebSub
 				if ($feed->selfUrl() !== $url) {	// https://github.com/pubsubhubbub/PubSubHubbub/wiki/Moving-Feeds-or-changing-Hubs
 					$selfUrl = checkUrl($feed->selfUrl());
@@ -445,7 +447,28 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 				}
 			} elseif ($feed->url() !== $url) {	// HTTP 301 Moved Permanently
 				Minz_Log::notice('Feed ' . $url . ' moved permanently to ' . $feed->url(false));
-				$feedDAO->updateFeed($feed->id(), array('url' => $feed->url()));
+				$feedProperties['url'] = $feed->url();
+			}
+
+			if ($simplePie != null) {
+				if (trim($feed->name()) == '') {
+					//HTML to HTML-PRE	//ENT_COMPAT except '&'
+					$name = strtr(html_only_entity_decode($simplePie->get_title()), array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;'));
+					$feedProperties['name'] = $name == '' ? $feed->url() : $name;
+				}
+				if (trim($feed->website()) == '') {
+					$website = html_only_entity_decode($simplePie->get_link());
+					$feedProperties['website'] = $website == '' ? $feed->url() : $website;
+				}
+				if (trim($feed->description()) == '') {
+					$description = html_only_entity_decode($simplePie->get_description());
+					if ($description != '') {
+						$feedProperties['description'] = $description;
+					}
+				}
+			}
+			if (!empty($feedProperties)) {
+				$feedDAO->updateFeed($feed->id(), $feedProperties);
 			}
 
 			$feed->faviconPrepare();