2 Commits 22a866edb5 ... a377d5c981

Author SHA1 Message Date
  Tobias Kappé a377d5c981 Determine language for atom entry without a loop. 1 year ago
  Tobias Kappé 3bbaf902ab Sanitize language obtained for an entry. 1 year ago
2 changed files with 9 additions and 7 deletions
  1. 8 6
      classes/feeditem/atom.php
  2. 1 1
      classes/rssutils.php

+ 8 - 6
classes/feeditem/atom.php

@@ -1,5 +1,6 @@
 <?php
 class FeedItem_Atom extends FeedItem_Common {
+	const NS_XML = "http://www.w3.org/XML/1998/namespace";
 
 	function get_id() {
 		$id = $this->elem->getElementsByTagName("id")->item(0);
@@ -198,12 +199,13 @@ class FeedItem_Atom extends FeedItem_Common {
 	}
 
 	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);
+		$lang = $this->elem->getAttributeNS(self::NS_XML, "lang");
 
-		return $lang;
+		if (!empty($lang)) {
+			return $lang;
+		} else {
+			// Fall back to the language declared on the feed, if any.
+			return $this->doc->firstChild->getAttributeNS(self::NS_XML, "lang");
+		}
 	}
 }

+ 1 - 1
classes/rssutils.php

@@ -637,7 +637,7 @@ class RSSUtils {
 
 				$entry_link = rewrite_relative_url($site_url, $item->get_link());
 
-				$entry_language = $item->get_language();
+				$entry_language = mb_substr(trim($item->get_language()), 0, 2);
 
 				_debug("title $entry_title", $debug_enabled);
 				_debug("link $entry_link", $debug_enabled);