diff --git a/app/Controller/BooksController.php b/app/Controller/BooksController.php index 7eaecfe..99352da 100644 --- a/app/Controller/BooksController.php +++ b/app/Controller/BooksController.php @@ -20,10 +20,18 @@ class BooksController extends AppController { * @return void */ public function index() { - $this->Book->recursive = 1; - $this->set('books', $this->paginate()); + if ($this->layoutPath == 'xml') { + $this->Book->recursive = 0; + $books = $this->paginate(); + $info = $this->Book->getInfo(); + $this->set(compact('books', 'info')); + } else { + $this->Book->recursive = 1; + $this->set('books', $this->paginate()); + } } + /** * view method * diff --git a/app/View/Books/xml/index.ctp b/app/View/Books/xml/index.ctp new file mode 100644 index 0000000..0aa78a8 --- /dev/null +++ b/app/View/Books/xml/index.ctp @@ -0,0 +1,31 @@ +Opds->getDefaultXmlArray(array( + 'title' => 'Calibre Books', + 'id' => array('calibre:books'), + 'updated' => $info['summary']['updated'], + )); + + $feed = $this->Opds->addLink($feed, array( + 'href' => $this->Html->url(array('controller'=>'books', 'action'=>'opds.xml'), false), + 'rel' => 'start', + 'title' => 'Home', + )); + + $feed = $this->Opds->addLink($feed, array( + 'href' => $this->Html->url(array('controller'=>'books', 'action'=>'index.xml'), false), + 'rel' => 'self', + )); + + foreach ($info['Book'] as $book) { + $feed = $this->Opds->addEntry($feed, array( + 'link' => $this->Html->url(array('controller'=>'books', 'action'=>'view', $book['id']. '.xml'), false), + 'title' => $book['name'], + 'updated' => $book['updated'], + 'id' => 'calbire:books:' . $book['id'] + )); + } + + $xmlObject = Xml::fromArray($feed); + $feed = $xmlObject->asXML(); + echo $feed; +?> \ No newline at end of file diff --git a/app/View/Books/xml/opds.ctp b/app/View/Books/xml/opds.ctp index 24dcdb5..5468b7b 100644 --- a/app/View/Books/xml/opds.ctp +++ b/app/View/Books/xml/opds.ctp @@ -16,6 +16,14 @@ 'rel' => 'self' )); + $feed = $this->Opds->addEntry($feed, array( + 'link' => $this->Html->url(array('controller'=>'books', 'action'=>'index.xml'), false), + 'title' => 'By Title', + 'updated' => $info['books']['summary']['updated'], + 'id' => 'calbire:books', + 'content' => 'books sorted by ' . $this->Txt->numberToWords($info['books']['summary']['count'], true) . ' titles', + )); + $feed = $this->Opds->addEntry($feed, array( 'link' => $this->Html->url(array('controller'=>'authors', 'action'=>'index.xml'), false), 'title' => 'By Author', @@ -24,6 +32,7 @@ 'content' => 'books sorted by ' . $this->Txt->numberToWords($info['authors']['summary']['count'], true) . ' authors', )); + $feed = $this->Opds->addEntry($feed, array( 'link' => $this->Html->url(array('controller'=>'publishers', 'action'=>'index.xml'), false), 'title' => 'By Publisher', diff --git a/app/View/Books/xml/view.ctp b/app/View/Books/xml/view.ctp new file mode 100644 index 0000000..564490b --- /dev/null +++ b/app/View/Books/xml/view.ctp @@ -0,0 +1,44 @@ +Opds->getDefaultXmlArray(array( + 'title' => $book['Book']['sort'], + 'id' => array('calibre:book:' . $book['Book']['id']), + 'updated' => $info['summary']['updated'], + )); + + $feed = $this->Opds->addLink($feed, array( + 'href' => $this->Html->url(array('controller'=>'books', 'action'=>'opds'), false), + 'rel' => 'start', + 'title' => 'Home', + )); + + $feed = $this->Opds->addLink($feed, array( + 'href' => $this->Html->url(array('controller'=>'books', 'action'=>'view', $book['Book']['id'] . '.xml'), false), + 'rel' => 'self', + )); + + $entry = array( + 'link' => $this->Html->url(array('controller'=>'books', 'action'=>'view', $book['Book']['id']. '.xml'), false), + 'title' => $book['Book']['sort'], + 'updated' => date(DATE_ATOM, strtotime($book['Book']['last_modified'])), + 'id' => 'urn:uuid:' . $book['Book']['uuid'], + 'content' => '', + 'author' => $book['Author'], + 'published' => date(DATE_ATOM, strtotime($book['Book']['pubdate'])), + 'download' => array('downloads' => $book['Datum'], 'bookpath' => $book['Book']['path']), + 'tag' => $book['Tag'], + ); + + if (!empty($book['Series'])) { + $entry['content'] = 'Book ' . $book['Book']['series_index'] . ' in the ' . $book['Series'][0]['sort'] . ' series'; + } + if ($book['Book']['has_cover']) { + $entry['thumbnail'] = $this->Image->resizeUrl($book['Book']['path'], $this->Image->resizeSettings['view']); + $entry['image'] = $this->Image->resizeUrl($book['Book']['path'], $this->Image->resizeSettings['opds']); + } + $feed = $this->Opds->addEntry($feed, $entry); + + $xmlObject = Xml::fromArray($feed); + $feed = $xmlObject->asXML(); + echo $feed; +?> \ No newline at end of file