Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/Controller/BooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
31 changes: 31 additions & 0 deletions app/View/Books/xml/index.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
$feed = $this->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;
?>
9 changes: 9 additions & 0 deletions app/View/Books/xml/opds.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
44 changes: 44 additions & 0 deletions app/View/Books/xml/view.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
$key = $book['Book']['sort'];
$feed = $this->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;
?>