mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-31 21:12:41 +00:00
Add category list to feed items
This commit is contained in:
parent
140d608f0f
commit
ba61ca2b2c
3 changed files with 36 additions and 4 deletions
28
lib/Feed.php
28
lib/Feed.php
|
@ -104,30 +104,50 @@ class Feed {
|
||||||
} else {
|
} else {
|
||||||
$f->titleContentHash = hash('sha256', $f->title.$content);
|
$f->titleContentHash = hash('sha256', $f->title.$content);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is an Atom id element use it as the id.
|
// If there is an Atom id element use it as the id.
|
||||||
$id = (string)$f->xml->children('http://www.w3.org/2005/Atom')->id;
|
$id = (string)$f->xml->children('http://www.w3.org/2005/Atom')->id;
|
||||||
if ($id !== '') {
|
if ($id !== '') {
|
||||||
$f->id = hash('sha256', $id);
|
$f->id = hash('sha256', $id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is a guid element use it as the id.
|
// If there is a guid element use it as the id.
|
||||||
$id = (string)$f->xml->guid;
|
$id = (string)$f->xml->guid;
|
||||||
if ($id !== '') {
|
if ($id !== '') {
|
||||||
$f->id = hash('sha256', $id);
|
$f->id = hash('sha256', $id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is a Dublin Core identifier use it.
|
// If there is a Dublin Core identifier use it.
|
||||||
$id = (string)$f->xml->children('http://purl.org/dc/elements/1.1/')->identifier;
|
$id = (string)$f->xml->children('http://purl.org/dc/elements/1.1/')->identifier;
|
||||||
if ($id !== '') {
|
if ($id !== '') {
|
||||||
$f->id = hash('sha256', $id);
|
$f->id = hash('sha256', $id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there aren't any of those there is no id.
|
// If there aren't any of those there is no id.
|
||||||
$f->id = null;
|
$f->id = null;
|
||||||
|
|
||||||
|
// PicoFeed also doesn't gather up categories, so we do this as well
|
||||||
|
$f->categories = [];
|
||||||
|
// first add Atom categories
|
||||||
|
foreach($f->xml->children('http://www.w3.org/2005/Atom')->category as $c) {
|
||||||
|
// if the category has a label, use that
|
||||||
|
$name = (string) $c->attributes()->label;
|
||||||
|
// otherwise use the term
|
||||||
|
if(!strlen($name)) $name = (string) $c->attributes()->term;
|
||||||
|
// ... assuming it has that much
|
||||||
|
if(strlen($name)) $f->categories[] = $name;
|
||||||
|
}
|
||||||
|
// next add RSS2 categories
|
||||||
|
foreach($f->xml->children()->category as $c) {
|
||||||
|
$name = (string) $c;
|
||||||
|
if(strlen($name)) $f->categories[] = $name;
|
||||||
|
}
|
||||||
|
// and finally try Dublin Core subjects
|
||||||
|
foreach($f->xml->children('http://purl.org/dc/elements/1.1/')->subject as $c) {
|
||||||
|
$name = (string) $c;
|
||||||
|
if(strlen($name)) $f->categories[] = $name;
|
||||||
|
}
|
||||||
|
//sort the results
|
||||||
|
sort($f->categories);
|
||||||
}
|
}
|
||||||
$this->data = $feed;
|
$this->data = $feed;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -117,6 +117,14 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
|
||||||
$this->assertSame(null, $f->data->items[3]->id);
|
$this->assertSame(null, $f->data->items[3]->id);
|
||||||
$this->assertSame(null, $f->data->items[4]->id);
|
$this->assertSame(null, $f->data->items[4]->id);
|
||||||
$this->assertSame(null, $f->data->items[5]->id);
|
$this->assertSame(null, $f->data->items[5]->id);
|
||||||
|
// check categories
|
||||||
|
$categories = [
|
||||||
|
"Aniki!",
|
||||||
|
"Beams",
|
||||||
|
"Bodybuilders",
|
||||||
|
"Men",
|
||||||
|
];
|
||||||
|
$this->assertSame($categories, $f->data->items[5]->categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testParseEntityExpansionAttack() {
|
function testParseEntityExpansionAttack() {
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
<item>
|
<item>
|
||||||
<description>Example content</description>
|
<description>Example content</description>
|
||||||
<enclosure url="http://example.com/text" type="text/plain"/>
|
<enclosure url="http://example.com/text" type="text/plain"/>
|
||||||
|
<category>Men</category>
|
||||||
|
<atom:category term="Beams"/>
|
||||||
|
<atom:category term="Hoo! Haa!" label="Aniki!"/>
|
||||||
|
<dc:subject>Bodybuilders</dc:subject>
|
||||||
</item>
|
</item>
|
||||||
</channel>
|
</channel>
|
||||||
</rss>
|
</rss>
|
||||||
|
|
Loading…
Reference in a new issue