%PDF- %PDF-
| Direktori : /www/varak.net/catalog.varak.net/app/presenters/ |
| Current File : /www/varak.net/catalog.varak.net/app/presenters/BookshelfPresenter.php |
<?php
use Nette\Diagnostics\Debugger;
use Nette\Application\Responses;
/**
* Homepage presenter.
*/
class BookshelfPresenter extends BasePresenter
{
private $model;
public function injectModels(Bookshelf $model)
{
$this->model = $model;
}
public function startup()
{
parent::startup();
// Datetime NOW
$this->template->now = date('Y-m-d\\TH:i:sP');
$httpResponse = $this->getContext()->getService('httpResponse');
// Set right content-type
if(!Nette\Diagnostics\Debugger::isEnabled())
{
$httpResponse->setContentType('text/xml', 'UTF-8');
// $httpResponse->setContentType('application/atom+xml; profile=opds-catalog; kind=navigation; charset=utf-8');
}
}
public function renderDefault()
{
}
public function renderSeries()
{
}
public function renderAuthors($id)
{
if(isset($id) && $id != null)
{
$this->template->data = $this->model->getAuthorsBySurname($id)->fetchAll();
$this->template->id = $id;
}
else
{
$this->template->setFile(__DIR__.'/../templates/Bookshelf/authorsletters.latte');
$this->template->data = $this->model->getAuthorLetters()->fetchAll();
}
}
public function renderAuthor($id, $language = 0, $genre = 0)
{
$this->template->data = $this->model->getBooksByAuthor($id, $language, $genre)->fetchAll();
$this->template->id = $id;
}
public function renderGenres()
{
$this->template->data = $this->model->getGenres()->fetchAll();
}
public function renderGenre($id)
{
$this->template->data = $this->model->getBooksByGenre($id)->fetchAll();
$this->template->id = $id;
}
public function renderSeriesByName($id)
{
if(isset($id) && $id != null)
{
$this->template->data = $this->model->getSeriesByName($id)->fetchAll();
$this->template->id = $id;
}
else
{
$this->template->setFile(__DIR__.'/../templates/Bookshelf/seriesbynameletter.latte');
$this->template->data = $this->model->getSeriesLetters()->fetchAll();
}
}
public function renderSeriesByAuthors($id)
{
if(isset($id) && $id != null)
{
$this->template->data = $this->model->getSeriesByAuthorLetter($id)->fetchAll();
$this->template->id = $id;
}
else
{
$this->template->setFile(__DIR__.'/../templates/Bookshelf/seriesbyauthorletters.latte');
$this->template->data = $this->model->getSeriesLetters()->fetchAll();
}
}
public function renderSerie($id)
{
$this->template->data = $this->model->getBooksBySerie($id);
$this->template->id = $id;
}
public function renderSeriesByGenre($id)
{
if(isset($id) && $id != null)
{
$this->template->data = $this->model->getSeriesByGenre($id)->fetchAll();
$this->template->id = $id;
}
else
{
$this->template->setFile(__DIR__.'/../templates/Bookshelf/seriesbygenres.latte');
$this->template->data = $this->model->getSeriesGenres()->fetchAll();
}
}
public function renderSeriesByAuthor($id)
{
$this->template->data = $this->model->getSeriesByAuthor($id)->fetchAll();
$this->template->id = $id;
}
public function actionBook($id, $format)
{
// Determine shard no
$shard = floor($id / 1000);
$httpResponse = $this->getHttpResponse();
$file = false;
$fmime = "";
if($format == 'epub')
{
$file = realpath(__DIR__."/../books/$shard/$id.epub");
$fmime = 'application/epub+zip';
$fext = "epub";
}
elseif($format == 'mobi')
{
$file = realpath(__DIR__."/../books/$shard/$id.mobi");
$fmime = 'application/x-mobipocket-ebook';
$fext = "mobi";
}
if($file)
{
$this->model->increaseBookDownloadCounter($id);
$filename = $this->model->getBookName($id).".".$fext;
$httpResponse->setHeader('Pragma', "public");
$httpResponse->setHeader('Expires', 0);
$httpResponse->setHeader('Cache-Control', "must-revalidate, post-check=0, pre-check=0");
$httpResponse->setHeader('Content-Transfer-Encoding', "binary");
$httpResponse->setHeader('Content-Description', "File Transfer");
$httpResponse->setHeader('Content-Length', filesize($file));
$this->sendResponse(new Nette\Application\Responses\FileResponse($file, $filename, $fmime));
}
else
{
$httpResponse->setCode(Nette\Http\Response::S404_NOT_FOUND);
echo "Book $file ($shard/$id) not found";
$this->terminate();
}
}
}