%PDF- %PDF-
Direktori : /www/varak.net/povidky.varak.net/app/presenters/ |
Current File : /www/varak.net/povidky.varak.net/app/presenters/BookshelfPresenter.php |
<?php use Nette\Diagnostics\Debugger; use Nette\Application\Responses; /** * Homepage presenter. */ class BookshelfPresenter extends BasePresenter { /** * @var Bookshelf Bookshelf model */ 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'); } } public function renderDefault() { } 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 renderSubgenre($id) { $this->template->data = $this->model->getBooksByGenre($id)->fetchAll(); $this->template->id = $id; } public function actionGenre($id) { $this->template->data = $this->model->getSubgenres($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(); } } }