]> git.wh0rd.org Git - tt-rss.git/commitdiff
Store language of entries as indicated by the feed.
authorTobias Kappé <tobias.kappe@gmail.com>
Sun, 12 Aug 2018 13:54:13 +0000 (14:54 +0100)
committerTobias Kappé <tobias.kappe@gmail.com>
Sun, 12 Aug 2018 14:27:26 +0000 (15:27 +0100)
classes/feeditem.php
classes/feeditem/atom.php
classes/feeditem/rss.php
classes/feedparser.php
classes/rssutils.php

index 594f56984cfcea2f7d6139e346d181f0c78752d6..3a5e5dc0941307466310b58fa2a195855005e8f7 100644 (file)
@@ -11,5 +11,6 @@ abstract class FeedItem {
        abstract function get_categories();
        abstract function get_enclosures();
        abstract function get_author();
+       abstract function get_language();
 }
 
index 77cd448b862a8d61fafec8d75531f63d9ad245c2..6e7a904f8c7d4153460eec7cbf67a73f155a2b7a 100644 (file)
@@ -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;
+       }
 }
index a3fa7e636578bfd9ed6c3270d2baac310f226b06..dca125be6db58886948019f622162d3390fbaa59 100644 (file)
@@ -189,4 +189,14 @@ class FeedItem_RSS extends FeedItem_Common {
                return $encs;
        }
 
-}
\ No newline at end of file
+       function get_language() {
+               $languages = $this->doc->getElementsByTagName('language');
+
+               if (count($languages) == 0) {
+                       return "";
+               }
+
+               return $languages[0]->textContent;
+       }
+
+}
index 860ebd73f6d34e8d2ee2bf6b35596921d2a8dd84..a5e406149d46062c620b60a6ce53738f0b0d13d8 100644 (file)
@@ -283,4 +283,4 @@ class FeedParser {
 
                return $rv;
        }
-}
\ No newline at end of file
+}
index b69bb25a034022d17e8c3210a2e6ea2b69f17dd2..6fa1e9f4fa453bb3298d4ae9dd629ac388f6590d 100755 (executable)
@@ -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