diff options
Diffstat (limited to 'inc/poche')
-rwxr-xr-x | inc/poche/Poche.class.php | 115 | ||||
-rwxr-xr-x | inc/poche/Routing.class.php | 18 | ||||
-rw-r--r-- | inc/poche/Template.class.php | 6 | ||||
-rw-r--r-- | inc/poche/WallabagEBooks.class.php | 271 | ||||
-rw-r--r-- | inc/poche/WallabagEpub.class.php | 135 | ||||
-rwxr-xr-x | inc/poche/config.inc.default.php | 11 | ||||
-rwxr-xr-x | inc/poche/global.inc.php | 9 |
7 files changed, 402 insertions, 163 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 16235474..f9928145 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -180,6 +180,13 @@ class Poche | |||
180 | } | 180 | } |
181 | } | 181 | } |
182 | 182 | ||
183 | // if there are tags, add them to the new article | ||
184 | if (isset($_GET['tags'])) { | ||
185 | $_POST['value'] = $_GET['tags']; | ||
186 | $_POST['entry_id'] = $last_id; | ||
187 | $this->action('add_tag', $url); | ||
188 | } | ||
189 | |||
183 | $this->messages->add('s', _('the link has been added successfully')); | 190 | $this->messages->add('s', _('the link has been added successfully')); |
184 | } | 191 | } |
185 | else { | 192 | else { |
@@ -192,20 +199,34 @@ class Poche | |||
192 | } else { | 199 | } else { |
193 | Tools::redirect('?view=home&closewin=true'); | 200 | Tools::redirect('?view=home&closewin=true'); |
194 | } | 201 | } |
202 | return $last_id; | ||
195 | break; | 203 | break; |
196 | case 'delete': | 204 | case 'delete': |
197 | $msg = 'delete link #' . $id; | 205 | if (isset($_GET['search'])) { |
198 | if ($this->store->deleteById($id, $this->user->getId())) { | 206 | //when we want to apply a delete to a search |
199 | if (DOWNLOAD_PICTURES) { | 207 | $tags = array($_GET['search']); |
200 | Picture::removeDirectory(ABS_PATH . $id); | 208 | $allentry_ids = $this->store->search($tags[0], $this->user->getId()); |
209 | $entry_ids = array(); | ||
210 | foreach ($allentry_ids as $eachentry) { | ||
211 | $entry_ids[] = $eachentry[0]; | ||
201 | } | 212 | } |
202 | $this->messages->add('s', _('the link has been deleted successfully')); | 213 | } else { // delete a single article |
214 | $entry_ids = array($id); | ||
203 | } | 215 | } |
204 | else { | 216 | foreach($entry_ids as $id) { |
205 | $this->messages->add('e', _('the link wasn\'t deleted')); | 217 | $msg = 'delete link #' . $id; |
206 | $msg = 'error : can\'t delete link #' . $id; | 218 | if ($this->store->deleteById($id, $this->user->getId())) { |
219 | if (DOWNLOAD_PICTURES) { | ||
220 | Picture::removeDirectory(ABS_PATH . $id); | ||
221 | } | ||
222 | $this->messages->add('s', _('the link has been deleted successfully')); | ||
223 | } | ||
224 | else { | ||
225 | $this->messages->add('e', _('the link wasn\'t deleted')); | ||
226 | $msg = 'error : can\'t delete link #' . $id; | ||
227 | } | ||
228 | Tools::logm($msg); | ||
207 | } | 229 | } |
208 | Tools::logm($msg); | ||
209 | Tools::redirect('?'); | 230 | Tools::redirect('?'); |
210 | break; | 231 | break; |
211 | case 'toggle_fav' : | 232 | case 'toggle_fav' : |
@@ -220,8 +241,21 @@ class Poche | |||
220 | } | 241 | } |
221 | break; | 242 | break; |
222 | case 'toggle_archive' : | 243 | case 'toggle_archive' : |
223 | $this->store->archiveById($id, $this->user->getId()); | 244 | if (isset($_GET['tag_id'])) { |
224 | Tools::logm('archive link #' . $id); | 245 | //when we want to archive a whole tag |
246 | $tag_id = $_GET['tag_id']; | ||
247 | $allentry_ids = $this->store->retrieveEntriesByTag($tag_id, $this->user->getId()); | ||
248 | $entry_ids = array(); | ||
249 | foreach ($allentry_ids as $eachentry) { | ||
250 | $entry_ids[] = $eachentry[0]; | ||
251 | } | ||
252 | } else { //archive a single article | ||
253 | $entry_ids = array($id); | ||
254 | } | ||
255 | foreach($entry_ids as $id) { | ||
256 | $this->store->archiveById($id, $this->user->getId()); | ||
257 | Tools::logm('archive link #' . $id); | ||
258 | } | ||
225 | if ( Tools::isAjaxRequest() ) { | 259 | if ( Tools::isAjaxRequest() ) { |
226 | echo 1; | 260 | echo 1; |
227 | exit; | 261 | exit; |
@@ -303,6 +337,27 @@ class Poche | |||
303 | $this->messages->add('s', _('The tag has been successfully deleted')); | 337 | $this->messages->add('s', _('The tag has been successfully deleted')); |
304 | Tools::redirect(); | 338 | Tools::redirect(); |
305 | break; | 339 | break; |
340 | |||
341 | case 'reload_article' : | ||
342 | Tools::logm('reload article'); | ||
343 | $id = $_GET['id']; | ||
344 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); | ||
345 | Tools::logm('reload url ' . $entry['url']); | ||
346 | $url = new Url(base64_encode($entry['url'])); | ||
347 | $this->action('add', $url); | ||
348 | break; | ||
349 | |||
350 | /* For some unknown reason I can't get displayView() to work here (it redirects to home view afterwards). So here's a dirty fix which redirects directly to URL */ | ||
351 | case 'random': | ||
352 | $id = 0; | ||
353 | while ($this->store->retrieveOneById($id,$this->user->getId()) == null) { | ||
354 | $count = $this->store->getEntriesByViewCount($view, $this->user->getId()); | ||
355 | $id = rand(1,$count); | ||
356 | } | ||
357 | Tools::logm('get a random article'); | ||
358 | Tools::redirect('?view=view&id=' . $id); | ||
359 | //$this->displayView('view', $id); | ||
360 | break; | ||
306 | default: | 361 | default: |
307 | break; | 362 | break; |
308 | } | 363 | } |
@@ -405,9 +460,12 @@ class Poche | |||
405 | } | 460 | } |
406 | 461 | ||
407 | # flattr checking | 462 | # flattr checking |
408 | $flattr = new FlattrItem(); | 463 | $flattr = NULL; |
409 | $flattr->checkItem($entry['url'], $entry['id']); | 464 | if (FLATTR) { |
410 | 465 | $flattr = new FlattrItem(); | |
466 | $flattr->checkItem($entry['url'], $entry['id']); | ||
467 | } | ||
468 | |||
411 | # tags | 469 | # tags |
412 | $tags = $this->store->retrieveTagsByEntry($entry['id']); | 470 | $tags = $this->store->retrieveTagsByEntry($entry['id']); |
413 | 471 | ||
@@ -540,6 +598,8 @@ class Poche | |||
540 | Tools::redirect($referer); | 598 | Tools::redirect($referer); |
541 | } | 599 | } |
542 | $this->messages->add('e', _('login failed: bad login or password')); | 600 | $this->messages->add('e', _('login failed: bad login or password')); |
601 | // log login failure in web server log to allow fail2ban usage | ||
602 | error_log('user '.$login.' authentication failure'); | ||
543 | Tools::logm('login failed'); | 603 | Tools::logm('login failed'); |
544 | Tools::redirect(); | 604 | Tools::redirect(); |
545 | } | 605 | } |
@@ -625,7 +685,18 @@ class Poche | |||
625 | $urlsInserted[] = $url; //add | 685 | $urlsInserted[] = $url; //add |
626 | if (isset($record['tags']) && trim($record['tags'])) { | 686 | if (isset($record['tags']) && trim($record['tags'])) { |
627 | 687 | ||
628 | // @TODO: set tags | 688 | $tags = explode(',', $record['tags']); |
689 | foreach($tags as $tag) { | ||
690 | $entry_id = $id; | ||
691 | $tag_id = $this->store->retrieveTagByValue($tag); | ||
692 | if ($tag_id) { | ||
693 | $this->store->setTagToEntry($tag_id['id'], $entry_id); | ||
694 | } else { | ||
695 | $this->store->createTag($tag); | ||
696 | $tag_id = $this->store->retrieveTagByValue($tag); | ||
697 | $this->store->setTagToEntry($tag_id['id'], $entry_id); | ||
698 | } | ||
699 | } | ||
629 | 700 | ||
630 | } | 701 | } |
631 | } | 702 | } |
@@ -748,10 +819,11 @@ class Poche | |||
748 | * | 819 | * |
749 | * @param $token | 820 | * @param $token |
750 | * @param $user_id | 821 | * @param $user_id |
751 | * @param $tag_id | 822 | * @param $tag_id if $type is 'tag', the id of the tag to generate feed for |
752 | * @param string $type | 823 | * @param string $type the type of feed to generate |
824 | * @param int $limit the maximum number of items (0 means all) | ||
753 | */ | 825 | */ |
754 | public function generateFeeds($token, $user_id, $tag_id, $type = 'home') | 826 | public function generateFeeds($token, $user_id, $tag_id, $type = 'home', $limit = 0) |
755 | { | 827 | { |
756 | $allowed_types = array('home', 'fav', 'archive', 'tag'); | 828 | $allowed_types = array('home', 'fav', 'archive', 'tag'); |
757 | $config = $this->store->getConfigUser($user_id); | 829 | $config = $this->store->getConfigUser($user_id); |
@@ -778,8 +850,13 @@ class Poche | |||
778 | $entries = $this->store->getEntriesByView($type, $user_id); | 850 | $entries = $this->store->getEntriesByView($type, $user_id); |
779 | } | 851 | } |
780 | 852 | ||
853 | // if $limit is set to zero, use all entries | ||
854 | if (0 == $limit) { | ||
855 | $limit = count($entries); | ||
856 | } | ||
781 | if (count($entries) > 0) { | 857 | if (count($entries) > 0) { |
782 | foreach ($entries as $entry) { | 858 | for ($i = 0; $i < min(count($entries), $limit); $i++) { |
859 | $entry = $entries[$i]; | ||
783 | $newItem = $feed->createNewItem(); | 860 | $newItem = $feed->createNewItem(); |
784 | $newItem->setTitle($entry['title']); | 861 | $newItem->setTitle($entry['title']); |
785 | $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); | 862 | $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); |
diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index 6ae93d21..a8d00b89 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php | |||
@@ -102,7 +102,8 @@ class Routing | |||
102 | $this->wallabag->login($this->referer); | 102 | $this->wallabag->login($this->referer); |
103 | } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) { | 103 | } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) { |
104 | $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); | 104 | $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); |
105 | $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']); | 105 | $limit = (isset($_GET['limit']) ? intval($_GET['limit']) : 0); |
106 | $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type'], $limit); | ||
106 | } | 107 | } |
107 | 108 | ||
108 | //allowed ONLY to logged in user | 109 | //allowed ONLY to logged in user |
@@ -115,12 +116,21 @@ class Routing | |||
115 | // update password | 116 | // update password |
116 | $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); | 117 | $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); |
117 | } elseif (isset($_GET['newuser'])) { | 118 | } elseif (isset($_GET['newuser'])) { |
118 | $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']); | 119 | $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail']); |
119 | } elseif (isset($_GET['deluser'])) { | 120 | } elseif (isset($_GET['deluser'])) { |
120 | $this->wallabag->deleteUser($_POST['password4deletinguser']); | 121 | $this->wallabag->deleteUser($_POST['password4deletinguser']); |
121 | } elseif (isset($_GET['epub'])) { | 122 | } elseif (isset($_GET['epub'])) { |
122 | $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); | 123 | $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); |
123 | $epub->run(); | 124 | $epub->prepareData(); |
125 | $epub->produceEpub(); | ||
126 | } elseif (isset($_GET['mobi'])) { | ||
127 | $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); | ||
128 | $mobi->prepareData(); | ||
129 | $mobi->produceMobi(); | ||
130 | } elseif (isset($_GET['pdf'])) { | ||
131 | $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); | ||
132 | $pdf->prepareData(); | ||
133 | $pdf->producePDF(); | ||
124 | } elseif (isset($_GET['import'])) { | 134 | } elseif (isset($_GET['import'])) { |
125 | $import = $this->wallabag->import(); | 135 | $import = $this->wallabag->import(); |
126 | $tplVars = array_merge($this->vars, $import); | 136 | $tplVars = array_merge($this->vars, $import); |
@@ -148,4 +158,4 @@ class Routing | |||
148 | { | 158 | { |
149 | echo $this->wallabag->tpl->render($file, $vars); | 159 | echo $this->wallabag->tpl->render($file, $vars); |
150 | } | 160 | } |
151 | } \ No newline at end of file | 161 | } |
diff --git a/inc/poche/Template.class.php b/inc/poche/Template.class.php index b686f2ec..4d0bfdbb 100644 --- a/inc/poche/Template.class.php +++ b/inc/poche/Template.class.php | |||
@@ -24,7 +24,7 @@ class Template extends Twig_Environment | |||
24 | 24 | ||
25 | $themeDirectory = (is_null($pocheUser) ? DEFAULT_THEME : $pocheUser->getConfigValue('theme')); | 25 | $themeDirectory = (is_null($pocheUser) ? DEFAULT_THEME : $pocheUser->getConfigValue('theme')); |
26 | 26 | ||
27 | if ($themeDirectory === false) { | 27 | if ($themeDirectory === false || !is_dir(THEME . '/' . $themeDirectory)) { |
28 | $themeDirectory = DEFAULT_THEME; | 28 | $themeDirectory = DEFAULT_THEME; |
29 | } | 29 | } |
30 | 30 | ||
@@ -181,7 +181,7 @@ class Template extends Twig_Environment | |||
181 | while (($theme = readdir($handle)) !== false) { | 181 | while (($theme = readdir($handle)) !== false) { |
182 | # Themes are stored in a directory, so all directory names are themes | 182 | # Themes are stored in a directory, so all directory names are themes |
183 | # @todo move theme installation data to database | 183 | # @todo move theme installation data to database |
184 | if (!is_dir(THEME . '/' . $theme) || in_array($theme, array('.', '..'))) { | 184 | if (!is_dir(THEME . '/' . $theme) || in_array($theme, array('.', '..', '_global'))) { |
185 | continue; | 185 | continue; |
186 | } | 186 | } |
187 | 187 | ||
@@ -232,4 +232,4 @@ class Template extends Twig_Environment | |||
232 | Tools::emptyCache(); | 232 | Tools::emptyCache(); |
233 | Tools::redirect('?view=config'); | 233 | Tools::redirect('?view=config'); |
234 | } | 234 | } |
235 | } \ No newline at end of file | 235 | } |
diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php new file mode 100644 index 00000000..55831571 --- /dev/null +++ b/inc/poche/WallabagEBooks.class.php | |||
@@ -0,0 +1,271 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * wallabag, self hostable application allowing you to not miss any content anymore | ||
4 | * | ||
5 | * @category wallabag | ||
6 | * @author Nicolas LÅ“uillet <nicolas@loeuillet.org> | ||
7 | * @copyright 2013 | ||
8 | * @license http://opensource.org/licenses/MIT see COPYING file | ||
9 | */ | ||
10 | |||
11 | class WallabagEBooks | ||
12 | { | ||
13 | protected $wallabag; | ||
14 | protected $method; | ||
15 | protected $value; | ||
16 | protected $entries; | ||
17 | protected $bookTitle; | ||
18 | protected $bookFileName; | ||
19 | protected $author = 'wallabag'; | ||
20 | |||
21 | public function __construct(Poche $wallabag, $method, $value) | ||
22 | { | ||
23 | $this->wallabag = $wallabag; | ||
24 | $this->method = $method; | ||
25 | $this->value = $value; | ||
26 | } | ||
27 | |||
28 | public function prepareData() | ||
29 | { | ||
30 | switch ($this->method) { | ||
31 | case 'id': | ||
32 | $entryID = filter_var($this->value, FILTER_SANITIZE_NUMBER_INT); | ||
33 | $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId()); | ||
34 | $this->entries = array($entry); | ||
35 | $this->bookTitle = $entry['title']; | ||
36 | $this->bookFileName = str_replace('/', '_', substr($this->bookTitle, 0, 200)); | ||
37 | $this->author = preg_replace('#^w{3}.#', '', Tools::getdomain($entry["url"])); # if only one article, set author to domain name (we strip the eventual www part) | ||
38 | Tools::logm('Producing ebook from article ' . $this->bookTitle); | ||
39 | break; | ||
40 | case 'all': | ||
41 | $this->entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); | ||
42 | $this->bookTitle = sprintf(_('All my articles on %s'), date(_('d.m.y'))); #translatable because each country has it's own date format system | ||
43 | $this->bookFileName = _('Allarticles') . date(_('dmY')); | ||
44 | Tools::logm('Producing ebook from all articles'); | ||
45 | break; | ||
46 | case 'tag': | ||
47 | $tag = filter_var($this->value, FILTER_SANITIZE_STRING); | ||
48 | $tags_id = $this->wallabag->store->retrieveAllTags($this->wallabag->user->getId(), $tag); | ||
49 | $tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround. | ||
50 | $this->entries = $this->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); | ||
51 | $this->bookTitle = sprintf(_('Articles tagged %s'), $tag); | ||
52 | $this->bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); | ||
53 | Tools::logm('Producing ebook from tag ' . $tag); | ||
54 | break; | ||
55 | case 'category': | ||
56 | $category = filter_var($this->value, FILTER_SANITIZE_STRING); | ||
57 | $this->entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); | ||
58 | $this->bookTitle = sprintf(_('Articles in category %s'), $category); | ||
59 | $this->bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); | ||
60 | Tools::logm('Producing ebook from category ' . $category); | ||
61 | break; | ||
62 | case 'search': | ||
63 | $search = filter_var($this->value, FILTER_SANITIZE_STRING); | ||
64 | Tools::logm($search); | ||
65 | $this->entries = $this->wallabag->store->search($search, $this->wallabag->user->getId()); | ||
66 | $this->bookTitle = sprintf(_('Articles for search %s'), $search); | ||
67 | $this->bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); | ||
68 | Tools::logm('Producing ebook from search ' . $search); | ||
69 | break; | ||
70 | case 'default': | ||
71 | die(_('Uh, there is a problem while generating eBook.')); | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | |||
76 | class WallabagEpub extends WallabagEBooks | ||
77 | { | ||
78 | /** | ||
79 | * handle ePub | ||
80 | */ | ||
81 | public function produceEpub() | ||
82 | { | ||
83 | Tools::logm('Starting to produce ePub 3 file'); | ||
84 | |||
85 | try { | ||
86 | |||
87 | $content_start = | ||
88 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
89 | . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n" | ||
90 | . "<head>" | ||
91 | . "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n" | ||
92 | . "<title>" . _("wallabag articles book") . "</title>\n" | ||
93 | . "</head>\n" | ||
94 | . "<body>\n"; | ||
95 | |||
96 | $bookEnd = "</body>\n</html>\n"; | ||
97 | |||
98 | $log = new Logger("wallabag", TRUE); | ||
99 | $fileDir = CACHE; | ||
100 | |||
101 | $book = new EPub(EPub::BOOK_VERSION_EPUB3, DEBUG_POCHE); | ||
102 | $log->logLine("new EPub()"); | ||
103 | $log->logLine("EPub class version: " . EPub::VERSION); | ||
104 | $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION); | ||
105 | $log->logLine("Zip version: " . Zip::VERSION); | ||
106 | $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); | ||
107 | $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); | ||
108 | |||
109 | Tools::logm('Filling metadata for ePub...'); | ||
110 | |||
111 | $book->setTitle($this->bookTitle); | ||
112 | $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID. | ||
113 | //$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. | ||
114 | $book->setDescription(_("Some articles saved on my wallabag")); | ||
115 | $book->setAuthor($this->author,$this->author); | ||
116 | $book->setPublisher("wallabag", "wallabag"); // I hope this is a non existant address :) | ||
117 | $book->setDate(time()); // Strictly not needed as the book date defaults to time(). | ||
118 | //$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. | ||
119 | $book->setSourceURL("http://$_SERVER[HTTP_HOST]"); | ||
120 | |||
121 | $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); | ||
122 | $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "wallabag"); | ||
123 | |||
124 | $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"; | ||
125 | |||
126 | $log->logLine("Add Cover"); | ||
127 | |||
128 | $fullTitle = "<h1> " . $this->bookTitle . "</h1>\n"; | ||
129 | |||
130 | $book->setCoverImage("Cover.png", file_get_contents("themes/_global/img/appicon/apple-touch-icon-152.png"), "image/png", $fullTitle); | ||
131 | |||
132 | $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; | ||
133 | |||
134 | //$book->addChapter("Table of Contents", "TOC.xhtml", NULL, false, EPub::EXTERNAL_REF_IGNORE); | ||
135 | $book->addChapter("Notices", "Cover2.html", $cover); | ||
136 | |||
137 | $book->buildTOC(); | ||
138 | |||
139 | Tools::logm('Adding actual content...'); | ||
140 | |||
141 | foreach ($this->entries as $entry) { //set tags as subjects | ||
142 | $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); | ||
143 | foreach ($tags as $tag) { | ||
144 | $book->setSubject($tag['value']); | ||
145 | } | ||
146 | |||
147 | $log->logLine("Set up parameters"); | ||
148 | |||
149 | $chapter = $content_start . $entry['content'] . $bookEnd; | ||
150 | $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); | ||
151 | $log->logLine("Added chapter " . $entry['title']); | ||
152 | } | ||
153 | |||
154 | if (DEBUG_POCHE) { | ||
155 | $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // log generation | ||
156 | Tools::logm('Production log available in produced file'); | ||
157 | } | ||
158 | $book->finalize(); | ||
159 | $zipData = $book->sendBook($this->bookFileName); | ||
160 | Tools::logm('Ebook produced'); | ||
161 | } | ||
162 | catch (Exception $e) { | ||
163 | Tools::logm('PHPePub has encountered an error : '.$e->getMessage()); | ||
164 | $this->wallabag->messages->add('e', $e->getMessage()); | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | |||
169 | class WallabagMobi extends WallabagEBooks | ||
170 | { | ||
171 | /** | ||
172 | * MOBI Class | ||
173 | * @author Sander Kromwijk | ||
174 | */ | ||
175 | |||
176 | public function produceMobi() | ||
177 | { | ||
178 | try { | ||
179 | Tools::logm('Starting to produce Mobi file'); | ||
180 | $mobi = new MOBI(); | ||
181 | $content = new MOBIFile(); | ||
182 | |||
183 | $messages = new Messages(); // for later | ||
184 | |||
185 | Tools::logm('Filling metadata for Mobi...'); | ||
186 | |||
187 | $content->set("title", $this->bookTitle); | ||
188 | $content->set("author", $this->author); | ||
189 | $content->set("subject", $this->bookTitle); | ||
190 | |||
191 | # introduction | ||
192 | $content->appendParagraph('<div style="text-align:center;" ><p>' . _('Produced by wallabag with PHPMobi') . '</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>'); | ||
193 | $content->appendImage(imagecreatefrompng("themes/_global/img/appicon/apple-touch-icon-152.png")); | ||
194 | $content->appendPageBreak(); | ||
195 | |||
196 | Tools::logm('Adding actual content...'); | ||
197 | |||
198 | foreach ($this->entries as $item) { | ||
199 | $content->appendChapterTitle($item['title']); | ||
200 | $content->appendParagraph($item['content']); | ||
201 | $content->appendPageBreak(); | ||
202 | } | ||
203 | $mobi->setContentProvider($content); | ||
204 | |||
205 | // the browser inside Kindle Devices doesn't likes special caracters either, we limit to A-z/0-9 | ||
206 | $this->bookFileName = preg_replace('/[^A-Za-z0-9\-]/', '', $this->bookFileName); | ||
207 | |||
208 | // we offer file to download | ||
209 | $mobi->download($this->bookFileName.'.mobi'); | ||
210 | Tools::logm('Mobi file produced'); | ||
211 | } | ||
212 | catch (Exception $e) { | ||
213 | Tools::logm('PHPMobi has encountered an error : '.$e->getMessage()); | ||
214 | $this->wallabag->messages->add('e', $e->getMessage()); | ||
215 | } | ||
216 | } | ||
217 | } | ||
218 | |||
219 | class WallabagPDF extends WallabagEbooks | ||
220 | { | ||
221 | public function producePDF() | ||
222 | { | ||
223 | |||
224 | Tools::logm('Starting to produce PDF file'); | ||
225 | @define ('K_TCPDF_THROW_EXCEPTION_ERROR', TRUE); | ||
226 | try { | ||
227 | $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); | ||
228 | |||
229 | Tools::logm('Filling metadata for PDF...'); | ||
230 | $pdf->SetCreator(PDF_CREATOR); | ||
231 | $pdf->SetAuthor('wallabag'); | ||
232 | $pdf->SetTitle($this->bookTitle); | ||
233 | $pdf->SetSubject('Articles via wallabag'); | ||
234 | $pdf->SetKeywords('wallabag'); | ||
235 | |||
236 | Tools::logm('Adding introduction...'); | ||
237 | $pdf->AddPage(); | ||
238 | $intro = '<h1>' . $this->bookTitle . '</h1><div style="text-align:center;" > | ||
239 | <p>' . _('Produced by wallabag with tcpdf') . '</p> | ||
240 | <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> | ||
241 | <img src="themes/_global/img/appicon/apple-touch-icon-152.png" /></div>'; | ||
242 | |||
243 | |||
244 | $pdf->writeHTMLCell(0, 0, '', '', $intro, 0, 1, 0, true, '', true); | ||
245 | |||
246 | $i = 1; | ||
247 | Tools::logm('Adding actual content...'); | ||
248 | foreach ($this->entries as $item) { | ||
249 | $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); | ||
250 | foreach ($tags as $tag) { | ||
251 | $pdf->SetKeywords($tag['value']); | ||
252 | } | ||
253 | $pdf->AddPage(); | ||
254 | $html = '<h1>' . $item['title'] . '</h1>'; | ||
255 | $html .= $item['content']; | ||
256 | $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); | ||
257 | } | ||
258 | |||
259 | // set image scale factor | ||
260 | $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); | ||
261 | |||
262 | |||
263 | $pdf->Output($this->bookFileName . '.pdf', 'FD'); | ||
264 | } | ||
265 | catch (Exception $e) { | ||
266 | Tools::logm('TCPDF has encountered an error : '.$e->getMessage()); | ||
267 | $this->wallabag->messages->add('e', $e->getMessage()); | ||
268 | } | ||
269 | |||
270 | } | ||
271 | } | ||
diff --git a/inc/poche/WallabagEpub.class.php b/inc/poche/WallabagEpub.class.php deleted file mode 100644 index 9c4d3566..00000000 --- a/inc/poche/WallabagEpub.class.php +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * wallabag, self hostable application allowing you to not miss any content anymore | ||
4 | * | ||
5 | * @category wallabag | ||
6 | * @author Nicolas LÅ“uillet <nicolas@loeuillet.org> | ||
7 | * @copyright 2013 | ||
8 | * @license http://opensource.org/licenses/MIT see COPYING file | ||
9 | */ | ||
10 | |||
11 | class WallabagEpub | ||
12 | { | ||
13 | protected $wallabag; | ||
14 | protected $method; | ||
15 | protected $value; | ||
16 | |||
17 | public function __construct(Poche $wallabag, $method, $value) | ||
18 | { | ||
19 | $this->wallabag = $wallabag; | ||
20 | $this->method = $method; | ||
21 | $this->value = $value; | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | * handle ePub | ||
26 | */ | ||
27 | public function run() | ||
28 | { | ||
29 | switch ($this->method) { | ||
30 | case 'id': | ||
31 | $entryID = filter_var($this->value, FILTER_SANITIZE_NUMBER_INT); | ||
32 | $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId()); | ||
33 | $entries = array($entry); | ||
34 | $bookTitle = $entry['title']; | ||
35 | $bookFileName = substr($bookTitle, 0, 200); | ||
36 | break; | ||
37 | case 'all': | ||
38 | $entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); | ||
39 | $bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system | ||
40 | $bookFileName = _('Allarticles') . date(_('dmY')); | ||
41 | break; | ||
42 | case 'tag': | ||
43 | $tag = filter_var($this->value, FILTER_SANITIZE_STRING); | ||
44 | $tags_id = $this->wallabag->store->retrieveAllTags($this->wallabag->user->getId(), $tag); | ||
45 | $tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround. | ||
46 | $entries = $this->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); | ||
47 | $bookTitle = sprintf(_('Articles tagged %s'), $tag); | ||
48 | $bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); | ||
49 | break; | ||
50 | case 'category': | ||
51 | $category = filter_var($this->value, FILTER_SANITIZE_STRING); | ||
52 | $entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); | ||
53 | $bookTitle = sprintf(_('All articles in category %s'), $category); | ||
54 | $bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); | ||
55 | break; | ||
56 | case 'search': | ||
57 | $search = filter_var($this->value, FILTER_SANITIZE_STRING); | ||
58 | $entries = $this->store->search($search, $this->wallabag->user->getId()); | ||
59 | $bookTitle = sprintf(_('All articles for search %s'), $search); | ||
60 | $bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); | ||
61 | break; | ||
62 | case 'default': | ||
63 | die(_('Uh, there is a problem while generating epub.')); | ||
64 | } | ||
65 | |||
66 | $content_start = | ||
67 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
68 | . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n" | ||
69 | . "<head>" | ||
70 | . "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n" | ||
71 | . "<title>wallabag articles book</title>\n" | ||
72 | . "</head>\n" | ||
73 | . "<body>\n"; | ||
74 | |||
75 | $bookEnd = "</body>\n</html>\n"; | ||
76 | |||
77 | $log = new Logger("wallabag", TRUE); | ||
78 | $fileDir = CACHE; | ||
79 | |||
80 | $book = new EPub(EPub::BOOK_VERSION_EPUB3, DEBUG_POCHE); | ||
81 | $log->logLine("new EPub()"); | ||
82 | $log->logLine("EPub class version: " . EPub::VERSION); | ||
83 | $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION); | ||
84 | $log->logLine("Zip version: " . Zip::VERSION); | ||
85 | $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); | ||
86 | $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); | ||
87 | |||
88 | $book->setTitle($bookTitle); | ||
89 | $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID. | ||
90 | //$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. | ||
91 | $book->setDescription(_("Some articles saved on my wallabag")); | ||
92 | $book->setAuthor("wallabag", "wallabag"); | ||
93 | $book->setPublisher("wallabag", "wallabag"); // I hope this is a non existant address :) | ||
94 | $book->setDate(time()); // Strictly not needed as the book date defaults to time(). | ||
95 | //$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. | ||
96 | $book->setSourceURL("http://$_SERVER[HTTP_HOST]"); | ||
97 | |||
98 | $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); | ||
99 | $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "wallabag"); | ||
100 | |||
101 | $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"; | ||
102 | |||
103 | $log->logLine("Add Cover"); | ||
104 | |||
105 | $fullTitle = "<h1> " . $bookTitle . "</h1>\n"; | ||
106 | |||
107 | $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle); | ||
108 | |||
109 | $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; | ||
110 | |||
111 | //$book->addChapter("Table of Contents", "TOC.xhtml", NULL, false, EPub::EXTERNAL_REF_IGNORE); | ||
112 | $book->addChapter("Notices", "Cover2.html", $cover); | ||
113 | |||
114 | $book->buildTOC(); | ||
115 | |||
116 | foreach ($entries as $entry) { //set tags as subjects | ||
117 | $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); | ||
118 | foreach ($tags as $tag) { | ||
119 | $book->setSubject($tag['value']); | ||
120 | } | ||
121 | |||
122 | $log->logLine("Set up parameters"); | ||
123 | |||
124 | $chapter = $content_start . $entry['content'] . $bookEnd; | ||
125 | $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); | ||
126 | $log->logLine("Added chapter " . $entry['title']); | ||
127 | } | ||
128 | |||
129 | if (DEBUG_POCHE) { | ||
130 | $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // log generation | ||
131 | } | ||
132 | $book->finalize(); | ||
133 | $zipData = $book->sendBook($bookFileName); | ||
134 | } | ||
135 | } \ No newline at end of file | ||
diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index f666f468..aaaf12a6 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php | |||
@@ -44,15 +44,25 @@ | |||
44 | @define ('SHARE_MAIL', TRUE); | 44 | @define ('SHARE_MAIL', TRUE); |
45 | @define ('SHARE_SHAARLI', FALSE); | 45 | @define ('SHARE_SHAARLI', FALSE); |
46 | @define ('SHAARLI_URL', 'http://myshaarliurl.com'); | 46 | @define ('SHAARLI_URL', 'http://myshaarliurl.com'); |
47 | @define ('SHARE_DIASPORA', FALSE); | ||
48 | @define ('DIASPORA_URL', 'http://diasporapod.com'); # Don't add a / at the end | ||
47 | @define ('FLATTR', TRUE); | 49 | @define ('FLATTR', TRUE); |
48 | @define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url='); | 50 | @define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url='); |
49 | @define ('NOT_FLATTRABLE', '0'); | 51 | @define ('NOT_FLATTRABLE', '0'); |
50 | @define ('FLATTRABLE', '1'); | 52 | @define ('FLATTRABLE', '1'); |
51 | @define ('FLATTRED', '2'); | 53 | @define ('FLATTRED', '2'); |
54 | @define ('CARROT', FALSE); | ||
55 | |||
56 | // ebook | ||
57 | @define ('EPUB', TRUE); | ||
58 | @define ('MOBI', FALSE); | ||
59 | @define ('PDF', FALSE); | ||
60 | |||
52 | // display or not print link in article view | 61 | // display or not print link in article view |
53 | @define ('SHOW_PRINTLINK', '1'); | 62 | @define ('SHOW_PRINTLINK', '1'); |
54 | // display or not percent of read in article view. Affects only default theme. | 63 | // display or not percent of read in article view. Affects only default theme. |
55 | @define ('SHOW_READPERCENT', '1'); | 64 | @define ('SHOW_READPERCENT', '1'); |
65 | @define ('RELOAD_ARTICLE', TRUE); | ||
56 | @define ('ABS_PATH', 'assets/'); | 66 | @define ('ABS_PATH', 'assets/'); |
57 | 67 | ||
58 | @define ('DEFAULT_THEME', 'baggy'); | 68 | @define ('DEFAULT_THEME', 'baggy'); |
@@ -67,4 +77,3 @@ | |||
67 | @define ('IMPORT_LIMIT', 5); | 77 | @define ('IMPORT_LIMIT', 5); |
68 | //delay between downloads (in sec) | 78 | //delay between downloads (in sec) |
69 | @define ('IMPORT_DELAY', 5); | 79 | @define ('IMPORT_DELAY', 5); |
70 | |||
diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index b8c487e3..728528f8 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php | |||
@@ -22,7 +22,7 @@ require_once ROOT . '/vendor/autoload.php'; | |||
22 | require_once INCLUDES . '/poche/Template.class.php'; | 22 | require_once INCLUDES . '/poche/Template.class.php'; |
23 | require_once INCLUDES . '/poche/Language.class.php'; | 23 | require_once INCLUDES . '/poche/Language.class.php'; |
24 | require_once INCLUDES . '/poche/Routing.class.php'; | 24 | require_once INCLUDES . '/poche/Routing.class.php'; |
25 | require_once INCLUDES . '/poche/WallabagEpub.class.php'; | 25 | require_once INCLUDES . '/poche/WallabagEBooks.class.php'; |
26 | require_once INCLUDES . '/poche/Poche.class.php'; | 26 | require_once INCLUDES . '/poche/Poche.class.php'; |
27 | 27 | ||
28 | require_once INCLUDES . '/poche/Database.class.php'; | 28 | require_once INCLUDES . '/poche/Database.class.php'; |
@@ -41,6 +41,13 @@ require_once INCLUDES . '/3rdparty/libraries/PHPePub/Logger.php'; | |||
41 | require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php'; | 41 | require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php'; |
42 | require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php'; | 42 | require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php'; |
43 | 43 | ||
44 | # mobi library | ||
45 | require_once INCLUDES . '/3rdparty/libraries/MOBIClass/MOBI.php'; | ||
46 | |||
47 | # pdf library | ||
48 | #require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php'; | ||
49 | require_once INCLUDES . '/3rdparty/libraries/tcpdf/tcpdf.php'; | ||
50 | |||
44 | # system configuration; database credentials et caetera | 51 | # system configuration; database credentials et caetera |
45 | require_once INCLUDES . '/poche/config.inc.php'; | 52 | require_once INCLUDES . '/poche/config.inc.php'; |
46 | require_once INCLUDES . '/poche/config.inc.default.php'; | 53 | require_once INCLUDES . '/poche/config.inc.default.php'; |