aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
authortcit <tcit@tcit.fr>2014-04-25 16:20:25 +0200
committertcit <tcit@tcit.fr>2014-04-25 16:20:25 +0200
commit7ec445b06e05d8caa5219c5802007d897c48ab4e (patch)
treeebd94986e35dd01b4b6d94dbce590e585f179e2c /inc/poche
parent72a857158c187206dae2eed08143d5743322cb0c (diff)
downloadwallabag-7ec445b06e05d8caa5219c5802007d897c48ab4e.tar.gz
wallabag-7ec445b06e05d8caa5219c5802007d897c48ab4e.tar.zst
wallabag-7ec445b06e05d8caa5219c5802007d897c48ab4e.zip
Big changes for epub export. Now possible to do it from a tag, a category and a search. Also, improved ebook rendering.
Diffstat (limited to 'inc/poche')
-rwxr-xr-xinc/poche/Poche.class.php56
1 files changed, 38 insertions, 18 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index e5539468..c476df3e 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -1136,36 +1136,52 @@ class Poche
1136 * handle epub 1136 * handle epub
1137 */ 1137 */
1138 public function createEpub() { 1138 public function createEpub() {
1139 1139
1140 if (isset($_GET['epub']) && isset($_GET['id'])) { 1140 switch ($_GET['method']) {
1141 if ($_GET['id'] == "all") { // we put all entries in the file 1141 case 'id':
1142 $entries = $this->store->retrieveAll($this->user->getId());
1143 }
1144 else { // we put only one entry in the file
1145 $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT); 1142 $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT);
1146 $entry = $this->store->retrieveOneById($entryID, $this->user->getId()); 1143 $entry = $this->store->retrieveOneById($entryID, $this->user->getId());
1147 $entries = array($entry); 1144 $entries = array($entry);
1148 } 1145 break;
1146 case 'all':
1147 $entries = $this->store->retrieveAll($this->user->getId());
1148 break;
1149 case 'tag':
1150 $tag = filter_var($_GET['tag'],FILTER_SANITIZE_STRING);
1151 $tags_id = $this->store->retrieveAllTags($this->user->getId(),$tag);
1152 $tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround.
1153 $entries = $this->store->retrieveEntriesByTag($tag_id,$this->user->getId());
1154 break;
1155 case 'category':
1156 $category = filter_var($_GET['category'],FILTER_SANITIZE_STRING);
1157 $entries = $this->store->getEntriesByView($category,$this->user->getId());
1158 break;
1159 case 'search':
1160 $search = filter_var($_GET['search'],FILTER_SANITIZE_STRING);
1161 $entries = $this->store->search($search,$this->user->getId());
1162 break;
1163 case 'default':
1164 die(_('Uh, there is a problem while generating epub.'));
1165
1149 } 1166 }
1167
1150 $content_start = 1168 $content_start =
1151 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 1169 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
1152 . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n" 1170 . "<!DOCTYPE html>\n"
1153 . " \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" 1171 . "<html>\n"
1154 . "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" 1172 . "<head>\n"
1155 . "<head>"
1156 . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"
1157 . "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n" 1173 . "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n"
1158 . "<title>Test Book</title>\n" 1174 . "<title>wallabag article</title>\n"
1159 . "</head>\n" 1175 . "</head>\n"
1160 . "<body>\n"; 1176 . "<body>\n";
1161 1177
1162 $bookEnd = "</body>\n</html>\n"; 1178 $bookEnd = "</body>\n</html>\n";
1163 1179
1164 $log = new Logger($entryID, TRUE); 1180 $log = new Logger("wallabag", TRUE);
1165 $fileDir = CACHE; 1181 $fileDir = CACHE;
1166 1182
1167 1183
1168 $book = new EPub(); 1184 $book = new EPub(EPub::BOOK_VERSION_EPUB3);
1169 $log->logLine("new EPub()"); 1185 $log->logLine("new EPub()");
1170 $log->logLine("EPub class version: " . EPub::VERSION); 1186 $log->logLine("EPub class version: " . EPub::VERSION);
1171 $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION); 1187 $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
@@ -1186,6 +1202,10 @@ class Poche
1186 $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); 1202 $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP");
1187 1203
1188 $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"; 1204 $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";
1205
1206 $log->logLine("Add Cover Image");
1207 $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png");
1208
1189 $cover = $content_start . "<h1>My articles on wallabag</h1>\n<h2>As seen on : http://$_SERVER[HTTP_HOST]</h2>\n" . $bookEnd; 1209 $cover = $content_start . "<h1>My articles on wallabag</h1>\n<h2>As seen on : http://$_SERVER[HTTP_HOST]</h2>\n" . $bookEnd;
1190 $book->addChapter("Notices", "Cover.html", $cover); 1210 $book->addChapter("Notices", "Cover.html", $cover);
1191 $book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE); 1211 $book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE);
@@ -1193,7 +1213,7 @@ class Poche
1193 foreach ($entries as $entry) { 1213 foreach ($entries as $entry) {
1194 $tags = $this->store->retrieveTagsByEntry($entry['id']); 1214 $tags = $this->store->retrieveTagsByEntry($entry['id']);
1195 foreach ($tags as $tag) { 1215 foreach ($tags as $tag) {
1196 $book->setSubject($tag); 1216 $book->setSubject($tag['value']);
1197 } 1217 }
1198 1218
1199 $log->logLine("Set up parameters"); 1219 $log->logLine("Set up parameters");
@@ -1201,11 +1221,11 @@ class Poche
1201 1221
1202 1222
1203 $chapter = $content_start . $entry['content'] . $bookEnd; 1223 $chapter = $content_start . $entry['content'] . $bookEnd;
1204 $book->addChapter("Chapter " . $entry['id'] . ": " . $entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); 1224 $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD);
1205 } 1225 }
1206 1226
1207 1227
1208 if (true) { 1228 if (DEBUG_POCHE) {
1209 $epuplog = $book->getLog(); 1229 $epuplog = $book->getLog();
1210 $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // generation log 1230 $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // generation log
1211 // Only used in case we need to debug EPub.php. 1231 // Only used in case we need to debug EPub.php.