mirror of
https://github.com/standardebooks/web.git
synced 2025-07-13 18:11:52 -04:00
Flesh out OPDS generation backend to be more robust and to support generic Atom feeds
This commit is contained in:
parent
35188195f1
commit
f6df03cfca
23 changed files with 1549 additions and 267 deletions
46
lib/Feed.php
Normal file
46
lib/Feed.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?
|
||||
use function Safe\file_get_contents;
|
||||
use function Safe\file_put_contents;
|
||||
use function Safe\tempnam;
|
||||
use function Safe\unlink;
|
||||
|
||||
class Feed{
|
||||
public $Url;
|
||||
public $Title;
|
||||
public $Entries = [];
|
||||
public $Path = null;
|
||||
public $Stylesheet = null;
|
||||
protected $XmlString = null;
|
||||
|
||||
public function __construct(string $url, string $title, string $path, array $entries){
|
||||
$this->Url = $url;
|
||||
$this->Title = $title;
|
||||
$this->Path = $path;
|
||||
$this->Entries = $entries;
|
||||
}
|
||||
|
||||
protected function CleanXmlString(string $xmlString): string{
|
||||
$tempFilename = tempnam('/tmp/', 'se-');
|
||||
file_put_contents($tempFilename, $xmlString);
|
||||
exec('se clean ' . escapeshellarg($tempFilename) . ' 2>&1', $output); // Capture the result in case there's an error, otherwise it prints to stdout
|
||||
$output = file_get_contents($tempFilename);
|
||||
unlink($tempFilename);
|
||||
|
||||
if($this->Stylesheet !== null){
|
||||
$output = str_replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"" . $this->Stylesheet . "\" type=\"text/xsl\"?>", $output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function GetXmlString(): string{
|
||||
// Virtual function, meant to be implemented by subclass
|
||||
return '';
|
||||
}
|
||||
|
||||
function Save(): void{
|
||||
$feed = $this->GetXmlString();
|
||||
|
||||
file_put_contents($this->Path, $feed);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue