Further refinment to OPDS/RSS generation and also add Atom feeds

This commit is contained in:
Alex Cabal 2022-06-23 15:03:52 -05:00
parent d75d847004
commit f9fd6c8a02
23 changed files with 733 additions and 859 deletions

View file

@ -2,24 +2,26 @@
use function Safe\file_put_contents;
class OpdsFeed extends AtomFeed{
public $Updated = null;
public $Parent = null; // OpdsNavigationFeed class
public function __construct(string $url, string $title, string $path, array $entries, ?OpdsNavigationFeed $parent){
parent::__construct($url, $title, $path, $entries);
public function __construct(string $title, string $subtitle, string $url, string $path, array $entries, ?OpdsNavigationFeed $parent){
parent::__construct($title, $subtitle, $url, $path, $entries);
$this->Parent = $parent;
$this->Stylesheet = '/opds/style';
}
protected function SaveUpdatedTimestamp(string $entryId, DateTime $updatedTimestamp): void{
// Only save the updated timestamp for the given entry ID in this file
foreach($this->Entries as $entry){
if($entry->Id == $entryId){
$entry->Updated = $updatedTimestamp;
if(is_a($entry, 'OpdsNavigationEntry')){
if($entry->Id == SITE_URL . $entryId){
$entry->Updated = $updatedTimestamp;
}
}
}
$this->Updated = $updatedTimestamp;
$this->XmlString = null;
file_put_contents($this->Path, $this->GetXmlString());
@ -29,17 +31,19 @@ class OpdsFeed extends AtomFeed{
}
}
protected function SaveIfChanged(): void{
public function SaveIfChanged(): void{
// Did we actually update the feed? If so, write to file and update the index
if($this->HasChanged($this->Path)){
// Files don't match, save the file and update the parent navigation feed with the last updated timestamp
$this->Updated = new DateTime();
if($this->Parent !== null){
$this->Parent->SaveUpdatedTimestamp($this->Id, $this->Updated);
}
// Save our own file
parent::Save();
$this->Save();
}
}
}