mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 02:46:46 -04:00
Further refinment to OPDS/RSS generation and also add Atom feeds
This commit is contained in:
parent
d75d847004
commit
f9fd6c8a02
23 changed files with 733 additions and 859 deletions
|
@ -2,8 +2,8 @@
|
|||
class RssFeed extends Feed{
|
||||
public $Description;
|
||||
|
||||
public function __construct(string $url, string $title, string $path, string $description, array $entries){
|
||||
parent::__construct($url, $title, $path, $entries);
|
||||
public function __construct(string $title, string $description, string $url, string $path, array $entries){
|
||||
parent::__construct($title, $url, $path, $entries);
|
||||
$this->Description = $description;
|
||||
$this->Stylesheet = '/rss/style';
|
||||
}
|
||||
|
@ -17,4 +17,44 @@ class RssFeed extends Feed{
|
|||
|
||||
return $this->XmlString;
|
||||
}
|
||||
|
||||
protected function HasChanged(string $path): bool{
|
||||
// RSS doesn't have information about when an item was updated,
|
||||
// only when it was first published. So, we approximate on whether the feed
|
||||
// has changed by looking at the length of the enclosed file.
|
||||
// This can sometimes be the same even if the file has changed, but most of the time
|
||||
// it also changes.
|
||||
|
||||
if(!is_file($path)){
|
||||
return true;
|
||||
}
|
||||
|
||||
$currentEntries = [];
|
||||
foreach($this->Entries as $entry){
|
||||
$obj = new StdClass();
|
||||
$obj->Size = (string)filesize(WEB_ROOT . $entry->EpubUrl);
|
||||
$obj->Id = preg_replace('/^url:/ius', '', $entry->Identifier);
|
||||
$currentEntries[] = $obj;
|
||||
}
|
||||
|
||||
$oldEntries = [];
|
||||
try{
|
||||
$xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', file_get_contents($path)));
|
||||
$xml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
|
||||
foreach($xml->xpath('/rss/channel/item') ?: [] as $entry){
|
||||
$obj = new StdClass();
|
||||
foreach($entry->xpath('enclosure') ?: [] as $enclosure){
|
||||
$obj->Size = (string)$enclosure['length'];
|
||||
}
|
||||
$obj->Id = (string)$entry->guid;
|
||||
$oldEntries[] = $obj;
|
||||
}
|
||||
}
|
||||
catch(Exception $ex){
|
||||
// Invalid XML
|
||||
return true;
|
||||
}
|
||||
|
||||
return $currentEntries != $oldEntries;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue