File modified by Dawson for use in eBook Creator Added pagebreaks and a setting to remove table of contents.
Inheritance: extends ContentProvider
Ejemplo n.º 1
0
         $content = new OnlineArticle($url);
     }
     $mobi->setContentProvider($content);
     //Get title and make it a 12 character long filename
     $title = $mobi->getTitle();
     if ($title === false) {
         $title = 'file';
     }
     $title = urlencode(str_replace(' ', '_', strtolower(substr($title, 0, 12))));
     //Send the mobi file as download
     $mobi->download($title . '.mobi');
     die;
 } else {
     //Create the mobi object
     $mobi = new MOBI();
     $content = new MOBIFile();
     $content->set('title', 'My first eBook');
     $content->set('author', 'Me');
     $content->appendChapterTitle('Introduction');
     for ($i = 0, $lenI = rand(5, 10); $i < $lenI; ++$i) {
         $content->appendParagraph('P' . ($i + 1));
     }
     //Based on PHP's imagecreatetruecolor help paage
     $im = imagecreatetruecolor(220, 200);
     $text_color = imagecolorallocate($im, 233, 14, 91);
     imagestring($im, 10, 5, 5, 'A Simple Text String', $text_color);
     imagestring($im, 5, 15, 75, 'A Simple Text String', $text_color);
     imagestring($im, 3, 25, 125, 'A Simple Text String', $text_color);
     imagestring($im, 2, 10, 155, 'A Simple Text String', $text_color);
     $content->appendImage($im);
     imagedestroy($im);
Ejemplo n.º 2
0
             $title = formatTitle($title, $i);
             $filename = "Chapter" . ($i + 1) . ".html";
             $book->addChapter($title, $filename, $content_start . "<h2>{$title}</h2>" . $content . $bookEnd, true, EPub::EXTERNAL_REF_ADD);
         }
     }
     $book->finalize();
     $filename = $uniqid . "_" . $story["title"] . " - " . $story["author"] . ".epub";
     $book->saveBook($filename, "./tmp");
     if (!empty($email)) {
         mailAttachment($filename, "./tmp/", $email, $uniqid);
     }
 } else {
     if ($format == "mobi") {
         include_once "mobi/MOBI.php";
         $mobi = new MOBI();
         $mobiContent = new MOBIFile();
         $mobiContent->set("title", $story["title"]);
         $mobiContent->set("author", $story["author"]);
         $mobiContent->set("toc", true);
         $mobiContent->appendChapterTitle($story["title"]);
         $mobiContent->appendParagraph("by: " . $story["author"]);
         $mobiContent->appendPageBreak();
         for ($i = 0; $i < $numChapter; $i++) {
             $title = isset($story["chapters"]["title"][$i]) ? $story["chapters"]["title"][$i] : "";
             $content = isset($story["chapters"]["content"][$i]) ? $story["chapters"]["content"][$i] : "";
             if (!empty($content) && !empty($title)) {
                 $title = formatTitle($title, $i);
                 $mobiContent->appendChapterTitle($title);
                 $mobiContent->appendParagraph($content);
                 $mobiContent->appendPageBreak();
             }
Ejemplo n.º 3
0
         $content = new OnlineArticle($url);
     }
     $mobi->setContentProvider($content);
     //Get title and make it a 12 character long filename
     $title = $mobi->getTitle();
     if ($title === false) {
         $title = "file";
     }
     $title = urlencode(str_replace(" ", "_", strtolower(substr($title, 0, 12))));
     //Send the mobi file as download
     $mobi->download($title . ".mobi");
     die;
 } else {
     //Create the mobi object
     $mobi = new MOBI();
     $content = new MOBIFile();
     $content->set("title", "My first eBook");
     $content->set("author", "Me");
     $content->appendChapterTitle("Introduction");
     for ($i = 0, $lenI = rand(5, 10); $i < $lenI; $i++) {
         $content->appendParagraph("P" . ($i + 1));
     }
     //Based on PHP's imagecreatetruecolor help paage
     $im = imagecreatetruecolor(220, 200);
     $text_color = imagecolorallocate($im, 233, 14, 91);
     imagestring($im, 10, 5, 5, 'A Simple Text String', $text_color);
     imagestring($im, 5, 15, 75, 'A Simple Text String', $text_color);
     imagestring($im, 3, 25, 125, 'A Simple Text String', $text_color);
     imagestring($im, 2, 10, 155, 'A Simple Text String', $text_color);
     $content->appendImage($im);
     imagedestroy($im);
Ejemplo n.º 4
0
 /**
  * Use PHPMobi to dump a .mobi file.
  *
  * @return Response
  */
 private function produceMobi()
 {
     $mobi = new \MOBI();
     $content = new \MOBIFile();
     /*
      * Book metadata
      */
     $content->set('title', $this->title);
     $content->set('author', implode($this->authors));
     $content->set('subject', $this->title);
     /*
      * Front page
      */
     $content->appendParagraph($this->getExportInformation('PHPMobi'));
     if (file_exists($this->logoPath)) {
         $content->appendImage(imagecreatefrompng($this->logoPath));
     }
     $content->appendPageBreak();
     /*
      * Adding actual entries
      */
     foreach ($this->entries as $entry) {
         $content->appendChapterTitle($entry->getTitle());
         $content->appendParagraph($entry->getContent());
         $content->appendPageBreak();
     }
     $mobi->setContentProvider($content);
     // the browser inside Kindle Devices doesn't likes special caracters either, we limit to A-z/0-9
     $this->title = preg_replace('/[^A-Za-z0-9\\-]/', '', $this->title);
     return Response::create($mobi->toString(), 200, ['Accept-Ranges' => 'bytes', 'Content-Description' => 'File Transfer', 'Content-type' => 'application/x-mobipocket-ebook', 'Content-Disposition' => 'attachment; filename="' . $this->title . '.mobi"', 'Content-Transfer-Encoding' => 'binary']);
 }
Ejemplo n.º 5
0
 /**
  * MOBI Class
  * @author Sander Kromwijk
  */
 public function produceMobi()
 {
     try {
         Tools::logm('Starting to produce Mobi file');
         $mobi = new MOBI();
         $content = new MOBIFile();
         $messages = new Messages();
         // for later
         Tools::logm('Filling metadata for Mobi...');
         $content->set("title", $this->bookTitle);
         $content->set("author", $this->author);
         $content->set("subject", $this->bookTitle);
         # introduction
         $content->appendParagraph('<div style="text-align:center;" ><p>' . _('Produced by wallabag with PHPMobi') . '</p><p>' . _('Please open <a href="https://github.com/wallabag/wallabag/issues" >an issue</a> if you have trouble with the display of this E-Book on your device.') . '</p></div>');
         $content->appendImage(imagecreatefrompng("themes/_global/img/appicon/apple-touch-icon-152.png"));
         $content->appendPageBreak();
         Tools::logm('Adding actual content...');
         foreach ($this->entries as $item) {
             $content->appendChapterTitle($item['title']);
             $content->appendParagraph($item['content']);
             $content->appendPageBreak();
         }
         $mobi->setContentProvider($content);
         // the browser inside Kindle Devices doesn't likes special caracters either, we limit to A-z/0-9
         $this->bookFileName = preg_replace('/[^A-Za-z0-9\\-]/', '', $this->bookFileName);
         // we offer file to download
         $mobi->download($this->bookFileName . '.mobi');
         Tools::logm('Mobi file produced');
     } catch (Exception $e) {
         Tools::logm('PHPMobi has encountered an error : ' . $e->getMessage());
         $this->wallabag->messages->add('e', $e->getMessage());
     }
 }