Esempio n. 1
0
         $download['statusMessage'] = "Failed to download chapter {$download['currentChapter']}.";
         unset($_SESSION[$download['id']]);
     }
 } else {
     if ($download['status'] == Status::DOWNLOAD_COMPLETE) {
         $download['status'] = Status::BUILDING;
     } else {
         if ($download['status'] == Status::BUILDING) {
             if ($activeBuilds >= 1) {
                 continue;
             }
             $activeBuilds++;
             try {
                 $book = new \PHPePub\Core\EPub();
                 $book->setTitle($download['story']['title']);
                 $book->setAuthor($download['story']['author'], $download['story']['author']);
                 $book->setIdentifier($download['id'], PHPePub\Core\EPub::IDENTIFIER_UUID);
                 $book->setSourceURL($download['story']['url']);
                 if (!empty($download['story']['description'])) {
                     $book->setDescription($download['story']['description']);
                 }
                 $contentStart = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n" . "    \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" . "<head>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" . "<title>" . $download['story']['title'] . "</title>\n" . "<style type=\"text/css\">\n" . "body{font-family:'Arial',sans-serif;}\n" . "</style>\n" . "</head>\n" . "<body>\n";
                 $contentEnd = "</body>\n</html>\n";
                 $book->addChapter($download['story']['title'] . " by " . $download['story']['author'], 'Cover.html', $contentStart . '<div style="text-align: center;">' . '<h1>' . htmlspecialchars($download['story']['title']) . '</h1>' . '<h3><i>by ' . $download['story']['author'] . '</i></h3>' . '<div style="text-align: left;">' . $download['story']['description'] . '</div>' . '<div style="text-align: left;">URL: <a href="' . $download['story']['url'] . '">' . $download['story']['url'] . '</a></div>' . '</div>' . $contentEnd);
                 if ($download['totalChapters'] > 1) {
                     $book->buildTOC();
                 }
                 foreach ($_SESSION[$download['id']] as $chapter) {
                     $chapterTitle = htmlspecialchars($chapter['title']);
                     if ($book->addChapter($chapterTitle, $book->sanitizeFileName($chapter['title']) . ".html", $contentStart . '<h2 style="text-align: center;">' . $chapterTitle . '</h2>' . PHP_EOL . '<div>' . PHP_EOL . $chapter['content'] . PHP_EOL . '</div>' . $contentEnd) === FALSE) {
                         $download['status'] = Status::ERROR;