#!/usr/bin/php ModifiedTimestamp->format('Y-m-d\TH:i:s\Z') . ' ' . $ebook->Identifier] = $ebook; $newestEbooks[$ebook->Timestamp->format('Y-m-d\TH:i:s\Z') . ' ' . $ebook->Identifier] = $ebook; foreach($ebook->Tags as $tag){ // Add the book's subjects to the main subjects list if(!in_array($tag->Name, $subjects)){ $subjects[] = $tag->Name; } // Sort this ebook by subject $ebooksBySubject[$tag->Name][$ebook->Timestamp->format('Y-m-d\TH:i:s\Z') . ' ' . $ebook->Identifier] = $ebook; } } catch(\Exception $ex){ print('Failed to generate OPDS entry for `' . $ebookWwwFilesystemPath . '`. Exception: ' . $ex->getMessage()); continue; } } krsort($newestEbooks); $newestEbooks = array_slice($newestEbooks, 0, $ebooksPerNewestEbooksFeed); $now = new DateTime(); // Create OPDS feeds $opdsRootEntries = [ new OpdsNavigationEntry( 'Newest ' . number_format($ebooksPerNewestEbooksFeed) . ' Standard Ebooks', 'The ' . number_format($ebooksPerNewestEbooksFeed) . ' latest Standard Ebooks, most-recently-released first.', '/opds/new-releases', $now, 'http://opds-spec.org/sort/new', 'acquisition' ), new OpdsNavigationEntry( 'Standard Ebooks by Subject', 'Browse Standard Ebooks by subject.', '/opds/subjects', $now, 'subsection', 'navigation'), new OpdsNavigationEntry( 'All Standard Ebooks', 'All Standard Ebooks, most-recently-updated first. This is a Complete Acquisition Feed as defined in OPDS 1.2 §2.5.', '/opds/all', $now, 'http://opds-spec.org/crawlable', 'acquisition') ]; $opdsRoot = new OpdsNavigationFeed('Standard Ebooks', 'The navigation root for the Standard Ebooks OPDS feed.', '/opds', WEB_ROOT . '/opds/index.xml', $opdsRootEntries, null); $opdsRoot->SaveIfChanged(); // Create the subjects navigation document sort($subjects); $subjectNavigationEntries = []; foreach($subjects as $subject){ $subjectNavigationEntries[] = new OpdsNavigationEntry($subject, 'Standard Ebooks tagged with “' . strtolower($subject) . ',” most-recently-released first.', '/opds/subjects/' . Formatter::MakeUrlSafe($subject), $now, 'subsection', 'navigation'); } $subjectsFeed = new OpdsNavigationFeed('Standard Ebooks by Subject', 'Browse Standard Ebooks by subject.', '/opds/subjects', WEB_ROOT . '/opds/subjects/index.xml', $subjectNavigationEntries, $opdsRoot); $subjectsFeed->Subtitle = 'Browse Standard Ebooks by subject.'; $subjectsFeed->SaveIfChanged(); // Now generate each individual subject feed foreach($subjectNavigationEntries as $subjectNavigationEntry){ krsort($ebooksBySubject[$subjectNavigationEntry->Title]); $subjectFeed = new OpdsAcquisitionFeed($subjectNavigationEntry->Title . ' Ebooks', $subjectNavigationEntry->Description, '/opds/subjects/' . Formatter::MakeUrlSafe($subjectNavigationEntry->Title), WEB_ROOT . '/opds/subjects/' . Formatter::MakeUrlSafe($subjectNavigationEntry->Title) . '.xml', $ebooksBySubject[$subjectNavigationEntry->Title], $subjectsFeed); $subjectFeed->SaveIfChanged(); } // Create the 'all' feed krsort($allEbooks); $allFeed = new OpdsAcquisitionFeed('All Standard Ebooks', 'All Standard Ebooks, most-recently-updated first. This is a Complete Acquisition Feed as defined in OPDS 1.2 §2.5.', '/opds/all', WEB_ROOT . '/opds/all.xml', $allEbooks, $opdsRoot, true); $allFeed->SaveIfChanged(); // Create the 'newest' feed $newestFeed = new OpdsAcquisitionFeed('Newest ' . number_format($ebooksPerNewestEbooksFeed) . ' Standard Ebooks', 'The ' . number_format($ebooksPerNewestEbooksFeed) . ' latest Standard Ebooks, most-recently-released first.', '/opds/new-releases', WEB_ROOT . '/opds/new-releases.xml', $newestEbooks, $opdsRoot); $newestFeed->SaveIfChanged(); // Now create RSS feeds // Create the 'newest' feed $newestRssFeed = new RssFeed('Standard Ebooks - Newest Ebooks', 'The ' . number_format($ebooksPerNewestEbooksFeed) . ' latest Standard Ebooks, most-recently-released first.', '/rss/new-releases', WEB_ROOT . '/rss/new-releases.xml', $newestEbooks); $newestRssFeed->SaveIfChanged(); // Create the 'all' feed $allRssFeed = new RssFeed('Standard Ebooks - All Ebooks', 'All Standard Ebooks, most-recently-released first.', '/rss/all', WEB_ROOT . '/rss/all.xml', $allEbooks); $allRssFeed->SaveIfChanged(); // Generate each individual subject feed foreach($ebooksBySubject as $subject => $ebooks){ krsort($ebooks); $subjectRssFeed = new RssFeed('Standard Ebooks - ' . (string)$subject . ' Ebooks', 'Standard Ebooks tagged with “' . strtolower($subject) . ',” most-recently-released first.', '/rss/subjects/' . Formatter::MakeUrlSafe((string)$subject), WEB_ROOT . '/rss/subjects/' . Formatter::MakeUrlSafe((string)$subject) . '.xml', $ebooks); $subjectRssFeed->SaveIfChanged(); } // Now create the Atom feeds // Create the 'newest' feed $newestAtomFeed = new AtomFeed('Standard Ebooks - Newest Ebooks', 'The ' . number_format($ebooksPerNewestEbooksFeed) . ' latest Standard Ebooks, most-recently-released first.', '/atom/new-releases', WEB_ROOT . '/atom/new-releases.xml', $newestEbooks); $newestAtomFeed->SaveIfChanged(); // Create the 'all' feed $allAtomFeed = new AtomFeed('Standard Ebooks - All Ebooks', 'All Standard Ebooks, most-recently-released first.', '/atom/all', WEB_ROOT . '/atom/all.xml', $allEbooks); $allAtomFeed->SaveIfChanged(); // Generate each individual subject feed foreach($ebooksBySubject as $subject => $ebooks){ krsort($ebooks); $subjectAtomFeed = new AtomFeed('Standard Ebooks - ' . (string)$subject . ' Ebooks', 'Standard Ebooks tagged with “' . strtolower($subject) . ',” most-recently-released first.', '/atom/subjects/' . Formatter::MakeUrlSafe((string)$subject), WEB_ROOT . '/atom/subjects/' . Formatter::MakeUrlSafe((string)$subject) . '.xml', $ebooks); $subjectAtomFeed->SaveIfChanged(); } ?>