aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
authortcit <tcit@tcit.fr>2014-04-24 03:04:02 +0200
committertcit <tcit@tcit.fr>2014-04-24 03:04:02 +0200
commit87090d8ae7582708d20f3c09fb37d780af860bcd (patch)
treea12a6cc1ad396606e7370474f5aec1fe6bb9acd7 /inc/poche/Poche.class.php
parent8af31ae0f789f890517da0dbb13faa615638449b (diff)
downloadwallabag-87090d8ae7582708d20f3c09fb37d780af860bcd.tar.gz
wallabag-87090d8ae7582708d20f3c09fb37d780af860bcd.tar.zst
wallabag-87090d8ae7582708d20f3c09fb37d780af860bcd.zip
Added epub export function
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-xinc/poche/Poche.class.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 7e3e6afe..e5539468 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -1131,4 +1131,87 @@ class Poche
1131 1131
1132 return new HTMLPurifier($config); 1132 return new HTMLPurifier($config);
1133 } 1133 }
1134
1135 /**
1136 * handle epub
1137 */
1138 public function createEpub() {
1139
1140 if (isset($_GET['epub']) && isset($_GET['id'])) {
1141 if ($_GET['id'] == "all") { // we put all entries in the file
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);
1146 $entry = $this->store->retrieveOneById($entryID, $this->user->getId());
1147 $entries = array($entry);
1148 }
1149 }
1150 $content_start =
1151 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
1152 . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n"
1153 . " \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
1154 . "<html xmlns=\"http://www.w3.org/1999/xhtml\">\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"
1158 . "<title>Test Book</title>\n"
1159 . "</head>\n"
1160 . "<body>\n";
1161
1162 $bookEnd = "</body>\n</html>\n";
1163
1164 $log = new Logger($entryID, TRUE);
1165 $fileDir = CACHE;
1166
1167
1168 $book = new EPub();
1169 $log->logLine("new EPub()");
1170 $log->logLine("EPub class version: " . EPub::VERSION);
1171 $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
1172 $log->logLine("Zip version: " . Zip::VERSION);
1173 $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
1174 $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());
1175
1176 $book->setTitle("wallabag's articles");
1177 $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID.
1178 //$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.
1179 $book->setDescription("Some articles saved on my wallabag");
1180 $book->setAuthor("wallabag","wallabag");
1181 $book->setPublisher("wallabag","wallabag"); // I hope this is a non existant address :)
1182 $book->setDate(time()); // Strictly not needed as the book date defaults to time().
1183 //$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.
1184 $book->setSourceURL("http://$_SERVER[HTTP_HOST]");
1185
1186 $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP");
1187
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";
1189 $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);
1191 $book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE);
1192
1193 foreach ($entries as $entry) {
1194 $tags = $this->store->retrieveTagsByEntry($entry['id']);
1195 foreach ($tags as $tag) {
1196 $book->setSubject($tag);
1197 }
1198
1199 $log->logLine("Set up parameters");
1200
1201
1202
1203 $chapter = $content_start . $entry['content'] . $bookEnd;
1204 $book->addChapter("Chapter " . $entry['id'] . ": " . $entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD);
1205 }
1206
1207
1208 if (true) {
1209 $epuplog = $book->getLog();
1210 $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.
1212 //$book->addChapter("ePubLog", "ePubLog.html", $content_start . $epuplog . "\n</pre>" . $bookEnd);
1213 }
1214 $book->finalize();
1215 $zipData = $book->sendBook("wallabag's articles");
1216 }
1134} 1217}