diff options
author | Thomas Citharel <tcit@tcit.fr> | 2015-02-18 19:17:31 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2015-02-18 19:17:31 +0100 |
commit | 4b1fa4c2febc7abbc6da3d65e4e760949a55843c (patch) | |
tree | a93ec906dbb03ec70e9cdc5dc876392c6d758e97 /inc/poche | |
parent | 364953ede585b75fb29dc94b1c5f853053eaed0b (diff) | |
parent | df89c6f71adebfdb754ec3eb2fd775d8efbdb280 (diff) | |
download | wallabag-1.9.tar.gz wallabag-1.9.tar.zst wallabag-1.9.zip |
Merge pull request #1081 from wallabag/dev1.9
Version 1.9.0
Diffstat (limited to 'inc/poche')
-rwxr-xr-x | inc/poche/Database.class.php | 27 | ||||
-rw-r--r-- | inc/poche/Language.class.php | 2 | ||||
-rwxr-xr-x | inc/poche/Poche.class.php | 198 | ||||
-rwxr-xr-x | inc/poche/Routing.class.php | 31 | ||||
-rw-r--r-- | inc/poche/Template.class.php | 6 | ||||
-rwxr-xr-x | inc/poche/Tools.class.php | 2 | ||||
-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 | 17 | ||||
-rwxr-xr-x | inc/poche/global.inc.php | 9 |
10 files changed, 508 insertions, 190 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index f6ba4708..65675afe 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php | |||
@@ -31,10 +31,15 @@ class Database { | |||
31 | $this->handle = new PDO($db_path); | 31 | $this->handle = new PDO($db_path); |
32 | break; | 32 | break; |
33 | case 'mysql': | 33 | case 'mysql': |
34 | $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4'; | 34 | if (MYSQL_USE_UTF8MB4) { |
35 | $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array( | 35 | $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4'; |
36 | PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', | 36 | $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array( |
37 | )); | 37 | PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', |
38 | )); | ||
39 | } else { | ||
40 | $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; | ||
41 | $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD); | ||
42 | } | ||
38 | break; | 43 | break; |
39 | case 'postgres': | 44 | case 'postgres': |
40 | $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; | 45 | $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; |
@@ -293,7 +298,7 @@ class Database { | |||
293 | $sql_limit = "LIMIT ".$limit." OFFSET 0"; | 298 | $sql_limit = "LIMIT ".$limit." OFFSET 0"; |
294 | } | 299 | } |
295 | 300 | ||
296 | $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=? ORDER BY id " . $sql_limit; | 301 | $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=? ORDER BY id " . $sql_limit; |
297 | $query = $this->executeQuery($sql, array($user_id)); | 302 | $query = $this->executeQuery($sql, array($user_id)); |
298 | $entries = $query->fetchAll(); | 303 | $entries = $query->fetchAll(); |
299 | 304 | ||
@@ -302,7 +307,7 @@ class Database { | |||
302 | 307 | ||
303 | public function retrieveUnfetchedEntriesCount($user_id) | 308 | public function retrieveUnfetchedEntriesCount($user_id) |
304 | { | 309 | { |
305 | $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=?"; | 310 | $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=?"; |
306 | $query = $this->executeQuery($sql, array($user_id)); | 311 | $query = $this->executeQuery($sql, array($user_id)); |
307 | list($count) = $query->fetch(); | 312 | list($count) = $query->fetch(); |
308 | 313 | ||
@@ -406,6 +411,16 @@ class Database { | |||
406 | 411 | ||
407 | return $count; | 412 | return $count; |
408 | } | 413 | } |
414 | public function getRandomId($user_id) { | ||
415 | $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()'; | ||
416 | $sql = "SELECT id FROM entries WHERE user_id=? ORDER BY ". $random . " LIMIT 1"; | ||
417 | $params = array($user_id); | ||
418 | $query = $this->executeQuery($sql, $params); | ||
419 | $id = $query->fetchAll(); | ||
420 | |||
421 | return $id; | ||
422 | } | ||
423 | |||
409 | 424 | ||
410 | public function updateContent($id, $content, $user_id) | 425 | public function updateContent($id, $content, $user_id) |
411 | { | 426 | { |
diff --git a/inc/poche/Language.class.php b/inc/poche/Language.class.php index 420f2fb9..962159c0 100644 --- a/inc/poche/Language.class.php +++ b/inc/poche/Language.class.php | |||
@@ -17,7 +17,7 @@ class Language | |||
17 | private $languageNames = array( | 17 | private $languageNames = array( |
18 | 'cs_CZ.utf8' => 'čeština', | 18 | 'cs_CZ.utf8' => 'čeština', |
19 | 'de_DE.utf8' => 'German', | 19 | 'de_DE.utf8' => 'German', |
20 | 'en_EN.utf8' => 'English', | 20 | 'en_GB.utf8' => 'English (GB)', |
21 | 'en_US.utf8' => 'English (US)', | 21 | 'en_US.utf8' => 'English (US)', |
22 | 'es_ES.utf8' => 'Español', | 22 | 'es_ES.utf8' => 'Español', |
23 | 'fa_IR.utf8' => 'فارسی', | 23 | 'fa_IR.utf8' => 'فارسی', |
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 16235474..fd2600f3 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -74,16 +74,57 @@ class Poche | |||
74 | /** | 74 | /** |
75 | * Creates a new user | 75 | * Creates a new user |
76 | */ | 76 | */ |
77 | public function createNewUser($username, $password, $email = "") | 77 | public function createNewUser($username, $password, $email = "", $internalRegistration = false) |
78 | { | 78 | { |
79 | Tools::logm('Trying to create a new user...'); | ||
79 | if (!empty($username) && !empty($password)){ | 80 | if (!empty($username) && !empty($password)){ |
80 | $newUsername = filter_var($username, FILTER_SANITIZE_STRING); | 81 | $newUsername = filter_var($username, FILTER_SANITIZE_STRING); |
81 | $email = filter_var($email, FILTER_SANITIZE_STRING); | 82 | $email = filter_var($email, FILTER_SANITIZE_STRING); |
82 | if (!$this->store->userExists($newUsername)){ | 83 | if (!$this->store->userExists($newUsername)){ |
83 | if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername), $email)) { | 84 | if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername), $email)) { |
84 | Tools::logm('The new user ' . $newUsername . ' has been installed'); | 85 | if ($email != "") { // if email is filled |
86 | if (SEND_CONFIRMATION_EMAIL && function_exists('mail')) { | ||
87 | |||
88 | // if internal registration from config screen | ||
89 | $body_internal = _('Hi,') . "\r\n\r\n" . sprintf(_('Someone just created a wallabag account for you on %1$s.'), Tools::getPocheUrl()) . | ||
90 | "\r\n\r\n" . sprintf(_('Your login is %1$s.'), $newUsername) ."\r\n\r\n" . | ||
91 | _('Note : The password has been chosen by the person who created your account. Get in touch with that person to know your password and change it as soon as possible') . "\r\n\r\n" . | ||
92 | _('Have fun with it !') . "\r\n\r\n" . | ||
93 | _('This is an automatically generated message, no one will answer if you respond to it.'); | ||
94 | |||
95 | // if external (public) registration | ||
96 | $body = sprintf(_('Hi, %1$s'), $newUsername) . "\r\n\r\n" . | ||
97 | sprintf(_('You\'ve just created a wallabag account on %1$s.'), Tools::getPocheUrl()) . | ||
98 | "\r\n\r\n" . _("Have fun with it !"); | ||
99 | |||
100 | $body = $internalRegistration ? $body_internal : $body; | ||
101 | |||
102 | $body = wordwrap($body, 70, "\r\n"); // cut lines with more than 70 caracters (MIME standard) | ||
103 | if (mail($email, sprintf(_('Your new wallabag account on %1$s'), Tools::getPocheUrl()), $body, | ||
104 | 'X-Mailer: PHP/' . phpversion() . "\r\n" . | ||
105 | 'Content-type: text/plain; charset=UTF-8' . "\r\n" . | ||
106 | "From: " . $newUsername . "@" . gethostname() . "\r\n")) { | ||
107 | Tools::logm('The user ' . $newUsername . ' has been emailed'); | ||
108 | $this->messages->add('i', sprintf(_('The new user %1$s has been sent an email at %2$s. You may have to check spam folder.'), $newUsername, $email)); | ||
109 | Tools::redirect('?'); | ||
110 | |||
111 | } else { | ||
112 | Tools::logm('A problem has been encountered while sending an email'); | ||
113 | $this->messages->add('e', _('A problem has been encountered while sending an email')); | ||
114 | } | ||
115 | } else { | ||
116 | Tools::logm('The user has been created, but the server did not authorize sending emails'); | ||
117 | $this->messages->add('i', _('The server did not authorize sending a confirmation email, but the user was created.')); | ||
118 | } | ||
119 | } else { | ||
120 | Tools::logm('The user has been created, but no email was saved, so no confimation email was sent'); | ||
121 | $this->messages->add('i', _('The user was created, but no email was sent because email was not filled in')); | ||
122 | } | ||
123 | Tools::logm('The new user ' . $newUsername . ' has been installed'); | ||
124 | if (\Session::isLogged()) { | ||
85 | $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>'), $newUsername)); | 125 | $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>'), $newUsername)); |
86 | Tools::redirect(); | 126 | } |
127 | Tools::redirect(); | ||
87 | } | 128 | } |
88 | else { | 129 | else { |
89 | Tools::logm('error during adding new user'); | 130 | Tools::logm('error during adding new user'); |
@@ -96,6 +137,9 @@ class Poche | |||
96 | Tools::redirect(); | 137 | Tools::redirect(); |
97 | } | 138 | } |
98 | } | 139 | } |
140 | else { | ||
141 | Tools::logm('Password or username were empty'); | ||
142 | } | ||
99 | } | 143 | } |
100 | 144 | ||
101 | /** | 145 | /** |
@@ -180,6 +224,13 @@ class Poche | |||
180 | } | 224 | } |
181 | } | 225 | } |
182 | 226 | ||
227 | // if there are tags, add them to the new article | ||
228 | if (isset($_GET['tags'])) { | ||
229 | $_POST['value'] = $_GET['tags']; | ||
230 | $_POST['entry_id'] = $last_id; | ||
231 | $this->action('add_tag', $url); | ||
232 | } | ||
233 | |||
183 | $this->messages->add('s', _('the link has been added successfully')); | 234 | $this->messages->add('s', _('the link has been added successfully')); |
184 | } | 235 | } |
185 | else { | 236 | else { |
@@ -188,24 +239,38 @@ class Poche | |||
188 | } | 239 | } |
189 | 240 | ||
190 | if ($autoclose == TRUE) { | 241 | if ($autoclose == TRUE) { |
191 | Tools::redirect('?view=home'); | 242 | Tools::redirect('?view=home&closewin=true'); |
192 | } else { | 243 | } else { |
193 | Tools::redirect('?view=home&closewin=true'); | 244 | Tools::redirect('?view=home'); |
194 | } | 245 | } |
246 | return $last_id; | ||
195 | break; | 247 | break; |
196 | case 'delete': | 248 | case 'delete': |
197 | $msg = 'delete link #' . $id; | 249 | if (isset($_GET['search'])) { |
198 | if ($this->store->deleteById($id, $this->user->getId())) { | 250 | //when we want to apply a delete to a search |
199 | if (DOWNLOAD_PICTURES) { | 251 | $tags = array($_GET['search']); |
200 | Picture::removeDirectory(ABS_PATH . $id); | 252 | $allentry_ids = $this->store->search($tags[0], $this->user->getId()); |
253 | $entry_ids = array(); | ||
254 | foreach ($allentry_ids as $eachentry) { | ||
255 | $entry_ids[] = $eachentry[0]; | ||
201 | } | 256 | } |
202 | $this->messages->add('s', _('the link has been deleted successfully')); | 257 | } else { // delete a single article |
258 | $entry_ids = array($id); | ||
203 | } | 259 | } |
204 | else { | 260 | foreach($entry_ids as $id) { |
205 | $this->messages->add('e', _('the link wasn\'t deleted')); | 261 | $msg = 'delete link #' . $id; |
206 | $msg = 'error : can\'t delete link #' . $id; | 262 | if ($this->store->deleteById($id, $this->user->getId())) { |
263 | if (DOWNLOAD_PICTURES) { | ||
264 | Picture::removeDirectory(ABS_PATH . $id); | ||
265 | } | ||
266 | $this->messages->add('s', _('the link has been deleted successfully')); | ||
267 | } | ||
268 | else { | ||
269 | $this->messages->add('e', _('the link wasn\'t deleted')); | ||
270 | $msg = 'error : can\'t delete link #' . $id; | ||
271 | } | ||
272 | Tools::logm($msg); | ||
207 | } | 273 | } |
208 | Tools::logm($msg); | ||
209 | Tools::redirect('?'); | 274 | Tools::redirect('?'); |
210 | break; | 275 | break; |
211 | case 'toggle_fav' : | 276 | case 'toggle_fav' : |
@@ -220,8 +285,21 @@ class Poche | |||
220 | } | 285 | } |
221 | break; | 286 | break; |
222 | case 'toggle_archive' : | 287 | case 'toggle_archive' : |
223 | $this->store->archiveById($id, $this->user->getId()); | 288 | if (isset($_GET['tag_id'])) { |
224 | Tools::logm('archive link #' . $id); | 289 | //when we want to archive a whole tag |
290 | $tag_id = $_GET['tag_id']; | ||
291 | $allentry_ids = $this->store->retrieveEntriesByTag($tag_id, $this->user->getId()); | ||
292 | $entry_ids = array(); | ||
293 | foreach ($allentry_ids as $eachentry) { | ||
294 | $entry_ids[] = $eachentry[0]; | ||
295 | } | ||
296 | } else { //archive a single article | ||
297 | $entry_ids = array($id); | ||
298 | } | ||
299 | foreach($entry_ids as $id) { | ||
300 | $this->store->archiveById($id, $this->user->getId()); | ||
301 | Tools::logm('archive link #' . $id); | ||
302 | } | ||
225 | if ( Tools::isAjaxRequest() ) { | 303 | if ( Tools::isAjaxRequest() ) { |
226 | echo 1; | 304 | echo 1; |
227 | exit; | 305 | exit; |
@@ -303,6 +381,26 @@ class Poche | |||
303 | $this->messages->add('s', _('The tag has been successfully deleted')); | 381 | $this->messages->add('s', _('The tag has been successfully deleted')); |
304 | Tools::redirect(); | 382 | Tools::redirect(); |
305 | break; | 383 | break; |
384 | |||
385 | case 'reload_article' : | ||
386 | Tools::logm('reload article'); | ||
387 | $id = $_GET['id']; | ||
388 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); | ||
389 | Tools::logm('reload url ' . $entry['url']); | ||
390 | $url = new Url(base64_encode($entry['url'])); | ||
391 | $this->action('add', $url); | ||
392 | break; | ||
393 | |||
394 | /* 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 */ | ||
395 | case 'random': | ||
396 | Tools::logm('get a random article'); | ||
397 | if ($this->store->getRandomId($this->user->getId())) { | ||
398 | $id_array = $this->store->getRandomId($this->user->getId()); | ||
399 | $id = $id_array[0]; | ||
400 | Tools::redirect('?view=view&id=' . $id[0]); | ||
401 | Tools::logm('got the article with id ' . $id[0]); | ||
402 | } | ||
403 | break; | ||
306 | default: | 404 | default: |
307 | break; | 405 | break; |
308 | } | 406 | } |
@@ -405,9 +503,12 @@ class Poche | |||
405 | } | 503 | } |
406 | 504 | ||
407 | # flattr checking | 505 | # flattr checking |
408 | $flattr = new FlattrItem(); | 506 | $flattr = NULL; |
409 | $flattr->checkItem($entry['url'], $entry['id']); | 507 | if (FLATTR) { |
410 | 508 | $flattr = new FlattrItem(); | |
509 | $flattr->checkItem($entry['url'], $entry['id']); | ||
510 | } | ||
511 | |||
411 | # tags | 512 | # tags |
412 | $tags = $this->store->retrieveTagsByEntry($entry['id']); | 513 | $tags = $this->store->retrieveTagsByEntry($entry['id']); |
413 | 514 | ||
@@ -540,6 +641,8 @@ class Poche | |||
540 | Tools::redirect($referer); | 641 | Tools::redirect($referer); |
541 | } | 642 | } |
542 | $this->messages->add('e', _('login failed: bad login or password')); | 643 | $this->messages->add('e', _('login failed: bad login or password')); |
644 | // log login failure in web server log to allow fail2ban usage | ||
645 | error_log('user '.$login.' authentication failure'); | ||
543 | Tools::logm('login failed'); | 646 | Tools::logm('login failed'); |
544 | Tools::redirect(); | 647 | Tools::redirect(); |
545 | } | 648 | } |
@@ -625,7 +728,18 @@ class Poche | |||
625 | $urlsInserted[] = $url; //add | 728 | $urlsInserted[] = $url; //add |
626 | if (isset($record['tags']) && trim($record['tags'])) { | 729 | if (isset($record['tags']) && trim($record['tags'])) { |
627 | 730 | ||
628 | // @TODO: set tags | 731 | $tags = explode(',', $record['tags']); |
732 | foreach($tags as $tag) { | ||
733 | $entry_id = $id; | ||
734 | $tag_id = $this->store->retrieveTagByValue($tag); | ||
735 | if ($tag_id) { | ||
736 | $this->store->setTagToEntry($tag_id['id'], $entry_id); | ||
737 | } else { | ||
738 | $this->store->createTag($tag); | ||
739 | $tag_id = $this->store->retrieveTagByValue($tag); | ||
740 | $this->store->setTagToEntry($tag_id['id'], $entry_id); | ||
741 | } | ||
742 | } | ||
629 | 743 | ||
630 | } | 744 | } |
631 | } | 745 | } |
@@ -640,7 +754,7 @@ class Poche | |||
640 | Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).'); | 754 | Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).'); |
641 | } | 755 | } |
642 | else { | 756 | else { |
643 | $this->messages->add('s', _('Did you forget to select a file?')); | 757 | $this->messages->add('e', _('Did you forget to select a file?')); |
644 | } | 758 | } |
645 | // file parsing finished here | 759 | // file parsing finished here |
646 | // now download article contents if any | 760 | // now download article contents if any |
@@ -669,17 +783,23 @@ class Poche | |||
669 | $purifier = $this->_getPurifier(); | 783 | $purifier = $this->_getPurifier(); |
670 | foreach($items as $item) { | 784 | foreach($items as $item) { |
671 | $url = new Url(base64_encode($item['url'])); | 785 | $url = new Url(base64_encode($item['url'])); |
672 | Tools::logm('Fetching article ' . $item['id']); | 786 | if( $url->isCorrect() ) |
673 | $content = Tools::getPageContent($url); | 787 | { |
674 | $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled')); | 788 | Tools::logm('Fetching article ' . $item['id']); |
675 | $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined')); | 789 | $content = Tools::getPageContent($url); |
676 | 790 | $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled')); | |
677 | // clean content to prevent xss attack | 791 | $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined')); |
678 | 792 | ||
679 | $title = $purifier->purify($title); | 793 | // clean content to prevent xss attack |
680 | $body = $purifier->purify($body); | 794 | |
681 | $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); | 795 | $title = $purifier->purify($title); |
682 | Tools::logm('Article ' . $item['id'] . ' updated.'); | 796 | $body = $purifier->purify($body); |
797 | $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); | ||
798 | Tools::logm('Article ' . $item['id'] . ' updated.'); | ||
799 | } else | ||
800 | { | ||
801 | Tools::logm('Unvalid URL (' . $item['url'] .') to fetch for article ' . $item['id']); | ||
802 | } | ||
683 | } | 803 | } |
684 | } | 804 | } |
685 | } | 805 | } |
@@ -748,10 +868,11 @@ class Poche | |||
748 | * | 868 | * |
749 | * @param $token | 869 | * @param $token |
750 | * @param $user_id | 870 | * @param $user_id |
751 | * @param $tag_id | 871 | * @param $tag_id if $type is 'tag', the id of the tag to generate feed for |
752 | * @param string $type | 872 | * @param string $type the type of feed to generate |
873 | * @param int $limit the maximum number of items (0 means all) | ||
753 | */ | 874 | */ |
754 | public function generateFeeds($token, $user_id, $tag_id, $type = 'home') | 875 | public function generateFeeds($token, $user_id, $tag_id, $type = 'home', $limit = 0) |
755 | { | 876 | { |
756 | $allowed_types = array('home', 'fav', 'archive', 'tag'); | 877 | $allowed_types = array('home', 'fav', 'archive', 'tag'); |
757 | $config = $this->store->getConfigUser($user_id); | 878 | $config = $this->store->getConfigUser($user_id); |
@@ -778,8 +899,13 @@ class Poche | |||
778 | $entries = $this->store->getEntriesByView($type, $user_id); | 899 | $entries = $this->store->getEntriesByView($type, $user_id); |
779 | } | 900 | } |
780 | 901 | ||
902 | // if $limit is set to zero, use all entries | ||
903 | if (0 == $limit) { | ||
904 | $limit = count($entries); | ||
905 | } | ||
781 | if (count($entries) > 0) { | 906 | if (count($entries) > 0) { |
782 | foreach ($entries as $entry) { | 907 | for ($i = 0; $i < min(count($entries), $limit); $i++) { |
908 | $entry = $entries[$i]; | ||
783 | $newItem = $feed->createNewItem(); | 909 | $newItem = $feed->createNewItem(); |
784 | $newItem->setTitle($entry['title']); | 910 | $newItem->setTitle($entry['title']); |
785 | $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); | 911 | $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..177b74d5 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php | |||
@@ -33,6 +33,7 @@ class Routing | |||
33 | $this->view = Tools::checkVar('view', 'home'); | 33 | $this->view = Tools::checkVar('view', 'home'); |
34 | $this->action = Tools::checkVar('action'); | 34 | $this->action = Tools::checkVar('action'); |
35 | $this->id = Tools::checkVar('id'); | 35 | $this->id = Tools::checkVar('id'); |
36 | $this->autoclose = Tools::checkVar('autoclose',FALSE); | ||
36 | $_SESSION['sort'] = Tools::checkVar('sort', 'id'); | 37 | $_SESSION['sort'] = Tools::checkVar('sort', 'id'); |
37 | $this->url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); | 38 | $this->url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); |
38 | } | 39 | } |
@@ -64,9 +65,15 @@ class Routing | |||
64 | $tplVars = array(); | 65 | $tplVars = array(); |
65 | 66 | ||
66 | if (\Session::isLogged()) { | 67 | if (\Session::isLogged()) { |
67 | $this->wallabag->action($this->action, $this->url, $this->id); | 68 | $this->wallabag->action($this->action, $this->url, $this->id, FALSE, $this->autoclose); |
68 | $tplFile = Tools::getTplFile($this->view); | 69 | $tplFile = Tools::getTplFile($this->view); |
69 | $tplVars = array_merge($this->vars, $this->wallabag->displayView($this->view, $this->id)); | 70 | $tplVars = array_merge($this->vars, $this->wallabag->displayView($this->view, $this->id)); |
71 | } elseif(ALLOW_REGISTER && isset($_GET['registerform'])) { | ||
72 | Tools::logm('register'); | ||
73 | $tplFile = Tools::getTplFile('register'); | ||
74 | } elseif (ALLOW_REGISTER && isset($_GET['register'])){ | ||
75 | $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail']); | ||
76 | Tools::redirect(); | ||
70 | } elseif(isset($_SERVER['PHP_AUTH_USER'])) { | 77 | } elseif(isset($_SERVER['PHP_AUTH_USER'])) { |
71 | if($this->wallabag->store->userExists($_SERVER['PHP_AUTH_USER'])) { | 78 | if($this->wallabag->store->userExists($_SERVER['PHP_AUTH_USER'])) { |
72 | $this->wallabag->login($this->referer); | 79 | $this->wallabag->login($this->referer); |
@@ -102,8 +109,11 @@ class Routing | |||
102 | $this->wallabag->login($this->referer); | 109 | $this->wallabag->login($this->referer); |
103 | } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) { | 110 | } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) { |
104 | $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); | 111 | $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']); | 112 | $limit = (isset($_GET['limit']) ? intval($_GET['limit']) : 0); |
106 | } | 113 | $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type'], $limit); |
114 | } //elseif (ALLOW_REGISTER && isset($_GET['register'])) { | ||
115 | //$this->wallabag->register | ||
116 | //} | ||
107 | 117 | ||
108 | //allowed ONLY to logged in user | 118 | //allowed ONLY to logged in user |
109 | if (\Session::isLogged() === true) | 119 | if (\Session::isLogged() === true) |
@@ -115,12 +125,21 @@ class Routing | |||
115 | // update password | 125 | // update password |
116 | $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); | 126 | $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); |
117 | } elseif (isset($_GET['newuser'])) { | 127 | } elseif (isset($_GET['newuser'])) { |
118 | $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']); | 128 | $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail'], true); |
119 | } elseif (isset($_GET['deluser'])) { | 129 | } elseif (isset($_GET['deluser'])) { |
120 | $this->wallabag->deleteUser($_POST['password4deletinguser']); | 130 | $this->wallabag->deleteUser($_POST['password4deletinguser']); |
121 | } elseif (isset($_GET['epub'])) { | 131 | } elseif (isset($_GET['epub'])) { |
122 | $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); | 132 | $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); |
123 | $epub->run(); | 133 | $epub->prepareData(); |
134 | $epub->produceEpub(); | ||
135 | } elseif (isset($_GET['mobi'])) { | ||
136 | $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); | ||
137 | $mobi->prepareData(); | ||
138 | $mobi->produceMobi(); | ||
139 | } elseif (isset($_GET['pdf'])) { | ||
140 | $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); | ||
141 | $pdf->prepareData(); | ||
142 | $pdf->producePDF(); | ||
124 | } elseif (isset($_GET['import'])) { | 143 | } elseif (isset($_GET['import'])) { |
125 | $import = $this->wallabag->import(); | 144 | $import = $this->wallabag->import(); |
126 | $tplVars = array_merge($this->vars, $import); | 145 | $tplVars = array_merge($this->vars, $import); |
@@ -148,4 +167,4 @@ class Routing | |||
148 | { | 167 | { |
149 | echo $this->wallabag->tpl->render($file, $vars); | 168 | echo $this->wallabag->tpl->render($file, $vars); |
150 | } | 169 | } |
151 | } \ No newline at end of file | 170 | } |
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/Tools.class.php b/inc/poche/Tools.class.php index 7ccfc069..d0b31d4f 100755 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php | |||
@@ -117,7 +117,7 @@ final class Tools | |||
117 | { | 117 | { |
118 | $views = array( | 118 | $views = array( |
119 | 'install', 'import', 'export', 'config', 'tags', | 119 | 'install', 'import', 'export', 'config', 'tags', |
120 | 'edit-tags', 'view', 'login', 'error', 'about' | 120 | 'edit-tags', 'view', 'login', 'error', 'about', 'register' |
121 | ); | 121 | ); |
122 | 122 | ||
123 | return (in_array($view, $views) ? $view . '.twig' : 'home.twig'); | 123 | return (in_array($view, $views) ? $view . '.twig' : 'home.twig'); |
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..09d3aa9a 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php | |||
@@ -20,6 +20,7 @@ | |||
20 | @define ('STORAGE_DB', 'poche'); | 20 | @define ('STORAGE_DB', 'poche'); |
21 | @define ('STORAGE_USER', 'poche'); | 21 | @define ('STORAGE_USER', 'poche'); |
22 | @define ('STORAGE_PASSWORD', 'poche'); | 22 | @define ('STORAGE_PASSWORD', 'poche'); |
23 | @define ('MYSQL_USE_UTF8MB4', FALSE); // This should be false unless you know what it is | ||
23 | 24 | ||
24 | ################################################################################# | 25 | ################################################################################# |
25 | # Do not trespass unless you know what you are doing | 26 | # Do not trespass unless you know what you are doing |
@@ -44,15 +45,30 @@ | |||
44 | @define ('SHARE_MAIL', TRUE); | 45 | @define ('SHARE_MAIL', TRUE); |
45 | @define ('SHARE_SHAARLI', FALSE); | 46 | @define ('SHARE_SHAARLI', FALSE); |
46 | @define ('SHAARLI_URL', 'http://myshaarliurl.com'); | 47 | @define ('SHAARLI_URL', 'http://myshaarliurl.com'); |
48 | @define ('SHARE_EVERNOTE', FALSE); | ||
49 | @define ('SHARE_DIASPORA', FALSE); | ||
50 | @define ('DIASPORA_URL', 'http://diasporapod.com'); # Don't add a / at the end | ||
47 | @define ('FLATTR', TRUE); | 51 | @define ('FLATTR', TRUE); |
48 | @define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url='); | 52 | @define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url='); |
49 | @define ('NOT_FLATTRABLE', '0'); | 53 | @define ('NOT_FLATTRABLE', '0'); |
50 | @define ('FLATTRABLE', '1'); | 54 | @define ('FLATTRABLE', '1'); |
51 | @define ('FLATTRED', '2'); | 55 | @define ('FLATTRED', '2'); |
56 | @define ('CARROT', FALSE); | ||
57 | |||
58 | // ebook | ||
59 | @define ('EPUB', TRUE); | ||
60 | @define ('MOBI', FALSE); | ||
61 | @define ('PDF', FALSE); | ||
62 | |||
63 | // registration | ||
64 | @define ('ALLOW_REGISTER', FALSE); | ||
65 | @define ('SEND_CONFIRMATION_EMAIL', FALSE); | ||
66 | |||
52 | // display or not print link in article view | 67 | // display or not print link in article view |
53 | @define ('SHOW_PRINTLINK', '1'); | 68 | @define ('SHOW_PRINTLINK', '1'); |
54 | // display or not percent of read in article view. Affects only default theme. | 69 | // display or not percent of read in article view. Affects only default theme. |
55 | @define ('SHOW_READPERCENT', '1'); | 70 | @define ('SHOW_READPERCENT', '1'); |
71 | @define ('RELOAD_ARTICLE', TRUE); | ||
56 | @define ('ABS_PATH', 'assets/'); | 72 | @define ('ABS_PATH', 'assets/'); |
57 | 73 | ||
58 | @define ('DEFAULT_THEME', 'baggy'); | 74 | @define ('DEFAULT_THEME', 'baggy'); |
@@ -67,4 +83,3 @@ | |||
67 | @define ('IMPORT_LIMIT', 5); | 83 | @define ('IMPORT_LIMIT', 5); |
68 | //delay between downloads (in sec) | 84 | //delay between downloads (in sec) |
69 | @define ('IMPORT_DELAY', 5); | 85 | @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'; |