aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche')
-rwxr-xr-xinc/poche/Poche.class.php110
-rwxr-xr-xinc/poche/global.inc.php5
2 files changed, 115 insertions, 0 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 5aa6ea07..85dd3848 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -1131,4 +1131,114 @@ 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 switch ($_GET['method']) {
1141 case 'id':
1142 $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT);
1143 $entry = $this->store->retrieveOneById($entryID, $this->user->getId());
1144 $entries = array($entry);
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
1166 }
1167
1168 $content_start =
1169 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
1170 . "<!DOCTYPE html>\n"
1171 . "<html>\n"
1172 . "<head>\n"
1173 . "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n"
1174 . "<title>wallabag article</title>\n"
1175 . "</head>\n"
1176 . "<body>\n";
1177
1178 $bookEnd = "</body>\n</html>\n";
1179
1180 $log = new Logger("wallabag", TRUE);
1181 $fileDir = CACHE;
1182
1183
1184 $book = new EPub(EPub::BOOK_VERSION_EPUB3);
1185 $log->logLine("new EPub()");
1186 $log->logLine("EPub class version: " . EPub::VERSION);
1187 $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
1188 $log->logLine("Zip version: " . Zip::VERSION);
1189 $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
1190 $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());
1191
1192 $book->setTitle(_('wallabag\'s articles'));
1193 $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID.
1194 //$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.
1195 $book->setDescription(_("Some articles saved on my wallabag"));
1196 $book->setAuthor("wallabag","wallabag");
1197 $book->setPublisher("wallabag","wallabag"); // I hope this is a non existant address :)
1198 $book->setDate(time()); // Strictly not needed as the book date defaults to time().
1199 //$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.
1200 $book->setSourceURL("http://$_SERVER[HTTP_HOST]");
1201
1202 $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP");
1203 $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "wallabag");
1204
1205 $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";
1206
1207 $log->logLine("Add Cover");
1208 if (count($entries)>1){
1209 $cover = sprintf(_('<h1>%s and %s other articles</h1>'), $entries[0]['title'], count($entries));
1210 } else {
1211 $cover = sprintf(_('<h1>%s</h1>'), $entries[0]['title']);
1212 }
1213 $book->setCover("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $cover);
1214
1215
1216 $book->setCover($cover);
1217 //$book->addChapter("Notices", "Cover.html", $cover);
1218 $book->buildTOC(NULL, "toc", _('Table of Contents'), TRUE, TRUE);
1219 $subject = "";
1220
1221 foreach ($entries as $entry) {
1222 $tags = $this->store->retrieveTagsByEntry($entry['id']);
1223 foreach ($tags as $tag) {
1224 $subject =. $tag['value'] . ',';
1225 }
1226
1227 $log->logLine("Set up parameters");
1228
1229 $chapter = $content_start . $entry['content'] . $bookEnd;
1230 $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD);
1231 $log->logLine("Added chapter " . $entry['title']);
1232 }
1233 $book->setSubject($subject);
1234
1235 if (DEBUG_POCHE) {
1236 $epuplog = $book->getLog();
1237 $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // generation log
1238 // Only used in case we need to debug EPub.php.
1239 //$book->addChapter("ePubLog", "ePubLog.html", $content_start . $epuplog . "\n</pre>" . $bookEnd);
1240 }
1241 $book->finalize();
1242 $zipData = $book->sendBook(_('wallabag\'s articles'));
1243 }
1134} 1244}
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;