mirror of
https://github.com/standardebooks/web.git
synced 2025-07-21 23:04:57 -04:00
Add collections and authors RSS/Atom/OPDS feeds
This commit is contained in:
parent
e19847adac
commit
05e0f77b45
19 changed files with 280 additions and 142 deletions
|
@ -17,21 +17,24 @@ require_once('Core.php');
|
|||
<p>The fifteen latest Standard Ebooks, most-recently-released first.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/feeds/atom/all">All ebooks</a></p>
|
||||
<p class="url"><?= SITE_URL ?>/feeds/atom/all</p>
|
||||
<p><a href="<? if($GLOBALS['User'] !== null){ ?>https://<?= rawurlencode($GLOBALS['User']->Email) ?>@<?= SITE_DOMAIN ?><? } ?>/feeds/atom/all">All ebooks</a></p>
|
||||
<p class="url"><? if($GLOBALS['User'] !== null){ ?>https://<?= rawurlencode($GLOBALS['User']->Email) ?>@<?= SITE_DOMAIN ?><? }else{ ?><?= SITE_URL ?><? } ?>/feeds/atom/all</p>
|
||||
<p>All Standard Ebooks, most-recently-released first.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section id="ebooks-by-subject">
|
||||
<h2>Ebooks by subject</h2>
|
||||
<section id="feeds-by-topic">
|
||||
<h2>Feeds by topic</h2>
|
||||
<ul class="feed">
|
||||
<? foreach(SE_SUBJECTS as $subject){ ?>
|
||||
<li>
|
||||
<p><a href="/feeds/atom/subjects/<?= Formatter::MakeUrlSafe($subject) ?>"><?= Formatter::ToPlainText($subject) ?></a></p>
|
||||
<p class="url"><?= SITE_URL ?>/feeds/atom/subjects/<?= Formatter::MakeUrlSafe($subject) ?></p>
|
||||
<p><a href="/feeds/atom/authors">Feeds by author</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/feeds/atom/collections">Feeds by collection</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/feeds/atom/subjects">Feeds by subject</a></p>
|
||||
</li>
|
||||
<? } ?>
|
||||
</ul>
|
||||
</section>
|
||||
</section>
|
||||
|
|
|
@ -16,7 +16,7 @@ catch(\Exception $ex){
|
|||
include(WEB_ROOT . '/404.php');
|
||||
exit();
|
||||
}
|
||||
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"/feeds/atom/style\" type=\"text/xsl\"?>\n");
|
||||
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"" . SITE_URL . "/feeds/atom/style\" type=\"text/xsl\"?>\n");
|
||||
?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
|
||||
<id><?= SITE_URL ?>/feeds/atom/all?query=<?= urlencode($query) ?></id>
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
<?
|
||||
require_once('Core.php');
|
||||
|
||||
?><?= Template::Header(['title' => 'Atom 1.0 Ebook Feeds by Subject', 'description' => 'A list of available Atom 1.0 feeds of Standard Ebooks ebooks by subject.']) ?>
|
||||
<main>
|
||||
<article>
|
||||
<h1>Atom 1.0 Ebook Feeds by Subject</h1>
|
||||
<?= Template::FeedHowTo() ?>
|
||||
<section id="ebooks-by-subject">
|
||||
<h2>Ebooks by subject</h2>
|
||||
<ul class="feed">
|
||||
<? foreach(SE_SUBJECTS as $subject){ ?>
|
||||
<li>
|
||||
<p><a href="/feeds/atom/subjects/<?= Formatter::MakeUrlSafe($subject) ?>"><?= Formatter::ToPlainText($subject) ?></a></p>
|
||||
<p class="url"><?= SITE_URL ?>/feeds/atom/subjects/<?= Formatter::MakeUrlSafe($subject) ?></p>
|
||||
</li>
|
||||
<? } ?>
|
||||
</ul>
|
||||
</section>
|
||||
</article>
|
||||
</main>
|
||||
<?= Template::Footer() ?>
|
79
www/feeds/collection.php
Normal file
79
www/feeds/collection.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?
|
||||
require_once('Core.php');
|
||||
|
||||
use function Safe\apcu_fetch;
|
||||
use function Safe\glob;
|
||||
use function Safe\preg_replace;
|
||||
use function Safe\usort;
|
||||
|
||||
$name = HttpInput::Str(GET, 'name', false) ?? '';
|
||||
$type = HttpInput::Str(GET, 'type', false) ?? '';
|
||||
|
||||
if($name != 'authors' && $name != 'collections' && $name != 'subjects'){
|
||||
Template::Emit404();
|
||||
}
|
||||
|
||||
if($type != 'rss' && $type != 'atom'){
|
||||
Template::Emit404();
|
||||
}
|
||||
|
||||
$feeds = [];
|
||||
|
||||
$lcTitle = preg_replace('/s$/', '', $name);
|
||||
$ucTitle = ucfirst($lcTitle);
|
||||
$ucType = 'RSS 2.0';
|
||||
if($type === 'atom'){
|
||||
$ucType = 'Atom 1.0';
|
||||
}
|
||||
|
||||
try{
|
||||
$feeds = apcu_fetch('feeds-index-' . $type . '-' . $name);
|
||||
}
|
||||
catch(Safe\Exceptions\ApcuException $ex){
|
||||
$files = glob(WEB_ROOT . '/feeds/' . $type . '/' . $name . '/*.xml');
|
||||
|
||||
$feeds = [];
|
||||
|
||||
foreach($files as $file){
|
||||
$obj = new stdClass();
|
||||
$obj->Url = '/feeds/' . $type . '/' . $name . '/' . basename($file, '.xml');
|
||||
|
||||
$obj->Label = exec('attr -g se-label ' . escapeshellarg($file)) ?: null;
|
||||
if($obj->Label == null){
|
||||
$obj->Label = basename($file, '.xml');
|
||||
}
|
||||
|
||||
$obj->LabelSort = exec('attr -g se-label-sort ' . escapeshellarg($file)) ?: null;
|
||||
if($obj->LabelSort == null){
|
||||
$obj->LabelSort = basename($file, '.xml');
|
||||
}
|
||||
|
||||
$feeds[] = $obj;
|
||||
}
|
||||
|
||||
$collator = Collator::create('en_US'); // Used for sorting letters with diacritics like in author names
|
||||
if($collator !== null){
|
||||
usort($feeds, function($a, $b) use($collator){ return $collator->compare($a->LabelSort, $b->LabelSort); });
|
||||
}
|
||||
|
||||
apcu_store('feeds-index-' . $type . '-' . $name, $feeds, 43200); // 12 hours
|
||||
}
|
||||
?><?= Template::Header(['title' => $ucType . ' Ebook Feeds by ' . $ucTitle, 'description' => 'A list of available ' . $ucType . ' feeds of Standard Ebooks ebooks by ' . $lcTitle . '.']) ?>
|
||||
<main>
|
||||
<article>
|
||||
<h1><?= $ucType ?> Ebook Feeds by <?= $ucTitle ?></h1>
|
||||
<?= Template::FeedHowTo() ?>
|
||||
<section id="ebooks-by-<?= $lcTitle ?>">
|
||||
<h2>Ebooks by <?= $lcTitle ?></h2>
|
||||
<ul class="feed">
|
||||
<? foreach($feeds as $feed){ ?>
|
||||
<li>
|
||||
<p><a href="<? if($GLOBALS['User'] !== null){ ?>https://<?= rawurlencode($GLOBALS['User']->Email) ?>@<?= SITE_DOMAIN ?><? } ?><?= Formatter::ToPlainText($feed->Url) ?>"><?= Formatter::ToPlainText($feed->Label) ?></a></p>
|
||||
<p class="url"><? if($GLOBALS['User'] !== null){ ?>https://<?= rawurlencode($GLOBALS['User']->Email) ?>@<?= SITE_DOMAIN ?><? }else{ ?><?= SITE_URL ?><? } ?><?= Formatter::ToPlainText($feed->Url) ?></p>
|
||||
</li>
|
||||
<? } ?>
|
||||
</ul>
|
||||
</section>
|
||||
</article>
|
||||
</main>
|
||||
<?= Template::Footer() ?>
|
|
@ -18,8 +18,8 @@ require_once('Core.php');
|
|||
<p>They’re also perfect for scripting, or for libraries or other organizations who wish to download, process, and keep up to date with our catalog of ebooks.</p>
|
||||
<ul class="feed">
|
||||
<li>
|
||||
<p><a href="/feeds/opds">The Standard Ebooks OPDS feed</a></p>
|
||||
<p class="url"><?= SITE_URL ?>/feeds/opds</p>
|
||||
<p><a href="<? if($GLOBALS['User'] !== null){ ?>https://<?= rawurlencode($GLOBALS['User']->Email) ?>@<?= SITE_DOMAIN ?><? } ?>/feeds/opds">The Standard Ebooks OPDS feed</a></p>
|
||||
<p class="url"><? if($GLOBALS['User'] !== null){ ?>https://<?= rawurlencode($GLOBALS['User']->Email) ?>@<?= SITE_DOMAIN ?><? }else{ ?><?= SITE_URL ?><? } ?>/feeds/opds</p>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
|
|
@ -15,7 +15,7 @@ catch(\Exception $ex){
|
|||
http_response_code(500);
|
||||
exit();
|
||||
}
|
||||
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"/feeds/opds/style\" type=\"text/xsl\"?>\n");
|
||||
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"". SITE_URL . "/feeds/opds/style\" type=\"text/xsl\"?>\n");
|
||||
?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:schema="http://schema.org/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
|
||||
<id><?= SITE_URL ?>/feeds/opds/all?query=<?= urlencode($query) ?></id>
|
||||
|
|
|
@ -8,7 +8,7 @@ require_once('Core.php');
|
|||
<p>RSS feeds are the predecessors of <a href="/feeds/atom">Atom feeds</a>. They contain less information than Atom feeds, but might be better supported by some news readers.</p>
|
||||
<?= Template::FeedHowTo() ?>
|
||||
<section id="general-feeds">
|
||||
<h2>General Feeds</h2>
|
||||
<h2>General feeds</h2>
|
||||
<ul class="feed">
|
||||
<li>
|
||||
<p><a href="/feeds/rss/new-releases">New releases</a> (Public)</p>
|
||||
|
@ -22,15 +22,18 @@ require_once('Core.php');
|
|||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section id="ebooks-by-subject">
|
||||
<h2>Ebooks by subject</h2>
|
||||
<section id="ebooks-by-collection">
|
||||
<h2>Feeds by topic</h2>
|
||||
<ul class="feed">
|
||||
<? foreach(SE_SUBJECTS as $subject){ ?>
|
||||
<li>
|
||||
<p><a href="/feeds/rss/subjects/<?= Formatter::MakeUrlSafe($subject) ?>"><?= Formatter::ToPlainText($subject) ?></a></p>
|
||||
<p class="url"><?= SITE_URL ?>/feeds/rss/subjects/<?= Formatter::MakeUrlSafe($subject) ?></p>
|
||||
<p><a href="/feeds/rss/authors">Feeds by author</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/feeds/rss/collections">Feeds by collection</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/feeds/rss/subjects">Feeds by subject</a></p>
|
||||
</li>
|
||||
<? } ?>
|
||||
</ul>
|
||||
</section>
|
||||
</section>
|
||||
|
|
|
@ -16,7 +16,7 @@ catch(\Exception $ex){
|
|||
include(WEB_ROOT . '/404.php');
|
||||
exit();
|
||||
}
|
||||
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"/feeds/rss/style\" type=\"text/xsl\"?>\n");
|
||||
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"" . SITE_URL . "/feeds/rss/style\" type=\"text/xsl\"?>\n");
|
||||
?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
|
||||
<channel>
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
<?
|
||||
require_once('Core.php');
|
||||
|
||||
?><?= Template::Header(['title' => 'RSS 2.0 Ebook Feeds by Subject', 'description' => 'A list of available RSS 2.0 feeds of Standard Ebooks ebooks by subject.']) ?>
|
||||
<main>
|
||||
<article>
|
||||
<h1>RSS 2.0 Ebook Feeds by Subject</h1>
|
||||
<?= Template::FeedHowTo() ?>
|
||||
<section id="ebooks-by-subject">
|
||||
<h2>Ebooks by subject</h2>
|
||||
<ul class="feed">
|
||||
<? foreach(SE_SUBJECTS as $subject){ ?>
|
||||
<li>
|
||||
<p><a href="/feeds/rss/subjects/<?= Formatter::MakeUrlSafe($subject) ?>"><?= Formatter::ToPlainText($subject) ?></a></p>
|
||||
<p class="url"><?= SITE_URL ?>/feeds/rss/subjects/<?= Formatter::MakeUrlSafe($subject) ?></p>
|
||||
</li>
|
||||
<? } ?>
|
||||
</ul>
|
||||
</section>
|
||||
</article>
|
||||
</main>
|
||||
<?= Template::Footer() ?>
|
Loading…
Add table
Add a link
Reference in a new issue