aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
authortcitworld <tcit@tcit.fr>2014-05-18 19:00:51 +0200
committertcitworld <tcit@tcit.fr>2014-05-18 19:00:51 +0200
commit04b43dc097c3d69fd42d724b2cf082aff86d7272 (patch)
tree3eb36cf21a705c94a034e2937526a228bbbba730 /inc/poche/Poche.class.php
parent230fa05eb736ab58d4183ddb2932bc7c620a2dd4 (diff)
parentbecc5bfbf289b1dda65fea4761742f1998d2143a (diff)
downloadwallabag-04b43dc097c3d69fd42d724b2cf082aff86d7272.tar.gz
wallabag-04b43dc097c3d69fd42d724b2cf082aff86d7272.tar.zst
wallabag-04b43dc097c3d69fd42d724b2cf082aff86d7272.zip
Merge pull request #697 from tcitworld/dev
Up-to-date with me
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-xinc/poche/Poche.class.php115
1 files changed, 115 insertions, 0 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 515d4cac..1b69cd61 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -1149,4 +1149,119 @@ 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 . '<div style="text-align:center;"><p>' . _('Produced by wallabag with PHPePub') . '</p><p>'. _('Please open <a href="https://github.com/wallabag/wallabag/issues" >an issue</a> if you have trouble with the display of this E-Book on your device.') . '</p></div>' . $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) { //set tags as subjects
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); // log generation
1263 }
1264 $book->finalize();
1265 $zipData = $book->sendBook($bookFileName);
1266 }
1152} 1267}