Browse Source

Store language of entries as indicated by the feed.

Tobias Kappé 1 year ago
parent
commit
22a866edb5
5 changed files with 25 additions and 4 deletions
  1. 1 0
      classes/feeditem.php
  2. 9 0
      classes/feeditem/atom.php
  3. 11 1
      classes/feeditem/rss.php
  4. 1 1
      classes/feedparser.php
  5. 3 2
      classes/rssutils.php

+ 1 - 0
classes/feeditem.php

@@ -11,5 +11,6 @@ abstract class FeedItem {
 	abstract function get_categories();
 	abstract function get_enclosures();
 	abstract function get_author();
+	abstract function get_language();
 }
 

+ 9 - 0
classes/feeditem/atom.php

@@ -197,4 +197,13 @@ class FeedItem_Atom extends FeedItem_Common {
 		return $encs;
 	}
 
+	function get_language() {
+		$elem = $this->elem;
+		do {
+			$lang = $elem->getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang");
+			$elem = $elem->parentNode;
+		} while (empty($lang) && $elem instanceof DOMElement);
+
+		return $lang;
+	}
 }

+ 11 - 1
classes/feeditem/rss.php

@@ -189,4 +189,14 @@ class FeedItem_RSS extends FeedItem_Common {
 		return $encs;
 	}
 
-}
+	function get_language() {
+		$languages = $this->doc->getElementsByTagName('language');
+
+		if (count($languages) == 0) {
+			return "";
+		}
+
+		return $languages[0]->textContent;
+	}
+
+}

+ 1 - 1
classes/feedparser.php

@@ -283,4 +283,4 @@ class FeedParser {
 
 		return $rv;
 	}
-}
+}

+ 3 - 2
classes/rssutils.php

@@ -637,8 +637,11 @@ class RSSUtils {
 
 				$entry_link = rewrite_relative_url($site_url, $item->get_link());
 
+				$entry_language = $item->get_language();
+
 				_debug("title $entry_title", $debug_enabled);
 				_debug("link $entry_link", $debug_enabled);
+				_debug("language $entry_language", $debug_enabled);
 
 				if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);;
 
@@ -694,7 +697,6 @@ class RSSUtils {
 					$base_entry_id = $row["id"];
 					$entry_stored_hash = $row["content_hash"];
 					$article_labels = Article::get_article_labels($base_entry_id, $owner_uid);
-					$entry_language = $row["lang"];
 
 					$existing_tags = Article::get_article_tags($base_entry_id, $owner_uid);
 					$entry_tags = array_unique(array_merge($entry_tags, $existing_tags));
@@ -702,7 +704,6 @@ class RSSUtils {
 					$base_entry_id = false;
 					$entry_stored_hash = "";
 					$article_labels = array();
-					$entry_language = "";
 				}
 
 				$article = array("owner_uid" => $owner_uid, // read only