コード例 #1
0
$book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd);
if ($book->isLogging) {
    // Only used in case we need to debug EPub.php.
    $epuplog = $book->getLog();
    $book->addChapter("ePubLog", "ePubLog.html", $content_start . $epuplog . "\n</pre>" . $bookEnd);
}
$book->finalize();
// Finalize the book, and build the archive.
// This is not really a part of the EPub class, but IF you have errors and want to know about them,
//  they would have been written to the output buffer, preventing the book from being sent.
//  This behaviour is desired as the book will then most likely be corrupt.
//  However you might want to dump the output to a log, this example section can do that:
/*
if (ob_get_contents() !== false && ob_get_contents() != '') {
   $f = fopen ('./log.txt', 'a') or die("Unable to open log.txt.");
   fwrite($f, "\r\n" . date("D, d M Y H:i:s T") . ": Error in " . __FILE__ . ": \r\n");
   fwrite($f, ob_get_contents() . "\r\n");
   fclose($f);
}
* or just:
	$bufferData = ob_get_contents();
	ob_end_clean();
*/
// Save book as a file relative to your script (for local ePub generation)
// Notice that the extions .epub will be added by the script.
// The second parameter is a directory name which is '.' by default. Don't use trailing slash!
//$book->saveBook('epub-filename', '.');
// Send the book to the client. ".epub" will be appended if missing.
$zipData = $book->sendBook("ExampleBook2");
// After this point your script should call exit. If anything is written to the output,
// it'll be appended to the end of the book, causing the epub file to become corrupt.
コード例 #2
0
ファイル: epub.php プロジェクト: YesWiki/yeswiki-sandstorm
        $cssData .= file_get_contents($value);
    }
    $book->addCSSFile("styles.css", "css1", $cssData);
    // This test requires you have an image, change "demo/cover-image.jpg" to match your location.
    $book->setCoverImage("Cover.jpg", file_get_contents($metadatas["ebook-cover-image"]), "image/jpeg");
    // Titre et courte description de l'ouvrage
    $cover = $content_start . '<h1>' . $metadatas["ebook-title"] . '</h1>' . "\n" . '<h2>' . _t('TAGS_BY') . ': ' . $metadatas["ebook-author"] . '</h2>' . "\n" . $metadatas["ebook-description"] . $bookEnd;
    $book->addChapter(_t('TAGS_ABOUT_THIS_EBOOK'), "Cover.html", $cover);
    // on recupere les include pour faire les chapitres
    preg_match_all("/{{include.*page=\"(.*)\".*class=\"(.*)\".*}}/U", $this->page["body"], $matches);
    foreach ($matches[1] as $nb => $pageWiki) {
        $page = $this->LoadPage($pageWiki);
        $url = explode('wakka.php', $this->config['base_url']);
        if (TEMPLATES_DEFAULT_CHARSET != 'UTF-8') {
            $contentpage = utf8_encode($content_start . str_replace('<img src="' . $url[0], '<img src="', $this->Format('{{include page="' . $pageWiki . '" class="' . $matches[2][$nb] . '"}}')) . $bookEnd);
        } else {
            $contentpage = $content_start . str_replace('<img src="' . $url[0], '<img src="', $this->Format('{{include page="' . $pageWiki . '" class="' . $matches[2][$nb] . '"}}')) . $bookEnd;
        }
        $book->addChapter(get_title_from_body($page), $pageWiki . ".html", $contentpage, false, EPub::EXTERNAL_REF_ADD);
    }
    $book->finalize();
    // Finalize the book, and build the archive.
    // Save book as a file relative to your script (for local ePub generation)
    // Notice that the extions .epub will be added by the script.
    // The second parameter is a directory name which is '.' by default. Don't use trailing slash!
    $book->saveBook($this->getPageTag(), 'cache');
    // Send the book to the client. ".epub" will be appended if missing.
    $zipData = $book->sendBook($this->getPageTag());
} else {
    echo $this->Header() . '<div class="alert alert-danger">' . _t('TAGS_NO_EBOOK_METADATAS') . '</div>' . $this->Footer();
}
}
// Notice that Chapter 1 have an image reference in paragraph 2?
// We can tell EPub to automatically load embedded images and other references:
// The parameters for addChapter are:
//  1: Chapter Name
//  2: File Name (in the book)
//  3: Chapter Data (HTML or array of HTML strings making up one chapter)
//  4: Auto Split Chapter (Default false)
//  5: External References, How to handle external references, default is EPub::EXTERNAL_REF_IGNORE
//  6: Base Dir, This is important, as this have to point to the root of the imported HTML, as seen from it's Document root.
//     if you are importing an HTML designed to live in "http://server/story/book.html", $baseDir must be "story"
//     It is used to resolve any links in the HTML.
$book->addChapter("Chapter 6: Image test", "Chapter006.html", $chapter1, false, EPub::EXTERNAL_REF_ADD, $fileDir);
$book->finalize();
// Finalize the book, and build the archive.
// This is not really a part of the EPub class, but IF you have errors and want to know about them,
//  they would have been written to the output buffer, preventing the book from being sent.
//  This behaviour is desired as the book will then most likely be corrupt.
//  However you might want to dump the output to a log, this example section can do that:
/* 
if (ob_get_contents() !== false && ob_get_contents() != '') {
	$f = fopen ('./log.txt', 'a') or die("Unable to open log.txt.");
	fwrite($f, "\r\n" . date("D, d M Y H:i:s T") . ": Error in " . __FILE__ . ": \r\n");
	fwrite($f, ob_get_contents() . "\r\n");
	fclose($f);
}
*/
// Send the book to the client. ".epub" will be appended if missing.
$zipData = $book->sendBook("Example1Book");
// After this point your script should call exit. If anything is written to the output,
// it'll be appended to the end of the book, causing the epub file to become corrupt.
コード例 #4
0
// Title and Identifier are mandatory!
$book->setTitle("Simple Test book");
$book->setIdentifier("http://JohnJaneDoePublications.com/books/TestBookSimple.html", EPub::IDENTIFIER_URI);
// Could also be the ISBN number, prefered for published books, or a UUID.
$book->setLanguage("en");
// Not needed, but included for the example, Language is mandatory, but EPub defaults to "en". Use RFC3066 Language codes, such as "en", "da", "fr" etc.
$book->setDescription("This is a brief description\nA test ePub book as an example of building a book in PHP");
$book->setAuthor("John Doe Johnson", "Johnson, John Doe");
$book->setPublisher("John and Jane Doe Publications", "http://JohnJaneDoePublications.com/");
// I hope this is a non existant address :)
$book->setDate(time());
// Strictly not needed as the book date defaults to time().
$book->setRights("Copyright and licence information specific for the book.");
// As this is generated, this _could_ contain the name or licence information of the user who purchased the book, if needed. If this is used that way, the identifier must also be made unique for the book.
$book->setSourceURL("http://JohnJaneDoePublications.com/books/TestBookSimple.html");
// A book need styling, in this case we use static text, but it could have been a file.
$cssData = "body {\n  margin-left: .5em;\n  margin-right: .5em;\n  text-align: justify;\n}\n\np {\n  font-family: serif;\n  font-size: 10pt;\n  text-align: justify;\n  text-indent: 1em;\n  margin-top: 0px;\n  margin-bottom: 1ex;\n}\n\nh1, h2 {\n  font-family: sans-serif;\n  font-style: italic;\n  text-align: center;\n  background-color: #6b879c;\n  color: white;\n  width: 100%;\n}\n\nh1 {\n    margin-bottom: 2px;\n}\n\nh2 {\n    margin-top: -2px;\n    margin-bottom: 2px;\n}\n";
$book->addCSSFile("styles.css", "css1", $cssData);
// Add cover page
$cover = $content_start . "<h1>Test Book</h1>\n<h2>By: John Doe Johnson</h2>\n" . $bookEnd;
$book->addChapter("Notices", "Cover.html", $cover);
$chapter1 = $content_start . "<h1>Chapter 1</h1>\n" . "<h2>Lorem ipsum</h2>\n" . "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec magna lorem, mattis sit amet porta vitae, consectetur ut eros. Nullam id mattis lacus. In eget neque magna, congue imperdiet nulla. Aenean erat lacus, imperdiet a adipiscing non, dignissim eget felis. Nulla facilisi. Vivamus sit amet lorem eget mauris dictum pharetra. In mauris nulla, placerat a accumsan ac, mollis sit amet ligula. Donec eget facilisis dui. Cras elit quam, imperdiet at malesuada vitae, luctus id orci. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque eu libero in leo ultrices tristique. Etiam quis ornare massa. Donec in velit leo. Sed eu ante tortor.</p>\n" . "<p><img src=\"http://www.grandt.com/ePub/AnotherHappilyMarriedCouple.jpg\" alt=\"Test Image retrieved off the internet: Another happily married couple\" />Nullam at tempus enim. Nunc et augue non lectus consequat rhoncus ac a odio. Morbi et tellus eget nisi volutpat tincidunt. Curabitur tristique neque tincidunt purus blandit bibendum. Maecenas eleifend sem quis magna semper id pulvinar nisi porttitor. In in lectus accumsan eros tristique pharetra sit amet ac nulla. Nam vitae felis et orci congue porta nec non ipsum. Donec pretium blandit accumsan. In aliquam lacinia nisi, ut venenatis mauris condimentum ut. Morbi rutrum orci et nisl accumsan euismod. Etiam viverra luctus sem pellentesque suscipit. Aliquam ultricies egestas risus at eleifend. Ut lacinia, tortor non varius malesuada, massa diam aliquet augue, vitae tempor metus tellus eget diam. Nulla vel augue eu elit adipiscing egestas. Duis et nulla est, ac congue arcu. Phasellus semper, ipsum et blandit rutrum, erat ante semper quam, at iaculis quam tellus sed neque.</p>\n" . "<p>Pellentesque vulputate sollicitudin justo, at faucibus nisl convallis in. Nulla facilisi. Curabitur nec mauris eu justo ultricies ultricies gravida eu ipsum. Pellentesque at nunc velit, vitae congue nisl. Nam varius imperdiet leo eu accumsan. Nullam elementum fermentum diam euismod porttitor. Etiam sed pellentesque ante. Donec in est elementum mi tempor consectetur. Fusce orci lorem, mollis at tincidunt eget, fringilla sed nunc. Ut consectetur condimentum condimentum. Phasellus sed felis non massa gravida euismod ut in tellus. Curabitur suscipit pharetra sapien vitae dignissim. Morbi id arcu nec ante viverra lobortis vitae nec quam. Mauris id gravida odio. Nunc non sem nisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque hendrerit volutpat nisl id elementum. Vivamus lobortis iaculis nisi, sit amet tristique risus porttitor vel. Suspendisse potenti.</p>\n" . "<p>Quisque aliquet sapien leo, vitae eleifend dolor. Fusce quis tincidunt nunc. Nam nec purus nulla, ac eleifend lorem. Curabitur eu quam et nibh egestas mattis. Maecenas eget felis augue. Integer scelerisque commodo urna, a pulvinar tortor euismod et. Praesent in nunc sapien. Ut iaculis auctor neque, sit amet rutrum est faucibus vitae. Sed a sagittis quam. Quisque interdum luctus fringilla. Vestibulum vitae nunc in felis luctus ultricies at id magna. Nam volutpat sapien ac lorem interdum pellentesque. Suspendisse faucibus, leo vitae laoreet interdum, mi mi pulvinar neque, sit amet tristique sapien nulla nec dolor. Etiam non ligula augue.</p>\n" . "<p>Vivamus purus elit, ornare eget accumsan ut, luctus et orci. Sed vestibulum turpis ut quam vehicula id hendrerit velit suscipit. Pellentesque pulvinar, libero vitae sagittis scelerisque, felis ante faucibus risus, ut viverra velit mi at tortor. Aliquam lacinia condimentum felis, eu elementum ligula laoreet vitae. Sed placerat tempus turpis a fringilla. Etiam porta accumsan feugiat. Phasellus et cursus magna. Suspendisse vitae odio sit amet urna vulputate consectetur. Vestibulum massa magna, sagittis at dictum vitae, sagittis scelerisque erat. Donec viverra tincidunt lacus. Maecenas fermentum erat et mauris tincidunt sed eleifend quam tempus. In at augue mi, in tincidunt arcu. Duis dapibus aliquet mi, ac ullamcorper est semper quis. Sed nec nulla nec odio malesuada viverra id sed nulla. Donec lobortis euismod aliquam. Praesent sit amet dolor quis lacus auctor lobortis. In hac habitasse platea dictumst. Sed at nisi sed nisi ullamcorper pellentesque. Vivamus eget enim sem, non laoreet leo. Sed vel odio lacus.</p>\n" . $bookEnd;
$book->addChapter("Chapter 1: Lorem ipsum", "Chapter001.html", $chapter1, true, EPub::EXTERNAL_REF_ADD);
$chapter2 = $content_start . "<h1>Chapter 2</h1>\n" . "<h2>Vivamus bibendum massa</h2>\n" . "<p>Vivamus bibendum massa ac magna congue gravida. Curabitur nulla ante, accumsan sit amet luctus a, fermentum ut diam. Maecenas porttitor faucibus mattis. Ut auctor aliquet ligula nec posuere. Nullam arcu turpis, dapibus sit amet tempor nec, cursus at augue. Aliquam sed sem velit, id sagittis mauris. Donec sed ipsum nisi, id scelerisque felis. Cras lacus est, fermentum in ultricies eu, congue in elit. Nulla tincidunt posuere eros, eget suscipit tellus porta vel. Aliquam ut sollicitudin libero. Suspendisse potenti. Sed cursus dignissim nulla in elementum. Aliquam id quam justo, sit amet laoreet ligula. Etiam pellentesque tellus a nisi commodo eu sodales ante commodo. Vestibulum ultricies sapien arcu. Proin nunc mauris, ultrices id imperdiet ac, malesuada ac nunc. Nunc a mi quis nunc ultricies rhoncus. Mauris pellentesque eros eu augue congue ac tincidunt est gravida.</p>\n" . "<p>Integer lobortis facilisis magna, non tristique sem facilisis ut. Sed id nisi diam. Nulla viverra lectus ut purus tempus sagittis. Quisque dictum enim tempus ipsum mollis blandit. Cras in mi non nulla imperdiet fringilla at blandit urna. Donec vel dui quis sem congue ullamcorper nec a massa. Vivamus in dui nunc. Donec sit amet augue odio, at imperdiet lacus. Mauris sit amet magna justo. Maecenas ultrices orci ultrices sapien ornare eget consequat nisl tristique. Integer non mi ac eros vehicula pharetra. Curabitur risus augue, sollicitudin vitae pharetra interdum, sollicitudin sit amet magna. Nunc sit amet est lacus, vel sodales elit. Duis dolor lorem, convallis eu dignissim quis, vulputate at nibh.</p>\n" . "<p>Praesent gravida, sapien aliquet interdum elementum, magna mauris hendrerit eros, blandit posuere lectus neque sed massa. Cras ultricies rhoncus mi, vitae posuere ligula scelerisque sit amet. Cras porttitor congue odio, sit amet tristique magna euismod id. Cras enim dolor, scelerisque eget egestas vel, consectetur vel purus. Aenean et convallis felis. Mauris in arcu sollicitudin ipsum lobortis fringilla. Suspendisse felis mauris, convallis ac blandit interdum, imperdiet eget massa. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris scelerisque velit quis augue commodo tristique. Maecenas dictum dui congue enim tristique vel mattis neque luctus. Fusce neque dui, laoreet suscipit varius sed, mattis sit amet diam. Nullam elementum, ante non cursus imperdiet, eros dui placerat elit, sit amet elementum erat risus eget nunc.</p>\n" . "<p id=\"internalLink\">Nam tellus nibh, vehicula a laoreet non, fermentum vel leo. Proin id augue tellus. Donec placerat pharetra interdum. Aliquam vestibulum viverra bibendum. Nullam auctor congue tortor. Sed sagittis, massa ac cursus malesuada, ipsum velit aliquam lectus, quis tincidunt tellus risus id justo. Suspendisse sodales adipiscing eros, ut pulvinar eros suscipit in. Fusce vel libero id urna blandit pharetra. Cras aliquam suscipit ultrices. Vivamus luctus tristique vestibulum. Nam placerat dolor ipsum. Nulla vitae tristique sapien. Nulla laoreet ante ut elit dictum ultricies. Fusce mi tortor, commodo sit amet tincidunt semper, pellentesque nec ante. Vestibulum nec dui at massa adipiscing pulvinar. Integer ultrices tristique odio, iaculis bibendum metus fringilla id. Ut ac elit ac enim convallis dignissim pharetra id purus. Nunc pulvinar blandit nulla, in ornare erat condimentum id. Sed sit amet placerat est. Curabitur pretium tellus in velit aliquet eu dictum arcu consectetur.</p>\n" . "<p>In hac habitasse platea dictumst. Integer lectus augue, varius nec rutrum non, fringilla eu neque. Curabitur a gravida velit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque vestibulum orci ac ligula interdum dapibus. Maecenas sollicitudin aliquet libero in sodales. In tempor orci vitae nisi imperdiet at varius sem dignissim. Aenean tortor libero, pellentesque eget hendrerit id, ullamcorper in justo. Sed euismod egestas est vitae convallis. Nunc tempus lacinia purus condimentum mattis. Sed id elementum est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In nec tempus eros. </p>\n" . $bookEnd;
$book->addChapter("Chapter 2: Vivamus bibendum massa", "Chapter002.html", $chapter2, true, EPub::EXTERNAL_REF_ADD);
$book->finalize();
// Finalize the book, and build the archive.
// Send the book to the client. ".epub" will be appended if missing.
$zipData = $book->sendBook("ExampleBookSimple");
// After this point your script should call exit. If anything is written to the output,
// it'll be appended to the end of the book, causing the epub file to become corrupt.
コード例 #5
0
 /**
  * handle ePub
  */
 public function produceEpub()
 {
     Tools::logm('Starting to produce ePub 3 file');
     try {
         $content_start = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n" . "<head>" . "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n" . "<title>" . _("wallabag articles book") . "</title>\n" . "</head>\n" . "<body>\n";
         $bookEnd = "</body>\n</html>\n";
         $log = new Logger("wallabag", TRUE);
         $fileDir = CACHE;
         $book = new EPub(EPub::BOOK_VERSION_EPUB3, DEBUG_POCHE);
         $log->logLine("new EPub()");
         $log->logLine("EPub class version: " . EPub::VERSION);
         $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
         $log->logLine("Zip version: " . Zip::VERSION);
         $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
         $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());
         Tools::logm('Filling metadata for ePub...');
         $book->setTitle($this->bookTitle);
         $book->setIdentifier("http://{$_SERVER['HTTP_HOST']}", EPub::IDENTIFIER_URI);
         // Could also be the ISBN number, prefered for published books, or a UUID.
         //$book->setLanguage("en"); // Not needed, but included for the example, Language is mandatory, but EPub defaults to "en". Use RFC3066 Language codes, such as "en", "da", "fr" etc.
         $book->setDescription(_("Some articles saved on my wallabag"));
         $book->setAuthor($this->author, $this->author);
         $book->setPublisher("wallabag", "wallabag");
         // I hope this is a non existant address :)
         $book->setDate(time());
         // Strictly not needed as the book date defaults to time().
         //$book->setRights("Copyright and licence information specific for the book."); // As this is generated, this _could_ contain the name or licence information of the user who purchased the book, if needed. If this is used that way, the identifier must also be made unique for the book.
         $book->setSourceURL("http://{$_SERVER['HTTP_HOST']}");
         $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP");
         $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "wallabag");
         $cssData = "body {\n margin-left: .5em;\n margin-right: .5em;\n text-align: justify;\n}\n\np {\n font-family: serif;\n font-size: 10pt;\n text-align: justify;\n text-indent: 1em;\n margin-top: 0px;\n margin-bottom: 1ex;\n}\n\nh1, h2 {\n font-family: sans-serif;\n font-style: italic;\n text-align: center;\n background-color: #6b879c;\n color: white;\n width: 100%;\n}\n\nh1 {\n margin-bottom: 2px;\n}\n\nh2 {\n margin-top: -2px;\n margin-bottom: 2px;\n}\n";
         $log->logLine("Add Cover");
         $fullTitle = "<h1> " . $this->bookTitle . "</h1>\n";
         $book->setCoverImage("Cover.png", file_get_contents("themes/_global/img/appicon/apple-touch-icon-152.png"), "image/png", $fullTitle);
         $cover = $content_start . '<div style="text-align:center;"><p>' . _('Produced by wallabag with PHPePub') . '</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>' . $bookEnd;
         //$book->addChapter("Table of Contents", "TOC.xhtml", NULL, false, EPub::EXTERNAL_REF_IGNORE);
         $book->addChapter("Notices", "Cover2.html", $cover);
         $book->buildTOC();
         Tools::logm('Adding actual content...');
         foreach ($this->entries as $entry) {
             //set tags as subjects
             $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']);
             foreach ($tags as $tag) {
                 $book->setSubject($tag['value']);
             }
             $log->logLine("Set up parameters");
             $chapter = $content_start . $entry['content'] . $bookEnd;
             $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD);
             $log->logLine("Added chapter " . $entry['title']);
         }
         if (DEBUG_POCHE) {
             $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd);
             // log generation
             Tools::logm('Production log available in produced file');
         }
         $book->finalize();
         $zipData = $book->sendBook($this->bookFileName);
         Tools::logm('Ebook produced');
     } catch (Exception $e) {
         Tools::logm('PHPePub has encountered an error : ' . $e->getMessage());
         $this->wallabag->messages->add('e', $e->getMessage());
     }
 }
コード例 #6
0
function create_epub($title, $qry_articles, $external_content)
{
    $configManager = new Configuration();
    $configManager->getAll();
    $nbArticles = mysql_num_rows($qry_articles);
    // TODO PHP 5.5.0, remove this function to use mysqli_stmt_num_rows or PDO
    if ($nbArticles > 0) {
        // Epub initialisation
        switch ($configManager->get('epub_version')) {
            case 3:
                $book = new EPub(EPub::BOOK_VERSION_EPUB3);
                $epubbook_start = constant("EPUBBOOK_HEAD_START_v3") . $title . constant("EPUBBOOK_HEAD_END");
                break;
            case 2:
            default:
                $book = new EPub(EPub::BOOK_VERSION_EPUB2);
                $epubbook_start = constant("EPUBBOOK_HEAD_START_v2") . $title . constant("EPUBBOOK_HEAD_END");
                break;
        }
        $book->setTitle($title);
        $book->setIdentifier("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "/" . $title, EPub::IDENTIFIER_URI);
        $book->setLanguage("fr");
        // TODO L10N
        $book->setDescription(_t('P_EPUB_BOOK_DESCRIPTION'));
        //$book->addCSSFile("styles.css", "css1", $cssData); //TODO add Leed css ?
        //$book->setCoverImage("Cover.jpg", file_get_contents("demo/cover-image.jpg"), "image/jpeg");
        $cover = $epubbook_start . "<h1>" . $title . "</h1>\n<h2>" . _t('P_EPUB_BYLEED') . "</h2>\n" . constant("EPUBBOOK_END");
        $book->addChapter("Notices", "Cover.html", $cover);
        // Epub chapters (articles) creation
        $chapNb = 1;
        while ($data = mysql_fetch_array($qry_articles)) {
            $title_article = html_entity_decode($data['title'], ENT_QUOTES, 'UTF-8');
            $author_article = html_entity_decode($data['creator'], ENT_QUOTES, 'UTF-8');
            $html_content = $epubbook_start . '<h2 class="articleTitle">' . $title_article . '</h2>' . '<h3 class="articleDetails">' . _t('P_EPUB_BY') . ' ' . $author_article . ' ' . _t('P_EPUB_ON_DATE') . ' ' . date("d/m/Y", $data['pubdate']) . ' ' . _t('P_EPUB_AT_TIME') . ' ' . date("H:i:s", $data['pubdate']) . '</h3>' . $data['content'] . constant("EPUBBOOK_END");
            $html_content = html_entity_decode($html_content, ENT_QUOTES, 'UTF-8');
            switch ($external_content) {
                case "textonly":
                    // Replace img tags by their alt value if possible (PHPePub make it only for Epub::EXTERNAL_REF_REPLACE_IMAGES)
                    $html_content = preg_replace('/<\\s*?img.*alt="(.*?)".*?>/', '[image: ${1}]', $html_content);
                    $html_content = preg_replace('/<\\s*?br.*(.*?)".*?>/', '[image: ${1}]', $html_content);
                    $book->addChapter($title_article, _t('P_EPUB_CHAPTER') . "_" . $chapNb . ".html", $html_content, true, EPub::EXTERNAL_REF_IGNORE);
                    break;
                case "noimage":
                    $book->addChapter($title_article, _t('P_EPUB_CHAPTER') . "_" . $chapNb . ".html", $html_content, true, EPub::EXTERNAL_REF_REPLACE_IMAGES);
                    break;
                case "full":
                default:
                    $book->addChapter($title_article, _t('P_EPUB_CHAPTER') . "_" . $chapNb . ".html", $html_content, true, EPub::EXTERNAL_REF_ADD);
                    break;
            }
            $chapNb++;
        }
        // Epub finalization
        $book->buildTOC();
        $book->finalize();
        $zipData = $book->sendBook(preg_replace("( )", '_', preg_replace("([^\\w\\s\\d\\,;\\[\\]\\(\\]])", '', $title)));
        exit;
    } else {
        echo _t('P_EPUB_NOARTICLES_WARNING');
    }
}
コード例 #7
0
ファイル: Poche.class.php プロジェクト: akoenig/wallabag
 /**
  * handle epub
  */
 public function createEpub()
 {
     switch ($_GET['method']) {
         case 'id':
             $entryID = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
             $entry = $this->store->retrieveOneById($entryID, $this->user->getId());
             $entries = array($entry);
             $bookTitle = $entry['title'];
             $bookFileName = substr($bookTitle, 0, 200);
             break;
         case 'all':
             $entries = $this->store->retrieveAll($this->user->getId());
             $bookTitle = sprintf(_('All my articles on '), date(_('d.m.y')));
             #translatable because each country has it's own date format system
             $bookFileName = _('Allarticles') . date(_('dmY'));
             break;
         case 'tag':
             $tag = filter_var($_GET['tag'], FILTER_SANITIZE_STRING);
             $tags_id = $this->store->retrieveAllTags($this->user->getId(), $tag);
             $tag_id = $tags_id[0]["id"];
             // we take the first result, which is supposed to match perfectly. There must be a workaround.
             $entries = $this->store->retrieveEntriesByTag($tag_id, $this->user->getId());
             $bookTitle = sprintf(_('Articles tagged %s'), $tag);
             $bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200);
             break;
         case 'category':
             $category = filter_var($_GET['category'], FILTER_SANITIZE_STRING);
             $entries = $this->store->getEntriesByView($category, $this->user->getId());
             $bookTitle = sprintf(_('All articles in category %s'), $category);
             $bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200);
             break;
         case 'search':
             $search = filter_var($_GET['search'], FILTER_SANITIZE_STRING);
             $entries = $this->store->search($search, $this->user->getId());
             $bookTitle = sprintf(_('All articles for search %s'), $search);
             $bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200);
             break;
         case 'default':
             die(_('Uh, there is a problem while generating epub.'));
     }
     $content_start = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n" . "<head>" . "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n" . "<title>wallabag articles book</title>\n" . "</head>\n" . "<body>\n";
     $bookEnd = "</body>\n</html>\n";
     $log = new Logger("wallabag", TRUE);
     $fileDir = CACHE;
     $book = new EPub(EPub::BOOK_VERSION_EPUB3, DEBUG_POCHE);
     $log->logLine("new EPub()");
     $log->logLine("EPub class version: " . EPub::VERSION);
     $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
     $log->logLine("Zip version: " . Zip::VERSION);
     $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
     $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());
     $book->setTitle(_('wallabag\'s articles'));
     $book->setIdentifier("http://{$_SERVER['HTTP_HOST']}", EPub::IDENTIFIER_URI);
     // Could also be the ISBN number, prefered for published books, or a UUID.
     //$book->setLanguage("en"); // Not needed, but included for the example, Language is mandatory, but EPub defaults to "en". Use RFC3066 Language codes, such as "en", "da", "fr" etc.
     $book->setDescription(_("Some articles saved on my wallabag"));
     $book->setAuthor("wallabag", "wallabag");
     $book->setPublisher("wallabag", "wallabag");
     // I hope this is a non existant address :)
     $book->setDate(time());
     // Strictly not needed as the book date defaults to time().
     //$book->setRights("Copyright and licence information specific for the book."); // As this is generated, this _could_ contain the name or licence information of the user who purchased the book, if needed. If this is used that way, the identifier must also be made unique for the book.
     $book->setSourceURL("http://{$_SERVER['HTTP_HOST']}");
     $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP");
     $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "wallabag");
     $cssData = "body {\n margin-left: .5em;\n margin-right: .5em;\n text-align: justify;\n}\n\np {\n font-family: serif;\n font-size: 10pt;\n text-align: justify;\n text-indent: 1em;\n margin-top: 0px;\n margin-bottom: 1ex;\n}\n\nh1, h2 {\n font-family: sans-serif;\n font-style: italic;\n text-align: center;\n background-color: #6b879c;\n color: white;\n width: 100%;\n}\n\nh1 {\n margin-bottom: 2px;\n}\n\nh2 {\n margin-top: -2px;\n margin-bottom: 2px;\n}\n";
     $log->logLine("Add Cover");
     $fullTitle = "<h1> " . $bookTitle . "</h1>\n";
     $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle);
     $cover = $content_start . '<div style="text-align:center;"><p>' . _('Produced by wallabag with PHPePub') . '</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>' . $bookEnd;
     //$book->addChapter("Table of Contents", "TOC.xhtml", NULL, false, EPub::EXTERNAL_REF_IGNORE);
     $book->addChapter("Notices", "Cover2.html", $cover);
     $book->buildTOC();
     foreach ($entries as $entry) {
         //set tags as subjects
         $tags = $this->store->retrieveTagsByEntry($entry['id']);
         foreach ($tags as $tag) {
             $book->setSubject($tag['value']);
         }
         $log->logLine("Set up parameters");
         $chapter = $content_start . $entry['content'] . $bookEnd;
         $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD);
         $log->logLine("Added chapter " . $entry['title']);
     }
     if (DEBUG_POCHE) {
         $epuplog = $book->getLog();
         $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd);
         // log generation
     }
     $book->finalize();
     $zipData = $book->sendBook($bookFileName);
 }