mirror of
https://github.com/standardebooks/web.git
synced 2025-07-05 14:20:29 -04:00
67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?
|
|
use Safe\DateTimeImmutable;
|
|
use function Safe\file_put_contents;
|
|
|
|
class OpdsFeed extends AtomFeed{
|
|
public ?OpdsNavigationFeed $Parent = null;
|
|
|
|
/**
|
|
* @param string $title
|
|
* @param string $subtitle
|
|
* @param string $url
|
|
* @param string $path
|
|
* @param array<Ebook> $entries
|
|
* @param OpdsNavigationFeed $parent
|
|
*/
|
|
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 = SITE_URL . '/feeds/opds/style';
|
|
}
|
|
|
|
|
|
// *******
|
|
// METHODS
|
|
// *******
|
|
|
|
protected function SaveUpdated(string $entryId, DateTimeImmutable $updated): void{
|
|
// Only save the updated timestamp for the given entry ID in this file
|
|
foreach($this->Entries as $entry){
|
|
if($entry instanceof OpdsNavigationEntry){
|
|
if($entry->Id == SITE_URL . $entryId){
|
|
$entry->Updated = $updated;
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->Updated = $updated;
|
|
|
|
$this->XmlString = null;
|
|
file_put_contents($this->Path, $this->GetXmlString());
|
|
|
|
// Do we have any parents of our own to update?
|
|
if($this->Parent !== null){
|
|
$this->Parent->SaveUpdated($this->Id, $updated);
|
|
}
|
|
}
|
|
|
|
public function SaveIfChanged(): bool{
|
|
// 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
|
|
|
|
/** @throws void */
|
|
$this->Updated = new DateTimeImmutable();
|
|
|
|
if($this->Parent !== null){
|
|
$this->Parent->SaveUpdated($this->Id, $this->Updated);
|
|
}
|
|
|
|
// Save our own file
|
|
$this->Save();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|