1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-23 17:42:15 -05:00

Fix bugs and improved epub rendering

This commit is contained in:
tcit 2014-05-14 22:03:16 +02:00
parent 6a3c510157
commit f2b6b4e230
2 changed files with 28 additions and 26 deletions

View File

@ -574,7 +574,7 @@ class EPub {
* @param string $mimetype Image mimetype, such as "image/jpeg" or "image/png". * @param string $mimetype Image mimetype, such as "image/jpeg" or "image/png".
* @return bool $success * @return bool $success
*/ */
function setCover($fileName, $imageData = NULL, $mimetype = NULL, $coverText=NULL) { function setCoverImage($fileName, $imageData = NULL, $mimetype = NULL,$bookTitle) {
if ($this->isFinalized || $this->isCoverImageSet || array_key_exists("CoverPage.html", $this->fileList)) { if ($this->isFinalized || $this->isCoverImageSet || array_key_exists("CoverPage.html", $this->fileList)) {
return FALSE; return FALSE;
} }
@ -621,13 +621,13 @@ class EPub {
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\" xml:lang=\"en\">\n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\" xml:lang=\"en\">\n"
. "\t<head>\n" . "\t<head>\n"
. "\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n" . "\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"
. "\t\t<title>Cover</title>\n" . "\t\t<title>Cover Image</title>\n"
. "\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\"Styles/CoverPage.css\" />\n" . "\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\"Styles/CoverPage.css\" />\n"
. "\t</head>\n" . "\t</head>\n"
. "\t<body>\n" . "\t<body>\n"
. "\t\t" . $coverText . "\n" . "\t" . $bookTitle . "\n"
. "\t\t<div>\n" . "\t\t<div>\n"
. "\t\t\t<img src=\"" . $imgPath . "\" alt=\"Cover image\" style=\"height: 40%\"/>\n" . "\t\t\t<img src=\"" . $imgPath . "\" alt=\"Cover image\" style=\"height: 100%\"/>\n"
. "\t\t</div>\n" . "\t\t</div>\n"
. "\t</body>\n" . "\t</body>\n"
. "</html>\n"; . "</html>\n";
@ -636,13 +636,13 @@ class EPub {
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n"
. "<head>" . "<head>"
. "\t<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n" . "\t<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n"
. "\t\t<title>Cover</title>\n" . "\t\t<title>Cover Image</title>\n"
. "\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\"Styles/CoverPage.css\" />\n" . "\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\"Styles/CoverPage.css\" />\n"
. "\t</head>\n" . "\t</head>\n"
. "\t<body>\n" . "\t<body>\n"
. "\t\t<section epub:type=\"cover\">\n" . "\t\t<section epub:type=\"cover\">\n"
. "\t\t" . $coverText . "\n" . "\t" . $bookTitle . "\n"
. "\t\t\t<img src=\"" . $imgPath . "\" alt=\"Cover image\" style=\"height: 40%\"/>\n" . "\t\t\t<img src=\"" . $imgPath . "\" alt=\"Cover image\" style=\"height: 30%\"/>\n"
. "\t\t</section>\n" . "\t\t</section>\n"
. "\t</body>\n" . "\t</body>\n"
. "</html>\n"; . "</html>\n";

View File

@ -1142,23 +1142,28 @@ class Poche
$entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT); $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT);
$entry = $this->store->retrieveOneById($entryID, $this->user->getId()); $entry = $this->store->retrieveOneById($entryID, $this->user->getId());
$entries = array($entry); $entries = array($entry);
$bookTitle = $entry['title'];
break; break;
case 'all': case 'all':
$entries = $this->store->retrieveAll($this->user->getId()); $entries = $this->store->retrieveAll($this->user->getId());
$bookTitle = _('All my articles');
break; break;
case 'tag': case 'tag':
$tag = filter_var($_GET['tag'],FILTER_SANITIZE_STRING); $tag = filter_var($_GET['tag'],FILTER_SANITIZE_STRING);
$tags_id = $this->store->retrieveAllTags($this->user->getId(),$tag); $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. $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()); $entries = $this->store->retrieveEntriesByTag($tag_id,$this->user->getId());
$bookTitle = sprintf(_('Articles related to %s'),$tag);
break; break;
case 'category': case 'category':
$category = filter_var($_GET['category'],FILTER_SANITIZE_STRING); $category = filter_var($_GET['category'],FILTER_SANITIZE_STRING);
$entries = $this->store->getEntriesByView($category,$this->user->getId()); $entries = $this->store->getEntriesByView($category,$this->user->getId());
$bookTitle = sprintf(_('All my articles in category %s'), $category);
break; break;
case 'search': case 'search':
$search = filter_var($_GET['search'],FILTER_SANITIZE_STRING); $search = filter_var($_GET['search'],FILTER_SANITIZE_STRING);
$entries = $this->store->search($search,$this->user->getId()); $entries = $this->store->search($search,$this->user->getId());
$bookTitle = sprintf(_('All my articles for search %s'), $search);
break; break;
case 'default': case 'default':
die(_('Uh, there is a problem while generating epub.')); die(_('Uh, there is a problem while generating epub.'));
@ -1166,12 +1171,11 @@ class Poche
} }
$content_start = $content_start =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
. "<!DOCTYPE html>\n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n"
. "<html>\n" . "<head>"
. "<head>\n" . "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n"
. "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n" . "<title>wallabag articles book</title>\n"
. "<title>wallabag article</title>\n"
. "</head>\n" . "</head>\n"
. "<body>\n"; . "<body>\n";
@ -1205,23 +1209,22 @@ class Poche
$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"; $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"); $log->logLine("Add Cover");
if (count($entries)>1){
$cover = sprintf(_('<h1>%s and %s other articles</h1>'), $entries[0]['title'], count($entries));
} else {
$cover = sprintf(_('<h1>%s</h1>'), $entries[0]['title']);
}
$book->setCover("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $cover);
$fullTitle = "<h1> " . $bookTitle . "</h1>\n";
$book->setCover($cover); $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle);
//$book->addChapter("Notices", "Cover.html", $cover);
$book->buildTOC(NULL, "toc", _('Table of Contents'), TRUE, TRUE); $cover = $content_start . _('<span style="text-align:center;display:block;">Produced by wallabag with PHPePub</span>') . $bookEnd;
$subject = "";
//$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) { foreach ($entries as $entry) {
$tags = $this->store->retrieveTagsByEntry($entry['id']); $tags = $this->store->retrieveTagsByEntry($entry['id']);
foreach ($tags as $tag) { foreach ($tags as $tag) {
$subject =. $tag['value'] . ','; $book->setSubject($tag['value']);
} }
$log->logLine("Set up parameters"); $log->logLine("Set up parameters");
@ -1230,7 +1233,6 @@ class Poche
$book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD);
$log->logLine("Added chapter " . $entry['title']); $log->logLine("Added chapter " . $entry['title']);
} }
$book->setSubject($subject);
if (DEBUG_POCHE) { if (DEBUG_POCHE) {
$epuplog = $book->getLog(); $epuplog = $book->getLog();