aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
authortcit <tcit@tcit.fr>2014-05-16 16:31:18 +0200
committertcit <tcit@tcit.fr>2014-05-16 16:31:18 +0200
commit404adf970d985da0f624c42a5aa5e9c63694b08d (patch)
treeab298f6d6687dcef7494d7bd938dcdaac80a48fc /inc/poche
parent74e09e562ba46c52da364539aa4fc0414114ca87 (diff)
parentf3f0b11393dd7f11bc1e63df9488c3930c0bc06f (diff)
downloadwallabag-404adf970d985da0f624c42a5aa5e9c63694b08d.tar.gz
wallabag-404adf970d985da0f624c42a5aa5e9c63694b08d.tar.zst
wallabag-404adf970d985da0f624c42a5aa5e9c63694b08d.zip
Merge branch 'epub' into dev
Conflicts: themes/baggy/home.twig
Diffstat (limited to 'inc/poche')
-rwxr-xr-xinc/poche/Poche.class.php117
-rwxr-xr-xinc/poche/global.inc.php5
2 files changed, 122 insertions, 0 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 515d4cac..92db7d1b 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -1149,4 +1149,121 @@ class Poche
1149 1149
1150 return new HTMLPurifier($config); 1150 return new HTMLPurifier($config);
1151 } 1151 }
1152
1153 /**
1154 * handle epub
1155 */
1156 public function createEpub() {
1157
1158 switch ($_GET['method']) {
1159 case 'id':
1160 $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT);
1161 $entry = $this->store->retrieveOneById($entryID, $this->user->getId());
1162 $entries = array($entry);
1163 $bookTitle = $entry['title'];
1164 $bookFileName = substr($bookTitle, 0, 200);
1165 break;
1166 case 'all':
1167 $entries = $this->store->retrieveAll($this->user->getId());
1168 $bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system
1169 $bookFileName = _('Allarticles') . date(_('dmY'));
1170 break;
1171 case 'tag':
1172 $tag = filter_var($_GET['tag'],FILTER_SANITIZE_STRING);
1173 $tags_id = $this->store->retrieveAllTags($this->user->getId(),$tag);
1174 $tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround.
1175 $entries = $this->store->retrieveEntriesByTag($tag_id,$this->user->getId());
1176 $bookTitle = sprintf(_('Articles tagged %s'),$tag);
1177 $bookFileName = substr(sprintf(_('Tag %s'),$tag), 0, 200);
1178 break;
1179 case 'category':
1180 $category = filter_var($_GET['category'],FILTER_SANITIZE_STRING);
1181 $entries = $this->store->getEntriesByView($category,$this->user->getId());
1182 $bookTitle = sprintf(_('All articles in category %s'), $category);
1183 $bookFileName = substr(sprintf(_('Category %s'),$category), 0, 200);
1184 break;
1185 case 'search':
1186 $search = filter_var($_GET['search'],FILTER_SANITIZE_STRING);
1187 $entries = $this->store->search($search,$this->user->getId());
1188 $bookTitle = sprintf(_('All articles for search %s'), $search);
1189 $bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200);
1190 break;
1191 case 'default':
1192 die(_('Uh, there is a problem while generating epub.'));
1193
1194 }
1195
1196 $content_start =
1197 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1198 . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n"
1199 . "<head>"
1200 . "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n"
1201 . "<title>wallabag articles book</title>\n"
1202 . "</head>\n"
1203 . "<body>\n";
1204
1205 $bookEnd = "</body>\n</html>\n";
1206
1207 $log = new Logger("wallabag", TRUE);
1208 $fileDir = CACHE;
1209
1210
1211 $book = new EPub(EPub::BOOK_VERSION_EPUB3);
1212 $log->logLine("new EPub()");
1213 $log->logLine("EPub class version: " . EPub::VERSION);
1214 $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
1215 $log->logLine("Zip version: " . Zip::VERSION);
1216 $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
1217 $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());
1218
1219 $book->setTitle(_('wallabag\'s articles'));
1220 $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID.
1221 //$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.
1222 $book->setDescription(_("Some articles saved on my wallabag"));
1223 $book->setAuthor("wallabag","wallabag");
1224 $book->setPublisher("wallabag","wallabag"); // I hope this is a non existant address :)
1225 $book->setDate(time()); // Strictly not needed as the book date defaults to time().
1226 //$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.
1227 $book->setSourceURL("http://$_SERVER[HTTP_HOST]");
1228
1229 $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP");
1230 $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "wallabag");
1231
1232 $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";
1233
1234 $log->logLine("Add Cover");
1235
1236 $fullTitle = "<h1> " . $bookTitle . "</h1>\n";
1237
1238 $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle);
1239
1240 $cover = $content_start . _('<span style="text-align:center;display:block;">Produced by wallabag with PHPePub</span>') . $bookEnd;
1241
1242 //$book->addChapter("Table of Contents", "TOC.xhtml", NULL, false, EPub::EXTERNAL_REF_IGNORE);
1243 $book->addChapter("Notices", "Cover2.html", $cover);
1244
1245 $book->buildTOC();
1246
1247 foreach ($entries as $entry) {
1248 $tags = $this->store->retrieveTagsByEntry($entry['id']);
1249 foreach ($tags as $tag) {
1250 $book->setSubject($tag['value']);
1251 }
1252
1253 $log->logLine("Set up parameters");
1254
1255 $chapter = $content_start . $entry['content'] . $bookEnd;
1256 $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD);
1257 $log->logLine("Added chapter " . $entry['title']);
1258 }
1259
1260 if (DEBUG_POCHE) {
1261 $epuplog = $book->getLog();
1262 $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // generation log
1263 // Only used in case we need to debug EPub.php.
1264 //$book->addChapter("ePubLog", "ePubLog.html", $content_start . $epuplog . "\n</pre>" . $bookEnd);
1265 }
1266 $book->finalize();
1267 $zipData = $book->sendBook($bookFileName);
1268 }
1152} 1269}
diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php
index 14e9dd93..8cf86d03 100755
--- a/inc/poche/global.inc.php
+++ b/inc/poche/global.inc.php
@@ -31,6 +31,11 @@ require_once INCLUDES . '/3rdparty/FlattrItem.class.php';
31 31
32require_once INCLUDES . '/3rdparty/htmlpurifier/HTMLPurifier.auto.php'; 32require_once INCLUDES . '/3rdparty/htmlpurifier/HTMLPurifier.auto.php';
33 33
34# epub library
35require_once INCLUDES . '/3rdparty/libraries/PHPePub/Logger.php';
36require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php';
37require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php';
38
34# Composer its autoloader for automatically loading Twig 39# Composer its autoloader for automatically loading Twig
35if (! file_exists(ROOT . '/vendor/autoload.php')) { 40if (! file_exists(ROOT . '/vendor/autoload.php')) {
36 Poche::$canRenderTemplates = false; 41 Poche::$canRenderTemplates = false;