mirror of
https://github.com/standardebooks/web.git
synced 2025-07-07 07:10:29 -04:00
Add endpoint to get collections for an ebook or placeholder
This commit is contained in:
parent
ed5540c177
commit
bdeebc8291
3 changed files with 32 additions and 1 deletions
|
@ -10,6 +10,9 @@ RewriteRule ^/images/covers/(.+?)\-[a-z0-9]{8}\-(cover|hero)(@2x)?\.(jpg|avif)$
|
|||
# Rewrite ebook downloads.
|
||||
RewriteRule ^/ebooks/(.+?)/download$ /ebooks/download.php?url-path=$1 [QSA]
|
||||
|
||||
# Rewrite ebook collections.
|
||||
RewriteRule ^/ebooks/(.+?)/collections$ /ebooks/collections.php?url-path=$1 [QSA]
|
||||
|
||||
# Misc ebook rewrites.
|
||||
RewriteRule ^/subjects/([^\./]+?)$ /ebooks/index.php?tags[]=$1 [B,QSA]
|
||||
RewriteRule ^/ebooks/([^\./]+?)$ /authors/get.php?url-path=$1 [B,QSA]
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?
|
||||
use function Safe\preg_replace;
|
||||
use function Safe\session_unset;
|
||||
|
||||
session_start();
|
||||
|
|
29
www/ebooks/collections.php
Normal file
29
www/ebooks/collections.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?
|
||||
$identifier = EBOOKS_IDENTIFIER_PREFIX . trim(str_replace('.', '', HttpInput::Str(GET, 'url-path') ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after `https://standardebooks.org/ebooks/`.
|
||||
|
||||
$ebook = null;
|
||||
|
||||
try{
|
||||
$ebook = Ebook::GetByIdentifier($identifier);
|
||||
}
|
||||
catch(Exceptions\EbookNotFoundException){
|
||||
Template::ExitWithCode(Enums\HttpCode::NotFound);
|
||||
}
|
||||
|
||||
header('content-type: application/xml; charset=utf-8');
|
||||
print('<?xml version="1.0" encoding="utf-8"?>');
|
||||
print("\n");
|
||||
?>
|
||||
<collections>
|
||||
<? foreach($ebook->CollectionMemberships as $collectionMembership){ ?>
|
||||
<collection>
|
||||
<meta id="collection-<?= $collectionMembership->SortOrder + 1 ?>" property="belongs-to-collection"><?= Formatter::EscapeXml($collectionMembership->Collection->Name) ?></meta>
|
||||
<? if($collectionMembership->Collection->Type !== null){ ?>
|
||||
<meta property="collection-type" refines="#collection-<?= $collectionMembership->SortOrder + 1 ?>"><?= $collectionMembership->Collection->Type->value ?></meta>
|
||||
<? } ?>
|
||||
<? if($collectionMembership->SequenceNumber !== null){ ?>
|
||||
<meta property="group-position" refines="#collection-<?= $collectionMembership->SortOrder + 1 ?>"><?= $collectionMembership->SequenceNumber ?></meta>
|
||||
<? } ?>
|
||||
</collection>
|
||||
<? } ?>
|
||||
</collections>
|
Loading…
Add table
Add a link
Reference in a new issue