1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Fix feed ID discovery so it doesn't short-circuit the item loop

This commit is contained in:
J. King 2017-06-03 13:43:58 -04:00
parent ba61ca2b2c
commit 0ab6210214
2 changed files with 12 additions and 19 deletions

View file

@ -104,26 +104,15 @@ class Feed {
} else {
$f->titleContentHash = hash('sha256', $f->title.$content);
}
// If there is an Atom id element use it as the id.
$id = (string)$f->xml->children('http://www.w3.org/2005/Atom')->id;
if ($id !== '') {
$f->id = hash('sha256', $id);
continue;
}
// If there is a guid element use it as the id.
$id = (string)$f->xml->guid;
if ($id !== '') {
$f->id = hash('sha256', $id);
continue;
}
// If there is a Dublin Core identifier use it.
$id = (string)$f->xml->children('http://purl.org/dc/elements/1.1/')->identifier;
if ($id !== '') {
$f->id = hash('sha256', $id);
continue;
}
// If there aren't any of those there is no id.
$f->id = null;
// prefer an Atom ID as the item's ID
$id = (string) $f->xml->children('http://www.w3.org/2005/Atom')->id;
// otherwise use the RSS2 guid element
if(!strlen($id)) $id = (string) $f->xml->guid;
// otherwise use the Dublin Core identifier element
if(!strlen($id)) $id = (string) $f->xml->children('http://purl.org/dc/elements/1.1/')->identifier;
// otherwise there is no ID; if there is one, hash it
if(strlen($id)) $f->id = hash('sha256', $id);
// PicoFeed also doesn't gather up categories, so we do this as well
$f->categories = [];

View file

@ -124,6 +124,10 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
"Bodybuilders",
"Men",
];
$this->assertSame([], $f->data->items[0]->categories);
$this->assertSame([], $f->data->items[1]->categories);
$this->assertSame([], $f->data->items[3]->categories);
$this->assertSame([], $f->data->items[4]->categories);
$this->assertSame($categories, $f->data->items[5]->categories);
}