diff options
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-x | inc/poche/Poche.class.php | 289 |
1 files changed, 241 insertions, 48 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 811895dc..37cf66a3 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -72,7 +72,7 @@ class Poche | |||
72 | 72 | ||
73 | # l10n | 73 | # l10n |
74 | $language = $this->user->getConfigValue('language'); | 74 | $language = $this->user->getConfigValue('language'); |
75 | putenv('LC_ALL=' . $language); | 75 | @putenv('LC_ALL=' . $language); |
76 | setlocale(LC_ALL, $language); | 76 | setlocale(LC_ALL, $language); |
77 | bindtextdomain($language, LOCALE); | 77 | bindtextdomain($language, LOCALE); |
78 | textdomain($language); | 78 | textdomain($language); |
@@ -101,7 +101,7 @@ class Poche | |||
101 | 101 | ||
102 | public function configFileIsAvailable() { | 102 | public function configFileIsAvailable() { |
103 | if (! self::$configFileAvailable) { | 103 | if (! self::$configFileAvailable) { |
104 | $this->notInstalledMessage[] = 'You have to rename inc/poche/config.inc.php.new to inc/poche/config.inc.php.'; | 104 | $this->notInstalledMessage[] = 'You have to copy (don\'t just rename!) inc/poche/config.inc.default.php to inc/poche/config.inc.php.'; |
105 | 105 | ||
106 | return false; | 106 | return false; |
107 | } | 107 | } |
@@ -242,6 +242,58 @@ class Poche | |||
242 | $this->tpl->addFilter($filter); | 242 | $this->tpl->addFilter($filter); |
243 | } | 243 | } |
244 | 244 | ||
245 | public function createNewUser() { | ||
246 | if (isset($_GET['newuser'])){ | ||
247 | if ($_POST['newusername'] != "" && $_POST['password4newuser'] != ""){ | ||
248 | $newusername = filter_var($_POST['newusername'], FILTER_SANITIZE_STRING); | ||
249 | if (!$this->store->userExists($newusername)){ | ||
250 | if ($this->store->install($newusername, Tools::encodeString($_POST['password4newuser'] . $newusername))) { | ||
251 | Tools::logm('The new user '.$newusername.' has been installed'); | ||
252 | $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>'),$newusername)); | ||
253 | Tools::redirect(); | ||
254 | } | ||
255 | else { | ||
256 | Tools::logm('error during adding new user'); | ||
257 | Tools::redirect(); | ||
258 | } | ||
259 | } | ||
260 | else { | ||
261 | $this->messages->add('e', sprintf(_('Error : An user with the name %s already exists !'),$newusername)); | ||
262 | Tools::logm('An user with the name '.$newusername.' already exists !'); | ||
263 | Tools::redirect(); | ||
264 | } | ||
265 | } | ||
266 | } | ||
267 | } | ||
268 | |||
269 | public function deleteUser(){ | ||
270 | if (isset($_GET['deluser'])){ | ||
271 | if ($this->store->listUsers() > 1) { | ||
272 | if (Tools::encodeString($_POST['password4deletinguser'].$this->user->getUsername()) == $this->store->getUserPassword($this->user->getId())) { | ||
273 | $username = $this->user->getUsername(); | ||
274 | $this->store->deleteUserConfig($this->user->getId()); | ||
275 | Tools::logm('The configuration for user '. $username .' has been deleted !'); | ||
276 | $this->store->deleteTagsEntriesAndEntries($this->user->getId()); | ||
277 | Tools::logm('The entries for user '. $username .' has been deleted !'); | ||
278 | $this->store->deleteUser($this->user->getId()); | ||
279 | Tools::logm('User '. $username .' has been completely deleted !'); | ||
280 | Session::logout(); | ||
281 | Tools::logm('logout'); | ||
282 | Tools::redirect(); | ||
283 | $this->messages->add('s', sprintf(_('User %s has been successfully deleted !'),$newusername)); | ||
284 | } | ||
285 | else { | ||
286 | Tools::logm('Bad password !'); | ||
287 | $this->messages->add('e', _('Error : The password is wrong !')); | ||
288 | } | ||
289 | } | ||
290 | else { | ||
291 | Tools::logm('Only user !'); | ||
292 | $this->messages->add('e', _('Error : You are the only user, you cannot delete your account !')); | ||
293 | } | ||
294 | } | ||
295 | } | ||
296 | |||
245 | private function install() | 297 | private function install() |
246 | { | 298 | { |
247 | Tools::logm('poche still not installed'); | 299 | Tools::logm('poche still not installed'); |
@@ -434,12 +486,24 @@ class Poche | |||
434 | case 'toggle_fav' : | 486 | case 'toggle_fav' : |
435 | $this->store->favoriteById($id, $this->user->getId()); | 487 | $this->store->favoriteById($id, $this->user->getId()); |
436 | Tools::logm('mark as favorite link #' . $id); | 488 | Tools::logm('mark as favorite link #' . $id); |
437 | Tools::redirect(); | 489 | if ( Tools::isAjaxRequest() ) { |
490 | echo 1; | ||
491 | exit; | ||
492 | } | ||
493 | else { | ||
494 | Tools::redirect(); | ||
495 | } | ||
438 | break; | 496 | break; |
439 | case 'toggle_archive' : | 497 | case 'toggle_archive' : |
440 | $this->store->archiveById($id, $this->user->getId()); | 498 | $this->store->archiveById($id, $this->user->getId()); |
441 | Tools::logm('archive link #' . $id); | 499 | Tools::logm('archive link #' . $id); |
442 | Tools::redirect(); | 500 | if ( Tools::isAjaxRequest() ) { |
501 | echo 1; | ||
502 | exit; | ||
503 | } | ||
504 | else { | ||
505 | Tools::redirect(); | ||
506 | } | ||
443 | break; | 507 | break; |
444 | case 'archive_all' : | 508 | case 'archive_all' : |
445 | $this->store->archiveAll($this->user->getId()); | 509 | $this->store->archiveAll($this->user->getId()); |
@@ -447,42 +511,55 @@ class Poche | |||
447 | Tools::redirect(); | 511 | Tools::redirect(); |
448 | break; | 512 | break; |
449 | case 'add_tag' : | 513 | case 'add_tag' : |
450 | $tags = explode(',', $_POST['value']); | 514 | if (isset($_GET['search'])) { |
451 | $entry_id = $_POST['entry_id']; | 515 | //when we want to apply a tag to a search |
452 | $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); | 516 | $tags = array($_GET['search']); |
453 | if (!$entry) { | 517 | $allentry_ids = $this->store->search($tags[0], $this->user->getId()); |
454 | $this->messages->add('e', _('Article not found!')); | 518 | $entry_ids = array(); |
455 | Tools::logm('error : article not found'); | 519 | foreach ($allentry_ids as $eachentry) { |
456 | Tools::redirect(); | 520 | $entry_ids[] = $eachentry[0]; |
457 | } | 521 | } |
458 | //get all already set tags to preven duplicates | 522 | } else { //add a tag to a single article |
459 | $already_set_tags = array(); | 523 | $tags = explode(',', $_POST['value']); |
460 | $entry_tags = $this->store->retrieveTagsByEntry($entry_id); | 524 | $entry_ids = array($_POST['entry_id']); |
461 | foreach ($entry_tags as $tag) { | ||
462 | $already_set_tags[] = $tag['value']; | ||
463 | } | 525 | } |
464 | foreach($tags as $key => $tag_value) { | 526 | foreach($entry_ids as $entry_id) { |
465 | $value = trim($tag_value); | 527 | $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); |
466 | if ($value && !in_array($value, $already_set_tags)) { | 528 | if (!$entry) { |
467 | $tag = $this->store->retrieveTagByValue($value); | 529 | $this->messages->add('e', _('Article not found!')); |
468 | 530 | Tools::logm('error : article not found'); | |
469 | if (is_null($tag)) { | 531 | Tools::redirect(); |
470 | # we create the tag | 532 | } |
471 | $tag = $this->store->createTag($value); | 533 | //get all already set tags to preven duplicates |
472 | $sequence = ''; | 534 | $already_set_tags = array(); |
473 | if (STORAGE == 'postgres') { | 535 | $entry_tags = $this->store->retrieveTagsByEntry($entry_id); |
474 | $sequence = 'tags_id_seq'; | 536 | foreach ($entry_tags as $tag) { |
537 | $already_set_tags[] = $tag['value']; | ||
538 | } | ||
539 | foreach($tags as $key => $tag_value) { | ||
540 | $value = trim($tag_value); | ||
541 | if ($value && !in_array($value, $already_set_tags)) { | ||
542 | $tag = $this->store->retrieveTagByValue($value); | ||
543 | if (is_null($tag)) { | ||
544 | # we create the tag | ||
545 | $tag = $this->store->createTag($value); | ||
546 | $sequence = ''; | ||
547 | if (STORAGE == 'postgres') { | ||
548 | $sequence = 'tags_id_seq'; | ||
549 | } | ||
550 | $tag_id = $this->store->getLastId($sequence); | ||
475 | } | 551 | } |
476 | $tag_id = $this->store->getLastId($sequence); | 552 | else { |
477 | } | 553 | $tag_id = $tag['id']; |
478 | else { | 554 | } |
479 | $tag_id = $tag['id']; | 555 | |
480 | } | 556 | # we assign the tag to the article |
481 | 557 | $this->store->setTagToEntry($tag_id, $entry_id); | |
482 | # we assign the tag to the article | 558 | } |
483 | $this->store->setTagToEntry($tag_id, $entry_id); | ||
484 | } | 559 | } |
485 | } | 560 | } |
561 | $this->messages->add('s', _('The tag has been applied successfully')); | ||
562 | Tools::logm('The tag has been applied successfully'); | ||
486 | Tools::redirect(); | 563 | Tools::redirect(); |
487 | break; | 564 | break; |
488 | case 'remove_tag' : | 565 | case 'remove_tag' : |
@@ -494,6 +571,11 @@ class Poche | |||
494 | Tools::redirect(); | 571 | Tools::redirect(); |
495 | } | 572 | } |
496 | $this->store->removeTagForEntry($id, $tag_id); | 573 | $this->store->removeTagForEntry($id, $tag_id); |
574 | Tools::logm('tag entry deleted'); | ||
575 | if ($this->store->cleanUnusedTag($tag_id)) { | ||
576 | Tools::logm('tag deleted'); | ||
577 | } | ||
578 | $this->messages->add('s', _('The tag has been successfully deleted')); | ||
497 | Tools::redirect(); | 579 | Tools::redirect(); |
498 | break; | 580 | break; |
499 | default: | 581 | default: |
@@ -520,6 +602,7 @@ class Poche | |||
520 | $languages = $this->getInstalledLanguages(); | 602 | $languages = $this->getInstalledLanguages(); |
521 | $token = $this->user->getConfigValue('token'); | 603 | $token = $this->user->getConfigValue('token'); |
522 | $http_auth = (isset($_SERVER['PHP_AUTH_USER']) || isset($_SERVER['REMOTE_USER'])) ? true : false; | 604 | $http_auth = (isset($_SERVER['PHP_AUTH_USER']) || isset($_SERVER['REMOTE_USER'])) ? true : false; |
605 | $only_user = ($this->store->listUsers() > 1) ? false : true; | ||
523 | $tpl_vars = array( | 606 | $tpl_vars = array( |
524 | 'themes' => $themes, | 607 | 'themes' => $themes, |
525 | 'languages' => $languages, | 608 | 'languages' => $languages, |
@@ -532,6 +615,7 @@ class Poche | |||
532 | 'token' => $token, | 615 | 'token' => $token, |
533 | 'user_id' => $this->user->getId(), | 616 | 'user_id' => $this->user->getId(), |
534 | 'http_auth' => $http_auth, | 617 | 'http_auth' => $http_auth, |
618 | 'only_user' => $only_user | ||
535 | ); | 619 | ); |
536 | Tools::logm('config view'); | 620 | Tools::logm('config view'); |
537 | break; | 621 | break; |
@@ -822,13 +906,6 @@ class Poche | |||
822 | */ | 906 | */ |
823 | public function import() { | 907 | public function import() { |
824 | 908 | ||
825 | if (!defined('IMPORT_LIMIT')) { | ||
826 | define('IMPORT_LIMIT', 5); | ||
827 | } | ||
828 | if (!defined('IMPORT_DELAY')) { | ||
829 | define('IMPORT_DELAY', 5); | ||
830 | } | ||
831 | |||
832 | if ( isset($_FILES['file']) ) { | 909 | if ( isset($_FILES['file']) ) { |
833 | Tools::logm('Import stated: parsing file'); | 910 | Tools::logm('Import stated: parsing file'); |
834 | 911 | ||
@@ -1065,11 +1142,127 @@ class Poche | |||
1065 | * return new purifier object with actual config | 1142 | * return new purifier object with actual config |
1066 | */ | 1143 | */ |
1067 | protected function getPurifier() { | 1144 | protected function getPurifier() { |
1068 | $config = HTMLPurifier_Config::createDefault(); | 1145 | $config = HTMLPurifier_Config::createDefault(); |
1069 | $config->set('Cache.SerializerPath', CACHE); | 1146 | $config->set('Cache.SerializerPath', CACHE); |
1070 | $config->set('HTML.SafeIframe', true); | 1147 | $config->set('HTML.SafeIframe', true); |
1071 | $config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%'); //allow YouTube and Vimeo$purifier = new HTMLPurifier($config); | 1148 | //allow YouTube, Vimeo and dailymotion videos |
1072 | 1149 | $config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/|www\.dailymotion\.com/embed/video/)%'); | |
1150 | |||
1073 | return new HTMLPurifier($config); | 1151 | return new HTMLPurifier($config); |
1074 | } | 1152 | } |
1153 | |||
1154 | /** | ||
1155 | * handle epub | ||
1156 | */ | ||
1157 | public function createEpub() { | ||
1158 | |||
1159 | switch ($_GET['method']) { | ||
1160 | case 'id': | ||
1161 | $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT); | ||
1162 | $entry = $this->store->retrieveOneById($entryID, $this->user->getId()); | ||
1163 | $entries = array($entry); | ||
1164 | $bookTitle = $entry['title']; | ||
1165 | $bookFileName = substr($bookTitle, 0, 200); | ||
1166 | break; | ||
1167 | case 'all': | ||
1168 | $entries = $this->store->retrieveAll($this->user->getId()); | ||
1169 | $bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system | ||
1170 | $bookFileName = _('Allarticles') . date(_('dmY')); | ||
1171 | break; | ||
1172 | case 'tag': | ||
1173 | $tag = filter_var($_GET['tag'],FILTER_SANITIZE_STRING); | ||
1174 | $tags_id = $this->store->retrieveAllTags($this->user->getId(),$tag); | ||
1175 | $tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround. | ||
1176 | $entries = $this->store->retrieveEntriesByTag($tag_id,$this->user->getId()); | ||
1177 | $bookTitle = sprintf(_('Articles tagged %s'),$tag); | ||
1178 | $bookFileName = substr(sprintf(_('Tag %s'),$tag), 0, 200); | ||
1179 | break; | ||
1180 | case 'category': | ||
1181 | $category = filter_var($_GET['category'],FILTER_SANITIZE_STRING); | ||
1182 | $entries = $this->store->getEntriesByView($category,$this->user->getId()); | ||
1183 | $bookTitle = sprintf(_('All articles in category %s'), $category); | ||
1184 | $bookFileName = substr(sprintf(_('Category %s'),$category), 0, 200); | ||
1185 | break; | ||
1186 | case 'search': | ||
1187 | $search = filter_var($_GET['search'],FILTER_SANITIZE_STRING); | ||
1188 | $entries = $this->store->search($search,$this->user->getId()); | ||
1189 | $bookTitle = sprintf(_('All articles for search %s'), $search); | ||
1190 | $bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); | ||
1191 | break; | ||
1192 | case 'default': | ||
1193 | die(_('Uh, there is a problem while generating epub.')); | ||
1194 | |||
1195 | } | ||
1196 | |||
1197 | $content_start = | ||
1198 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
1199 | . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n" | ||
1200 | . "<head>" | ||
1201 | . "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n" | ||
1202 | . "<title>wallabag articles book</title>\n" | ||
1203 | . "</head>\n" | ||
1204 | . "<body>\n"; | ||
1205 | |||
1206 | $bookEnd = "</body>\n</html>\n"; | ||
1207 | |||
1208 | $log = new Logger("wallabag", TRUE); | ||
1209 | $fileDir = CACHE; | ||
1210 | |||
1211 | |||
1212 | $book = new EPub(EPub::BOOK_VERSION_EPUB3); | ||
1213 | $log->logLine("new EPub()"); | ||
1214 | $log->logLine("EPub class version: " . EPub::VERSION); | ||
1215 | $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION); | ||
1216 | $log->logLine("Zip version: " . Zip::VERSION); | ||
1217 | $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); | ||
1218 | $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); | ||
1219 | |||
1220 | $book->setTitle(_('wallabag\'s articles')); | ||
1221 | $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID. | ||
1222 | //$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. | ||
1223 | $book->setDescription(_("Some articles saved on my wallabag")); | ||
1224 | $book->setAuthor("wallabag","wallabag"); | ||
1225 | $book->setPublisher("wallabag","wallabag"); // I hope this is a non existant address :) | ||
1226 | $book->setDate(time()); // Strictly not needed as the book date defaults to time(). | ||
1227 | //$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. | ||
1228 | $book->setSourceURL("http://$_SERVER[HTTP_HOST]"); | ||
1229 | |||
1230 | $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); | ||
1231 | $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "wallabag"); | ||
1232 | |||
1233 | $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"; | ||
1234 | |||
1235 | $log->logLine("Add Cover"); | ||
1236 | |||
1237 | $fullTitle = "<h1> " . $bookTitle . "</h1>\n"; | ||
1238 | |||
1239 | $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle); | ||
1240 | |||
1241 | $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; | ||
1242 | |||
1243 | //$book->addChapter("Table of Contents", "TOC.xhtml", NULL, false, EPub::EXTERNAL_REF_IGNORE); | ||
1244 | $book->addChapter("Notices", "Cover2.html", $cover); | ||
1245 | |||
1246 | $book->buildTOC(); | ||
1247 | |||
1248 | foreach ($entries as $entry) { //set tags as subjects | ||
1249 | $tags = $this->store->retrieveTagsByEntry($entry['id']); | ||
1250 | foreach ($tags as $tag) { | ||
1251 | $book->setSubject($tag['value']); | ||
1252 | } | ||
1253 | |||
1254 | $log->logLine("Set up parameters"); | ||
1255 | |||
1256 | $chapter = $content_start . $entry['content'] . $bookEnd; | ||
1257 | $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); | ||
1258 | $log->logLine("Added chapter " . $entry['title']); | ||
1259 | } | ||
1260 | |||
1261 | if (DEBUG_POCHE) { | ||
1262 | $epuplog = $book->getLog(); | ||
1263 | $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // log generation | ||
1264 | } | ||
1265 | $book->finalize(); | ||
1266 | $zipData = $book->sendBook($bookFileName); | ||
1267 | } | ||
1075 | } | 1268 | } |