Browse Source

Implement feed language

master
J. King 4 years ago
parent
commit
fc9c0c6122
  1. 18
      lib/Parser/XML/Construct.php
  2. 10
      lib/Parser/XML/Feed.php
  3. 15
      tests/cases/XML/feed-atom.yaml
  4. 10
      tests/cases/XML/feed-rss0.yaml
  5. 13
      tests/cases/XML/feed-rss1.yaml
  6. 10
      tests/cases/XML/feed-rss2.yaml

18
lib/Parser/XML/Construct.php

@ -209,4 +209,22 @@ abstract class Construct {
protected function getIdDC(): ?string {
return $this->fetchString("dc:identifier", ".+");
}
protected function getLangXML(): ?string {
// walk up the tree looking for the nearest language tag
$el = $this->subject;
do {
$out = $this->fetchString("@xml:lang", ".+", false, $el);
$el = $el->parentNode;
} while (is_null($out) && $el);
return $out;
}
protected function getLangDC(): ?string {
return $this->fetchString("dc:language", ".+");
}
protected function getLangRss2(): ?string {
return $this->fetchString("language", ".+");
}
}

10
lib/Parser/XML/Feed.php

@ -83,7 +83,7 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
$feed->meta->url = $this->url;
$feed->sched = $this->getSchedule();
$feed->id = $this->getId();
//$feed->lang = $this->getLang();
$feed->lang = $this->getLang();
//$feed->url = $this->getUrl();
//$feed->link = $this->getLink();
//$feed->title = $this->getTitle();
@ -115,6 +115,10 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
return $sched;
}
public function getLang(): ?string {
return $this->getLangXML() ?? $this->getLangDC() ?? $this->getLangRss2();
}
public function getUrl(): ?Url {
return $this->getUrlAtom() ?? $this->getUrlRss1() ?? $this->getUrlPod();
}
@ -152,10 +156,6 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
return $this->getEntriesAtom() ?? $this->getEntriesRss1() ?? $this->getEntriesRss2() ?? [];
}
public function getLang(): ?string {
return null;
}
public function getIcon(): ?Url {
return null;
}

15
tests/cases/XML/feed-atom.yaml

@ -39,3 +39,18 @@ Bogus ID before good:
format: atom
version: '1.0'
id: 'http://example.com/'
Feed language:
input: >
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"/>
output:
format: atom
version: '1.0'
lang: en
Bogus feed language:
input: >
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang=""/>
output:
format: atom
version: '1.0'

10
tests/cases/XML/feed-rss0.yaml

@ -24,3 +24,13 @@ Minimal feed without channel 2:
output:
format: rdf
version: '0.90'
Feed language: # demonstrate walking up the DOM
input: >
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://channel.netscape.com/rdf/simple/0.9/" xml:lang="fr">
<channel xml:lang=""/>
</rdf:RDF>
output:
format: rdf
version: '0.90'
lang: fr

13
tests/cases/XML/feed-rss1.yaml

@ -150,3 +150,16 @@ Syndication schedule base 1:
sched:
interval: PT24H
base: '2020-03-01T20:21:12-04:00'
DC language:
input: >
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<dc:language/>
<dc:language>de</dc:language>
</channel>
</rdf:RDF>
output:
format: rdf
version: '1.0'
lang: de

10
tests/cases/XML/feed-rss2.yaml

@ -177,7 +177,6 @@ Skip all hours:
expired: true
skip: 16777215 # 0b111111111111111111111111
Skip all days and hours:
input: >
<rss><channel>
@ -222,3 +221,12 @@ Skip all days and hours:
sched:
expired: true
skip: 2147483647 # 0b1111111111111111111111111111111
Feed language:
input: >
<rss><channel>
<language>ja</language>
</channel></rss>
output:
format: rss
lang: ja

Loading…
Cancel
Save