Example #1
0
 /**
  * Read book method.
  *
  * @throws NotFoundException
  * @param string $id
  * @param string $extension
  * @return void
  */
 public function read($id = null, $extension = null)
 {
     if (!$this->Book->exists($id)) {
         throw new NotFoundException(__('Invalid book'));
     }
     if (!$extension) {
         throw new NotFoundException(__('Invalid extension'));
     }
     $extension = strtolower($extension);
     $options = array('conditions' => array('Book.' . $this->Book->primaryKey => $id), 'recursive' => 1);
     $book = $this->Book->find('first', $options);
     $fileName = '';
     foreach ($book['Datum'] as $file) {
         if ($file['format'] == strtoupper($extension)) {
             $fileName = $file['name'];
         }
     }
     if (!$fileName) {
         throw new NotFoundException(__('Invalid file name or extension'));
     }
     $book['File'] = array('file_name' => $fileName, 'file_path' => $book['Book']['path'] . DS . $fileName . '.' . $extension, 'extension' => $extension);
     $bookReader = new BookReader\Reader($this->Book->getCalibrePath() . $book['File']['file_path']);
     $this->autoRender = false;
     $this->layout = false;
     $this->set(array('book' => $book, 'reader' => $bookReader->read($this->request)));
     $this->render('/Books/read');
 }
Example #2
0
 /**
  * ebookLinks
  *
  * @param array $files to provide links for
  * @return string a string with the links to all the book formats items
  */
 public function ebookLinks($files = array(), $divClass = 'btn-toolbar', $positionClass = 'pull-right')
 {
     $links = '';
     // Downloads links
     $downloadLinks = array();
     foreach ($files as $key => $file) {
         $downloadLinks[] = '<li>' . $this->Html->link($file['format'] . ' <small>(' . $this->Number->toReadableSize($file['uncompressed_size']) . ')</small>', array('controller' => 'books', 'action' => 'download', $file['book'], strtolower($file['format'])), array('escape' => false, 'title' => $this->Number->toReadableSize($file['uncompressed_size']))) . '</li>';
     }
     if (count($downloadLinks) > 0) {
         $links .= '<div class="btn-group">';
         $links .= '<button class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="icon-download"></i> ' . __("Download") . ' <span class="caret"></span></button>';
         $links .= '<ul class="dropdown-menu ' . $positionClass . '">' . implode("", $downloadLinks) . '</ul>';
         $links .= '</div> ';
     }
     // Views links
     $viewLinks = array();
     foreach ($files as $key => $file) {
         if (!BookReader\Reader::hasSupported($file['format'])) {
             continue;
         }
         $viewLinks[] = '<li>' . $this->Html->link($file['format'], array('controller' => 'books', 'action' => 'read', $file['book'], strtolower($file['format'])), array('escape' => false, 'target' => '_blank')) . '</li>';
     }
     if (count($viewLinks) > 0) {
         $links .= '<div class="btn-group">';
         $links .= '<button class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="icon-eye-open"></i> ' . __("Read") . ' <span class="caret"></span></button>';
         $links .= '<ul class="dropdown-menu ' . $positionClass . '">' . implode("", $viewLinks) . '</ul>';
         $links .= '</div> ';
     }
     // E-Mail / Share
     $formats = array();
     foreach ($files as $file) {
         $formats[$file['format']] = $file['format'];
     }
     $emailTargets = array();
     foreach ($this->getShareConfig() as $email => $emailFormats) {
         $emailFormats = (array) explode(",", strtoupper($emailFormats));
         foreach ($emailFormats as $format) {
             if (isset($formats[$format])) {
                 $emailTargets[$email] = $format;
                 continue 2;
             }
         }
     }
     $shareLinks = array();
     foreach ($emailTargets as $email => $format) {
         $url = $this->Html->url(array('controller' => 'books', 'action' => 'share', $files[0]['book'], $email, $format));
         $shareLinks[] = '<li><a href="#" class="calibre-share" data-share-url="' . $url . '">' . $email . '</a></li>';
     }
     if (!empty($shareLinks)) {
         $links .= '<div class="btn-group">';
         $links .= '<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown"><i class="icon-envelope icon-white"></i> ' . __("Share") . ' <span class="caret"></span></button>';
         $links .= '<ul class="dropdown-menu ' . $positionClass . '">' . implode("", $shareLinks) . '</ul>';
         $links .= '</div>';
     }
     if ($links) {
         return '<div class="' . $divClass . '">' . $links . '</div>';
     } else {
         return '';
     }
 }